/* Hem — one small design system. Sections: tokens, base, layout, surfaces,
   components, forms. Every visual choice is a class here; templates carry no
   inline styles except the per-member colour passed as --c by the ui tags. */

/* --- Tokens ------------------------------------------------------------- */

:root {
  /* Dark is the app's own look, on every device. */
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273449;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --line: #334155;
  --accent: #818cf8;
  --accent-text: #0f172a;
  --on-color: #ffffff;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 14px;
  --radius-sm: 10px;
  --radius-pill: 999px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  --tabbar-h: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

/* Light palette, kept for a future theme switch: <html data-theme="light">. */
:root[data-theme="light"] {
  --bg: #f4f5f9;
  --surface: #ffffff;
  --surface-2: #eef0f6;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #6366f1;
  --accent-text: #ffffff;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 4px 12px rgba(15, 23, 42, 0.04);
  color-scheme: light;
}

/* --- Base ----------------------------------------------------------------- */

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom));
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
/* No double-tap-to-zoom heuristics on anything tappable. */
a, button, label { touch-action: manipulation; }
h1, h2, h3 { margin: 0; font-weight: 700; }
p { margin: 0 0 0.75rem; }
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.big { font-size: 3rem; margin: 0.25rem 0; }

/* --- Layout --------------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 52px;
  padding: calc(var(--safe-top) + 6px) 1rem 6px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar__title {
  flex: 1;
  min-width: 0;
  font-size: 1.25rem;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar__context { color: var(--muted); font-weight: 500; }
.topbar__sep { color: var(--line); font-weight: 300; margin: 0 0.45rem; }
.topbar__back {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  margin: -0.5rem 0 -0.5rem -0.75rem;
}

/* Line icons (inline SVG symbols in base.html): inherit the text colour. */
.icon, .tab__icon, .tile__icon {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tile__icon { width: 30px; height: 30px; color: var(--accent); }
.topbar__actions { display: flex; gap: 0.5rem; }

.page { max-width: 640px; margin: 0 auto; padding: 1rem; }
.stack { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 1rem; }
.stack--tight { margin-top: 0; }
.empty { padding: 2rem 1rem; }
.logo { border-radius: 18px; margin: 0.5rem auto 0.75rem; display: block; }

.messages { list-style: none; margin: 0 0 1rem; padding: 0; }
.message {
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
}
.message--success { background: color-mix(in srgb, var(--success) 18%, var(--surface)); }
.message--error { background: color-mix(in srgb, var(--danger) 18%, var(--surface)); }

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 10;
  display: flex;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
}
.tab--active { color: var(--accent); }

/* --- Surfaces ----------------------------------------------------------- */
/* Everything that sits as a raised block on the page shares one treatment. */

.card, .tile, .list__item, .rows, .scores {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card { padding: 1.1rem; margin-bottom: 1rem; }
.card--center { text-align: center; }
.card--center h2 { margin-bottom: 1rem; }
.card--center .form { text-align: left; }

.tiles { display: grid; grid-template-columns: 1fr; gap: 0.9rem; }
@media (min-width: 480px) { .tiles { grid-template-columns: 1fr 1fr; } }
.tile { display: block; color: inherit; padding: 1rem 1.1rem; transition: transform 0.08s ease; }
.tile:active { transform: scale(0.98); }
.tile__head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
.tile__title { font-weight: 700; font-size: 1.3rem; }
.tile__sub { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; color: var(--muted); margin: 0; font-size: 0.9rem; }

.list { list-style: none; margin: 0 0 1rem; padding: 0; }
.list__item { display: flex; align-items: center; gap: 0.8rem; padding: 0.75rem 0.9rem; margin-bottom: 0.5rem; }
.list--muted .list__item { opacity: 0.7; }
.list__body { flex: 1; min-width: 0; }
.list__title { font-weight: 600; }
.list__meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem; margin-top: 0.15rem; color: var(--muted); font-size: 0.85rem; }

.rows { overflow: hidden; }
.row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 42px;
  padding: 0.3rem 0.6rem 0.3rem 0.5rem;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row--later { color: var(--muted); }
