/* Design tokens.
 *
 * Both themes are defined here rather than toggled with a class on every
 * element, so dark mode is a single attribute on <html> and the OS preference
 * is respected when the user has not chosen.
 */
:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #16181d;
  --text-dim: #5b616e;
  --border: #e2e5ea;
  --accent: #2f6df6;
  --accent-text: #ffffff;
  --ok: #1f9d55;
  --warn: #c76a00;
  --danger: #d33a3a;
  --radius: 14px;
  --gap: 12px;
  --shadow: 0 1px 2px rgba(16, 20, 30, 0.06), 0 4px 16px rgba(16, 20, 30, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1e222b;
    --text: #e8eaee;
    --text-dim: #99a0ae;
    --border: #272c36;
    --accent: #5b8dff;
    --accent-text: #0b0d11;
    --ok: #3ecf8e;
    --warn: #e2a03f;
    --danger: #f06a6a;
    --shadow: none;
  }
}

:root[data-theme='dark'] {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1e222b;
  --text: #e8eaee;
  --text-dim: #99a0ae;
  --border: #272c36;
  --accent: #5b8dff;
  --accent-text: #0b0d11;
  --ok: #3ecf8e;
  --warn: #e2a03f;
  --danger: #f06a6a;
  --shadow: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Persian reads better with a font that has proper Arabic-script shaping and
   slightly more line height. */
html[lang='fa'] body {
  font-family: 'Vazirmatn', 'IRANSans', 'Segoe UI', Tahoma, system-ui, sans-serif;
  line-height: 1.75;
}

/* Logical properties throughout, so the entire layout mirrors for RTL without
   a single direction-specific rule. */
.app {
  max-width: 560px;
  margin-inline: auto;
  padding: 16px 16px 92px;
}

header.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  margin-block-end: 16px;
}

h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 8px; }

.muted { color: var(--text-dim); font-size: 0.9rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-block-end: var(--gap);
  box-shadow: var(--shadow);
}

.row { display: flex; align-items: center; gap: var(--gap); }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: var(--gap); }

/*
 * `a.button` exists so a control that navigates can look like a button without
 * pretending to be one: a link the browser can open in a new tab, middle-click
 * or read out as a link, rather than a button with an onclick that sets the
 * hash.
 */
