/* ============================================================================
   مجلس — نظام تصميم لوحة إدارة شاشات المساجد
   لوحة ألوان: ورق عاجي + أخضر مجلس عميق + نحاس.
   الخطوط: Sakkal Majalla للعناوين، Segoe UI للواجهة، Amiri لنص الآيات.
   ========================================================================== */

:root {
  --paper: #f6f1e6;
  --paper-2: #fcf9f2;
  --paper-3: #efe7d6;
  --ink: #152019;
  --ink-2: #3b4a42;
  --ink-3: #6d7a72;
  --line: #e1d7c2;
  --line-strong: #cfc1a1;
  --green: #0e4638;
  --green-2: #0a3329;
  --green-3: #12604a;
  --brass: #a07c2c;
  --brass-2: #c9a25a;
  --danger: #8f2a2a;
  --ok: #1c6b4c;
  --stage: #08201a;
  --font-ui: "Segoe UI", Tahoma, "Noto Sans Arabic", system-ui, sans-serif;
  --font-display: "Sakkal Majalla", "Traditional Arabic", "Amiri", "Segoe UI", serif;
  --font-quran: "Amiri", "Sakkal Majalla", "Traditional Arabic", serif;
  --r: 4px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 700; line-height: 1.25; margin: 0; }
p { margin: 0; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }

.boot { min-height: 100dvh; display: grid; place-items: center; }
.boot__line { color: var(--ink-3); font-size: 14px; letter-spacing: .01em; }

/* ---------------------------------------------------------------- التخطيط */
.shell {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  min-height: 100dvh;
}

.sidebar {
  background: var(--green-2);
  color: #efe6d2;
  position: sticky;
  top: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  border-inline-start: 1px solid var(--green-2);
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 20px 18px 16px;
  border-bottom: 1px solid rgba(201, 162, 90, .18);
}

.brandmark {
  width: 34px;
  height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  border: 1px solid rgba(201, 162, 90, .45);
  border-radius: 3px;
  background: rgba(201, 162, 90, .08);
}

.sidebar__title { font-family: var(--font-display); font-size: 21px; line-height: 1; }
.sidebar__sub { font-size: 11.5px; color: rgba(239, 230, 210, .62); margin-top: 4px; }

.sidebar__nav { flex: 1; overflow-y: auto; padding: 12px 10px 18px; }

.nav-group { margin-bottom: 14px; }
.nav-group__label {
  font-size: 11.5px;
  color: rgba(239, 230, 210, .45);
  padding: 6px 10px 6px;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-radius: 3px;
  color: rgba(239, 230, 210, .82);
  text-decoration: none;
  font-size: 14px;
  border-inline-start: 3px solid transparent;
}

.nav a:hover { background: rgba(255, 255, 255, .05); color: #fff; }
.nav a[aria-current="page"] {
  background: rgba(201, 162, 90, .13);
  border-inline-start-color: var(--brass-2);
  color: #fdf6e3;
}

.nav svg { flex: none; opacity: .8; }
.nav a[aria-current="page"] svg { opacity: 1; }

.sidebar__foot {
  padding: 12px 14px 16px;
  border-top: 1px solid rgba(201, 162, 90, .18);
  font-size: 12px;
  color: rgba(239, 230, 210, .6);
  display: grid;
  gap: 10px;
}

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 24px;
  background: rgba(246, 241, 230, .94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.topbar__title { font-size: 14px; color: var(--ink-2); }
.topbar__spacer { flex: 1; }

.context-select {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-3);
}

.context-select select {
  width: auto;
  padding: 5px 9px;
  font-size: 13px;
  background: var(--paper-2);
  border-radius: 3px;
}

.content {
  padding: 26px 28px 72px;
  width: 100%;
  max-width: 1280px;
}

/* ------------------------------------------------------------- ترويسة صفحة */
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.page-head h1 { font-size: 30px; letter-spacing: 0; }

.page-head__sub {
  margin-top: 4px;
  font-size: 13.5px;
  color: var(--ink-3);
  max-width: 62ch;
}

.page-head__actions { display: flex; gap: 8px; flex-wrap: wrap; }

.frieze {
  height: 10px;
  margin: 0 0 22px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='10'%3E%3Cpath d='M0 5 6 1 12 5 18 1 24 5' fill='none' stroke='%23cfc1a1' stroke-width='1.2'/%3E%3C/svg%3E");
  background-repeat: repeat-x;
  opacity: .8;
}

/* ------------------------------------------------------------------ أزرار */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line-strong);
  background: var(--paper-2);
  color: var(--ink);
  padding: 8px 13px;
  border-radius: 3px;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  transition: background-color .12s ease, border-color .12s ease;
}

