/* ==========================================================================
   Shared design system for MyFitness and MyFinance.
   Look: warm cream page, white rounded cards, pastel orange accent,
   floating pill tab bar. Dark mode keeps the cards WHITE on a warm dark page.
   Theme is set on <html data-theme="light|dark">. Apps may override --accent.
   ========================================================================== */

@font-face {
    font-family: "Plus Jakarta Sans";
    font-style: normal;
    font-weight: 200 800;
    font-display: swap;
    src: url("../fonts/plus-jakarta-sans-latin-wght-normal.woff2") format("woff2");
}

:root {
    /* Accent */
    --accent: #FFB37C;
    --on-accent: #3A1C08;

    /* Page (changes with theme) */
    --bg: #FFF7F1;
    --text: #2A1A10;
    --muted: #7A6558;
    --accent-text: #A84C17;
    --tint: #FFEBDD;
    --track: #F6EAE1;
    --dash: #F0D3BF;
    --nav-bg: #FFFFFF;
    --nav-icon: #7A6558;
    --shadow: 0 1px 2px rgba(60, 30, 10, 0.04), 0 6px 20px rgba(60, 30, 10, 0.06);

    /* Cards and sheets (white in BOTH themes) */
    --card: #FFFFFF;
    --card-text: #2A1A10;
    --card-muted: #7A6558;
    --card-tint: #FFEBDD;
    --card-accent: #A84C17;
    --card-track: #F6EAE1;
    --card-line: #F3E6DC;
    --toggle-border: #F0E2D7;
    --sheet-bg: #FFF7F1;
    --danger: #C0392B;
    --danger-tint: #FDE3DF;

    --radius: 24px;
    --space: 20px;
    --font: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;

    color-scheme: light;
}

:root[data-theme="dark"] {
    --bg: #15110E;
    --text: #F8EEE7;
    --muted: #B5A59A;
    --accent-text: #FFBE91;
    --tint: #3B2A1F;
    --track: #3A302A;
    --dash: #4A3B31;
    --nav-bg: #2C2420;
    --nav-icon: #C9B9AE;
    --shadow: none;
    --toggle-border: #FFFFFF;
    color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.4;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: none;
}
body:has(.sheet) { overflow: hidden; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin: 0; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- App shell + floating tab bar ---------- */

.app-content {
    max-width: 640px;
    margin: 0 auto;
    padding: calc(env(safe-area-inset-top) + 20px) var(--space)
             calc(env(safe-area-inset-bottom) + 120px);
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.tab-bar {
    position: fixed;
    left: 50%;
    bottom: calc(env(safe-area-inset-bottom) + 12px);
    transform: translateX(-50%);
    width: min(600px, calc(100% - 40px));
    height: 68px;
    padding: 0 8px;
    border-radius: 34px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--nav-bg);
    box-shadow: 0 10px 30px rgba(60, 30, 10, 0.16);
    z-index: 10;
}
.tab {
    height: 52px;
    min-width: 52px;
    border-radius: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--nav-icon);
    font-size: 14px;
    font-weight: 800;
    transition: background 0.2s, color 0.2s;
}
.tab .tab-label { display: none; }
.tab.active { padding: 0 18px; background: var(--accent); color: var(--on-accent); }
.tab.active .tab-label { display: inline; }

/* ---------- Page header ---------- */

.page-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.page-header-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.page-eyebrow { font-size: 13px; font-weight: 600; color: var(--muted); }
.page-header h1 { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.2; }
.page-header-actions { display: flex; gap: 8px; flex: none; }
.link-btn { background: none; border: 0; padding: 6px 0; color: var(--accent-text); font-weight: 700; font-size: 14px; }

.icon-btn {
    position: relative;
    width: 44px; height: 44px;
    border-radius: 22px; border: 0;
    display: grid; place-items: center;
    background: var(--card); color: var(--card-text);
    box-shadow: var(--shadow);
}
.icon-btn input[type="date"] { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; font-size: 16px; }

/* ---------- Week strip ---------- */

.week-strip { display: flex; justify-content: space-between; gap: 4px; }
.day {
    width: 46px; height: 66px;
    border-radius: 23px; border: 0; padding: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    background: transparent; color: var(--text);
}
.day-letter { font-size: 12px; font-weight: 600; opacity: 0.75; }
.day-number { font-size: 17px; font-weight: 800; }
.day-dot { width: 5px; height: 5px; border-radius: 3px; background: transparent; }
.day.logged .day-dot { background: var(--accent); }
.day.selected { background: var(--accent); color: var(--on-accent); }
.day.selected .day-dot { background: var(--on-accent); }
.day:disabled { opacity: 0.3; }

/* ---------- Goals hero ---------- */

