/* Design system. Edit these tokens and the whole app follows —
   change --accent once rather than hunting hex codes through the markup. */
:root {
  --bg: #111111;
  --fg: #ffffff;
  --mute: #9ca3af;
  --card: #181818;
  --border: #272727;
  --accent: #ef4444;
  --danger: #ef4444;
  --ok: #ffffff;
  --on-accent: #ffffff; /* text and icons drawn on --accent */
  --radius: 12px;
  /* Real height of the tab bar, used to pad the scroll area so the last row
     is never trapped underneath it. */
  --tabbar: calc(58px + env(safe-area-inset-bottom));
}

/* A light look: set <html data-theme="light"> (or "dark" back) and change these
   alongside :root. Every colour below is a token, so nothing else needs touching. */
[data-theme=light] {
  --bg: #ffffff;
  --fg: #111111;
  --mute: #5b6070;
  --card: #f3f3f6;
  --border: #dcdcdc;
  --accent: #ef4444;
  --danger: #ef4444;
  --ok: #111111;
  --on-accent: #ffffff;
  color-scheme: light;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  min-height: 100vh;
  min-height: 100dvh; /* dvh survives the mobile URL bar collapsing */
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  /* No pull-to-refresh bounce past the ends: the giveaway that a PWA is a
     web page wearing a costume. */
  overscroll-behavior-y: none;
}

/* ── Right-to-left ───────────────────────────────────────────────────
   Set <html lang="ar" dir="rtl"> and this file flips by itself: spacing and
   alignment use logical properties (margin-inline, padding-inline, inset-inline,
   text-align: start). The exception is the safe-area padding on the bars below:
   a notch or home indicator is on a physical side, so those stay left/right. */

/* ── App bar ─────────────────────────────────────────────────────── */
.appbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: .75rem;
  padding: calc(env(safe-area-inset-top) + .875rem) calc(1.25rem + env(safe-area-inset-right)) .875rem calc(1.25rem + env(safe-area-inset-left));
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.appbar h1 { font-size: 1.125rem; font-weight: 650; letter-spacing: -.02em; word-break: break-word; }
.status { display: inline-flex; align-items: center; gap: .375rem; margin-inline-start: auto; flex: none; padding: .25rem .625rem; background: var(--card); border: 1px solid var(--border); border-radius: 999px; font-size: .6875rem; color: var(--mute); }
.status .dot { width: 6px; height: 6px; background: #22c55e; border-radius: 50%; box-shadow: 0 0 8px #22c55e; }

/* ── Screens ─────────────────────────────────────────────────────── */
main { padding: 1rem calc(1.25rem + env(safe-area-inset-right)) calc(var(--tabbar) + 1.5rem) calc(1.25rem + env(safe-area-inset-left)); }
.screen { display: none; }
.screen.active { display: block; animation: rise .18s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card { padding: 1.25rem; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); margin-block-end: .875rem; }
.card h2 { font-size: 1rem; font-weight: 600; letter-spacing: -.01em; margin-block-end: .375rem; }
.card p { font-size: .875rem; color: var(--mute); line-height: 1.55; }

.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; margin-block-start: .875rem; padding-inline: 1.25rem; background: var(--accent); color: var(--on-accent); border: 0; border-radius: 10px; font-size: .9375rem; font-weight: 600; font-family: inherit; cursor: pointer; }
.btn:active { transform: scale(.98); }

.list { list-style: none; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .875rem 1.25rem; font-size: .875rem; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list .meta { color: var(--mute); font-size: .75rem; flex: none; }

footer { margin-block-start: 1.5rem; text-align: center; font-size: .75rem; color: var(--mute); }
footer a { color: var(--mute); }

/* ── Bottom tab bar ──────────────────────────────────────────────── */
.tabbar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 20;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--border);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: 58px; padding: 0; border: 0; background: none; cursor: pointer;
  color: var(--mute); font-family: inherit; font-size: .625rem; font-weight: 500;
  -webkit-tap-highlight-color: transparent;
}
.tab svg { width: 22px; height: 22px; }
.tab.active { color: var(--accent); }

/* ── Forms and states ────────────────────────────────────────────────
   Unused until the app needs them: no markup here uses them, they carry no copy,
   and every colour is a token. 16px text stops iOS zooming the page when a field
   is focused; 44px is a comfortable tap. */
