/* Hessa demo: a phone-first working tool. Sticky app bar, bottom tab bar, content capped at 720px. */
:root {
  --bg: #EDF1EF; --surface: #FFFFFF; --sunk: #F4F7F5; --ink: #14201C; --muted: #5A6A65; --line: #D5DED9;
  --accent: #1D6B57; --accent-soft: #DCEEE6; --on-accent: #FFFFFF;
  --ok: #1E7D46; --ok-soft: #DCF0E3; --warn: #9C5E14; --warn-soft: #F7EAD3; --bad: #B23825; --bad-soft: #F7DED9;
  --wa: #1FA855; --on-wa: #FFFFFF;
  --f-display: "Readex Pro", "IBM Plex Sans Arabic", system-ui, sans-serif;
  --f-body: "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  --r: 12px;
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1513; --surface: #161F1C; --sunk: #121A17; --ink: #E4EDE9; --muted: #98AAA3; --line: #2A3732;
    --accent: #52B797; --accent-soft: #1C3A30; --on-accent: #08130F;
    --ok: #5CC88A; --ok-soft: #173426; --warn: #E0A456; --warn-soft: #3A2B15; --bad: #F07F6C; --bad-soft: #3D1E19;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--f-body); font-size: 15px; line-height: 1.5; min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--f-display); margin: 0; line-height: 1.3; text-wrap: balance; }
h2 { font-size: 1.1rem; font-weight: 600; }
h3 { font-size: .98rem; font-weight: 600; }
p { margin: 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .84rem; }
.mono { font-family: var(--f-mono); font-size: .86em; letter-spacing: .02em; direction: ltr; unicode-bidi: isolate; }
.ltr { direction: ltr; unicode-bidi: isolate; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* App bar */
.appbar { position: sticky; top: 0; z-index: 10; background: var(--accent); color: var(--on-accent); padding-top: env(safe-area-inset-top, 0px); }
.appbar-in { max-width: 720px; margin: 0 auto; display: flex; align-items: center; gap: 8px; min-height: 56px;
  padding-left: max(8px, env(safe-area-inset-left, 0px)); padding-right: max(8px, env(safe-area-inset-right, 0px)); }
.appbar h1 { flex: 1; font-size: 1.15rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-inline: 8px; }
.icon-btn { background: none; border: 0; color: inherit; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; }
.icon-btn:hover { background: rgba(255,255,255,.12); }
[dir=rtl] #backBtn svg { transform: scaleX(-1); }

/* Main */
main { max-width: 720px; margin: 0 auto; display: grid; gap: 14px;
  padding-top: 16px; padding-bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom, 0px));
  padding-left: max(14px, env(safe-area-inset-left, 0px)); padding-right: max(14px, env(safe-area-inset-right, 0px)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; display: grid; gap: 10px; min-width: 0; }
.card.tap { cursor: pointer; }
.card.tap:hover { border-color: var(--accent); }
.head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 10px; }
.sect-title { font-size: .76rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; margin-top: 4px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.note { font-size: .84rem; color: var(--muted); background: var(--sunk); border: 1px dashed var(--line); border-radius: 10px; padding: 9px 12px; }
.empty { text-align: center; color: var(--muted); padding: 22px 10px; display: grid; gap: 10px; justify-items: center; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface);
  border-radius: 10px; padding: 9px 14px; cursor: pointer; font-weight: 500; text-decoration: none; color: var(--ink); min-height: 42px; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.btn.wa { background: var(--wa); color: var(--on-wa); border-color: var(--wa); }
.btn.block { width: 100%; }
.btn.big { min-height: 54px; font-size: 1.05rem; font-weight: 600; }
.btn.sm { min-height: 34px; padding: 5px 11px; font-size: .86rem; }
.btn.danger { color: var(--bad); }
.btn.armed { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* Forms */
.form { display: grid; gap: 12px; }
.field { display: grid; gap: 5px; font-size: .86rem; color: var(--muted); font-weight: 500; }
.field input, .field select, .field textarea, .input {
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 1rem; width: 100%; min-width: 0; }
.field textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.days { display: flex; flex-wrap: wrap; gap: 6px; }
.days label { position: relative; }
.days input { position: absolute; opacity: 0; inset: 0; }
.days span { display: inline-block; border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; cursor: pointer; color: var(--ink); background: var(--surface); font-size: .9rem; }
.days input:checked + span { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.days input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--ink); cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

/* Chips / segmented */
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 13px; cursor: pointer; white-space: nowrap; font-size: .9rem; }
.chip.on { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.stats.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; display: grid; }
.stat b { font-family: var(--f-display); font-size: 1.35rem; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat span { font-size: .72rem; color: var(--muted); }
.stat.ok b { color: var(--ok); } .stat.warn b { color: var(--warn); } .stat.bad b { color: var(--bad); }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; display: grid; }
.item { display: flex; align-items: center; justify-content: space-between; gap: 8px 12px; padding: 10px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.item:first-child { border-top: 0; }
.item.tap { cursor: pointer; }
.item .who { display: grid; min-width: 0; flex: 1; }
.item .nm { font-weight: 600; overflow-wrap: anywhere; }
.item .sub { font-size: .82rem; color: var(--muted); }
.mark { border-inline-start: 3px solid transparent; padding-inline-start: 10px; }
.mark.present { border-inline-start-color: var(--ok); }
.mark.late { border-inline-start-color: var(--warn); }
.mark.absent { border-inline-start-color: var(--bad); }
.flash { animation: flash 1s; }
@keyframes flash { from { background: var(--ok-soft); } to { background: transparent; } }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 7px 12px; cursor: pointer; font-size: .86rem; color: var(--muted); min-height: 38px; }
.seg button + button { border-inline-start: 1px solid var(--line); }
.seg button.on.k-present { background: var(--ok-soft); color: var(--ok); font-weight: 600; }
.seg button.on.k-late { background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.seg button.on.k-absent { background: var(--bad-soft); color: var(--bad); font-weight: 600; }

.pill { display: inline-block; font-size: .74rem; padding: 2px 9px; border-radius: 999px; font-weight: 600; white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.neutral { background: var(--sunk); color: var(--muted); border: 1px solid var(--line); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }

.score { width: 76px; text-align: center; font-variant-numeric: tabular-nums; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font-size: 1rem; }
.bar { height: 6px; background: var(--sunk); border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); }

/* Message preview */
.bubble { background: var(--accent-soft); border-radius: 12px; border-start-start-radius: 3px; padding: 10px 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--warn-soft); color: var(--warn); border-radius: var(--r); padding: 10px 14px; font-weight: 500; cursor: pointer; border: 0; width: 100%; text-align: start; }

/* QR */
.qr { width: 160px; height: 160px; image-rendering: pixelated; background: #fff; border-radius: 6px; }
.qr-wrap { display: grid; justify-items: center; gap: 4px; }

/* Bottom nav */
nav.bottom { position: fixed; z-index: 10; inset-inline: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--line);
  display: flex; justify-content: center; padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px); }
