/* ============================================================
   EDUSOLVER SaaS — Design System v2
   RTL Arabic · Tajawal · Polished UI/UX
   ============================================================ */

@font-face {
  font-family: 'Tajawal';
  src: url('../assets/Tajawal-Regular.ttf') format('truetype');
  font-weight: 400; font-display: swap;
}
@font-face {
  font-family: 'Tajawal';
  src: url('../assets/Tajawal-Medium.ttf') format('truetype');
  font-weight: 500; font-display: swap;
}
@font-face {
  font-family: 'Tajawal';
  src: url('../assets/Tajawal-Bold.ttf') format('truetype');
  font-weight: 700; font-display: swap;
}
@font-face {
  font-family: 'Tajawal';
  src: url('../assets/Tajawal-ExtraBold.ttf') format('truetype');
  font-weight: 800; font-display: swap;
}
@font-face {
  font-family: 'Tajawal';
  src: url('../assets/Tajawal-Light.ttf') format('truetype');
  font-weight: 300; font-display: swap;
}

/* ---------- Theme Tokens ---------- */
:root {
  --brand-1: #dc2626;
  --brand-2: #b91c1c;
  --brand-3: #ef4444;
  --brand-grad: linear-gradient(135deg, #dc2626 0%, #b91c1c 55%, #ef4444 100%);
  --brand-grad-soft: linear-gradient(135deg, rgba(220,38,38,.10), rgba(239,68,68,.06));

  --bg: #ffffff;
  --bg-mesh: radial-gradient(ellipse 80% 50% at 100% -20%, rgba(220,38,38,.04), transparent),
             radial-gradient(ellipse 60% 40% at 0% 100%, rgba(239,68,68,.03), transparent);
  --surface: #ffffff;
  --surface-2: #fafafa;
  --surface-3: #f5f5f5;
  --border: #e8e8e8;
  --border-strong: #d4d4d4;

  --text: #171717;
  --text-soft: #525252;
  --text-muted: #a3a3a3;

  --primary: #dc2626;
  --primary-hover: #b91c1c;
  --primary-soft: #fee2e2;
  --success: #10b981;
  --success-soft: #d1fae5;
  --warning: #f59e0b;
  --warning-soft: #fef3c7;
  --danger: #ef4444;
  --danger-soft: #fee2e2;

  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 18px;
  --radius-xl: 24px;

  --shadow-sm: 0 1px 2px rgba(23,23,23,.04), 0 1px 3px rgba(23,23,23,.05);
  --shadow: 0 4px 16px rgba(23,23,23,.06), 0 2px 6px rgba(23,23,23,.04);
  --shadow-lg: 0 20px 44px rgba(23,23,23,.10), 0 8px 16px rgba(23,23,23,.05);
  --shadow-brand: 0 12px 28px rgba(220,38,38,.25);

  --sidebar-w: 276px;
  --topbar-h: 68px;
  --font: 'Tajawal', system-ui, 'Segoe UI', sans-serif;
  --ease: cubic-bezier(.2,.8,.2,1);
  --focus-ring: 0 0 0 3px var(--primary-soft);
}

[data-theme="dark"] {
  --bg: #141414;
  --bg-mesh: radial-gradient(ellipse 80% 50% at 100% -20%, rgba(220,38,38,.12), transparent),
             radial-gradient(ellipse 60% 40% at 0% 100%, rgba(239,68,68,.07), transparent);
  --surface: #1c1c1c;
  --surface-2: #262626;
  --surface-3: #333333;
  --border: #404040;
  --border-strong: #525252;
  --text: #f5f5f5;
  --text-soft: #d4d4d4;
  --text-muted: #a3a3a3;
  --primary-soft: #3f1d1d;
  --success-soft: #0f2e22;
  --warning-soft: #3a2e0e;
  --danger-soft: #3f1414;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.35);
  --shadow: 0 4px 16px rgba(0,0,0,.4);
  --shadow-lg: 0 20px 44px rgba(0,0,0,.55);
  --focus-ring: 0 0 0 3px rgba(220,38,38,.35);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg);
  background-image: var(--bg-mesh);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100%;
  overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; font-size: 14px; color: var(--text); }
