/* Etqan – calm pastel RTL interface.
   Layout idea: right-hand navigation rail on desktop, bottom tab bar on phones,
   content in quiet cards; colour carries state (green met, lavender in progress, peach needs review). */
:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --ink: #243041;
  --muted: #667085;
  --line: #e1e6ef;
  --blue: #dce8f7;      --blue-ink: #2f5d93;   --accent: #4a78b5;
  --lav: #ebe5f6;       --lav-ink: #5b4b8a;
  --green: #dff2e3;     --green-ink: #2f6b3f;
  --cream: #fff8e7;     --cream-line: #f0e2bd;
  --peach: #fde7e2;     --peach-ink: #9a3b2e;
  --gray-chip: #eef1f5;
  --shadow: 0 1px 2px rgba(36, 48, 65, .06), 0 4px 14px rgba(36, 48, 65, .05);
  --font-body: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  --font-display: "Readex Pro", "IBM Plex Sans Arabic", Tahoma, sans-serif;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151a22; --surface: #1d2430; --ink: #e6eaf1; --muted: #a2acbd; --line: #2e3746;
    --blue: #22324a; --blue-ink: #a9c6ee; --accent: #7fa6dc;
    --lav: #2c2740; --lav-ink: #c9bdf0; --green: #1f3a2a; --green-ink: #9fd8ae;
    --cream: #2c2818; --cream-line: #4a4226; --peach: #3d2420; --peach-ink: #f2b3a6; --gray-chip: #283141;
    --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151a22; --surface: #1d2430; --ink: #e6eaf1; --muted: #a2acbd; --line: #2e3746;
  --blue: #22324a; --blue-ink: #a9c6ee; --accent: #7fa6dc;
  --lav: #2c2740; --lav-ink: #c9bdf0; --green: #1f3a2a; --green-ink: #9fd8ae;
  --cream: #2c2818; --cream-line: #4a4226; --peach: #3d2420; --peach-ink: #f2b3a6; --gray-chip: #283141;
  --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 15px; line-height: 1.6; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; text-wrap: balance; margin: 0; line-height: 1.35; }
