@font-face { font-family: Figtree; src: url('../fonts/Figtree-Variable.ttf') format('truetype'); font-style: normal; font-weight: 300 900; font-display: swap; }
@font-face { font-family: "Noto Sans"; src: url('../fonts/NotoSans-Variable.ttf') format('truetype'); font-style: normal; font-weight: 100 900; font-display: swap; }

:root {
  color-scheme: light;
  --background: #F3FAFC;
  --surface: #FFFFFF;
  --text: #123247;
  --primary: #075985;
  --secondary: #0E7490;
  --berry: #4C3F91;
  --focus: #2563EB;
  --within: #0F766E;
  --outside: #9A3412;
  --muted: #526B7A;
  --border: #BCD4DF;
  --soft: #E4F1F5;
  --danger-soft: #FFF1EB;
  --shadow: 0 12px 34px rgba(18, 50, 71, .09);
  --radius-sm: .75rem;
  --radius-md: 1.125rem;
  --radius-lg: 1.5rem;
  --content: 72rem;
  --font-heading: Figtree, "Segoe UI", sans-serif;
  --font-body: "Noto Sans", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 0; overflow-x: clip; background: var(--background); scroll-behavior: smooth; scrollbar-gutter: stable; }
body { margin: 0; overflow-x: clip; background: var(--background); color: var(--text); font: 400 1rem/1.55 var(--font-body); }
button, input, textarea, select { color: inherit; font: inherit; }
button, a, select, input[type="checkbox"], input[type="radio"] { cursor: pointer; }
a { color: var(--primary); }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3, .brand strong { font-family: var(--font-heading); letter-spacing: -.02em; }
h1 { margin-bottom: .25rem; font-size: clamp(2rem, 7vw, 3rem); line-height: 1.05; }
h2 { margin-bottom: .5rem; font-size: 1.2rem; line-height: 1.25; }
svg { display: block; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.is-hidden, [hidden] { display: none !important; }

.skip-link { position: fixed; z-index: 100; top: .5rem; left: .5rem; padding: .65rem 1rem; border-radius: .5rem; background: var(--text); color: #fff; transform: translateY(-150%); }
.skip-link:focus { transform: translateY(0); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.app-header { position: sticky; z-index: 10; top: 0; display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 4.5rem; padding: max(.75rem, env(safe-area-inset-top)) clamp(1rem, 4vw, 2rem) .75rem; border-bottom: 1px solid rgba(188, 212, 223, .75); background: rgba(243, 250, 252, .96); }
.brand { display: inline-flex; align-items: center; gap: .7rem; color: var(--text); text-decoration: none; }
.brand-mark { display: grid; width: 2.5rem; height: 2.5rem; place-items: center; border-radius: 50% 50% 48% 52%; background: var(--berry); color: #fff; font: 700 1.25rem/1 var(--font-heading); box-shadow: 0 5px 14px rgba(76, 63, 145, .22); }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 1.1rem; line-height: 1.1; }
.brand small { margin-top: .1rem; color: var(--muted); font-size: .72rem; }
.sync-pill { display: flex; align-items: center; gap: .45rem; margin: 0; color: var(--muted); font-size: .8rem; }
.status-dot { width: .6rem; height: .6rem; border: 2px solid var(--surface); border-radius: 50%; background: var(--secondary); box-shadow: 0 0 0 1px var(--secondary); }
.sync-pill.is-pending .status-dot { background: var(--outside); box-shadow: 0 0 0 1px var(--outside); }

#app-main { width: min(100%, var(--content)); min-height: calc(100vh - 9.5rem); margin: 0 auto; padding: 1.5rem clamp(1rem, 4vw, 2.5rem) calc(7rem + env(safe-area-inset-bottom)); }
.view { animation: reveal .2s ease-out; }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.section-heading time { color: var(--muted); font-weight: 600; }
.eyebrow { margin-bottom: .25rem; color: var(--secondary); font-family: var(--font-heading); font-size: .75rem; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.notice { margin-bottom: 1rem; padding: .85rem 1rem; border: 1px solid #7FB5C8; border-radius: var(--radius-sm); background: #E8F7FA; }
.notice--archived { border-color: #B9ADDA; background: #F2F0FA; }

.slot-grid { display: grid; gap: 1rem; }
.slot-card { position: relative; overflow: hidden; padding: 1.25rem; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow); }
.slot-card::before { position: absolute; inset: 0 auto 0 0; width: .35rem; background: var(--secondary); content: ""; }
.slot-card[data-status="recorded"]::before { background: var(--within); }
.slot-card[data-status="queued"]::before { background: var(--outside); }
.slot-top { display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem; }
.slot-time { color: var(--muted); font-size: .9rem; }
.status-label { display: inline-flex; align-items: center; gap: .35rem; padding: .3rem .6rem; border-radius: 999px; background: var(--soft); color: var(--primary); font-size: .78rem; font-weight: 700; }
.slot-card[data-status="recorded"] .status-label { background: #DDF2EC; color: var(--within); }
.slot-card[data-status="queued"] .status-label { background: var(--danger-soft); color: var(--outside); }
.reading-result { margin: 1rem 0; }
.reading-result strong { font: 700 clamp(2.25rem, 9vw, 3.5rem)/1 var(--font-heading); }
.reading-result span { margin-left: .35rem; color: var(--muted); }
.objective-status { margin: -.5rem 0 1rem; font-weight: 700; }
.objective-status--within { color: var(--within); }
.objective-status--outside { color: var(--outside); }
.slot-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
.timer { margin: .85rem 0 0; color: var(--berry); font-weight: 700; }

.button { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: .7rem 1rem; border: 1px solid transparent; border-radius: .75rem; font-weight: 750; text-align: center; text-decoration: none; transition: background-color .2s ease, border-color .2s ease, box-shadow .2s ease, opacity .2s ease; }
.button:hover { box-shadow: 0 4px 14px rgba(18, 50, 71, .14); }
.button:active { opacity: .78; }
.button:disabled, .button[aria-disabled="true"] { cursor: not-allowed; opacity: .48; box-shadow: none; }
.button--primary { background: var(--primary); color: #fff; }
.button--primary:hover { background: #064C70; }
.button--secondary { border-color: var(--primary); background: var(--surface); color: var(--primary); }
.button--danger { border-color: #CBA087; background: var(--surface); color: var(--outside); }
.button-stack { display: grid; gap: .75rem; width: 100%; margin-top: 1.5rem; }
.text-link { display: inline-flex; min-height: 44px; align-items: center; font-weight: 700; }

.help-card, .settings-card, .chart-card, .report-card { border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); box-shadow: 0 5px 18px rgba(18, 50, 71, .05); }
.help-card { display: flex; gap: 1rem; margin-top: 1.5rem; padding: 1rem; }
.help-card p, .settings-card p, .report-card p { margin-bottom: 0; color: var(--muted); }
.icon-wrap { flex: 0 0 auto; display: grid; width: 2.75rem; height: 2.75rem; place-items: center; border-radius: .85rem; background: var(--soft); color: var(--primary); }
.icon-wrap svg { width: 1.5rem; height: 1.5rem; }
.icon-wrap--large { width: 3.5rem; height: 3.5rem; margin: 0 auto 1rem; color: var(--berry); }

.filter-bar { display: grid; gap: .75rem; margin-bottom: 1rem; padding: 1rem; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); }
label, legend { color: var(--text); font-weight: 700; }
label { display: grid; gap: .4rem; }
input, select, textarea { width: 100%; min-height: 44px; padding: .7rem .8rem; border: 1px solid #8DAAB8; border-radius: .65rem; background: var(--surface); }
textarea { resize: vertical; }
input:hover, select:hover, textarea:hover { border-color: var(--primary); }
.helper, .field-message, .field-error { margin: .35rem 0 .8rem; color: var(--muted); font-size: .87rem; }
.field-error { color: var(--outside); font-weight: 650; }
.chart-card { margin: 1rem 0; padding: 1rem; }
.card-heading p { margin-bottom: .5rem; color: var(--muted); font-size: .87rem; }
.trend-chart { width: 100%; min-height: 13rem; overflow: visible; color: var(--muted); }
.trend-chart .axis { stroke: #8DAAB8; stroke-width: 1; }
.trend-chart .grid { stroke: #D8E7EC; stroke-width: 1; }
.trend-chart .fasting-line { stroke: var(--primary); stroke-width: 3; }
.trend-chart .meal-line { stroke: var(--berry); stroke-width: 3; stroke-dasharray: 8 6; }
.trend-chart .point { fill: var(--surface); stroke-width: 3; }
.trend-chart text { fill: var(--muted); stroke: none; font: 12px var(--font-body); }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
caption { padding: 1rem; font-weight: 800; text-align: left; }
th, td { padding: .8rem 1rem; border-top: 1px solid var(--border); text-align: left; }
th { color: var(--muted); font-size: .78rem; text-transform: uppercase; }
.table-action { min-width: 44px; min-height: 44px; border: 0; border-radius: .5rem; background: var(--soft); color: var(--primary); font-weight: 700; }
.empty-state { padding: 2rem 1rem; border: 1px dashed #8DAAB8; border-radius: var(--radius-md); text-align: center; }
.report-card { max-width: 34rem; padding: 1.5rem; text-align: center; }
.settings-list { display: grid; gap: 1rem; }
.settings-card { padding: 1.25rem; }
.settings-card form { margin-top: 1rem; }
.settings-card dl { margin: 0; }
.settings-card dl div { display: flex; justify-content: space-between; gap: 1rem; padding: .75rem 0; border-bottom: 1px solid var(--border); }
.settings-card dd { margin: 0; font-weight: 750; }
.danger-zone { border-color: #DAB9A6; }

.bottom-nav { position: fixed; z-index: 20; inset: auto 0 0; display: grid; grid-template-columns: repeat(4, 1fr); padding: .45rem max(.5rem, env(safe-area-inset-right)) calc(.45rem + env(safe-area-inset-bottom)) max(.5rem, env(safe-area-inset-left)); border-top: 1px solid var(--border); background: rgba(255, 255, 255, .97); }
.bottom-nav a { display: grid; min-height: 56px; place-items: center; align-content: center; gap: .15rem; border-radius: .75rem; color: var(--muted); font-size: .72rem; font-weight: 700; text-decoration: none; transition: background-color .2s ease, color .2s ease; }
.bottom-nav a:hover, .bottom-nav a[aria-current="page"] { background: var(--soft); color: var(--primary); }
.bottom-nav svg { width: 1.4rem; height: 1.4rem; }

dialog { width: min(calc(100% - 2rem), 32rem); max-height: calc(100dvh - 2rem); padding: 0; overflow: auto; border: 0; border-radius: var(--radius-lg); background: var(--surface); box-shadow: 0 24px 70px rgba(18, 50, 71, .28); }
dialog::backdrop { background: rgba(11, 31, 43, .58); }
dialog form { display: grid; gap: .75rem; padding: 1.25rem; }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.icon-button { display: grid; flex: 0 0 44px; width: 44px; height: 44px; place-items: center; border: 0; border-radius: 50%; background: var(--soft); color: var(--text); }
.icon-button svg { width: 1.4rem; height: 1.4rem; }
.value-input { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: .5rem; padding-right: .8rem; border: 1px solid #8DAAB8; border-radius: .75rem; }
.value-input:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.value-input input { min-height: 64px; border: 0; font: 750 2rem/1 var(--font-heading); }
.value-input input:focus-visible { outline: 0; }
.value-input strong { color: var(--muted); }
.toast { position: fixed; z-index: 40; right: 1rem; bottom: calc(6rem + env(safe-area-inset-bottom)); max-width: min(24rem, calc(100% - 2rem)); padding: .8rem 1rem; border-radius: .75rem; background: var(--text); color: #fff; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translateY(.5rem); transition: opacity .2s ease, transform .2s ease; }
.toast.is-visible { opacity: 1; transform: translateY(0); }

.auth-page { min-height: 100vh; }
.auth-shell { width: min(100% - 2rem, 30rem); margin: 0 auto; padding: max(2rem, env(safe-area-inset-top)) 0 max(2rem, env(safe-area-inset-bottom)); }
.auth-shell--wide { width: min(100% - 2rem, 48rem); }
.brand--center { display: flex; width: max-content; margin: 0 auto 1.5rem; }
.auth-card { padding: clamp(1.25rem, 5vw, 2rem); border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow); }
.auth-card form { display: grid; gap: 1rem; margin: 1.25rem 0; }
.auth-card fieldset { display: grid; gap: .75rem; margin: 0; padding: 1rem; border: 1px solid var(--border); border-radius: var(--radius-md); }
.choice-card, .check-row { display: grid; grid-template-columns: auto 1fr; align-items: start; gap: .75rem; padding: .75rem; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.choice-card input, .check-row input { width: 1.25rem; min-height: 1.25rem; margin-top: .2rem; }
.choice-card strong, .choice-card small { display: block; }
.choice-card small { color: var(--muted); font-weight: 400; }
.form-grid { display: grid; gap: 1rem; }

@keyframes reveal { from { opacity: 0; transform: translateY(.35rem); } to { opacity: 1; transform: none; } }

@media (min-width: 44rem) {
  .slot-grid, .settings-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-bar { grid-template-columns: 1fr 1fr auto; align-items: end; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .report-card { margin: 2rem auto; padding: 2rem; }
}

@media (min-width: 60rem) {
  .bottom-nav { right: auto; left: 50%; width: min(calc(100% - 4rem), var(--content)); transform: translateX(-50%); border: 1px solid var(--border); border-bottom: 0; border-radius: 1rem 1rem 0 0; }
  .bottom-nav a { grid-template-columns: auto auto; place-content: center; gap: .5rem; }
}

@media (orientation: landscape) and (max-height: 32rem) { dialog { max-height: calc(100dvh - 1rem); } .app-header { position: static; } }
@media (max-width: 22.5rem) {
  .app-header, main { width: calc(100% - .9375rem); }
  .bottom-nav { right: .9375rem; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; } }
@media (forced-colors: active) { .status-dot, .slot-card::before { border: 1px solid CanvasText; } }
.chart-card { overflow: hidden; }
.trend-chart { min-width: 0; width: 100%; height: auto; }
.trend-chart text { font-size: 13px; fill: var(--text, #123247); }
.trend-chart .point:focus { outline: 2px solid #2563EB; outline-offset: 3px; }
.table-action { min-height: 44px; margin: 4px; }
.table-action:disabled { opacity: .55; cursor: not-allowed; }
img.brand-mark { object-fit: contain; flex-shrink: 0; padding: 0; }
@media (max-width: 40rem) {
  #history-table { min-width: 0; width: 100%; }
  #history-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  #history-table tbody, #history-table tr, #history-table td { display: block; }
  #history-table tr { padding: .75rem; border-bottom: 1px solid var(--border); }
  #history-table td { padding: .4rem .25rem; border: 0; white-space: normal; }
  #history-table td::before { content: attr(data-label); display: block; font-weight: 600; font-size: .8rem; color: var(--muted); }
}
