@font-face {
  font-family: Tajawal;
  src: url('/fonts/tajawal-400.woff2') format('woff2');
  font-display: swap;
  font-weight: 400;
}

@font-face {
  font-family: Tajawal;
  src: url('/fonts/tajawal-700.woff2') format('woff2');
  font-display: swap;
  font-weight: 700;
}

@font-face {
  font-family: Tajawal;
  src: url('/fonts/tajawal-800.woff2') format('woff2');
  font-display: swap;
  font-weight: 800;
}

:root {
  color-scheme: light;
  font-family: Tajawal, 'Geeza Pro', Tahoma, sans-serif;
  --ink: #162b3d;
  --muted: #526373;
  --accent: #1e4872;
  --accent-deep: #12334f;
  --wash: #f8f4ee;
  --blue-soft: #dce8f3;
  --sand-soft: #e7ddd4;
  --line: #dbe0e5;
  --control-border: #77899b;
  --white: #fffdfa;
  color: var(--ink);
  background: var(--wash);
  font-size: 17px;
  line-height: 1.6;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
button, textarea { font: inherit; }
button, a, textarea { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
h1, h2, h3, h4, p { margin: 0; }
svg { display: block; }
button svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.topbar { background: var(--white); border-block-end: 1px solid var(--line); }
.topbar-inner, .page { width: min(100% - 56px, 1200px); margin-inline: auto; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 74px; }
.brand { display: flex; gap: 10px; align-items: center; color: var(--accent); font-weight: 800; font-size: 1.09rem; line-height: 1.25; text-decoration: none; }
.brand img { flex: none; }
.brand-copy { display: grid; gap: 2px; justify-items: start; }
.brand-copy bdi { color: var(--muted); font: 600 .62rem/1.3 system-ui, sans-serif; letter-spacing: .09em; }
.button { min-height: 44px; padding: 7px 14px; display: inline-flex; gap: 7px; align-items: center; justify-content: center; border: 1px solid transparent; border-radius: 12px; cursor: pointer; font-weight: 700; line-height: 1.25; white-space: nowrap; }
.action-icon { flex: none; object-fit: contain; }
.reset { flex: none; }
.secondary { background: var(--white); color: var(--accent); border-color: var(--control-border); }
.secondary:hover { background: var(--blue-soft); }
.primary { background: var(--accent); color: var(--white); padding-inline: 17px; box-shadow: 0 5px 14px #12334f22; }
.primary:hover { background: var(--accent-deep); }
.button:disabled { opacity: .58; cursor: wait; }
.page { padding-block: 24px 36px; }
.intro {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(155px, 25%);
  align-items: center;
  gap: 15px;
  min-height: 198px;
  padding: 14px clamp(20px, 4vw, 52px);
  margin-block-end: 20px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: radial-gradient(ellipse at 12% 55%, #dce8f3 0, transparent 52%), var(--white);
}
h1 { color: var(--accent); font-size: clamp(1.85rem, 3.55vw, 2.9rem); font-weight: 800; line-height: 1.2; }
.engine { color: var(--muted); font-size: .86rem; margin-block-start: 10px; }
.engine bdi { display: inline-block; margin-inline-start: 7px; }
.engine[data-ready] { color: var(--accent); }
.engine[data-ready]::before { content: ''; display: inline-block; width: 7px; height: 7px; margin-inline-end: 6px; border-radius: 50%; background: var(--accent); }
.companion { display: grid; justify-items: center; gap: 2px; margin: 0; }
.companion img { display: block; width: min(168px, 100%); height: auto; }
.companion figcaption { color: var(--accent-deep); font-weight: 800; line-height: 1.2; }
.intro.has-phone-entry { grid-template-columns: minmax(0, 1fr) minmax(95px, 20%) auto; }
.phone-entry { justify-self: center; }
.phone-entry a { display: grid; justify-items: center; gap: 4px; color: var(--accent); font-size: .86rem; font-weight: 700; text-align: center; }
.phone-entry img { display: block; width: 128px; height: auto; border: 1px solid var(--line); background: var(--white); }
@media (max-width: 620px) {
  .intro.has-phone-entry { grid-template-columns: minmax(0, 1fr) minmax(80px, 28%); }
  .phone-entry { grid-column: 1 / -1; justify-self: stretch; border-block-start: 1px solid var(--line); padding-block-start: 9px; }
  .phone-entry a { display: flex; align-items: center; justify-content: center; gap: 10px; }
  .phone-entry img { width: 88px; }
}
.workspace { display: grid; grid-template-columns: minmax(0, 1.38fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.pane { min-width: 0; background: var(--white); border: 1px solid var(--line); border-radius: 19px; box-shadow: 0 10px 24px #12334f0c; }
.pane-head { display: flex; align-items: center; gap: 10px; padding: 13px 20px; border-block-end: 1px solid var(--line); }
.pane-head h2 { color: var(--accent-deep); font-size: 1.13rem; line-height: 1.3; white-space: nowrap; }
.pane-icon { display: block; flex: none; object-fit: contain; }
.thread { block-size: clamp(214px, 28svh, 380px); overflow: auto; padding: 20px; scrollbar-color: #a6b7c9 transparent; overflow-wrap: anywhere; }
.welcome { padding: 18px; background: var(--wash); border-radius: 12px; border: 1px solid var(--sand-soft); color: var(--muted); }
.welcome p:first-child { font-weight: 700; color: var(--ink); }
.welcome p + p { margin-block-start: 4px; }
.message { margin-block-end: 15px; }
.message:last-child { margin-block-end: 0; }
.teacher-message { margin-inline-end: 12%; padding: 11px 14px; border-radius: 13px 4px 13px 13px; background: var(--accent); color: var(--white); white-space: pre-wrap; }
.assistant-message { background: #f2f6fa; border: 1px solid var(--line); border-radius: 4px 13px 13px 13px; padding: 13px 15px 15px; }
.message-label { font-weight: 700; font-size: .83rem; margin-block-end: 3px; }
.teacher-message .message-label { color: var(--blue-soft); }
.assistant-byline { display: flex; align-items: center; gap: 8px; }
.assistant-byline .message-label { color: var(--accent); font-size: 1rem; margin: 0; }
.assistant-avatar { flex: none; display: block; border-radius: 50%; object-fit: cover; background: var(--blue-soft); }
.assistant-message h4 { font-size: 1rem; margin-block: 12px 1px; }
.assistant-message ol { margin: 2px 0 0; padding-inline-start: 23px; }
.assistant-message li { padding-inline-start: 3px; margin-block: 7px; }
.say { color: var(--accent); display: block; font-weight: 700; }
.monitor { margin-block-start: 5px; padding: 10px 12px; border-inline-start: 3px solid #6385a9; background: var(--white); border-radius: 7px; }
.monitor p + p { margin-block-start: 5px; }
.monitor ul { margin: 3px 0 6px; padding-inline-start: 21px; }
.monitor li { margin-block: 2px; }
.inline-preview { margin-block-start: 10px; }
.compose { border-block-start: 1px solid var(--line); padding: 16px 20px 18px; }
.compose label { font-weight: 700; display: block; margin-block-end: 5px; }
.compose textarea { resize: vertical; width: 100%; min-height: 94px; padding: 10px 12px; color: var(--ink); background: #fffdf9; border: 1px solid var(--control-border); border-radius: 10px; line-height: 1.55; }
.compose textarea::placeholder { color: var(--muted); }
.compose-footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-block-start: 7px; }
.compose-footer small { font-size: .78rem; line-height: 1.4; color: var(--muted); max-width: 45ch; }
.request-status { display: flex; gap: 5px; align-items: center; margin-inline-start: auto; padding: 4px 7px; border-radius: 9px; background: var(--blue-soft); color: var(--accent-deep); font-size: .81rem; line-height: 1.15; }
.error { padding: 8px 10px; border-radius: 8px; margin-block-end: 9px; background: #fff0eb; color: #7d3023; border: 1px solid #e7beb2; }
.material-empty { min-height: 260px; padding: 28px 24px 34px; display: grid; align-content: center; justify-items: center; gap: 9px; text-align: center; color: var(--muted); }
.material-empty img { width: min(132px, 62%); height: auto; }
.material-toolbar { padding: 15px 17px 0; }
.material-toolbar h3 { font-size: 1.09rem; overflow-wrap: anywhere; }
.material-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-block-start: 8px; }
.material-buttons .button { font-size: .87rem; }
.cards { padding: 16px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.cards[data-single] { grid-template-columns: minmax(0, 1fr); }
.card { min-width: 0; overflow: hidden; margin: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--white); break-inside: avoid; }
.card svg { width: 100%; height: auto; }
.card figcaption { color: var(--ink); background: var(--white); text-align: center; font-weight: 700; padding: 7px; overflow-wrap: anywhere; }
.card:only-child { width: min(100%, 420px); margin-inline: auto; }
dialog { width: min(960px, calc(100% - 24px)); max-height: calc(100% - 24px); padding: 0; border: 1px solid var(--line); border-radius: 16px; }
dialog::backdrop { background: #162b3d; }
.display-head { position: sticky; top: 0; padding: 10px 16px; border-block-end: 1px solid var(--line); background: var(--white); z-index: 1; }
.presentation { gap: 12px; }

@media (max-width: 850px) {
  .topbar-inner, .page { width: min(100% - 32px, 680px); }
  .page { padding-block-start: 18px; }
  .intro { min-height: 155px; }
  .companion img { width: min(124px, 100%); }
  .workspace { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .thread { block-size: clamp(200px, 27svh, 330px); }
}

@media (max-width: 480px) {
  .topbar-inner, .page { width: calc(100% - 24px); }
  .topbar-inner { min-height: 66px; gap: 6px; }
  .brand { font-size: .95rem; gap: 7px; }
  .brand img { width: 31px; height: 39px; }
  .reset { font-size: .86rem; padding-inline: 8px; }
  .reset .action-icon { width: 20px; height: 20px; }
  .intro { grid-template-columns: minmax(0, 1fr) minmax(80px, 29%); min-height: 137px; gap: 9px; padding: 13px; margin-block-end: 14px; }
  h1 { font-size: clamp(1.34rem, 6.05vw, 1.74rem); }
  .engine { font-size: .76rem; margin-block-start: 6px; line-height: 1.4; }
  .engine bdi { display: block; margin: 2px 0 0; }
  .companion figcaption { font-size: .88rem; }
  .pane-head { padding: 10px 12px; gap: 7px; }
  .pane-head h2 { font-size: 1.02rem; }
  .pane-icon { width: 32px; height: 32px; }
  .request-status { font-size: .75rem; padding-inline: 5px; }
  .thread { block-size: clamp(204px, 25svh, 260px); }
  .thread, .compose { padding: 13px; }
  .compose-footer { align-items: start; }
  .compose-footer small { font-size: .75rem; }
  .material-empty { min-height: 200px; }
  .cards { padding: 11px; gap: 7px; }
  .presentation { grid-template-columns: minmax(0, 1fr); }
}

@page { size: A4 portrait; margin: 13mm; }
@media print {
  :root { background: white; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .topbar, .intro, .conversation, .pane-head, .material-empty, .material-toolbar, .display-head { display: none !important; }
  .page { width: 100%; padding: 0; }
  body:has(#student-display[open]) .page { display: none; }
  #student-display[open] { position: static; width: 100%; max-width: none; max-height: none; margin: 0; border: 0; overflow: visible; }
  #student-display::backdrop { display: none; }
  .workspace { display: block; }
  .materials { border: 0; border-radius: 0; box-shadow: none; }
  #student-cards, #display-cards { padding: 0; gap: 5mm; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #student-cards[data-single], #display-cards[data-single] { grid-template-columns: minmax(0, 1fr); }
  .card { border: 0.3mm solid #b8c3ce; border-radius: 2mm; }
}
