:root {
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-2: #eef3f1;
  --border: #d6e0dc;
  --text: #13201c;
  --muted: #4f625b;
  --primary: #0e6b62;
  --primary-strong: #0a524b;
  --primary-soft: #dcefeb;
  --on-primary: #ffffff;
  --ok: #16703a;  --ok-soft: #dff3e6;
  --warn: #8a5300; --warn-soft: #fbeed5;
  --bad: #b3261e;  --bad-soft: #fbe3e1;
  --info: #1d5a99; --info-soft: #e0ecf8;
  --shadow: 0 1px 2px rgba(16, 40, 34, .06), 0 4px 16px rgba(16, 40, 34, .06);
  --radius: 14px;
  --radius-sm: 10px;
  --font: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1614; --surface: #17211e; --surface-2: #1e2a27; --border: #2c3b37;
    --text: #e8f0ed; --muted: #a3b5af; --primary: #4fb8aa; --primary-strong: #74cdc1; --primary-soft: #1b3531;
    --on-primary: #06201c;
    --ok: #6fd394; --ok-soft: #173325; --warn: #f1b75a; --warn-soft: #3a2b12; --bad: #ff8a80; --bad-soft: #3d1c1a;
    --info: #8fc1f5; --info-soft: #172b40; --shadow: 0 1px 2px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16px; line-height: 1.6;
  -webkit-tap-highlight-color: transparent; min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; unicode-bidi: isolate; display: inline-block; }
[hidden] { display: none !important; }
.banner svg { width: 20px; height: 20px; flex-shrink: 0; }

/* ===== الهيكل ===== */
.app { display: flex; min-height: 100dvh; }
.side { display: none; }
.main { flex: 1; min-width: 0; padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; display: flex; align-items: center; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.brand img { width: 32px; height: 32px; }
.brand small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); line-height: 1.2; }
.topbar .spacer { flex: 1; }
.env-badge { font-size: 12px; background: var(--warn-soft); color: var(--warn); padding: 2px 10px; border-radius: 99px; font-weight: 600; }
.content { padding: 16px; max-width: 1100px; margin: 0 auto; }
.banner { margin: 0; padding: 10px 16px; font-size: 14px; font-weight: 600; display: flex; gap: 8px; align-items: center; }
.banner.offline { background: var(--bad-soft); color: var(--bad); }

.tabbar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--border);
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 6px; min-height: 60px;
  color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 500;
}
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a[aria-current="page"] { color: var(--primary); font-weight: 700; }
.tabbar a[aria-current="page"] svg { stroke-width: 2.4; }

@media (min-width: 900px) {
  .tabbar { display: none; }
  .main { padding-bottom: 24px; }
  .side {
    display: flex; flex-direction: column; width: 250px; flex-shrink: 0; background: var(--surface);
    border-inline-end: 1px solid var(--border); position: sticky; top: 0; height: 100dvh; overflow-y: auto; padding: 16px 12px;
  }
  .side .brand { padding: 4px 8px 16px; }
  .side h3 { font-size: 12px; color: var(--muted); margin: 16px 10px 6px; font-weight: 600; }
  .side a {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--radius-sm);
    color: var(--text); text-decoration: none; font-weight: 500;
  }
  .side a svg { width: 20px; height: 20px; color: var(--muted); }
  .side a:hover { background: var(--surface-2); }
  .side a[aria-current="page"] { background: var(--primary-soft); color: var(--primary-strong); font-weight: 700; }
  .side a[aria-current="page"] svg { color: var(--primary); }
  .topbar .brand { display: none; }
  .content { padding: 24px; }
}

