/* ============ Ezazah design system ============ */
:root {
  --bg: #f3f8fb;
  --surface: #ffffff;
  --surface-2: #f7fafc;
  --ink: #0f2233;
  --muted: #5b7080;
  --faint: #6f8494;
  --accent: #4f46e5;
  --accent-strong: #4338ca;
  --accent-soft: #e0e7ff;
  --accent-ghost: rgba(79, 70, 229, 0.10);
  --danger: #c0392b;
  --danger-soft: #fbeae7;
  --line: #dfe9f0;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(15, 34, 51, 0.05), 0 10px 30px rgba(15, 34, 51, 0.06);
  --ring-bg: #e2eef6;
  --bar: #7cc4ea;
  --bar-today: #4f46e5;
}

[data-theme="dark"] {
  --bg: #0b141d;
  --surface: #132231;
  --surface-2: #182a3b;
  --ink: #e8f2f9;
  --muted: #93a9ba;
  --faint: #8498a8;
  --accent: #818cf8;
  --accent-strong: #a5b4fc;
  --accent-soft: #26245c;
  --accent-ghost: rgba(129, 140, 248, 0.14);
  --danger: #e57367;
  --danger-soft: #3a201d;
  --line: #23384a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 30px rgba(0, 0, 0, 0.35);
  --ring-bg: #1c3247;
  --bar: #2f6a94;
  --bar-today: #818cf8;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: "Segoe UI", "Noto Kufi Arabic", Tahoma, -apple-system, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.65;
  font-size: 16px;
}

.container { max-width: 720px; margin-inline: auto; padding-inline: 18px; }

.skip-link {
  position: absolute;
  inset-inline-start: 12px;
  top: -48px;
  background: var(--accent);
  color: #fff;
  padding: 8px 16px;
  border-radius: 8px;
  z-index: 50;
  transition: top 0.2s;
  text-decoration: none;
}
.skip-link:focus { top: 8px; }

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; padding-block: 12px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { border-radius: 10px; flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-name { font-weight: 800; font-size: 1.2rem; }
.brand-tag { font-size: 0.78rem; color: var(--muted); }
.header-actions { display: flex; gap: 8px; }

.icon-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  min-width: 40px;
  height: 40px;
  padding: 0 10px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.icon-btn:hover { border-color: var(--accent); background: var(--accent-ghost); }
.icon-btn:active { transform: scale(0.96); }
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }
.icon-sun { display: none; }
.icon-moon { display: block; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-block: 16px;
}
.card h2 { margin: 0 0 14px; font-size: 1.05rem; font-weight: 800; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.card-head h2 { margin: 0; }

/* Ring */
.ring-card { text-align: center; padding-block: 28px; }
.ring-wrap { position: relative; width: 210px; margin-inline: auto; }
.ring { width: 100%; height: auto; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--ring-bg); stroke-width: 16; }
.ring-fg {
  fill: none;
  stroke: var(--accent);
  stroke-width: 16;
  stroke-linecap: round;
  stroke-dasharray: 527.8;
  stroke-dashoffset: 527.8;
  transition: stroke-dashoffset 0.7s cubic-bezier(0.22, 1, 0.36, 1), stroke 0.3s;
}
.ring-fg.done { stroke: #16a34a; }
.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
.ring-pct { font-size: 2.3rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.ring-ml { font-size: 0.9rem; color: var(--muted); font-variant-numeric: tabular-nums; direction: ltr; }
.ring-left { font-size: 0.78rem; color: var(--faint); }
.goal-note { margin-top: 14px; font-size: 0.85rem; color: var(--muted); }

/* Quick add */
.quick-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.quick-btn {
  border: 1.5px solid var(--line);
  background: var(--surface-2);
  color: var(--accent-strong);
  border-radius: var(--radius-sm);
  padding: 14px 6px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font: inherit;
  transition: transform 0.12s, border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.quick-btn b { font-size: 0.85rem; color: var(--ink); }
.quick-ml { font-size: 0.75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.quick-btn:hover { border-color: var(--accent); background: var(--accent-ghost); box-shadow: var(--shadow); }
.quick-btn:active { transform: scale(0.95); }
.quick-btn.added { animation: pop 0.35s ease; }
@keyframes pop { 40% { transform: scale(1.06); } }

.custom-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  margin-top: 12px;
}
.custom-form .field { flex: 1; }

.undo-btn { margin-top: 12px; width: 100%; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-block: 16px; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.stat-label { font-size: 0.78rem; color: var(--muted); font-weight: 600; }
.stat-value { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-sub { font-size: 0.72rem; color: var(--faint); min-height: 1.1em; }

/* Week chart */
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 0.8rem; color: var(--muted); }
.dash { width: 14px; height: 0; border-top: 2px dashed var(--danger); display: inline-block; }
#weekChart { display: block; width: 100%; height: auto; }

/* Entries */
.count-pill {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
  border-radius: 99px;
  padding: 3px 12px;
  font-variant-numeric: tabular-nums;
}
.entries-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.entry-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 6px;
  border-bottom: 1px solid var(--line);
}
.entry-row:last-child { border-bottom: 0; }
.entry-time { font-size: 0.82rem; color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.entry-ml { font-weight: 800; font-variant-numeric: tabular-nums; flex: 1; }
.row-btn {
  border: 0;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: inline-flex;
}
.row-btn:hover { color: var(--danger); background: var(--danger-soft); }
.muted-note { color: var(--faint); font-size: 0.88rem; margin: 4px 0; }

/* Forms */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
input, select {
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: var(--surface-2);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-variant-numeric: tabular-nums;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ghost); }
input::placeholder { color: var(--faint); }
input.invalid { border-color: var(--danger); }
.input-unit { position: relative; display: block; }
.input-unit input { padding-inline-end: 46px; }
.input-unit b {
  position: absolute;
  inset-inline-end: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--faint);
  font-size: 0.8rem;
  pointer-events: none;
}
.cups-row { display: flex; gap: 8px; }

/* Switch */
.reminder-row { margin-block: 4px 12px; }
.switch-label { display: flex; align-items: center; gap: 10px; font-size: 0.9rem; cursor: pointer; color: var(--ink); }
.switch-label input { width: 20px; height: 20px; accent-color: var(--accent); }

/* Buttons */
.btn {
  font: inherit;
  font-weight: 700;
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: transform 0.1s, background 0.15s, border-color 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 4px 14px rgba(2, 132, 199, 0.3); }
.btn-primary:hover { background: var(--accent-strong); }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--ink); font-size: 0.85rem; padding: 10px 14px; }
.btn-ghost:hover { border-color: var(--accent); background: var(--accent-ghost); }
.btn-danger-ghost { background: var(--surface); border-color: var(--line); color: var(--danger); font-size: 0.85rem; padding: 10px 14px; }
.btn-danger-ghost:hover { border-color: var(--danger); background: var(--danger-soft); }

