/* ==========================================================================
   FuDiApp styles
   - light + dark themes via [data-theme] on <html>
   - RTL/LTR handled with CSS logical properties only
   ========================================================================== */

:root {
  --brand: #15803d;
  --brand-strong: #166534;
  --brand-soft: #dcfce7;
  --brand-ink: #ffffff;
  --accent: #0d9488;

  --bg: #f5f7f6;
  --bg-elev: #ffffff;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --text: #111827;
  --text-soft: #374151;
  --muted: #6b7280;
  --border: #e5e7eb;
  --border-strong: #d1d5db;

  --slot-breakfast: #d97706;
  --slot-lunch: #059669;
  --slot-dinner: #4f46e5;
  --slot-snacks: #db2777;

  --danger: #dc2626;
  --danger-soft: #fee2e2;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 4%);
  --shadow: 0 4px 14px rgb(16 24 40 / 8%);
  --shadow-lg: 0 18px 40px rgb(16 24 40 / 16%);
  --header-h: 62px;
}

[data-theme='dark'] {
  --brand: #22c55e;
  --brand-strong: #16a34a;
  --brand-soft: #123322;
  --brand-ink: #06210f;
  --accent: #2dd4bf;

  --bg: #0d1210;
  --bg-elev: #141a17;
  --surface: #161d1a;
  --surface-2: #1b231f;
  --text: #e9f1eb;
  --text-soft: #c6d3cb;
  --muted: #93a49a;
  --border: #273331;
  --border-strong: #35443f;

  --slot-breakfast: #f59e0b;
  --slot-lunch: #34d399;
  --slot-dinner: #818cf8;
  --slot-snacks: #f472b6;

  --danger: #f87171;
  --danger-soft: #3a1717;

  --shadow-sm: 0 1px 2px rgb(0 0 0 / 40%);
  --shadow: 0 6px 18px rgb(0 0 0 / 45%);
  --shadow-lg: 0 22px 48px rgb(0 0 0 / 55%);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Naskh Arabic',
    'Helvetica Neue', Tahoma, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.25; font-weight: 700; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.22rem; }
h3 { font-size: 1.03rem; }
p { margin: 0 0 .7em; }

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.tiny { font-size: .78rem; }
.center { text-align: center; }
.row { display: flex; gap: 10px; align-items: center; }
.row-wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.hidden { display: none !important; }
/* ------------------------------------------------------------------ topbar */

.topbar {
  position: sticky;
  inset-block-start: 0;
  z-index: 40;
  min-height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px clamp(12px, 3vw, 26px);
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  backdrop-filter: blur(10px);
  border-block-end: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -.01em; }
.brand-mark {
  inline-size: 34px; block-size: 34px; display: grid; place-items: center;
  border-radius: 10px; background: var(--brand); color: var(--brand-ink);
  font-size: 1.05rem; font-weight: 800;
}
.brand-name { font-size: 1.08rem; }
.brand-tag { font-size: .72rem; color: var(--muted); display: block; margin-block-start: -3px; }

.nav { display: flex; gap: 4px; margin-inline-start: clamp(6px, 2vw, 22px); flex-wrap: wrap; }
.nav-link {
  padding: 7px 13px; border-radius: 999px; color: var(--text-soft);
  font-weight: 600; font-size: .92rem; border: 1px solid transparent; cursor: pointer;
  background: none; font-family: inherit;
}
.nav-link:hover { background: var(--surface-2); }
.nav-link.is-active { background: var(--brand-soft); color: var(--brand-strong); border-color: var(--brand); }
[data-theme='dark'] .nav-link.is-active { color: var(--brand); }

.topbar-actions { margin-inline-start: auto; display: flex; align-items: center; gap: 8px; }

.user-chip {
  display: flex; align-items: center; gap: 8px; padding: 4px 10px 4px 5px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
}
.user-avatar {
  inline-size: 27px; block-size: 27px; border-radius: 50%; display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand-strong); font-weight: 700; font-size: .8rem;
}
[data-theme='dark'] .user-avatar { color: var(--brand); }
.user-name {
  font-size: .86rem; font-weight: 600; max-inline-size: 130px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}

/* ------------------------------------------------------------------ layout */

