@import url("https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100..900;1,100..900&display=swap");

:root {
    --color-bg: #f4f7fc;
    --color-bg2: #eef4ff;
    --color-surface: #ffffff;
    --color-primary: #2563eb;
    --color-primary-soft: #e0ecff;
    --color-success: #22c55e;
    --color-danger: #ef4444;
    --color-warning: #f59e0b;
    --color-info: #0ea5e9;
    --color-border: #e2e8f0;
    --color-text: #111827;
    --color-muted: #6b7280;
    --radius-lg: 15px;
    --radius-md: 10px;
    --shadow-sm: 0 2px 6px rgba(15, 23, 42, 0.12);
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
}

body {
    background: var(--color-bg);
    font-family: "Montserrat", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    min-height: 100vh;
    padding: 28px 0 44px;
    color: var(--color-text);
}

/* Layout base tipo "Bootstrap" simplificado */
.container-fluid {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 16px;
}

.row {
    display: flex;
    flex-wrap: wrap;
    margin: 0 -8px;
}

[class^="col-"],
[class*=" col-"] {
    padding: 0 8px;
}

.col-12 {
    flex: 0 0 100%;
    max-width: 100%;
}

.col-6 {
    flex: 0 0 50%;
    max-width: 50%;
}

.col-md-2,
.col-md-3,
.col-md-4,
.col-md-7 {
    flex: 0 0 100%;
    max-width: 100%;
}

.col-lg-4,
.col-lg-8 {
    flex: 0 0 100%;
    max-width: 100%;
}

@media (min-width: 768px) {
    .col-md-2 { flex: 0 0 16.666%; max-width: 16.666%; }
    .col-md-3 { flex: 0 0 25%; max-width: 25%; }
    .col-md-4 { flex: 0 0 33.333%; max-width: 33.333%; }
    .col-md-7 { flex: 0 0 58.333%; max-width: 58.333%; }
}

@media (min-width: 992px) {
    .col-lg-4 { flex: 0 0 33.333%; max-width: 33.333%; }
    .col-lg-8 { flex: 0 0 66.666%; max-width: 66.666%; }
}

/* Espaciados utilitarios */
.mb-0 { margin-bottom: 0 !important; }
.mb-2 { margin-bottom: 0.5rem !important; }
.mb-3 { margin-bottom: 1rem !important; }
.mb-4 { margin-bottom: 1.5rem !important; }
.mt-1 { margin-top: 0.25rem !important; }
.mt-2 { margin-top: 0.5rem !important; }
.py-4 { padding-top: 1.5rem; padding-bottom: 1.5rem; }

