/* سند: تابع's structure (floating bars, one headline per page), night by default.
   Solid surfaces, glass only on the floating bars and sheets.
   Red (hue 352) is for actions only; teal = success, amber = waiting. */
@import url('../fonts/alexandria.css');
@import url('../fonts/plex-arabic.css');

:root {
  --font: 'IBM Plex Sans Arabic', system-ui, sans-serif;
  --display: 'Alexandria', 'IBM Plex Sans Arabic', sans-serif;
  --red: #D2475A; --red-deep: #B23A4B; --red-soft: rgba(210,71,90,.10); --red-line: rgba(210,71,90,.45);
  --ok: #2B7A76; --warn: #9A6418;
  --page: #F1F3F6; --surface: #FFFFFF; --surface-2: #F4F6F9; --surface-3: #FFFFFF;
  --ink: #141A21; --ink-2: #3A4552; --mute: #6B7582;
  --line: rgba(20,30,45,.08); --line-2: rgba(20,30,45,.15); --sunken: rgba(20,30,45,.05);
  --glass: rgba(255,255,255,.80); --blur: blur(20px) saturate(160%);
  --shadow: 0 1px 2px rgba(20,30,45,.05), 0 3px 12px rgba(20,30,45,.05);
  --shadow-float: 0 10px 34px rgba(20,30,45,.14);
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --r-sm: 10px; --r: 14px; --r-lg: 20px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --page: #0E1217; --surface: #151B22; --surface-2: #1B222B; --surface-3: #262F3A;
  --ink: #E7EBF0; --ink-2: #B4BEC9; --mute: #808A96;
  --line: rgba(160,180,205,.09); --line-2: rgba(160,180,205,.16); --sunken: rgba(160,180,205,.07);
  --glass: rgba(21,27,34,.86);
  --shadow: none; --shadow-float: 0 12px 40px rgba(0,0,0,.5);
  --red-soft: rgba(210,71,90,.14); --ok: #5FB3AE; --warn: #E0A54A;
  color-scheme: dark;
}

/* base */
* { box-sizing: border-box; }
html, body { margin: 0; }
body { min-height: 100dvh; background: var(--page); color: var(--ink); font: 15px/1.6 var(--font); -webkit-tap-highlight-color: transparent; }
body.noscroll { overflow: hidden; }
h1, h2, h3 { margin: 0; letter-spacing: 0; }
h1 { font: 700 22px/1.4 var(--display); }
h2 { font-size: 17px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 600; }
p { margin: 0; }
svg { flex: none; }
:focus-visible { outline: 2px solid var(--red-line); outline-offset: 2px; }

/* helpers */
.muted { color: var(--mute); }
.small { font-size: 13px; }
.meta { font-size: 12px; color: var(--mute); }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: var(--s2); }
.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: var(--s3); }
.mt-2 { margin-top: var(--s2); } .mt-3 { margin-top: var(--s3); } .mt-4 { margin-top: var(--s4); }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }
#app { position: relative; }

/* logo: the red horse, no ring */
.logo { width: 28px; height: 28px; background: url(../logo.svg) center / contain no-repeat; flex: none; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; padding: 0 16px; border-radius: var(--r);
  border: 1px solid var(--line-2); background: var(--surface-2); color: var(--ink); font: 600 14px var(--font); cursor: pointer;
  transition: transform .12s, background .15s, border-color .15s; white-space: nowrap; }
.btn:hover { border-color: var(--mute); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.btn-red { background: var(--red); border-color: var(--red); color: #fff; }
.btn-red:hover { background: var(--red-deep); border-color: var(--red-deep); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--mute); }
.btn-ghost:hover { background: var(--sunken); border-color: transparent; color: var(--ink); }
.btn-danger { color: var(--red); }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 13px; border-radius: var(--r-sm); }
.btn-block { width: 100%; }
.btn svg { width: 16px; height: 16px; }
.btn .spin { width: 16px; height: 16px; margin: 0; border-width: 2px; border-color: currentColor; border-top-color: transparent; }
.icon-btn { width: 40px; height: 40px; display: inline-grid; place-items: center; border-radius: 50%; border: 0; background: transparent;
  color: var(--ink-2); cursor: pointer; flex: none; transition: background .15s; }
