/* منصتي الدراسية — التنسيقات */

:root {
  color-scheme: light;
  --blob-1: rgba(45, 212, 191, .16);
  --blob-2: rgba(167, 139, 250, .12);
  /* الشكل الناعم (Soft UI) — ألوان «التعليم الإلكتروني» من الـ Skill */
  --bg: #F1F7F6;
  --surface: #FFFFFF;
  --surface-2: #F3F8F7;
  --border: #E1ECE9;
  --border-strong: #C5D6D2;
  --text: #17312F;
  --muted: #52646A;
  --primary: #0F766E;
  --primary-hover: #0B5F59;
  --primary-soft: #DCF3EE;
  --on-primary: #FFFFFF;
  --danger: #C62828;
  --danger-soft: #FDECEC;
  --ok: #16794A;
  --ok-soft: #E5F5EC;
  --warn: #A35208;
  --warn-soft: #FDF1E0;
  --shadow: 0 1px 2px rgba(15, 60, 55, .04), 0 8px 24px rgba(15, 60, 55, .07);
  --shadow-lift: 0 2px 6px rgba(15, 60, 55, .06), 0 18px 40px rgba(15, 60, 55, .12);
  --r-lg: 22px;
  --r-md: 14px;
  --r-sm: 10px;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

.c-indigo { --tint: #EEF0FF; --tint-fg: #4338CA; }
.c-teal   { --tint: #E1F5F1; --tint-fg: #0F766E; }
.c-amber  { --tint: #FDF1DC; --tint-fg: #A35208; }
.c-rose   { --tint: #FCE8EF; --tint-fg: #BE185D; }
.c-sky    { --tint: #E3F1FC; --tint-fg: #0369A1; }
.c-violet { --tint: #F1EAFE; --tint-fg: #6D28D9; }

/* الوضع الداكن: يُفعَّل حسب اختيار المستخدم أو حسب جهازه (تلقائي) */
:root[data-mode="dark"] {
  color-scheme: dark;
  --bg: #0E1716;
  --surface: #152220;
  --surface-2: #1B2A28;
  --border: #243634;
  --border-strong: #35504C;
  --text: #E6F2F0;
  --muted: #9FB5B1;
  --primary: #5EEAD4;
  --primary-hover: #99F6E4;
  --primary-soft: #12403B;
  --on-primary: #04201D;
  --danger: #F28B82;
  --danger-soft: #3A1F22;
  --ok: #6FD3A0;
  --ok-soft: #173326;
  --warn: #F3BD6B;
  --warn-soft: #3A2C16;
  --shadow: 0 1px 2px rgba(0, 0, 0, .25), 0 6px 20px rgba(0, 0, 0, .22);
  --shadow-lift: 0 2px 6px rgba(0, 0, 0, .3), 0 16px 36px rgba(0, 0, 0, .35);
}
[data-mode="dark"] .c-indigo { --tint: rgba(144, 146, 249, .16); --tint-fg: #AEB0FC; }
[data-mode="dark"] .c-teal   { --tint: rgba(45, 212, 191, .14);  --tint-fg: #5EEAD4; }
[data-mode="dark"] .c-amber  { --tint: rgba(251, 191, 36, .14);  --tint-fg: #FCD34D; }
[data-mode="dark"] .c-rose   { --tint: rgba(244, 114, 182, .14); --tint-fg: #F9A8D4; }
[data-mode="dark"] .c-sky    { --tint: rgba(56, 189, 248, .14);  --tint-fg: #7DD3FC; }
[data-mode="dark"] .c-violet { --tint: rgba(167, 139, 250, .16); --tint-fg: #C4B5FD; }

/* ---------- ألوان المنصة: كل مستخدم يختار ما يريح عينه ----------
   النعناع (الافتراضي أعلاه) — الليلك — الوردي — الرملي.
   كل لون رئيسي يحقق تباين 4.5:1 على الأقل مع نص الأزرار. */

:root[data-theme="lilac"] {
  --blob-1: rgba(167, 139, 250, .18); --blob-2: rgba(244, 114, 182, .10);
  --bg: #F5F3FB; --surface-2: #F5F2FC; --border: #E8E3F5; --border-strong: #CFC6E6;
  --text: #231C3A; --muted: #5B5873;
  --primary: #6D28D9; --primary-hover: #5B21B6; --primary-soft: #EDE7FB;
  --shadow: 0 1px 2px rgba(45, 25, 90, .04), 0 8px 24px rgba(45, 25, 90, .07);
  --shadow-lift: 0 2px 6px rgba(45, 25, 90, .06), 0 18px 40px rgba(45, 25, 90, .12);
}
:root[data-theme="rose"] {
  --blob-1: rgba(244, 114, 182, .16); --blob-2: rgba(251, 191, 36, .10);
  --bg: #FBF4F7; --surface-2: #FBF3F6; --border: #F2E3EA; --border-strong: #E2C6D3;
  --text: #3A1A28; --muted: #6B5560;
  --primary: #BE185D; --primary-hover: #9D174D; --primary-soft: #FCE7F1;
  --shadow: 0 1px 2px rgba(90, 20, 50, .04), 0 8px 24px rgba(90, 20, 50, .07);
  --shadow-lift: 0 2px 6px rgba(90, 20, 50, .06), 0 18px 40px rgba(90, 20, 50, .12);
}
:root[data-theme="sand"] {
  --blob-1: rgba(251, 191, 36, .16); --blob-2: rgba(45, 212, 191, .08);
  --bg: #FAF6EF; --surface-2: #F9F4EC; --border: #EEE5D6; --border-strong: #DCCDB4;
  --text: #33261A; --muted: #6A5D4D;
  --primary: #B45309; --primary-hover: #92400E; --primary-soft: #FBEBD3;
  --shadow: 0 1px 2px rgba(80, 50, 15, .04), 0 8px 24px rgba(80, 50, 15, .07);
  --shadow-lift: 0 2px 6px rgba(80, 50, 15, .06), 0 18px 40px rgba(80, 50, 15, .12);
}

:root[data-mode="dark"][data-theme="lilac"] {
  --blob-1: rgba(167, 139, 250, .14); --blob-2: rgba(244, 114, 182, .07);
  --bg: #12101B; --surface: #1A1727; --surface-2: #221E33; --border: #2E2944; --border-strong: #433C60;
  --text: #ECE9F7; --muted: #ADA6C6;
  --primary: #C4B5FD; --primary-hover: #DDD6FE; --primary-soft: #2D2550; --on-primary: #1E1238;
}
:root[data-mode="dark"][data-theme="rose"] {
  --blob-1: rgba(244, 114, 182, .12); --blob-2: rgba(251, 191, 36, .06);
  --bg: #170F13; --surface: #22161C; --surface-2: #2B1D24; --border: #3A2830; --border-strong: #553A46;
  --text: #F6E9EF; --muted: #C3A9B5;
  --primary: #F9A8D4; --primary-hover: #FBCFE8; --primary-soft: #4A1F33; --on-primary: #3B0A22;
}
:root[data-mode="dark"][data-theme="sand"] {
  --blob-1: rgba(251, 191, 36, .10); --blob-2: rgba(45, 212, 191, .05);
  --bg: #16120D; --surface: #201A13; --surface-2: #2A2219; --border: #382D21; --border-strong: #54442F;
  --text: #F5EDE2; --muted: #C2B29C;
  --primary: #FCD34D; --primary-hover: #FDE68A; --primary-soft: #3F3015; --on-primary: #2A1B02;
}
:root[data-mode="dark"] { --blob-1: rgba(45, 212, 191, .10); --blob-2: rgba(167, 139, 250, .07); }
:root[data-mode="dark"][data-theme] {
  --shadow: 0 1px 2px rgba(0, 0, 0, .25), 0 6px 20px rgba(0, 0, 0, .22);
  --shadow-lift: 0 2px 6px rgba(0, 0, 0, .3), 0 16px 36px rgba(0, 0, 0, .35);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }

/* يلغي تأخير اللمس في الهاتف */
a, button, input, select, textarea, label { touch-action: manipulation; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans Arabic", system-ui, "Segoe UI", Tahoma, sans-serif;
  font-size: 16px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
body.no-scroll { overflow: hidden; }

h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.6rem; line-height: 1.4; font-weight: 700; text-wrap: balance; }
h2 { font-size: 1.15rem; line-height: 1.5; font-weight: 700; }
h3 { font-size: 1.05rem; line-height: 1.5; font-weight: 600; }
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }
img { max-width: 100%; }

.muted { color: var(--muted); }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.icon { display: inline-flex; flex: none; }
.icon svg { display: block; }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.noscript { padding: 24px; text-align: center; }

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--primary) 55%, transparent);
  outline-offset: 2px;
}

/* ---------- الأزرار ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 20px;
  border: 0; border-radius: var(--r-md);
  background: var(--primary); color: var(--on-primary);
  font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background .2s var(--ease), transform .12s var(--ease), opacity .2s;
}
.btn:hover { background: var(--primary-hover); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .65; cursor: default; }
.btn.loading::after {
  content: ""; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-inline-end-color: transparent;
  animation: spin .7s linear infinite;
}
.btn-block { width: 100%; }
.btn-ghost { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--border); }
.btn-ghost:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger); filter: brightness(.92); }
[data-mode="dark"] .btn-danger { color: #2A1010; }

.icon-btn {
  display: inline-grid; place-items: center; flex: none;
  width: 44px; height: 44px; padding: 0;
  border: 0; border-radius: 12px; background: transparent; color: var(--muted);
  cursor: pointer; transition: background .2s, color .2s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { background: var(--border); }

.skip-link {
  position: absolute; z-index: 40; top: -64px; inset-inline-start: 12px;
  padding: 10px 16px; border-radius: 12px;
  background: var(--primary); color: var(--on-primary); font-weight: 600;
  transition: top .2s var(--ease);
}
.skip-link:focus { top: 10px; }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }

/* ---------- الحقول ---------- */

.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field label { font-size: .92rem; font-weight: 600; }
.hint { font-size: .84rem; color: var(--muted); }

.input {
  width: 100%; min-height: 48px; padding: 10px 14px;
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  background: var(--surface); color: var(--text);
  transition: border-color .2s, box-shadow .2s;
}
.input::placeholder { color: var(--muted); opacity: .8; }
.input:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent);
}
textarea.input { min-height: 140px; resize: vertical; line-height: 1.8; }
select.input { appearance: auto; }
.ltr { direction: ltr; text-align: left; }
input[type="file"].input { padding: 9px 12px; }

.check { display: flex; align-items: center; gap: 10px; min-height: 44px; margin-bottom: 16px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--primary); }

.form-error {
  margin-bottom: 14px; padding: 10px 14px; border-radius: var(--r-sm);
  background: var(--danger-soft); color: var(--danger); font-size: .93rem; font-weight: 500;
}
.field-error { margin: 0; color: var(--danger); font-size: .88rem; font-weight: 500; }
.field-error.center { margin: -8px 0 16px; text-align: center; }
.input[aria-invalid="true"] { border-color: var(--danger); }
.input[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 22%, transparent); }

.pw-wrap { position: relative; }
.pw-wrap .input { padding-right: 52px; }
.pw-toggle {
  position: absolute; top: 50%; right: 2px; transform: translateY(-50%);
  display: grid; place-items: center; width: 44px; height: 44px;
  border: 0; border-radius: 10px; background: transparent; color: var(--muted); cursor: pointer;
  transition: color .2s, background .2s;
}
.pw-toggle:hover { color: var(--text); }
.pw-toggle:active { background: var(--surface-2); }

.form-actions { display: flex; gap: 10px; justify-content: flex-start; flex-wrap: wrap; margin-top: 8px; }

.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch { position: relative; }
.swatch input { position: absolute; inset: 0; opacity: 0; cursor: pointer; margin: 0; }
.swatch span {
  display: block; width: 44px; height: 44px; border-radius: 14px;
  background: var(--tint); box-shadow: inset 0 0 0 2px transparent;
  transition: box-shadow .2s, transform .2s;
}
.swatch span::after {
  content: ""; display: block; width: 16px; height: 16px; margin: 14px; border-radius: 50%;
  background: var(--tint-fg);
}
.swatch input:checked + span { box-shadow: inset 0 0 0 2px var(--tint-fg); transform: scale(1.05); }
.swatch input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--primary) 55%, transparent); outline-offset: 2px; }

/* ---------- شاشة التسجيل ---------- */

.auth {
  min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px;
  background:
    radial-gradient(600px 300px at 85% -5%, color-mix(in srgb, var(--primary) 12%, transparent), transparent 70%),
    radial-gradient(500px 280px at 5% 105%, color-mix(in srgb, #0D9488 10%, transparent), transparent 70%),
    var(--bg);
}
.auth-card {
  width: 100%; max-width: 440px; padding: 30px 26px 26px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 26px; box-shadow: var(--shadow-lift);
  animation: rise .35s var(--ease) both;
}
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; margin-bottom: 20px; }
.auth-brand h1 { font-size: 1.45rem; }
.auth-brand p { color: var(--muted); font-size: .95rem; max-width: 30ch; }

.brand-mark {
  display: inline-grid; place-items: center; flex: none;
  width: 40px; height: 40px; border-radius: 13px;
  background: var(--primary); color: var(--on-primary);
}
.auth-brand .brand-mark { width: 56px; height: 56px; border-radius: 18px; }

.tabs {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin-bottom: 22px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px;
}
.tabs button {
  min-height: 44px; border: 0; border-radius: 10px; background: transparent;
  color: var(--muted); font-weight: 600; cursor: pointer;
  transition: background .2s var(--ease), color .2s, box-shadow .2s;
}
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.avatar-pick {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  margin: 0 auto 18px; width: fit-content; cursor: pointer;
  color: var(--primary); font-weight: 600; font-size: .93rem;
}
.avatar-pick-circle {
  display: grid; place-items: center; width: 96px; height: 96px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary);
  border: 2px dashed color-mix(in srgb, var(--primary) 45%, transparent);
  overflow: hidden; transition: transform .2s var(--ease), border-color .2s;
}
.avatar-pick:hover .avatar-pick-circle { transform: scale(1.04); border-color: var(--primary); }
.avatar-pick-circle.has-img { border-style: solid; border-color: var(--primary); }
.avatar-pick-circle img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-pick:focus-within .avatar-pick-circle {
  outline: 3px solid color-mix(in srgb, var(--primary) 55%, transparent); outline-offset: 3px;
}

/* ---------- الهيكل العام ---------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px); backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar-in {
  display: flex; align-items: center; gap: 16px;
  max-width: 1080px; margin: 0 auto; padding: 10px 20px; min-height: 64px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.08rem; border-radius: 12px; }
.nav { display: flex; gap: 4px; margin-inline-start: 12px; }
.nav a {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px;
  border-radius: 11px; color: var(--muted); font-weight: 500;
  transition: background .2s, color .2s;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }

.userbox { display: flex; align-items: center; gap: 10px; margin-inline-start: auto; min-width: 0; }
.user-meta { display: grid; line-height: 1.35; min-width: 0; }
.user-meta strong { font-size: .93rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 16ch; }
.user-meta span { font-size: .8rem; color: var(--muted); direction: ltr; text-align: right; }

.avatar { border-radius: 50%; object-fit: cover; flex: none; background: var(--surface-2); display: block; }
.avatar-fallback {
  display: inline-grid; place-items: center;
  background: var(--primary-soft); color: var(--primary); font-weight: 700;
}

.container { max-width: 1080px; margin: 0 auto; padding: 28px 20px 96px; outline: none; }
.container.enter > * { animation: rise .28s var(--ease) both; }

.bottomnav { display: none; }

/* ---------- الصفحات ---------- */

.page { display: grid; gap: 22px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head p { margin-top: 2px; }
.back-link {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px;
  color: var(--muted); font-weight: 500; font-size: .93rem; width: fit-content; border-radius: 8px;
}
.back-link:hover { color: var(--primary); }
.back-link .icon { transform: scaleX(-1); }

.section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section-title a {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 8px;
  color: var(--primary); font-weight: 600; font-size: .92rem; border-radius: 8px;
}
.section-title a:hover { text-decoration: underline; }

.hero {
  display: flex; align-items: center; gap: 16px; padding: 22px;
  background:
    radial-gradient(420px 180px at 0% 0%, color-mix(in srgb, var(--primary) 14%, transparent), transparent 70%),
    var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow);
}
.hero p { color: var(--muted); }

/* المستطيلات الرئيسية */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.tile {
  display: flex; align-items: center; gap: 16px; padding: 18px 20px; min-height: 96px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow);
  transition: transform .22s var(--ease), box-shadow .22s var(--ease), border-color .22s;
}
.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); border-color: color-mix(in srgb, var(--tint-fg) 35%, var(--border)); }
.tile:active { transform: translateY(0) scale(.995); }
.tile-icon {
  display: grid; place-items: center; flex: none; width: 54px; height: 54px;
  border-radius: 16px; background: var(--tint); color: var(--tint-fg);
}
.tile-text { display: grid; gap: 1px; min-width: 0; flex: 1; }
.tile-text strong { font-size: 1.08rem; font-weight: 700; }
.tile-text span { color: var(--muted); font-size: .92rem; }
.tile-meta {
  flex: none; padding: 3px 12px; border-radius: 999px;
  background: var(--tint); color: var(--tint-fg); font-size: .84rem; font-weight: 600; white-space: nowrap;
}
.tile-arrow { color: var(--muted); flex: none; transition: transform .22s var(--ease); }
.tile:hover .tile-arrow { transform: translateX(-3px); color: var(--tint-fg); }

