/* ==========================================================================
   نظام انصراف — نظام التصميم
   الفكرة: "لوحة انصراف" على غرار لوحات المغادرة في المطارات، مطبّقة على
   طابور نداء الطلاب: صفوف عريضة، اسم ضخم يُقرأ من بعيد، وشريط حالة يتقدّم.
   ========================================================================== */

:root {
  /* الألوان — حبر بترولي عميق + ورق بارد + نحاسي مؤسسي */
  --ink:        #0E2A33;
  --ink-2:      #143A46;
  --ink-3:      #1D4E5C;
  --ink-line:   #23596A;
  --paper:      #F4F7F7;
  --surface:    #FFFFFF;
  --surface-2:  #EDF2F2;
  --text:       #14262C;
  --text-soft:  #567079;
  --text-faint: #8AA0A7;
  --line:       #DBE4E5;

  --brass:      #C08A1E;
  --brass-soft: #FBF1DA;
  --green:      #1E7A5A;
  --green-soft: #E3F3ED;
  --amber:      #B26A00;
  --amber-soft: #FBEEDA;
  --red:        #A8322D;
  --red-soft:   #FBE7E6;
  --blue:       #1F5F8B;
  --blue-soft:  #E4EFF6;

  --radius:     10px;
  --radius-lg:  16px;
  --shadow-sm:  0 1px 2px rgba(14, 42, 51, .06), 0 1px 3px rgba(14, 42, 51, .04);
  --shadow-md:  0 4px 14px rgba(14, 42, 51, .08);
  --shadow-lg:  0 12px 32px rgba(14, 42, 51, .14);

  --nav-width:  256px;
  --header-h:   62px;

  --font-body: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  --font-display: "Tajawal", "IBM Plex Sans Arabic", Tahoma, sans-serif;

  /* تجاوز متغيرات بوتستراب لتتبع هوية النظام */
  --bs-body-font-family: var(--font-body);
  --bs-body-color: var(--text);
  --bs-body-bg: var(--paper);
  --bs-primary: var(--ink-3);
  --bs-border-color: var(--line);
  --bs-border-radius: var(--radius);
}

* { -webkit-tap-highlight-color: transparent; }

html { font-size: 15px; }

body {
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--text);
  font-feature-settings: "tnum" 1;
  min-height: 100vh;
}

h1, h2, h3, h4, .display-face { font-family: var(--font-display); font-weight: 800; letter-spacing: -.01em; }

a { color: var(--ink-3); text-underline-offset: 3px; }
a:hover { color: var(--ink); }

/* حالات التركيز واضحة دائماً (وصول لوحة المفاتيح) */
:focus-visible {
  outline: 3px solid var(--brass);
  outline-offset: 2px;
  border-radius: 4px;
}

::selection { background: var(--brass-soft); color: var(--ink); }

/* ==========================================================================
   الهيكل: قائمة جانبية ثابتة (يمين) + رأس + محتوى
   ========================================================================== */

.app-shell { min-height: 100vh; }

