/* Sahtek: whitewashed walls and blue doors (Sidi Bou Said), harissa red for warnings. */
:root {
  --wall: #f4f7f9;
  --card: #ffffff;
  --ink: #10283a;
  --ink-2: #4a6073;
  --line: #dde6ec;
  --door: #1b5ea6;
  --door-deep: #0f3f73;
  --door-tint: #e6eff8;
  --harissa: #c93a1e;
  --harissa-tint: #fbe9e5;
  --saffron: #d99a12;
  --olive: #5f7a2b;
  --shadow-sheet: 0 -8px 30px rgba(16, 40, 58, 0.18);
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --wall: #0b1a26;
    --card: #11273a;
    --ink: #e8f0f6;
    --ink-2: #9db3c4;
    --line: #213a50;
    --door: #5aa0e6;
    --door-deep: #8cc0f5;
    --door-tint: #17324b;
    --harissa: #ff7a5c;
    --harissa-tint: #3a1d17;
    --saffron: #f0b43a;
    --olive: #9bbd54;
    --shadow-sheet: 0 -8px 30px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--wall); color: var(--ink); }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, 'Noto Sans Arabic', 'Geeza Pro', Tahoma, sans-serif;
  font-size: 16px; line-height: 1.45; min-height: 100vh;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
html[dir='rtl'] body { line-height: 1.6; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.6rem; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
.muted { color: var(--ink-2); }
.small { font-size: 0.85rem; }
.num { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 3px solid var(--door); outline-offset: 2px; }

/* ---------- layout ---------- */
.wrap { max-width: 520px; margin: 0 auto; padding: 0 16px; }
.screen { padding-block: 14px 24px; display: grid; gap: 14px; }
.top {
  position: sticky; top: 0; z-index: 20; background: var(--wall);
  padding-top: env(safe-area-inset-top);
}
.top::after { /* a strip of blue tiles */
  content: ''; display: block; height: 6px;
  background: conic-gradient(from 45deg at 50% 50%, var(--door) 25%, transparent 0 50%, var(--door) 0 75%, transparent 0) 0 0 / 12px 12px;
  opacity: 0.85;
}
.top .wrap { display: flex; align-items: center; justify-content: space-between; gap: 10px; height: 54px; }
.brand { font-weight: 800; font-size: 1.25rem; color: var(--door-deep); letter-spacing: 0.01em; }
.langs { display: flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--card); }
.langs button { border: 0; background: transparent; padding: 6px 11px; font-size: 0.85rem; font-weight: 700; color: var(--ink-2); }
.langs button[aria-pressed='true'] { background: var(--door); color: #fff; }
.pill { font-size: 0.78rem; border-radius: 999px; padding: 3px 10px; background: var(--door-tint); color: var(--door-deep); border: 0; }
.pill.warn { background: var(--harissa-tint); color: var(--harissa); }
.statusbar { display: flex; justify-content: flex-start; }

/* ---------- cards & controls ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.card.flat { padding: 0; overflow: hidden; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack { display: grid; gap: 10px; }
.btn {
  border: 1px solid var(--door); background: var(--door); color: #fff; font-weight: 700;
  border-radius: 10px; padding: 11px 16px; min-height: 44px;
}
.btn.ghost { background: transparent; color: var(--door-deep); }
.btn.danger { background: transparent; color: var(--harissa); border-color: var(--harissa); }
.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 0.9rem; }
.btn:disabled { opacity: 0.5; }
.iconbtn { border: 1px solid var(--line); background: var(--card); border-radius: 10px; width: 44px; height: 44px; display: grid; place-items: center; font-size: 1.2rem; }
.link { background: none; border: 0; color: var(--door-deep); font-weight: 600; padding: 6px 2px; text-decoration: underline; text-underline-offset: 3px; }
label.field { display: grid; gap: 4px; font-weight: 600; font-size: 0.9rem; }
.field input, .field select, .input {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 11px 12px; min-height: 46px; font-weight: 400;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.err { color: var(--harissa); font-size: 0.9rem; font-weight: 600; }
.ok { color: var(--olive); font-weight: 600; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 8px 14px; white-space: nowrap; font-weight: 600; font-size: 0.9rem; min-height: 38px;
}
.chip[aria-pressed='true'] { background: var(--door); border-color: var(--door); color: #fff; }

/* ---------- the plate (today) ---------- */
.plate { display: grid; place-items: center; padding-block: 6px 2px; }
.plate svg { width: min(78vw, 250px); height: auto; overflow: visible; }
.plate .rim { fill: none; stroke: var(--line); stroke-width: 1.5; stroke-dasharray: 2 5; }
.plate .track { fill: none; stroke: var(--door-tint); stroke-width: 18; }
.plate .arc { fill: none; stroke: var(--door); stroke-width: 18; stroke-linecap: round; transition: stroke-dashoffset 0.6s ease; }
.plate.over .arc { stroke: var(--harissa); }
.plate .big { font-size: 2.7rem; font-weight: 800; fill: var(--ink); font-variant-numeric: tabular-nums; }
.plate.over .big { fill: var(--harissa); }
.plate .lbl { font-size: 0.95rem; fill: var(--ink-2); }
.plate .sub { font-size: 0.8rem; fill: var(--ink-2); }
@media (prefers-reduced-motion: reduce) { .plate .arc { transition: none; } }

.macros { display: grid; gap: 10px; }
.macro { display: grid; grid-template-columns: 78px 1fr auto; align-items: center; gap: 10px; font-size: 0.9rem; }
.bar { height: 8px; border-radius: 99px; background: var(--door-tint); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--c, var(--door)); }
.c-p { --c: var(--door); } .c-c { --c: var(--saffron); } .c-f { --c: var(--olive); }

