:root {
  --bg: #f6f3ec;
  --surface: #fffdf8;
  --field: #f6f3ec;
  --ink: #1c2421;
  --muted: #6e756f;
  --line: #e4dfd3;
  --primary: #12463b;
  --primary-deep: #0c332b;
  --on-primary: #fbf8f1;
  --gold: #b08d4f;
  --leave: #7a2e2a;
  --good-bg: #e3efe6;
  --good-text: #1d5a45;
  --warn-bg: #f5ead2;
  --warn-text: #7a5a14;
  --bad-bg: #f5e1dc;
  --bad-text: #8a2f24;
  --quiet-bg: #ece8df;
  --shadow: 0 8px 24px rgba(28, 36, 33, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101614;
    --surface: #182120;
    --field: #101614;
    --ink: #eef0ea;
    --muted: #9ba49d;
    --line: #2b3633;
    --primary: #1f6a59;
    --primary-deep: #0b1e1a;
    --on-primary: #fbf8f1;
    --gold: #c9a766;
    --leave: #96413a;
    --good-bg: #17392f;
    --good-text: #8fd6b7;
    --warn-bg: #3d3115;
    --warn-text: #e6c67c;
    --bad-bg: #43201b;
    --bad-text: #f0a597;
    --quiet-bg: #29322f;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Alexandria", "Segoe UI", Tahoma, sans-serif;
  font-weight: 300;
  line-height: 1.6;
}

main { max-width: 440px; margin: 0 auto; padding: 28px 20px; }

h1 { font-size: 1.3rem; font-weight: 500; margin: 0; }
h2 { font-size: .95rem; font-weight: 500; margin: 0 0 12px; }
code { direction: ltr; unicode-bidi: isolate; }

.muted { color: var(--muted); font-size: .8rem; }
.ltr { direction: ltr; text-align: left; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 20px; margin-bottom: 18px; }

/* الحقول والأزرار */
label { display: block; font-size: .82rem; font-weight: 500; margin-bottom: 16px; }
input, textarea, select {
  display: block; width: 100%; margin-top: 7px; padding: 11px 16px; min-height: 46px;
  font: inherit; font-weight: 300; color: var(--ink); background: var(--field);
  border: 1px solid var(--line); border-radius: 12px;
}
input:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
input[type="checkbox"] { display: inline-block; width: 18px; min-height: 18px; margin: 0 0 0 8px; accent-color: var(--primary); }
.check { display: inline-flex; align-items: center; font-weight: 300; margin: 0 0 8px 18px; }

button, .button {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 8px 18px;
  font: inherit; font-size: .85rem; font-weight: 400; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; cursor: pointer; text-decoration: none;
  transition: background-color .15s, border-color .15s, transform .15s;
}
button:hover, .button:hover { border-color: var(--gold); }
button:focus-visible, .button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
button:disabled { opacity: .6; cursor: default; }
button.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-weight: 500; }
button.small { min-height: 34px; padding: 3px 12px; font-size: .75rem; color: var(--muted); border-radius: 8px; }
.pill { min-height: 36px; padding: 4px 14px; border-radius: 999px; font-size: .75rem; color: var(--muted); background: transparent; }
.link-button { display: block; width: 100%; background: none; border: 0; color: var(--primary); font-size: .8rem; margin-top: 8px; }
.full { width: 100%; }

/* الرسائل والحالات */
.message { padding: 11px 14px; border-radius: 12px; margin-bottom: 14px; font-size: .85rem; font-weight: 400; }
.message-error { background: var(--bad-bg); color: var(--bad-text); }
.message-success { background: var(--good-bg); color: var(--good-text); }
.message-info { background: var(--quiet-bg); }

.badge { display: inline-block; padding: 3px 12px; border-radius: 999px; font-size: .72rem; font-weight: 500; white-space: nowrap; }
.badge-good { background: var(--good-bg); color: var(--good-text); }
.badge-warn { background: var(--warn-bg); color: var(--warn-text); }
.badge-bad { background: var(--bad-bg); color: var(--bad-text); }
.badge-muted { background: var(--quiet-bg); color: var(--muted); }

/* الدخول */
.brand { text-align: center; padding: 48px 0 32px; }
.brand-mark { display: grid; place-items: center; width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 50%; background: var(--primary); }
.brand-mark::after { content: ""; width: 16px; height: 16px; border: 2px solid var(--gold); border-radius: 50%; }
.brand h1 { font-size: 1.5rem; }
.login-card { padding: 24px; border-radius: 22px; box-shadow: var(--shadow); }

/* شاشة الموظف */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 24px; flex-wrap: wrap; }
.topbar-actions { display: flex; gap: 8px; }

