/* styles.css — Sakina. Calm, quiet, high tap-targets. ADHD-informed. */

:root {
  --bg: #f4efe3;           /* warm, paper-leaning — not hospital white */
  --surface: #fffdf8;      /* warm white card */
  --surface-2: #efe9db;
  --text: #23201b;
  --text-dim: #6f6a5f;
  --accent: #0f6b5c;       /* deep teal — the single accent */
  --accent-ink: #ffffff;
  --overdue: #d97706;      /* amber — overdue dot ONLY */
  --line: #e6dfce;
  --radius: 14px;          /* one consistent radius everywhere */
  --tap: 48px;             /* minimum tap target */
  --base: 17px;
  /* very soft card shadow */
  --shadow: 0 1px 2px rgba(60, 50, 30, 0.05), 0 4px 14px rgba(60, 50, 30, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17150f;         /* warm dark, still paper-family */
    --surface: #201d16;
    --surface-2: #272319;
    --text: #ece7db;
    --text-dim: #9c9686;
    --accent: #2a9d8a;
    --accent-ink: #06120f;
    --overdue: #eab155;
    --line: #322d22;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 14px rgba(0, 0, 0, 0.25);
  }
}

* { box-sizing: border-box; }

/* The `hidden` attribute must always win, even for elements we style with an
   explicit `display` (the gate + sheet host). Without this, those overlays
   stay on-screen and silently intercept every click. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "IBM Plex Sans Arabic", "Rubik", "Segoe UI", "Noto Naskh Arabic", "Tahoma", system-ui, sans-serif;
  font-size: var(--base);
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  cursor: pointer;
}

/* --- first-launch gate --------------------------------------------------- */
.gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  z-index: 50;
}
.gate-card { text-align: center; padding: 24px; }
.gate-card h1 { font-size: 34px; margin: 0 0 8px; color: var(--accent); }
.gate-card p { color: var(--text-dim); margin: 0 0 24px; }
.gate-choices { display: flex; gap: 16px; justify-content: center; }
.gate-btn {
  min-width: 120px;
  min-height: 56px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 20px;
}
.gate-btn:active { background: var(--surface-2); }

/* --- app shell ----------------------------------------------------------- */
.screen {
  padding: 16px 16px calc(var(--tap) + 88px);
  max-width: 620px;
  margin: 0 auto;
  min-height: 100vh;
}
.screen h2 { font-size: 23px; font-weight: 700; margin: 4px 4px 14px; }

.section-label { color: var(--text-dim); font-size: 14px; margin: 18px 4px 8px; }

/* --- filter chips -------------------------------------------------------- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 14px; }
.chip {
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-dim);
}
.chip[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

/* --- task rows ----------------------------------------------------------- */
.list { display: flex; flex-direction: column; gap: 10px; }

.row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  min-height: var(--tap);
  overflow: hidden;
  box-shadow: var(--shadow);
}

/* one-tap complete circle */
.complete {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: transparent;
  padding: 0;
}
.complete:active { background: var(--accent); }

.row-body { flex: 1 1 auto; min-width: 0; }
.row-title { display: block; overflow-wrap: anywhere; }
.row-meta { display: block; color: var(--text-dim); font-size: 13px; margin-top: 2px; }

/* overdue amber dot — the ONLY use of amber */
.overdue-dot {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--overdue);
  align-self: center;
}

.owner-tag {
  flex: 0 0 auto;
  font-size: 12px;
  color: var(--text-dim);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 2px 10px;
}

/* postpone actions revealed under a row */
.row-actions {
  display: flex;
  gap: 8px;
  padding: 0 4px 4px;
  flex-wrap: wrap;
}
.mini {
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-dim);
  font-size: 14px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  padding: 6px 4px;
  font-size: 14px;
}

/* progress like "٣/٧" — plain text, no bar */
.subprogress { color: var(--text-dim); font-size: 13px; }

/* empty state — quiet */
.empty { color: var(--text-dim); text-align: center; padding: 48px 16px; }

/* --- completed rows + "finished today" section --------------------------- */
.row-done { opacity: 0.55; }
.row-done .row-title { text-decoration: line-through; }
.complete-done { background: var(--accent); border-color: var(--accent); }

.done-section { margin-top: 22px; }
.done-header {
  width: 100%;
  min-height: var(--tap);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 4px;
  border: none;
  background: none;
  color: var(--text-dim);
  text-align: start;
}
.done-header .caret { font-size: 12px; }
.done-section .list { margin-top: 8px; }

