/* Paleta saludable: verdes, blancos, grises */
:root {
    --verde-primario: #2d8a4e;
    --verde-claro: #e8f5e9;
    --verde-oscuro: #1b5e20;
    --gris-fondo: #f5f5f5;
    --gris-borde: #dee2e6;

    /* Colores para macros */
    --color-kcal: #e53935;
    --color-kcal-bg: #ffebee;
    --color-prot: #1e88e5;
    --color-prot-bg: #e3f2fd;
    --color-carb: #f9a825;
    --color-carb-bg: #fff8e1;
    --color-gras: #6d4c41;
    --color-gras-bg: #efebe9;
    --color-fibra: #43a047;
    --color-fibra-bg: #e8f5e9;
}

body {
    background-color: var(--gris-fondo);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Navbar */
.navbar {
    background-color: var(--verde-primario) !important;
}

.navbar-brand {
    font-weight: 700;
    font-size: 1.3rem;
}

/* Cards de comida */
.card-comida {
    border: none;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
    cursor: pointer;
}

.card-comida:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

/* Boton favorita (estrella) */
.btn-favorita {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2;
    background: rgba(255, 255, 255, 0.85);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    font-size: 1.1rem;
    color: #ccc;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background 0.2s;
    line-height: 1;
}

.btn-favorita:hover {
    color: #f9a825;
    background: rgba(255, 255, 255, 0.95);
}

.btn-favorita.activa {
    color: #f9a825;
}

/* Badge manual */
.bg-outline-manual {
    background-color: transparent;
    border: 1px solid #adb5bd;
    color: #6c757d;
    font-weight: 500;
}

/* Preview de imagen en formulario */
.form-imagen-preview {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    object-fit: cover;
    border: 1px solid var(--gris-borde);
    flex-shrink: 0;
}

/* Badges por tipo de comida */
.badge-desayuno { background-color: #42a5f5; }
.badge-media_mañana { background-color: #ffa726; }
.badge-comida { background-color: #ef5350; }
.badge-merienda { background-color: var(--verde-primario); }
.badge-cena { background-color: #7e57c2; }

/* Macros (datos nutricionales) - cada uno con su color */
.macros {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    font-size: 0.78rem;
}

.macros span {
    padding: 2px 8px;
    border-radius: 20px;
    font-weight: 600;
}

.macro-kcal {
    background-color: var(--color-kcal-bg);
    color: var(--color-kcal);
}

.macro-prot {
    background-color: var(--color-prot-bg);
    color: var(--color-prot);
}

.macro-carb {
    background-color: var(--color-carb-bg);
    color: var(--color-carb);
}

.macro-gras {
    background-color: var(--color-gras-bg);
    color: var(--color-gras);
}

.macro-fibra {
    background-color: var(--color-fibra-bg);
    color: var(--color-fibra);
}

/* Fuente PDF - discreta */
.fuente-pdf {
    font-size: 0.65rem;
    color: #adb5bd;
    margin-top: auto;
    padding-top: 6px;
}

/* Buscador */
#buscador {
    border-radius: 10px;
    padding: 10px 20px;
    border: 2px solid var(--gris-borde);
    font-size: 0.95rem;
}

#buscador:focus {
    border-color: var(--verde-primario);
    box-shadow: 0 0 0 0.2rem rgba(45, 138, 78, 0.15);
}

/* Botón X para limpiar búsqueda */
.btn-limpiar-busqueda {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 1.3rem;
    color: #adb5bd;
    cursor: pointer;
    padding: 0 6px;
    line-height: 1;
}

.btn-limpiar-busqueda:hover {
    color: #495057;
}

/* Filtros */
.filtros .btn {
    border-radius: 20px;
    font-size: 0.9rem;
}

.filtros .btn.active {
    background-color: var(--verde-primario);
    border-color: var(--verde-primario);
    color: #fff;
}

/* Spinner de carga */
.spinner-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
}

/* Imagen en card de comida */
.card-img-comida {
    height: 180px;
    object-fit: cover;
    border-radius: 12px 12px 0 0;
}

/* Imagen en modal de detalle */
.modal-img-comida {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 8px;
    background-color: #f8f9fa;
    max-height: 450px;
}

/* Sección ingredientes/elaboración dentro del modal */
.detalle-seccion h6 {
    color: var(--verde-primario);
    font-weight: 600;
    margin-top: 1rem;
}

.detalle-seccion p {
    white-space: pre-line;
}

/* ===== Plan Semanal ===== */

/* Input kcal */
.kcal-input-group {
    width: 200px;
}

/* Grid de días: 3 columnas por fila */
.plan-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 12px;
}

@media (max-width: 991px) {
    .plan-grid, .plan-grid-3 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 575px) {
    .plan-grid, .plan-grid-3 {
        grid-template-columns: 1fr;
    }
}

/* Card de cada día */
.dia-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    overflow: hidden;
}

