/* ==========================================================================
   Thabat Teacher Dashboard — design system
   Direction: calm, clean, trustworthy, warm; Islamic without cliché.
   Mobile-first, RTL-first. Tokens per ui-ux-pro-max guidance (4/8 spacing,
   ≥44px touch targets, 4.5:1 contrast, visible focus states).
   ========================================================================== */

:root {
  /* color tokens */
  --bg: #f7f5f0;            /* warm sand */
  --surface: #ffffff;
  --text: #292524;          /* stone-800 */
  --text-muted: #57534e;    /* stone-600 — 4.6:1 on --bg */
  --border: #e7e5e4;
  --border-strong: #d6d3d1;
  --primary: #166534;       /* deep calm green — 6.3:1 on white */
  --primary-hover: #14532d;
  --primary-soft: #ecfdf3;
  --accent: #b45309;        /* amber-700 — codes/highlights 4.8:1 on white */
  --accent-soft: #fef3e2;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --ok: #15803d;
  --focus-ring: #166534;

  /* spacing scale (4/8 system) */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 24px; --sp-6: 32px; --sp-7: 48px;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgb(41 37 36 / 0.06), 0 1px 3px rgb(41 37 36 / 0.08);
  --font: "IBM Plex Sans Arabic", "Noto Naskh Arabic", "Segoe UI", Tahoma, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------- accessibility ---------- */

.skip-link {
  position: absolute;
  inset-inline-start: -9999px;
  top: 8px;
  background: var(--surface);
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--radius-sm);
  z-index: 100;
}
.skip-link:focus { inset-inline-start: 8px; }

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 4px;
}

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

/* ---------- topbar ---------- */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 820px;
  margin: 0 auto;
  padding: var(--sp-3) var(--sp-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}
.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  text-decoration: none;
  color: var(--text);
}
.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 19px;
  display: grid;
  place-items: center;
}
.brand-name { font-weight: 700; font-size: 18px; }
.brand-sub { color: var(--text-muted); font-size: 13px; }
.topbar-actions { display: flex; align-items: center; gap: var(--sp-2); }
.teacher-chip { color: var(--text-muted); font-size: 14px; }

/* ---------- layout ---------- */

.container {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: var(--sp-5) var(--sp-4) var(--sp-7);
  flex: 1;
}

.footer {
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  padding: var(--sp-4);
  color: var(--text-muted);
  font-size: 13px;
  border-top: 1px solid var(--border);
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
}
.page-head h1 { margin: 0 0 var(--sp-1); font-size: 24px; line-height: 1.3; }
.page-head p { margin: 0; }

h2 { font-size: 18px; margin: 0; }

.muted { color: var(--text-muted); font-size: 14px; }

.crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: var(--sp-4);
}
.crumbs a { color: var(--primary); text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }

.section { margin-top: var(--sp-6); }
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-3);
}
.section-danger { border-top: 1px solid var(--border); padding-top: var(--sp-4); }
.section-danger h2 { font-size: 15px; color: var(--text-muted); font-weight: 600; }

/* ---------- panels / cards ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-5);
  box-shadow: var(--shadow);
}
.panel-narrow { max-width: 560px; }
.panel-subtle { padding: var(--sp-3) var(--sp-4); box-shadow: none; }
.panel-title { font-size: 14px; font-weight: 600; color: var(--text-muted); margin: var(--sp-4) 0 var(--sp-2); }
.panel-title:first-child { margin-top: 0; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 44px;
  padding: var(--sp-2) var(--sp-4);
  border-radius: 10px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease;
  touch-action: manipulation;
}
.btn-sm { min-height: 36px; padding: var(--sp-1) var(--sp-3); font-size: 14px; }
.btn-lg { min-height: 48px; padding: var(--sp-3) var(--sp-5); font-size: 16px; }
.btn-block { width: 100%; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  background: var(--surface);
  color: var(--primary);
  border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--primary-soft); border-color: var(--primary); }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.92); }
.btn-danger:disabled { opacity: 0.5; cursor: not-allowed; }

.icon-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  font-size: 15px;
  color: var(--text-muted);
  display: grid;
  place-items: center;
}
.icon-btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.inline-form { display: inline; }

/* ---------- forms ---------- */

.stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.stack-tight { gap: var(--sp-3); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 600; font-size: 14px; }
.optional { color: var(--text-muted); font-weight: 400; font-size: 13px; }
.hint { color: var(--text-muted); font-size: 13px; margin: 0; }

input[type="text"], input[type="password"], textarea, select {
  font-family: inherit;
  font-size: 16px; /* ≥16px avoids iOS zoom */
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
  width: 100%;
}
textarea { resize: vertical; min-height: 96px; }
input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
  border-color: var(--primary);
}

.error-list { margin: 0; padding-inline-start: 20px; }
.error-list li { margin: 4px 0; }

/* ---------- flash / feedback ---------- */