.btn:hover { background: var(--paper-3); }

.btn--primary {
  background: var(--green);
  border-color: var(--green);
  color: #f8f2e2;
}

.btn--primary:hover { background: var(--green-3); border-color: var(--green-3); }

.btn--ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn--ghost:hover { background: rgba(21, 32, 25, .05); }

.btn--danger { color: var(--danger); border-color: #e2c8c3; background: #fdf5f3; }
.btn--danger:hover { background: #f8e9e6; }

.btn--sm { padding: 5px 10px; font-size: 13px; }
.btn--block { width: 100%; }

.btn[disabled] { opacity: .5; cursor: not-allowed; }

.iconbtn {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
}

.iconbtn:hover { background: rgba(21, 32, 25, .06); border-color: var(--line); }

/* --------------------------------------------------------------- شرائح حالة */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  font-size: 12px;
  background: var(--paper);
  white-space: nowrap;
}

.chip--ok { color: var(--ok); border-color: #bed7c8; background: #eef6f1; }
.chip--off { color: #86392b; border-color: #e3c9c1; background: #fbf0ed; }
.chip--warn { color: var(--warn, #94660f); border-color: #e6d4a9; background: #fdf6e4; }
.chip--muted { color: var(--ink-3); }

.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }

/* ----------------------------------------------------------------- بطاقات */
.panel {
  border: 1px solid var(--line);
  background: var(--paper-2);
  border-radius: var(--r);
  overflow: hidden;
}

.panel + .panel { margin-top: 18px; }

.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(to bottom, rgba(201, 162, 90, .05), transparent);
}

.panel__head h2 { font-size: 16.5px; }
.panel__hint { font-size: 12.5px; color: var(--ink-3); }
.panel__body { padding: 18px; }
.panel__body--flush { padding: 0; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.split { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 18px; align-items: start; }

/* ------------------------------------------------------------------ إحصاء */
.stat-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--paper-2);
  margin-bottom: 18px;
}

.stat { padding: 15px 17px; border-inline-start: 1px solid var(--line); }
.stat:first-child { border-inline-start: 0; }
.stat b { display: block; font-family: var(--font-display); font-size: 29px; line-height: 1.15; }
.stat span { font-size: 12.5px; color: var(--ink-3); }
.stat em { font-style: normal; font-size: 12px; color: var(--ok); }

/* ------------------------------------------------------------------- جداول */
table { width: 100%; border-collapse: collapse; font-size: 14px; }

thead th {
  text-align: start;
  font-weight: 500;
  font-size: 12.5px;
  color: var(--ink-3);
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  background: rgba(239, 231, 214, .35);
}

tbody td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(160, 124, 44, .045); }

.cell-main { font-weight: 600; }
.cell-sub { font-size: 12.5px; color: var(--ink-3); }
.num { font-variant-numeric: tabular-nums; }
.actions { display: flex; gap: 4px; justify-content: flex-end; }

/* ------------------------------------------------------------------- نماذج */
.field { display: grid; gap: 6px; margin-bottom: 13px; }
.field label { font-size: 13px; color: var(--ink-2); }
.field .help { font-size: 12px; color: var(--ink-3); }

input, select, textarea {
  width: 100%;
  background: var(--paper-2);
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  padding: 8px 10px;
  font-size: 14px;
}

textarea { resize: vertical; min-height: 76px; line-height: 1.7; }
input[type="checkbox"] { width: auto; accent-color: var(--green); }

.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }

.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.inline-form .field { flex: 1 1 180px; margin-bottom: 0; }

.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.switch input { appearance: none; width: 34px; height: 19px; border-radius: 999px; background: #d8cfb9; border: 1px solid var(--line-strong); position: relative; cursor: pointer; }
.switch input::after { content: ""; position: absolute; inset-inline-start: 2px; top: 2px; width: 13px; height: 13px; border-radius: 50%; background: #fff; transition: inset-inline-start .14s ease; }
.switch input:checked { background: var(--green); border-color: var(--green); }
.switch input:checked::after { inset-inline-start: 16px; }

/* ------------------------------------------------------------------ تنبيهات */
.notice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 11px 14px;
  border: 1px solid #e6d4a9;
  border-inline-start: 3px solid var(--brass);
  background: #fdf7e9;
  border-radius: 3px;
  font-size: 13px;
  color: #6b5420;
}

.notice--info { border-color: #cfdcd4; border-inline-start-color: var(--green-3); background: #f1f7f3; color: #2c4a3d; }

.empty { padding: 34px 20px; text-align: center; color: var(--ink-3); font-size: 14px; }
.empty strong { display: block; color: var(--ink-2); font-size: 15px; margin-bottom: 4px; }

/* ------------------------------------------------------------------ تسجيل */
.auth { min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1.02fr) minmax(0, .98fr); }

.auth__brand {
  position: relative;
  background: var(--green-2);
  color: #f2e9d5;
  padding: 46px 44px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}

.auth__brand::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='72' height='72'%3E%3Cg fill='none' stroke='%23c9a25a' stroke-width='1'%3E%3Cpath d='M36 6 42 30 66 36 42 42 36 66 30 42 6 36 30 30Z'/%3E%3Ccircle cx='36' cy='36' r='2.4'/%3E%3C/g%3E%3C/svg%3E");
  opacity: .1;
  pointer-events: none;
}