.punch-area { text-align: center; margin-bottom: 22px; }
.ring { display: grid; place-items: center; width: 232px; height: 232px; margin: 0 auto 14px; border: 1px solid var(--gold); border-radius: 50%; }
.punch {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  width: 204px; height: 204px; padding: 16px; border: 0; border-radius: 50%;
  color: var(--on-primary); background: var(--primary); box-shadow: 0 14px 32px rgba(18, 70, 59, .28);
  font-size: .95rem;
}
.punch:hover { transform: scale(1.02); }
.punch:active { transform: scale(.98); }
.punch strong { font-size: 2rem; font-weight: 500; line-height: 1.4; }
.punch.out { background: var(--leave); box-shadow: 0 14px 32px rgba(122, 46, 42, .26); }
.punch.loading { font-size: .85rem; }

.times { display: grid; grid-template-columns: 1fr 1px 1fr; align-items: center; text-align: center; padding: 16px 8px; }
.times::before { content: ""; grid-column: 2; grid-row: 1; width: 1px; height: 36px; background: var(--line); }
.times > :first-child { grid-column: 1; grid-row: 1; }
.times > :last-child { grid-column: 3; grid-row: 1; }
.times strong { display: block; font-size: 1.35rem; font-weight: 300; direction: ltr; }

.day-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); }
.day-row:first-child { border-top: 0; }
.day-row b { display: block; font-size: .82rem; font-weight: 400; }
.day-row bdi { color: var(--muted); font-size: .75rem; }

.scan-note { text-align: center; padding: 32px 24px; margin-bottom: 22px; }
.scan-mark {
  width: 72px; height: 72px; margin: 0 auto 16px; border-radius: 16px; border: 2px solid var(--gold);
  background: repeating-conic-gradient(var(--primary) 0 25%, transparent 0 50%) 50% / 24px 24px;
}

/* شاشة المكتب */
.kiosk main { max-width: 620px; min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.kiosk h1 { font-size: 2rem; }
.kiosk .muted { font-size: 1rem; margin: 6px 0 24px; }
.qr-frame { width: min(84vw, 62vh); padding: 18px; background: #fff; border: 1px solid var(--gold); border-radius: 22px; box-shadow: var(--shadow); }
.qr-frame svg { display: block; width: 100%; height: auto; }
.qr-progress { width: min(84vw, 62vh); height: 4px; margin-top: 18px; overflow: hidden; border-radius: 999px; background: var(--line); }
.qr-progress span { display: block; height: 100%; background: var(--gold); transition: width .25s linear; }
.kiosk-field { margin: 14px 0 0; }

/* لوحة الإدارة */
.admin { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: var(--primary-deep); color: var(--on-primary); padding: 32px 20px; }
.sidebar-brand { font-size: 1.05rem; font-weight: 500; }
.sidebar-sub { color: var(--gold); font-size: .75rem; margin-bottom: 26px; }
.tabs { display: flex; flex-direction: column; gap: 6px; }
.tabs button {
  justify-content: flex-start; width: 100%; padding: 10px 14px; background: none; border: 0; border-radius: 10px;
  color: var(--on-primary); font-weight: 300; font-size: .88rem; opacity: .82;
}
.tabs button:hover { opacity: 1; background: rgba(255, 255, 255, .06); }
.tabs button.active { background: var(--primary); font-weight: 500; opacity: 1; }
.tabs button.active::before { content: ""; width: 6px; height: 6px; margin-inline-end: 10px; border-radius: 50%; background: var(--gold); }

main.wide { max-width: 1120px; width: 100%; margin: 0; padding: 36px 40px; }
main.wide .topbar h1 { font-size: 1.6rem; }

.counts { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 14px; margin-bottom: 20px; }
.count { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 18px 22px; }
.count strong { display: block; font-size: 2rem; font-weight: 300; line-height: 1.4; }
.count .muted { font-weight: 400; }
.tone-good strong { color: var(--good-text); }
.tone-warn strong { color: var(--warn-text); }
.tone-bad strong { color: var(--bad-text); }

.table-wrap { overflow-x: auto; }
.table-card { padding: 8px 24px; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: .82rem; }
th, td { padding: 13px 10px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
th { color: var(--muted); font-size: .75rem; font-weight: 400; }
td.name { font-weight: 500; }
td.time { direction: ltr; text-align: right; }
td.wrap { font-size: .72rem; line-height: 1.5; }
td.actions { text-align: left; }
td.actions button { margin-inline-start: 4px; }

.export-banner { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.report-note { margin-top: 12px; }

.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; align-items: end; }
.row label { margin-bottom: 0; }
.section-gap { margin-bottom: 22px; }

dialog { border: 1px solid var(--line); border-radius: 18px; padding: 24px; background: var(--surface); color: var(--ink); width: min(92vw, 400px); }
dialog::backdrop { background: rgba(12, 51, 43, .45); }
.dialog-actions { display: flex; gap: 8px; margin-top: 8px; }

@media (max-width: 860px) {
  .admin { display: block; }
  .sidebar { padding: 18px 16px 10px; }
  .sidebar-sub { margin-bottom: 12px; }
  .tabs { flex-direction: row; overflow-x: auto; padding-bottom: 6px; }
  .tabs button { width: auto; flex: none; }
  main.wide { padding: 22px 16px; }
  .table-card { padding: 4px 14px; }
}
