/* Meals & Workout Planner — local tracker.
   Touch targets are 48px minimum and bottom-anchored throughout: bilateral
   wrist and elbow pain means small targets near the top of the screen require
   extending and rotating the wrist, many times a day.
   Logical properties (margin-inline etc.) everywhere so the Arabic RTL toggle
   costs nothing. */

:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #f0efeb;
  --line: #e2e0da;
  --line-strong: #cfccc3;
  --ink: #1a1a17;
  --ink-2: #55534c;
  --ink-3: #8b887f;
  --accent: #2f6f4e;
  --accent-ink: #ffffff;
  --accent-soft: #e6f0ea;
  --warn: #9a5b1a;
  --warn-soft: #fbf0e2;
  --danger: #a33227;
  --danger-soft: #fbeae8;
  --ok: #2f6f4e;
  --info: #2b5a80;
  --info-soft: #e6eef5;
  --radius: 14px;
  --radius-sm: 9px;
  --tap: 48px;
  --pad: 16px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans Arabic", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 14px rgba(0,0,0,.04);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14140f;
    --surface: #1d1d18;
    --surface-2: #26261f;
    --line: #32322a;
    --line-strong: #45443a;
    --ink: #f0efe8;
    --ink-2: #b4b2a7;
    --ink-3: #85837a;
    --accent: #6cc39a;
    --accent-ink: #10231a;
    --accent-soft: #1c3128;
    --warn: #e0a860;
    --warn-soft: #33270f;
    --danger: #f08a7c;
    --danger-soft: #3a1c18;
    --ok: #6cc39a;
    --info: #8bbde5;
    --info-soft: #16283a;
    --shadow: 0 1px 2px rgba(0,0,0,.35), 0 4px 16px rgba(0,0,0,.28);
  }
}
:root[data-theme="dark"] {
  --bg: #14140f; --surface: #1d1d18; --surface-2: #26261f; --line: #32322a;
  --line-strong: #45443a; --ink: #f0efe8; --ink-2: #b4b2a7; --ink-3: #85837a;
  --accent: #6cc39a; --accent-ink: #10231a; --accent-soft: #1c3128;
  --warn: #e0a860; --warn-soft: #33270f; --danger: #f08a7c; --danger-soft: #3a1c18;
  --ok: #6cc39a; --info: #8bbde5; --info-soft: #16283a;
  --shadow: 0 1px 2px rgba(0,0,0,.35), 0 4px 16px rgba(0,0,0,.28);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: 16px; line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
h1, h2, h3, h4 { margin: 0; font-weight: 650; line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0 0 10px; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }

/* ------------------------------------------------------------- layout --- */
#app { padding-block-end: calc(var(--tap) + 34px + env(safe-area-inset-bottom)); }
.screen { max-width: 720px; margin-inline: auto; padding: var(--pad); }

.appbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-block-end: 1px solid var(--line);
}
.appbar-inner {
  max-width: 720px; margin-inline: auto;
  display: flex; align-items: center; gap: 10px;
  padding: 10px var(--pad); min-height: 56px;
}
.appbar h1 { flex: 1; font-size: 19px; }
.appbar .sub { color: var(--ink-3); font-size: 13px; font-weight: 500; }

/* ---------------------------------------------------------------- nav --- */
.tabbar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-block-start: 1px solid var(--line);
  padding-block-end: env(safe-area-inset-bottom);
}
.tabbar button {
  min-height: var(--tap); border: 0; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; padding: 6px 2px 8px; color: var(--ink-3); font-size: 11px; font-weight: 600;
  letter-spacing: .01em;
}
.tabbar button .ic { font-size: 19px; line-height: 1; }
.tabbar button[aria-current="page"] { color: var(--accent); }