.dia-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background-color: var(--verde-primario);
    color: #fff;
}

.dia-header-excede {
    background-color: #e53935;
}

.dia-card-hoy {
    transform: translateY(-6px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    border: 1px solid var(--verde-primario);
    z-index: 1;
}

.dia-header-hoy {
    background-color: var(--verde-oscuro);
}

.dia-header h5 {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
}

.dia-totales {
    font-size: 0.85rem;
    font-weight: 600;
    opacity: 0.9;
}

.dia-ingestas {
    padding: 8px 0;
}

/* Cada ingesta dentro de un día */
.ingesta-item {
    padding: 8px 12px;
    border-bottom: 1px solid var(--gris-borde);
    cursor: pointer;
    transition: background-color 0.15s;
}

.ingesta-item:hover {
    background-color: var(--verde-claro);
}

.ingesta-item:last-child {
    border-bottom: none;
}

.ingesta-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.ingesta-macros-header {
    display: flex;
    gap: 6px;
    align-items: center;
}

.ingesta-kcal {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-kcal);
}

.ingesta-prot {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-prot);
}

.ingesta-body {
    display: flex;
    gap: 12px;
    align-items: center;
}

.ingesta-img {
    width: 45px;
    height: 45px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
}

.ingesta-info strong {
    font-size: 0.85rem;
    display: block;
    margin-bottom: 2px;
}

/* ===== Selector de comida ===== */

.selector-item {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid var(--gris-borde);
    cursor: pointer;
    border-radius: 8px;
    transition: background-color 0.15s;
}

.selector-item:last-child {
    border-bottom: none;
}

.selector-item:hover {
    background-color: var(--verde-claro);
}

.selector-item-loading {
    opacity: 0.5;
    pointer-events: none;
}

.selector-item-img {
    width: 50px;
    height: 50px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
}

.selector-item-info strong {
    font-size: 0.9rem;
    display: block;
    margin-bottom: 2px;
}

#buscador-selector {
    border-radius: 10px;
    padding: 8px 16px;
    border: 2px solid var(--gris-borde);
    font-size: 0.9rem;
}

#buscador-selector:focus {
    border-color: var(--verde-primario);
    box-shadow: 0 0 0 0.2rem rgba(45, 138, 78, 0.15);
}

/* ===== Historial de Planes ===== */

.historial-item {
    padding: 12px 14px;
    border-bottom: 1px solid var(--gris-borde);
    cursor: pointer;
    transition: background-color 0.15s;
    border-radius: 0;
}

.historial-item:first-child {
    border-radius: 8px 8px 0 0;
}

.historial-item:last-child {
    border-bottom: none;
    border-radius: 0 0 8px 8px;
}

.historial-item:hover {
    background-color: var(--verde-claro);
}

.historial-item-activo {
    background-color: var(--verde-claro);
    border-left: 3px solid var(--verde-primario);
}

.historial-item-fecha {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.historial-item-info {
    display: flex;
    gap: 6px;
    font-size: 0.85rem;
    color: #6c757d;
}

/* ===== Lista de la Compra ===== */

.lista-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: #fff;
    border-bottom: 1px solid var(--gris-borde);
    transition: background-color 0.15s, opacity 0.2s;
}

.lista-item:first-child {
    border-radius: 8px 8px 0 0;
}