.w-100 { width: 100%; }
.hidden { display: none !important; }
.d-flex { display: flex; }
.justify-content-between { justify-content: space-between; }
.align-items-center { align-items: center; }
.align-items-end { align-items: flex-end; }
.text-center { text-align: center; }
.text-white { color: #ffffff; }
.text-dark { color: #111827; }
.text-muted { color: var(--color-muted); }

/* Tarjetas */
.card {
    border-radius: 16px;
    border: 1px solid #e8edf5;
    background: var(--color-surface);
    box-shadow: 0 4px 16px rgba(15, 23, 42, 0.06);
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.card:hover {
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

.card-header {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 1rem 1.25rem;
    font-weight: 600;
}

.card-body {
    padding: 1.25rem;
}

.shadow-sm { box-shadow: var(--shadow-sm); }

.bg-primary { background-color: var(--color-primary); }
.bg-success { background-color: var(--color-success); }
.bg-dark { background-color: #111827; }
.bg-info { background-color: var(--color-info); }
.bg-light { background-color: #f9fafb; }
.bg-danger { background-color: var(--color-danger); }
.bg-warning { background-color: var(--color-warning); }

.card-title {
    color: #0f172a;
    font-weight: 700;
    letter-spacing: 0.02em;
}

/* Formularios */
.form-label {
    display: block;
    margin-bottom: 0.25rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-muted);
}

.form-select,
.form-control {
    width: 100%;
    border-radius: 8px;
    border: 1px solid var(--color-border);
    padding: 0.65rem 0.75rem;
    font-size: 0.95rem;
    background-color: #ffffff;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.form-control-lg {
    padding: 0.8rem 0.9rem;
    font-size: 1rem;
}

.form-select:focus,
.form-control:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.25);
}

.input-group {
    display: flex;
    align-items: stretch;
    width: 100%;
}

.input-group-text {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 0.75rem;
    background-color: #f3f4f6;
    border: 1px solid var(--color-border);
    border-right: none;
    border-radius: 8px 0 0 8px;
    color: var(--color-muted);
}

.input-group .form-control {
    border-radius: 0 8px 8px 0;
}

small {
    font-size: 0.8rem;
}

/* Botones */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    border-radius: 8px;
    font-weight: 500;
    border: 1px solid transparent;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease, border-color 0.2s ease;
    background-color: #e5e7eb;
    color: #111827;
}

.btn:hover {
    /*transform: translateY(-1px);*/
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.15);
}

.btn-success {
    background-color: var(--color-success);
    border-color: var(--color-success);
    color: #ffffff;
}

.btn-success:hover {
    background-color: #16a34a;
}

.btn-danger {
    background-color: var(--color-danger);
    border-color: var(--color-danger);
    color: #ffffff;
}

.btn-danger:hover {
    background-color: #dc2626;
}

.btn-outline-secondary {
    background-color: transparent;
    border-color: #9ca3af;
    color: #111827;
}

.btn-outline-secondary:hover {
    background-color: #e5e7eb;
}

.btn-delete {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
}

.btn-delete:hover {
    transform: scale(1.05) !important;
    background-color: var(--color-danger) !important;
    color: #ffffff !important;
}

/* Alerts */
.alert {
    border-radius: var(--radius-md);
    border: none;
    padding: 0.75rem 0.9rem;
    background-color: #f9fafb;
}

.alert-info {
    background-color: #ecfeff;
    color: #075985;
}

.alert-light {
    background-color: #f9fafb;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
    font-weight: 600;
}

/* Progreso */
.progress {
    width: 100%;
    border-radius: 999px;
    background-color: #e5e7eb;
    overflow: hidden;
    box-shadow: inset 0 1px 3px rgba(15, 23, 42, 0.1);
}

.progress.small { height: 8px; }
.progress.large { height: 30px; }

.progress-bar {
    height: 100%;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.8rem;
    color: #ffffff;
    background: linear-gradient(90deg, #22c55e, #16a34a);
    transition: width 0.4s ease, background-color 0.4s ease;
    position: relative;
}

.progress-bar.bg-danger {
    background: linear-gradient(90deg, #ef4444, #b91c1c);
}

.progress-bar.bg-warning {
    background: linear-gradient(90deg, #facc15, #eab308);
    color: #1f2937;
}

.progress-bar.bg-success {
    background: linear-gradient(90deg, #22c55e, #16a34a);
}

/* Tabla */
.table-responsive {
    width: 100%;
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.table thead th {
    border-bottom: 2px solid var(--color-border);
    font-weight: 600;
    color: #4b5563;
    background-color: #f9fafb;
    padding: 0.75rem;
    text-align: left;
}

.table tbody td {
    vertical-align: middle;
    padding: 0.75rem;
    border-bottom: 1px solid #e5e7eb;
}

.table-hover tbody tr:hover {
    background-color: #f3f4f6;
}

.table-primary {
    background-color: var(--color-primary-soft);
}

/* Iconos de valor biológico */
.valor-icono {
    font-size: 2rem;
    margin-bottom: 4px;
}

/* Utilidades varias */
.fa-star { margin-right: 3px; }

.optgroup-label {
    font-weight: 700;
    color: #4b5563;
    background-color: #f3f4f6;
    padding: 4px 6px;
    border-radius: 5px;
}

/* Animaciones */
@keyframes slideIn {
    from { opacity: 0; transform: translateX(-30px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

@keyframes slideInRight {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.animate-add { animation: slideIn 0.4s ease; }
.animate-fade { animation: slideInRight 0.3s ease; }

.progress-bar.bg-success {
    animation: pulse 2s infinite;
}

.alert-dismissible {
    animation: slideInRight 0.3s ease;
}

/* Responsive ajustes finos */
@media (max-width: 768px) {
    .card-body {
        padding: 1rem;
    }

    .table {
        font-size: 0.85rem;
    }

    .btn {
        font-size: 0.85rem;
        padding: 0.45rem 0.9rem;
    }

    #consumoActual {
        font-size: 1.6rem;
    }
}

/* Diseño de aplicación nutricional */
.app-hero {
    display: grid;
    grid-template-columns: 180px minmax(0, 1fr) 180px;
    align-items: center;
    gap: 18px;
    padding: 18px 22px;
    border-left: 4px solid var(--color-primary);
}

.app-logo {
    width: 150px;
    height: 120px;
    object-fit: contain;
    background: #fff;
    border-radius: 16px;
    padding: 10px;
    box-shadow: 0 7px 18px rgba(37, 99, 235, 0.16);
}

.eyebrow { color: var(--color-primary); font-size: .72rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; }
.app-hero > div { grid-column: 2; text-align: center; }
.app-hero::after { content: ''; grid-column: 3; grid-row: 1; }
.app-hero h1 { margin: 3px 0; font-size: 1.75rem; color: var(--color-text); letter-spacing: -.03em; }
.app-hero p { margin: 0; color: var(--color-muted); font-size: .95rem; }

.daily-limit-card { border-left: 4px solid var(--color-primary); }
.daily-limit-content { display: flex; align-items: end; justify-content: space-between; gap: 24px; }
.daily-limit-content .section-heading { margin-bottom: 0; flex: 1; }
.daily-limit-field { width: min(100%, 270px); flex: 0 0 270px; }
.section-heading { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.section-heading h5 { color: var(--color-text); font-size: 1rem; }
.section-heading p { margin: 3px 0 0; color: var(--color-muted); font-size: .78rem; }
.section-icon { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; }
.section-icon-primary { color: var(--color-primary); background: #e8f0ff; }
.limit-input-wrap { position: relative; }
.limit-input-wrap .form-control { padding-right: 42px; font-weight: 700; color: var(--color-text); }
.limit-input-wrap span { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--color-muted); font-weight: 600; }

.panel-header-primary { background: #2563eb; color: #fff; }
.panel-header-success { background: #22c55e; color: #fff; }
.panel-header-dark { background: #111827; color: #fff; }
.panel-header-primary h5, .panel-header-success h5, .panel-header-dark h5 { font-size: .96rem; }

.compact-filters {
    display: grid;
    grid-template-columns: minmax(160px, 1.4fr) minmax(130px, 1fr) minmax(120px, 1fr) 36px;
    gap: 8px;
    align-items: center;
    padding: 10px;
    margin-bottom: 18px;
    border: 1px solid #e8edf5;
    border-radius: 12px;
    background: #f8faff;
}

.compact-filters .filter-control, .filter-field {
    height: 36px;
    min-width: 0;
    border: 1px solid #dbe4f0;
    border-radius: 8px;
    background: #fff;
    color: #475569;
    font: inherit;
    font-size: .79rem;
}
.compact-filters .filter-control {
    appearance: auto;
    padding: 0 9px;
    cursor: pointer;
}
.filter-field { display: flex; align-items: center; gap: 7px; padding: 0 10px; }
.filter-field i { color: #94a3b8; font-size: .78rem; }
.filter-field input { min-width: 0; width: 100%; border: 0; outline: 0; background: transparent; color: var(--color-text); font: inherit; font-size: .79rem; }
.btn-filter-reset { width: 36px; height: 36px; padding: 0; color: #64748b; background: #fff; border-color: #dbe4f0; }
.btn-filter-reset:hover { color: var(--color-primary); border-color: var(--color-primary); background: #eff6ff; }

.alert-info { background: #f0f7ff; color: #1e3a5f; border: 1px solid #dbeafe; }
.form-label { color: #475569; }
.form-select, .form-control { border-color: #dbe4f0; }
.form-select:focus, .form-control:focus { border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.progress { background: #e8edf5; }
.table thead th { background: #f8faff; color: #64748b; font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; }

@media (max-width: 768px) {
    .compact-filters { grid-template-columns: 1fr 1fr 36px; }
    .filter-search { grid-column: 1 / -1; }
    .app-hero h1 { font-size: 1.28rem; }
}

@media (max-width: 430px) {
    .compact-filters { grid-template-columns: 1fr 36px; }
    .compact-filters .filter-control { grid-column: span 1; }
}

/* Ajustes de flujo para tabletas y móviles */
@media (max-width: 991px) {
    body { padding: 20px 0 32px; }
    .container-fluid { max-width: 760px; }
    .col-lg-4, .col-lg-8 { flex: 0 0 100%; max-width: 100%; }
    .daily-limit-content { align-items: center; }
}

@media (max-width: 767px) {
    .container-fluid { padding: 0 12px; }
    .row { margin: 0 -6px; }
    [class^="col-"], [class*=" col-"] { padding: 0 6px; }
    .app-hero { display: flex; gap: 12px; padding: 15px; }
    .app-logo { width: 64px; height: 64px; border-radius: 12px; }
    .app-hero > div { text-align: left; }
    .app-hero h1 { font-size: 1.2rem; }
    .app-hero p { font-size: .79rem; line-height: 1.4; }
    .card-header { padding: .85rem 1rem; }
    .card-body { padding: 1rem; }
    .daily-limit-content { display: block; }
    .daily-limit-content .section-heading { margin-bottom: 14px; }
    .daily-limit-field { width: 100%; }
    .compact-filters { grid-template-columns: 1fr 1fr 36px; padding: 8px; gap: 7px; }
    .filter-search { grid-column: 1 / -1; }
    .compact-filters .filter-control { height: 38px; font-size: .76rem; }
    .filter-field { height: 38px; }
    .table thead th, .table tbody td { padding: .65rem .5rem; }
}

@media (max-width: 480px) {
    .app-hero { align-items: flex-start; }
    .eyebrow { font-size: .65rem; }
    .daily-limit-card { margin-bottom: 1rem !important; }
    .compact-filters { grid-template-columns: 1fr 36px; }
    .filter-search { grid-column: 1 / -1; }
    .compact-filters .filter-control { grid-column: 1 / 2; }
    .btn-filter-reset { grid-column: 2 / 3; }
    .col-6 { flex: 0 0 50%; max-width: 50%; }
    .table { min-width: 620px; }
    .table-responsive { margin: 0 -1rem; width: calc(100% + 2rem); padding: 0 1rem; }
}

/* En móvil, el registro de alimentos se muestra antes del resumen. */
@media (max-width: 767px) {
    .col-lg-8 { order: 1; }
    .col-lg-4 { order: 2; }
    .col-lg-4 .card { height: auto !important; }
}

/* Tabla de alimentos como tarjetas: legible y sin desplazamiento horizontal. */
@media (max-width: 600px) {
    .table-responsive {
        width: 100%;
        margin: 0;
        padding: 0;
        overflow: visible;
    }

    .table { min-width: 0; display: block; }
    .table thead { display: none; }
    .table tbody, .table tfoot { display: block; }

    .table tbody tr {
        display: grid;
        grid-template-columns: 1fr auto;
        gap: 2px 12px;
        margin-bottom: 10px;
        padding: 10px 12px;
        border: 1px solid #e5ebf4;
        border-radius: 10px;
        background: #fff;
        box-shadow: 0 2px 6px rgba(15, 23, 42, .04);
    }

    .table tbody td {
        display: block;
        padding: 3px 0;
        border: 0;
        font-size: .82rem;
    }

    .table tbody td:first-child { grid-column: 1 / -1; padding-bottom: 5px; }
    .table tbody td:nth-child(2)::before { content: 'Cantidad: '; color: #64748b; }
    .table tbody td:nth-child(3)::before { content: 'Proteína: '; color: #64748b; }
    .table tbody td:nth-child(4) { grid-column: 1 / 2; }
    .table tbody td:nth-child(5) { grid-column: 2 / 3; text-align: right; }

    .table tbody td[colspan] { grid-column: 1 / -1; text-align: center; padding: 16px 0; }

    .table tfoot tr {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 4px 10px;
        padding: 11px 12px;
        border-radius: 10px;
    }

    .table tfoot th { display: block; padding: 0; border: 0; }
    .table tfoot th:first-child { flex: 1 0 100%; font-size: .75rem; }
    .table tfoot th:nth-child(2) { flex: 1; }
    .table tfoot th:last-child { margin-left: auto; }
}