/* --------------------------------------------------------------- card --- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin-block-end: 12px;
  box-shadow: var(--shadow);
}
.card.tight { padding: 10px 12px; }
.card-head { display: flex; align-items: baseline; gap: 8px; margin-block-end: 10px; }
.card-head h2 { flex: 1; }
.card-head .meta { color: var(--ink-3); font-size: 12px; font-weight: 600; }

.section-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em;
  color: var(--ink-3); margin: 20px 0 8px;
}

.muted { color: var(--ink-2); }
.dim { color: var(--ink-3); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.num { font-variant-numeric: tabular-nums; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-block-start: 8px; }
.hr { height: 1px; background: var(--line); margin: 12px 0; border: 0; }

/* -------------------------------------------------------------- banner --- */
.banner {
  border-radius: var(--radius); padding: 12px 14px; margin-block-end: 12px;
  border: 1px solid var(--line);
}
.banner h3 { margin-block-end: 4px; font-size: 14px; }
.banner p { margin: 0; font-size: 13px; }
.banner.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.banner.warn h3 { color: var(--warn); }
.banner.info { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 30%, transparent); }
.banner.info h3 { color: var(--info); }
.banner.danger { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.banner.danger h3 { color: var(--danger); }
.banner.ok { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.banner.ok h3 { color: var(--accent); }

/* ------------------------------------------------------------- buttons --- */
.btn {
  min-height: var(--tap); border-radius: var(--radius-sm); border: 1px solid var(--line-strong);
  background: var(--surface); padding: 0 16px; cursor: pointer; font-weight: 600; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.danger { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 40%, transparent); color: var(--danger); }
.btn.block { width: 100%; }
.btn.sm { min-height: 38px; font-size: 14px; padding: 0 12px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; min-width: 120px; }

/* Bottom-anchored primary action bar. */
.actionbar {
  position: sticky; bottom: calc(var(--tap) + env(safe-area-inset-bottom) + 6px);
  z-index: 15; display: flex; gap: 8px; padding: 8px 0 4px;
}
.actionbar .btn { flex: 1; box-shadow: var(--shadow); }

/* --------------------------------------------------------------- forms --- */
label.field { display: block; margin-block-end: 12px; }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-block-end: 5px; }
input[type=text], input[type=number], input[type=date], input[type=time], input[type=search], select, textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { min-height: 88px; resize: vertical; line-height: 1.5; }
input[type=range] { width: 100%; height: var(--tap); }
.field-row { display: flex; gap: 10px; }
.field-row > * { flex: 1; }

.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button {
  min-height: 40px; padding: 0 12px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--surface);
  font-size: 14px; font-weight: 600; color: var(--ink-2);
}
.seg button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* ---------------------------------------------------------- check rows --- */
.checkrow {
  display: flex; align-items: center; gap: 12px; width: 100%;
  min-height: 60px; padding: 10px 12px; cursor: pointer; text-align: start;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  margin-block-end: 8px; -webkit-tap-highlight-color: transparent;
}
.checkrow:active { background: var(--surface-2); }
.checkrow .tick {
  flex: none; width: 34px; height: 34px; border-radius: 50%;
  border: 2px solid var(--line-strong); display: grid; place-items: center;
  font-size: 17px; color: transparent; transition: all .12s ease;
}
.checkrow[aria-pressed="true"] .tick { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.checkrow[aria-pressed="true"] .title { text-decoration: line-through; color: var(--ink-3); }
.checkrow .body { flex: 1; min-width: 0; }
.checkrow .title { font-weight: 620; font-size: 15px; }
.checkrow .sub { font-size: 12.5px; color: var(--ink-3); margin-block-start: 2px; }
.checkrow .side { flex: none; text-align: end; font-size: 12px; color: var(--ink-3); font-weight: 600; }
.checkrow .time {
  flex: none; font-family: var(--mono); font-size: 12px; font-weight: 700;
  color: var(--ink-3); width: 44px;
}

/* ---------------------------------------------------------------- meta --- */
.pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700; background: var(--surface-2); color: var(--ink-2);
  border: 1px solid var(--line);
}
.pill.ok { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.pill.info { background: var(--info-soft); color: var(--info); border-color: transparent; }

/* --------------------------------------------------------------- stats --- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: 8px; }
.stat { background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px; text-align: center; }
.stat .v { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat .l { font-size: 11px; color: var(--ink-3); font-weight: 600; margin-block-start: 3px; }
.stat .s { font-size: 11px; color: var(--ink-3); }

.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .25s ease; }
.bar.over > i { background: var(--warn); }
.bar.protein > i { background: var(--info); }

.macro-line { display: flex; gap: 8px; font-size: 12px; color: var(--ink-2); font-weight: 600; }
.macro-line span { white-space: nowrap; }

/* --------------------------------------------------------------- table --- */
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { text-align: start; padding: 8px 10px; border-block-end: 1px solid var(--line); vertical-align: top; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); font-weight: 700; }
td.num, th.num { text-align: end; font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------- chart --- */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--ink-3); font-size: 10px; font-family: var(--font); }
.chart .dot { fill: var(--ink-3); }
.chart .dot.out { fill: none; stroke: var(--danger); stroke-width: 1.5; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .line2 { fill: none; stroke: var(--info); stroke-width: 2; stroke-dasharray: 4 3; }
.chart .band { fill: var(--accent-soft); opacity: .55; }

/* --------------------------------------------------------------- ring --- */
.ring { display: flex; align-items: center; gap: 14px; }
.ring svg { flex: none; }
.ring .track { fill: none; stroke: var(--surface-2); stroke-width: 9; }
.ring .val { fill: none; stroke: var(--accent); stroke-width: 9; stroke-linecap: round; transform: rotate(-90deg); transform-origin: 50% 50%; }

/* --------------------------------------------------------------- sheet --- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.42);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease;
}
.sheet {
  background: var(--bg); width: 100%; max-width: 720px;
  border-radius: 18px 18px 0 0; max-height: 90vh; overflow-y: auto;
  padding: 8px var(--pad) calc(var(--pad) + env(safe-area-inset-bottom));
  animation: rise .2s cubic-bezier(.2,.8,.3,1);
}
.sheet-grip { width: 38px; height: 4px; border-radius: 99px; background: var(--line-strong); margin: 6px auto 12px; }
.sheet h2 { margin-block-end: 10px; }
@keyframes fade { from { opacity: 0 } }
@keyframes rise { from { transform: translateY(18px); opacity: .5 } }

/* --------------------------------------------------------------- toast --- */
#toast {
  position: fixed; inset-inline: 0; bottom: calc(var(--tap) + env(safe-area-inset-bottom) + 16px);
  z-index: 50; display: flex; justify-content: center; pointer-events: none;
}
#toast .t {
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 99px;
  font-size: 14px; font-weight: 600; box-shadow: var(--shadow); animation: rise .18s ease;
  max-width: 90%;
}

