/* ═══════════════════════════════════════════════════════
   OpenCalorieTracker – Dark Theme Stylesheet
   ═══════════════════════════════════════════════════════ */

/* ── Variables ──────────────────────────────────────── */
:root {
    --bg:           #0d1117;
    --surface:      #161b22;
    --card:         #1c2128;
    --card-hover:   #22272e;
    --border:       #30363d;
    --primary:      #58a6ff;
    --primary-hover:#79b8ff;
    --success:      #3fb950;
    --warning:      #d29922;
    --danger:       #f85149;
    --danger-hover: #ff6e6e;
    --text:         #c9d1d9;
    --text-muted:   #8b949e;
    --text-bright:  #f0f6fc;
    --radius:       8px;
    --radius-lg:    12px;
    --shadow:       0 2px 8px rgba(0,0,0,.3);
    --transition:   .2s ease;

    /* macro colours */
    --cal-color:    #ff9800;
    --fat-color:    #f44336;
    --carb-color:   #42a5f5;
    --prot-color:   #66bb6a;
    --salt-color:   #ab47bc;
    --tef-color:    #26c6da;
}

/* ── Light theme variable overrides ────────────────── */
[data-theme="light"] {
    --bg:           #f6f8fa;
    --surface:      #ffffff;
    --card:         #ffffff;
    --card-hover:   #f3f4f6;
    --border:       #d0d7de;
    --primary:      #0969da;
    --primary-hover:#0550ae;
    --success:      #2da44e;
    --warning:      #9a6700;
    --danger:       #cf222e;
    --danger-hover: #a40e26;
    --text:         #24292f;
    --text-muted:   #57606a;
    --text-bright:  #000000;
    --shadow:       0 2px 8px rgba(0,0,0,.12);
    --tef-color:    #00838f;
}

/* ── Reset ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; overflow-x: hidden; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }
input, select, button, textarea { font-family: inherit; font-size: inherit; }
table { border-collapse: collapse; width: 100%; }

/* ── Loading spinner ────────────────────────────────── */
.app-loading {
    position: fixed; inset: 0; z-index: 9999;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg);
}
.spinner {
    width: 40px; height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Utility ────────────────────────────────────────── */
.hidden { display: none !important; }
.view   { display: none; }
.view:not(.hidden) { display: block; }

/* ── Buttons ────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 500;
    transition: background var(--transition), border-color var(--transition), color var(--transition);
    background: var(--card);
    color: var(--text);
    white-space: nowrap;
}
.btn:hover { background: var(--card-hover); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary   { background: var(--primary); color: #000; border-color: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-secondary { background: var(--surface); border-color: var(--border); }
.btn-secondary:hover { background: var(--card); }
.btn-outline   { background: transparent; border-color: var(--border); color: var(--text-muted); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-danger    { background: transparent; color: var(--danger); }
.btn-danger:hover { background: rgba(248,81,73,.12); }
.btn-success   { background: transparent; color: var(--success); }
.btn-success:hover { background: rgba(35,197,94,.12); }
.btn-icon {
    padding: 6px 10px; background: transparent; border: none;
    color: var(--text-muted); font-size: 1rem;
}
.btn-icon:hover { color: var(--text-bright); }
.btn-sm  { padding: 5px 12px; font-size: .85rem; }
.btn-block { width: 100%; justify-content: center; }

/* ── Cards ──────────────────────────────────────────── */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}
.card h3 {
    font-size: 1rem; font-weight: 600;
    margin-bottom: 14px; color: var(--text-bright);
    display: flex; align-items: center; gap: 8px;
}
.card-header-row {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 14px;
}
.card-header-row h3 { margin-bottom: 0; }

/* ── Forms ──────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.form-group.flex-2 { flex: 2; }
.form-group label {
    font-size: .82rem; font-weight: 500; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: .4px;
}
.form-group input,
.form-group select,
.form-group textarea {
    padding: 9px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    transition: border-color var(--transition);
    width: 100%;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
}
.form-group textarea {
    resize: vertical;
    min-height: 72px;
    line-height: 1.5;
}
.form-row {
    display: flex; gap: 14px; margin-bottom: 14px; flex-wrap: wrap;
}
.form-row .form-group { min-width: 140px; }
.form-actions {
    display: flex; gap: 10px; margin-top: 8px; padding-top: 14px;
    border-top: 1px solid var(--border);
}
.form-actions-inline {
    display: flex; gap: 10px; margin-top: 10px; margin-bottom: 18px;
}
.error-text { margin-top: 12px; color: #ff6b6b; font-size: .9rem; }
.form-hint { color: var(--text-muted); font-size: .78rem; }
.form-hint-warning { color: var(--warning, #f59e0b); }
.form-card { border-color: var(--primary); border-style: dashed; }

/* ── Food form redesign ──────────────────────────────── */
.food-form-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 16px;
}
.food-form-header h3 { margin: 0; font-size: 1.1rem; color: var(--text-bright); }
.form-close-btn { opacity: .55; }
.form-close-btn:hover { opacity: 1; color: var(--danger); }

/* ── AI scan banner ─────────────────────────────────── */
.scan-label-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    margin-bottom: 20px;
    background: color-mix(in srgb, var(--primary) 8%, var(--card-hover));
    border: 1px dashed color-mix(in srgb, var(--primary) 40%, var(--border));
    border-radius: var(--radius);
    flex-wrap: wrap;
}
.scan-label-desc {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: .88rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 2px;
}
.scan-label-desc-icon {
    color: var(--primary);
    font-size: .85rem;
    opacity: .85;
}
.scan-label-hint {
    font-size: .8rem;
    color: var(--text-muted);
    opacity: .75;
    width: 100%;
    margin-top: 2px;
}
/* Camera button: visible only on touch/mobile devices */
.scan-camera-btn { display: none; }
@media (hover: none) and (pointer: coarse) {
    .scan-camera-btn { display: inline-flex; }
}

/* ── Scan label / AI photo button ───────────────────── */
.btn-scan-label {
    display: inline-flex; align-items: center; gap: 8px;
    font-size: .92rem; padding: 8px 16px;
    background: var(--primary); color: #fff; border: none;
    border-radius: var(--radius); cursor: pointer; font-weight: 500;
    white-space: nowrap;
}
.btn-scan-label:hover:not(:disabled) { filter: brightness(1.12); }
.btn-scan-label:disabled {
    opacity: .38; cursor: not-allowed; background: var(--bg-alt);
    color: var(--text-muted); border: 1px solid var(--border);
}
.btn-scan-label.scanning {
    pointer-events: none;
}
.scan-label-spinner {
    display: inline-block;
    width: 13px; height: 13px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    flex-shrink: 0;
}
.scan-label-spinner.hidden { display: none; }

/* ── Scan status bar ─────────────────────────────────── */
.scan-label-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    background: color-mix(in srgb, var(--primary) 8%, var(--card-hover));
    border: 1px solid color-mix(in srgb, var(--primary) 25%, var(--border));
    border-radius: var(--radius);
    font-size: .82rem;
    color: var(--text-muted);
    margin-bottom: 14px;
}
.scan-label-status .fa-circle-notch {
    color: var(--primary);
    font-size: .88rem;
    flex-shrink: 0;
}
.scan-label-status.hidden { display: none; }
.scan-label-status.success {
    background: color-mix(in srgb, var(--success) 10%, var(--card-hover));
    border-color: color-mix(in srgb, var(--success) 35%, var(--border));
    color: var(--success);
}
.scan-label-status.error {
    background: color-mix(in srgb, var(--danger) 10%, var(--card-hover));
    border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
    color: var(--danger);
}
.scan-label-status.warning {
    background: color-mix(in srgb, var(--warning) 10%, var(--card-hover));
    border-color: color-mix(in srgb, var(--warning) 35%, var(--border));
    color: var(--warning);
}

/* ── AI debug panel ──────────────────────────────────── */
.scan-debug-panel {
    margin-bottom: 14px;
    border: 1px solid color-mix(in srgb, var(--warning) 40%, var(--border));
    border-radius: var(--radius);
    font-size: .78rem;
    overflow: hidden;
}
.scan-debug-panel.hidden { display: none; }
.scan-debug-panel summary {
    padding: 6px 12px;
    background: color-mix(in srgb, var(--warning) 12%, var(--card-hover));
    color: var(--warning);
    cursor: pointer;
    font-weight: 600;
    user-select: none;
}
.scan-debug-panel summary:hover { filter: brightness(1.1); }
.scan-debug-panel pre {
    margin: 0;
    padding: 10px 14px;
    background: var(--bg-alt);
    color: var(--text-muted);
    font-size: .78rem;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 320px;
    overflow-y: auto;
}