.app-nav {
  position: fixed;
  inset-block: 0;
  /* inline-start في RTL = الحافة اليمنى، وهو الموضع الطبيعي للقائمة في العربية */
  inset-inline-start: 0;
  inset-inline-end: auto;
  width: var(--nav-width);
  background: var(--ink);
  color: #CFE0E5;
  display: flex;
  flex-direction: column;
  z-index: 1040;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.app-nav__brand {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: 1.1rem 1.15rem;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.app-nav__mark {
  width: 38px; height: 38px;
  border-radius: 11px;
  background: linear-gradient(160deg, var(--brass), #8A5F12);
  display: grid; place-items: center;
  color: #14262C;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.15rem;
  flex: none;
}

.app-nav__name {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.12rem;
  color: #fff;
  line-height: 1.1;
}
.app-nav__tag { font-size: .72rem; color: #86A6B0; }

.app-nav__section {
  padding: 1rem 1.15rem .35rem;
  font-size: .7rem;
  letter-spacing: .04em;
  color: #6E939E;
  font-weight: 600;
}

.app-nav__link {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .62rem 1.15rem;
  color: #CFE0E5;
  text-decoration: none;
  font-size: .93rem;
  border-inline-start: 3px solid transparent;
  transition: background .12s ease, color .12s ease;
}
.app-nav__link:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.app-nav__link.is-active {
  background: rgba(192, 138, 30, .14);
  color: #fff;
  border-inline-start-color: var(--brass);
  font-weight: 600;
}
.app-nav__link .icon { width: 20px; text-align: center; flex: none; opacity: .9; }
.app-nav__badge {
  margin-inline-start: auto;
  background: var(--red);
  color: #fff;
  font-size: .7rem;
  font-weight: 600;
  padding: .05rem .42rem;
  border-radius: 999px;
}

.app-main {
  margin-inline-start: var(--nav-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.15rem;
  position: sticky;
  top: 0;
  z-index: 1020;
}

.app-header__title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.12rem;
  margin: 0;
}

.app-header__clock {
  font-variant-numeric: tabular-nums;
  color: var(--text-soft);
  font-size: .88rem;
}

.app-content { padding: 1.35rem; flex: 1; }

.nav-toggle { display: none; }

@media (max-width: 991.98px) {
  .app-nav {
    transform: translateX(100%);
    transition: transform .2s ease;
    box-shadow: var(--shadow-lg);
  }
  .app-nav.is-open { transform: translateX(0); }
  .app-main { margin-inline-start: 0; }
  .nav-toggle { display: inline-flex; }
  .app-content { padding: 1rem .85rem 2.5rem; }
}

.nav-scrim {
  position: fixed; inset: 0;
  background: rgba(14, 42, 51, .45);
  z-index: 1035;
  display: none;
}
.nav-scrim.is-open { display: block; }

/* ==========================================================================
   البطاقات والجداول
   ========================================================================== */

.card-plain {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.card-plain__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .9rem 1.1rem;
  border-bottom: 1px solid var(--line);
}

.card-plain__title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1rem;
  margin: 0;
}

.card-plain__body { padding: 1.1rem; }

/* بطاقات الإحصاء */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: .85rem;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 1rem 1.1rem;
  position: relative;
  overflow: hidden;
}
.stat::before {
  content: "";
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  width: 4px;
  background: var(--ink-3);
}
.stat--brass::before { background: var(--brass); }
.stat--green::before { background: var(--green); }
.stat--amber::before { background: var(--amber); }
.stat--red::before   { background: var(--red); }

.stat__label { font-size: .84rem; color: var(--text-soft); margin-bottom: .3rem; }
.stat__value {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 2rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.stat__hint { font-size: .76rem; color: var(--text-faint); margin-top: .3rem; }

.table-plain { width: 100%; border-collapse: collapse; }
.table-plain th {
  text-align: start;
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-soft);
  padding: .6rem .8rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  white-space: nowrap;
}
.table-plain td {
  padding: .7rem .8rem;
  border-bottom: 1px solid var(--line);
  font-size: .9rem;
  vertical-align: middle;
}
.table-plain tbody tr:hover { background: #FAFCFC; }
.table-wrap { overflow-x: auto; }

/* ==========================================================================
   شارات الحالة — لون + رمز نصي (لا نعتمد على اللون وحده)
   ========================================================================== */

.badge-state {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .8rem;
  font-weight: 600;
  padding: .22rem .6rem;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge-state::before { font-size: .95em; line-height: 1; }

.badge-state--new        { background: var(--blue-soft);  color: #17456A; border-color: #C6DCEA; }
.badge-state--new::before { content: "•"; }
.badge-state--announcing { background: var(--brass-soft); color: #7A5510; border-color: #EBD9A9; }
.badge-state--announcing::before { content: "◉"; }
.badge-state--waiting    { background: var(--amber-soft); color: #7A4A02; border-color: #EDD6AC; }
.badge-state--waiting::before { content: "◔"; }
.badge-state--reannounce { background: #F3E8FB; color: #6A3592; border-color: #E0CBEF; }
.badge-state--reannounce::before { content: "↻"; }
.badge-state--done       { background: var(--green-soft); color: #14573F; border-color: #BFE2D5; }
.badge-state--done::before { content: "✓"; }
.badge-state--danger     { background: var(--red-soft);   color: #7E211D; border-color: #EFC7C4; }
.badge-state--danger::before { content: "!"; }
.badge-state--muted      { background: var(--surface-2);  color: var(--text-soft); border-color: var(--line); }
.badge-state--muted::before { content: "—"; }
.badge-state--secondary  { background: var(--surface-2);  color: var(--text-soft); border-color: var(--line); }
.badge-state--secondary::before { content: "…"; }

/* ==========================================================================
   لوحة النداء — العنصر المميّز في النظام
   ========================================================================== */

.board { display: flex; flex-direction: column; gap: .8rem; }

.call-row {
  --accent: var(--blue);
  display: grid;
  grid-template-columns: 74px 1fr auto;
  align-items: center;
  gap: 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-inline-start: 6px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: 1rem 1.15rem;
  box-shadow: var(--shadow-sm);
  position: relative;
}

.call-row--new        { --accent: var(--blue); }
.call-row--announcing { --accent: var(--brass); background: linear-gradient(90deg, var(--brass-soft), var(--surface) 55%); }
.call-row--waiting    { --accent: var(--amber); }
.call-row--reannounce { --accent: #7B3FA8; background: linear-gradient(90deg, #F7EFFC, var(--surface) 55%); }
.call-row--danger     { --accent: var(--red); background: linear-gradient(90deg, var(--red-soft), var(--surface) 55%); }

.call-row__slot {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.5rem;
  color: var(--accent);
  background: var(--surface-2);
  border-radius: 12px;
  height: 62px;
  display: grid;
  place-items: center;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.call-row__slot small { display: block; font-size: .58rem; font-weight: 500; color: var(--text-faint); }

.call-row__name {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.5rem, 2.6vw, 2.1rem);
  line-height: 1.15;
  margin: 0 0 .25rem;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.call-row__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem 1rem;
  font-size: .86rem;
  color: var(--text-soft);
}
.call-row__meta strong { color: var(--text); font-weight: 600; }
.call-row__meta time { font-variant-numeric: tabular-nums; }

.call-row__actions {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  min-width: 190px;
}

.call-row.is-fresh { animation: rowFlip .45s ease; }
@keyframes rowFlip {
  from { transform: translateY(-8px) scaleY(.96); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

.call-row.is-leaving { animation: rowLeave .3s ease forwards; }
@keyframes rowLeave {
  to { transform: translateX(-14px); opacity: 0; }
}

@media (max-width: 767.98px) {
  .call-row { grid-template-columns: 56px 1fr; }
  .call-row__actions { grid-column: 1 / -1; flex-direction: row; min-width: 0; }
  .call-row__actions .btn { flex: 1; }
  .call-row__slot { height: 52px; font-size: 1.2rem; }
}

/* أزرار الإجراءات الكبيرة */
.btn-action {
  font-weight: 600;
  font-size: 1rem;
  padding: .62rem 1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  cursor: pointer;
  transition: transform .08s ease, background .12s ease;
  background: var(--surface);
}
.btn-action:active { transform: translateY(1px); }
.btn-action:disabled { opacity: .55; cursor: not-allowed; }

.btn-done    { background: var(--green); color: #fff; }
.btn-done:hover { background: #17654A; color: #fff; }
.btn-repeat  { background: var(--surface); color: var(--ink); border-color: var(--ink-line); }
.btn-repeat:hover { background: var(--surface-2); }
.btn-ghost   { background: transparent; color: var(--text-soft); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-ink     { background: var(--ink); color: #fff; }
.btn-ink:hover { background: var(--ink-2); color: #fff; }
.btn-brass   { background: var(--brass); color: #17262B; }
.btn-brass:hover { background: #A97714; color: #17262B; }
.btn-danger-soft { background: var(--red-soft); color: var(--red); border-color: #EFC7C4; }
.btn-danger-soft:hover { background: #F6D8D6; }

/* شريط تفعيل الصوت */
.audio-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .75rem;
  padding: .8rem 1.1rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: var(--surface);
  margin-bottom: 1rem;
}
.audio-bar.is-off {
  background: linear-gradient(90deg, var(--brass-soft), var(--surface));
  border-color: #EBD9A9;
}
.audio-bar__status { font-size: .88rem; color: var(--text-soft); }
.audio-bar__status strong { color: var(--text); }

.pulse-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--green);
  display: inline-block;
  box-shadow: 0 0 0 0 rgba(30, 122, 90, .5);
  animation: pulse 2s infinite;
}
.pulse-dot--off { background: var(--text-faint); animation: none; }
@keyframes pulse {
  70%  { box-shadow: 0 0 0 8px rgba(30, 122, 90, 0); }
  100% { box-shadow: 0 0 0 0 rgba(30, 122, 90, 0); }
}

/* حالة فارغة */
.empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-soft);
}
.empty__mark {
  font-size: 2.4rem;
  margin-bottom: .6rem;
  opacity: .5;
}
.empty__title { font-family: var(--font-display); font-weight: 800; font-size: 1.15rem; color: var(--text); }

/* ==========================================================================
   النماذج
   ========================================================================== */

.form-label { font-size: .86rem; font-weight: 600; color: var(--text); margin-bottom: .3rem; }
.form-control, .form-select {
  border-color: var(--line);
  border-radius: var(--radius);
  padding: .55rem .75rem;
  font-size: .95rem;
}
.form-control:focus, .form-select:focus {
  border-color: var(--ink-3);
  box-shadow: 0 0 0 3px rgba(29, 78, 92, .12);
}
.form-hint { font-size: .78rem; color: var(--text-faint); margin-top: .25rem; }
.form-error { font-size: .8rem; color: var(--red); margin-top: .25rem; }

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: .7rem;
  align-items: end;
}

/* ==========================================================================
   تنبيهات
   ========================================================================== */

.flash-stack {
  position: fixed;
  top: calc(var(--header-h) + 12px);
  inset-inline-start: 16px;
  z-index: 1080;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  max-width: 380px;
}

.flash {
  padding: .7rem .95rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  font-size: .9rem;
  display: flex;
  gap: .5rem;
  align-items: flex-start;
}
.flash--success { border-inline-start: 4px solid var(--green); }
.flash--error   { border-inline-start: 4px solid var(--red); }
.flash--info    { border-inline-start: 4px solid var(--blue); }

.alert-inline {
  padding: .75rem .95rem;
  border-radius: var(--radius);
  font-size: .9rem;
  border: 1px solid var(--line);
  background: var(--surface);
}
.alert-inline--warn { background: var(--amber-soft); border-color: #EDD6AC; color: #6E4302; }
.alert-inline--info { background: var(--blue-soft); border-color: #C6DCEA; color: #17456A; }
.alert-inline--danger { background: var(--red-soft); border-color: #EFC7C4; color: #7E211D; }

/* ==========================================================================
   المسار الزمني
   ========================================================================== */

.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before {
  content: "";
  position: absolute;
  inset-block: 6px;
  inset-inline-start: 7px;
  width: 2px;
  background: var(--line);
}
.timeline__item { position: relative; padding-inline-start: 1.8rem; padding-bottom: 1.1rem; }
.timeline__dot {
  position: absolute;
  inset-inline-start: 0;
  top: 4px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--surface);
  border: 3px solid var(--ink-3);
}
.timeline__title { font-weight: 600; font-size: .93rem; }
.timeline__meta { font-size: .8rem; color: var(--text-soft); font-variant-numeric: tabular-nums; }

/* ==========================================================================
   الدخول
   ========================================================================== */

.auth-wrap {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.05fr .95fr;
  background: var(--paper);
}

.auth-side {
  background:
    radial-gradient(1200px 500px at 80% -10%, rgba(192, 138, 30, .22), transparent 60%),
    linear-gradient(160deg, var(--ink), #0A1E25);
  color: #DCE9EC;
  padding: 3rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.auth-side__title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2rem, 3.5vw, 3rem);
  color: #fff;
  line-height: 1.2;
  margin-bottom: .75rem;
}
.auth-side__lede { font-size: 1.02rem; color: #A9C4CB; max-width: 46ch; line-height: 1.8; }

.auth-side__board {
  margin-top: 2.2rem;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: rgba(255,255,255,.03);
}
.auth-side__board-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .7rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
  font-size: .92rem;
}
.auth-side__board-row:last-child { border-bottom: 0; }
.auth-side__board-name { font-family: var(--font-display); font-weight: 700; color: #fff; }
.auth-side__board-state { font-size: .78rem; color: var(--brass); }

.auth-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}
.auth-card { width: 100%; max-width: 400px; }

@media (max-width: 991.98px) {
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-side { display: none; }
}

/* ==========================================================================
   شاشة العرض الكبيرة
   ========================================================================== */

.display-body {
  background: linear-gradient(180deg, #0A1E25, #071519);
  color: #EAF3F5;
  min-height: 100vh;
  margin: 0;
}

.display-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 1.1rem 2rem;
  border-bottom: 1px solid rgba(255, 255, 255, .1);
}

.display-school {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.3rem, 2.2vw, 2rem);
  color: #fff;
  display: flex;
  align-items: center;
  gap: .8rem;
}

.display-clock {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.5rem, 3vw, 2.6rem);
  font-variant-numeric: tabular-nums;
  color: var(--brass);
  line-height: 1;
}
.display-date { font-size: .95rem; color: #8FB0B9; text-align: start; }

.display-main { padding: 1.5rem 2rem 3rem; }

.display-now {
  border: 2px solid var(--brass);
  border-radius: 18px;
  background: linear-gradient(120deg, rgba(192, 138, 30, .22), rgba(192, 138, 30, .05));
  padding: 1.5rem 2rem;
  margin-bottom: 1.5rem;
  display: none;
}
.display-now.is-on { display: block; animation: rowFlip .4s ease; }
.display-now__label {
  font-size: 1rem;
  color: var(--brass);
  letter-spacing: .05em;
  margin-bottom: .35rem;
}
.display-now__name {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.4rem, 7vw, 5.5rem);
  line-height: 1.05;
  color: #fff;
}
.display-now__meta { font-size: clamp(1rem, 1.8vw, 1.4rem); color: #C6D9DE; margin-top: .4rem; }

.display-list { display: flex; flex-direction: column; gap: .75rem; }

.display-row {
  display: grid;
  grid-template-columns: clamp(60px, 6vw, 110px) 1fr clamp(200px, 20vw, 320px);
  gap: 1.2rem;
  align-items: center;
  background: rgba(255, 255, 255, .05);
  border: 1px solid rgba(255, 255, 255, .09);
  border-inline-start: 6px solid var(--brass);
  border-radius: 14px;
  padding: 1rem 1.3rem;
}
.display-row--waiting { border-inline-start-color: #D79A2B; }
.display-row--new { border-inline-start-color: #4A9AC4; }

.display-row__slot {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.6rem, 2.6vw, 2.6rem);
  color: #8FB0B9;
  font-variant-numeric: tabular-nums;
  text-align: center;
}
.display-row__name {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.9rem, 4.4vw, 4rem);
  line-height: 1.15;
  color: #fff;
}
.display-row__meta { font-size: clamp(.95rem, 1.7vw, 1.5rem); color: #A9C4CB; margin-top: .2rem; }
.display-row__state {
  font-size: clamp(1rem, 1.7vw, 1.5rem);
  font-weight: 600;
  text-align: center;
  padding: .5rem .8rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, .08);
  color: #EAF3F5;
}

.display-empty {
  text-align: center;
  padding: 5rem 1rem;
  color: #7E9DA6;
}
.display-empty__title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.6rem, 3vw, 2.4rem);
  color: #C6D9DE;
}

@media (max-width: 767.98px) {
  .display-row { grid-template-columns: 48px 1fr; }
  .display-row__state { grid-column: 1 / -1; }
}

/* ==========================================================================
   المحاكي
   ========================================================================== */

.chat {
  background: #ECE5DD;
  border-radius: var(--radius-lg);
  padding: 1rem;
  height: 460px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: .55rem;
}
.chat__bubble {
  max-width: 82%;
  padding: .6rem .8rem;
  border-radius: 12px;
  font-size: .92rem;
  white-space: pre-wrap;
  line-height: 1.7;
  box-shadow: 0 1px 1px rgba(0,0,0,.08);
  overflow-wrap: anywhere;
}
.chat__bubble--out { background: #DCF8C6; align-self: flex-start; }
.chat__bubble--in  { background: #fff; align-self: flex-end; }
.chat__time { font-size: .68rem; color: #7A8A82; margin-top: .2rem; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: .35rem .8rem; font-size: .87rem; }
.kv dt { color: var(--text-soft); }
.kv dd { margin: 0; font-weight: 600; }

.token-box {
  font-family: ui-monospace, "IBM Plex Mono", monospace;
  background: var(--ink);
  color: #9FE8C4;
  padding: .8rem 1rem;
  border-radius: var(--radius);
  font-size: .85rem;
  word-break: break-all;
  direction: ltr;
  text-align: left;
}

.code-inline {
  font-family: ui-monospace, monospace;
  background: var(--surface-2);
  padding: .1rem .35rem;
  border-radius: 5px;
  font-size: .85em;
  direction: ltr;
  /* يعزل النص اللاتيني عن الجملة العربية، وإلا انتقلت الرموز المحايدة
     مثل _ و / و : إلى الطرف الخطأ من الكلمة */
  unicode-bidi: isolate;
  display: inline-block;
}

/* ترقيم الصفحات */
.pager { display: flex; gap: .35rem; flex-wrap: wrap; align-items: center; }
.pager a, .pager span {
  padding: .35rem .7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: .87rem;
  text-decoration: none;
  color: var(--text);
  background: var(--surface);
}
.pager .is-current { background: var(--ink); color: #fff; border-color: var(--ink); }
.pager .is-disabled { opacity: .45; pointer-events: none; }

/* أدوات مساعدة */
/* حقول تحمل قيماً إنجليزية (روابط، مفاتيح، أرقام) داخل صفحة عربية */
.ltr { direction: ltr; text-align: left; font-family: ui-monospace, monospace; font-size: .87rem; }
select.ltr { font-family: inherit; }

.text-soft { color: var(--text-soft); }
.text-faint { color: var(--text-faint); }
.nums { font-variant-numeric: tabular-nums; direction: ltr; display: inline-block; }
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: 1.1rem;
}
.page-head__title { font-family: var(--font-display); font-weight: 800; font-size: 1.4rem; margin: 0; }
.page-head__sub { font-size: .88rem; color: var(--text-soft); margin: .15rem 0 0; }

.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;
}

@media print {
  .app-nav, .app-header, .btn-action, .filters { display: none !important; }
  .app-main { margin: 0; }
}

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

/* ==========================================================================
   نافذة التأكيد
   ========================================================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(14, 42, 51, .55);
  display: grid;
  place-items: center;
  z-index: 1090;
  padding: 1rem;
  animation: fadeIn .12s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 1.5rem;
  max-width: 460px;
  width: 100%;
  border-top: 5px solid var(--brass);
}

.modal-box__title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.2rem;
  margin: 0 0 .6rem;
  color: var(--ink);
}

.modal-box__body {
  font-size: 1rem;
  line-height: 1.8;
  color: var(--text);
  margin: 0 0 1.3rem;
}

.modal-box__actions {
  display: flex;
  gap: .6rem;
  flex-wrap: wrap;
}
.modal-box__actions .btn-action { flex: 1; min-width: 130px; }

/* ==========================================================================
   مختبر الصوت
   ========================================================================== */

.lab-spoken {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.15rem, 2.2vw, 1.6rem);
  line-height: 2.1;
  color: var(--ink);
  background: var(--brass-soft);
  border: 1px solid #EBD9A9;
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  margin-bottom: .6rem;
  overflow-wrap: anywhere;
}

.engine-row,
.engine-play {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .75rem 0;
  border-bottom: 1px solid var(--line);
}
.engine-row:last-child,
.engine-play:last-child { border-bottom: 0; }

.engine-row__name { font-weight: 600; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.engine-row__note { font-size: .8rem; color: var(--text-soft); margin-top: .15rem; }

/* خيارات صيغة النداء */
.style-option {
  display: flex;
  gap: .7rem;
  align-items: flex-start;
  padding: .85rem .95rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: .6rem;
  cursor: pointer;
  transition: border-color .12s ease, background .12s ease;
}
.style-option:hover { background: var(--surface-2); }
.style-option.is-selected,
.style-option:has(input:checked) {
  border-color: var(--brass);
  background: var(--brass-soft);
}
.style-option input { margin-top: .3rem; flex: none; }
.style-option__name { display: block; font-weight: 600; margin-bottom: .3rem; }
.style-option__sample {
  display: block;
  font-family: var(--font-display);
  font-size: 1.02rem;
  line-height: 1.9;
  color: var(--ink);
  margin-bottom: .3rem;
  overflow-wrap: anywhere;
}
.style-option__note { display: block; font-size: .78rem; color: var(--text-soft); }

/* شبكة مقارنة صيغ النداء */
.variant-row {
  padding: .9rem 0;
  border-bottom: 1px solid var(--line);
}
.variant-row:last-child { border-bottom: 0; }
.variant-row.is-active { background: linear-gradient(90deg, var(--brass-soft), transparent 70%); }

.variant-row__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: .4rem;
}
.variant-row__text {
  font-family: var(--font-display);
  font-size: 1rem;
  line-height: 1.9;
  color: var(--ink);
  margin-bottom: .6rem;
  overflow-wrap: anywhere;
}
.variant-row__actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.variant-row__actions .btn-action { font-size: .85rem; padding: .4rem .8rem; }