.icon-btn:hover { background: var(--sunken); color: var(--ink); }
.icon-btn.danger:hover { color: var(--red); }
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn.busy svg { animation: spin .8s linear infinite; }

/* fields */
.input { width: 100%; min-height: 46px; padding: 10px 14px; border-radius: var(--r); border: 1px solid var(--line-2); background: var(--surface-2);
  color: var(--ink); font: 15px var(--font); outline: none; transition: border-color .15s, box-shadow .15s; }
.input:focus { border-color: var(--red-line); box-shadow: 0 0 0 3px var(--red-soft); }
.input::placeholder { color: var(--mute); }
textarea.input { min-height: 92px; resize: vertical; }
select.input { appearance: none; cursor: pointer; padding-left: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23808A96' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: left 14px center; background-size: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; color: var(--ink-2); }
.seg { display: inline-flex; gap: 2px; padding: 3px; border-radius: 99px; background: var(--sunken); }
.seg button { border: 0; background: none; color: var(--mute); font: 600 13px var(--font); padding: 7px 14px; border-radius: 99px; cursor: pointer; transition: background .15s, color .15s; }
.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--surface-3); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.18); }
.seg-full { display: flex; width: 100%; }
.seg-full button { flex: 1; }

/* switch */
.switch { position: relative; width: 50px; height: 30px; border-radius: 99px; border: 0; padding: 0; background: var(--line-2); cursor: pointer; flex: none; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; right: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .2s; }
.switch[aria-checked="true"] { background: var(--red); }
.switch[aria-checked="true"]::after { transform: translateX(-20px); }
.switch:disabled { opacity: .5; }

/* shell: floating top bar + floating tab bar (تابع) */
.top-wrap { position: sticky; top: 0; z-index: 20; padding: 10px 12px 8px; background: linear-gradient(var(--page) 70%, transparent); }
.top { display: flex; align-items: center; gap: var(--s2); padding: 6px; padding-inline-start: 12px; border-radius: var(--r-lg);
  background: var(--glass); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur); border: 1px solid var(--line); box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: var(--s2); }
.brand b { font: 800 20px/1 var(--display); }
.cls { font-size: 12px; color: var(--mute); padding: 3px 10px; border-radius: 99px; background: var(--sunken); }
main { max-width: 860px; margin: 0 auto; padding: var(--s3) var(--s4) 120px; }
.tabs { position: fixed; z-index: 20; bottom: calc(10px + env(safe-area-inset-bottom)); inset-inline: 12px; max-width: 520px; margin: 0 auto;
  display: flex; gap: 2px; padding: 6px; border-radius: 24px; background: var(--glass); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  border: 1px solid var(--line); box-shadow: var(--shadow-float); }
.tab { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 2px; border: 0; border-radius: 18px;
  background: none; color: var(--mute); font: 600 11px var(--font); cursor: pointer; white-space: nowrap; transition: background .15s, color .15s; }
.tab:hover { color: var(--ink); }
.tab svg { width: 21px; height: 21px; }
.tab.on { color: var(--red); background: var(--sunken); }