.data-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.privacy-note { font-size: 0.78rem; color: var(--faint); margin: 14px 0 0; }
.noscript-note {
  margin: 12px auto; max-width: 640px; padding: 12px 16px;
  background: #fef3c7; color: #92400e; border-radius: 10px;
  font-size: 0.9rem; text-align: center;
}

.app-footer { text-align: center; color: var(--faint); font-size: 0.78rem; padding: 26px 18px 34px; }

.toast {
  position: fixed;
  bottom: 22px;
  inset-inline-start: 50%;
  transform: translate(50%, 80px);
  background: var(--ink);
  color: var(--bg);
  padding: 12px 22px;
  border-radius: 99px;
  font-size: 0.88rem;
  font-weight: 700;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.3s;
  z-index: 60;
  pointer-events: none;
  max-width: min(90vw, 420px);
  text-align: center;
}
[dir="ltr"] .toast { transform: translate(-50%, 80px); }
.toast.show { transform: translate(50%, 0); opacity: 1; }
[dir="ltr"] .toast.show { transform: translate(-50%, 0); }

/* Focus */
.quick-btn:focus-visible,
.row-btn:focus-visible,
.btn:focus-visible,
.icon-btn:focus-visible,
.switch-label input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Responsive */
@media (max-width: 620px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stats-grid .stat-card:last-child { grid-column: 1 / -1; }
  .form-grid { grid-template-columns: 1fr; }
  .quick-grid { grid-template-columns: repeat(2, 1fr); }
  .card { padding: 18px; }
}
@media (max-width: 380px) {
  .container { padding-inline: 12px; }
  .card { padding: 14px; border-radius: 14px; }
  .brand-tag { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---- Nom additions ---- */
.stars { display: inline-flex; gap: 2px; direction: ltr; }
.star {
  background: none; border: none; padding: 2px; cursor: pointer;
  color: var(--faint); border-radius: 8px; line-height: 0;
  transition: transform 0.1s, color 0.15s;
}
.star:hover { transform: scale(1.12); }
.star.on { color: #f59e0b; }
.star:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.calc-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin: 10px 0 2px; }
.calc-row .field { flex: 1 1 160px; margin: 0; }
.calc-lead { font-size: 0.9rem; font-weight: 700; margin: 12px 0 8px; }
.chip-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.chip {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 14px; border-radius: 12px;
  background: var(--accent-ghost); border: 1px solid transparent;
}
.chip.best { border-color: var(--accent); background: var(--accent-soft); }
.chip-best {
  font-size: 0.68rem; font-weight: 800; color: #fff; background: var(--accent);
  padding: 2px 8px; border-radius: 999px;
}
.chip-time { font-size: 1.25rem; font-weight: 800; }
.chip-sub { font-size: 0.8rem; color: var(--muted); }

.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.entry-mid { flex: 1; font-size: 0.82rem; color: var(--muted); min-width: 0; }
.debt-bad { color: var(--danger); }

/* History rows wrap cleanly on narrow screens */
.entry-row { flex-wrap: wrap; }
@media (max-width: 560px) {
  .entry-mid { flex-basis: 100%; order: 5; margin-top: 2px; }
}
