:root {
    --app-bg: #07111a;
    --app-bg-deep: #050b12;
    --app-panel: #0e1a27;
    --app-panel-strong: #112235;
    --app-line: #1d3552;
    --app-line-soft: rgba(255, 255, 255, 0.1);
    --app-text: #eef5ff;
    --app-muted: #9eb4ca;
    --app-accent: #7fd6b5;
    --app-accent-2: #84b8ff;
    --app-danger: #ff8f8f;
    --app-warning: #f5c46a;
    --app-radius: 14px;
    --app-shadow: 0 18px 44px rgba(0, 0, 0, 0.28);
    --app-heading: #f6fbff;
}

*, *::before, *::after { box-sizing: border-box; }

html { min-width: 320px; background: var(--app-bg-deep); }

body {
    color: var(--app-text);
    background: radial-gradient(circle at top, #12304d 0, var(--app-bg) 38%, var(--app-bg-deep) 100%);
    font-family: "Trebuchet MS", "Segoe UI", Tahoma, sans-serif;
    line-height: 1.45;
    overflow-x: hidden;
}

.app-header { width: min(100% - 32px, 1240px); margin: 0 auto; padding: 16px 0 10px; display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.app-brand { display: inline-flex; min-width: 0; align-items: center; gap: 12px; color: var(--app-heading); font-size: 16px; font-weight: 800; text-decoration: none; white-space: nowrap; }
.app-brand img { display: block; width: 210px; height: 58px; object-fit: contain; object-position: left center; }
.app-nav { display: flex; min-width: 0; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.app-nav a { display: inline-flex; min-height: 42px; align-items: center; justify-content: center; padding: 8px 10px; border: 1px solid var(--app-line-soft); border-radius: 9px; color: var(--app-text); background: rgba(255,255,255,.04); font-size: 12px; font-weight: 800; text-decoration: none; }
.app-nav a:hover, .app-nav a:focus-visible, .app-nav a.is-active { border-color: rgba(127,214,181,.6); background: rgba(127,214,181,.16); color: var(--app-accent); }
.app-account { display: inline-flex; align-items: center; gap: 8px; color: var(--app-muted); font-size: 12px; white-space: nowrap; }
.app-account form { display: inline; }
.app-account button { min-height: 36px; padding: 6px 9px; border: 1px solid var(--app-line-soft); border-radius: 8px; background: transparent; color: var(--app-accent-2); cursor: pointer; font: inherit; font-weight: 800; }

/* Legacy page shells keep their content headings, but the shared header owns navigation. */
.top > .nav, .topline .right > a, .nutrition-shell .page-nav, .wrap > .top nav { display: none; }
.topline .right { display: none; }
.wrap > .hero { grid-template-columns: 1fr; }
.wrap .brand-lockup img { display: none; }

a { color: var(--app-accent-2); }
a:hover { color: var(--app-accent); }

h1, h2, h3, p { overflow-wrap: anywhere; }
h1, h2, h3 { line-height: 1.15; }

.wrap, .nutrition-shell {
    width: min(100% - 32px, 1240px);
    margin-inline: auto;
    padding-block: 20px 42px;
}

.card,
.panel,
.meal,
.top,
.hero {
    background: linear-gradient(180deg, rgba(255,255,255,.055), rgba(255,255,255,.02));
    border: 1px solid var(--app-line);
    border-radius: var(--app-radius);
    box-shadow: var(--app-shadow);
}

.pad, .panel, .meal, .search-card, .log-card, .summary-card, .meal-card { padding: 18px; }

.top, .hero { gap: 18px; }
.top { padding: 18px; }
.top h1, .hero-copy h1 { margin-top: 0; }
.brand-lockup { display: flex; min-width: 0; align-items: center; gap: 12px; }
.brand-lockup img { width: 42px; height: 42px; max-width: 42px; flex: 0 0 42px; object-fit: contain; border-radius: 10px; }

.nav, .page-nav, .right, .controls, .actions, .form-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.nav a, .page-nav a {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    padding: 9px 12px;
    border: 1px solid var(--app-line-soft);
    border-radius: 10px;
    color: var(--app-text);
    background: rgba(255,255,255,.045);
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
}

.module-nav, .wrap nav, .nutrition-shell nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.module-nav a, .wrap nav a, .nutrition-shell nav a {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    padding: 9px 12px;
    border: 1px solid var(--app-line-soft);
    border-radius: 10px;
    color: var(--app-text);
    background: rgba(255,255,255,.045);
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
}

.nav a.is-active, .page-nav a.is-active,
.nav a[aria-current="page"], .page-nav a[aria-current="page"],
.module-nav a.is-active, .right a.is-active, .wrap nav a.is-active, .nutrition-shell nav a.is-active,
.module-nav a[aria-current="page"], .right a[aria-current="page"], .wrap nav a[aria-current="page"], .nutrition-shell nav a[aria-current="page"] {
    border-color: rgba(127,214,181,.5);
    background: rgba(127,214,181,.14);
    color: var(--app-accent);
}

label { display: block; color: var(--app-muted); font-size: 13px; font-weight: 700; }

input, select, textarea, button, .btn {
    min-height: 44px;
    border-radius: 10px;
    font: inherit;
    font-size: 16px;
}

.controls input, .controls select, .controls textarea, .meal input, .meal select, .meal textarea {
    font-size: 16px !important;
}

input, select, textarea {
    width: 100%;
    border: 1px solid #284160;
    background: #06101a;
    color: var(--app-text);
    padding: 11px 12px;
}

textarea { min-height: 100px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
    outline: 3px solid rgba(132,184,255,.3);
    outline-offset: 2px;
}

button, .btn { border: 0; padding: 10px 14px; cursor: pointer; font-weight: 800; }
.btn.primary, button.primary, .primary-btn, .controls button, .meal button { background: linear-gradient(135deg, var(--app-accent), #4f8edf); color: #05111a; }
.btn.secondary, .secondary-btn { background: #11263a; color: var(--app-text); border: 1px solid var(--app-line); }
.btn.danger, .danger-btn { background: linear-gradient(135deg, #ff8d8d, #ff5f5f); color: #220505; }

.grid, .section-grid, .dashboard-grid { gap: 16px; }
.stats, .summary-grid, .target-grid { gap: 10px; }
.stat, .tile, .summary-pill, .target-card, .total {
    min-width: 0;
    border: 1px solid rgba(255,255,255,.08);
    border-radius: 12px;
    background: rgba(255,255,255,.045);
}
.stat, .tile, .summary-pill, .target-card, .total { padding: 12px; }
.stat .k, .tile .k { color: var(--app-muted); }
.stat .v, .tile .v, .summary-pill strong, .total b { overflow-wrap: anywhere; }

.alert, .notice, .error, .status-message {
    border-radius: 10px;
    border: 1px solid rgba(255,141,141,.35);
    background: rgba(255,141,141,.08);
    color: #ffd0d0;
    padding: 11px 13px;
}
.success, .notice.success { border-color: rgba(126,224,184,.35); background: rgba(126,224,184,.08); color: #cbffe7; }

.table-wrap { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--app-line-soft); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px; border-bottom: 1px solid rgba(255,255,255,.07); text-align: left; vertical-align: top; }
th { background: #081521; color: var(--app-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; }

.nutrition-shell .hero { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(250px, .7fr); padding: 20px; }
.nutrition-shell .dashboard-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 16px; }
.nutrition-shell .search-card, .nutrition-shell .summary-card, .nutrition-shell .log-card { grid-column: 1 / -1; }
.nutrition-shell .page-nav { margin-top: 18px; }
.nutrition-shell .page-nav a { min-height: 44px; }
.nutrition-shell .field-grid, .nutrition-shell .search-filters { gap: 12px; }
.nutrition-shell .summary-pill { background: rgba(127,214,181,.08); }

/* Today is intentionally denser and more thumb-friendly than the review pages. */
.nutrition-shell .meal { display: flex; flex-direction: column; min-height: 100%; }
.nutrition-shell .meal form { margin-top: auto; }
.nutrition-shell .meal button { width: 100%; }

.library-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.library-tab {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    padding: 9px 14px;
    border: 1px solid var(--app-line);
    border-radius: 10px;
    color: var(--app-text);
    background: rgba(255,255,255,.045);
    font-weight: 800;
    text-decoration: none;
}

.library-tab.is-active {
    border-color: rgba(127,214,181,.55);
    background: rgba(127,214,181,.16);
    color: var(--app-accent);
}

.library-card .serving-description {
    min-height: 2.9em;
    color: var(--app-text);
}

.library-card form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr);
    gap: 8px;
    margin-top: auto;
}

.library-card form button { grid-column: 1 / -1; }

.quick-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.quick-actions .btn { min-height: 44px; text-decoration: none; }
.photo-upload { margin-top: 18px; }
.photo-upload .btn, .screenshot-confirm .btn, .photo-cancel .btn { margin-top: 12px; }
.screenshot-confirm { margin-top: 16px; padding: 16px; border: 1px solid var(--app-line-soft); border-radius: 14px; background: rgba(255,255,255,.025); }
.screenshot-confirm h2 { margin: 0 0 6px; }
.photo-cancel { margin-top: 8px; }
.bp-import-rows { display: grid; gap: 12px; }
.bp-import-row { padding: 12px; border: 1px solid var(--app-line-soft); border-radius: 12px; background: rgba(0,0,0,.12); }
.bp-import-row-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.bp-import-row-grid { display: grid; grid-template-columns: repeat(6,minmax(90px,1fr)); gap: 8px; }
.bp-import-row-grid .bp-note { grid-column: 1 / -1; }
.bp-import-row-grid input, .bp-import-row-grid select, .bp-import-row-grid textarea { width: 100%; min-width: 0; }
@media (max-width: 700px) { .bp-import-row-grid { grid-template-columns: repeat(2,minmax(0,1fr)); } }
.dashboard-alerts { margin-top: 14px; }
.alert-list { display: grid; gap: 8px; }

.serving-choices { display: flex; flex-wrap: wrap; gap: 5px; grid-column: 1 / -1; }
.serving-choices button { flex: 0 0 44px; min-height: 44px; padding: 6px 4px; border: 1px solid var(--app-line); background: #11263a; color: var(--app-text); }
.serving-choices button:hover, .serving-choices button:focus-visible, .serving-choices button.is-selected { border-color: var(--app-accent); background: rgba(127,214,181,.22); color: var(--app-accent); box-shadow: inset 0 0 0 1px var(--app-accent); }
.add-serving-button { grid-column: 1 / -1; }

@media (max-width: 900px) {
    .nutrition-shell .hero { grid-template-columns: 1fr; }
    .nutrition-shell .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
    .app-header { width: min(100% - 20px, 1240px); align-items: flex-start; }
    .app-brand span { display: none; }
    .app-brand img { width: 42px; height: 42px; }
    .app-nav { justify-content: flex-start; }
    .app-nav a { min-height: 44px; padding-inline: 9px; }
    .wrap, .nutrition-shell { width: min(100% - 20px, 1240px); padding-block: 10px 28px; }
    .top, .hero, .pad, .panel, .meal, .search-card, .log-card, .summary-card, .meal-card { padding: 14px; }
    .top, .hero { display: block; }
    .top .nav, .hero .page-nav { margin-top: 14px; }
    .nav a, .page-nav a, .right a, .module-nav a, .wrap nav a, .nutrition-shell nav a { flex: 1 1 calc(50% - 8px); text-align: center; }
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
    .row, .field-grid, .search-filters, .meal form, .library-card form { grid-template-columns: 1fr !important; }
    .search-row { grid-template-columns: 1fr !important; }
    .search-row button, .controls button { width: 100%; }
    .controls > * { flex: 1 1 100%; }
    .controls label { flex-basis: 100%; }
    .section-head { align-items: flex-start; flex-direction: column; }
    .table-wrap table { min-width: 680px; }
    .nutrition-shell .meal { min-height: 0; }
    .nutrition-shell .entry { display: block; }
    .nutrition-shell .entry form { margin-top: 10px; }
    .dashboard-page .grid,
    .dashboard-page .section-grid { grid-template-columns: minmax(0, 1fr) !important; min-width: 0; }
    .dashboard-page .card.pad,
    .dashboard-page .grid,
    .dashboard-page .section-grid { max-width: 100%; }
    .wrap > .card, .wrap > .card > *, .wrap .table-wrap { width: 100%; max-width: 100%; min-width: 0; }
}

@media (min-width: 601px) and (max-width: 900px) {
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
}

@media (max-width: 767px) {
    .nutrition-shell,
    .nutrition-shell main,
    .nutrition-shell section,
    .nutrition-shell article,
    .nutrition-shell .dashboard-grid,
    .nutrition-shell .summary-grid,
    .nutrition-shell .target-grid,
    .nutrition-shell .meal-groups,
    .nutrition-shell .table-wrap {
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }
    .nutrition-shell .dashboard-grid,
    .nutrition-shell .summary-grid,
    .nutrition-shell .target-grid { grid-template-columns: minmax(0, 1fr) !important; }
    .nutrition-shell .table-wrap { overflow-x: auto; }
    .nutrition-shell table { min-width: 680px; }
}