/* --- undo snackbar (quiet) ----------------------------------------------- */
.snackbar {
  position: fixed;
  inset-inline: 16px;
  bottom: calc(var(--tap) + 16px);
  max-width: 588px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #2b312e;
  color: #f2f4f1;
  border-radius: 12px;
  padding: 10px 16px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  z-index: 45;
}
.snackbar-undo {
  min-height: 40px;
  padding: 4px 12px;
  border: none;
  background: none;
  color: #5cc2b1;
  font-weight: 600;
  font-size: var(--base);
}

/* --- floating action button ---------------------------------------------- */
.fab {
  position: fixed;
  inset-inline-start: 20px;      /* RTL: appears on the left */
  bottom: calc(var(--tap) + 26px);
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 30px;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  z-index: 30;
}

/* --- bottom tab bar ------------------------------------------------------ */
.tabbar {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  z-index: 20;
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1;
  min-height: var(--tap);
  border: none;
  background: none;
  color: var(--text-dim);
  padding: 12px 0;
}
.tab[aria-selected="true"] { color: var(--accent); font-weight: 600; }

/* --- sheets (quick add / editor) ----------------------------------------- */
.sheet-host {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  align-items: end;
  background: rgba(0, 0, 0, 0.34);
}
.sheet {
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  max-width: 620px;
  width: 100%;
  margin: 0 auto;
  max-height: 88vh;
  overflow-y: auto;
}
.sheet h3 { margin: 4px 0 14px; font-size: 19px; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; color: var(--text-dim); font-size: 14px; margin-bottom: 6px; }
.field input[type="text"],
.field input[type="date"],
.field input[type="number"],
.field textarea,
.field select {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: var(--base);
}
.field textarea { min-height: 72px; resize: vertical; }

.quick-input {
  width: 100%;
  min-height: 54px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 19px;
  margin-bottom: 14px;
}

.choice-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.choice {
  min-height: var(--tap);
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-dim);
}
.choice[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}
.choice[disabled] { opacity: 0.4; }

/* recurrence radio list */
.radio-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.radio-item {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  min-height: var(--tap);
}
.radio-item input { width: 20px; height: 20px; accent-color: var(--accent); }

.weekday-row { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 12px; }
.weekday {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text-dim);
  font-size: 14px;
}
.weekday[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

.interval-row { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.interval-row input[type="number"] { width: 84px; }
.interval-row select { flex: 1; }

/* subtasks editor */
.subtask-line { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.subtask-line input[type="text"] { flex: 1; }
.subtask-line input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }

.sheet-actions { display: flex; gap: 10px; margin-top: 8px; }
.btn-primary {
  flex: 1;
  min-height: 54px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 18px;
}
.btn-ghost {
  min-height: 54px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-dim);
}
.btn-danger { color: var(--overdue); border-color: var(--overdue); background: transparent; }

/* ========================================================================
   Phase 2 — Today header, tabs badge, search, inbox, info, appointments
   ======================================================================== */

/* --- Today header (date + Hijri + greeting) ------------------------------ */
.today-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin: 2px 2px 16px;
}
.today-date { font-size: 24px; font-weight: 700; line-height: 1.25; }
.today-hijri { color: var(--text-dim); font-size: 14px; margin-top: 2px; }
.today-greeting { color: var(--accent); font-size: 16px; margin-top: 8px; font-weight: 600; }
.today-appts-link { white-space: nowrap; }

/* --- inbox badge on the tab bar (quiet, number only) --------------------- */
.tab-badge {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  margin-inline-start: 5px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 12px;
  line-height: 18px;
  vertical-align: middle;
}
.tab[aria-selected="true"] .tab-badge { background: var(--accent); color: var(--accent-ink); }

/* --- hero search bar ----------------------------------------------------- */
.search-bar { margin: 2px 2px 14px; }
.search-input {
  width: 100%;
  min-height: 52px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 18px;
  box-shadow: var(--shadow);
}
.screen-body { display: block; }