/*
 * The page is deliberately FLUID: no max-width cap, so a wide laptop or a
 * 2560px monitor is fully used instead of leaving big empty gutters. Comfort on
 * very wide screens comes from the layouts inside (multi-column grids, the
 * sidebar+main split on Today), not from capping the container.
 */
.page {
  inline-size: 100%;
  margin: 0;
  padding: clamp(12px, 1.5vw, 24px) clamp(12px, 1.8vw, 36px) clamp(28px, 4vh, 56px);
}
.page-head { margin-block-end: 18px; }
.page-head p { color: var(--muted); margin: 0; }

/*
 * Prose and single-line controls would look silly stretched across an
 * ultrawide monitor, so we cap the *content* of form fields and long text
 * rather than capping the whole page.
 */
.card .field .input,
.card .field .select,
.card .field .textarea { max-inline-size: 680px; }
.card > p { max-inline-size: 90ch; }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid-stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px;
}
.card-tight { padding: 12px 14px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-block-end: 10px; flex-wrap: wrap;
}
.card-head h2, .card-head h3 { margin: 0; }

.section-title {
  font-size: .78rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); font-weight: 700; margin-block-end: 8px;
}
.mono-num { font-variant-numeric: tabular-nums; }

/* ----------------------------------------------------------------- buttons */

.btn {
  font-family: inherit; font-weight: 600; font-size: .95rem;
  padding: 9px 16px; border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text);
  cursor: pointer; white-space: nowrap;
  transition: background .14s, border-color .14s, transform .08s, color .14s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-soft); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.93); }
.btn-sm { padding: 6px 11px; font-size: .85rem; border-radius: 8px; }
.btn-block { inline-size: 100%; display: flex; justify-content: center; }

/* ------------------------------------------------------------------ inputs */

.field { display: flex; flex-direction: column; gap: 5px; margin-block-end: 12px; }
.field > label { font-size: .85rem; font-weight: 600; color: var(--text-soft); }

.input, .select, .textarea {
  font-family: inherit; font-size: .95rem;
  padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text);
  inline-size: 100%;
}
.textarea { min-block-size: 74px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--brand) 45%, transparent);
  outline-offset: 1px; border-color: var(--brand);
}

.seg {
  display: inline-flex; padding: 3px; gap: 3px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  flex-wrap: wrap;
}
.seg button {
  font-family: inherit; font-size: .86rem; font-weight: 600; border: 0; background: none;
  color: var(--text-soft); padding: 6px 14px; border-radius: 999px; cursor: pointer;
}
.seg button.is-active { background: var(--surface); color: var(--brand-strong); box-shadow: var(--shadow-sm); }
[data-theme='dark'] .seg button.is-active { color: var(--brand); }

/* ------------------------------------------------------------- checkboxes */

.check {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 10px; border-radius: 9px; cursor: pointer;
  border: 1px solid transparent; font-size: .93rem;
  transition: background .12s, border-color .12s;
}
.check:hover { background: var(--surface-2); }
.check input { inline-size: 17px; block-size: 17px; accent-color: var(--brand); cursor: pointer; flex: none; }
.check input:checked + span { font-weight: 650; color: var(--brand-strong); }
[data-theme='dark'] .check input:checked + span { color: var(--brand); }
.check.is-on { background: var(--brand-soft); }

/* One item line: checkbox + name, then its quantity stepper and remove ✕. */
.item-row {
  display: flex; align-items: center; gap: 2px;
  border-radius: 9px; padding-inline-end: 3px;
  transition: background .12s;
}
.item-row:hover { background: var(--surface-2); }
.item-row.is-on { background: var(--brand-soft); }
.item-row .check { flex: 1 1 auto; min-inline-size: 0; background: none; }
.item-row .check:hover { background: none; }