.datenav { display: flex; align-items: center; justify-content: space-between; }
.datenav .label { font-weight: 800; font-size: 1.05rem; }

.meal-h { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; }
.meal-h h3 { font-size: 1rem; }
.entry { display: flex; align-items: center; gap: 10px; width: 100%; text-align: start; background: none; border: 0; border-top: 1px solid var(--line); padding: 11px 14px; }
.entry .nm { font-weight: 600; }
.entry .kc { font-weight: 700; }
.empty { padding: 14px; color: var(--ink-2); font-size: 0.9rem; border-top: 1px solid var(--line); }
.water { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.drops { display: flex; flex-wrap: wrap; gap: 5px; }
.drop { width: 16px; height: 22px; border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%; border: 2px solid var(--door); }
.drop.on { background: var(--door); }

/* ---------- lists ---------- */
.list { display: grid; }
.item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: start; background: none; border: 0; border-top: 1px solid var(--line); padding: 12px 14px; min-height: 56px; }
.list > .item:first-child, .list > :first-child .item { border-top: 0; }
.item .t { font-weight: 600; }
.badge { font-size: 0.72rem; font-weight: 700; border-radius: 6px; padding: 2px 7px; background: var(--door-tint); color: var(--door-deep); }
.idea { padding: 14px; display: grid; gap: 8px; }
.idea + .idea { border-top: 1px solid var(--line); }
.macrorow { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 0.88rem; font-weight: 600; }

/* ---------- bottom nav ---------- */
.nav {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 30; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav .wrap { display: grid; grid-template-columns: repeat(5, 1fr); height: var(--nav-h); padding: 0; }
.nav button { border: 0; background: none; display: grid; place-items: center; align-content: center; gap: 2px; font-size: 0.74rem; font-weight: 700; color: var(--ink-2); }
.nav button svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav button[aria-current='page'] { color: var(--door-deep); }
.nav .plus { color: #fff; }
.nav .plus span { width: 46px; height: 46px; border-radius: 50%; background: var(--door); display: grid; place-items: center; margin-top: -14px; border: 3px solid var(--wall); }
.nav .plus svg { stroke: #fff; }

/* ---------- sheets ---------- */
.scrim { position: fixed; inset: 0; background: rgba(8, 20, 30, 0.55); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--card); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 20px 20px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-sheet); display: grid; gap: 14px; animation: rise 0.22s ease;
}
@keyframes rise { from { transform: translateY(24px); opacity: 0.4; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }
.sheet header { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 10px 6px; font-weight: 700; font-size: 0.9rem; }
.seg button[aria-pressed='true'] { background: var(--door); color: #fff; }
.preview { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; background: var(--door-tint); border-radius: 12px; padding: 10px 6px; }
.preview b { display: block; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.preview span { font-size: 0.78rem; color: var(--ink-2); }
video.cam { width: 100%; aspect-ratio: 4 / 3; background: #000; border-radius: 12px; object-fit: cover; }
.camwrap { position: relative; }
.camwrap::after { content: ''; position: absolute; inset-inline: 10%; top: 50%; height: 2px; background: var(--harissa); opacity: 0.85; }

.toast {
  position: fixed; inset-inline: 16px; bottom: calc(var(--nav-h) + 14px + env(safe-area-inset-bottom)); z-index: 60; margin-inline: auto; width: fit-content; max-width: 90vw;
  background: var(--ink); color: var(--wall); border-radius: 10px; padding: 10px 16px; font-weight: 600; font-size: 0.92rem; opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.toast.show { opacity: 1; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; align-content: center; gap: 18px; padding-block: 28px; }
.auth h1 { font-size: 2.3rem; color: var(--door-deep); }
.tiles { height: 14px; width: 120px; border-radius: 3px; background: conic-gradient(from 45deg at 50% 50%, var(--door) 25%, transparent 0 50%, var(--door) 0 75%, transparent 0) 0 0 / 14px 14px; }

/* ---------- charts ---------- */
.chart { direction: ltr; width: 100%; height: auto; display: block; }
.chart text { fill: var(--ink-2); font-size: 10px; }
.chart .gridl { stroke: var(--line); stroke-width: 1; }
.chart .tgt { stroke: var(--harissa); stroke-width: 1.5; stroke-dasharray: 4 3; }
.chart .bar-rect { fill: var(--door); }
.chart .bar-rect.over { fill: var(--harissa); }
.chart .line { fill: none; stroke: var(--door); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--door); }
.goalopt { display: grid; gap: 2px; text-align: start; width: 100%; border: 1.5px solid var(--line); background: var(--card); border-radius: 12px; padding: 11px 13px; }
.goalopt[aria-pressed='true'] { border-color: var(--door); background: var(--door-tint); }
.goalopt b { font-size: 1rem; }
.stat { display: grid; text-align: center; }
.stat b { font-size: 1.3rem; font-variant-numeric: tabular-nums; }