h1 { font-size: 1.45rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
.num, td.num, .tile b { font-variant-numeric: tabular-nums; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100%; }
.rail { background: var(--surface); border-inline-start: 1px solid var(--line); padding: 18px 14px; display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; }
.brand-mark { width: 38px; height: 38px; border-radius: 12px; background: linear-gradient(135deg, var(--blue), var(--lav)); display: grid; place-items: center; font-family: var(--font-display); font-weight: 700; color: var(--blue-ink); font-size: 1.1rem; }
.brand b { font-family: var(--font-display); font-size: 1.2rem; display: block; }
.brand small { color: var(--muted); font-size: .78rem; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; color: var(--ink); text-decoration: none; }
.nav a:hover { background: var(--gray-chip); }
.nav a[aria-current="page"] { background: var(--blue); color: var(--blue-ink); font-weight: 600; }
.nav svg { width: 20px; height: 20px; flex: none; }
.rail .me { margin-top: auto; padding: 12px; border-radius: 12px; background: var(--gray-chip); font-size: .85rem; }
.rail .me b { display: block; }
main { padding: 22px clamp(16px, 3vw, 34px) 90px; max-width: 1180px; width: 100%; }
.demo-banner { background: var(--lav); color: var(--lav-ink); border-radius: 10px; padding: 8px 14px; font-size: .85rem; margin-bottom: 16px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.tabbar { display: none; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .rail { display: none; }
  .tabbar { display: flex; position: fixed; inset-inline: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); z-index: 20; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .tabbar a { flex: 1; text-align: center; font-size: .72rem; color: var(--muted); text-decoration: none; padding: 4px 2px; border-radius: 10px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
  .tabbar a[aria-current="page"] { color: var(--blue-ink); background: var(--blue); font-weight: 600; }
  .tabbar svg { width: 22px; height: 22px; }
  .mobile-top { display: flex !important; }
}
.mobile-top { display: none; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 10px; }

/* ---------- building blocks ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile span { color: var(--muted); font-size: .82rem; display: block; }
.tile b { font-family: var(--font-display); font-size: 1.7rem; font-weight: 600; color: var(--blue-ink); }
.tile.good { background: var(--green); border-color: transparent; } .tile.good b { color: var(--green-ink); }
.tile.warn { background: var(--peach); border-color: transparent; } .tile.warn b { color: var(--peach-ink); }
.muted { color: var(--muted); }
.small { font-size: .84rem; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 500; text-decoration: none; color: var(--ink); min-height: 40px; }
.btn:hover { background: var(--gray-chip); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); background: var(--accent); }
.btn.soft { background: var(--blue); border-color: transparent; color: var(--blue-ink); }
.btn.danger { color: var(--peach-ink); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; background: var(--gray-chip); color: var(--muted); }
.pill.met { background: var(--green); color: var(--green-ink); }
.pill.in_progress { background: var(--lav); color: var(--lav-ink); }
.pill.training_only { background: var(--blue); color: var(--blue-ink); }
.pill.warn, .pill.invalid, .pill.excess { background: var(--peach); color: var(--peach-ink); }
.pill.valid { background: var(--green); color: var(--green-ink); }
.pill.void { background: var(--gray-chip); color: var(--muted); text-decoration: line-through; }

/* forms */
label.field { display: grid; gap: 4px; font-size: .86rem; font-weight: 500; }
.field input, .field select, .field textarea, select.input, input.input { background: var(--cream); border: 1px solid var(--cream-line); border-radius: 10px; padding: 9px 12px; min-height: 42px; width: 100%; }
.field textarea { min-height: 70px; resize: vertical; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.seg { display: inline-flex; background: var(--gray-chip); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { border: 0; background: transparent; padding: 8px 18px; border-radius: 9px; cursor: pointer; min-height: 40px; }
.seg button[aria-pressed="true"] { background: var(--surface); box-shadow: var(--shadow); font-weight: 600; color: var(--blue-ink); }

/* recording */
.resp-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.resp { border: 2px solid transparent; border-radius: 14px; padding: 16px 10px; font-size: 1.05rem; font-weight: 600; cursor: pointer; min-height: 70px; }
.resp.independent { background: var(--green); color: var(--green-ink); }
.resp.assisted { background: var(--blue); color: var(--blue-ink); }
.resp.incorrect { background: var(--peach); color: var(--peach-ink); }
.resp.no_response { background: var(--gray-chip); color: var(--muted); }
.resp[aria-pressed="true"] { border-color: currentColor; box-shadow: 0 0 0 3px var(--surface) inset; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--surface); padding: 8px 14px; border-radius: 999px; cursor: pointer; min-height: 40px; }
.chip[aria-pressed="true"] { background: var(--lav); color: var(--lav-ink); border-color: transparent; font-weight: 600; }
.progress { height: 10px; background: var(--gray-chip); border-radius: 999px; overflow: hidden; }
.progress i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #8fb3e0); border-radius: 999px; }
.skill-pick { display: grid; gap: 8px; }
.skill-pick button { text-align: start; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 10px 12px; cursor: pointer; display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; }
.skill-pick button[aria-pressed="true"] { border-color: var(--accent); background: var(--blue); }
.code { font-family: var(--font-display); font-weight: 600; color: var(--blue-ink); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { background: var(--lav); color: var(--lav-ink); font-weight: 600; text-align: start; padding: 9px 10px; white-space: nowrap; }
td { padding: 9px 10px; border-top: 1px solid var(--line); vertical-align: top; }
tr.archived td { color: var(--muted); }
td.group { background: var(--blue); color: var(--blue-ink); font-weight: 600; }
td.goalcell { background: color-mix(in srgb, var(--blue) 45%, var(--surface)); font-size: .86rem; }
tbody tr:hover td:not(.group):not(.goalcell) { background: color-mix(in srgb, var(--gray-chip) 60%, transparent); }
a.row-link { color: inherit; text-decoration: none; font-weight: 600; }
a.row-link:hover { color: var(--accent); }

/* charts */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font-body); }
.chart .grid-line { stroke: var(--line); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .8rem; color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-inline-end: 4px; }

/* dialog */
.overlay { position: fixed; inset: 0; background: rgba(20, 26, 36, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.dialog { background: var(--surface); border-radius: 18px; width: min(560px, 100%); max-height: 90vh; overflow: auto; padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.dialog.wide { width: min(980px, 100%); }
.dialog h2 { margin-bottom: 12px; }
.toast { position: fixed; bottom: 86px; inset-inline-start: 50%; transform: translateX(50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 12px; z-index: 60; box-shadow: var(--shadow); }
.notice { background: var(--peach); color: var(--peach-ink); border-radius: 10px; padding: 10px 12px; font-size: .88rem; }
.notice.info { background: var(--blue); color: var(--blue-ink); }
.notice.ok { background: var(--green); color: var(--green-ink); }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login .card { width: min(720px, 100%); }
.account-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.account { text-align: start; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px; cursor: pointer; display: grid; gap: 2px; }
.account:hover { border-color: var(--accent); background: var(--blue); }

/* report (A4 at 96dpi ≈ 794 × 1123) */
.report-stage { overflow-x: auto; background: var(--gray-chip); border-radius: 14px; padding: 16px; }
.a4 { width: 794px; min-height: 1123px; margin: 0 auto; background: #fff; color: #243041; padding: 40px 44px; font-family: var(--font-body); font-size: 12.5px; line-height: 1.55; }
.a4 h1 { font-size: 20px; color: #2f5d93; }
.a4 h3 { font-size: 13.5px; margin: 16px 0 6px; color: #5b4b8a; }
.a4 table { font-size: 11.5px; }
.a4 th { background: #ebe5f6; color: #5b4b8a; }
.a4 td { border-top: 1px solid #e1e6ef; padding: 6px 8px; }
.a4 .kv { display: grid; grid-template-columns: 130px 1fr 130px 1fr; border: 1px solid #e1e6ef; border-radius: 8px; overflow: hidden; }
.a4 .kv > div { padding: 6px 10px; border-bottom: 1px solid #e1e6ef; }
.a4 .kv > .k { background: #f3f0fa; color: #5b4b8a; font-weight: 600; }
.a4 .rep-head { display: flex; justify-content: space-between; align-items: center; border-bottom: 3px solid #dce8f7; padding-bottom: 10px; margin-bottom: 14px; }
.a4 .chart text { fill: #667085; }
.a4 .chart .grid-line { stroke: #e1e6ef; }
.a4 .pill.met { background: #dff2e3; color: #2f6b3f; } .a4 .pill.in_progress { background: #ebe5f6; color: #5b4b8a; }
.a4 .foot { margin-top: 18px; color: #667085; font-size: 10.5px; border-top: 1px solid #e1e6ef; padding-top: 8px; }

@media print {
  body { background: #fff; }
  .rail, .tabbar, .no-print, .demo-banner, .page-head, .mobile-top { display: none !important; }
  main { padding: 0; max-width: none; }
  .report-stage { padding: 0; background: none; overflow: visible; }
  .a4 { width: auto; min-height: 0; padding: 0; }
  @page { size: A4; margin: 14mm; }
}

/* keep wide tables scrolling inside their own box instead of stretching the page */
main, .card, .grid > *, .tile, .dialog { min-width: 0; }
.card [style*="display:grid"] { grid-template-columns: minmax(0, 1fr); }
.btn svg { width: 18px; height: 18px; flex: none; }

/* ABA program card */
.program { display: grid; grid-template-columns: 120px 1fr; gap: 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; font-size: .88rem; background: var(--surface); }
.program > div { padding: 7px 10px; border-bottom: 1px solid var(--line); }
.program > .k { background: var(--blue); color: var(--blue-ink); font-weight: 600; }
.hint { border-inline-start: 4px solid var(--accent); background: var(--blue); color: var(--blue-ink); border-radius: 10px; padding: 9px 12px; font-size: .88rem; }
.hint.up { border-color: var(--peach-ink); background: var(--peach); color: var(--peach-ink); }
.chip small { display: block; font-size: .72rem; color: var(--muted); font-weight: 400; }
.chip.met { border-color: transparent; background: var(--green); color: var(--green-ink); }
.chip.current { box-shadow: 0 0 0 2px var(--accent) inset; }
.seg.wrap { flex-wrap: wrap; }
.session-sum { display: flex; flex-wrap: wrap; gap: 8px; font-size: .86rem; }
.session-sum span { background: var(--gray-chip); border-radius: 999px; padding: 3px 10px; }
.a4 .program > .k { background: #eef4fb; color: #2f5d93; }