.flash {
  border-radius: var(--radius-sm);
  padding: var(--sp-3) var(--sp-4);
  margin-bottom: var(--sp-4);
  font-size: 15px;
  border: 1px solid transparent;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
}
.flash-success { background: var(--primary-soft); color: var(--ok); border-color: #bbe7c9; }
.flash-error { background: var(--danger-soft); color: var(--danger); border-color: #f3c8c8; }
.flash-warn { background: var(--accent-soft); color: #92400e; border-color: #f0d5ad; }

/* ---------- badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12.5px;
  font-weight: 600;
  border-radius: 999px;
  padding: 2px 10px;
  white-space: nowrap;
}
.badge-ok { background: var(--primary-soft); color: var(--ok); }
.badge-warn { background: var(--accent-soft); color: #92400e; }

/* ---------- dashboard group list ---------- */

.group-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--sp-3); }
.group-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4);
}
.group-link {
  flex: 1 1 260px;
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  text-decoration: none;
  color: inherit;
  min-width: 0;
}
.group-main { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.group-name { font-weight: 700; font-size: 17px; }
.group-meta { display: flex; flex-wrap: wrap; gap: var(--sp-2); color: var(--text-muted); font-size: 13.5px; }
.group-side { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }

.code-chip {
  font-family: ui-monospace, monospace;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  border-radius: 6px;
  padding: 1px 8px;
  font-size: 14px;
  letter-spacing: 1px;
}

/* ---------- group page ---------- */

.code-line { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.code-big {
  font-family: ui-monospace, monospace;
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 8px;
  padding: 2px 12px;
  letter-spacing: 2px;
}

.publish-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--sp-4) var(--sp-5);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-2);
}
.publish-state { display: flex; flex-direction: column; gap: 2px; min-width: 200px; }
.publish-actions { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.public-link { font-size: 13px; color: var(--primary); word-break: break-all; }
.publish-dirty { border-inline-start: 4px solid var(--accent); }
.publish-clean { border-inline-start: 4px solid var(--ok); }
.publish-never { border-inline-start: 4px solid var(--danger); }

/* ---------- item lists (curricula / lessons) ---------- */

.item-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--sp-2); }
.item-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--sp-2) var(--sp-3);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}
.row-inactive { opacity: 0.62; }
.order-btns { display: flex; flex-direction: column; gap: 2px; }
.item-main {
  flex: 1;
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
  text-decoration: none;
  color: inherit;
  min-width: 0;
  padding: var(--sp-1) 0;
}
a.item-main:hover .item-title { color: var(--primary); }
.item-title { font-weight: 600; overflow-wrap: anywhere; }
.lesson-num { color: var(--text-muted); font-size: 14px; flex-shrink: 0; }
.lesson-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.lesson-desc { font-size: 13.5px; }
.item-actions { display: flex; align-items: center; gap: var(--sp-1); flex-shrink: 0; }

.yt-chip {
  font-family: ui-monospace, monospace;
  font-size: 12.5px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 6px;
  padding: 1px 8px;
  text-decoration: none;
  width: fit-content;
}
.yt-chip:hover { text-decoration: underline; }

/* ---------- assignments ---------- */

.assignment-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--sp-2); }
.assignment-list li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--sp-3) var(--sp-4);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
}
.a-curriculum { font-weight: 700; }
.a-arrow { color: var(--text-muted); }
.a-lesson { color: var(--primary); font-weight: 600; }

.assign-grid { display: flex; flex-direction: column; gap: var(--sp-4); }
.assign-row { display: flex; flex-direction: column; gap: 6px; }
.assign-label { font-weight: 700; font-size: 15px; }

/* ---------- publish summary ---------- */

.summary-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--sp-2); }
.summary-list li {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-3);
  border-bottom: 1px dashed var(--border);
  padding-bottom: var(--sp-2);
  flex-wrap: wrap;
}
.summary-list li:last-child { border-bottom: none; padding-bottom: 0; }
.publish-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-4);
  margin: var(--sp-4) 0;
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg);
  border-radius: var(--radius-sm);
  font-size: 14px;
}

/* ---------- details / danger zone ---------- */

.danger-details summary {
  cursor: pointer;
  color: var(--text-muted);
  font-size: 14px;
  padding: var(--sp-2) 0;
}
.danger-details[open] summary { margin-bottom: var(--sp-3); }
.danger-zone { display: flex; flex-wrap: wrap; gap: var(--sp-3); margin-top: var(--sp-3); }

/* ---------- auth ---------- */

.auth-wrap { max-width: 420px; margin: var(--sp-7) auto 0; }
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--sp-6);
}
.auth-title { margin: 0 0 var(--sp-1); font-size: 22px; }
.auth-sub { color: var(--text-muted); margin: 0 0 var(--sp-4); font-size: 14px; }
.auth-note { text-align: center; color: var(--text-muted); font-size: 13.5px; }

/* ---------- empty states ---------- */

.empty-state {
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: var(--sp-7) var(--sp-5);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
}
.empty-state h2, .empty-state h1 { margin: 0; }
.empty-state p { margin: 0; color: var(--text-muted); max-width: 400px; }
.empty-sm { padding: var(--sp-4); }

/* ---------- code input row ---------- */

.code-row { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.code-input {
  font-family: ui-monospace, monospace;
  font-size: 18px;
  letter-spacing: 2px;
  text-transform: uppercase;
  max-width: 220px;
  font-weight: 700;
}

/* ---------- responsive ---------- */

@media (min-width: 640px) {
  .page-head h1 { font-size: 28px; }
  .assign-row { flex-direction: row; align-items: center; }
  .assign-row select { max-width: 420px; }
  .item-actions { gap: var(--sp-2); }
}

/* very narrow phones: keep actions reachable, no horizontal scroll */
@media (max-width: 380px) {
  .container { padding-inline: var(--sp-3); }
  .item-row { flex-wrap: wrap; }
  .item-actions { margin-inline-start: 44px; }
  .group-row { flex-direction: column; align-items: stretch; }
  .group-side { justify-content: flex-end; }
  .publish-actions { width: 100%; }
}