/* ------------------------------------------------------------ listitem --- */
.listitem {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: start;
  min-height: var(--tap); padding: 8px 12px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  margin-block-end: 6px; cursor: pointer;
}
.listitem:active { background: var(--surface-2); }
.listitem .n { flex: 1; min-width: 0; font-weight: 600; font-size: 14.5px; }
.listitem .k { font-size: 12px; color: var(--ink-3); font-weight: 600; white-space: nowrap; }

.entry {
  display: flex; align-items: center; gap: 10px; padding: 7px 0;
  border-block-end: 1px solid var(--line);
}
.entry:last-child { border: 0; }
.entry .n { flex: 1; min-width: 0; font-size: 14px; }
.entry .n small { display: block; color: var(--ink-3); font-size: 11.5px; }
.entry .k { font-size: 13px; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.entry .x { border: 0; background: none; color: var(--ink-3); cursor: pointer; font-size: 18px; width: 34px; height: 34px; }

.empty { text-align: center; color: var(--ink-3); padding: 26px 12px; font-size: 14px; }

details.disclosure { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0; margin-block-end: 8px; background: var(--surface); }
details.disclosure > summary { cursor: pointer; padding: 12px 14px; font-weight: 620; font-size: 14.5px; min-height: var(--tap); display: flex; align-items: center; }
details.disclosure > div { padding: 0 14px 12px; font-size: 13.5px; color: var(--ink-2); }
details.disclosure ul { margin: 0; padding-inline-start: 20px; }
details.disclosure li { margin-block-end: 5px; }

ul.plain { list-style: none; margin: 0; padding: 0; }
ul.bullets { margin: 0; padding-inline-start: 20px; }
ul.bullets li { margin-block-end: 5px; }

.kv { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-block-end: 1px solid var(--line); font-size: 13.5px; }
.kv:last-child { border: 0; }
.kv .k { color: var(--ink-2); }
.kv .v { font-weight: 650; font-variant-numeric: tabular-nums; text-align: end; }

[dir="rtl"] .checkrow .time { text-align: end; }

.mealrow { display: flex; gap: 6px; align-items: stretch; margin-block-end: 8px; }
.mealrow .checkrow { flex: 1; margin-block-end: 0; }
.mealrow .more {
  flex: none; width: 46px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--ink-3); font-size: 17px; cursor: pointer;
}
.mealrow .more:active { background: var(--surface-2); }
.setgrid { display: grid; grid-template-columns: 26px 1fr 1fr 1fr 34px; gap: 6px; align-items: center; margin-block-end: 6px; }
.setgrid input { min-height: 42px; padding: 6px 8px; text-align: center; }
.setgrid .ix { font-size: 12px; font-weight: 700; color: var(--ink-3); text-align: center; }
.setgrid .hd { font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); font-weight: 700; text-align: center; }
.setgrid .rm { border: 0; background: none; color: var(--ink-3); font-size: 16px; cursor: pointer; min-height: 42px; }

/* Saturated fat past the 16 g/day ceiling — 03-MEALS-AND-FOOD.md. Colour plus
   a weight change, so it doesn't rely on colour alone. */
.macro-line .over-cap { color: var(--warn); font-weight: 700; }
