:root {
  color-scheme: light;
  --bg: #eef2f1;
  --surface: #ffffff;
  --surface-2: #f6f8f7;
  --ink: #18262b;
  --muted: #5d6e72;
  --line: #d6dedc;
  --primary: #0e5b57;
  --primary-ink: #ffffff;
  --primary-soft: #dcebe9;
  --gate: #b97c0c;
  --gate-soft: #fbf0d9;
  --ok: #2b7a4b;
  --ok-soft: #e0f1e6;
  --danger: #b23a2a;
  --danger-soft: #f8e1dd;
  --radius-s: 6px;
  --radius-m: 10px;
  --shadow: 0 1px 2px rgba(24, 38, 43, .06), 0 8px 24px rgba(24, 38, 43, .08);
  --font: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, system-ui, sans-serif;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1618; --surface: #162022; --surface-2: #1b2729; --ink: #e4ebe9; --muted: #93a4a7;
    --line: #2a3739; --primary: #56b5aa; --primary-ink: #0b1a19; --primary-soft: #183634;
    --gate: #e2b14c; --gate-soft: #3a2f16; --ok: #5ec48a; --ok-soft: #173325;
    --danger: #f08a7a; --danger-soft: #3d1d18; --shadow: 0 8px 24px rgba(0,0,0,.35);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1618; --surface: #162022; --surface-2: #1b2729; --ink: #e4ebe9; --muted: #93a4a7;
  --line: #2a3739; --primary: #56b5aa; --primary-ink: #0b1a19; --primary-soft: #183634;
  --gate: #e2b14c; --gate-soft: #3a2f16; --ok: #5ec48a; --ok-soft: #173325;
  --danger: #f08a7a; --danger-soft: #3d1d18; --shadow: 0 8px 24px rgba(0,0,0,.35);
}

*, *::before, *::after { box-sizing: inherit; }
html { scroll-padding-top: env(safe-area-inset-top, 0px); }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ── Top bar ── */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px clamp(16px, 3vw, 32px);
  background: var(--surface); border-bottom: 1px solid var(--line);
}
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 21; background: var(--surface); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; text-decoration: none; color: var(--ink); }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: var(--primary); color: var(--primary-ink); font-size: 15px; font-weight: 600;
}
.crumb { color: var(--muted); }
.crumb::before { content: "/"; margin-inline-end: 12px; color: var(--line); }
.topbar .spacer { flex: 1; }
.who { text-align: end; line-height: 1.25; }
.who small { display: block; color: var(--muted); font-size: 12px; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  padding: 8px 14px; border-radius: var(--radius-s); border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn-primary:hover { filter: brightness(1.08); background: var(--primary); }
.btn-gate { background: var(--gate-soft); color: var(--gate); border-color: transparent; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Layout ── */
.page { max-width: 1400px; margin: 0 auto; padding: 24px clamp(16px, 3vw, 32px) 64px; }
.page-head { display: flex; align-items: end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { margin: 0; font-size: 26px; font-weight: 600; letter-spacing: -.01em; }
.page-head p { margin: 2px 0 0; color: var(--muted); }
.page-head .actions { margin-inline-start: auto; display: flex; gap: 8px; }

/* ── Inputs ── */
.field { display: grid; gap: 4px; }
.field label { font-size: 13px; color: var(--muted); }
.input, .select, .textarea {
  width: 100%; padding: 8px 10px; border-radius: var(--radius-s);
  border: 1px solid var(--line); background: var(--surface);
}
.textarea { min-height: 72px; resize: vertical; }
.input[readonly] { background: var(--surface-2); color: var(--muted); }

/* ── Status chips ── */
.chip {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12.5px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap;
}
.chip[data-tone="review"] { background: var(--gate-soft); color: var(--gate); border-color: transparent; }
.chip[data-tone="done"] { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip[data-tone="bad"] { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.chip[data-tone="active"] { background: var(--primary-soft); color: var(--primary); border-color: transparent; }

/* ── Table ── */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); }
table.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
.grid th {
  position: sticky; top: 0; text-align: start; font-weight: 500; color: var(--muted);
  padding: 10px 12px; background: var(--surface-2); border-bottom: 1px solid var(--line); white-space: nowrap;
}
.grid td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid tbody tr { cursor: pointer; }
.grid tbody tr:hover td { background: var(--surface-2); }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid .uid { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; font-size: 13px; }
.grid .title { min-width: 260px; max-width: 420px; font-weight: 500; }
.empty { padding: 48px 16px; text-align: center; color: var(--muted); }

/* ── Drawer ── */
.scrim { position: fixed; inset: 0; background: rgba(10, 20, 22, .38); z-index: 40; }
.drawer {
  position: fixed; inset-block: 0; inset-inline-end: 0; z-index: 41;
  width: min(560px, 100vw); background: var(--surface); box-shadow: var(--shadow);
  display: grid; grid-template-rows: auto 1fr auto;
  padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px);
  transform: translateX(0); transition: transform .22s ease;
}
[dir="ltr"] .drawer.closing, .drawer.closing { transform: translateX(105%); }
.drawer header { padding: 18px 20px 12px; border-bottom: 1px solid var(--line); }
.drawer header h2 { margin: 4px 0 0; font-size: 18px; font-weight: 600; line-height: 1.35; }
.drawer .body { overflow-y: auto; padding: 16px 20px; display: grid; gap: 14px; align-content: start; }
.drawer footer { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; flex-wrap: wrap; }
.drawer footer .spacer { flex: 1; }

/* ── Modal ── */
.modal {
  position: fixed; z-index: 51; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(460px, calc(100vw - 32px)); background: var(--surface); border-radius: var(--radius-m);
  box-shadow: var(--shadow); padding: 22px;
}
.modal h3 { margin: 0 0 6px; font-size: 18px; font-weight: 600; }
.modal p { margin: 0 0 16px; color: var(--muted); }
.modal .choices { display: grid; gap: 8px; }
.choice {
  display: grid; gap: 2px; text-align: start; padding: 12px 14px; border-radius: var(--radius-s);
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
}
.choice:hover { border-color: var(--primary); background: var(--primary-soft); }
.choice strong { font-weight: 600; }
.choice span { color: var(--muted); font-size: 13.5px; }
.modal .row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ── Toast ── */
.toasts { position: fixed; z-index: 60; inset-inline-start: 50%; transform: translateX(-50%); bottom: calc(20px + env(safe-area-inset-bottom, 0px)); display: grid; gap: 8px; }
.toast { padding: 10px 16px; border-radius: var(--radius-s); background: var(--ink); color: var(--surface); box-shadow: var(--shadow); max-width: 90vw; }
.toast[data-type="error"] { background: var(--danger); color: #fff; }

.loading { color: var(--muted); padding: 32px 0; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media (max-width: 640px) {
  .who small { display: none; }
  .page-head h1 { font-size: 22px; }
}