/* page headline: one sentence that says what matters now */
.head { margin: var(--s2) 2px var(--s4); }
.head p { color: var(--mute); margin-top: 2px; font-size: 13px; }
.head.row { align-items: center; }
.section-title { display: flex; align-items: center; gap: var(--s2); margin: var(--s5) 2px var(--s3); }
.section-title h2 { flex: 1; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--s4); box-shadow: var(--shadow); }
.card.flush { padding: 0; overflow: hidden; }
.card.list { padding: 0 var(--s4); }
.grid { display: grid; gap: var(--s3); grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid-2 { display: grid; gap: var(--s3); grid-template-columns: 1fr 1fr; }
.tile { display: flex; flex-direction: column; gap: var(--s1); text-align: start; cursor: pointer; color: inherit; font: inherit; width: 100%;
  transition: border-color .15s, transform .12s; }
.tile:hover { border-color: var(--line-2); }
.tile:active { transform: scale(.98); }
.tile .row svg { width: 16px; height: 16px; color: var(--mute); }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 99px; font-size: 12px; font-weight: 500; color: var(--mute);
  background: var(--sunken); white-space: nowrap; }
.chip svg { width: 13px; height: 13px; }
.chip.new { color: var(--ink); background: var(--surface-3); border: 1px solid var(--line-2); font-weight: 600; }
.chip.red { color: var(--red); background: var(--red-soft); }
.chip.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 13%, transparent); }
.chip.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 13%, transparent); }
.list-item { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item.btnlike { width: 100%; border-inline: 0; border-top: 0; background: none; color: inherit; font: inherit; text-align: start; cursor: pointer; }
.names { display: flex; flex-wrap: wrap; gap: var(--s2); }
.name { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: var(--r-sm); font-size: 14px; background: var(--surface); border: 1px solid var(--line); }
.name svg { width: 14px; height: 14px; color: var(--warn); }
.empty { display: flex; flex-direction: column; align-items: center; gap: var(--s2); padding: var(--s5) var(--s3); color: var(--mute); text-align: center; font-size: 14px; }
.empty svg { width: 26px; height: 26px; opacity: .6; }
.stat { font: 700 28px/1.15 var(--display); }

/* login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: var(--s5) var(--s4); }
.login-box { width: 100%; max-width: 380px; border-radius: 24px; padding: var(--s6) var(--s5); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
.login-box .brand { margin-bottom: var(--s6); }
.login-box h1 { font-size: 26px; margin-bottom: var(--s4); }
.login-box .seg-full { margin-bottom: var(--s5); padding: 4px; }
.login-box .seg-full button { padding: 9px 10px; font-size: 14px; }
.login-box .seg-full button.on { color: var(--red); }
.login-box form { gap: var(--s4); }
.pw { position: relative; }
.pw .input { padding-left: 46px; }
.eye { position: absolute; left: 5px; top: 50%; transform: translateY(-50%); width: 36px; height: 36px; border: 0; background: none; border-radius: 50%;
  color: var(--mute); cursor: pointer; display: grid; place-items: center; }
.eye svg { width: 18px; height: 18px; }
.login-box .btn-red { min-height: 48px; font-size: 15px; }
.err { color: var(--red); font-size: 13px; }
.err:empty { display: none; }

/* gate */
.count-big { font: 800 56px/1 var(--display); }
.bar { height: 8px; border-radius: 99px; background: var(--sunken); overflow: hidden; margin-top: var(--s3); }
.bar i { display: block; height: 100%; background: var(--ok); border-radius: 99px; transition: width .4s; }
.cand { display: flex; align-items: center; gap: var(--s3); width: 100%; padding: var(--s3) var(--s4); border-radius: var(--r); border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: 500 15px var(--font); cursor: pointer; text-align: start; transition: border-color .15s; }
.cand:hover:not(:disabled) { border-color: var(--line-2); }
.cand.mine { border-color: var(--red-line); }
.cand:disabled { cursor: default; }
.cand .n { font-weight: 700; font-size: 17px; min-width: 22px; text-align: center; }
.meter { height: 4px; border-radius: 99px; background: var(--sunken); overflow: hidden; margin-top: 6px; }
.meter i { display: block; height: 100%; background: var(--mute); }
.cand.mine .meter i { background: var(--red); }

/* solutions */
.sol { display: flex; flex-direction: column; gap: var(--s1); }
.sol h3 { font-size: 16px; }
.sol .acts { display: flex; gap: var(--s2); margin-top: var(--s3); }

/* madrasati numbers: open is the headline, the rest is small */
.mstat { display: flex; align-items: center; gap: var(--s4); }
.mstat .big { display: flex; align-items: baseline; gap: 6px; }
.mstat .rest { display: flex; gap: var(--s4); font-size: 13px; color: var(--mute); }
.mstat .rest b { color: var(--ink); font-weight: 600; }
.mstat .rest b.zero { color: var(--mute); font-weight: 400; }

/* chat */
.chat { display: flex; flex-direction: column; height: min(62vh, 600px); }
.chat.full { height: calc(100dvh - 385px); min-height: 300px; }
.chat-msgs { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding: 4px 2px 8px; }
.msg { max-width: 80%; padding: 8px 13px; border-radius: 18px; background: var(--surface-2); white-space: pre-wrap; word-break: break-word; align-self: flex-start; }
.msg.me { align-self: flex-end; background: var(--red); color: #fff; }
.msg small { display: block; font-size: 11px; opacity: .65; margin-top: 2px; }
.msg a { color: inherit; display: inline-flex; align-items: center; gap: 4px; }
.msg a svg { width: 15px; height: 15px; }
.chat-form { display: flex; align-items: flex-end; gap: 6px; padding-top: var(--s3); border-top: 1px solid var(--line); }
.chat-form textarea { min-height: 44px; height: 44px; max-height: 140px; border-radius: 22px; padding: 10px 16px; resize: none; overflow-y: auto; }
.send { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--red); color: #fff; display: grid; place-items: center; cursor: pointer; flex: none; }
.send:hover { background: var(--red-deep); }
.send svg { width: 18px; height: 18px; transform: scaleX(-1); }
.conv { display: flex; align-items: center; gap: var(--s3); width: 100%; padding: var(--s3) var(--s4); border: 0; border-bottom: 1px solid var(--line);
  background: none; color: var(--ink); font: inherit; cursor: pointer; text-align: start; }
.conv:hover { background: var(--sunken); }
.conv.on { background: var(--sunken); box-shadow: inset -3px 0 0 var(--red); }
.split { display: grid; gap: var(--s3); }
@media (min-width: 820px) { .split { grid-template-columns: 280px 1fr; } }

/* dev: grouped settings inside a card */
.group { margin-top: var(--s4); padding-top: var(--s4); border-top: 1px solid var(--line); }
.group > h3 { font-size: 13px; color: var(--mute); font-weight: 600; margin-bottom: var(--s2); }
.person { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) 0; border-bottom: 1px solid var(--line); }
.person:last-child { border-bottom: 0; }
.person .who { flex: 1; min-width: 0; }
.person .who b { font-weight: 600; }
.person .acts { display: flex; gap: 2px; }
details summary { cursor: pointer; color: var(--mute); font-size: 13px; padding: 6px 0; }
.class-head { all: unset; display: flex; gap: var(--s3); align-items: center; width: 100%; cursor: pointer; }
.class-head .stat { font-size: 20px; }

/* sheet */
.sheet-bg { position: fixed; inset: 0; z-index: 50; background: rgba(8,10,12,.45); display: grid; place-items: end center; animation: fade .2s; }
.sheet { width: 100%; max-width: 540px; max-height: 92dvh; overflow-y: auto; background: var(--surface); border-radius: 24px 24px 0 0; border: 1px solid var(--line);
  padding: var(--s4) var(--s4) calc(var(--s4) + env(safe-area-inset-bottom)); box-shadow: var(--shadow-float); animation: up .25s cubic-bezier(.2,.8,.2,1); }
.sheet::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 99px; background: var(--line-2); margin: -4px auto var(--s3); }
@media (min-width: 820px) {
  .sheet-bg { place-items: center; }
  .sheet { border-radius: 24px; animation: pop .2s ease-out; }
  .sheet::before { display: none; }
}
.sheet-head { display: flex; align-items: center; gap: var(--s2); margin-bottom: var(--s4); }
.file-row { display: flex; align-items: center; gap: var(--s2); padding: 6px 10px; border-radius: var(--r-sm); background: var(--surface-2); font-size: 14px; }
.file-row svg { width: 16px; height: 16px; color: var(--mute); }
.file-row .icon-btn { width: 30px; height: 30px; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(100%); } }
@keyframes pop { from { opacity: 0; transform: scale(.96); } }