label { display: block; font-size: .875rem; font-weight: 500; margin-block-end: .375rem; }
.form-group { display: flex; flex-direction: column; margin-block-end: 1rem; }
input, select, textarea { width: 100%; min-height: 44px; padding: .625rem .875rem; background: var(--card); color: var(--fg); border: 1px solid var(--border); border-radius: 10px; font: inherit; font-size: 1rem; text-align: start; }
textarea { min-height: 96px; resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: auto; min-height: 0; }
input::placeholder, textarea::placeholder { color: var(--mute); }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--danger); }
[hidden] { display: none !important; }
.btn:disabled, .btn[aria-busy="true"] { opacity: .55; cursor: not-allowed; }
.loading { display: flex; align-items: center; gap: .625rem; color: var(--mute); font-size: .875rem; }
.loading::before { content: ""; width: 1rem; height: 1rem; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.error { padding: .75rem 1rem; background: rgba(248, 113, 113, .1); background: color-mix(in srgb, var(--danger) 12%, var(--bg)); border: 1px solid var(--danger); border-radius: 10px; color: var(--fg); font-size: .875rem; }
.empty { padding: 2rem 1rem; text-align: center; border: 1px dashed var(--border); border-radius: var(--radius); color: var(--mute); font-size: .9375rem; }

/* ── Components ──────────────────────────────────────────────────────
   Small, on the tokens, RTL-safe. Use them as they are; change the tokens, not
   these. Behaviour lives in app.js: api(), toast(), sheet(). */

/* row: one line of a list. Put rows in a .list (or any card). */
.row { display: flex; align-items: center; gap: .75rem; min-height: 56px; padding: .625rem 1.25rem; border-block-end: 1px solid var(--border); }
.row:last-child { border-block-end: 0; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-size: .9375rem; overflow-wrap: anywhere; }
.row-sub { font-size: .75rem; color: var(--mute); }
.row .btn { margin: 0; min-height: 44px; }
.list-actions { display: flex; flex-wrap: wrap; gap: .75rem; margin-block-start: .875rem; }
.list-actions .btn { flex: 1 1 8rem; min-width: 0; margin: 0; }
.btn.secondary { background: var(--card); color: var(--fg); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); color: var(--on-accent); }
.btn.block { display: flex; width: 100%; }

/* field: a label, a control and a hint under it; .invalid turns the hint red. */
.field { display: flex; flex-direction: column; gap: .375rem; margin-block-end: 1rem; }
.field label { margin: 0; }
.field .hint { font-size: .75rem; color: var(--mute); }
.field.invalid .hint { color: var(--danger); }
.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--danger); }

/* sheet: a panel that slides up over the page (sheet() in app.js builds it). */
.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .5); animation: fade .15s ease-out; }
.sheet { position: fixed; inset-inline: 0; bottom: 0; z-index: 41; max-height: 85vh; max-height: 85dvh; overflow-y: auto; overscroll-behavior: contain; padding: 1.25rem calc(1.25rem + env(safe-area-inset-right)) calc(1.25rem + env(safe-area-inset-bottom)) calc(1.25rem + env(safe-area-inset-left)); background: var(--card); color: var(--fg); border-block-start: 1px solid var(--border); border-radius: calc(var(--radius) + 6px) calc(var(--radius) + 6px) 0 0; animation: slide .2s ease-out; }
.sheet h2 { font-size: 1.0625rem; font-weight: 600; margin-block-end: .5rem; }
.sheet p { color: var(--mute); font-size: .9375rem; }
.sheet-actions { display: flex; gap: .75rem; margin-block-start: 1.25rem; }
.sheet-actions .btn { flex: 1; margin: 0; }
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateY(100%); } }

/* segmented: pick one of a few options (tablist semantics, aria-selected). */
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px; padding: 3px; margin-block-end: 1rem; background: var(--bg); border: 1px solid var(--border); border-radius: 12px; }
.segmented button { min-height: 40px; padding-inline: .75rem; border: 0; border-radius: 9px; background: none; color: var(--mute); font: inherit; font-size: .875rem; font-weight: 500; cursor: pointer; }
.segmented button[aria-selected="true"] { background: var(--card); color: var(--fg); box-shadow: 0 0 0 1px var(--border); }

/* toast: a short message over the tab bar (toast() in app.js). */
.toast { position: fixed; inset-inline: 0; inset-block-end: calc(var(--tabbar) + .75rem); z-index: 50; width: fit-content; max-width: calc(100% - 2.5rem); margin-inline: auto; padding: .625rem 1rem; background: var(--fg); color: var(--bg); border-radius: 999px; font-size: .875rem; text-align: center; animation: rise .18s ease-out; }
.toast.error { background: var(--danger); color: var(--on-accent); }

/* empty state: .empty already exists; these add a heading, an icon slot and an action. */
.empty strong { display: block; margin-block-end: .25rem; color: var(--fg); font-weight: 600; }
.empty .btn { margin-block-start: 1rem; }