img { display: block; max-width: 100%; }
:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); background-clip: padding-box; }

/* ---------- Utility ---------- */
.row { display: flex; align-items: center; }
.col { display: flex; flex-direction: column; }
.between { justify-content: space-between; }
.center { justify-content: center; align-items: center; }
.gap-4 { gap: 4px; } .gap-8 { gap: 8px; } .gap-12 { gap: 12px; }
.gap-16 { gap: 16px; } .gap-24 { gap: 24px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--text-muted); }
.soft { color: var(--text-soft); }
.bold { font-weight: 700; }
.hidden { display: none !important; }
.text-c { text-align: center; }
.text-r { text-align: right; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 700; white-space: nowrap;
  transition: transform .18s var(--ease), box-shadow .18s, background .15s, border-color .15s, filter .15s;
  cursor: pointer;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border);
  user-select: none;
}
.btn:hover { background: var(--surface-2); transform: translateY(-1px); border-color: var(--border-strong); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; pointer-events: none; }
.btn-primary {
  background: var(--brand-grad); color: #fff; border: none;
  box-shadow: var(--shadow-brand);
}
.btn-primary:hover { box-shadow: 0 16px 36px rgba(220,38,38,.30); filter: brightness(1.06); border: none; }
.btn-success { background: var(--success); color: #fff; border: none; }
.btn-success:hover { background: #0ea271; border: none; }
.btn-danger { background: var(--danger); color: #fff; border: none; }
.btn-danger:hover { background: #dc2626; border: none; }
.btn-ghost { background: transparent; border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-icon {
  width: 40px; height: 40px; padding: 0; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-2); border: 1px solid var(--border);
  transition: all .15s var(--ease); flex-shrink: 0;
}
.btn-icon:hover { background: var(--surface-3); border-color: var(--border-strong); transform: translateY(-1px); }
.btn-icon:active { transform: none; }
.btn-sm { padding: 7px 14px; font-size: 13px; border-radius: 9px; }
.btn-lg { padding: 14px 28px; font-size: 16px; }

/* ---------- Inputs ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 700; color: var(--text-soft); }
.field .hint { font-size: 12px; color: var(--text-muted); }
.input, .select, .textarea {
  width: 100%; padding: 11px 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.input:hover, .select:hover, .textarea:hover { border-color: var(--border-strong); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: var(--focus-ring);
}
.input::placeholder, .textarea::placeholder { color: var(--text-muted); }
.textarea { resize: vertical; min-height: 80px; }
.checkbox { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.checkbox input { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }

/* Password field with toggle */
.input-wrap {
  position: relative; display: flex; align-items: center;
}
.input-wrap .input { padding-inline-end: 46px; }
.input-wrap .toggle-pass {
  position: absolute; inset-inline-end: 10px;
  width: 34px; height: 34px; border-radius: 8px;
  display: grid; place-items: center;
  color: var(--text-muted); font-size: 15px;
  transition: color .15s, background .15s;
}
.input-wrap .toggle-pass:hover { color: var(--text); background: var(--surface-2); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
  padding: 22px;
  transition: border-color .18s, box-shadow .18s;
}
.card-hover {
  transition: transform .2s var(--ease), box-shadow .2s, border-color .18s;
  cursor: pointer;
}
.card-hover:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: color-mix(in srgb, var(--primary) 40%, var(--border));
}
.card-hover:active { transform: translateY(-1px); }

/* Project list item */
.project-item {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px; margin-bottom: 10px;
  border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  transition: all .18s var(--ease);
}
.project-item:hover {
  border-color: color-mix(in srgb, var(--primary) 45%, var(--border));
  background: var(--surface);
  box-shadow: var(--shadow);
  transform: translateX(-2px);
}
.project-item:last-child { margin-bottom: 0; }
.project-item .pi-icon {
  width: 46px; height: 46px; border-radius: 12px;
  background: var(--brand-grad-soft);
  display: grid; place-items: center; font-size: 20px; flex-shrink: 0;
}
.project-item .pi-body { flex: 1; min-width: 0; }
.project-item .pi-title { font-weight: 800; font-size: 15px; margin-bottom: 2px; }
.project-item .pi-meta { font-size: 12px; color: var(--text-muted); }
.project-item .pi-badges { display: flex; gap: 6px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }
.project-item .pi-arrow {
  color: var(--text-muted); font-size: 16px; opacity: 0;
  transition: opacity .15s, transform .15s; flex-shrink: 0;
}
.project-item:hover .pi-arrow { opacity: 1; transform: translateX(-3px); }

/* Template item */
.template-item {
  padding: 14px 16px; margin-bottom: 10px;
  border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface-2);
  transition: border-color .15s, background .15s;
}
.template-item:hover { border-color: var(--border-strong); background: var(--surface); }
.template-item:last-child { margin-bottom: 0; }

/* ---------- Badges & chips ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 11px; border-radius: 999px;
  font-size: 12px; font-weight: 700; white-space: nowrap;
}
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: #b45309; }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-muted { background: var(--surface-3); color: var(--text-soft); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: all .15s var(--ease);
}
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip.active { background: var(--brand-grad); color: #fff; border-color: transparent; box-shadow: var(--shadow-brand); }

/* ============================================================
   APP SHELL — sidebar + topbar + content
   ============================================================ */
.app { display: flex; min-height: 100vh; }

/* Sidebar overlay (mobile) */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 45;
  background: rgba(15,23,42,.45);
  backdrop-filter: blur(3px);
  opacity: 0; transition: opacity .25s;
}
.sidebar-overlay.show { display: block; opacity: 1; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w); background: var(--surface);
  border-inline-end: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  flex-shrink: 0; z-index: 50;
  transition: transform .3s var(--ease), box-shadow .3s;
}
.sidebar-head { padding: 20px 18px 14px; border-bottom: 1px solid var(--border); }
.sidebar-logo { display: flex; align-items: center; gap: 12px; }
.sidebar-logo .mark {
  width: 42px; height: 42px; border-radius: 12px;
  background: var(--brand-grad); display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 20px;
  box-shadow: var(--shadow-brand); flex-shrink: 0;
}
.sidebar-logo .name { font-weight: 800; font-size: 18px; letter-spacing: .2px; line-height: 1.2; }
.sidebar-logo .sub { font-size: 11px; color: var(--text-muted); margin-top: 1px; }