.auth__brand > * { position: relative; }

.auth__eyebrow { font-size: 12.5px; color: var(--brass-2); }

.auth__headline {
  font-family: var(--font-display);
  font-size: clamp(34px, 4.4vw, 54px);
  line-height: 1.18;
  margin: 14px 0 16px;
  max-width: 15ch;
}

.auth__lede { color: rgba(242, 233, 213, .74); font-size: 14.5px; max-width: 42ch; }

.auth__facts { list-style: none; padding: 0; margin: 26px 0 0; display: grid; gap: 11px; font-size: 13.5px; color: rgba(242, 233, 213, .8); }
.auth__facts li { display: flex; gap: 9px; align-items: baseline; }
.auth__facts b { color: var(--brass-2); font-weight: 600; font-variant-numeric: tabular-nums; }

.auth__form { padding: 46px 44px; display: flex; flex-direction: column; justify-content: center; background: var(--paper-2); }
.auth__form-inner { width: 100%; max-width: 380px; margin-inline: auto; }
.auth__form h1 { font-size: 26px; margin-bottom: 6px; }
.auth__form p.lede { color: var(--ink-3); font-size: 13.5px; margin-bottom: 22px; }

.role-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.role-pick label {
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  padding: 9px 11px;
  font-size: 13px;
  cursor: pointer;
  background: var(--paper-2);
  display: grid;
  gap: 2px;
}
.role-pick label span { font-size: 11.5px; color: var(--ink-3); }
.role-pick input { position: absolute; opacity: 0; pointer-events: none; }
.role-pick input:checked + label, .role-pick label:has(input:checked) {
  border-color: var(--green);
  background: #f1f6f2;
  box-shadow: inset 0 0 0 1px var(--green);
}

.demo-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: #7a5c1c;
  background: #fdf5e2;
  border: 1px solid #e7d5a9;
  border-radius: 999px;
  padding: 2px 9px;
}

/* ------------------------------------------------------------------ الشاشة */
.stage-wrap { background: var(--green-2); padding: 14px; border-radius: var(--r); }

.stage-shell {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--stage);
  border-radius: 2px;
  overflow: hidden;
  border: 1px solid rgba(201, 162, 90, .22);
}

.stage-shell:fullscreen { border: 0; border-radius: 0; aspect-ratio: auto; height: 100%; }

.scene {
  position: absolute;
  inset: 0;
  container-type: inline-size;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 1.6cqi;
  padding: 2.8cqi 3.2cqi;
  color: #f4ead2;
  background-color: var(--stage);
  overflow: hidden;
}

.scene::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cg fill='none' stroke='%23c9a25a' stroke-width='1'%3E%3Cpath d='M60 8 70 50 112 60 70 70 60 112 50 70 8 60 50 50Z'/%3E%3C/g%3E%3C/svg%3E");
  opacity: .07;
  pointer-events: none;
}