/* badge: a small status pill. */
.badge { display: inline-flex; align-items: center; padding: .125rem .5rem; border: 1px solid var(--border); border-radius: 999px; background: var(--bg); color: var(--mute); font-size: .6875rem; font-weight: 600; line-height: 1.4; white-space: nowrap; }
.badge.ok { color: var(--ok); border-color: var(--ok); }
.badge.accent { color: var(--accent); border-color: var(--accent); }
.badge.danger { color: var(--danger); border-color: var(--danger); }

/* avatar: a round picture or initials. */
.avatar { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 40px; height: 40px; overflow: hidden; border-radius: 50%; background: var(--accent); color: var(--on-accent); font-size: .9375rem; font-weight: 600; text-transform: uppercase; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.large { width: 72px; height: 72px; font-size: 1.5rem; }

.link { color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  .screen.active, .toast, .sheet, .sheet-backdrop { animation: none; }
  .loading::before { animation-duration: 2.4s; }
}

/* ── Site Handover additions ─────────────────────────────────────────── */

/* Pair of fields side by side (RTL-safe). */
.pair { display: flex; flex-wrap: wrap; gap: .75rem; }
.pair > .field { flex: 1 1 9rem; min-width: 0; }

/* A project row on the dashboard. */
.dash-row { display: flex; align-items: center; gap: .75rem; padding: .75rem 1rem; border-block-end: 1px solid var(--border); }
.dash-row:last-child { border-block-end: 0; }
.dash-row .dash-main { flex: 1; min-width: 0; }
.dash-row .dash-title { font-size: .9375rem; overflow-wrap: anywhere; }
.dash-row .dash-sub { font-size: .75rem; color: var(--mute); }
.dash-row .dash-actions { display: flex; flex-direction: column; gap: .5rem; flex: none; }
.dash-row .badge { font-size: .6875rem; padding: .125rem .5rem; }

/* Checklist rows. */
.check { padding: .875rem 0; border-block-end: 1px solid var(--border); }
.check .segmented { grid-auto-flow: row; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.check .segmented button { min-width: 0; min-height: 44px; }
.dash-row { flex-wrap: wrap; }
.dash-row .dash-main { flex: 1 1 9rem; }
.dash-row .dash-actions { flex-direction: row; align-items: center; flex-wrap: wrap; }
.check:last-child { border-block-end: 0; }
.check-name { font-weight: 600; overflow-wrap: anywhere; }
.check-hint { font-size: .75rem; color: var(--mute); margin-block-end: .5rem; }

/* Client preview sheet: paper white on the dark workspace. */
.client-sheet { background: #ffffff; color: #111111; border: 1px solid #dcdcdc; border-radius: 12px; padding: 1rem 1.25rem; }
.client-sheet h2, .client-sheet h3, .client-sheet h4 { color: #111111; margin-block-end: .5rem; }
.client-sheet p, .client-sheet li { color: #111111; }
.client-sheet .mute { color: #5b6070; }
.cs-head { display: flex; align-items: baseline; gap: .5rem; margin-block-end: .75rem; }
.cs-title { font-size: 1.125rem; font-weight: 650; letter-spacing: -.02em; }
.cs-sample { font-size: .75rem; color: #ef4444; border: 1px solid #ef4444; border-radius: 999px; padding: .125rem .5rem; font-weight: 600; white-space: nowrap; }
.cs-row { display: flex; justify-content: space-between; gap: 1rem; padding: .5rem 0; border-bottom: 1px solid #e5e5e5; }
.cs-row:last-child { border-bottom: 0; }
.cs-label { color: #5b6070; font-size: .875rem; flex: none; white-space: nowrap; }
.cs-value { text-align: end; overflow-wrap: break-word; font-size: .875rem; }
.cs-value a { color: #ef4444; text-decoration: underline; }
.cs-note { font-size: .75rem; color: #5b6070; margin-block-start: .75rem; }

/* Renewal rows in the editor. */
.renewal-row { display: flex; gap: .5rem; align-items: center; margin-block-end: .5rem; }
.renewal-row > input { flex: 1; min-width: 0; }
.renewal-row .btn { min-height: 36px; padding-inline: .625rem; font-size: .8125rem; }

/* OK badge on dark needs dark text on white fill. */
.badge.ok { background: var(--ok); color: #111111; border-color: var(--ok); }

/* Print: only the handover sheet, one page. */
@media print {
  body { background: #ffffff !important; color: #111111 !important; }
  body > *:not(.print-view) { display: none !important; }
  .print-view { position: static; width: 100%; }
  .print-view .client-sheet { border: 0; box-shadow: none; width: 100%; }
  .cs-row { border-bottom-color: #dcdcdc; }
  @page { size: A4; margin: 14mm 14mm 16mm; }
}