.lista-item:last-child {
    border-bottom: none;
    border-radius: 0 0 8px 8px;
}

.lista-item:only-child {
    border-radius: 8px;
}

.lista-item.checked {
    opacity: 0.5;
    background-color: #f8f9fa;
}

.lista-item.checked .lista-item-nombre {
    text-decoration: line-through;
    color: #adb5bd;
}

.lista-item-label {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    cursor: pointer;
    flex: 1;
}

.lista-item-nombre {
    font-size: 0.95rem;
}

.lista-item-count {
    font-size: 0.75rem;
    flex-shrink: 0;
}

.lista-check {
    cursor: pointer;
}

/* ===== Modal formulario comida: layout 2 paneles ===== */

.form-panel-titulo {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #6c757d;
}

/* Panel derecho: Nutricion */
.panel-nutricion {
    background-color: #f8faf8;
    border-left: 1px solid var(--gris-borde);
    min-height: 100%;
}

.panel-nutricion-inner {
    padding: 1.5rem;
    position: sticky;
    top: 0;
}

.nutricion-buscar {
    border-radius: 10px;
    padding: 6px 14px;
    border: 2px solid var(--gris-borde);
    font-size: 0.85rem;
    background: #fff;
}

.nutricion-buscar:focus {
    border-color: var(--verde-primario);
    box-shadow: 0 0 0 0.15rem rgba(45, 138, 78, 0.12);
}

/* Resultados búsqueda productos (estilo select2) */
.productos-resultados {
    position: absolute;
    z-index: 10;
    background: #fff;
    border: 1px solid var(--gris-borde);
    border-radius: 0 0 10px 10px;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.14);
    max-height: 220px;
    overflow-y: auto;
    width: 100%;
    left: 0;
    top: 100%;
    margin-top: -1px;
}

.producto-resultado {
    display: flex;
    align-items: center;
    padding: 7px 12px;
    cursor: pointer;
    font-size: 0.82rem;
    border-bottom: 1px solid #f5f5f5;
    gap: 6px;
    transition: background-color 0.1s;
}

.producto-resultado:last-child {
    border-bottom: none;
}

.producto-resultado:hover {
    background-color: var(--verde-claro);
}

.producto-resultado-added {
    opacity: 0.45;
    cursor: default;
    background-color: #f8f9fa;
}

.producto-resultado-nombre {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.producto-resultado-marca {
    font-size: 0.75rem;
    white-space: nowrap;
}

.producto-resultado-cat {
    font-size: 0.65rem;
    background: #e9ecef;
    color: #6c757d;
    padding: 1px 6px;
    border-radius: 10px;
    white-space: nowrap;
}

.producto-resultado-kcal {
    font-size: 0.72rem;
    color: var(--color-kcal);
    font-weight: 600;
    white-space: nowrap;
}

.producto-resultado-check {
    color: var(--verde-primario);
    font-weight: 700;
    font-size: 0.85rem;
}

/* Lista de productos añadidos */
.productos-lista-panel {
    max-height: 240px;
    overflow-y: auto;
}

.ingrediente-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 8px;
    background: #fff;
    border: 1px solid #e9ecef;
    margin-bottom: 6px;
    font-size: 0.85rem;
    transition: box-shadow 0.15s;
}

