:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f0;
  --text: #17211d;
  --muted: #5f6b66;
  --border: #dde4e0;
  --primary: #0f766e;
  --primary-ink: #ffffff;
  --primary-soft: #d9f0ec;
  --danger: #c2410c;
  --danger-soft: #fde8dc;
  --warn: #a16207;
  --warn-soft: #fbf0cf;
  --ok: #15803d;
  --ok-soft: #dcf3e3;
  --info: #1d4ed8;
  --info-soft: #e0e8fb;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 4px 16px rgb(0 0 0 / .05);
  color-scheme: light;
  accent-color: var(--primary);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1412;
    --surface: #171e1b;
    --surface-2: #1f2824;
    --text: #e7eeea;
    --muted: #9aa8a1;
    --border: #2b3631;
    --primary: #2dd4bf;
    --primary-ink: #04201c;
    --primary-soft: #133a35;
    --danger: #fb923c;
    --danger-soft: #3b2014;
    --warn: #facc15;
    --warn-soft: #3a3110;
    --ok: #4ade80;
    --ok-soft: #12301d;
    --info: #93b4ff;
    --info-soft: #1a2647;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 15px;
}
h1, h2, h3 { margin: 0; line-height: 1.3; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
/* direction: ltr يقلب محاذاة البداية لليسار، فنعيدها لليمين لتبقى تحت العناوين */
td.num, .kpi .num { text-align: right; }
.hidden { display: none !important; }

/* أزرار وحقول */
button, .btn {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: .55rem 1rem;
  border-radius: 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  text-decoration: none;
  min-height: 42px;
}
button:hover { border-color: var(--primary); }
button:disabled { opacity: .55; cursor: progress; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.btn-primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); font-weight: 600; }
.btn-danger { color: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: .3rem .7rem; min-height: 34px; font-size: .88rem; }

label { display: block; font-size: .9rem; color: var(--muted); margin-bottom: .25rem; }
input, select, textarea {
  font: inherit;
  width: 100%;
  padding: .55rem .75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  min-height: 42px;
}
textarea { min-height: 80px; resize: vertical; }
.field { margin-bottom: .9rem; }
.row { display: flex; gap: .75rem; flex-wrap: wrap; }
.row > * { flex: 1 1 140px; }
.check { display: flex; align-items: center; gap: .5rem; color: var(--text); font-size: .95rem; }
.check input { width: auto; min-height: auto; }
.days { display: flex; flex-wrap: wrap; gap: .4rem; }
.days label {
  display: inline-flex; align-items: center; gap: .3rem; margin: 0;
  border: 1px solid var(--border); border-radius: 999px; padding: .25rem .7rem; color: var(--text); cursor: pointer;
}
.days input { width: auto; min-height: auto; }

/* بطاقات وتخطيط */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
  box-shadow: var(--shadow);
}
.stack > * + * { margin-top: 1rem; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .75rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; }
.top-actions { display: flex; align-items: center; gap: .4rem; flex-shrink: 0; }
.logo {
  width: 34px; height: 34px; border-radius: 10px; background: var(--primary); color: var(--primary-ink);
  display: grid; place-items: center; font-weight: 800; flex-shrink: 0;
}

/* شارات الحالة */
.badge { display: inline-block; padding: .1rem .6rem; border-radius: 999px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.st-present { background: var(--ok-soft); color: var(--ok); }
.st-late { background: var(--warn-soft); color: var(--warn); }
.st-absent { background: var(--danger-soft); color: var(--danger); }
.st-leave { background: var(--info-soft); color: var(--info); }
.st-off, .st-upcoming, .st-cancelled { background: var(--surface-2); color: var(--muted); }
.st-pending { background: var(--warn-soft); color: var(--warn); }
.st-approved { background: var(--ok-soft); color: var(--ok); }
.st-rejected { background: var(--danger-soft); color: var(--danger); }

/* جداول */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: .6rem .5rem; text-align: start; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: .82rem; white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
.empty { text-align: center; color: var(--muted); padding: 1.5rem; }

/* إشعار */
#toast {
  position: fixed; inset-inline: 16px; bottom: 20px; margin-inline: auto; max-width: 460px;
  padding: .8rem 1rem; border-radius: 12px; background: var(--text); color: var(--bg);
  box-shadow: 0 8px 30px rgb(0 0 0 / .25); z-index: 100; text-align: center;
  transform: translateY(150%); transition: transform .25s ease;
}
#toast.show { transform: none; }
#toast.error { background: var(--danger); color: #fff; }

dialog {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text);
  padding: 0; width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog form { padding: 1.2rem; }
dialog h2 { margin-bottom: 1rem; }
.dialog-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