/* "− n +" quantity stepper, shown next to a ticked item. */
.qty { display: inline-flex; align-items: center; gap: 1px; flex: none; }
.qty-btn {
  inline-size: 22px; block-size: 22px; padding: 0; line-height: 1;
  border: 1px solid var(--border); border-radius: 7px;
  background: var(--surface); color: var(--text-soft);
  font: inherit; font-size: .95rem; cursor: pointer;
}
.qty-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.qty-btn:disabled { opacity: .35; cursor: default; }
.qty-input {
  inline-size: 34px; block-size: 22px; padding: 0 2px; text-align: center;
  border: 1px solid var(--border); border-radius: 7px;
  background: var(--surface); color: var(--text);
  font: inherit; font-size: .78rem; font-variant-numeric: tabular-nums;
  -moz-appearance: textfield; appearance: textfield;
}
.qty-input::-webkit-outer-spin-button,
.qty-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* Small square ✕ for "remove this type / item" (the counterpart of "+ Add"). */
.icon-btn {
  inline-size: 22px; block-size: 22px; padding: 0; line-height: 1; flex: none;
  border: 1px solid transparent; border-radius: 7px;
  background: none; color: var(--muted);
  font: inherit; font-size: .8rem; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn-danger:hover { background: var(--danger-soft); color: var(--danger); }

.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(214px, 1fr)); gap: 2px; }

/* --------------------------------------------------------------- auth page */

/* Password box with its show/hide toggle sitting inside the field. */
.pw-wrap { position: relative; }
.pw-wrap .input { padding-inline-end: 62px; }
.pw-toggle {
  position: absolute; inset-inline-end: 5px; top: 50%;
  transform: translateY(-50%);
  padding: 4px 8px; border: 0; border-radius: 7px;
  background: none; color: var(--muted);
  font: inherit; font-size: .76rem; font-weight: 600; cursor: pointer;
}
.pw-toggle:hover { background: var(--surface-2); color: var(--brand-strong); }
.pw-toggle[aria-pressed='true'] { color: var(--brand-strong); }

.auth-wrap {
  min-block-size: 100vh; display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr);
}
@media (max-width: 900px) { .auth-wrap { grid-template-columns: 1fr; } }

