:root {
  --bg: #f6f7f9; --card: #fff; --ink: #0f172a; --muted: #64748b; --line: #e2e8f0;
  --brand: #047857; --brand-ink: #fff; --brand-soft: #ecfdf5;
  --ok: #15803d; --ok-soft: #dcfce7; --bad: #b91c1c; --bad-soft: #fee2e2; --warn: #a16207; --warn-soft: #fef9c3;
  --radius: 14px; --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 2px 8px rgb(0 0 0 / .04);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b1120; --card: #131c2e; --ink: #e2e8f0; --muted: #94a3b8; --line: #23304a;
    --brand: #10b981; --brand-ink: #04281d; --brand-soft: #0f2a22;
    --ok: #4ade80; --ok-soft: #12321f; --bad: #f87171; --bad-soft: #3a1717; --warn: #facc15; --warn-soft: #3a3210; }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: system-ui, "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif; background: var(--bg); color: var(--ink);
  font-size: 16px; line-height: 1.5; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
h1 { font-size: 1.35rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
a { color: var(--brand); }
.muted { color: var(--muted); font-size: .9rem; }
.small { font-size: .85rem; }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.wrap { max-width: 640px; margin: 0 auto; padding: 16px 16px 96px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; }
.stack > * + * { margin-top: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
label { display: block; font-size: .9rem; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: 4px; }
input, select, textarea { width: 100%; font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 12px; min-height: 46px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
input[type=checkbox] { width: auto; min-height: 0; }
button, .btn { font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 10px; padding: 10px 16px; min-height: 44px; cursor: pointer; text-decoration: none; display: inline-flex;
  align-items: center; justify-content: center; gap: 6px; }
button.primary, .btn.primary { background: var(--brand); color: var(--brand-ink); border-color: transparent; }
button.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
button.block { width: 100%; }
button.sm { min-height: 34px; padding: 4px 10px; font-size: .85rem; }
button:disabled { opacity: .55; cursor: default; }
.err { color: var(--bad); font-size: .9rem; min-height: 1.2em; margin: 6px 0 0; }
.badge { display: inline-block; font-size: .78rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--line); color: var(--ink); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }
.seg { display: flex; background: var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; min-height: 40px; }
.seg button[aria-pressed=true] { background: var(--card); box-shadow: var(--shadow); }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 12px 0; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; }
.qr { background: #fff; border-radius: 12px; padding: 8px; display: inline-block; line-height: 0; }
.qr svg { width: min(72vw, 280px); height: auto; }
.code-big { font-size: 2rem; font-weight: 700; letter-spacing: .3em; direction: ltr; font-variant-numeric: tabular-nums; }
.center { text-align: center; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.top img { width: 36px; height: 36px; border-radius: 9px; }

/* bottom tabs (resident app) */
.tabs { position: fixed; inset: auto 0 0 0; background: var(--card); border-top: 1px solid var(--line); display: flex;
  padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
.tabs button { flex: 1; border: 0; border-radius: 0; background: transparent; flex-direction: column; gap: 2px; min-height: 60px;
  font-size: .78rem; font-weight: 600; color: var(--muted); position: relative; }
.tabs button svg { width: 22px; height: 22px; }
.tabs button[aria-current=page] { color: var(--brand); }
.tabs .dot { position: absolute; top: 6px; inset-inline-start: calc(50% + 6px); min-width: 18px; height: 18px; border-radius: 9px;
  background: var(--bad); color: #fff; font-size: .7rem; line-height: 18px; padding: 0 5px; }

/* bottom sheet / dialog */
dialog { border: 0; border-radius: 18px; padding: 0; width: min(560px, calc(100vw - 24px)); background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgb(0 0 0 / .5); }
dialog .body { padding: 20px; max-height: 85dvh; overflow: auto; }
.toast { position: fixed; inset: auto 16px 84px 16px; margin: 0 auto; max-width: 480px; background: var(--ink); color: var(--bg);
  border-radius: 12px; padding: 12px 16px; z-index: 50; text-align: center; box-shadow: var(--shadow); }
.days { display: flex; gap: 4px; flex-wrap: wrap; }
.days label { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); border-radius: 99px; padding: 6px 10px; color: var(--ink); }

/* admin layout */
.admin { display: grid; grid-template-columns: 220px 1fr; min-height: 100dvh; }
.admin nav { background: var(--card); border-inline-end: 1px solid var(--line); padding: 16px 10px; position: sticky; top: 0; height: 100dvh; overflow: auto; }
.admin nav button { width: 100%; justify-content: flex-start; border: 0; background: transparent; margin-bottom: 2px; }
.admin nav button[aria-current=page] { background: var(--brand-soft); color: var(--brand); }
.admin main { padding: 20px; min-width: 0; }
.admin main > section { max-width: 1100px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat b { display: block; font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: start; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: .82rem; white-space: nowrap; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; margin-bottom: 12px; }
.toolbar > * { width: auto; }
.toolbar input, .toolbar select { min-height: 40px; padding: 7px 10px; }
@media (max-width: 760px) {
  .admin { grid-template-columns: 1fr; }
  .admin nav { position: sticky; height: auto; display: flex; overflow-x: auto; padding: 8px; gap: 4px; z-index: 5; }
  .admin nav button { width: auto; white-space: nowrap; margin: 0; }
  .admin nav .brandline { display: none; }
  .admin main { padding: 12px; }
}

/* printing (activation cards, poster) */
.print-only { display: none; }
@media print {
  body { background: #fff; color: #000; }
  .no-print, .admin nav, .tabs { display: none !important; }
  .print-only { display: block; }
  .admin { display: block; }
  .card { box-shadow: none; break-inside: avoid; }
}
.codes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.code-card { border: 1px dashed #94a3b8; border-radius: 12px; padding: 12px; text-align: center; break-inside: avoid; background: #fff; color: #000; }
.code-card .k { font-size: 1.3rem; font-weight: 700; letter-spacing: .12em; direction: ltr; }
.poster { background: #fff; color: #000; text-align: center; padding: 32px; border-radius: 16px; }
.poster h1 { font-size: 2.2rem; }
.poster .qr svg { width: 340px; }