.form-icon { font-size: .75rem; opacity: .6; margin-right: 3px; }
.sub-icon { font-size: .7rem; opacity: .5; margin-right: 2px; transform: rotate(90deg); }

.form-section-label {
    font-size: .78rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: .6px; color: var(--text-muted);
    margin: 4px 0 12px;
    display: flex; align-items: center; gap: 6px;
}
.form-section-label::before, .form-section-label::after {
    content: ''; flex: 1; height: 1px; background: var(--border);
}

.input-with-unit {
    display: flex; align-items: stretch;
}
.input-with-unit input {
    border-top-right-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
    flex: 1; min-width: 0;
}
.unit-badge {
    background: var(--surface);
    border: 1px solid var(--border); border-left: none;
    border-top-right-radius: var(--radius); border-bottom-right-radius: var(--radius);
    padding: 0 10px; font-size: .78rem; font-weight: 600;
    color: var(--text-muted); display: flex; align-items: center;
    white-space: nowrap;
}

/* Macro row color accents on labels */
.macro-row { margin-bottom: 10px; }
.macro-group label { font-size: .76rem; }
.macro-cal  label { color: var(--cal-color) !important; }
.macro-fat  label { color: var(--fat-color) !important; }
.macro-prot label { color: var(--prot-color) !important; }
.macro-salt label { color: var(--salt-color) !important; }
.macro-carb label { color: var(--carb-color) !important; }
.macro-sugar label, .macro-starch label { color: var(--text-muted) !important; }
.macro-group { min-width: 110px !important; }

.form-select { cursor: pointer; }