/* ===== عناصر عامة ===== */
h1.page-title { font-size: 22px; margin: 4px 0 16px; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 16px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 16px;
}
.card.flat { box-shadow: none; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.grid { display: grid; gap: 12px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.stats { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
@media (min-width: 700px) { .grid.md-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 8px 18px;
  border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); font-weight: 600;
  cursor: pointer; text-decoration: none; color: var(--text); white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn svg { width: 20px; height: 20px; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { background: var(--primary-strong); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { min-height: 36px; padding: 4px 12px; font-size: 14px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

.punch-btn {
  width: 100%; min-height: 88px; border-radius: 20px; border: 0; font-size: 22px; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 12px; color: var(--on-primary); background: var(--primary);
  box-shadow: 0 6px 18px color-mix(in srgb, var(--primary) 35%, transparent);
}
.punch-btn svg { width: 30px; height: 30px; }
.punch-btn.out { background: #8a3b12; box-shadow: 0 6px 18px rgba(138,59,18,.3); }
@media (prefers-color-scheme: dark) { .punch-btn.out { background: #f0a36b; color: #2a1405; } }
.punch-btn[disabled] { opacity: .65; cursor: wait; }

label.field { display: block; font-weight: 600; font-size: 14px; }
label.field > span.hint { display: block; font-weight: 400; color: var(--muted); font-size: 13px; }
.input, select.input, textarea.input {
  display: block; width: 100%; min-height: 46px; margin-top: 6px; padding: 8px 12px; border-radius: var(--radius-sm);
  border: 1px solid color-mix(in srgb, var(--muted) 45%, var(--border)); background: var(--bg); font-size: 16px;
}
.stack > a { display: block; }
textarea.input { min-height: 90px; resize: vertical; }
.input:focus { border-color: var(--primary); outline: 2px solid color-mix(in srgb, var(--primary) 30%, transparent); }
.check { display: flex; align-items: center; gap: 8px; min-height: 40px; font-weight: 500; }
.check input { width: 20px; height: 20px; accent-color: var(--primary); }
.form-grid { display: grid; gap: 14px; }
@media (min-width: 700px) { .form-grid.two { grid-template-columns: 1fr 1fr; } .form-grid .full { grid-column: 1 / -1; } }

.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 99px; font-size: 13px; font-weight: 600;
  background: var(--surface-2); color: var(--muted); white-space: nowrap; line-height: 1.6;
}
.badge svg { width: 14px; height: 14px; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.primary { background: var(--primary-soft); color: var(--primary-strong); }

.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.stat .label { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.stat .value { font-size: 24px; font-weight: 700; }
.stat .value small { font-size: 13px; font-weight: 500; color: var(--muted); }
button.stat { text-align: start; cursor: pointer; width: 100%; }
button.stat[aria-pressed="true"] { border-color: var(--primary); outline: 2px solid var(--primary); }

.alert { border-radius: var(--radius-sm); padding: 12px 14px; display: flex; gap: 10px; align-items: flex-start; margin-bottom: 12px; }
.alert svg { width: 22px; height: 22px; flex-shrink: 0; margin-top: 2px; }
.alert.bad { background: var(--bad-soft); color: var(--bad); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.info { background: var(--info-soft); color: var(--info); }
.alert p { margin: 2px 0 0; color: var(--text); }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-bottom: 1px solid var(--border); padding: 12px 0; }
.list > li:last-child { border-bottom: 0; }
.list-btn { width: 100%; text-align: start; background: none; border: 0; padding: 0; cursor: pointer; display: block; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 8px 10px; text-align: start; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data th { background: var(--surface-2); font-weight: 600; position: sticky; top: 0; }
table.data tr:last-child td { border-bottom: 0; }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover td { background: var(--surface-2); }
table.data td.wrap { white-space: normal; min-width: 160px; }

.segmented { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; flex-wrap: wrap; }
.segmented button { border: 0; background: none; padding: 6px 14px; border-radius: 9px; font-weight: 600; cursor: pointer; min-height: 36px; color: var(--muted); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 16px; scrollbar-width: none; }
.chips a { flex-shrink: 0; padding: 6px 14px; border-radius: 99px; border: 1px solid var(--border); text-decoration: none; color: var(--text); font-weight: 500; font-size: 14px; background: var(--surface); }
.chips a[aria-current="page"] { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
@media (min-width: 900px) { .chips.admin-nav { display: none; } }

.month-nav { display: flex; align-items: center; gap: 8px; }
.month-nav strong { min-width: 130px; text-align: center; }

.empty { text-align: center; padding: 32px 16px; color: var(--muted); }
.empty svg { width: 44px; height: 44px; opacity: .6; }
.empty h3 { color: var(--text); margin-top: 8px; }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 8px; height: 18px; margin: 10px 0; }
@keyframes sk { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } * { transition: none !important; } }
.spinner { width: 22px; height: 22px; border: 3px solid currentColor; border-inline-end-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== الرئيسية ===== */
.today-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.clock { font-size: 40px; font-weight: 700; line-height: 1.1; }
.status-line { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; margin: 12px 0 4px; }
.status-line svg { width: 26px; height: 26px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 12px 0 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }
.progress-steps { margin-top: 12px; font-weight: 600; display: flex; align-items: center; gap: 10px; color: var(--primary-strong); }

/* ===== النوافذ ===== */
.overlay { position: fixed; inset: 0; z-index: 100; background: rgba(8, 20, 17, .45); display: flex; align-items: flex-end; justify-content: center; }
.dialog {
  background: var(--surface); width: 100%; max-height: 92dvh; overflow-y: auto; border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); box-shadow: 0 -8px 30px rgba(0,0,0,.2);
}
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.dialog-head h2 { margin: 0; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
@media (min-width: 700px) {
  .overlay { align-items: center; }
  .dialog { width: min(640px, 94vw); border-radius: 18px; padding: 22px; }
  .dialog.wide { width: min(980px, 96vw); }
}
.result-screen { text-align: center; padding: 8px 0; }
.result-screen .icon { width: 84px; height: 84px; border-radius: 50%; display: grid; place-items: center; margin: 6px auto 10px; }
.result-screen .icon svg { width: 48px; height: 48px; }
.result-screen.ok .icon { background: var(--ok-soft); color: var(--ok); }
.result-screen.bad .icon { background: var(--bad-soft); color: var(--bad); }
.result-screen.warn .icon { background: var(--warn-soft); color: var(--warn); }
.result-screen .big { font-size: 34px; font-weight: 700; }

.toasts { position: fixed; z-index: 200; inset-inline: 16px; bottom: calc(86px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; box-shadow: var(--shadow); max-width: 520px; pointer-events: auto; }
.toast.bad { background: var(--bad); color: #fff; }

/* ===== الدخول ===== */
.auth-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: min(420px, 100%); }
.auth-card .brand { justify-content: center; font-size: 26px; margin-bottom: 8px; }
.auth-card .brand img { width: 48px; height: 48px; }

.day-card { display: grid; grid-template-columns: 64px 1fr; gap: 12px; align-items: start; }
.day-date { text-align: center; background: var(--surface-2); border-radius: 12px; padding: 6px 4px; }
.day-date b { display: block; font-size: 22px; line-height: 1.1; }
.day-date span { font-size: 12px; color: var(--muted); }
.day-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 14px; color: var(--muted); margin-top: 4px; }
.day-meta b { color: var(--text); font-weight: 600; }
.timeline { border-inline-start: 3px solid var(--border); margin: 8px 6px; padding-inline-start: 14px; }
.timeline > div { position: relative; padding: 6px 0; }
.timeline > div::before { content: ""; position: absolute; inset-inline-start: -21px; top: 14px; width: 11px; height: 11px; border-radius: 50%; background: var(--primary); }
.defs dt { font-weight: 700; margin-top: 10px; }
.defs dd { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
details.card > summary { cursor: pointer; font-weight: 700; list-style: none; display: flex; justify-content: space-between; }
details.card > summary::after { content: "＋"; color: var(--muted); }
details.card[open] > summary::after { content: "－"; }
.code-box { font-family: ui-monospace, Consolas, monospace; font-size: 30px; letter-spacing: 6px; text-align: center; padding: 14px; background: var(--surface-2); border-radius: 12px; direction: ltr; font-weight: 700; user-select: all; }

/* ===== الطباعة / PDF ===== */
#print-root { display: none; }
@media print {
  @page { size: A4 landscape; margin: 10mm; }
  body { background: #fff; color: #000; font-size: 11px; }
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block; }
  #print-root h1 { font-size: 18px; margin: 0 0 4px; }
  #print-root table { width: 100%; border-collapse: collapse; margin-top: 8px; page-break-inside: auto; }
  #print-root th, #print-root td { border: 1px solid #999; padding: 3px 5px; text-align: start; }
  #print-root th { background: #e9efed; }
  #print-root tr { page-break-inside: avoid; }
  #print-root .p-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; margin-top: 8px; }
  #print-root .p-grid div { border: 1px solid #bbb; padding: 4px 6px; }
  #print-root .p-grid b { display: block; font-size: 13px; }
  #print-root .defs dt { font-weight: 700; margin-top: 4px; }
  #print-root .defs dd { margin: 0; }
}
