/* نظام جدولة دوام الأطباء — التنسيق العام */
:root {
  --primary: #0F766E;
  --primary-dark: #115E59;
  --primary-soft: #CCFBF1;
  --ink: #0F172A;
  --muted: #475569;
  --line: #E2E8F0;
  --bg: #F5F7F8;
  --card: #FFFFFF;
  --side: #0F172A;
  --warn-bg: #FEF3C7; --warn: #92400E;
  --danger-bg: #FEE2E2; --danger: #B91C1C;
  --ok-bg: #DCFCE7; --ok: #166534;
  --info-bg: #DBEAFE; --info: #1E40AF;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'IBM Plex Sans Arabic', Tahoma, system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
}
a { color: var(--primary); }
a:hover { color: var(--primary-dark); }
h1 { font-size: 24px; margin: 0 0 6px; }
h2 { font-size: 18px; margin: 0 0 12px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
small { font-size: 12px; }

/* ---------- التخطيط ---------- */
.layout { display: flex; min-height: 100vh; }
.nav-toggle { display: none; }
.topbar { display: none; }
.sidebar {
  width: 250px; flex-shrink: 0;
  background: var(--side); color: #E2E8F0;
  padding: 22px 14px; display: flex; flex-direction: column; gap: 18px;
  position: sticky; top: 0; height: 100vh;
}
.brand { padding: 0 10px; display: flex; flex-direction: column; }
.brand-name { font-weight: 700; font-size: 17px; color: #fff; }
.brand-sub { font-size: 12px; color: #94A3B8; }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; flex-grow: 1; }
.sidebar nav a, .sidebar nav .soon {
  display: block; padding: 11px 12px; border-radius: 10px;
  color: #CBD5E1; text-decoration: none;
}
.sidebar nav a:hover { background: #1E293B; color: #fff; }
.sidebar nav a.active { background: var(--primary); color: #fff; font-weight: 600; }
.sidebar nav .soon { color: #64748B; cursor: default; }
.sidebar nav .soon small { background: #1E293B; padding: 1px 7px; border-radius: 999px; margin-inline-start: 4px; }
.sidebar-user { border-top: 1px solid #1E293B; padding: 14px 10px 0; display: flex; flex-direction: column; }
.sidebar-user .who { color: #fff; font-weight: 600; }
.sidebar-user .role { font-size: 12px; color: #94A3B8; margin-bottom: 6px; }
.link-btn { background: none; border: none; padding: 6px 0; color: #94A3B8; font: inherit; cursor: pointer; text-align: start; }
.link-btn:hover { color: #fff; }
.content { flex-grow: 1; min-width: 0; padding: 28px 32px; max-width: 1200px; }

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .topbar {
    display: flex; align-items: center; gap: 12px;
    background: var(--side); color: #fff; padding: 10px 14px;
    position: sticky; top: 0; z-index: 20;
  }
  .burger { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; cursor: pointer; border-radius: 10px; }
  .topbar-title { font-weight: 600; }
  .sidebar { display: none; width: 100%; height: auto; position: static; }
  .nav-toggle:checked ~ .sidebar { display: flex; }
  .content { padding: 18px 14px; }
}

/* ---------- البطاقات والعناصر ---------- */
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 20px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat .label { font-size: 13px; color: var(--muted); }
.stat .value { font-size: 26px; font-weight: 700; }
.stat .value small { font-size: 14px; color: var(--muted); font-weight: 500; }

.badge { display: inline-block; padding: 3px 11px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-shift { background: var(--primary-soft); color: var(--primary-dark); }

.alert { padding: 12px 16px; border-radius: 12px; margin-bottom: 16px; }
.alert-success { background: var(--ok-bg); color: var(--ok); }
.alert-error { background: var(--danger-bg); color: var(--danger); }
.alert-warning { background: var(--warn-bg); color: var(--warn); }
.alert-info { background: var(--info-bg); color: var(--info); }

/* ---------- النماذج ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 14px; font-weight: 500; color: #334155; }
.field input, .field select, .field textarea {
  height: 46px; padding: 0 12px; border: 1px solid #CBD5E1; border-radius: 10px;
  font: inherit; background: #fff; color: var(--ink);
}
.field input:focus, .field select:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.field .hint { font-size: 12px; color: var(--muted); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 46px; padding: 0 20px; border-radius: 12px; border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  background: var(--primary); color: #fff;
}
.btn:hover { background: var(--primary-dark); color: #fff; }
.btn-light { background: #fff; color: var(--ink); border-color: #CBD5E1; }
.btn-light:hover { background: #F1F5F9; color: var(--ink); }
.btn-danger { background: var(--danger); }
.btn-block { width: 100%; }

/* ---------- الجداول ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 11px 12px; text-align: start; border-bottom: 1px solid #EEF2F6; }
.table th { background: #F1F5F9; font-size: 13px; color: #334155; font-weight: 600; }

/* ---------- صفحات الدخول والتثبيت ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 100%; max-width: 420px; background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 28px; }
.auth-card.wide { max-width: 560px; }
.auth-logo { width: 52px; height: 52px; border-radius: 14px; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; margin-bottom: 14px; }

/* ---------- إضافات المرحلة 2 ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.btn-sm { white-space: nowrap; height: 38px; padding: 0 14px; font-size: 14px; border-radius: 10px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.row-actions { display: flex; gap: 6px; white-space: nowrap; }
.row-actions form { margin: 0; }
.row-off td { opacity: .6; }
.table td { vertical-align: middle; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.check-card {
  display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 0 14px;
  border: 1px solid #CBD5E1; border-radius: 12px; background: #fff; cursor: pointer; font-weight: 500;
}
.check-card input { width: 20px; height: 20px; accent-color: var(--primary); margin: 0; }
.check-card:has(input:checked) { border-color: var(--primary); background: #F0FDFA; }

/* ---------- المرحلة 3: التوافر ---------- */
.avail-table th, .avail-table td { padding: 6px 10px; }
.avail-table thead th { position: sticky; top: 0; z-index: 2; }
.avail-table .c { text-align: center; }
.avail-table th.c { white-space: nowrap; }
.col-all {
  display: block; margin: 4px auto 0; padding: 2px 10px; border-radius: 999px;
  border: 1px solid #CBD5E1; background: #fff; font: inherit; font-size: 12px; cursor: pointer; color: var(--primary-dark);
}
.col-all:hover { background: #F0FDFA; }
.day-num { font-weight: 700; display: inline-block; min-width: 22px; }
.day-name { color: var(--muted); font-size: 13px; }
.avail-table tr.fri td { background: #F8FAFC; }
.cell-check { display: flex; align-items: center; justify-content: center; min-height: 44px; cursor: pointer; }
.cell-check input { width: 22px; height: 22px; accent-color: var(--primary); cursor: pointer; margin: 0; }
.cell-check input:disabled { cursor: not-allowed; }
.save-bar {
  position: sticky; bottom: 0; z-index: 5;
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 16px; box-shadow: 0 -4px 16px rgba(15, 23, 42, .06);
}
@media (max-width: 860px) {
  .avail-table .table-wrap { overflow: visible; }
  .avail-table th, .avail-table td { padding: 4px 6px; }
  .avail-table th.c { white-space: normal; font-size: 12px; }
}

/* ---------- المرحلة 4: متابعة التوافر ---------- */
.month-nav { display: flex; gap: 8px; flex-wrap: wrap; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; font-size: 13px; margin-bottom: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.lg { display: inline-block; width: 14px; height: 14px; border-radius: 4px; }
.lg-0 { background: #FEE2E2; color: #991B1B; }
.lg-1 { background: #FEF3C7; color: #92400E; }
.lg-2 { background: #CCFBF1; color: #115E59; }
.lg-3 { background: #0F766E; color: #FFFFFF; }
.cover-table td, .cover-table th { padding: 6px 8px; }
.cover {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 40px; height: 34px; border-radius: 8px; font-weight: 700; padding: 0 8px;
}
.cover-details summary { cursor: pointer; list-style: none; }
.cover-details summary::-webkit-details-marker { display: none; }
.cover-names { margin-top: 6px; font-size: 12px; color: var(--muted); text-align: center; line-height: 1.5; }

/* ---------- المرحلة 5: الجدول ---------- */
.gen-card { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; justify-content: space-between; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.sched-table th, .sched-table td { padding: 8px 10px; }
.sched-table { min-width: 720px; }
.sched-cell { vertical-align: top; border-inline-start: 1px solid #EEF2F6; }
.sched-cell.cell-single { background: #FFFBEB; }
.sched-cell.cell-empty { background: #FEF2F2; }
.doc-name { font-size: 14px; font-weight: 500; }
.doc-name.is-override { color: var(--info); }
.doc-name.is-override::after { content: ' (تجاوز)'; font-size: 11px; }
.doc-reserve { font-size: 12px; color: var(--warn); margin-top: 2px; }
.cell-note { font-size: 12px; font-weight: 600; color: var(--muted); }
.cell-single .cell-note { color: #B45309; }
.cell-empty .cell-note { color: var(--danger); }
.bar { height: 8px; background: #E2E8F0; border-radius: 4px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--primary); }

/* ---------- المرحلة 6: تعديل الجدول ---------- */
.sched-cell { position: relative; }
.cell-link { display: block; color: inherit; text-decoration: none; min-height: 44px; border-radius: 8px; padding: 2px; margin: -2px; }
.cell-link:hover { background: rgba(15, 118, 110, .07); color: inherit; }
.cell-link:focus-visible { outline: 2px solid var(--primary); }
.cell-edit { display: none; font-size: 11px; color: var(--primary); font-weight: 600; margin-top: 2px; }
.cell-link:hover .cell-edit, .cell-link:focus .cell-edit { display: block; }
.doc-reserve.is-override { color: var(--info); }
.override-warn { background: var(--info-bg); color: var(--info); border-radius: 10px; padding: 8px 12px; font-size: 13px; }
.approve-card { border-color: var(--primary); }
.sched-table tr:target td { box-shadow: inset 0 0 0 2px var(--primary-soft); }

/* ---------- المرحلة 7: جدولي ---------- */
.shift-list { display: flex; flex-direction: column; gap: 10px; max-width: 720px; }
.shift-item {
  display: flex; align-items: center; gap: 14px;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px;
}
.shift-item.is-reserve { border-style: dashed; border-color: #D97706; }
.shift-item.is-past { opacity: .55; }
.shift-item.is-today { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.shift-date { width: 56px; display: flex; flex-direction: column; align-items: center; flex-shrink: 0; }
.shift-date .n { font-size: 22px; font-weight: 700; line-height: 1.1; }
.shift-date .d { font-size: 12px; color: var(--muted); }
.shift-info { flex-grow: 1; display: flex; flex-direction: column; min-width: 0; }
.shift-info .t { font-weight: 600; }
.shift-info .w { font-size: 13px; color: var(--muted); }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
@media (max-width: 600px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 12px; }
  .stat .value { font-size: 22px; }
}

.shift-time { display: block; font-size: 11px; font-weight: 500; color: var(--muted); }
th .shift-time { margin-top: 1px; }

.day-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.day-chip { min-height: 44px; padding: 0 10px; font-size: 14px; }

.reserve-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; max-height: 320px; overflow-y: auto; padding: 2px; }
.reserve-item span { display: flex; flex-direction: column; line-height: 1.3; }
.reserve-item small { font-size: 11px; color: var(--info); font-weight: 400; }
.reserve-item.is-unavailable { background: #F8FAFC; }