.ingrediente-item:hover {
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.ingrediente-info {
    flex: 1;
    min-width: 0;
}

.ingrediente-info strong {
    font-size: 0.82rem;
    display: block;
    line-height: 1.2;
}

.ingrediente-info small {
    display: block;
    line-height: 1.2;
}

.ingrediente-cantidad {
    display: flex;
    align-items: center;
    gap: 3px;
    flex-shrink: 0;
}

.ingrediente-cantidad input {
    width: 62px !important;
    text-align: center;
    font-size: 0.8rem;
    border-radius: 6px;
}

.ingrediente-cantidad .text-muted {
    font-size: 0.75rem;
}

.ingrediente-kcal {
    font-size: 0.78rem;
    color: var(--color-kcal);
    font-weight: 600;
    white-space: nowrap;
    min-width: 50px;
    text-align: right;
}

.ingrediente-quitar {
    padding: 0 5px;
    font-size: 1rem;
    line-height: 1;
    border-radius: 50%;
    border-color: transparent;
    color: #adb5bd;
}

.ingrediente-quitar:hover {
    color: #dc3545;
    border-color: #dc3545;
}

/* Totales */
.productos-totales {
    background: #fff;
    border: 2px solid var(--verde-primario);
    border-radius: 10px;
    padding: 10px 14px;
    margin-top: 8px;
}

.productos-totales .macros {
    justify-content: center;
}

/* Separador con toggle */
.macros-separador {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 14px 0 10px;
}

.macros-separador-linea {
    flex: 1;
    height: 1px;
    background-color: var(--gris-borde);
}

.macros-toggle {
    font-size: 0.72rem;
    padding: 2px 10px;
    border-radius: 12px;
    white-space: nowrap;
}

/* Campos macros manuales */
.macros-manual {
    transition: opacity 0.2s;
}

.macros-manual.macros-collapsed {
    opacity: 0.4;
    pointer-events: none;
}

.macro-input-group {
    display: flex;
    align-items: center;
    gap: 0;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    overflow: hidden;
}

.macro-input-label {
    padding: 4px 8px;
    font-size: 0.72rem;
    font-weight: 700;
    white-space: nowrap;
    margin: 0;
    min-width: 38px;
    text-align: center;
}

.macro-label-kcal { background-color: var(--color-kcal-bg); color: var(--color-kcal); }
.macro-label-prot { background-color: var(--color-prot-bg); color: var(--color-prot); }
.macro-label-carb { background-color: var(--color-carb-bg); color: var(--color-carb); }
.macro-label-gras { background-color: var(--color-gras-bg); color: var(--color-gras); }
.macro-label-fibra { background-color: var(--color-fibra-bg); color: var(--color-fibra); }

.macro-input-group input {
    border: none;
    border-radius: 0;
    font-size: 0.82rem;
    text-align: center;
    padding: 4px 6px;
}

.macro-input-group input:focus {
    box-shadow: none;
    background-color: #f8f9fa;
}

/* Placeholder vacio */
.productos-vacio {
    text-align: center;
    padding: 20px 10px;
    color: #adb5bd;
}

.productos-vacio-icono {
    font-size: 2.5rem;
    margin-bottom: 8px;
    opacity: 0.5;
}

.productos-vacio p {
    font-size: 0.85rem;
    margin-bottom: 4px;
    color: #6c757d;
}

.productos-vacio small {
    font-size: 0.75rem;
}

/* Responsive: en mobile apilar los paneles */
@media (max-width: 991px) {
    .panel-nutricion {
        border-left: none;
        border-top: 1px solid var(--gris-borde);
    }
    .panel-nutricion-inner {
        position: static;
    }
}

/* Detalle productos en modal */
.detalle-productos-lista {
    margin-bottom: 12px;
}

.detalle-producto-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    font-size: 0.9rem;
    border-bottom: 1px solid #f0f0f0;
}

.detalle-producto-item:last-child {
    border-bottom: none;
}

.detalle-producto-kcal {
    font-size: 0.8rem;
    color: var(--color-kcal);
    font-weight: 600;
}

/* ===== Productos (catálogo) ===== */

.table-productos {
    margin-bottom: 0;
}

.table-productos thead th {
    background-color: var(--verde-claro);
    color: var(--verde-oscuro);
    font-size: 0.85rem;
    font-weight: 600;
    border-bottom: 2px solid var(--verde-primario);
    position: sticky;
    top: 0;
}

.producto-row {
    cursor: pointer;
    transition: background-color 0.15s;
}

.producto-row:hover {
    background-color: var(--verde-claro);
}

.producto-row td {
    vertical-align: middle;
    font-size: 0.9rem;
}

.producto-marca {
    font-size: 0.75rem;
    color: #6c757d;
    margin-left: 6px;
}

.producto-cat {
    background-color: #e9ecef;
    color: #495057;
    font-size: 0.7rem;
    font-weight: 500;
    margin-left: 6px;
}