nav.bottom .in { display: grid; grid-template-columns: repeat(5, 1fr); width: 100%; max-width: 720px; }
.nav-b { background: none; border: 0; cursor: pointer; display: grid; justify-items: center; gap: 2px; padding: 8px 2px; height: var(--nav-h); color: var(--muted); font-size: .72rem; position: relative; }
.nav-b svg { width: 24px; height: 24px; }
.nav-b.on { color: var(--accent); font-weight: 600; }
.nav-b .dot { position: absolute; top: 6px; inset-inline-start: calc(50% + 6px); background: var(--bad); color: #fff; font-size: .66rem; border-radius: 999px; padding: 0 6px; line-height: 1.6; }

/* Modal sheet */
.modal { position: fixed; inset: 0; z-index: 30; background: rgba(6, 12, 10, .55); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; display: grid; gap: 14px;
  padding: 18px max(16px, env(safe-area-inset-right, 0px)) calc(18px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); }
@media (min-width: 600px) { .modal { align-items: center; } .sheet { border-radius: 18px; } }

/* Scanner */
.scanner { position: fixed; inset: 0; z-index: 40; background: #000; color: #fff; }
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-frame { position: absolute; top: 50%; left: 50%; width: min(66vw, 300px); aspect-ratio: 1; transform: translate(-50%, -55%);
  border: 3px solid rgba(255,255,255,.9); border-radius: 18px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.45); }
.scan-top { position: absolute; top: 0; inset-inline: 0; display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 14px 12px; }
.scan-group { font-weight: 600; font-family: var(--f-display); }
.scan-top .btn { background: rgba(0,0,0,.5); color: #fff; border-color: rgba(255,255,255,.4); }
.scan-bottom { position: absolute; bottom: 0; inset-inline: 0; padding: 14px 14px calc(18px + env(safe-area-inset-bottom, 0px)); display: grid; gap: 8px; }
.scan-result { background: rgba(0,0,0,.65); border-radius: 14px; padding: 12px 14px; font-size: 1.05rem; font-weight: 600; min-height: 50px; display: grid; gap: 8px; }
.scan-result.ok { background: #1E7D46; } .scan-result.warn { background: #9C5E14; } .scan-result.bad { background: #B23825; }
.scan-result .row-actions .btn { background: #fff; color: #111; border-color: #fff; }
.scan-count { text-align: center; font-size: .9rem; opacity: .85; }

.toast { position: fixed; z-index: 50; inset-inline: 0; margin: 0 auto; width: max-content; max-width: calc(100% - 32px);
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom, 0px)); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 500; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.toast.bad { background: var(--bad); color: #fff; } .toast.warn { background: var(--warn); color: #fff; }

/* Welcome */
.welcome { display: grid; gap: 14px; padding-top: 10px; }
.welcome .logo { font-family: var(--f-display); font-size: 2.4rem; font-weight: 700; color: var(--accent); }

/* Print: QR cards on A4 */
#print-area { display: none; }
@media print {
  body > *:not(#print-area) { display: none !important; }
  body { background: #fff; }
  #print-area { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6mm; padding: 6mm; color: #000; }
  .pcard { border: 1px dashed #888; border-radius: 4mm; padding: 4mm; display: grid; justify-items: center; gap: 1.5mm; text-align: center; break-inside: avoid; }
  .pcard img { width: 38mm; height: 38mm; image-rendering: pixelated; }
  .pcard .t { font-size: 9pt; color: #1D6B57; font-weight: 700; }
  .pcard .n { font-size: 11pt; font-weight: 700; }
  .pcard .c { font-family: monospace; font-size: 10pt; }
  .pcard .g { font-size: 8pt; color: #444; }
}
@media (max-width: 420px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } .seg { width: 100%; } .seg button { flex: 1; } }
@media (prefers-reduced-motion: reduce) { .flash { animation: none; } }