.auth-hero {
  background: linear-gradient(155deg, var(--brand-strong), var(--brand) 55%, var(--accent));
  color: #fff; padding: clamp(26px, 5vw, 60px); display: flex;
  flex-direction: column; justify-content: center; gap: 14px;
}
.auth-hero h1 { font-size: clamp(1.7rem, 3.4vw, 2.5rem); margin: 0; }
.auth-hero p { color: rgb(255 255 255 / 88%); max-inline-size: 46ch; }
.auth-hero .brand-mark { background: rgb(255 255 255 / 18%); color: #fff; }
.auth-hero .brand-name { color: #fff; font-size: 1.35rem; }
.auth-hero-tag { color: rgb(255 255 255 / 78%); font-size: .9rem; }
.auth-hero-points { display: flex; flex-wrap: wrap; gap: 8px; margin-block-start: 6px; }
.auth-point {
  background: rgb(255 255 255 / 14%); border: 1px solid rgb(255 255 255 / 22%);
  border-radius: 999px; padding: 6px 13px; font-size: .84rem; font-weight: 600;
}

.auth-panel {
  display: flex; align-items: center; justify-content: center;
  padding: clamp(20px, 5vw, 50px); background: var(--bg);
}
.auth-card {
  inline-size: 100%; max-inline-size: 400px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px; padding: 24px;
  box-shadow: var(--shadow);
}
.auth-card h2 { margin-block-end: 4px; }
.auth-switch { margin-block-start: 14px; font-size: .9rem; color: var(--muted); text-align: center; }
.auth-lang { position: fixed; inset-block-start: 14px; inset-inline-end: 16px; z-index: 5; }
.auth-error {
  background: var(--danger-soft); color: var(--danger); border-radius: 9px;
  padding: 9px 12px; font-size: .88rem; margin-block-end: 10px;
}

/* --------------------------------------------------------------- slot cards */

.slot-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }

.slot-card {
  font-family: inherit; text-align: start; cursor: pointer;
  background: var(--surface); color: var(--text);
  border: 1.5px solid var(--border); border-radius: var(--radius);
  padding: 15px; display: flex; flex-direction: column; gap: 4px;
  transition: border-color .15s, box-shadow .15s, transform .1s;
  position: relative; overflow: hidden;
}
.slot-card::before {
  content: ''; position: absolute; inset-block-start: 0; inset-inline: 0; block-size: 4px;
  background: var(--slot-color, var(--brand));
}
.slot-card:hover { border-color: var(--slot-color, var(--brand)); box-shadow: var(--shadow); transform: translateY(-1px); }
.slot-card.is-active { border-color: var(--slot-color, var(--brand)); background: var(--brand-soft); }
.slot-card .slot-emoji { font-size: 1.5rem; line-height: 1; }
.slot-card .slot-label { font-weight: 700; font-size: 1.02rem; }
.slot-card .slot-meta { font-size: .8rem; color: var(--muted); }
.slot-card .slot-count {
  position: absolute; inset-block-start: 12px; inset-inline-end: 12px;
  background: var(--slot-color, var(--brand)); color: #fff; border-radius: 999px;
  font-size: .72rem; font-weight: 700; padding: 2px 8px;
}
.slot-breakfast { --slot-color: var(--slot-breakfast); }
.slot-lunch { --slot-color: var(--slot-lunch); }
.slot-dinner { --slot-color: var(--slot-dinner); }
.slot-snacks { --slot-color: var(--slot-snacks); }

/* ----------------------------------------------------------- categories UI */

.cat-block { border: 1px solid var(--border); border-radius: var(--radius); margin-block-end: 10px; overflow: hidden; }
.cat-head {
  display: flex; align-items: center; gap: 10px; padding: 10px 13px;
  background: var(--surface-2); cursor: pointer; user-select: none;
}
.cat-head:hover { background: var(--brand-soft); }
.cat-head .cat-emoji { font-size: 1.15rem; }
.cat-head .cat-name { font-weight: 700; }
.cat-head .cat-count { font-size: .8rem; color: var(--muted); margin-inline-start: auto; }
.cat-body { padding: 8px 13px 12px; }
.cat-toggle { inline-size: 18px; block-size: 18px; accent-color: var(--brand); cursor: pointer; flex: none; }
.cat-actions { display: flex; gap: 8px; align-items: center; margin-block-start: 8px; flex-wrap: wrap; }

.inline-form {
  display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap;
  padding: 10px; border: 1px dashed var(--border-strong); border-radius: 10px;
  margin-block-start: 8px; background: var(--surface-2);
}
.inline-form .field { margin: 0; flex: 1 1 150px; }

/* ------------------------------------------------------------- today layout */

.today-view { display: flex; flex-direction: column; gap: 14px; }

/*
 * Below 1000px the slot picker sits above the logger (one column).
 * At >=1000px it becomes a sticky left/right sidebar so the logger gets the
 * full remaining width — which is what removes the big empty gutters on
 * laptops and desktops.
 */
.today-layout { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }

.today-side .slot-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

@media (min-width: 640px) {
  .today-side .slot-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (min-width: 1000px) {
  .today-layout { grid-template-columns: minmax(240px, 20%) minmax(0, 1fr); }
  .today-side .slot-grid { grid-template-columns: minmax(0, 1fr); }
  .today-side .card-head h2 { font-size: 1.05rem; }
  .today-side .slot-card { padding: 12px; }
  .today-side .slot-card .slot-emoji { font-size: 1.3rem; }
  .today-side > .card { position: sticky; inset-block-start: calc(var(--header-h) + 14px); }
}

.today-main { min-inline-size: 0; }

/* ------------------------------------------------------------- day summary */

.summary-list { display: grid; gap: 10px; }

@media (min-width: 1400px) {
  /* Plenty of width: show the day's meals side by side instead of stacked. */
  .summary-list { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
}

.summary-slot {
  border: 1px solid var(--border);
  border-inline-start: 3px solid var(--slot-color, var(--brand));
  border-radius: var(--radius);
  padding: 11px 13px;
  background: var(--surface-2);
}
.summary-slot-head {
  display: flex; align-items: center; gap: 9px; flex-wrap: wrap;
  margin-block-end: 8px;
}
.summary-slot-name { font-weight: 700; color: var(--slot-color, var(--text)); }
.summary-slot-head .btn { margin-inline-start: auto; }
.summary-cats { display: grid; gap: 6px; }
.summary-cat { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.summary-cat-name {
  font-size: .82rem; font-weight: 700; color: var(--text-soft);
  min-inline-size: 110px;
}
.summary-slot .notes {
  margin: 8px 0 0; font-size: .82rem; color: var(--muted);
}

/* ---------------------------------------------------------------- tracker */

.week-strip { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.week-day {
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 8px; text-align: center;
  cursor: pointer; background: var(--surface); font-family: inherit; color: var(--text);
  display: flex; flex-direction: column; gap: 5px; align-items: center;
}
.week-day:hover { border-color: var(--brand); }
.week-day.is-today { outline: 2px solid var(--brand); outline-offset: -1px; }
.week-day.is-selected {
  background: var(--brand-soft);
  border-color: var(--brand);
  box-shadow: var(--shadow-sm);
}
.week-day.is-selected .wd-num { color: var(--brand-strong); }
[data-theme='dark'] .week-day.is-selected .wd-num { color: var(--brand); }
.week-day.is-empty { opacity: .6; }
.week-day .wd-name { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.week-day .wd-num { font-weight: 700; font-size: 1.02rem; }
.wd-dots { display: flex; gap: 3px; justify-content: center; min-block-size: 9px; }
.wd-dot { inline-size: 8px; block-size: 8px; border-radius: 50%; background: var(--border-strong); }

.month-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }

/*
 * On a wide screen the calendar would otherwise produce ~300px square cells,
 * so the overview caps the calendar column and puts the totals beside it.
 */
.tracker-overview { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }

@media (min-width: 1200px) {
  .tracker-overview {
    grid-template-columns: minmax(0, 880px) minmax(200px, 1fr);
    align-items: start;
  }
  /* The calendar keeps square-ish cells; the stats grow into the free space. */
  .tracker-stats { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
}
.month-dow {
  text-align: center; font-size: .72rem; color: var(--muted); font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em; padding-block-end: 2px;
}
.month-cell {
  aspect-ratio: 1 / 1; border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface); cursor: pointer; font-family: inherit; color: var(--text);
  padding: 5px; display: flex; flex-direction: column; gap: 3px; align-items: center;
  justify-content: flex-start; position: relative;
}
.month-cell:hover { border-color: var(--brand); }
.month-cell.is-blank { visibility: hidden; }
.month-cell.is-today { outline: 2px solid var(--brand); outline-offset: -1px; }
.month-cell.has-meals {
  background: var(--brand-soft);
  border-color: color-mix(in srgb, var(--brand) 35%, transparent);
}
.month-cell .mc-num { font-size: .82rem; font-weight: 600; }
.month-cell .mc-count { font-size: .68rem; color: var(--muted); }

/* The week strip on the Today view: keep its natural size instead of letting
   seven cells stretch to 300px each on a very wide monitor. */
.week-card .week-strip { max-inline-size: 900px; }
.week-totals { margin-block-start: 10px; font-variant-numeric: tabular-nums; }

/* ----------------------------------------------------------------- tables */

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table.data { inline-size: 100%; border-collapse: collapse; font-size: .89rem; min-inline-size: 560px; }
table.data th, table.data td {
  text-align: start; padding: 9px 12px; border-block-end: 1px solid var(--border);
  vertical-align: top;
}
table.data thead th {
  background: var(--brand-strong); color: #fff; font-weight: 700; font-size: .82rem;
  text-transform: uppercase; letter-spacing: .04em; position: sticky; inset-block-start: 0;
}
table.data tbody tr:nth-child(even) { background: var(--surface-2); }
table.data tbody tr:hover { background: var(--brand-soft); }
table.data td.num, table.data th.num { text-align: end; font-variant-numeric: tabular-nums; }
table.data .cell-slot { font-weight: 700; }

/* ------------------------------------------------------------------- chips */

.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 2px 10px; font-size: .82rem; color: var(--text-soft);
}
.badge {
  display: inline-block; border-radius: 999px; padding: 1px 8px; font-size: .72rem;
  font-weight: 700; background: var(--brand-soft); color: var(--brand-strong);
  border: 1px solid color-mix(in srgb, var(--brand) 30%, transparent);
}
[data-theme='dark'] .badge { color: var(--brand); }
.badge-muted { background: var(--surface-2); color: var(--muted); border-color: var(--border); }

/* ------------------------------------------------------------- stat cards */

.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 13px 15px; position: relative; overflow: hidden;
}
.stat-card::before {
  content: ''; position: absolute; inset-block-start: 0; inset-inline: 0; block-size: 3px;
  background: var(--stat-color, var(--brand));
}
.stat-card .stat-value { font-size: 1.6rem; font-weight: 800; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat-card .stat-label { font-size: .8rem; color: var(--muted); }

/* Category totals: label, a bar that takes the leftover width, then the value.
   The bar column is the flexible one, so the track reaches the card edge
   instead of stopping at a fixed width. */
.bar-row { display: grid; grid-template-columns: minmax(6rem, 24%) minmax(0, 1fr) 3rem; gap: 12px; align-items: center; }
.bar-row > :first-child { overflow-wrap: anywhere; }
.bar-track { block-size: 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.bar-fill { block-size: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--brand), var(--brand-strong)); }

/* ------------------------------------------------------------ empty/loading */

.empty {
  border: 1px dashed var(--border-strong); border-radius: var(--radius);
  padding: 26px; text-align: center; color: var(--muted); background: var(--surface-2);
}
.spinner {
  inline-size: 22px; block-size: 22px; border-radius: 50%;
  border: 2.5px solid var(--border); border-block-start-color: var(--brand);
  animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-row { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 18px 0; }

/* ------------------------------------------------------------- toast/modal */

.toast-host {
  position: fixed; inset-block-end: 20px; inset-inline-end: 20px; z-index: 90;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
}
.toast {
  background: var(--text); color: var(--bg-elev); padding: 10px 15px; border-radius: 10px;
  box-shadow: var(--shadow-lg); font-size: .9rem; font-weight: 600;
  opacity: 0; transform: translateY(8px); transition: opacity .25s, transform .25s;
  max-inline-size: 340px;
}
.toast-in { opacity: 1; transform: translateY(0); }
.toast-error { background: var(--danger); color: #fff; }
.toast-success { background: var(--brand); color: var(--brand-ink); }

.modal-overlay {
  position: fixed; inset: 0; z-index: 100; background: rgb(8 12 10 / 55%);
  display: grid; place-items: center; padding: 20px;
  opacity: 0; transition: opacity .15s;
}
.modal-overlay.modal-in { opacity: 1; }
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 20px; inline-size: min(440px, 100%); box-shadow: var(--shadow-lg);
}
.modal-title { margin-block-end: 6px; }
.modal-text { color: var(--text-soft); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-block-start: 16px; }

/* ---------------------------------------------------------------- settings */

.catalog-list { display: flex; flex-direction: column; gap: 10px; }
.catalog-item { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.catalog-head {
  display: flex; align-items: center; gap: 10px; padding: 10px 13px; background: var(--surface-2);
  flex-wrap: wrap;
}
.catalog-head .cat-emoji { font-size: 1.15rem; }
.catalog-head .grow { font-weight: 700; }
.danger-card { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.danger-card h3 { color: var(--danger); }

/* ---------------------------------------------------------------- reports */

.report-form { display: grid; gap: 12px; }
/* Control groups keep a uniform shape so the segmented buttons line up whether
   or not a group carries a caption underneath. */
.report-form .row { align-items: flex-start; }
.report-form .control-group { display: flex; flex-direction: column; gap: 6px; min-inline-size: 0; }
.report-form .control-caption { margin: 0; max-inline-size: 30ch; }
.report-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.sr-only {
  position: absolute; inline-size: 1px; block-size: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* --------------------------------------------------------------- responsive */

/* --- wide screens: keep multi-column grids from over-stretching --- */
@media (min-width: 1400px) {
  /* Settings reads best as two columns, even on very wide monitors. */
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* --- tablets & small laptops --- */
@media (max-width: 880px) {
  /*
   * The header has to fit one row or it wastes ~50px of height. Dropping the
   * brand tagline plus the user's name is the cheapest way to make room.
   */
  .topbar { flex-wrap: nowrap; gap: 6px; }
  .brand-tag,
  .brand-name,
  .user-name { display: none; }
  .brand { gap: 0; }
  .user-chip { padding: 3px; border: 0; background: none; }
  .nav { margin-inline-start: 6px; }
  .nav-link { padding: 7px 11px; font-size: .87rem; }
  .topbar-actions { gap: 5px; min-inline-size: 0; }
}

@media (max-width: 900px) {
  /* Auth: stack the hero above the form, compactly. */
  .auth-wrap { grid-template-columns: minmax(0, 1fr); }
  .auth-panel {
    flex-direction: column; align-items: stretch; justify-content: flex-start;
    padding: 16px;
  }
  .auth-card { max-inline-size: none; }
  .auth-lang { position: static; align-self: flex-end; margin-block-end: 6px; }
  .auth-hero { padding: 22px 20px; gap: 8px; }
  .auth-hero h1 { font-size: clamp(1.35rem, 5vw, 1.9rem); }
}

/* --- phones --- */
@media (max-width: 700px) {
  :root { --header-h: 54px; }
  body { font-size: 14.5px; }

  /*
   * Turn the top nav into a fixed bottom tab bar: it uses the dead space at the
   * bottom of a phone screen, keeps the header to a single row, and puts the
   * main destinations under the thumb. `backdrop-filter` must be dropped here
   * because it would otherwise become the containing block for the fixed nav.
   */
  .topbar {
    backdrop-filter: none;
    padding: 7px 10px;
    min-height: var(--header-h);
  }
  .brand-mark { inline-size: 30px; block-size: 30px; border-radius: 9px; font-size: .95rem; }
  .btn { padding: 8px 11px; font-size: .86rem; }
  .btn-sm { padding: 6px 9px; font-size: .82rem; }

  .nav {
    position: fixed;
    inset-block-end: 0;
    inset-inline: 0;
    margin: 0;
    padding: 5px 6px calc(5px + env(safe-area-inset-bottom, 0px));
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 3px;
    background: var(--surface);
    border-block-start: 1px solid var(--border);
    box-shadow: 0 -4px 18px rgb(16 24 40 / 12%);
    z-index: 60;
  }
  [data-theme='dark'] .nav { box-shadow: 0 -4px 18px rgb(0 0 0 / 55%); }
  .nav-link {
    padding: 8px 4px; font-size: .74rem; border-radius: 9px;
    text-align: center; line-height: 1.2;
  }
  body { padding-block-end: 74px; }
  .toast-host { inset-block-end: 84px; }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .btn { inline-size: 100%; }

  /* Tables: trim to what matters and scroll the rest. */
  table.data { min-inline-size: 460px; font-size: .84rem; }
  table.data th, table.data td { padding: 7px 9px; }
  table.data .col-weekday { display: none; }
  .table-wrap { scrollbar-width: thin; }

  /* Tracker */
  .week-strip { gap: 4px; }
  .week-day { padding: 7px 2px; border-radius: 8px; }
  .week-day .wd-name { font-size: .64rem; letter-spacing: 0; }
  .week-day .wd-num { font-size: .92rem; }
  .wd-dot { inline-size: 5px; block-size: 5px; }
  .wd-dots { gap: 2px; }

  /* Reports */
  .bar-row { grid-template-columns: minmax(0, 1fr) 64px 38px; gap: 7px; font-size: .86rem; }
  .report-actions .btn { inline-size: 100%; justify-content: center; }
  .report-actions { display: grid; gap: 8px; }

  /* Logging */
  .cat-head { flex-wrap: wrap; padding: 9px 11px; gap: 8px; }
  .cat-head .cat-count { margin-inline-start: 0; }
  .check-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .inline-form .field { flex: 1 1 100%; }
  .slot-card { padding: 12px; }

  /* Day summary */
  .summary-cat { flex-direction: column; gap: 4px; }
  .summary-cat-name { min-inline-size: 0; }
  .summary-slot-head .btn { margin-inline-start: 0; }

  .grid { gap: 11px; }
  .card { padding: 13px; border-radius: 11px; }
  .page { padding-block-end: 24px; }
}

/* --- small phones --- */
@media (max-width: 560px) {
  .auth-hero p,
  .auth-hero-points { display: none; }
  .month-grid { gap: 4px; }
  .month-cell { padding: 3px; border-radius: 7px; }
  .month-cell .mc-num { font-size: .76rem; }
  .month-cell .mc-count { display: none; }
  .grid-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .seg button { padding: 6px 10px; font-size: .8rem; }
  .check-grid { grid-template-columns: minmax(0, 1fr); }
}

/* Very short and landscape phones: don't let the sticky header eat the view. */
@media (max-height: 480px) {
  .topbar { position: static; }
}

@media print {
  .topbar, .nav, .toast-host, .btn, .report-actions, .toolbar { display: none !important; }
  body { background: #fff; padding-block-end: 0; }
  .card { break-inside: avoid; box-shadow: none; }
  .today-layout { grid-template-columns: minmax(0, 1fr); }
  .today-side > .card { position: static; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation-duration: .01ms !important; }
}