.hero {
    border-radius: 28px;
    padding: 20px 22px;
    display: flex; align-items: center; gap: 20px;
    background: var(--accent); color: var(--on-accent);
}
.hero-text { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.hero-eyebrow { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.7; }
.hero-message { font-size: 19px; font-weight: 800; line-height: 1.25; }
.ring { flex: none; }

/* ---------- Metric tiles ---------- */

.tile-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.tile {
    border: 0; border-radius: var(--radius);
    padding: 16px;
    display: flex; flex-direction: column; gap: 10px;
    text-align: left;
    background: var(--card); color: var(--card-text);
    box-shadow: var(--shadow);
    transition: transform 0.12s;
}
.tile:active { transform: scale(0.97); }
.tile-top { display: flex; justify-content: space-between; align-items: center; }
.icon-chip {
    width: 36px; height: 36px; border-radius: 12px; flex: none;
    display: grid; place-items: center;
    background: var(--card-tint); color: var(--card-accent);
}
.tile-badge { display: flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 700; color: var(--card-accent); }
.tile-label { font-size: 13px; font-weight: 600; color: var(--card-muted); }
.tile-value { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; line-height: 1; font-variant-numeric: tabular-nums; }
.tile-unit { font-size: 14px; font-weight: 600; color: var(--card-muted); letter-spacing: 0; }
.tile-foot { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--card-muted); }
.tile.empty { background: transparent; box-shadow: none; outline: 2px dashed var(--dash); outline-offset: -2px; color: var(--text); }
.tile.empty .icon-chip { background: var(--tint); color: var(--accent-text); }
.tile.empty .tile-label, .tile.empty .tile-foot { color: var(--muted); }
.tile-cta { font-size: 18px; font-weight: 800; line-height: 1.2; color: var(--accent-text); }

.bar { height: 8px; border-radius: 4px; background: var(--card-track); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; background: var(--accent); transition: width 0.3s; }
.sparkline { display: block; width: 100%; height: 26px; }

/* ---------- Toggles and rows ---------- */