.sidebar-nav {
  flex: 1; overflow-y: auto; padding: 12px 10px;
  scrollbar-width: thin;
}
.nav-section-label {
  font-size: 10.5px; font-weight: 800; color: var(--text-muted);
  letter-spacing: .6px; padding: 14px 12px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--text-soft); font-weight: 600; font-size: 14px;
  cursor: pointer; transition: all .15s var(--ease); margin-bottom: 2px;
  position: relative;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active {
  background: var(--primary-soft); color: var(--primary);
  font-weight: 700;
}
.nav-item.active::before {
  content: '';
  position: absolute; inset-inline-start: 0; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 60%; border-radius: 0 3px 3px 0;
  background: var(--brand-grad);
}
[dir="rtl"] .nav-item.active::before {
  border-radius: 3px 0 0 3px;
}
.nav-item .ico {
  width: 32px; height: 32px; border-radius: 9px;
  display: grid; place-items: center; font-size: 15px;
  background: var(--surface-2); flex-shrink: 0;
  transition: background .15s;
}
.nav-item:hover .ico { background: var(--surface-3); }
.nav-item.active .ico { background: color-mix(in srgb, var(--primary) 18%, transparent); }
.nav-item.disabled,
.nav-item.locked {
  opacity: .42; cursor: not-allowed;
}
.nav-item.locked:hover { background: transparent; color: var(--text-soft); }
.nav-item .lock-hint {
  margin-inline-start: auto;
  font-size: 11px; opacity: .7;
}