.two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px; align-items: start; }

/* البطاقات والقوائم */
.card {
  position: relative; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow);
}
.list { display: grid; gap: 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }

.subject { transition: transform .22s var(--ease), box-shadow .22s var(--ease), border-color .22s; }
.subject:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); border-color: color-mix(in srgb, var(--tint-fg) 35%, var(--border)); }
.subject-link { display: grid; gap: 10px; padding: 20px; height: 100%; border-radius: var(--r-lg); }
.subject-link p { color: var(--muted); font-size: .93rem; }
.subject .card-del { position: absolute; top: 10px; inset-inline-end: 10px; }
.subject-count { color: var(--tint-fg); font-weight: 600; font-size: .88rem; margin-top: auto; }

.row-card { display: flex; align-items: stretch; transition: transform .22s var(--ease), box-shadow .22s var(--ease), border-color .22s; }
.row-card:hover { transform: translateY(-1px); box-shadow: var(--shadow-lift); border-color: var(--border-strong); }
.row-main {
  display: flex; align-items: flex-start; gap: 14px; flex: 1; min-width: 0; padding: 16px 18px;
  border: 0; background: transparent; text-align: start; cursor: pointer; border-radius: var(--r-lg);
}
.row-main .tile-icon { width: 46px; height: 46px; border-radius: 14px; }
.row-text { display: grid; gap: 4px; min-width: 0; flex: 1; }
.row-text h3 { overflow-wrap: anywhere; }
.excerpt {
  color: var(--muted); font-size: .93rem;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.row-card .card-del { align-self: center; margin-inline-end: 8px; }

.meta { display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; color: var(--muted); font-size: .85rem; }
.meta .icon { vertical-align: -3px; margin-inline-end: 4px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 11px; border-radius: 999px;
  background: var(--tint, var(--surface-2)); color: var(--tint-fg, var(--muted));
  font-size: .82rem; font-weight: 600; white-space: nowrap;
}
.chip-ok { background: var(--ok-soft); color: var(--ok); }
.chip-warn { background: var(--warn-soft); color: var(--warn); }
.chip-off { background: var(--surface-2); color: var(--muted); box-shadow: inset 0 0 0 1px var(--border); }
.chip-admin { background: var(--primary-soft); color: var(--primary); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.chip-ok .dot { animation: pulse 2s ease-in-out infinite; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filter {
  min-height: 44px; padding: 0 16px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted); font-weight: 500;
  transition: background .2s, color .2s, border-color .2s, transform .12s var(--ease);
}
.filter:hover { border-color: var(--border-strong); color: var(--text); }
.filter[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-weight: 600; }

.news { padding: 20px 22px; display: grid; gap: 8px; }
.news.pinned { border-color: color-mix(in srgb, var(--warn) 40%, var(--border)); }
.news-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.news-head h3 { font-size: 1.12rem; overflow-wrap: anywhere; }
.news .card-del { margin: -8px; margin-inline-start: 0; }
.news-body { color: var(--text); max-width: 75ch; }

.mini { display: grid; gap: 10px; }
.mini-item {
  display: grid; gap: 2px; padding: 14px 16px; width: 100%;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  text-align: start; cursor: pointer; transition: border-color .2s, transform .2s var(--ease);
}
.mini-item:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.mini-item strong { font-weight: 600; overflow-wrap: anywhere; }
.mini-item span { color: var(--muted); font-size: .85rem; }

.empty {
  display: grid; justify-items: center; gap: 8px; padding: 44px 20px; text-align: center;
  background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--r-lg);
  color: var(--muted);
}
.empty .tile-icon { margin-bottom: 4px; }
.empty strong { color: var(--text); font-size: 1.02rem; }

.skeleton-wrap { display: grid; gap: 14px; }
.skeleton {
  height: 92px; border-radius: var(--r-lg);
  background: linear-gradient(100deg, var(--surface) 30%, var(--surface-2) 50%, var(--surface) 70%);
  background-size: 200% 100%; border: 1px solid var(--border);
  animation: shimmer 1.3s linear infinite;
}
.skeleton:first-child { height: 60px; width: 55%; }

/* ---------- لوحة التحكم ---------- */

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stat { padding: 18px 20px; display: grid; gap: 2px; }
.stat-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); font-size: .92rem; font-weight: 500; }
.stat-top .tile-icon { width: 38px; height: 38px; border-radius: 12px; }
.stat-value { font-size: 2rem; font-weight: 700; line-height: 1.3; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); font-size: .84rem; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.search { position: relative; flex: 1; max-width: 340px; min-width: 200px; }
.search .icon { position: absolute; top: 50%; inset-inline-start: 14px; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search .input { padding-inline-start: 44px; }

.table-wrap { overflow-x: auto; }
table.users { width: 100%; border-collapse: collapse; font-size: .94rem; }
.users th {
  text-align: start; padding: 14px 16px; color: var(--muted); font-size: .84rem; font-weight: 600;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.users td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.users tr:last-child td { border-bottom: 0; }
.users tbody tr { transition: background .2s; }
.users tbody tr:hover { background: var(--surface-2); }
.user-cell { display: flex; align-items: center; gap: 12px; min-width: 190px; }
.user-cell div { display: grid; line-height: 1.4; min-width: 0; }
.user-cell strong { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.user-cell span.handle { color: var(--muted); font-size: .84rem; direction: ltr; text-align: right; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- النوافذ والتنبيهات ---------- */

.backdrop {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px;
  background: rgba(16, 18, 30, .48); overflow-y: auto;
  animation: fade .2s ease both;
}
.modal {
  width: 100%; max-width: 480px; margin: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 24px; box-shadow: var(--shadow-lift);
  animation: pop .24s var(--ease) both; outline: none;
}
.modal-wide { max-width: 680px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 16px 12px 22px; padding-inline: 22px 12px;
}
.modal-head h2 { overflow-wrap: anywhere; }
.modal-body { padding: 4px 22px 22px; }
.confirm-text { margin-bottom: 18px; color: var(--muted); }
.summary-body { margin: 14px 0 4px; line-height: 1.95; }
.file-link { margin-top: 16px; max-width: 100%; }
.file-link span:last-child { overflow: hidden; text-overflow: ellipsis; }

#toast-root {
  position: fixed; z-index: 60; inset-inline: 0; bottom: 24px;
  display: grid; justify-items: center; gap: 8px; padding: 0 16px; pointer-events: none;
}
.toast {
  padding: 11px 18px; border-radius: 14px; max-width: 420px;
  background: var(--text); color: var(--bg); font-weight: 500; box-shadow: var(--shadow-lift);
  animation: rise .25s var(--ease) both; transition: opacity .3s, transform .3s;
}
.toast-error { background: var(--danger); color: #fff; }
[data-mode="dark"] .toast-error { color: #2A1010; }
.toast.hide { opacity: 0; transform: translateY(8px); }

/* ---------- إحساس اللمس والظهور المتتابع ---------- */

.filter:active, .mini-item:active { transform: scale(.97); }
.row-card:active, .tile:active, .subject:active { transform: scale(.99); }
.nav a:active, .bottomnav a:active { background: var(--primary-soft); }

/* إغلاق النافذة: أقصر من فتحها (حوالي ثلثي المدة) */
.backdrop.closing { pointer-events: none; animation: fade-out .16s ease forwards; }
.backdrop.closing .modal { animation: modal-out .16s ease forwards; }

/* عناصر القوائم تظهر واحداً بعد الآخر بفارق 40ms بدل ظهورها دفعة واحدة */
.container.enter :is(.tiles, .grid, .list, .mini) > * { animation: rise .32s var(--ease) both; }
.container.enter :is(.tiles, .grid, .list, .mini) > :nth-child(2) { animation-delay: 40ms; }
.container.enter :is(.tiles, .grid, .list, .mini) > :nth-child(3) { animation-delay: 80ms; }
.container.enter :is(.tiles, .grid, .list, .mini) > :nth-child(4) { animation-delay: 120ms; }
.container.enter :is(.tiles, .grid, .list, .mini) > :nth-child(5) { animation-delay: 160ms; }
.container.enter :is(.tiles, .grid, .list, .mini) > :nth-child(6) { animation-delay: 200ms; }
.container.enter :is(.tiles, .grid, .list, .mini) > :nth-child(n+7) { animation-delay: 240ms; }

/* ---------- عارض الملفات ---------- */

.viewer-backdrop {
  position: fixed; inset: 0; z-index: 70;
  display: grid; place-items: center; padding: 20px;
  /* خلفية معتمة بدون تمويه: التمويه يُعاد حسابه مع كل حركة داخل العارض فيثقله */
  background: rgba(14, 16, 28, .66);
  animation: fade .25s ease both;
}
.viewer {
  display: flex; flex-direction: column;
  width: min(1000px, 100%); height: min(94vh, 1200px); height: min(94dvh, 1200px);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 22px; overflow: hidden;
  box-shadow: 0 30px 80px rgba(10, 12, 24, .35);
  animation: viewer-in .42s cubic-bezier(.2, .8, .2, 1) both;
}
.viewer-backdrop.closing { animation: fade-out .24s ease forwards; }
.viewer-backdrop.closing .viewer { animation: viewer-out .24s ease forwards; }

.viewer-head {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; padding-inline-start: 16px;
  border-bottom: 1px solid var(--border);
}
.viewer-title { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.viewer-title .tile-icon { width: 40px; height: 40px; border-radius: 12px; }
.viewer-title > div { display: grid; min-width: 0; line-height: 1.45; }
.viewer-title strong, .viewer-title span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer-title strong { font-weight: 600; }
.viewer-title span { color: var(--muted); font-size: .84rem; }
.viewer-tools { display: flex; align-items: center; gap: 2px; flex: none; }
.viewer-pages {
  padding: 4px 12px; margin-inline-end: 6px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
  font-size: .86rem; font-weight: 500; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.viewer-zoombox {
  display: flex; align-items: center;
  padding-inline-end: 6px; margin-inline-end: 4px; border-inline-end: 1px solid var(--border);
}
.viewer-zoom { min-width: 50px; text-align: center; color: var(--muted); font-size: .86rem; font-variant-numeric: tabular-nums; }
.icon-btn:disabled { opacity: .4; cursor: default; background: transparent; }

.viewer-body {
  position: relative; flex: 1; min-height: 0; overflow: auto;
  direction: ltr; background: var(--surface-2);
  overscroll-behavior: contain; scrollbar-gutter: stable;
}
.viewer-body.framed { overflow: hidden; scrollbar-gutter: auto; }

.viewer-status {
  position: absolute; inset: 0; z-index: 2; direction: rtl;
  display: grid; place-content: center; justify-items: center; gap: 14px;
  padding: 24px; text-align: center; color: var(--muted); background: var(--surface-2);
  transition: opacity .35s ease, visibility .35s;
}
.viewer-status.hide { opacity: 0; visibility: hidden; }
.viewer-status strong { color: var(--text); }

.ring svg { display: block; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 5; }
.ring-track { stroke: var(--border); }
.ring-bar {
  stroke: var(--primary); stroke-linecap: round;
  stroke-dasharray: 163.36; stroke-dashoffset: 163.36;
  transition: stroke-dashoffset .25s ease;
}
.ring.spin { animation: spin 1s linear infinite; }
.ring.spin .ring-bar { stroke-dashoffset: 118; }

.pdf-pages {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  width: max-content; min-width: 100%; padding: 18px;
}
.pdf-page {
  position: relative; flex: none; overflow: hidden; border-radius: 6px;
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(16, 24, 40, .10), 0 8px 24px rgba(16, 24, 40, .08);
  contain: layout paint;
}
/* مكان الصفحة قبل رسمها: رقمها فقط، بدون حركة مستمرة تستهلك الجهاز */
.pdf-page::before {
  content: attr(data-page); position: absolute; inset: 0;
  display: grid; place-items: center;
  color: var(--border-strong); font-size: 1.5rem; font-weight: 600;
}
.pdf-page.ready { background: #fff; }
.pdf-page.ready::before { content: none; }
.pdf-page canvas { display: block; width: 100%; height: 100%; }
.pdf-page canvas.page-in, .img-stage img { animation: page-in .45s var(--ease) both; }

.img-stage {
  display: grid; place-items: center;
  width: max-content; min-width: 100%; min-height: 100%; padding: 18px;
}
.img-stage img {
  display: block; max-width: none; height: auto; border-radius: 8px; background: #fff;
  box-shadow: 0 1px 3px rgba(16, 24, 40, .10), 0 8px 24px rgba(16, 24, 40, .08);
}
.pdf-frame { display: block; width: 100%; height: 100%; border: 0; background: #fff; }

@media (max-width: 760px) {
  .viewer-backdrop { padding: 0; }
  .viewer { width: 100%; height: 100%; border: 0; border-radius: 0; animation-name: viewer-up; }
  .viewer-backdrop.closing .viewer { animation-name: viewer-down; }
  .viewer-head { gap: 8px; padding: 8px; padding-inline-start: 12px; }
  .viewer-title .tile-icon, .viewer-zoombox { display: none; }
  .viewer-pages { margin-inline-end: 2px; }
  .pdf-pages { gap: 10px; padding: 10px; }
  .img-stage { padding: 10px; }
}

/* ---------- الحركات ---------- */

@keyframes viewer-in { from { opacity: 0; transform: translateY(14px) scale(.92); } to { opacity: 1; transform: none; } }
@keyframes viewer-out { to { opacity: 0; transform: translateY(10px) scale(.96); } }
@keyframes viewer-up { from { opacity: 0; transform: translateY(40px); } to { opacity: 1; transform: none; } }
@keyframes viewer-down { to { opacity: 0; transform: translateY(40px); } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes modal-out { to { opacity: 0; transform: translateY(6px) scale(.98); } }
@keyframes page-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes pulse { 50% { opacity: .35; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ---------- الشاشات الصغيرة ---------- */

@media (max-width: 860px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-col { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  h1 { font-size: 1.35rem; }
  .nav { display: none; }
  .topbar-in { padding: 8px 16px; min-height: 58px; }
  .user-meta { display: none; }
  .container { padding: 20px 16px 110px; }
  .tiles { grid-template-columns: 1fr; }
  .tile { padding: 16px; gap: 14px; }
  .tile-meta { display: none; }
  .hero { padding: 18px; }

  .bottomnav {
    position: fixed; z-index: 20; inset-inline: 0; bottom: 0;
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
    border-top: 1px solid var(--border);
  }
  .bottomnav a {
    display: grid; justify-items: center; gap: 2px; min-height: 54px; padding: 6px 2px;
    border-radius: 12px; color: var(--muted); font-size: .74rem; font-weight: 500;
    transition: color .2s, background .2s;
  }
  .bottomnav a.active { color: var(--primary); background: var(--primary-soft); font-weight: 600; }
  #toast-root { bottom: 84px; }

  /* جدول المستخدمين يتحول إلى بطاقات */
  .table-wrap { overflow: visible; }
  table.users, .users tbody, .users tr, .users td { display: block; }
  .users thead { display: none; }
  .users tr { padding: 14px 16px; border-bottom: 1px solid var(--border); }
  .users tr:last-child { border-bottom: 0; }
  .users td { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 5px 0; border: 0; }
  .users td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: .86rem; }
  .users td.cell-user { padding-bottom: 10px; }
  .users td.cell-action { justify-content: flex-end; }
  .search { max-width: none; flex-basis: 100%; }
}

/* ==========================================================================
   الشكل الناعم (Soft UI Evolution — من الـ Skill)
   بطاقات بدون حدود حادة، ظلال ناعمة، ألوان باستيل، أزرار دائرية
   ========================================================================== */

/* خلفية ناعمة ثابتة: طبقة مستقلة حتى لا تُعاد رسمها أثناء التمرير */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(900px 520px at 100% -10%, var(--blob-1), transparent 60%),
    radial-gradient(760px 520px at -10% 110%, var(--blob-2), transparent 60%);
}

/* لا حدود حادة: الفصل بالظل واللون فقط */
.card, .tile, .hero, .mini-item, .auth-card, .modal, .filter, .tabs, .viewer { border-color: transparent; }

/* الشريط العلوي يطفو ككبسولة */
.topbar { background: transparent; border-bottom: 0; -webkit-backdrop-filter: none; backdrop-filter: none; padding: 12px 16px 0; }
.topbar-in {
  padding: 8px 14px; border-radius: 22px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: blur(14px) saturate(1.3); backdrop-filter: blur(14px) saturate(1.3);
  box-shadow: var(--shadow);
}

/* الترحيب */
.hero {
  padding: 26px;
  background:
    radial-gradient(420px 200px at 0% 100%, var(--blob-2), transparent 70%),
    linear-gradient(135deg, color-mix(in srgb, var(--primary) 16%, var(--surface)), var(--surface) 72%);
}
.hero .avatar { box-shadow: 0 0 0 4px var(--surface), 0 8px 20px rgba(15, 60, 55, .16); }

/* أقسام الصفحة الرئيسية: بطاقات باستيل ملوّنة */
.tile {
  min-height: 108px;
  background: linear-gradient(135deg, var(--tint), color-mix(in srgb, var(--tint) 30%, var(--surface)));
}
.tile .tile-icon {
  width: 58px; height: 58px; border-radius: 18px;
  background: var(--surface); box-shadow: 0 6px 16px color-mix(in srgb, var(--tint-fg) 20%, transparent);
}
.tile-meta { background: var(--surface); }
.tile:hover { border-color: transparent; }

/* المواد: لون المادة يتلاشى من أعلى البطاقة */
.subject { background: linear-gradient(180deg, var(--tint), var(--surface) 58%); }
.subject:hover { border-color: transparent; }
.subject .tile-icon { background: var(--surface); box-shadow: 0 6px 16px color-mix(in srgb, var(--tint-fg) 18%, transparent); }

/* الملخصات والأخبار */
.row-card:hover { border-color: transparent; }
.mini-item { box-shadow: var(--shadow); }
.mini-item:hover { box-shadow: var(--shadow-lift); }
.news.pinned { border-inline-start: 4px solid var(--warn); }
.stat { background: linear-gradient(160deg, var(--tint), var(--surface) 62%); }

/* الأزرار: كبسولات بظل ملوّن ناعم */
.btn { border-radius: 999px; box-shadow: 0 6px 16px color-mix(in srgb, var(--primary) 26%, transparent); }
.btn:hover { box-shadow: 0 8px 22px color-mix(in srgb, var(--primary) 32%, transparent); }
.btn-ghost, .btn-ghost:hover { background: var(--surface); box-shadow: var(--shadow); }
.btn-danger { box-shadow: 0 6px 16px color-mix(in srgb, var(--danger) 26%, transparent); }

/* الحقول: ممتلئة بلون هادئ بدل الحدود */
.input { background: var(--surface-2); border-color: transparent; }
.input:hover { border-color: var(--border-strong); }
.input:focus { background: var(--surface); border-color: var(--primary); }
.input[aria-invalid="true"], .input[aria-invalid="true"]:focus { border-color: var(--danger); }
.tabs { background: var(--surface-2); }

/* صفحة الدخول */
.auth {
  background:
    radial-gradient(640px 340px at 90% -5%, var(--blob-1), transparent 70%),
    radial-gradient(560px 320px at 5% 105%, var(--blob-2), transparent 70%),
    var(--bg);
}
.auth-card { border-radius: 30px; }
.auth-brand .brand-mark { box-shadow: 0 10px 24px color-mix(in srgb, var(--primary) 32%, transparent); }
.modal { border-radius: 28px; }

@media (max-width: 760px) {
  .topbar { padding: 8px 10px 0; }
  .topbar-in { padding: 6px 10px; border-radius: 18px; min-height: 58px; }
  /* شريط التنقل السفلي يطفو بزوايا دائرية */
  .bottomnav {
    inset-inline: 10px; bottom: calc(10px + env(safe-area-inset-bottom));
    padding: 6px; border: 0; border-radius: 24px;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    box-shadow: var(--shadow-lift);
  }
  .container { padding-bottom: 124px; }
  #toast-root { bottom: 100px; }
  .tile { min-height: 96px; }
  .hero { padding: 20px; }
}

/* ==========================================================================
   البحث الفوري
   ========================================================================== */

.kbd {
  display: inline-flex; align-items: center; padding: 1px 7px; border-radius: 7px;
  background: var(--surface-2); color: var(--muted);
  font: 500 .74rem/1.5 ui-monospace, "Cascadia Mono", Consolas, monospace;
  box-shadow: inset 0 -1px 0 var(--border-strong); direction: ltr; white-space: nowrap;
}

.search-trigger {
  display: inline-flex; align-items: center; gap: 10px; flex: none;
  min-height: 44px; margin-inline-start: auto; padding: 0 14px 0 12px; padding-inline: 14px 12px;
  border: 0; border-radius: 999px; background: var(--surface-2); color: var(--muted);
  font-size: .92rem; cursor: pointer; transition: background .2s, color .2s, transform .12s var(--ease);
}
.search-trigger:hover { background: var(--primary-soft); color: var(--text); }
.search-trigger:active { transform: scale(.97); }
.search-trigger + .userbox { margin-inline-start: 0; }

.hero { flex-wrap: wrap; }
.hero-search {
  display: flex; align-items: center; gap: 10px; flex-basis: 100%;
  min-height: 52px; padding: 0 18px; border: 0; border-radius: 999px;
  background: var(--surface); color: var(--muted); box-shadow: var(--shadow);
  font-size: .98rem; text-align: start; cursor: pointer;
  transition: box-shadow .2s, color .2s, transform .12s var(--ease);
}
.hero-search:hover { box-shadow: var(--shadow-lift); color: var(--text); }
.hero-search:active { transform: scale(.99); }
.hero-search .kbd { margin-inline-start: auto; }

.palette-backdrop {
  position: fixed; inset: 0; z-index: 65;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 12vh 16px 16px; background: rgba(10, 20, 18, .5);
  animation: fade .18s ease both;
}
.palette {
  display: flex; flex-direction: column; width: 100%; max-width: 620px; max-height: 72vh;
  background: var(--surface); border-radius: 24px; overflow: hidden;
  box-shadow: 0 30px 80px rgba(10, 24, 22, .3);
  animation: palette-in .26s cubic-bezier(.2, .8, .2, 1) both;
}
.palette-backdrop.closing { pointer-events: none; animation: fade-out .14s ease forwards; }
.palette-backdrop.closing .palette { animation: palette-out .14s ease forwards; }

.palette-head {
  display: flex; align-items: center; gap: 12px; padding: 12px 18px;
  border-bottom: 2px solid var(--border); color: var(--muted); transition: border-color .2s;
}
.palette-head:focus-within { border-bottom-color: var(--primary); }
.search-input {
  flex: 1; min-width: 0; min-height: 44px; border: 0; outline: none;
  background: transparent; color: var(--text); font-size: 1.08rem;
}
.search-input:focus-visible { outline: none; }

.search-results { overflow-y: auto; padding: 8px; overscroll-behavior: contain; }
.search-results[aria-busy="true"] { opacity: .7; transition: opacity .2s .15s; }
.palette-group + .palette-group { margin-top: 6px; }
.palette-group-title { padding: 8px 12px 4px; color: var(--muted); font-size: .8rem; font-weight: 600; }
.palette-item {
  display: flex; align-items: center; gap: 12px; min-height: 58px; padding: 9px 12px;
  border-radius: 14px; cursor: pointer; transition: background .12s;
}
.palette-item[aria-selected="true"] { background: var(--primary-soft); }
.palette-item .tile-icon { width: 40px; height: 40px; border-radius: 12px; }
.palette-text { display: grid; flex: 1; min-width: 0; line-height: 1.5; }
.palette-text strong, .palette-text span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-text strong { font-weight: 600; }
.palette-text span { color: var(--muted); font-size: .86rem; }
.palette-empty { display: grid; justify-items: center; gap: 6px; padding: 34px 16px; text-align: center; color: var(--muted); }
.palette-empty strong { color: var(--text); }
.palette-foot {
  display: flex; flex-wrap: wrap; gap: 6px 18px; padding: 10px 18px;
  border-top: 1px solid var(--border); color: var(--muted); font-size: .8rem;
}
.palette-foot .kbd { margin-inline: 2px; }

mark {
  padding: 0 2px; border-radius: 4px; color: inherit;
  background: color-mix(in srgb, var(--warn) 24%, transparent);
}

.flash { animation: flash 1.8s ease; }

@keyframes palette-in { from { opacity: 0; transform: translateY(-10px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes palette-out { to { opacity: 0; transform: translateY(-6px) scale(.98); } }
@keyframes flash {
  0%, 45% { box-shadow: 0 0 0 3px var(--primary), var(--shadow-lift); }
  100% { box-shadow: var(--shadow); }
}

@media (max-width: 1000px) {
  .search-trigger { width: 44px; padding: 0; justify-content: center; }
  .search-trigger-text, .search-trigger .kbd { display: none; }
}
@media (max-width: 760px) {
  .palette-backdrop { padding: 10px; }
  .palette { max-height: calc(100dvh - 20px); border-radius: 20px; }
  .palette-foot, .palette-head .kbd, .hero-search .kbd { display: none; }
}

/* ==========================================================================
   نافذة المظهر
   ========================================================================== */

.search-trigger + .theme-trigger + .userbox { margin-inline-start: 0; }
.theme-picker { display: grid; gap: 10px; }
.theme-label { margin-top: 4px; font-size: .92rem; color: var(--muted); font-weight: 600; }

.theme-group-mode {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px;
  background: var(--surface-2); border-radius: 16px;
}
.mode-option {
  display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px;
  border: 0; border-radius: 12px; background: transparent; color: var(--muted);
  font-weight: 600; cursor: pointer; transition: background .2s var(--ease), color .2s, box-shadow .2s;
}
.mode-option:hover { color: var(--text); }
.mode-option[aria-checked="true"] { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }

.theme-group-color { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.theme-option {
  --sw-main: #0F766E; --sw-soft: #DCF3EE; --sw-bg: #F1F7F6;
  display: flex; align-items: center; gap: 12px; min-height: 64px; padding: 10px 12px;
  border: 2px solid transparent; border-radius: 16px; background: var(--surface-2);
  text-align: start; cursor: pointer;
  transition: border-color .2s, background .2s, transform .12s var(--ease);
}
.theme-option:hover { background: var(--primary-soft); }
.theme-option:active { transform: scale(.98); }
.theme-option[aria-checked="true"] { border-color: var(--primary); background: var(--surface); box-shadow: var(--shadow); }
.theme-option[data-value="lilac"] { --sw-main: #6D28D9; --sw-soft: #EDE7FB; --sw-bg: #F5F3FB; }
.theme-option[data-value="rose"]  { --sw-main: #BE185D; --sw-soft: #FCE7F1; --sw-bg: #FBF4F7; }
.theme-option[data-value="sand"]  { --sw-main: #B45309; --sw-soft: #FBEBD3; --sw-bg: #FAF6EF; }
.theme-preview {
  position: relative; flex: none; width: 44px; height: 44px; border-radius: 14px; overflow: hidden;
  background: var(--sw-bg); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .06);
}
.theme-preview span { position: absolute; border-radius: 50%; }
.theme-preview span:nth-child(1) { width: 26px; height: 26px; top: 5px; inset-inline-start: 5px; background: var(--sw-main); }
.theme-preview span:nth-child(2) { width: 20px; height: 20px; bottom: 4px; inset-inline-end: 4px; background: var(--sw-soft); box-shadow: 0 0 0 2px var(--sw-bg); }
.theme-name { display: grid; line-height: 1.4; min-width: 0; }
.theme-name strong { font-weight: 600; }
.theme-name span { color: var(--muted); font-size: .82rem; }

/* انتقال ناعم للألوان لحظة تغيير المظهر فقط */
.theme-switching, .theme-switching *, .theme-switching *::before {
  transition: background-color .35s ease, color .35s ease, border-color .35s ease, box-shadow .35s ease !important;
}

@media (max-width: 420px) {
  .brand > span:last-child { display: none; }
  .theme-group-color { grid-template-columns: 1fr; }
}

/* الشريط العلوي على الشاشات المتوسطة: الاسم بجانب الصورة يختفي واسم المنصة لا ينكسر */
.brand { white-space: nowrap; flex: none; }
@media (max-width: 1180px) {
  .user-meta { display: none; }
  .nav { margin-inline-start: 4px; }
  .nav a { padding: 0 11px; }
  .topbar-in { gap: 10px; }
}