.table-productos .macros span {
    font-size: 0.8rem;
}

/* ===== Offcanvas selector / intercambiar ===== */

#offcanvasSelector,
#offcanvasIntercambiar {
    width: 420px;
    z-index: 1060;
}

@media (max-width: 575px) {
    #offcanvasSelector,
    #offcanvasIntercambiar {
        width: 100%;
    }
}

/* ===== Toast de confirmación ===== */

.toast-copiado {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #333;
    color: #fff;
    padding: 10px 24px;
    border-radius: 8px;
    font-size: 0.9rem;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    z-index: 9999;
    pointer-events: none;
}

.toast-copiado.toast-visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ===== Estilos para imprimir ===== */
@media print {
    /* Ocultar elementos de navegación e interacción */
    .navbar,
    #buscador, #btn-limpiar, #btn-marcar-todas, #btn-imprimir, #info-plan,
    #btn-generar, #btn-historial, #btn-imprimir-plan, #btn-compartir-plan,
    .kcal-input-group {
        display: none !important;
    }

    body {
        background: #fff !important;
        font-size: 11pt;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .container {
        max-width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    /* Título del plan */
    #plan-fecha {
        font-size: 10pt;
        color: #666 !important;
    }

    /* Grid de días: 3 columnas */
    .plan-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 6px !important;
        margin-bottom: 6px !important;
    }

    /* Cards de día */
    .dia-card {
        box-shadow: none !important;
        border: 1px solid #ccc;
        border-radius: 6px !important;
        break-inside: avoid;
        transform: none !important;
    }

    .dia-card-hoy {
        border-color: var(--verde-primario);
    }

    .dia-header {
        padding: 6px 8px !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .dia-header h5 {
        font-size: 0.85rem !important;
    }

    .dia-totales {
        font-size: 0.75rem !important;
    }

    /* Ingestas */
    .ingesta-item {
        padding: 4px 8px !important;
        cursor: default;
    }

    .ingesta-item:hover {
        background-color: transparent !important;
    }

    .ingesta-img {
        width: 30px !important;
        height: 30px !important;
        border-radius: 4px !important;
    }

    .ingesta-info strong {
        font-size: 0.75rem !important;
    }

    .ingesta-header {
        margin-bottom: 3px !important;
    }

    .ingesta-header .badge {
        font-size: 0.6rem !important;
        padding: 1px 5px !important;
    }

    .ingesta-kcal {
        font-size: 0.7rem !important;
    }

    .macros {
        font-size: 0.65rem !important;
        gap: 3px !important;
    }

    .macros span {
        padding: 1px 4px !important;
    }

    /* Lista de la compra */
    .lista-item.checked {
        opacity: 0.4;
    }

    .lista-item {
        padding: 4px 0;
        border-bottom: 1px dotted #ccc;
    }
}

/* ========== Login ========== */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--verde-claro) 0%, var(--gris-fondo) 100%);
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 1rem;
}

.login-card {
    background: #fff;
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 4px 24px rgba(0,0,0,0.1);
}

.login-header {
    text-align: center;
    margin-bottom: 1.5rem;
}

.login-icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.login-header h3 {
    color: var(--verde-oscuro);
    font-weight: 700;
    margin-bottom: 0.25rem;
}

/* ========== Auth navbar ========== */
.auth-nav-right {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

.auth-user-badge {
    background-color: rgba(255,255,255,0.18);
    border: 1px solid rgba(255,255,255,0.3);
    padding: 4px 14px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    color: #fff;
    letter-spacing: 0.3px;
}

.auth-logout-btn {
    color: rgba(255,255,255,0.7);
    font-size: 0.8rem;
    text-decoration: none;
    padding: 4px 10px;
    border-radius: 6px;
    transition: all 0.2s;
}

.auth-logout-btn:hover {
    color: #fff;
    background-color: rgba(255,255,255,0.15);
}

@media (max-width: 991px) {
    .auth-nav-right {
        margin-left: 0;
        margin-top: 10px;
        padding-top: 10px;
        border-top: 1px solid rgba(255,255,255,0.15);
    }
}