/* ── Fruit/Veg summary bar ─────────────────────────── */
.fruit-veg-bar {
    display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
    margin-top: 12px; padding: 10px 14px;
    background: rgba(102,187,106,.07);
    border-radius: var(--radius); border-left: 3px solid #66bb6a;
    font-size: .88rem;
}
[data-theme="light"] .fruit-veg-bar { background: rgba(56,142,60,.07); border-left-color: #388e3c; }
.fruit-veg-bar .fv-label {
    font-weight: 600; color: var(--text-muted); font-size: .78rem;
    text-transform: uppercase; letter-spacing: .4px;
}
.fv-item {
    display: flex; align-items: center; gap: 6px;
}
.fv-icon { font-size: 1rem; }
.fv-item .fv-val { font-weight: 700; font-size: 1.05rem; color: var(--text-bright); }
.fv-item .fv-unit { color: var(--text-muted); font-size: .82rem; }
.fv-divider { width: 1px; height: 20px; background: var(--border); }

/* ── Category badge (foods list) ────────────────────── */
.cat-badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 8px; border-radius: 9999px;
    font-size: .72rem; font-weight: 600; line-height: 1.6;
    background: var(--surface); border: 1px solid var(--border);
    color: var(--text-muted); white-space: nowrap;
}
.cat-badge.fruit     { border-color: #fb8c00; color: #fb8c00; background: rgba(251,140,0,.1); }
.cat-badge.vegetable { border-color: #66bb6a; color: #66bb6a; background: rgba(102,187,106,.1); }
.cat-badge.meat      { border-color: #ef5350; color: #ef5350; background: rgba(239,83,80,.1); }
.cat-badge.fish      { border-color: #29b6f6; color: #29b6f6; background: rgba(41,182,246,.1); }
.cat-badge.dairy     { border-color: #ce93d8; color: #ce93d8; background: rgba(206,147,216,.1); }
.cat-badge.egg       { border-color: #ffe082; color: #ffe082; background: rgba(255,224,130,.1); }
.cat-badge.grain     { border-color: #d4a017; color: #d4a017; background: rgba(212,160,23,.1); }
.cat-badge.legume    { border-color: #a5d6a7; color: #a5d6a7; background: rgba(165,214,167,.1); }
.cat-badge.nut       { border-color: #a1887f; color: #a1887f; background: rgba(161,136,127,.1); }
.cat-badge.oil       { border-color: #fff176; color: #aaa000; background: rgba(255,241,118,.08); }
.cat-badge.drink     { border-color: #4dd0e1; color: #4dd0e1; background: rgba(77,208,225,.1); }
.sys-badge {
    display: inline-flex; align-items: center; gap: 3px;
    padding: 1px 6px; border-radius: 9999px;
    font-size: .68rem; font-weight: 700; letter-spacing: .3px;
    background: rgba(102,187,106,.15); border: 1px solid #66bb6a; color: #66bb6a;
}

.section-title {
    font-size: .95rem; font-weight: 600; color: var(--text-muted);
    margin: 20px 0 10px; padding-top: 14px; border-top: 1px solid var(--border);
}
.info-box {
    display: flex; gap: 8px; align-items: flex-start;
    padding: 10px 12px;
    background: rgba(59,130,246,.08); border-left: 3px solid var(--primary);
    border-radius: var(--radius); font-size: .8rem; color: var(--text-muted);
    line-height: 1.5;
}
.info-box i { color: var(--primary); margin-top: 2px; flex-shrink: 0; }
[data-theme="light"] .info-box { background: rgba(59,130,246,.07); }

.field-hint { display: block; font-size: .75rem; color: var(--text-muted); margin-top: 2px; }
.checkbox-label { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: .9rem; padding-top: 24px; }
.checkbox-label input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }

/* ── TEF Panel (Profile Settings) ───────────────────── */
.tef-master-row {
    margin: 0 0 14px;
}
.tef-master-row .tef-toggle-label { font-size: .92rem; font-weight: 500; }
.tef-master-row .tef-toggle-info  { margin-left: 24px; margin-top: 4px; font-size: .78rem; color: var(--text-muted); line-height: 1.6; }

.tef-panel {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 24px;
}
.tef-panel-info { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.tef-panel-info .info-box { margin: 0; border-left-color: var(--tef-color); background: rgba(38,198,218,.07); }
.tef-panel-info .info-box i { color: var(--tef-color); }

.tef-rates-header, .tef-rate-row {
    display: grid;
    grid-template-columns: 1fr 70px 80px 85px;
    gap: 8px;
    padding: 8px 14px;
    align-items: center;
    border-bottom: 1px solid var(--border);
}
.tef-rates-header {
    font-size: .72rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: .05em; color: var(--text-muted);
    background: rgba(255,255,255,.025);
}
.tef-nutrient-label { display: flex; align-items: center; gap: 7px; font-size: .88rem; font-weight: 500; }
.tef-dot { font-size: .45em; }
.tef-muted { font-size: .8rem; color: var(--text-muted); }
.tef-col-rate { display: flex; align-items: center; gap: 5px; }
.tef-pct-input {
    width: 58px; padding: 5px 8px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); color: var(--text);
    font-size: .88rem; text-align: right;
    transition: border-color var(--transition);
}
.tef-pct-input:focus { outline: none; border-color: var(--primary); }
.tef-pct-sign { font-size: .82rem; color: var(--text-muted); }

.tef-fiber-section { border-top: 2px solid var(--border); }
.tef-section-subhead {
    padding: 6px 16px;
    font-size: .72rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: .05em; color: var(--text-muted);
    background: rgba(255,255,255,.025);
    border-bottom: 1px solid var(--border);
}
.tef-toggle-item { padding: 10px 16px; border-bottom: 1px solid var(--border); }
.tef-breakdown-toggle { border-top: 1px solid var(--border); margin-top: 10px; }
.tef-toggle-label {
    display: flex; align-items: center; gap: 8px;
    cursor: pointer; font-size: .88rem; color: var(--text);
}
.tef-toggle-label input[type="checkbox"] {
    width: 16px; height: 16px;
    accent-color: var(--primary); cursor: pointer; flex-shrink: 0;
}
.tef-toggle-info {
    font-size: .78rem; color: var(--text-muted);
    margin: 5px 0 0 24px; line-height: 1.6;
}
.tef-goal-section {
    display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
    padding: 14px 16px; border-top: 2px solid var(--border);
    background: rgba(255,255,255,.02);
}
.tef-goal-section .info-box { flex: 1; min-width: 200px; margin: 0; }

[data-theme="light"] .tef-rates-header,
[data-theme="light"] .tef-section-subhead { background: rgba(0,0,0,.04); }
[data-theme="light"] .tef-goal-section { background: rgba(0,0,0,.02); }
[data-theme="light"] .tef-panel-info .info-box { background: rgba(0,131,143,.08); }

/* ── Login ──────────────────────────────────────────── */
.login-container {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
    background: radial-gradient(ellipse at 50% 20%, #161b2e 0%, var(--bg) 70%);
}[data-theme="light"] .login-container {
    background: radial-gradient(ellipse at 50% 20%, #dbeafe 0%, var(--bg) 70%);
}.login-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 40px 36px;
    width: 100%; max-width: 400px;
    text-align: center;
    box-shadow: var(--shadow);
}
.login-logo {
    font-size: 3rem; color: var(--primary);
    margin-bottom: 8px;
}
.login-card h1 {
    font-size: 1.8rem; color: var(--text-bright); margin-bottom: 4px;
}
.login-sub { color: var(--text-muted); margin-bottom: 28px; }
.login-card .form-group { text-align: left; margin-bottom: 16px; }
.login-card .btn-block { margin-top: 10px; padding: 11px; font-size: 1rem; }
.login-footer {
    display: flex; align-items: center; justify-content: space-between;
    margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--border);
}

/* ── Navigation ─────────────────────────────────────── */
.main-nav {
    display: flex; align-items: center;
    padding: 0 24px; height: 56px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 100;
}
.nav-brand {
    font-size: 1.15rem; font-weight: 700; color: var(--primary);
    display: flex; align-items: center; gap: 8px;
    margin-right: 32px; cursor: pointer;
}
.nav-links { display: flex; gap: 4px; flex: 1; }
.nav-link {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 14px; border-radius: var(--radius);
    color: var(--text-muted); font-size: .9rem; font-weight: 500;
    transition: background var(--transition), color var(--transition);
}
.nav-link:hover { background: var(--card); color: var(--text); }
.nav-link.active { background: var(--card); color: var(--primary); }
.nav-user {
    display: flex; align-items: center; gap: 4px; margin-left: auto;
}
.nav-logout { color: var(--text-muted); }
.nav-logout:hover { color: var(--danger); }
.nav-theme { color: var(--text-muted); font-size: 1rem; }
.nav-theme:hover { color: var(--warning); }

/* ── Language switcher ────────────────────── */
.lang-switch {
    display: flex; border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden;
}
.lang-btn {
    background: transparent; border: none; cursor: pointer;
    padding: 4px 10px; font-size: .78rem; font-weight: 600;
    color: var(--text-muted); letter-spacing: .4px;
    transition: background var(--transition), color var(--transition);
}
.lang-btn:hover { background: var(--card-hover); color: var(--text); }
.lang-btn.active { background: var(--primary); color: #000; }
.nav-lang { margin-right: 4px; }

/* ── Main content ───────────────────────────────────── */
.main-content { padding: 24px; max-width: 1280px; margin: 0 auto; }

#page-profile > .page-header,
#page-profile > form,
#page-profile > .card { max-width: 1040px; margin-left: auto; margin-right: auto; }

.page-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 20px; flex-wrap: wrap; gap: 12px;
}
.page-header-actions {
    display: flex; align-items: stretch; gap: 8px; flex-wrap: wrap;
}
.page-header-actions .btn {
    padding: 8px 16px; font-size: .9rem;
}
.page-header h2 {
    font-size: 1.4rem; color: var(--text-bright);
    display: flex; align-items: center; gap: 10px;
}

/* ── Dashboard layout ───────────────────────────────── */
.dashboard-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 24px;
    align-items: start;
}
.dashboard-sidebar { position: sticky; top: 80px; }
.calendar-card { padding: 8px 12px 12px; }

/* ── Custom calendar ───────────────────────────────── */
.cal-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 10px; padding: 2px 0;
}
.cal-title {
    font-weight: 700; font-size: .95rem; color: var(--text-bright);
    letter-spacing: .2px;
}
.cal-nav {
    background: none; border: none; cursor: pointer;
    color: var(--text-muted); font-size: .8rem;
    width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%; transition: all var(--transition);
}
.cal-nav:hover { background: var(--surface); color: var(--primary); }
.cal-grid {
    display: grid; grid-template-columns: repeat(7, 1fr);
    gap: 2px;
}
.cal-dow {
    text-align: center; font-size: .66rem;
    color: var(--text-muted); font-weight: 700;
    text-transform: uppercase; letter-spacing: .4px;
    padding: 0 0 6px;
}
.cal-day {
    text-align: center; padding: 0;
    border-radius: 6px; font-size: .82rem;
    cursor: pointer; color: var(--text);
    transition: background var(--transition), color var(--transition);
    aspect-ratio: 1;
    display: flex; align-items: center; justify-content: center;
    position: relative;
}
.cal-day:hover:not(.empty) {
    background: var(--surface);
    color: var(--text-bright);
}
.cal-day.empty { cursor: default; pointer-events: none; }
.cal-day.weekend { color: var(--text-muted); }
.cal-day.today {
    font-weight: 700; color: var(--primary);
}
.cal-day.today::after {
    content: ''; position: absolute; bottom: 3px; left: 50%;
    transform: translateX(-50%);
    width: 4px; height: 4px; border-radius: 50%;
    background: var(--primary);
}
.cal-day.selected {
    background: var(--primary) !important;
    color: #000 !important;
    font-weight: 700;
}
.cal-day.today.selected::after { display: none; }
[data-theme="light"] .cal-day.selected { color: #fff !important; }

/* ── Date header ────────────────────────────────────── */
.date-header {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 20px;
}
.date-header h2 {
    font-size: 1.25rem; color: var(--text-bright);
    min-width: 180px; text-align: center;
}

/* ── Add entry ──────────────────────────────────────── */
.add-entry-form { display: flex; flex-direction: column; gap: 0; }
#entry-rows { display: flex; flex-direction: column; }
.food-row {
    display: flex; flex-direction: column; gap: 4px;
    padding: 8px 0; border-bottom: 1px solid var(--border);
}
.food-row:first-child { border-top: 1px solid var(--border); }
.food-row-main { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.food-row-search-wrapper { position: relative; flex: 1 1 220px; min-width: 0; }
.food-row-info {
    display: flex; gap: 14px; flex-wrap: wrap;
    font-size: .82rem; color: var(--text-muted); padding: 0 2px;
}
.food-row-remove { color: var(--text-muted); opacity: .7; }
.food-row-remove:hover { color: var(--danger); opacity: 1; }
.entry-bottom-bar {
    display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
    padding-top: 12px;
}
.search-wrapper { position: relative; flex: 2; min-width: 200px; }
.foods-filter-row {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.foods-filter-row .search-input-container { flex: 1; min-width: 180px; }

/* Source filter segmented control */
.source-filter-group {
    display: flex; border: 1px solid var(--border); border-radius: var(--radius);
    overflow: hidden; flex-shrink: 0;
}
.source-filter-opt {
    display: flex; align-items: center; cursor: pointer;
    padding: 5px 11px; font-size: .8rem; white-space: nowrap;
    color: var(--text-muted); transition: background var(--transition), color var(--transition);
    border-right: 1px solid var(--border);
}
.source-filter-opt:last-child { border-right: none; }
.source-filter-opt input[type="radio"] { display: none; }
.source-filter-opt:has(input:checked),
.source-filter-opt.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Open Food Facts credentials status */
.section-divider { border: none; border-top: 1px solid var(--border, rgba(255,255,255,.08)); margin: 20px 0 18px; }
.openfoodfacts-creds-status { margin-top: 6px; margin-bottom: 12px; font-size: .85rem; }
.profile-openfoodfacts-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 18px 0 8px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}
.profile-openfoodfacts-header .section-title {
    margin: 0;
    padding-top: 0;
    border-top: none;
    font-size: .97rem;
    color: var(--text-bright);
}
.openfoodfacts-logo-profile { height: 30px; width: auto; opacity: .95; flex-shrink: 0; }
.openfoodfacts-creds-connected   { color: var(--success, #66bb6a); }
.openfoodfacts-creds-disconnected { color: var(--text-muted); }

/* Source column badges */
.src-badge {
    display: inline-flex; align-items: center;
    padding: 2px 7px; border-radius: 9999px;
    font-size: .68rem; font-weight: 700; letter-spacing: .3px; white-space: nowrap;
}
.src-badge-system { background: rgba(102,187,106,.15); border: 1px solid #66bb6a; color: #66bb6a; }
.src-badge-user   { background: rgba(100,181,246,.15); border: 1px solid #64b5f6; color: #64b5f6; }
.src-badge-off    { background: rgba(255,160,0,.15);   border: 1px solid #ffa000; color: #ffa000; }
.toggle-label {
    display: flex; align-items: center; gap: 8px;
    cursor: pointer; user-select: none; white-space: nowrap;
}
.toggle-label input[type="checkbox"] { display: none; }
.toggle-switch {
    position: relative; width: 38px; height: 22px;
    background: var(--border); border-radius: 11px;
    transition: background var(--transition); flex-shrink: 0;
}
.toggle-switch::after {
    content: ''; position: absolute;
    top: 3px; left: 3px;
    width: 16px; height: 16px;
    background: #fff; border-radius: 50%;
    transition: transform var(--transition);
}
.toggle-label input:checked + .toggle-switch { background: var(--primary); }
.toggle-label input:checked + .toggle-switch::after { transform: translateX(16px); }
.toggle-text { font-size: .875rem; color: var(--text-muted); }
.toggle-label input:checked ~ .toggle-text { color: var(--text); }

.search-input-container {
    position: relative; width: 100%;
}
.search-icon {
    position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
    color: var(--text-muted); font-size: .85rem; pointer-events: none;
}
.search-input-container input {
    width: 100%; padding: 9px 12px 9px 36px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); color: var(--text);
    transition: border-color var(--transition);
}
.search-input-container input:focus {
    outline: none; border-color: var(--primary);
}
.amount-input {
    width: 100px; padding: 9px 12px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); color: var(--text);
}
.amount-input:focus { outline: none; border-color: var(--primary); }
.food-row-pieces {
    width: 60px; padding: 9px 8px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); color: var(--text-muted);
    text-align: center;
}
.food-row-pieces:not(:disabled):focus { outline: none; border-color: var(--primary); color: var(--text); }
.food-row-pieces:disabled { opacity: 0.35; cursor: not-allowed; }
.food-row-multiply {
    font-size: 0.9rem; color: var(--text-muted);
    padding: 0 2px; line-height: 1; align-self: center; user-select: none;
}
.meal-select {
    padding: 9px 12px; min-width: 130px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); color: var(--text);
}
.meal-select:focus { outline: none; border-color: var(--primary); }
.meal-name-input {
    flex: 1; min-width: 140px;
    padding: 9px 12px; border: 1px solid var(--border);
    border-radius: var(--radius); background: var(--surface);
    color: var(--text); font-size: .9rem;
}
.meal-name-input:focus { outline: none; border-color: var(--primary); }

/* ── Search results dropdown ────────────────────────── */
.search-results {
    position: absolute; top: 100%; left: 0; right: 0;
    z-index: 50;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-top: 4px;
    max-height: 260px; overflow-y: auto;
    box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.search-result-item {
    padding: 10px 14px;
    display: flex; justify-content: space-between; align-items: center;
    cursor: pointer;
    transition: background var(--transition);
    border-bottom: 1px solid var(--border);
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--card-hover); }
.search-result-item.kbd-active { background: var(--card-hover); outline: 2px solid var(--primary); outline-offset: -2px; }
.search-result-item.no-result {
    color: var(--text-muted); cursor: default; justify-content: center;
}
.search-result-item.search-create-hint {
    color: var(--primary); cursor: pointer; gap: 8px;
    border-top: 1px solid var(--border);
}
.search-result-item.search-create-hint:hover { background: var(--card-hover); }
.food-result-name { font-weight: 500; }
.food-result-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.food-result-kcal { color: var(--text-muted); font-size: .85rem; }
.food-result-brand { color: var(--text-muted); font-size: .85rem; margin-left: .35em; }
.food-row-editable { cursor: pointer; }

/* ── Favourite star button ──────────────────────────── */
.btn-fav-toggle {
    color: var(--text-muted);
    opacity: .45;
}
.btn-fav-toggle.active { color: #f5c518; opacity: 1; }

/* Star in form header – sits just before the close button */
#btn-food-fav { margin-left: auto; }

/* Favourite star indicator inside search-result items */
.food-result-fav { color: #f5c518; font-size: .78rem; line-height: 1; flex-shrink: 0; width: 0.9em; text-align: center; }
.food-result-fav-empty { visibility: hidden; }

/* Brand / manufacturer sub-line inside the name cell */
.food-brand-wrap { display: block; margin-top: 5px; }
.food-brand-line { display: block; color: var(--text-muted); font-size: .76rem; margin-top: 1px; }
.food-brand-wrap .food-brand-line:first-child { margin-top: 0; }
.food-brand-label { color: var(--text-muted); opacity: .55; font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; }

.food-edit-link {
    color: var(--text-muted); font-size: .8rem;
    opacity: .45;
    transition: opacity var(--transition), color var(--transition);
    display: inline-flex; align-items: center; justify-content: center;
    width: 1.4rem;
}
.search-result-item:hover .food-edit-link { opacity: .75; pointer-events: auto; }
.food-edit-link:hover { opacity: 1 !important; color: var(--primary); }
.food-edit-link-empty { visibility: hidden; pointer-events: none; }

/* ── Selected food info ─────────────────────────────── */
.selected-food-info {
    margin-top: 12px; padding: 10px 14px;
    background: var(--surface); border-radius: var(--radius);
    border-left: 3px solid var(--primary);
}
.food-info-grid {
    display: flex; gap: 16px; flex-wrap: wrap;
    font-size: .88rem; color: var(--text-muted);
}
.food-info-grid span:first-child { color: var(--text); font-weight: 500; }

/* ── Meal cards ─────────────────────────────────────── */
.meal-card { border-left: 3px solid var(--border); }
.meal-card.meal-breakfast { border-left-color: var(--warning); }
.meal-card.meal-lunch     { border-left-color: var(--success); }
.meal-card.meal-dinner    { border-left-color: var(--primary); }
.meal-card.meal-snack     { border-left-color: var(--salt-color); }
.meal-card.meal-custom    { border-left-color: var(--primary); }
.meal-time { font-size: .78rem; color: var(--text-muted); font-weight: 400; margin-left: 8px; }
.meal-weight { font-size: .8rem; color: var(--text-muted); font-weight: 400; padding-right: 8px; border-right: 1px solid var(--border); }
.meal-time-clickable { cursor: pointer; border-bottom: 1px dashed transparent; transition: color .15s, border-color .15s; }
.meal-time-clickable:hover { color: var(--primary); border-bottom-color: var(--primary); }
.meal-time-edit-form { display: inline-flex; align-items: center; gap: 4px; margin-left: 6px; }
.meal-time-input { width: 90px; padding: 2px 6px; font-size: .82rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); }

/* ── Add-entry live preview ─────────────────────────── */
.entry-preview {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    padding: 6px 12px;
    background: var(--surface-alt, rgba(255,255,255,.04));
    border-radius: var(--radius);
    font-size: .84rem;
    margin-bottom: 2px;
}
.entry-preview.hidden { display: none; }
.preview-cal { font-weight: 600; color: var(--cal-color); }
.preview-macro { color: var(--text-muted); }
.preview-sep { color: var(--border); font-size: .7rem; }
.meal-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 12px;
}
.meal-header h3 { margin-bottom: 0; }
.meal-header-right { display: flex; align-items: center; gap: 8px; }
.meal-total { color: var(--cal-color); font-weight: 600; font-size: .95rem; display: inline-flex; align-items: center; gap: 4px; }
.meal-tef-arrow { color: var(--text-muted); font-size: .9rem; line-height: 1; display: flex; align-items: center; }
.meal-tef-cal { color: var(--tef-color); font-weight: 600; cursor: default; }
.btn-delete-session {
    transition: opacity var(--transition);
}
.btn-delete-session:hover { opacity: .7; }
.meal-label-text {
    cursor: pointer;
    border-bottom: 1px dashed transparent;
    transition: color var(--transition), border-color var(--transition);
}
.meal-label-text:hover { color: var(--primary); border-bottom-color: var(--primary); }
.meal-rename-form { display: inline-flex; align-items: center; gap: 4px; vertical-align: middle; }
.meal-rename-select {
    padding: 2px 6px;
    background: var(--surface); border: 1px solid var(--primary);
    border-radius: var(--radius-sm, 4px); color: var(--text);
    font-size: .85rem; font-weight: 600;
}
.meal-rename-custom {
    padding: 2px 8px; min-width: 120px;
    background: var(--surface); border: 1px solid var(--primary);
    border-radius: var(--radius-sm, 4px); color: var(--text); font-size: .85rem;
}
.meal-rename-custom.hidden { display: none !important; }

/* ── Entry rows ─────────────────────────────────────── */
.entry-row {
    display: flex; align-items: center; gap: 8px;
    padding: 7px 0;
    border-bottom: 1px solid var(--border);
    transition: background var(--transition);
    position: relative;
}
.entry-row:last-child { border-bottom: none; }
.entry-row:hover { background: rgba(255,255,255,.02); margin: 0 -12px; padding: 7px 12px; border-radius: var(--radius); }
.entry-row[draggable="true"] { cursor: grab; }
.entry-row[draggable="true"]:active { cursor: grabbing; }
.entry-row.dragging { opacity: 0.35; }
.entry-row.drag-insert-above::before,
.entry-row.drag-insert-below::after {
    content: '';
    display: block;
    position: absolute;
    left: 0; right: 0; height: 2px;
    background: var(--primary);
    border-radius: 1px;
    pointer-events: none;
    z-index: 2;
}
.entry-row.drag-insert-above::before { top: -1px; }
.entry-row.drag-insert-below::after  { bottom: -1px; }
.meal-entries.drag-over {
    background: rgba(var(--primary-rgb,99,102,241), 0.08);
    border-radius: var(--radius);
    outline: 2px dashed rgba(var(--primary-rgb,99,102,241), 0.45);
    outline-offset: -2px;
}
.entry-info {
    flex: 1; min-width: 0;
    display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap;
}
.entry-name { font-weight: 400; color: var(--text-bright); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-amount { font-size: .82rem; color: var(--text-muted); white-space: nowrap; }
.entry-amount-clickable { cursor: pointer; border-bottom: 1px dashed var(--text-muted); padding-bottom: 1px; transition: color var(--transition), border-color var(--transition); }
.entry-amount-clickable:hover { color: var(--primary); border-color: var(--primary); }
.entry-pieces-label { display: none; color: var(--primary); font-size: .77rem; opacity: .85; }
.entry-pieces-label.entry-pieces-permanent { display: inline; }
.entry-row:hover .entry-pieces-label { display: inline; }
.entry-time   { font-size: .75rem; color: var(--text-muted); opacity: .65; white-space: nowrap; }
.entry-macros {
    display: flex; gap: 10px;
    font-size: .82rem; color: var(--text-muted);
    flex-shrink: 0;
}
.entry-kcal { color: var(--cal-color); font-weight: 600; min-width: 65px; text-align: right; }
.entry-actions { display: flex; gap: 2px; flex-shrink: 0; }

/* ── Entry inline amount edit ───────────────────────── */
.entry-amount-edit { display: inline-flex; align-items: center; gap: 3px; }
.entry-amount-input {
    width: 58px; padding: 2px 5px;
    font-size: .82rem;
    background: var(--input-bg, var(--surface-alt, #1e1e2e));
    border: 1px solid var(--primary); border-radius: var(--radius-sm, 4px);
    color: var(--text-bright); text-align: right;
}
.entry-amount-input:focus { outline: none; box-shadow: 0 0 0 2px rgba(var(--primary-rgb,99,102,241),.25); }
.entry-pieces-input {
    width: 44px; padding: 2px 4px;
    font-size: .82rem;
    background: var(--input-bg, var(--surface-alt, #1e1e2e));
    border: 1px solid var(--border); border-radius: var(--radius-sm, 4px);
    color: var(--text-bright); text-align: center;
}
.entry-pieces-input:focus { outline: none; border-color: var(--primary); }
.entry-edit-unit { font-size: .76rem; color: var(--text-muted); user-select: none; }

/* ── Custom confirm dialog ──────────────────────────── */
.confirm-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.6);
    display: flex; align-items: center; justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(3px);
    animation: fadeIn .15s ease;
}
.confirm-dialog {
    max-width: 340px; width: 90%;
    padding: 28px 24px;
    text-align: center;
    transform: translateY(12px) scale(.97); opacity: 0;
    transition: transform .18s ease, opacity .18s ease;
}
.confirm-dialog--in { transform: translateY(0) scale(1); opacity: 1; }
.confirm-icon    { font-size: 2rem; color: var(--danger, #ef4444); margin-bottom: 10px; }
.confirm-message { margin: 0 0 14px; color: var(--text-bright); font-size: 1rem; font-weight: 600; line-height: 1.4; }
.confirm-subtitle{ margin: 0 0 20px; color: var(--text-muted); font-size: .85rem; line-height: 1.45; }
.confirm-session-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: center; font-size: .82rem; color: var(--text-muted); }
.confirm-session-meta strong { color: var(--text); }
.confirm-session-meta i { color: var(--text-muted); font-size: .8rem; }
.confirm-session-sep { color: var(--border); font-size: .9rem; }
.confirm-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.confirm-actions .btn { flex: 1 1 auto; min-width: 0; }
.entry-macro { display: none; }

/* ── Summary / progress bars ────────────────────────── */
.macro-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-bottom: 20px; }
.macro-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 14px;
}
[data-theme="light"] .macro-card {
    border: 1px solid var(--border);
    box-shadow: 0 1px 4px rgba(0,0,0,.07);
}
.macro-card-clickable {
    cursor: pointer;
    transition: background var(--transition), box-shadow var(--transition);
}
.macro-card-clickable:hover {
    background: var(--card-hover, var(--border));
    box-shadow: 0 0 0 2px var(--border);
}
.macro-goal-input-wrap { display: inline-flex; align-items: center; gap: 3px; }
.macro-goal-input {
    width: 64px; padding: 1px 4px;
    background: var(--surface); border: 1px solid var(--primary);
    border-radius: 4px; color: var(--text-bright);
    font-size: .82rem; text-align: right;
}
.macro-goal-unit { font-size: .78rem; color: var(--text-muted); }
.macro-header {
    display: flex; justify-content: space-between; align-items: baseline;
    margin-bottom: 8px;
}
.macro-label { font-weight: 600; font-size: .9rem; color: var(--text-bright); }
.macro-values { font-size: .82rem; color: var(--text-muted); }
.progress-bar {
    width: 100%; height: 8px;
    background: var(--border); border-radius: 4px;
    overflow: hidden;
}
.progress-fill {
    height: 100%; border-radius: 4px;
    transition: width .4s ease;
}
.macro-remaining {
    font-size: .78rem; color: var(--text-muted);
    margin-top: 6px;
}
.macro-remaining.over { color: var(--danger); }

/* ── Detail table ───────────────────────────────────── */
.detail-table { overflow-x: auto; }

/* TEF breakdown box */
.tef-breakdown-box { margin: 0 0 18px; padding: 14px 18px; background: var(--card-bg); border: 1px solid var(--border); border-left: 3px solid var(--tef-color); border-radius: var(--radius); }
.tef-bd-title { font-size: .8rem; font-weight: 600; color: var(--tef-color); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 10px; }
.tef-bd-title i { margin-right: 5px; }
.tef-bd-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.tef-bd-table td { padding: 3px 8px 3px 0; color: var(--text-muted); }
.tef-bd-table td:first-child { color: var(--text); min-width: 160px; }
.tef-bd-table .tef-bd-result { text-align: right; white-space: nowrap; color: var(--text); font-variant-numeric: tabular-nums; }
.tef-bd-table tr.tef-bd-total td { border-top: 1px solid var(--border); padding-top: 6px; font-weight: 600; color: var(--text); }
.tef-bd-table tr.tef-bd-net td { color: var(--tef-color); font-weight: 600; }
.detail-table table { min-width: 420px; }
.detail-table th {
    text-align: left; font-size: .78rem;
    color: var(--text-muted); text-transform: uppercase;
    letter-spacing: .4px; padding: 8px 12px;
    border-bottom: 2px solid var(--border);
}
.detail-table td {
    padding: 8px 12px; border-bottom: 1px solid var(--border);
    font-size: .9rem;
}
.detail-table tr.sub-row td  { padding-left: 24px; font-size: .84rem; color: var(--text-muted); }
.detail-table tr.sub2-row td { padding-left: 44px; font-size: .80rem; color: var(--text-muted); opacity: .85; }
.detail-table .over { color: var(--danger); font-weight: 500; }

/* ── Data table (foods / users) ─────────────────────── */
.data-table th {
    text-align: left; font-size: .78rem;
    color: var(--text-muted); text-transform: uppercase;
    letter-spacing: .4px; padding: 10px 12px;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}
.data-table td {
    padding: 10px 12px; border-bottom: 1px solid var(--border);
    font-size: .9rem; vertical-align: middle;
}
.data-table tbody tr { transition: background var(--transition); }
.data-table tbody tr:hover { background: rgba(255,255,255,.02); }
.data-table .actions {
    white-space: nowrap; text-align: right;
}

/* ── Badges ─────────────────────────────────────────── */
.badge {
    display: inline-block; padding: 2px 10px;
    border-radius: 12px; font-size: .78rem; font-weight: 600;
}
.badge-admin { background: rgba(88,166,255,.15); color: var(--primary); }
.badge-user  { background: rgba(139,148,158,.15); color: var(--text-muted); }
.user-row-inactive td { opacity: .45; }
.user-row-inactive .btn-toggle-user { opacity: 1; }
.badge-self   { background: rgba(88,166,255,.1); color: var(--primary); }

.summary-card { cursor: pointer; }
.summary-card #daily-summary { cursor: default; }
.summary-card .card-header-row i { transition: transform .2s ease; }
.summary-card.collapsed #summary-body { display: none; }
.summary-card.collapsed .card-header-row i { transform: rotate(180deg); }
.summary-card.collapsed:hover { background: var(--card-hover); }

/* ── Empty state ────────────────────────────────────── */
.empty-state {
    text-align: center; padding: 40px 20px;
    color: var(--text-muted);
}
.empty-state i { font-size: 2.5rem; margin-bottom: 10px; display: block; opacity: .4; }
.empty-state p { font-size: .95rem; }

/* ── Toast ──────────────────────────────────────────── */
#toast-container {
    position: fixed; bottom: 24px; right: 24px;
    z-index: 10000; display: flex;
    flex-direction: column; gap: 8px;
}
.toast {
    padding: 12px 20px;
    border-radius: var(--radius);
    color: #fff; font-size: .9rem; font-weight: 500;
    min-width: 240px;
    box-shadow: 0 4px 16px rgba(0,0,0,.4);
    white-space: pre-line;
    animation: toastIn .3s ease, toastOut .3s ease 2.7s forwards;
}
.toast-success  { background: #1a7f37; }
.toast-error    { background: #a1232b; }
.toast-info     { background: #1a5276; }
.toast-warning  { background: #7a5800; }
@keyframes toastIn  { from { opacity:0; transform:translateY(20px); } to { opacity:1; transform:translateY(0); } }
@keyframes toastOut { from { opacity:1; } to { opacity:0; transform:translateY(-10px); } }
@keyframes fadeIn   { from { opacity:0; } to { opacity:1; } }
@keyframes slideUp  { from { opacity:0; transform:translateY(16px) scale(.97); } to { opacity:1; transform:translateY(0) scale(1); } }

/* ── Responsive ─────────────────────────────────────── */
@media (max-width: 900px) {
    .dashboard-layout {
        grid-template-columns: 1fr;
    }
    .dashboard-sidebar {
        position: static;
    }
    .entry-macros .entry-macro { display: none; }
}
@media (max-width: 640px) {
    .main-nav { padding: 0 12px; }
    .nav-brand span { display: none; }
    .nav-link span { display: none; }
    .nav-link { padding: 8px 10px; }
    .main-content { padding: 12px; }
    .add-entry-form { flex-direction: column; }
    .entry-bottom-bar { flex-direction: column; }
    .food-row-main { flex-wrap: wrap; }
    .search-wrapper { min-width: 0; width: 100%; }
    .amount-input { width: 100%; }
    .meal-select { width: 100%; }
    .meal-name-input { width: 100%; }
    .macro-cards { grid-template-columns: 1fr 1fr; }
    .form-row { flex-direction: column; }
    .form-row .form-group { min-width: 100%; }
    .date-header h2 { min-width: 0; font-size: 1.05rem; }
    .entry-kcal { min-width: 52px; }
    .detail-table table { min-width: 0; }
    .page-header { gap: 8px; }

    /* ── Macro cards: single column, compact on mobile ── */
    .macro-cards { grid-template-columns: 1fr; gap: 8px; }
    .macro-card { padding: 10px 12px; }
    .macro-header { flex-direction: row; align-items: baseline; }
    .macro-values { font-size: .8rem; }

    /* ── Detail / nutrition table on mobile ── */
    .detail-table th,
    .detail-table td { padding: 6px 8px; font-size: .8rem; }
    .detail-table tr.sub-row  td { padding-left: 16px; }
    .detail-table tr.sub2-row td { padding-left: 28px; }
    /* Drop the "Remaining" column on small screens */
    .detail-table thead tr th:nth-child(3),
    .detail-table tbody tr td:nth-child(3) { display: none; }

    /* ── Food-row remove button: inline, right-aligned ── */
    .food-row-main { position: relative; flex-wrap: nowrap; align-items: flex-start; }
    .food-row-search-wrapper { flex: 1 1 0; min-width: 0; }
    .food-row-amount.amount-input { width: 72px; flex-shrink: 0; }
    .food-row-pieces { width: 50px; flex-shrink: 0; }
    .food-row-remove {
        flex-shrink: 0;
        visibility: visible !important;
        align-self: center;
    }

    /* ── Larger search results dropdown on mobile ── */
    /* Extend beyond the narrow search-wrapper to fill the full card width */
    .food-row-results.search-results {
        max-height: 55vh;
        width: min(360px, calc(100vw - 48px));
        right: auto;
    }

    /* ── Meal session header on mobile ── */
    .meal-header { flex-wrap: wrap; row-gap: 3px; }
    .meal-header h3 { font-size: .88rem; min-width: 0; flex: 1 1 auto; }
    .meal-header-right { gap: 6px; }
    .meal-weight { font-size: .72rem; padding-right: 5px; }
    .meal-total { font-size: .85rem; gap: 3px; }
    .meal-tef-cal { font-size: .85rem; }

    /* ── Foods page action buttons on mobile: 2-col grid ── */
    .page-header { flex-direction: column; align-items: stretch; }
    .page-header-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; }
    .page-header-actions .btn { justify-content: center; }
    /* Primary and OFFs buttons always span full width */
    .page-header-actions .btn-primary,
    .page-header-actions .btn-openfoodfacts { grid-column: 1 / -1; }

    /* ── Toast on mobile ── */
    #toast-container { right: 12px; left: 12px; bottom: 16px; align-items: stretch; }
    .toast { min-width: 0; width: 100%; text-align: left; }
}
@media (min-width: 1024px) {
    .entry-macros .entry-macro { display: inline; }
}

/* ── Flatpickr overrides (dark) ─────────────────────── */
/* ── TEF card ──────────────────────────────────────── */
.macro-tef {
    display: flex; align-items: center; gap: 5px;
    margin-top: 7px; padding-top: 7px;
    border-top: 1px solid var(--border);
    font-size: .75rem; color: var(--text-muted);
}
.macro-tef-icon { color: var(--tef-color); font-size: .75rem; }
.macro-tef-label { cursor: help; }
.macro-tef-value { font-weight: 600; color: var(--tef-color); }
.macro-tef-saving { margin-left: auto; color: var(--success, #4caf50); }
[data-theme="light"] .macro-tef-saving { color: #2e7d32; }
.macro-tef-label:hover::after {
    content: attr(title);
    position: absolute; bottom: calc(100% + 6px); left: 50%;
    transform: translateX(-50%);
    background: var(--card); border: 1px solid var(--border);
    padding: 8px 12px; border-radius: var(--radius);
    font-size: .75rem; white-space: normal; width: 260px; line-height: 1.45;
    box-shadow: var(--shadow); color: var(--text); z-index: 200;
    pointer-events: none;
}
.macro-tef-label { position: relative; }
.tef-saving-cell { color: var(--success, #4caf50); font-size: .85rem; }
[data-theme="light"] .tef-saving-cell { color: #2e7d32; }
.fruitveg-row td { border-top: 1px solid var(--border); }
.macro-set-goal { color: var(--text-muted); font-size: .8rem; font-style: italic; opacity: .75; }
.macro-no-goal  { display: none; }

.flatpickr-calendar.inline { display: none; } /* removed */

/* ── Food category sections ─────────────────────────── */
.food-cat-section {
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
    margin-bottom: 10px;
}
.food-cat-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px;
    background: var(--surface);
    cursor: pointer;
    user-select: none;
    transition: background var(--transition);
}
.food-cat-header:hover { background: var(--card-hover, var(--border)); }
.food-cat-title {
    display: flex; align-items: center; gap: 10px;
    font-weight: 600; font-size: .95rem; color: var(--text-bright);
}
.food-cat-emoji { font-size: 1.2rem; line-height: 1; }
.food-cat-count {
    background: var(--border); color: var(--text-muted);
    border-radius: 12px; padding: 1px 8px;
    font-size: .75rem; font-weight: 600;
}
.food-cat-chevron {
    color: var(--text-muted); font-size: .8rem;
    transition: transform .2s ease;
}
.food-cat-section.collapsed .food-cat-chevron { transform: rotate(-90deg); }
.food-cat-body { background: var(--card); overflow-x: auto; }
.food-cat-section.collapsed .food-cat-body { display: none; }
.food-cat-table { width: 100%; }
.food-cat-table td:first-child,
.food-cat-table th:first-child { padding-left: 16px; }
.food-primary-name { font-weight: 500; color: var(--text-bright); }
.food-alt-name { font-size: .74rem; color: var(--text-muted); }

/* Category left-border accent */
.food-cat-section[data-cat="fruit"]     .food-cat-header { border-left: 3px solid #fb8c00; }
.food-cat-section[data-cat="vegetable"] .food-cat-header { border-left: 3px solid #66bb6a; }
.food-cat-section[data-cat="meat"]      .food-cat-header { border-left: 3px solid #ef5350; }
.food-cat-section[data-cat="fish"]      .food-cat-header { border-left: 3px solid #29b6f6; }
.food-cat-section[data-cat="dairy"]     .food-cat-header { border-left: 3px solid #ce93d8; }
.food-cat-section[data-cat="egg"]       .food-cat-header { border-left: 3px solid #ffe082; }
.food-cat-section[data-cat="grain"]     .food-cat-header { border-left: 3px solid #d4a017; }
.food-cat-section[data-cat="legume"]    .food-cat-header { border-left: 3px solid #a5d6a7; }
.food-cat-section[data-cat="nut"]       .food-cat-header { border-left: 3px solid #a1887f; }
.food-cat-section[data-cat="oil"]       .food-cat-header { border-left: 3px solid #ffee58; }
.food-cat-section[data-cat="drink"]     .food-cat-header { border-left: 3px solid #4dd0e1; }
.food-cat-section[data-cat="sweet"]     .food-cat-header { border-left: 3px solid #f48fb1; }
.food-cat-section[data-cat="other"]     .food-cat-header { border-left: 3px solid var(--border); }

/* hide-sm columns on small screens */
@media (max-width: 760px) { .hide-sm { display: none; } }

/* -- Setup form ------------------------------- */
.setup-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-bright);
    margin: 0 0 18px;
    text-align: center;
}

/* -- Foods Dedup page ----------------------- */
.dedup-summary { margin-bottom: 12px; padding: 12px 16px; }
.dedup-group { margin-bottom: 14px; padding: 0; overflow: hidden; }
.dedup-group-header {
    display: flex; align-items: center; gap: 8px;
    padding: 12px 16px; background: var(--surface-alt, var(--surface));
    border-bottom: 1px solid var(--border);
    font-size: .95rem;
}
.dedup-table { width: 100%; border-collapse: collapse; font-size: .84rem; }
.dedup-table thead tr { background: var(--surface); }
.dedup-table th { padding: 7px 12px; text-align: left; font-weight: 600; color: var(--text-muted); border-bottom: 1px solid var(--border); font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; }
.dedup-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.dedup-table tbody tr:last-child td { border-bottom: none; }
.dedup-keeper td { background: rgba(var(--primary-rgb,99,102,241),.06); }
.dedup-referenced td { opacity: .7; }
.dedup-ref-yes { color: var(--warning, #f59e0b); font-size: .82rem; }
.dedup-ref-no  { color: var(--text-muted); font-size: .82rem; }
.dedup-blocked { font-size: .8rem; }

/* ── Persistent Sessions ──────────────────────────────── */
.session-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.session-item { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.session-item.current { border-color: var(--primary); }
.session-device-icon { width: 28px; text-align: center; color: var(--text-muted); font-size: 1.1rem; flex-shrink: 0; }
.session-info { flex: 1; min-width: 0; }
.session-info-main { font-size: .88rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-info-sub  { font-size: .75rem; color: var(--text-muted); margin-top: 2px; }
.badge-current { display: inline-block; font-size: .68rem; font-weight: 600; background: var(--primary); color: #fff; border-radius: 4px; padding: 1px 5px; margin-left: 5px; vertical-align: middle; }
.sessions-extra { display: none; }
.sessions-toggle-btn { margin-top: 4px; margin-bottom: 4px; }
.session-revoke-all-row { display: flex; justify-content: flex-end; margin-bottom: 16px; }
.btn-sm { font-size: .8rem; padding: 5px 10px; }
.badge-keeper { background: var(--primary); color: #fff; font-size: .72rem; padding: 2px 7px; border-radius: 10px; }
.dedup-group-footer { padding: 10px 16px; background: var(--surface); border-top: 1px solid var(--border); }
.btn-sm { padding: 4px 10px; font-size: .82rem; }

/* -- Meal-times section in profile ----------- */
.meal-times-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 18px;
}
.meal-time-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.meal-time-label {
    font-weight: 600;
    color: var(--text-bright);
    min-width: 96px;
    flex-shrink: 0;
}
.meal-time-range {
    display: flex;
    align-items: center;
    gap: 6px;
}
.meal-time-sep {
    color: var(--text-muted);
    font-size: .9rem;
}
/* Custom time picker (two selects inside a <span>) */
.time-picker {
    display: inline-flex;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color var(--transition);
}
.time-picker:focus-within {
    border-color: var(--primary);
}
.time-picker select {
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    padding: 5px 6px;
    cursor: pointer;
    font-variant-numeric: tabular-nums;
    text-align: center;
}
.time-picker select:first-child { padding-right: 2px; }
.time-picker select:last-child  { padding-left: 2px; }
.time-picker-colon {
    color: var(--text-muted);
    font-weight: 700;
    pointer-events: none;
    padding: 0 1px;
    line-height: 1;
}

/* ── Open Food Facts import button ───────────────────── */
.btn-openfoodfacts {
    background: transparent;
    border-color: rgba(232, 82, 10, .45);
    color: #c87848;
}
.btn-openfoodfacts:hover { background: rgba(232, 82, 10, .08); border-color: rgba(232, 82, 10, .7); color: #e08850; }
[data-theme="light"] .btn-openfoodfacts {
    background: transparent;
    border-color: rgba(194, 65, 12, .4);
    color: #9a3412;
}
[data-theme="light"] .btn-openfoodfacts:hover { background: rgba(194, 65, 12, .06); border-color: rgba(194, 65, 12, .65); }

/* ── Open Food Facts panel ───────────────────────────── */
.openfoodfacts-panel {
    padding: 0;
    overflow: hidden;
    margin-bottom: 12px;
}
.openfoodfacts-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    gap: 12px;
}
.openfoodfacts-panel-title {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}
.openfoodfacts-logo {
    height: 22px;
    width: auto;
    flex-shrink: 0;
}
.openfoodfacts-title-text {
    font-weight: 600;
    color: var(--text-bright);
    font-size: .97rem;
}
.openfoodfacts-search-row {
    display: flex;
    gap: 10px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    align-items: center;
}
.openfoodfacts-country-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 8px 18px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.openfoodfacts-country-label {
    font-size: .82rem;
    color: var(--text-muted);
    font-weight: 600;
    white-space: nowrap;
}
.openfoodfacts-country-opt {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: .85rem;
    cursor: pointer;
    user-select: none;
    color: var(--text);
}
.openfoodfacts-country-opt input[type="checkbox"] {
    cursor: pointer;
}
.openfoodfacts-search-input { flex: 1; min-width: 0; }
.openfoodfacts-search-input input { width: 100%; }
.openfoodfacts-status {
    padding: 10px 18px;
    font-size: .88rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 8px;
}
.openfoodfacts-status.hidden { display: none; }
.openfoodfacts-status.is-error {
    color: var(--danger, #e74c3c);
    font-weight: 500;
}
.openfoodfacts-results { display: flex; flex-direction: column; }
.openfoodfacts-results.hidden { display: none; }
.openfoodfacts-results-header {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 10px 18px 6px;
    border-bottom: 1px solid var(--border);
}
.openfoodfacts-results-count {
    font-weight: 600;
    color: var(--text-bright);
    font-size: .9rem;
}
.openfoodfacts-results-hint {
    font-size: .8rem;
    color: var(--text-muted);
}
.openfoodfacts-results-list {
    max-height: 460px;
    overflow-y: auto;
}
.openfoodfacts-result-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 18px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background var(--transition);
}
.openfoodfacts-result-row:last-child { border-bottom: none; }
.openfoodfacts-result-row:hover { background: var(--card-hover); }
.openfoodfacts-result-img {
    width: 44px;
    height: 44px;
    object-fit: contain;
    border-radius: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    flex-shrink: 0;
}
.openfoodfacts-result-img-placeholder {
    width: 44px;
    height: 44px;
    border-radius: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 1.1rem;
}
.openfoodfacts-result-body { flex: 1; min-width: 0; }
.openfoodfacts-result-name {
    font-weight: 600;
    color: var(--text-bright);
    font-size: .92rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.openfoodfacts-result-brand {
    font-size: .78rem;
    color: var(--text-muted);
    margin-top: 1px;
}
.openfoodfacts-result-macros {
    display: flex;
    gap: 8px;
    margin-top: 4px;
    flex-wrap: wrap;
}
.openfoodfacts-macro-pill {
    font-size: .73rem;
    padding: 2px 8px;
    border-radius: 99px;
    border: 1px solid var(--border);
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    line-height: 1;
}
.openfoodfacts-macro-pill.cal  { color: var(--cal-color);  border-color: var(--cal-color);  }
.openfoodfacts-macro-pill.fat  { color: var(--fat-color);  border-color: var(--fat-color);  }
.openfoodfacts-macro-pill.carb { color: var(--carb-color); border-color: var(--carb-color); }
.openfoodfacts-macro-pill.prot { color: var(--prot-color); border-color: var(--prot-color); }
.openfoodfacts-result-action {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    flex-shrink: 0;
    width: 175px;
}
.openfoodfacts-status-row {
    display: flex;
    align-items: center;
    gap: 6px;
}
.openfoodfacts-website-btn,
.openfoodfacts-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    font-size: .72rem;
    padding: 5px 10px;
    border-radius: var(--radius);
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    transition: border-color var(--transition), color var(--transition), background var(--transition);
    white-space: nowrap;
    text-decoration: none;
    font-family: inherit;
    font-weight: 500;
    width: 100%;
    box-sizing: border-box;
}
.openfoodfacts-website-btn:hover,
.openfoodfacts-action-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(88,166,255,.07);
}
.openfoodfacts-status-row .openfoodfacts-action-btn {
    flex: 1;
}
.openfoodfacts-delete-btn {
    color: var(--text-muted);
    opacity: .7;
    flex-shrink: 0;
    margin-left: auto;
    transition: opacity var(--transition), color var(--transition);
}
.openfoodfacts-delete-btn:hover {
    color: var(--danger);
    opacity: 1;
}
.openfoodfacts-result-barcode {
    font-size: .72rem;
    color: var(--text-muted);
    font-family: monospace;
    text-align: right;
}
.openfoodfacts-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: .78rem;
    padding: 3px 10px;
    border-radius: 99px;
    white-space: nowrap;
}
.openfoodfacts-badge.ok {
    background: rgba(63,185,80,.12);
    border: 1px solid rgba(63,185,80,.35);
    color: var(--success);
}
.openfoodfacts-badge.outdated {
    background: rgba(210,153,34,.12);
    border: 1px solid rgba(210,153,34,.4);
    color: var(--warning);
}
@media (max-width: 600px) {
    .openfoodfacts-search-row { flex-direction: column; align-items: stretch; }
    .openfoodfacts-result-macros { display: none; }
}
/* ── System-admin badge ─────────────────────────────── */
.badge-system-admin {
    background: rgba(167,139,250,.15);
    color: #a78bfa;
}

/* ── Settings page ──────────────────────────────────── */
.settings-section { margin-bottom: 16px; }
.settings-section .section-title {
    margin: 0 0 16px;
    padding: 0 0 10px;
    border-top: none;
    border-bottom: 1px solid var(--border);
    color: var(--text-bright);
}
.settings-bool-row .form-group { margin-bottom: 4px; }
/* Toggle text inside settings bools must not inherit form-label uppercase */
.settings-bool-row .toggle-text { text-transform: none; letter-spacing: 0; font-size: .92rem; font-weight: 500; color: var(--text); }
.settings-bool-row .toggle-label input:checked ~ .toggle-text { color: var(--text); }
.settings-save-row {
    display: flex; justify-content: flex-start;
    padding: 8px 0 24px;
}
/* Inline info note inside a settings section (e.g. account-level tip before credentials) */
.settings-info-note {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: .84rem;
    color: var(--text-muted);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    margin: 0 0 14px;
    line-height: 1.4;
}
.settings-info-note .fa-circle-info {
    color: var(--accent);
    font-size: .9rem;
    flex-shrink: 0;
    margin-top: 1px;
}

/* Sub-section divider inside a settings card */
.settings-subsection-header {
    display: flex; align-items: center; gap: 10px;
    margin: 18px 0 10px;
    color: var(--text-muted);
    justify-content: center;
    font-size: .75rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
}
.settings-subsection-header::before,
.settings-subsection-header::after {
    content: ''; flex: 1; height: 1px; background: var(--border);
}

.settings-section-legal .settings-bool-row {
    margin-bottom: 14px;
}
.settings-section-legal .settings-collapsible {
    padding-top: 4px;
}
.settings-section-legal .form-row:last-child {
    margin-bottom: 0;
}

/* AI section provider mini-boxes */
.settings-provider-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin: 6px 0 10px;
}
.settings-provider-box {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 12px 12px 6px;
}
.settings-provider-box-title {
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-bright);
    margin: 0 0 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}
.settings-provider-box .form-row {
    margin-bottom: 10px;
}
.settings-provider-box .form-row:last-child {
    margin-bottom: 0;
}
@media (max-width: 900px) {
    .settings-provider-grid {
        grid-template-columns: 1fr;
    }
}

/* Secret field wrapper */
.settings-secret-wrap { position: relative; display: flex; align-items: center; }
.settings-secret-wrap input { flex: 1; padding-right: 32px; }
.settings-secret-check {
    position: absolute; right: 10px;
    color: var(--success, #3fb950);
    pointer-events: none; font-size: .95rem;
}
.settings-secret-badge { display: none; }   /* legacy – kept to avoid JS errors */

/* Provider key dependency highlights */
.settings-field-required label { font-weight: 600; }
.settings-field-missing label { color: var(--warning, #f59e0b); }
.settings-field-missing input { border-color: var(--warning, #f59e0b) !important; }

/* ═══════════════════════════════════════════════════════════════
   Legal page footer & overlay
   ═══════════════════════════════════════════════════════════════ */

/* Injected at the bottom of each page section — scrolls with content */
.legal-page-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 20px;
    padding: 12px 24px 16px;
    border-top: none;
    font-size: .72rem;
    color: color-mix(in srgb, var(--text-muted) 55%, transparent);
    opacity: 1;
    transition: opacity .25s ease;
}
[data-legal-loading] .legal-page-footer {
    opacity: 0;
    pointer-events: none;
}
.legal-page-appname {
    font-weight: 600;
    color: color-mix(in srgb, var(--text-muted) 55%, transparent);
    letter-spacing: .02em;
}
.legal-page-sep {
    color: color-mix(in srgb, var(--border) 50%, transparent);
    font-size: .65rem;
    user-select: none;
}
.legal-page-link {
    color: color-mix(in srgb, var(--text-muted) 55%, transparent);
    text-decoration: none;
    transition: color .15s ease;
}
.legal-page-link:hover { color: var(--primary); text-decoration: underline; }

/* Login page: reduce top margin, sits inside the card */
.login-card .legal-page-footer {
    margin-top: 20px;
    padding-top: 16px;
    padding-bottom: 0;
}

/* Full-screen dimmed overlay */
.legal-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0,0,0,.65);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    backdrop-filter: blur(4px);
}
.legal-overlay.hidden { display: none; }

/* Modal card */
.legal-overlay-inner {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg, 12px);
    max-width: 680px;
    width: 100%;
    max-height: 82vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 14px 52px rgba(0,0,0,.45);
    overflow: hidden;
}

/* Header bar */
.legal-overlay-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 14px;
    background: var(--surface);
    border-bottom: 2px solid var(--primary);
    flex-shrink: 0;
}
.legal-overlay-header h2 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-bright);
    letter-spacing: .01em;
}

/* Scrollable body */
.legal-overlay-content {
    padding: 24px 28px 32px;
    overflow-y: auto;
    color: var(--text);
    font-size: .9rem;
    line-height: 1.72;
    flex: 1;
}

/* Section headings */
.legal-overlay-content h3 {
    margin: 26px 0 10px;
    font-size: .8rem;
    font-weight: 700;
    letter-spacing: .07em;
    text-transform: uppercase;
    color: var(--primary);
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}
.legal-overlay-content h3:first-child { margin-top: 0; }
.legal-overlay-content p { margin: 0 0 12px; }
.legal-overlay-content strong { color: var(--text-bright); }

/* Address block in imprint */
.legal-overlay-content .legal-address {
    font-style: normal;
    color: var(--text);
    margin: 4px 0 14px;
    line-height: 1.6;
}

/* Lists as styled pill-rows */
.legal-overlay-content ul {
    margin: 4px 0 16px;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.legal-overlay-content li {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 9px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: .875rem;
    line-height: 1.55;
}
.legal-overlay-content li::before {
    content: '›';
    color: var(--primary);
    font-weight: 700;
    font-size: 1rem;
    flex-shrink: 0;
    margin-top: -1px;
}
.legal-overlay-content a { color: var(--primary); }
.legal-overlay-content a:hover { text-decoration: underline; }
.legal-not-configured { color: var(--text-muted); font-style: italic; }

/* Thin custom scrollbar */
.legal-overlay-content::-webkit-scrollbar { width: 5px; }
.legal-overlay-content::-webkit-scrollbar-track { background: transparent; }
.legal-overlay-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.legal-overlay-content::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

@media (max-width: 600px) {
    .legal-overlay { padding: 8px; }
    .legal-overlay-inner { max-height: 93vh; border-radius: var(--radius); }
    .legal-overlay-header { padding: 12px 16px 11px; }
    .legal-overlay-content { padding: 16px 18px 24px; }
}