.section-label { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.section { display: flex; flex-direction: column; gap: 10px; }
.toggle-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.toggle-card {
    height: 60px; border-radius: 20px;
    display: flex; align-items: center; gap: 10px; padding: 0 16px;
    border: 2px solid var(--toggle-border);
    background: var(--card); color: var(--card-text);
    font-size: 16px; font-weight: 700; text-align: left;
    transition: background 0.15s, border-color 0.15s;
}
.toggle-card .toggle-label { flex: 1; }
.toggle-card.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

.row-card {
    width: 100%; border: 0; border-radius: 22px;
    padding: 14px 16px;
    display: flex; align-items: center; gap: 14px; text-align: left;
    background: var(--card); color: var(--card-text); box-shadow: var(--shadow);
}
.row-card .icon-chip { width: 40px; height: 40px; border-radius: 14px; }
.row-text { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.row-title { font-size: 16px; font-weight: 700; }
.row-sub { font-size: 13px; font-weight: 500; color: var(--card-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-card > .icon:last-child { color: var(--card-muted); flex: none; }

/* ---------- Generic cards (Settings, History) ---------- */

.card {
    border-radius: var(--radius);
    padding: 16px;
    background: var(--card); color: var(--card-text);
    box-shadow: var(--shadow);
}
.card-header { display: flex; align-items: center; gap: 8px; width: 100%; padding: 0 0 6px; background: none; border: 0; text-align: left; color: inherit; }
.card-title { flex: 1; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--card-muted); }
.card-summary { font-size: 14px; color: var(--card-muted); }
.card-chevron { color: var(--card-muted); transition: transform 0.2s; }
.card-collapsible.collapsed .card-chevron { transform: rotate(-90deg); }
.card-collapsible.collapsed .card-header { padding-bottom: 0; }
.card-body > p { color: var(--card-muted); font-size: 14px; padding: 4px 0 8px; }

.field {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    min-height: 52px;
    border-bottom: 1px solid var(--card-line);
}
.field:last-child { border-bottom: 0; }
.field-label { font-size: 16px; font-weight: 600; }
.field-input { display: flex; align-items: baseline; gap: 6px; }
.field input {
    width: 7ch; padding: 6px 0;
    text-align: right;
    font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums;   /* >= 16px: no iOS zoom */
    background: transparent; border: 0; outline: none; color: var(--card-text);
}
.field input.field-text { width: 12ch; font-size: 18px; font-weight: 700; }
.field input::placeholder { color: var(--card-muted); opacity: 0.5; font-weight: 500; }
.field input:focus { color: var(--card-accent); }
.field.invalid input { color: var(--danger); }
.field-unit { font-size: 14px; font-weight: 600; color: var(--card-muted); min-width: 2.5ch; }
.field-group-title { font-size: 14px; font-weight: 800; padding-top: 10px; }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--card-line); font-size: 15px; }
.kv:last-child { border-bottom: 0; }
.kv > span:first-child { color: var(--card-muted); }
.kv > span:last-child { font-weight: 700; }

.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--card-line); }
.list-row:last-child { border-bottom: 0; }
.list-row-main { flex: 1; min-width: 0; }
.list-row-title { display: flex; align-items: center; gap: 6px; font-weight: 700; }
.list-row-title .icon { color: var(--card-accent); }
.list-row-sub { font-size: 13px; color: var(--card-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row > .icon { color: var(--card-muted); flex: none; }

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 50px; padding: 0 18px;
    border: 0; border-radius: 16px;
    background: var(--card-tint); color: var(--card-accent);
    font-size: 16px; font-weight: 800;
}
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-danger { background: var(--danger-tint); color: var(--danger); }
.btn-ghost { background: transparent; color: var(--accent-text); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.45; }
.btn-row { display: flex; gap: 10px; padding-top: 8px; }
.btn-row > .btn { flex: 1; }

/* ---------- Segmented control ---------- */

.segmented { display: flex; padding: 3px; border-radius: 14px; background: var(--card-track); }
.segmented button {
    flex: 1; min-height: 40px; border: 0; border-radius: 11px; background: transparent;
    font-size: 14px; font-weight: 700; color: var(--card-muted);
}
.segmented button.selected { background: var(--card); color: var(--card-text); box-shadow: 0 1px 3px rgba(60, 30, 10, 0.12); }

/* ---------- Bottom sheet + number pad ---------- */

.sheet-backdrop {
    position: fixed; inset: 0; z-index: 40;
    background: rgba(42, 26, 16, 0.38);
    animation: fade-in 0.2s ease-out;
}
.sheet {
    position: fixed; left: 50%; bottom: 0; z-index: 41;
    width: min(640px, 100%);
    max-height: calc(100dvh - env(safe-area-inset-top) - 24px);
    overflow-y: auto;
    transform: translateX(-50%);
    border-radius: 32px 32px 0 0;
    padding: 10px var(--space) calc(env(safe-area-inset-bottom) + 20px);
    display: flex; flex-direction: column; gap: 14px;
    background: var(--sheet-bg); color: var(--card-text);
    animation: sheet-up 0.28s cubic-bezier(0.2, 0.9, 0.3, 1);
}
.sheet-grabber { width: 40px; height: 5px; border-radius: 3px; background: #E6D4C7; align-self: center; }
.sheet-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sheet-header h2 { font-size: 22px; font-weight: 800; }
.sheet-sub { font-size: 13px; font-weight: 600; color: var(--card-muted); }
.sheet .icon-btn { box-shadow: none; }
.sheet .card { box-shadow: none; }

.stepper { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; }
.round-btn {
    width: 56px; height: 56px; flex: none;
    border-radius: 28px; border: 0;
    display: grid; place-items: center;
    background: var(--card-tint); color: var(--card-accent);
}
.big-value { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.big-number { font-size: 58px; font-weight: 800; letter-spacing: -0.03em; line-height: 1; font-variant-numeric: tabular-nums; }
.big-unit { font-size: 22px; font-weight: 700; color: var(--card-muted); letter-spacing: 0; }
.big-hint { font-size: 13px; font-weight: 600; color: var(--card-muted); text-align: center; }

.keypad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.key {
    height: 58px; border: 0; border-radius: 18px;
    display: grid; place-items: center;
    background: var(--card); color: var(--card-text);
    font-size: 24px; font-weight: 700;
    box-shadow: 0 1px 2px rgba(60, 30, 10, 0.05);
}
.key:active { background: var(--card-tint); }

@keyframes sheet-up { from { transform: translate(-50%, 100%); } to { transform: translate(-50%, 0); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet, .sheet-backdrop { animation: none; } }

/* ---------- Notices ---------- */

.notice {
    display: flex; gap: 12px; align-items: flex-start;
    padding: 14px 16px; border-radius: 20px;
    background: var(--card); color: var(--card-text); box-shadow: var(--shadow);
    font-size: 15px;
}
.notice .icon-chip { width: 36px; height: 36px; }
.notice strong { font-weight: 800; }
.notice p { color: var(--card-muted); font-size: 14px; margin-top: 2px; }
.notice.error .icon-chip { background: var(--danger-tint); color: var(--danger); }
.icon.inline { vertical-align: -3px; }

/* ---------- Misc ---------- */

.muted { color: var(--muted); }
.small { font-size: 13px; }
.text-danger { color: var(--danger) !important; }
.status-line { min-height: 20px; font-size: 13px; font-weight: 600; color: var(--muted); text-align: center; }
.empty-state { padding: 48px 16px; display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; color: var(--muted); }
.visually-hidden {
    position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.boot { min-height: 100dvh; display: grid; place-items: center; align-content: center; gap: 16px; color: var(--muted); font-weight: 600; }
.boot img { width: 72px; height: 72px; border-radius: 18px; }

.update-bar {
    position: fixed; left: 16px; right: 16px; z-index: 30;
    bottom: calc(env(safe-area-inset-bottom) + 92px);
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 10px 10px 10px 18px; border-radius: 20px;
    background: var(--card); color: var(--card-text);
    box-shadow: 0 10px 30px rgba(60, 30, 10, 0.2);
    font-size: 15px; font-weight: 600;
}
.update-bar button { border: 0; border-radius: 14px; padding: 10px 16px; background: var(--accent); color: var(--on-accent); font-weight: 800; }

#blazor-error-ui {
    display: none;
    position: fixed; inset: auto 0 0 0; z-index: 50;
    padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px);
    background: var(--danger); color: #fff;
}
#blazor-error-ui .reload { color: #fff; font-weight: 800; margin-left: 8px; }
#blazor-error-ui .dismiss { float: right; cursor: pointer; }