.scene[data-bg="emerald"] { background: radial-gradient(120% 100% at 50% 0%, #0d3a2e 0%, #07211b 62%, #051813 100%); }
.scene[data-bg="night"] { background: radial-gradient(110% 90% at 50% 10%, #14232e 0%, #0a1116 70%); }
.scene[data-bg="sand"] { background: radial-gradient(110% 90% at 50% 0%, #2e2a1e 0%, #1a1710 75%); }
.scene[data-bg="ink"] { background: #0a0f0d; }

.scene__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 2cqi;
  padding-bottom: 1.2cqi;
  border-bottom: 1px solid rgba(201, 162, 90, .4);
  position: relative;
  z-index: 1;
}

.scene__council { font-family: var(--font-display); font-size: 3.4cqi; color: #f0e2c2; }
.scene__meta { font-size: 2cqi; color: rgba(240, 226, 194, .66); white-space: nowrap; }

.scene__mid {
  position: relative;
  z-index: 1;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 1.6cqi;
  min-height: 0;
  text-align: center;
}

.scene__surah { font-size: 2.1cqi; color: var(--brass-2); }

.scene__verse {
  font-family: var(--font-quran);
  font-size: 5cqi;
  line-height: 1.95;
  color: #f7eccd;
  max-width: 88%;
  white-space: pre-line;
  text-wrap: balance;
}

.scene__namecard {
  width: min(70%, 78cqi);
  border: 1px solid rgba(201, 162, 90, .5);
  background: rgba(201, 162, 90, .07);
  padding: 2.4cqi 3cqi;
  display: grid;
  gap: .8cqi;
  justify-items: center;
}

.scene__name { font-family: var(--font-display); font-size: 6.4cqi; color: #f3d999; line-height: 1.25; }
.scene__relation { font-size: 2.3cqi; color: rgba(243, 236, 214, .75); }
.scene__dua { font-family: var(--font-quran); font-size: 2.5cqi; color: rgba(243, 217, 153, .9); line-height: 1.9; }

.scene__clock { font-family: var(--font-display); font-size: 7cqi; line-height: 1; color: #f5e8c6; }
.scene__clock small { display: block; font-family: var(--font-ui); font-size: 1.8cqi; color: rgba(243, 236, 214, .6); }

.scene__foot {
  position: relative;
  z-index: 1;
  border-top: 1px solid rgba(201, 162, 90, .4);
  padding-top: 1.2cqi;
  display: flex;
  justify-content: space-between;
  gap: 2cqi;
  align-items: center;
  font-size: 2cqi;
  color: rgba(243, 236, 214, .78);
}

.scene__ticker { overflow: hidden; flex: 1; }
.scene__ticker span {
  display: inline-block;
  white-space: nowrap;
  animation: ticker 26s linear infinite;
  padding-inline-end: 8cqi;
}

@keyframes ticker {
  from { transform: translateX(100%); }
  to { transform: translateX(-100%); }
}

.scene--empty .scene__mid { color: rgba(243, 236, 214, .5); font-size: 2.6cqi; }

/* ------------------------------------------------------------------ المصمم */
.designer { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 18px; align-items: start; }

.block-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }

.block-item {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--paper-2);
  font-size: 13px;
}

.block-item[data-selected="true"] { border-color: var(--green); box-shadow: inset 0 0 0 1px var(--green); background: #f2f7f3; }
.block-item__handle { color: var(--ink-3); cursor: grab; font-size: 13px; }
.block-item__ops { display: flex; gap: 2px; }

.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 14px; }

.media-item { border: 1px solid var(--line); background: var(--paper-2); border-radius: 3px; overflow: hidden; display: grid; }

.media-thumb {
  aspect-ratio: 16 / 9;
  display: grid;
  place-items: center;
  color: #f6efdc;
  position: relative;
  font-size: 12px;
}

.media-thumb svg { opacity: .85; }
.media-meta { padding: 8px 10px; display: grid; gap: 2px; }
.media-meta b { font-size: 13px; font-weight: 600; }
.media-meta span { font-size: 11.5px; color: var(--ink-3); }

/* ------------------------------------------------------------------ التوست */
.toast-host {
  position: fixed;
  inset-block-end: 20px;
  inset-inline-start: 20px;
  display: grid;
  gap: 8px;
  z-index: 90;
}

.toast {
  background: var(--green-2);
  color: #f6efdc;
  border: 1px solid rgba(201, 162, 90, .4);
  border-radius: 3px;
  padding: 9px 14px;
  font-size: 13.5px;
  box-shadow: 0 6px 20px rgba(10, 30, 24, .25);
  animation: toast-in .16s ease-out;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* -------------------------------------------------------------- الاستجابة */
@media (max-width: 1080px) {
  .designer { grid-template-columns: minmax(0, 1fr); }
  .split, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .auth { grid-template-columns: minmax(0, 1fr); }
  .auth__brand { display: none; }
}

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; }
  .sidebar__nav { display: flex; gap: 6px; overflow-x: auto; padding: 10px; }
  .nav-group { margin: 0; display: flex; gap: 4px; }
  .nav-group__label { display: none; }
  .nav a { white-space: nowrap; padding: 7px 10px; border-inline-start: 0; border-bottom: 3px solid transparent; }
  .nav a[aria-current="page"] { border-inline-start-color: transparent; border-bottom-color: var(--brass-2); }
  .sidebar__foot { display: none; }
  .content { padding: 20px 16px 56px; }
  .stat-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat:nth-child(3) { border-inline-start: 0; }
  .stat:nth-child(n + 3) { border-top: 1px solid var(--line); }
  .grid-2, .form-row { grid-template-columns: minmax(0, 1fr); }
  .page-head h1 { font-size: 25px; }
  .topbar { padding: 8px 14px; flex-wrap: wrap; }
}

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

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