/* --- inbox items --------------------------------------------------------- */
.inbox-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.inbox-top { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.inbox-text { flex: 1; overflow-wrap: anywhere; }
.inbox-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.mini-danger { color: var(--overdue); }

/* --- security hint ------------------------------------------------------- */
.hint {
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 14px;
}

/* --- information cards ---------------------------------------------------- */
.add-card-btn {
  width: 100%;
  min-height: var(--tap);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: transparent;
  color: var(--accent);
  margin-bottom: 14px;
}
.info-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.info-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.info-title { font-weight: 600; margin-bottom: 4px; overflow-wrap: anywhere; flex: 1; }
.info-card.pinned { border-inline-start: 3px solid var(--accent); }
.pin-btn {
  flex: 0 0 auto;
  border: none;
  background: none;
  font-size: 15px;
  line-height: 1;
  padding: 2px 4px;
  min-height: 32px;
  opacity: 0.3;
  filter: grayscale(1);
}
.pin-btn.on { opacity: 1; filter: none; }
.info-body { color: var(--text-dim); font-size: 15px; white-space: pre-wrap; overflow-wrap: anywhere; }
.note-link { color: var(--accent); text-decoration: underline; }
.note-body { min-height: 120px; }

/* --- appointments -------------------------------------------------------- */
.appt-pinned { margin-bottom: 12px; }
.appt-row { gap: 12px; }
.appt-time {
  flex: 0 0 auto;
  min-width: 48px;
  text-align: center;
  font-weight: 600;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.sub-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.sub-head h2 { margin: 0; }

/* time-bound task inside the calendar — distinct from a fixed appointment */
.cal-task .cal-task-time { color: var(--text-dim); }
.cal-task { border-inline-start: 3px dashed var(--line); }

/* quiet "بكرة عندك …" look-ahead at the bottom of Today */
.tomorrow {
  margin-top: 24px;
  padding: 12px 2px 0;
  border-top: 1px dashed var(--line);
  color: var(--text-dim);
  font-size: 13px;
}
.tomorrow-lead { font-weight: 700; color: var(--text); }

/* ========================================================================
   UX pass — subtitles, capture box, inbox distinction, week calendar
   ======================================================================== */

.screen-sub { color: var(--text-dim); font-size: 14px; margin: -8px 2px 16px; }

/* --- direct capture box (top of الوارد) ---------------------------------- */
.capture-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.capture-input {
  width: 100%;
  min-height: 52px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 18px;
  margin-bottom: 12px;
}
.capture-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.capture-main {
  min-height: var(--tap);
  padding: 0 20px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  font-size: 16px;
}
.capture-or { color: var(--text-dim); font-size: 13px; margin-inline-start: 4px; }
.capture-chip {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-dim);
  font-size: 14px;
}

/* --- inbox item: unmistakably NOT a task --------------------------------- */
.inbox-item { border-inline-start: 3px dashed var(--text-dim); }
.inbox-top { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.inbox-badge-tag {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 2px 9px;
}
.inbox-hint { color: var(--text-dim); font-size: 13px; align-self: center; }

/* --- week calendar ------------------------------------------------------- */
.week-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 6px 2px 16px;
}
.week-btn {
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-dim);
  font-size: 14px;
}
.week-label { text-align: center; }
.week-title { font-weight: 700; font-size: 16px; }
.week-range { color: var(--text-dim); font-size: 12px; margin-top: 2px; }

/* horizontal week strip — 7 day columns across the width */
.week-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
  margin-bottom: 18px;
}
.day-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: 64px;
  padding: 8px 1px 7px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
}
.col-name { font-size: 11px; color: var(--text-dim); }
.col-num { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.col-dots { display: flex; gap: 3px; min-height: 6px; }
.col-dot { width: 5px; height: 5px; border-radius: 50%; }
.dot-appt { background: var(--accent); }
.dot-task { background: var(--text-dim); }

/* calm colour cue for time-distance */
.day-col.rel-today {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
}
.day-col.rel-today .col-name { color: var(--accent); font-weight: 700; }
.day-col.rel-tomorrow { background: color-mix(in srgb, var(--accent) 4%, var(--surface)); }
.day-col.rel-past { opacity: 0.5; }
.day-col.selected { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

/* --- important flag + waiting (blocked) tasks ---------------------------- */
.star { color: var(--accent); font-size: 14px; margin-inline-end: 6px; }
.important-toggle[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}
.row.is-waiting { opacity: 0.6; }
.row.is-waiting .complete { border-color: var(--text-dim); }

.field-label { color: var(--text-dim); font-size: 14px; margin: 16px 2px 8px; }

/* --- settings button + household members --------------------------------- */
.settings-btn {
  position: fixed;
  top: 14px;
  inset-inline-end: 14px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 20px;
  line-height: 1;
  z-index: 25;
  opacity: 0.7;
}
.settings-btn:active { background: var(--surface-2); }

.members-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.member-line { display: flex; align-items: center; gap: 8px; }
.member-line input[type="text"] {
  flex: 1;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: var(--base);
}
.mini[disabled] { opacity: 0.35; }