.row form { display: contents; }
.row.htmx-request { opacity: 0.6; }
.row__title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 0.95rem; }
.row__status { flex: none; font-size: 0.78rem; font-weight: 600; color: var(--muted); white-space: nowrap; }
.row__status--overdue { color: var(--danger); }
.row__status--due_soon, .row__status--nudge { color: var(--warning); }
.row__who { flex: none; font-size: 1.05rem; line-height: 1; }

.scores { width: 100%; border-collapse: collapse; overflow: hidden; margin-bottom: 1.25rem; }
.scores th, .scores td { padding: 0.65rem 0.8rem; text-align: right; border-bottom: 1px solid var(--line); }
.scores th:first-child, .scores td:first-child { text-align: left; }
.scores th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.scores tr:last-child td { border-bottom: 0; }

.group { margin-bottom: 1.25rem; }
.group__title { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0.25rem 0.5rem; }
.group__title--overdue { color: var(--danger); }
.group__title--due_soon { color: var(--warning); }

/* --- Components --------------------------------------------------------- */

/* Buttons: one base, variants after it so they win on equal specificity. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  padding: 0.7rem 1.1rem;
  border-radius: 12px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  text-align: center;
}
.btn:active { filter: brightness(0.95); }
.btn--primary { background: var(--accent); color: var(--accent-text); }
.btn--ghost { background: transparent; border-color: var(--line); }
.btn--danger { background: var(--danger); color: var(--on-color); }
.btn--danger-ghost { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn--small { padding: 0.35rem 0.7rem; font-size: 0.85rem; border-radius: var(--radius-sm); }
.btn--text { background: transparent; color: var(--accent); padding: 0 0.2rem; font-size: 0.75rem; border: 0; }
.btn--block { width: 100%; }

/* Round done toggle used in chore rows. */
.check {
  flex: none;
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: transparent;
  color: transparent;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.08s ease;
}
.check:active { transform: scale(0.9); }
.check--done { background: var(--success); border-color: var(--success); color: var(--on-color); }

/* Pills: selectable options. Used by the list filters and by every radio /
   checkbox group in forms, so the two never drift apart. */
.pill, .field--choices > div label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.pill--active, .field--choices > div label:has(input:checked) {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}
.pills { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1rem; }

/* Segmented control for sections within an app. */
.segments { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; margin-bottom: 1rem; }
.segment { flex: 1; text-align: center; padding: 0.5rem 0.25rem; border-radius: 9px; color: var(--muted); font-weight: 600; font-size: 0.92rem; }
.segment--active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* Chips: small labels. --c is the tint; member chips get it from the ui tag. */
.chip {
  --c: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.1rem 0.55rem;
  border-radius: var(--radius-pill);
  font-size: 0.78rem;
  font-weight: 600;
  background: color-mix(in srgb, var(--c) 18%, var(--surface));
  color: color-mix(in srgb, var(--c) 80%, var(--text));
}
.chip--overdue { --c: var(--danger); }
.chip--due_soon, .chip--nudge { --c: var(--warning); }

/* Avatars: a member's emoji in their colour, two sizes; --plain for non-member icons. */
.avatar {
  --c: var(--muted);
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  background: color-mix(in srgb, var(--c) 22%, var(--surface));
  box-shadow: inset 0 0 0 2px var(--c);
}
.avatar--sm { width: 28px; height: 28px; font-size: 0.95rem; vertical-align: middle; }
.avatar--plain { background: var(--surface-2); box-shadow: none; }

/* --- Forms ---------------------------------------------------------------- */

.form { display: flex; flex-direction: column; gap: 1rem; }
.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field__label { font-weight: 600; font-size: 0.92rem; }
.field__help { color: var(--muted); font-size: 0.82rem; margin: 0; }
.field__error { color: var(--danger); font-size: 0.85rem; margin: 0; }
.field input[type="text"], .field input[type="password"], .field input[type="number"], .field input[type="date"], .field textarea, .field select {
  width: 100%;
  font: inherit;
  font-size: 16px; /* prevents iOS zoom on focus */
  padding: 0.65rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  -webkit-appearance: none;
  appearance: none;
}
.field input:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.field--error input, .field--error textarea { border-color: var(--danger); }
.field--checkbox { flex-direction: row; align-items: center; gap: 0.6rem; }
.field--checkbox .field__label { order: 2; }
.field input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }
.field--choices > div { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.field--choices > div > div { display: contents; }
.field--choices > div label input { position: absolute; opacity: 0; width: 0; height: 0; }