.sidebar-foot { padding: 12px 12px 16px; border-top: 1px solid var(--border); }
.user-pill {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid transparent;
  transition: border-color .15s;
}
.user-pill:hover { border-color: var(--border); }
.user-pill .avatar {
  width: 38px; height: 38px; border-radius: 11px;
  background: var(--brand-grad); color: #fff; font-weight: 800;
  display: grid; place-items: center; flex-shrink: 0; font-size: 15px;
}
.user-pill .info { overflow: hidden; flex: 1; min-width: 0; }
.user-pill .info .em {
  font-size: 13px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-pill .info .ro { font-size: 11px; color: var(--text-muted); }
.user-pill .btn-icon {
  width: 34px; height: 34px; border-radius: 9px;
  background: transparent; border-color: transparent;
}
.user-pill .btn-icon:hover { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

/* Main */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: var(--topbar-h);
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 14px; padding: 0 24px;
  position: sticky; top: 0; z-index: 30;
}
.topbar .page-title { font-size: 18px; font-weight: 800; line-height: 1.25; }
.topbar .page-sub { font-size: 12px; color: var(--text-muted); margin-top: 1px; }
.topbar-actions { margin-inline-start: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.content { padding: 26px 28px 40px; flex: 1; }
.page { display: none; animation: pageIn .32s var(--ease); }
.page.active { display: block; }
@keyframes pageIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Page header ---------- */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; margin-bottom: 22px; flex-wrap: wrap;
}
.page-head h1 { font-size: 23px; font-weight: 800; letter-spacing: -.02em; }
.page-head p { color: var(--text-muted); font-size: 14px; margin-top: 3px; }

/* Workflow strip on home */
.workflow {
  display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 8px;
  margin-bottom: 22px; scrollbar-width: none;
}
.workflow::-webkit-scrollbar { display: none; }
.workflow-step {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border);
  min-width: 148px; flex-shrink: 0;
  cursor: pointer; transition: all .18s var(--ease);
  box-shadow: var(--shadow-sm);
}
.workflow-step:hover {
  border-color: color-mix(in srgb, var(--primary) 40%, var(--border));
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}
.workflow-step .ws-num {
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--brand-grad); color: #fff;
  font-size: 12px; font-weight: 800;
  display: grid; place-items: center; flex-shrink: 0;
}
.workflow-step .ws-label { font-size: 13px; font-weight: 700; line-height: 1.3; }
.workflow-step .ws-hint { font-size: 11px; color: var(--text-muted); }

/* ---------- Tabs ---------- */
.tabs {
  display: inline-flex; gap: 4px; padding: 5px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 20px;
  max-width: 100%; overflow-x: auto;
}
.tab {
  padding: 9px 18px; border-radius: var(--radius-sm);
  font-weight: 700; font-size: 13.5px; color: var(--text-soft);
  cursor: pointer; transition: all .15s var(--ease); white-space: nowrap;
}
.tab:hover { color: var(--text); background: color-mix(in srgb, var(--surface) 60%, transparent); }
.tab.active {
  background: var(--surface); color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* ---------- Tables ---------- */
.table-wrap {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-sm);
}
.table-scroll { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tbl th {
  background: var(--surface-2); text-align: right; font-weight: 700;
  color: var(--text-soft); padding: 13px 16px; white-space: nowrap;
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 1;
  font-size: 12.5px;
}
table.tbl td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.tbl tbody tr { transition: background .12s; }
table.tbl tbody tr:hover { background: var(--surface-2); }
table.tbl tbody tr:last-child td { border-bottom: none; }

/* ---------- Grid helpers ---------- */
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 720px) {
  .grid-2, .grid-3, .grid-4, .grid-auto { grid-template-columns: 1fr; }
  .content { padding: 16px 14px 32px; }
  .topbar { padding: 0 12px; gap: 10px; }
  .page-head h1 { font-size: 20px; }
  .topbar .page-title { font-size: 16px; }
  .topbar .page-sub { display: none; }
}