button, a.button {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  min-height: 44px; /* comfortable tap target */
}
a.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  box-sizing: border-box;
}
button:hover, a.button:hover { border-color: var(--accent); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.primary, a.button.primary {
  background: var(--accent); color: var(--accent-text); border-color: transparent;
}
button.ghost, a.button.ghost { background: transparent; }
button.small, a.button.small { min-height: 36px; padding: 6px 10px; font-size: 0.9rem; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
  min-height: 44px;
}
label { display: block; font-size: 0.9rem; color: var(--text-dim); margin-block-end: 4px; }
.field { margin-block-end: var(--gap); }

/* Timeline ---------------------------------------------------------------- */

/*
 * Time and name on one line; actions on the next.
 *
 * Three columns across a phone leaves the buttons about ninety pixels each,
 * which truncates the labels and puts two tap targets within a thumb-width of
 * each other. The actions get their own row and the full width instead.
 */
.entry {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas: 'time name' '. actions';
  align-items: center;
  gap: 8px var(--gap);
  padding: 12px 0;
  border-block-end: 1px solid var(--border);
}
.entry .time { grid-area: time; }
.entry .name { grid-area: name; }
.entry > .row:last-child { grid-area: actions; flex-wrap: wrap; }
.entry:last-child { border-block-end: none; }

@media (min-width: 480px) {
  /* Room for all three on one line. */
  .entry {
    grid-template-columns: auto 1fr auto;
    grid-template-areas: 'time name actions';
  }
}

.entry .time {
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  font-size: 0.95rem;
  min-width: 3.5rem;
}
.entry .name { font-weight: 500; }
.entry.done .name { text-decoration: line-through; color: var(--text-dim); }

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.pill.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.pill.late { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.pill.missed { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }

/* Progress ---------------------------------------------------------------- */

.meter {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.meter > span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--gap); }
.stat .value { font-size: 1.4rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat .label { color: var(--text-dim); font-size: 0.85rem; }

/* Bottom navigation ------------------------------------------------------- */

nav.tabs {
  position: fixed;
  inset-block-end: 0;
  inset-inline: 0;
  display: flex;
  justify-content: center;
  gap: 4px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  border-block-start: 1px solid var(--border);
}
nav.tabs a {
  flex: 1 1 0;
  max-width: 120px;
  text-align: center;
  padding: 8px 4px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--text-dim);
  font-size: 0.82rem;
}
nav.tabs a[aria-current='page'] { color: var(--accent); background: var(--surface-2); }

/* Banners ----------------------------------------------------------------- */

.banner {
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-block-end: var(--gap);
  font-size: 0.92rem;
  border: 1px solid;
}
.banner.info { border-color: color-mix(in srgb, var(--accent) 35%, transparent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.banner.warn { border-color: color-mix(in srgb, var(--warn) 35%, transparent); background: color-mix(in srgb, var(--warn) 8%, transparent); }
.banner.error { border-color: color-mix(in srgb, var(--danger) 35%, transparent); background: color-mix(in srgb, var(--danger) 8%, transparent); }

/* Chat -------------------------------------------------------------------- */

.msg { padding: 10px 12px; border-radius: var(--radius); margin-block-end: 8px; max-width: 85%; }
.msg.user { background: var(--accent); color: var(--accent-text); margin-inline-start: auto; }
.msg.assistant { background: var(--surface-2); margin-inline-end: auto; white-space: pre-wrap; }

.msg .source {
  display: block;
  width: fit-content;
  margin-block-end: 6px;
  font-size: 0.72rem;
}

/*
 * The seconds before the first token.
 *
 * A remote model can take several seconds to begin, and for those seconds a
 * disabled button and an empty bubble look exactly like a broken app. The
 * pulse is the difference between "it is working on it" and "nothing
 * happened"; it is removed the instant real text arrives, and the
 * reduced-motion rule below turns it into plain text for anyone who asked
 * for that.
 */
.msg .thinking {
  display: inline-block;
  color: var(--muted);
  font-style: italic;
  animation: pulse 1.4s ease-in-out infinite;
}

.msg .note {
  display: block;
  margin-block-start: 6px;
  font-size: 0.78rem;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.chat-input { display: flex; gap: 8px; align-items: flex-end; }

/* Respect a user who prefers less motion. */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Routine adaptation review ------------------------------------------------
 *
 * Each proposal is a block with its own tick box, so accepting one change and
 * refusing another is a single tap each rather than an all-or-nothing choice.
 */

.proposal {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-block-start: 10px;
}
.proposal label { cursor: pointer; align-items: flex-start; }
.proposal input[type='checkbox'] {
  width: 22px;
  height: 22px;
  min-height: 22px;
  flex: none;
  accent-color: var(--accent);
}
.proposal .proposal-line { font-weight: 600; }
.proposal p { margin-block: 6px 0; }

p.small, span.small { font-size: 0.85rem; }

/* Dialogs ------------------------------------------------------------------
 *
 * `modal()` in lib/dom.js builds these. Without a stacking context above the
 * page the dialog renders in normal flow and the content behind it keeps
 * taking clicks, which is how a Save button ends up unpressable.
 */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: color-mix(in srgb, #000 55%, transparent);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  width: min(640px, 100%);
  /* Tall forms scroll inside the dialog rather than off the screen. */
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 18px 48px rgb(0 0 0 / 0.35);
}
.modal-title { font-size: 1.15rem; margin: 0 0 12px; }
.modal-body { overflow-y: auto; flex: 1; min-height: 0; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-block-start: 14px;
  flex: none;
}

@media (max-width: 560px) {
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal-card {
    max-height: 92vh;
    border-radius: var(--radius) var(--radius) 0 0;
    width: 100%;
  }
}

/* Choice chips ------------------------------------------------------------
 *
 * One tap per answer. A select would be fewer pixels and more taps, and this
 * is a screen someone is using while standing in a shop.
 */

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.92rem;
}
.chip[aria-checked='true'] {
  background: color-mix(in srgb, var(--accent) 18%, var(--surface-2));
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 500;
}
.field { margin-block-end: var(--gap); }
.field label { display: block; font-size: 0.85rem; color: var(--text-dim); margin-block-end: 6px; }
.stat .delta { font-size: 0.8rem; font-variant-numeric: tabular-nums; }

/* The overdue prompt ------------------------------------------------------
 *
 * The largest thing on the screen, because it is the one thing the app is
 * waiting on. It sits in the flow rather than over it: a modal that has to be
 * dismissed to reach the rest of the app is how a reminder becomes a nag.
 */

.reminder {
  background: var(--surface);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: 18px 16px;
  margin-block-end: var(--gap);
  box-shadow: 0 8px 28px color-mix(in srgb, var(--accent) 18%, transparent);
}
.reminder-when {
  margin: 0;
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.reminder-title { font-size: 1.5rem; margin: 6px 0 2px; line-height: 1.3; }
.reminder-ask { margin: 0 0 14px; color: var(--text-dim); }
.reminder-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.reminder-actions button, .reminder-actions .button { flex: 1 1 auto; min-width: 110px; }
.reminder-actions button.primary { flex-basis: 100%; min-height: 52px; font-size: 1.05rem; }
.reminder-more { margin-block-start: 12px; margin-block-end: 0; font-size: 0.85rem; }

/* Feature lists -----------------------------------------------------------
 *
 * What a plan includes, and what it does not. The distinction is carried by a
 * mark and a colour, and also by the text itself — colour alone is not a way
 * to tell someone what they have.
 */

.feature-list { list-style: none; margin: 0; padding: 0; }
.feature-list li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 6px 0;
  font-size: 0.95rem;
}
.feature-list li::before { flex: none; font-weight: 700; }
.feature-list li.has::before { content: '✓'; color: var(--ok); }
.feature-list li.missing::before { content: '—'; color: var(--text-dim); }
.feature-list li.missing { color: var(--text-dim); }

/* Charts ------------------------------------------------------------------
 *
 * Shared with the consoles through lib/charts.js, so the member app needs the
 * same handful of rules. Kept here rather than in console.css because this is
 * the stylesheet both entry points load.
 */

/* Chart tokens, defined once for every page that draws one. */
:root {
  --chart-bar: color-mix(in srgb, var(--accent) 55%, transparent);
  --chart-area: color-mix(in srgb, var(--accent) 14%, transparent);
  /* Up is not good news on a weight chart, and this is where that is decided. */
  --chart-up: var(--danger);
  --chart-down: var(--ok);
}

.chart { margin: 0; }
.chart svg { width: 100%; display: block; }
.chart-empty {
  padding: 24px;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 0.9rem;
}
.chart-caption {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  padding-block-start: 6px;
  color: var(--text-dim);
}
.chart-caption .up { color: var(--chart-up); }
.chart-caption .down { color: var(--chart-down); }

/* Weekly report -----------------------------------------------------------
 *
 * A trend's direction is carried by a word and a mark, not by colour alone.
 */

.report-headline { font-size: 1.05rem; margin: 10px 0 4px; }
.trend-list { list-style: none; margin: 10px 0; padding: 0; }
.trend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  padding: 6px 0;
  border-block-end: 1px solid var(--border);
  font-size: 0.92rem;
}
.trend:last-child { border-block-end: none; }
.trend strong::before { margin-inline-end: 6px; }
.trend.up strong::before { content: '▲'; color: var(--ok); }
.trend.down strong::before { content: '▼'; color: var(--danger); }
.trend.flat strong::before { content: '—'; color: var(--text-dim); }

/*
 * A measurement reads left-to-right whatever language surrounds it.
 *
 * "0 / 1800" is a left-to-right construction. Its digits are bidi-neutral, so
 * inside a Persian sentence the browser reorders them and the screen shows
 * "1800 / 0" — the same two numbers, swapped, on exactly the figure someone is
 * checking. `dir="ltr"` on the element and an isolate here keep it intact
 * without affecting anything around it.
 */
.measurement {
  unicode-bidi: isolate;
  font-variant-numeric: tabular-nums;
}

/* Two facts side by side, without a character between them that a reader
   could mistake for a digit. */
.history-meta { gap: 10px; }