.toast { position: fixed; z-index: 90; bottom: calc(96px + env(safe-area-inset-bottom)); inset-inline: 16px; margin: 0 auto; max-width: 380px; width: fit-content;
  padding: 10px 18px; border-radius: 99px; background: var(--surface-3); border: 1px solid var(--line-2); color: var(--ink); font-weight: 600; text-align: center;
  box-shadow: var(--shadow-float); animation: up .25s cubic-bezier(.2,.8,.2,1); }
.toast.bad { color: var(--red); }

/* pdf viewer */
.pdfv { position: fixed; inset: 0; z-index: 60; background: var(--page); display: flex; flex-direction: column; animation: fade .15s; }
.pdfv-bar { display: flex; align-items: center; gap: var(--s2); margin: 10px 12px 0; padding: 6px; border-radius: var(--r-lg);
  background: var(--glass); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur); border: 1px solid var(--line); }
.pdfv-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.pdfv-pages { flex: 1; overflow: auto; display: flex; flex-direction: column; align-items: center; gap: var(--s3); padding: var(--s3); }
.pdfv-page { background: #fff; flex: none; border-radius: 6px; overflow: hidden; box-shadow: var(--shadow); }
.pdfv-page canvas { width: 100%; height: 100%; display: block; }
.pdfv-frame { width: 100%; height: 100%; border: 0; background: #fff; }
.spin { width: 26px; height: 26px; border: 3px solid var(--line-2); border-top-color: var(--red); border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto; }
.spin.inline { width: 20px; height: 20px; border-width: 2px; margin: 4px 0; }
@keyframes spin { to { transform: rotate(360deg); } }

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

/* مدرستي: copied from تابع's layout */
.mad-sec { margin-top: 36px; }
.mad-sec h2 { margin-bottom: var(--s3); }
.mad-figures { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--s3); }
.mad-figures > div { display: flex; flex-direction: column; gap: 4px; padding: 16px 18px; border-radius: var(--r-lg); background: var(--surface); }
.mad-figures > .danger { background: var(--red-soft); }
.mad-figures b { font-size: 26px; font-weight: 600; line-height: 1.2; }
.mad-figures small { color: var(--mute); font-size: 13px; }
.mad-figures .danger b { color: var(--red); }
.mad-dot { display: inline-block; width: 4px; height: 4px; border-radius: 50%; background: var(--mute); vertical-align: middle; margin: 0 8px; }
.mad-kv { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.mad-kv span { color: var(--mute); }
.mad-raw summary { cursor: pointer; color: var(--red); font-weight: 600; padding: 8px 0; }
.mad-list { border-radius: var(--r-lg); background: var(--surface); overflow: hidden; margin-top: var(--s2); }
.mad-li { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.mad-li:last-child { border-bottom: 0; }
.mad-title { font-weight: 600; }
.mad-note { padding: 14px 16px; margin-bottom: var(--s4); border-radius: var(--r-lg); background: var(--surface); border-inline-start: 3px solid var(--warn); }
.mad-note b { display: block; margin-bottom: 4px; }
.mad-note p { margin: 0; color: var(--ink-2); font-size: 14px; line-height: 1.7; }
.t-warn { color: var(--warn); }
@media (max-width: 560px) { .mad-figures { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s2); } }