/* ---------- Stat cards ---------- */
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 18px 18px 16px;
  box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 4px;
  position: relative; overflow: hidden;
  transition: transform .18s var(--ease), box-shadow .18s;
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat::after {
  content: '';
  position: absolute; inset-inline-end: 0; top: 0; bottom: 0;
  width: 3px; border-radius: 3px 0 0 3px;
  background: var(--stat-accent, var(--primary));
  opacity: .7;
}
[dir="rtl"] .stat::after { border-radius: 0 3px 3px 0; }
.stat .stat-ico {
  position: absolute; inset-inline-end: 14px; top: 14px;
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center; font-size: 18px;
}
.stat .v {
  font-size: 28px; font-weight: 800; line-height: 1.1;
  letter-spacing: -.02em;
}
.stat .l { font-size: 13px; color: var(--text-muted); font-weight: 600; }

/* Section card header */
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}
.section-head h3 {
  font-size: 16px; font-weight: 800;
  display: flex; align-items: center; gap: 8px;
}

/* ---------- Empty state ---------- */
.empty {
  text-align: center; padding: 48px 20px; color: var(--text-muted);
}
.empty .ico {
  font-size: 48px; margin-bottom: 12px; opacity: .45;
  filter: grayscale(.2);
}
.empty h3 { color: var(--text-soft); font-size: 16px; margin-bottom: 6px; font-weight: 700; }
.empty p { font-size: 13px; max-width: 280px; margin: 0 auto 16px; line-height: 1.5; }
.empty .btn { margin-top: 4px; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.5);
  backdrop-filter: blur(6px); display: grid; place-items: center;
  z-index: 100; padding: 20px; animation: fadeIn .2s;
}
.modal {
  background: var(--surface); border-radius: var(--radius-xl);
  width: 100%; max-width: 540px; max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  animation: slideUp .28s var(--ease);
}
.modal.lg { max-width: 760px; }
.modal-head {
  padding: 20px 22px 0;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.modal-head h3 { font-size: 18px; font-weight: 800; }
.modal-body { padding: 18px 22px; }
.modal-foot {
  padding: 12px 22px 20px;
  display: flex; justify-content: flex-start; gap: 10px; flex-wrap: wrap;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp {
  from { transform: translateY(24px) scale(.98); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* ---------- Toast ---------- */
.toast-wrap {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%);
  z-index: 200; display: flex; flex-direction: column;
  gap: 10px; align-items: center;
  pointer-events: none; max-width: calc(100vw - 32px);
}
.toast {
  background: var(--text); color: var(--surface);
  padding: 12px 20px; border-radius: 14px; font-size: 13.5px; font-weight: 600;
  box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 8px;
  animation: toastIn .28s var(--ease);
  pointer-events: auto; max-width: 420px;
  text-align: center; line-height: 1.4;
  transition: opacity .25s;
}
.toast.success { background: var(--success); color: #fff; }
.toast.error { background: var(--danger); color: #fff; }
.toast.info { background: var(--primary); color: #fff; }
@keyframes toastIn {
  from { transform: translateY(16px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* ---------- Progress ---------- */
.progress {
  height: 8px; background: var(--surface-3);
  border-radius: 999px; overflow: hidden;
}
.progress > div {
  height: 100%; background: var(--brand-grad);
  border-radius: 999px; transition: width .4s var(--ease);
}

/* ---------- Availability grid (Timing) ---------- */
.avail-grid { display: grid; gap: 6px; }
.avail-cell {
  aspect-ratio: 1.4; border-radius: 8px; background: var(--surface-3);
  border: 1px solid var(--border); cursor: pointer; transition: all .12s;
  display: grid; place-items: center; font-size: 12px; font-weight: 700; color: var(--text-muted);
}
.avail-cell.on { background: var(--success); color: #fff; border-color: var(--success); }
.avail-cell:hover { transform: scale(1.05); }

/* ---------- Timetable grid ---------- */
.tt { border-collapse: separate; border-spacing: 4px; width: 100%; }
.tt th, .tt td { padding: 10px 8px; border-radius: 10px; text-align: center; font-size: 13px; }
.tt th { background: var(--surface-2); color: var(--text-soft); font-weight: 700; min-width: 70px; }
.tt td.slot { background: var(--surface-2); min-height: 52px; min-width: 110px; }
.tt td.slot.filled { color: #fff; font-weight: 700; box-shadow: var(--shadow-sm); }
.tt td.slot.empty { color: var(--text-muted); border: 1px dashed var(--border); background: transparent; }

/* ---------- Subject color dots ---------- */
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  display: inline-block; flex-shrink: 0;
  vertical-align: middle; margin-inline-end: 4px;
  box-shadow: 0 0 0 2px color-mix(in srgb, currentColor 10%, transparent);
}

/* ---------- Help step cards ---------- */
.help-card .help-num {
  font-size: 11px; font-weight: 800; color: var(--primary);
  letter-spacing: .4px; margin-bottom: 2px;
}

/* ---------- Skeleton / loading ---------- */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 8px;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---------- Mobile sidebar ---------- */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    transform: translateX(110%);
    box-shadow: none;
  }
  [dir="rtl"] .sidebar { transform: translateX(-110%); }
  .sidebar.open {
    transform: none;
    box-shadow: var(--shadow-lg);
  }
  #menuToggle { display: inline-flex !important; }
  .sidebar-overlay.show { display: block; }
}

/* ---------- Print ---------- */
@media print {
  .sidebar, .topbar, .toast-wrap, #modalRoot, .btn { display: none !important; }
  .content { padding: 0; }
  .page { display: block !important; }
  body { background: #fff; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* ============================================================
   SCREEN POLISH — forms, toolbars, dispatch, generate, timing
   ============================================================ */

/* Panel / form card header */
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}
.panel-head h3 {
  font-size: 16px; font-weight: 800;
  display: flex; align-items: center; gap: 8px;
}
.panel-head .count-badge {
  font-size: 12px; font-weight: 700;
  padding: 4px 10px; border-radius: 999px;
  background: var(--primary-soft); color: var(--primary);
}

/* Inline toolbar above tables */
.toolbar {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; margin-bottom: 12px;
}
.toolbar .search-wrap {
  position: relative; flex: 1; min-width: 180px; max-width: 320px;
}
.toolbar .search-wrap .input {
  padding-inline-start: 38px; margin: 0;
}
.toolbar .search-wrap .search-ico {
  position: absolute; inset-inline-start: 12px; top: 50%;
  transform: translateY(-50%); color: var(--text-muted); font-size: 14px;
  pointer-events: none;
}

/* Form footer actions */
.form-actions {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; margin-top: 4px;
}
.form-actions .hint {
  font-size: 12px; color: var(--text-muted); margin-inline-start: auto;
}

/* Compact select inside tables */
.select-sm {
  min-width: 100px; padding: 6px 8px !important;
  font-size: 12.5px !important; border-radius: 8px !important;
}
table.tbl td .select-sm { width: 100%; max-width: 140px; }

/* Action buttons in table rows */
.row-actions {
  display: inline-flex; align-items: center; gap: 4px;
}
.row-actions .btn-icon {
  width: 32px; height: 32px; border-radius: 8px; font-size: 13px;
}
.btn-icon.danger:hover {
  background: var(--danger-soft); color: var(--danger); border-color: transparent;
}

/* Data entry form card */
.form-card {
  margin-bottom: 18px;
  border: 1px dashed var(--border-strong);
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
}
.form-card:focus-within {
  border-style: solid;
  border-color: color-mix(in srgb, var(--primary) 40%, var(--border));
  box-shadow: var(--shadow-sm);
}

/* Dispatch matrix */
.dispatch-wrap {
  overflow: auto; max-height: min(560px, 70vh);
  border-radius: var(--radius); border: 1px solid var(--border);
}
.dispatch-wrap table.tbl th.subj-head {
  writing-mode: vertical-rl; text-orientation: mixed;
  text-align: center; font-size: 11.5px; font-weight: 700;
  min-width: 42px; max-width: 48px; padding: 10px 6px;
  white-space: nowrap; letter-spacing: .02em;
}
.dispatch-wrap table.tbl th.subj-head .subj-dot {
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block; margin-bottom: 6px;
}
.dispatch-wrap table.tbl td {
  padding: 6px 8px; vertical-align: middle;
}
.dispatch-wrap table.tbl tbody tr:nth-child(even) { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.dispatch-wrap table.tbl th.sticky-col,
.dispatch-wrap table.tbl td.sticky-col {
  position: sticky; inset-inline-start: 0; z-index: 2;
  background: var(--surface); box-shadow: -4px 0 8px rgba(15,23,42,.04);
}
[dir="rtl"] .dispatch-wrap table.tbl th.sticky-col,
[dir="rtl"] .dispatch-wrap table.tbl td.sticky-col {
  box-shadow: 4px 0 8px rgba(15,23,42,.04);
}
.dispatch-wrap table.tbl thead th.sticky-col { z-index: 3; background: var(--surface-2); }

/* Coverage ring / big progress */
.coverage-card {
  text-align: center; padding: 8px 0 4px;
}
.coverage-ring {
  width: 120px; height: 120px; margin: 0 auto 12px; position: relative;
}
.coverage-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.coverage-ring .ring-label {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 22px; font-weight: 800; transform: none;
}
.coverage-card .coverage-sub {
  font-size: 13px; color: var(--text-muted); font-weight: 600;
}

/* Generate readiness checklist */
.check-list { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.check-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 13.5px; font-weight: 600;
}
.check-item.ok { border-color: color-mix(in srgb, var(--success) 35%, var(--border)); }
.check-item.ok .ci-ico { color: var(--success); }
.check-item.bad { border-color: color-mix(in srgb, var(--warning) 40%, var(--border)); }
.check-item.bad .ci-ico { color: var(--warning); }
.check-item .ci-ico { font-size: 16px; width: 22px; text-align: center; }

/* Gen log */
#genLog, .gen-log {
  background: var(--surface-2); border-radius: 12px; padding: 14px;
  height: 380px; overflow: auto;
  font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
  font-size: 12.5px; color: var(--text-soft);
  border: 1px solid var(--border); line-height: 1.55;
}
.gen-log .log-line { padding: 2px 0; border-bottom: 1px solid transparent; }
.gen-log .log-line:hover { background: color-mix(in srgb, var(--surface) 40%, transparent); }
.gen-log .log-ok { color: var(--success); }
.gen-log .log-err { color: var(--danger); }
.gen-log .log-warn { color: var(--warning); }
.gen-log .log-info { color: var(--primary); }
.gen-log .log-head { color: var(--text); font-weight: 700; letter-spacing: .02em; }

.gen-progress-wrap { margin: 12px 0 4px; }
.gen-progress-wrap .row { margin-bottom: 6px; font-size: 12px; color: var(--text-muted); }

/* Timing availability */
.avail-legend {
  display: flex; gap: 14px; flex-wrap: wrap;
  font-size: 12px; color: var(--text-muted); margin: 8px 0 12px;
}
.avail-legend span { display: inline-flex; align-items: center; gap: 6px; }
.avail-legend .swatch {
  width: 14px; height: 14px; border-radius: 4px; border: 1px solid var(--border);
}
.avail-legend .swatch.on { background: var(--success); border-color: var(--success); }
.avail-legend .swatch.off { background: var(--surface-3); }

.avail-grid {
  display: grid; gap: 5px;
  max-width: 100%; overflow-x: auto;
}
.avail-cell {
  min-height: 36px; aspect-ratio: auto;
  border-radius: 8px; background: var(--surface-3);
  border: 1px solid var(--border); cursor: pointer; transition: all .12s;
  display: grid; place-items: center; font-size: 11.5px; font-weight: 700;
  color: var(--text-muted); user-select: none;
}
.avail-cell.hdr {
  background: transparent; border: none; cursor: default;
  color: var(--text-soft); font-size: 11px; min-height: 28px;
}
.avail-cell.hdr:hover { transform: none; }
.avail-cell.on {
  background: var(--success); color: #fff; border-color: var(--success);
  box-shadow: 0 2px 8px rgba(16,185,129,.25);
}
.avail-cell:not(.hdr):hover { transform: scale(1.06); z-index: 1; }
.avail-cell:not(.hdr):active { transform: scale(.96); }

.chip-scroll {
  display: flex; gap: 8px; flex-wrap: nowrap; overflow-x: auto;
  padding-bottom: 6px; margin-bottom: 14px;
  scrollbar-width: thin;
}

/* Manual fill meter */
.fill-meter {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 12.5px; font-weight: 700;
}
.fill-meter .fm-bar {
  width: 64px; height: 6px; border-radius: 999px;
  background: var(--surface-3); overflow: hidden;
}
.fill-meter .fm-bar > i {
  display: block; height: 100%; background: var(--brand-grad);
  border-radius: inherit;
}

/* Soft callout */
.callout {
  padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--primary-soft); color: var(--primary);
  font-size: 13px; font-weight: 600; line-height: 1.45;
  border: 1px solid color-mix(in srgb, var(--primary) 20%, transparent);
  margin-top: 14px;
}
.callout.warn {
  background: var(--warning-soft); color: #b45309;
  border-color: color-mix(in srgb, var(--warning) 25%, transparent);
}

/* Table empty cell fix */
table.tbl td .empty { padding: 32px 12px; }
table.tbl td .empty .ico { font-size: 36px; }

/* Preview frame for timetable */
.tt-frame {
  overflow: auto; border-radius: var(--radius);
  border: 1px solid var(--border); padding: 8px;
  background: var(--surface-2);
}
.tt th, .tt td { transition: transform .12s, box-shadow .12s; }
.tt td.slot.filled { cursor: default; }
.tt td.slot.filled:hover { filter: brightness(1.08); box-shadow: var(--shadow); }

/* Settings color row polish */
.color-row {
  padding: 8px 10px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2);
  transition: border-color .15s;
}
.color-row:hover { border-color: var(--border-strong); }

/* Desktop hand-off steps on the Generate page */
.handoff-steps {
  counter-reset: step; list-style: none; padding: 0; margin: 14px 0 0;
  display: flex; flex-direction: column; gap: 10px;
}
.handoff-steps li {
  position: relative; padding: 12px 14px 12px 52px;
  border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 13.5px; font-weight: 600; line-height: 1.5;
}
[dir="rtl"] .handoff-steps li { padding: 12px 52px 12px 14px; }
.handoff-steps li::before {
  counter-increment: step; content: counter(step);
  position: absolute; top: 50%; transform: translateY(-50%);
  inset-inline-start: 12px;
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--brand-grad); color: #fff;
  font-size: 13px; font-weight: 800;
}
.handoff-steps li strong { color: var(--primary); font-weight: 800; }

@media (max-width: 720px) {
  .dispatch-wrap table.tbl th.subj-head {
    writing-mode: horizontal-tb; min-width: 72px; max-width: none;
  }
  .form-actions .hint { display: none; }
  .coverage-ring { width: 100px; height: 100px; }
}
