/* Vono AI — component styles: brand, orbs, shell, nav, cards, chat, answers, overlays. */

/* Preference: text scale + reduce-motion override */
:root[data-text-scale="sm"] { font-size: 15px; }
:root[data-text-scale="md"] { font-size: 16px; }
:root[data-text-scale="lg"] { font-size: 18px; }
:root[data-reduce-motion="on"] * { animation: none !important; transition: none !important; }

/* ---- Brand ---- */
.brand-logo { display: inline-flex; align-items: center; gap: 10px; }
.brand-mark { display: block; flex: none; filter: drop-shadow(0 6px 14px rgba(123,92,255,.28)); }
.brand-logo__text { display: inline-flex; flex-direction: column; line-height: 1.05; }
.brand-logo__name { font-weight: 800; font-size: 1.18rem; color: var(--ink); letter-spacing: .2px; }
.brand-name { font-weight: 800; }
.brand-logo__tag { font-size: .72rem; color: var(--muted); font-weight: 600; }

/* ---- Orbs ---- */
.gradient-orb { display: block; }
.orb-bg { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }
.orb-bg__item { position: absolute; }
.orb-loader { display: inline-flex; align-items: center; justify-content: center; }
.orbit-lines { position: absolute; inset: 0; margin: auto; pointer-events: none; }

/* ---- App shell ---- */
/* Viewport-bounded shell (100dvh, with a 100vh fallback) so screens scroll INSIDE .app-scroll — not the window.
   This keeps the chat composer a true persistent footer and the topbar fixed. */
.app-shell { display: flex; height: 100vh; height: 100dvh; overflow: hidden; position: relative; }
.app-main { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; z-index: 1; }
.app-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; scroll-behavior: smooth; }
.screen-slot { min-height: 100%; outline: none; }                 /* normal screens scroll inside .app-scroll */
/* CHAT ROUTE ONLY: the shell content is height-locked so the chat owns its own internal scroller (no page scroll). */
.app-main.is-chat .app-scroll { overflow: hidden; }
.app-main.is-chat .screen-slot { height: 100%; min-height: 0; overflow: hidden; }
@media (prefers-reduced-motion: reduce) {
  .app-scroll, .chat__scroll { scroll-behavior: auto; }
  .scroll-to-bottom { transition: opacity 120ms ease, visibility 120ms ease; }
}

/* ---- Sidebar (desktop) ---- */
.sidebar { display: none; }
@media (min-width: 1024px) {
  .sidebar {
    display: flex; flex-direction: column; gap: 10px; width: var(--sidebar-w); flex: none;
    padding: 22px 16px; position: sticky; top: 0; height: 100dvh;
    background: var(--glass); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
    border-inline-end: 1px solid var(--border); z-index: 2;
  }
}
.sidebar__brand { padding: 6px 8px 14px; flex: none; }
.side-link {
  position: relative; display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border-radius: var(--r-md); color: var(--ink-soft); font-weight: 600; font-size: .98rem;
  transition: background var(--t-base), color var(--t-base);
}
.side-link:hover { background: var(--mist); color: var(--ink); }
.side-link__icon { display: inline-flex; color: var(--muted); transition: color var(--t-base); }
/* lock sits right after the nav icon (the right side in this RTL sidebar) */
.side-link__lock { display: inline-flex; color: var(--muted); opacity: .85; margin-inline-start: -4px; }
.side-link.is-locked .side-link__label { color: var(--muted); }
.side-link__ind { position: absolute; inset-inline-start: 0; top: 50%; transform: translateY(-50%) scaleY(0); width: 4px; height: 60%; border-radius: 4px; background: var(--grad-primary); transition: transform var(--t-base) var(--ease-spring); }
.side-link.is-active { background: rgba(231,214,255,.45); color: var(--ink); }
.side-link.is-active .side-link__icon { color: var(--violet); }
.side-link.is-active .side-link__ind { transform: translateY(-50%) scaleY(1); }
.sidebar__cta { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: var(--r-md); color: #fff; background: var(--grad-violet); font-weight: 700; box-shadow: var(--sh-sm); }
.sidebar__cta .side-link__icon { color: #fff; }

/* ---- Top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: var(--z-nav); display: flex; align-items: center; gap: 14px;
  height: var(--nav-h); padding: 0 clamp(14px, 4vw, 28px); padding-top: var(--safe-top);
  background: var(--glass); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar__title { flex: 1; min-width: 0; font-weight: 700; color: var(--ink); }
.topbar__actions { display: flex; align-items: center; gap: 8px; }
.topbar__avatar { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 50%; background: var(--grad-violet); color: #fff; font-weight: 800; box-shadow: var(--sh-sm); }
@media (min-width: 1024px) { .topbar__brand { display: none; } }

/* ---- Floating menu button (mobile) + bottom-sheet nav ---- */
.fab-nav {
  position: fixed; z-index: var(--z-nav); inset-inline-end: 16px;
  bottom: calc(16px + var(--safe-bottom));
  width: 56px; height: 56px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; background: var(--grad-primary); background-size: 160% 160%;
  box-shadow: var(--sh-glow); transition: transform var(--t-fast) var(--ease-spring), box-shadow var(--t-base);
  overflow: visible;
}
.fab-nav:active { transform: scale(.9); }
.fab-nav:hover { box-shadow: 0 22px 60px rgba(123,92,255,.34), 0 10px 28px rgba(243,77,184,.24); }
.fab-nav__glow { position: absolute; inset: -6px; border-radius: 50%; background: var(--grad-primary); filter: blur(14px); opacity: .45; z-index: -1; }
@media (min-width: 1024px) { .fab-nav { display: none; } }

.sheet-nav__title { font-weight: 800; }
.sheet-nav__list { display: flex; flex-direction: column; gap: 2px; }
.sheet-nav__row { display: flex; align-items: center; gap: 13px; padding: 13px 14px; min-height: 48px; border-radius: var(--r-md); color: var(--ink-soft); font-weight: 700; transition: background var(--t-base), color var(--t-base); }
.sheet-nav__row:hover { background: var(--mist); }
.sheet-nav__icon { display: inline-flex; color: var(--muted); transition: color var(--t-base); }
.sheet-nav__row.is-active { background: var(--grad-violet); color: #fff; }
.sheet-nav__row.is-active .sheet-nav__icon { color: #fff; }
.sheet-nav__dot { margin-inline-start: auto; width: 8px; height: 8px; border-radius: 50%; background: #fff; }
.sheet-nav__sep { height: 1px; background: var(--border); margin: 10px 0; }

/* ---- Bare chrome (splash/onboarding/auth) ---- */
.bare-chrome { position: relative; min-height: 100dvh; display: flex; }
.bare-slot { flex: 1; min-width: 0; }

/* ---- Generic page scaffold ---- */
.page { width: var(--container); margin-inline: auto; padding: clamp(20px, 4vw, 40px) 0 64px; }
.page-wide { width: min(1340px, 94vw); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 26px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.page-sub { color: var(--muted); font-size: var(--fs-sm); margin-top: 4px; }

/* ---- Feature / glass cards ---- */
.feature-card { padding: 22px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--sh-sm); }
.feature-card h3 { font-size: 1.06rem; margin: 14px 0 6px; }
.feature-card p { color: var(--muted); font-size: var(--fs-sm); margin: 0; }
.feature-card--accent { background: linear-gradient(160deg, rgba(231,214,255,.5), rgba(255,255,255,.9)); }

/* ---- Subject card ---- */
.subject-card { position: relative; overflow: hidden; padding: 20px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--sh-sm); }
.subject-card__top { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.subject-card__orb { width: 46px; height: 46px; border-radius: 14px; display: inline-flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; box-shadow: var(--sh-sm); }
.subject-card h3 { margin: 0; font-size: 1.1rem; }
.subject-card__desc { color: var(--muted); font-size: var(--fs-sm); margin: 0 0 14px; }
.subject-card__actions { display: flex; flex-wrap: wrap; gap: 8px; }
.subject-card__progress { height: 7px; border-radius: 999px; background: var(--mist); overflow: hidden; margin: 8px 0 14px; }
.subject-card__progress > i { display: block; height: 100%; border-radius: 999px; background: var(--grad-primary); }

/* ---- Conversation card ---- */
.conv-card { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--sh-sm); transition: background var(--t-base); }
.conv-card:hover { background: var(--mist); }
.conv-card__icon { flex: none; }
.conv-card__body { min-width: 0; flex: 1; }
.conv-card__title { font-weight: 700; font-size: .96rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-card__meta { color: var(--muted); font-size: var(--fs-xs); }

/* ---- Prompt composer ---- */
.composer { display: flex; flex-direction: column; gap: 10px; padding: 14px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--border-strong); box-shadow: var(--sh-md); }
.composer__row { display: flex; align-items: flex-end; gap: 10px; }
.composer textarea { flex: 1; resize: none; border: none; outline: none; background: transparent; font-size: 1.02rem; line-height: 1.6; max-height: 160px; min-height: 28px; color: var(--ink); }
/* No purple focus ring on the message text area when selected — the caret already signals focus. */
.composer textarea:focus, .composer textarea:focus-visible,
.home-composer textarea:focus, .home-composer textarea:focus-visible { box-shadow: none; outline: none; }
.composer__tools { display: flex; align-items: center; gap: 6px; }
.composer__send { width: 46px; height: 46px; border-radius: 50%; background: var(--grad-primary); color: #fff; display: inline-flex; align-items: center; justify-content: center; box-shadow: var(--sh-glow); transition: transform var(--t-fast) var(--ease-spring); }
.composer__send:active { transform: scale(.92); }
.composer__send[disabled] { opacity: .5; }

/* Next-exam card — compact, RTL, server-driven (Asia/Baghdad). Hidden when no upcoming exam. */
.exam-card { width: min(880px, 100%); margin: 10px auto 0; padding-inline: clamp(12px, 4vw, 28px); }
.exam-card[hidden] { display: none; }
.exam-card__body { position: relative; display: flex; flex-direction: column; gap: 4px; padding: 12px 14px;
  background: linear-gradient(135deg, rgba(123,92,255,.10), rgba(162,89,255,.05)); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--sh-md); }
.exam-card__head { display: flex; align-items: center; gap: 6px; color: var(--violet); }
.exam-card__label { color: var(--muted); font-weight: 700; font-size: .82rem; }
.exam-card__subject { font-size: 1.1rem; font-weight: 800; color: var(--ink); }
.exam-card__when { color: var(--ink-soft); font-size: .9rem; }
.exam-card__count { color: var(--violet); font-weight: 700; font-size: .95rem; }
.exam-card__stale { color: var(--coral); font-size: .78rem; }
.exam-card__btn { align-self: flex-start; margin-top: 8px; display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 999px; background: var(--grad-violet); color: #fff; font-weight: 700;
  font-size: .85rem; border: none; box-shadow: var(--sh-glow); transition: transform var(--t-fast) var(--ease-spring); }
.exam-card__btn:active { transform: scale(.95); }
@media (max-width: 520px) { .exam-card__subject { font-size: 1.02rem; } .exam-card__body { padding: 11px 12px; } }

/* ---- Shared chat-history block (lives in the desktop sidebar AND the mobile drawer) ---- */
.chat-history { display: flex; flex-direction: column; min-height: 0; flex: 1; gap: 8px; }
.chat-history__new { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 14px; flex: none;
  border-radius: var(--r-md); background: var(--grad-violet); color: #fff; font-weight: 700; border: none;
  box-shadow: var(--sh-glow); transition: transform var(--t-fast) var(--ease-spring); }
.chat-history__new:active { transform: scale(.97); }
.chat-history__label { flex: none; padding: 2px 8px; font-size: .72rem; font-weight: 800; letter-spacing: .02em; color: var(--muted); }
.chat-history__list { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; min-height: 0; flex: 1; margin-inline: -4px; padding-inline: 4px; }
.chat-history__item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: start; padding: 10px 12px;
  border-radius: var(--r-md); background: transparent; border: none; color: var(--ink-soft); font-size: .92rem; cursor: pointer;
  transition: background var(--t-base), color var(--t-base); }
.chat-history__item:hover { background: var(--mist); color: var(--ink); }
.chat-history__item-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-history__empty { color: var(--muted); font-size: .85rem; padding: 14px 8px; text-align: center; }

/* Desktop sidebar: brand fixed, chat history grows/scrolls, sections + CTA pinned below a divider. */
.sidebar__sections { display: flex; flex-direction: column; gap: 4px; flex: none; padding-top: 8px; margin-top: 2px; border-top: 1px solid var(--border); }
.sidebar__sections .side-link { padding: 10px 14px; font-size: .94rem; }

/* ---- Mobile slide-out sidebar (opened by the top-bar ☰). RTL: slides in from the right (leading edge). ---- */
.chat-drawer { position: fixed; inset: 0; z-index: 60; }
.chat-drawer[hidden] { display: none; }
.chat-drawer__backdrop { position: absolute; inset: 0; background: rgba(15,18,48,.42); opacity: 0; transition: opacity .24s ease; }
.chat-drawer.is-open .chat-drawer__backdrop { opacity: 1; }
.chat-drawer__panel { position: absolute; top: 0; bottom: 0; right: 0; width: min(312px, 88vw);
  display: flex; flex-direction: column; gap: 10px; padding: calc(14px + var(--safe-top, 0px)) 14px calc(14px + var(--safe-bottom, 0px));
  background: var(--surface); border-inline-start: 1px solid var(--border); box-shadow: -14px 0 48px rgba(15,18,48,.20);
  transform: translateX(110%); transition: transform .26s var(--ease-spring); }
.chat-drawer.is-open .chat-drawer__panel { transform: translateX(0); }
.chat-drawer__head { display: flex; align-items: center; justify-content: space-between; flex: none; padding-bottom: 2px; }
.chat-drawer__brand { display: inline-flex; align-items: center; }
.chat-drawer__sections { display: flex; flex-direction: column; gap: 4px; flex: none; padding-top: 8px; border-top: 1px solid var(--border); }
.chat-drawer__sections .side-link { padding: 10px 12px; font-size: .94rem; }
.chat-drawer__cta { flex: none; justify-content: center; }
@media (min-width: 1024px) { .topbar__menu { display: none; } }   /* desktop has the persistent sidebar */

.chat-resumed-note { color: var(--muted); font-size: .85rem; text-align: center; padding: 16px; }
.chip-rail { display: flex; gap: 8px; overflow-x: auto; padding: 2px; scrollbar-width: none; }
.chip-rail::-webkit-scrollbar { display: none; }

/* ---- Chat ---- */
/* Full-height chat: a relative viewport holding an ABSOLUTE scroll area + an ABSOLUTELY-pinned composer.
   .chat__scroll is the ONE scroll owner; its bottom padding == the (measured) composer height so messages clear it. */
.chat.home-screen--chat { height: 100%; min-height: 0; overflow: hidden; }
.chat-viewport { position: relative; width: 100%; height: 100%; min-height: 0; overflow: hidden; }
.chat__scroll { position: absolute; inset: 0; min-height: 0; overflow-x: hidden; overflow-y: auto;
  display: flex; flex-direction: column;
  padding-bottom: calc(var(--composer-height, 118px) + 14px);
  overscroll-behavior-y: contain; touch-action: pan-y; -webkit-overflow-scrolling: touch; }
.chat__stream { flex: 1; display: flex; flex-direction: column; gap: 18px; padding: 18px clamp(12px,4vw,28px) 8px; width: min(880px, 100%); margin-inline: auto; }
.msg { max-width: 86%; }
.msg--student { align-self: flex-start; }
.msg--tutor { align-self: flex-end; width: 100%; max-width: 100%; }
.msg__bubble-student { background: var(--grad-violet); color: #fff; padding: 13px 16px; border-radius: 20px 20px 20px 6px; box-shadow: var(--sh-sm); font-size: var(--fs-sm); }
.msg__role { font-size: var(--fs-xs); color: var(--muted); margin-bottom: 6px; display: flex; align-items: center; gap: 7px; }
/* Composer footer — ABSOLUTELY pinned to the bottom of the chat viewport (never moves, never scrolls away).
   pointer-events:none on the shell lets the gradient pass scroll/clicks through; the composer + button re-enable it. */
.chat-composer-shell { position: absolute; inset-inline: 0; bottom: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; pointer-events: none;
  padding: 10px clamp(10px,3vw,24px) max(12px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg-tint) 66%, transparent); }
.chat-composer-shell .home-composer { pointer-events: auto; }
.chat-composer-shell .chat-beta-notice { pointer-events: none; }
/* Scroll-to-latest — pinned above the composer, kept mounted (visibility via .is-visible). RTL-safe physical centering. */
.scroll-to-bottom { position: absolute; left: 50%; bottom: calc(100% + 10px); transform: translate(-50%, 8px);
  width: 42px; height: 42px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface); color: var(--ink-soft); border: 1px solid var(--border); box-shadow: var(--sh-md);
  opacity: 0; visibility: hidden; pointer-events: none; z-index: 60;
  transition: opacity 150ms ease, transform 150ms ease, visibility 150ms ease; }
.scroll-to-bottom.is-visible { opacity: 1; visibility: visible; pointer-events: auto; transform: translate(-50%, 0); }
.scroll-to-bottom:hover { color: var(--violet); border-color: var(--violet); }
.scroll-to-bottom:focus-visible { outline: 2px solid var(--violet); outline-offset: 2px; }
.chat-bottom-sentinel { height: 1px; width: 100%; pointer-events: none; flex: none; }
.typing { display: inline-flex; gap: 5px; padding: 12px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--sh-sm); }
.typing i { width: 8px; height: 8px; border-radius: 50%; background: var(--purple); animation: typing 1.2s var(--ease-in-out) infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes typing { 0%,60%,100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-4px); } }
@media (prefers-reduced-motion: reduce) { .typing i { animation: none; opacity: .6; } }

/* ---- Answer card ---- */
.answer { border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--sh-md); overflow: hidden; }
.answer__head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); background: linear-gradient(180deg, rgba(231,214,255,.28), transparent); }
.answer__title { font-weight: 800; font-size: 1rem; flex: 1; }
.answer__body { padding: 6px 18px 16px; }
.answer-section { padding: 12px 0; border-bottom: 1px dashed var(--border); }
.answer-section:last-child { border-bottom: 0; }
.answer-section__h { display: flex; align-items: center; gap: 8px; font-weight: 800; color: var(--ink); font-size: .96rem; margin-bottom: 5px; }
.answer-section__h .chip-num { width: 24px; height: 24px; border-radius: 8px; background: var(--chip-bg); color: var(--chip-ink); display: inline-flex; align-items: center; justify-content: center; font-size: .8rem; font-weight: 800; }
.answer-section p { color: var(--ink-soft); font-size: var(--fs-sm); margin: 0; line-height: 1.75; }
.answer-section.is-uncertain { background: rgba(255,138,76,.06); border-radius: 12px; padding-inline: 12px; }
.answer__warn { display: flex; gap: 9px; align-items: flex-start; margin: 12px 18px 16px; padding: 11px 14px; border-radius: 14px; background: rgba(255,138,76,.1); color: #8a3d08; font-size: var(--fs-sm); }
.answer__warn.is-info { background: rgba(123,92,255,.08); color: #4a2f8f; }
.answer__actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 18px 16px; }
.lead-answer { font-size: 1.05rem; font-weight: 700; color: var(--ink); padding: 14px 18px 4px; }

/* Chat: the AI answer reads as full-width text on the page (no white card / bubble). */
.msg--tutor .answer { background: transparent; border: none; box-shadow: none; border-radius: 0; overflow: visible; }
.msg--tutor .answer__head { background: transparent; border-bottom: none; padding: 2px 0 8px; }
.msg--tutor .answer__body { padding: 4px 0; }
.msg--tutor .lead-answer { padding: 10px 0 2px; }
.msg--tutor .answer__warn { margin: 12px 0; }
.msg--tutor .sources { margin: 6px 0; }
.msg--tutor .answer__actions { padding: 4px 0 0; }

/* Inline / block math (native MathML) */
.math { direction: ltr; unicode-bidi: isolate; }
.math math { font-size: 1.08em; }
.math--block { display: block; text-align: center; margin: 10px 0; overflow-x: auto; }
.math--block math { font-size: 1.18em; }
.calc-result .math math { font-weight: 800; }

/* Calculation steps */
.calc-steps { display: flex; flex-direction: column; gap: 10px; }
.calc-step { display: flex; gap: 12px; align-items: flex-start; }
.calc-step__n { flex: none; width: 26px; height: 26px; border-radius: 8px; background: var(--grad-violet); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: .8rem; }
.calc-result { margin-top: 6px; padding: 12px 14px; border-radius: 12px; background: linear-gradient(135deg, rgba(123,92,255,.1), rgba(243,77,184,.08)); font-weight: 800; }

/* Comparison table */
.cmp-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-sm); }
.cmp-table th, .cmp-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: start; vertical-align: top; }
.cmp-table thead th { background: var(--mist); font-weight: 800; }
.cmp-table th:first-child { border-start-start-radius: 12px; } .cmp-table th:last-child { border-start-end-radius: 12px; }

/* Source disclosure */
.sources { margin: 4px 18px 16px; border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.sources__btn { width: 100%; display: flex; align-items: center; gap: 8px; padding: 11px 14px; font-weight: 700; font-size: var(--fs-sm); color: var(--chip-ink); background: rgba(231,214,255,.28); }
.sources__btn .chev { margin-inline-start: auto; transition: transform var(--t-base); }
.sources[open] .chev, .sources.is-open .chev { transform: rotate(180deg); }
.sources__body { padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.source-row { display: flex; gap: 10px; align-items: center; font-size: var(--fs-xs); color: var(--muted); }

/* ---- Curriculum source (compact, collapsed by default in teaching; one line in exam) ---- */
.cur-src { margin: 6px 0 2px; }
.cur-src__btn { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border: 1px solid var(--border);
  border-radius: 999px; background: rgba(231,214,255,.22); color: var(--chip-ink); font-weight: 700; font-size: var(--fs-xs); cursor: pointer; }
.cur-src__btn:hover { background: rgba(231,214,255,.4); }
.cur-src__btn .chev { display: inline-flex; transition: transform var(--t-base); }
.cur-src.is-open .cur-src__btn .chev { transform: rotate(180deg); }
.cur-src__body { margin-top: 6px; display: flex; flex-direction: column; gap: 4px; }
.cur-src__list { display: flex; flex-direction: column; gap: 4px; }
.cur-src__body[hidden], .cur-src__list[hidden] { display: none; }   /* must beat the flex display above so the toggle can actually collapse */
.cur-src__item { font-size: var(--fs-xs); color: var(--muted); line-height: 1.5; }
.cur-src__more { align-self: flex-start; margin-top: 2px; padding: 0; border: 0; background: none; color: var(--brand, #7c3aed); font-size: var(--fs-xs); font-weight: 700; cursor: pointer; }
.cur-src--exam { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: var(--fs-xs); color: var(--muted); }
.cur-src--exam .cur-src__label { font-weight: 700; color: var(--chip-ink); }

/* ---- Skeleton ---- */
.skeleton { background: linear-gradient(100deg, var(--mist) 30%, #fff 50%, var(--mist) 70%); background-size: 200% 100%; border-radius: 12px; animation: skel 1.3s linear infinite; }
@keyframes skel { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }
.skeleton-line { height: 12px; margin: 8px 0; }

/* ---- Empty / error states ---- */
.state { text-align: center; max-width: 460px; margin: 40px auto; padding: 30px 22px; }
.state h2 { font-size: 1.4rem; margin: 18px 0 8px; }
.state p { color: var(--muted); margin: 0 0 18px; }
.state__actions { display: inline-flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* ---- Modal / bottom sheet ---- */
.scrim { position: fixed; inset: 0; background: rgba(15,18,48,.42); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); z-index: var(--z-overlay); display: flex; align-items: center; justify-content: center; padding: 18px; }
.modal { width: min(520px, 100%); background: var(--surface); border-radius: var(--r-xl); box-shadow: var(--sh-lg); border: 1px solid var(--border); overflow: hidden; }
.modal__head { display: flex; align-items: center; gap: 10px; padding: 18px 20px 8px; }
.modal__head h3 { flex: 1; margin: 0; }
.modal__body { padding: 6px 20px 20px; }
.modal__actions { display: flex; gap: 10px; justify-content: flex-end; padding: 0 20px 20px; }
@media (max-width: 600px) {
  .scrim { align-items: flex-end; padding: 0; }
  .modal { width: 100%; border-radius: 24px 24px 0 0; padding-bottom: var(--safe-bottom); }
}

/* ---- Toast ---- */
.toast-host { position: fixed; inset-inline: 0; bottom: calc(84px + var(--safe-bottom)); z-index: var(--z-toast); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 14px; }
@media (min-width: 1024px) { .toast-host { bottom: 20px; align-items: flex-start; padding-inline-start: 24px; } }
.toast { pointer-events: auto; display: inline-flex; align-items: center; gap: 10px; padding: 11px 16px; border-radius: var(--r-pill); background: var(--ink); color: #fff; box-shadow: var(--sh-lg); font-size: var(--fs-sm); max-width: 92vw; }
.toast--success { background: #1E7A4E; } .toast--error { background: #b53a2a; }
.toast__icon { display: inline-flex; }

/* ---- Dev panel ---- */
.dev-panel { position: fixed; inset-inline-end: 14px; bottom: calc(var(--bottomnav-h) + 18px); z-index: 90; width: 280px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-md); box-shadow: var(--sh-lg); padding: 12px; transform: translateY(140%); transition: transform var(--t-base) var(--ease-out); }
.dev-panel.is-open { transform: none; }
.dev-panel__head { display: flex; align-items: center; justify-content: space-between; }
.dev-panel__x { font-size: 1.4rem; line-height: 1; color: var(--muted); }
.dev-panel__note { font-size: var(--fs-xs); color: var(--muted); margin: 6px 0 10px; }
.dev-panel__select { width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--mist); }
@media (min-width: 1024px) { .dev-panel { bottom: 18px; } }

/* ---- Field / form ---- */
.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 14px; }
.field label { font-size: var(--fs-sm); font-weight: 700; color: var(--ink-soft); }
.field input, .field select, .field textarea { padding: 13px 15px; border-radius: var(--r-md); border: 1px solid var(--border-strong); background: var(--surface); font-size: 1rem; transition: border-color var(--t-base), box-shadow var(--t-base); }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--violet); box-shadow: 0 0 0 3px rgba(123,92,255,.18); outline: none; }
.field__hint { font-size: var(--fs-xs); color: var(--muted); }

/* Segmented control */
.segmented { display: inline-flex; gap: 4px; padding: 4px; background: var(--mist); border-radius: var(--r-pill); border: 1px solid var(--border); }
.segmented button { padding: 8px 16px; border-radius: var(--r-pill); font-weight: 700; font-size: var(--fs-sm); color: var(--muted); transition: all var(--t-base); }
.segmented button.is-active { background: var(--surface); color: var(--ink); box-shadow: var(--sh-sm); }

/* Toggle switch */
.switch { position: relative; width: 48px; height: 28px; border-radius: 999px; background: var(--border-strong); transition: background var(--t-base); flex: none; }
.switch[aria-checked="true"] { background: var(--grad-violet); }
.switch::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: var(--sh-sm); transition: transform var(--t-base) var(--ease-spring); }
.switch[aria-checked="true"]::after { transform: translateX(-20px); }
[dir="rtl"] .switch[aria-checked="true"]::after { transform: translateX(-20px); }

/* ---- Mobile density (smaller/denser items; tap targets stay >=44px) ---- */
@media (max-width: 768px) {
  .card-pad { padding: 16px; }
  .feature-card { padding: 16px; }
  .subject-card { padding: 16px; }
  .answer__head { padding: 12px 14px; }
  .answer__body { padding: 4px 14px 12px; }
  .lead-answer { padding: 12px 14px 2px; }
  .answer__warn, .sources { margin-inline: 14px; }
  .answer__actions { padding: 0 14px 14px; }
  .composer { padding: 11px; }
  .q-card { padding: 14px; }
  .conv-card { padding: 12px 13px; }
  .chip { padding: 8px 13px; min-height: 38px; }
  .btn { padding: 11px 20px; min-height: 44px; }     /* keep >=44px hit area */
  .icon-btn { width: 42px; height: 42px; }
  .icon-tile { width: 40px; height: 40px; }
  .section-title { margin: 18px 0 10px; }
  .section-title h2 { font-size: 1.12rem; }
  .feature-card h3 { font-size: 1rem; }
  .topbar { height: 60px; gap: 10px; padding-inline: 14px; }
  .topbar__avatar { width: 36px; height: 36px; }
}

/* Progress ring + bar */
.ring { transform: rotate(-90deg); }
.ring__bg { stroke: var(--mist); } .ring__fg { stroke: url(#ringgrad); stroke-linecap: round; }
.progress-bar { height: 10px; border-radius: 999px; background: var(--mist); overflow: hidden; }
.progress-bar > i { display: block; height: 100%; background: var(--grad-primary); border-radius: 999px; transition: width var(--t-slow) var(--ease-out); }

/* ===========================================================================
 * GPT-5.5 chat answer: markdown rendering + controls + beta notice
 * =========================================================================== */
.md { color: var(--ink, #1a1c22); line-height: 1.75; font-size: var(--fs-sm, .98rem); }
.md-streaming { white-space: pre-wrap; word-break: break-word; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md-p { margin: .55em 0; }
.md-h { margin: .9em 0 .4em; font-weight: 700; line-height: 1.4; }
h2.md-h { font-size: 1.18em; } h3.md-h { font-size: 1.08em; } h4.md-h, h5.md-h { font-size: 1em; }
.md-ul, .md-ol { margin: .5em 0; padding-inline-start: 1.5em; }
.md-ul li, .md-ol li { margin: .28em 0; }
.md-quote { margin: .6em 0; padding: .4em .9em; border-inline-start: 3px solid var(--border-strong, #c9cdd6);
  color: var(--ink-soft, #4a4f5a); background: var(--mist, #f4f5f8); border-radius: 6px; }
.md-code { font-family: ui-monospace, "Cascadia Code", Menlo, monospace; font-size: .92em;
  background: var(--mist, #f1f2f5); padding: .08em .35em; border-radius: 5px; direction: ltr; unicode-bidi: bidi-override; display: inline-block; }
.md-pre { margin: .6em 0; padding: .8em 1em; overflow-x: auto; background: #11151c; color: #e6edf3;
  border-radius: var(--r-md, 10px); direction: ltr; }
.md-pre code { font-family: ui-monospace, Menlo, monospace; font-size: .9em; white-space: pre; }

.chat-actions { display: flex; gap: .5rem; margin-top: .7rem; flex-wrap: wrap; }
.chat-act { display: inline-flex; align-items: center; gap: .35rem; font: inherit; font-size: var(--fs-xs, .8rem);
  color: var(--muted, #6b7280); background: var(--surface, #fff); border: 1px solid var(--border, #e3e6ec);
  border-radius: 999px; padding: .35rem .8rem; cursor: pointer; transition: .15s ease; }
.chat-act:hover { color: var(--ink, #1a1c22); border-color: var(--border-strong, #c9cdd6); }
.chat-act.is-done { color: #15803d; border-color: #86efac; }
.chat-act--ghost { background: transparent; }
/* answer footer: source + «متابعة» + copy actions */
.ai-foot { display: flex; flex-direction: column; gap: .35rem; }
.chat-continue { align-self: flex-start; font-weight: 700; color: var(--chip-ink, #5b21b6); border-color: var(--border-strong, #c9cdd6);
  background: rgba(231,214,255,.28); }
.chat-continue:hover { background: rgba(231,214,255,.5); color: var(--chip-ink, #5b21b6); }
.chat-continue.is-loading { opacity: .6; pointer-events: none; }
.chat-continue .chev, .chat-continue svg { transition: transform var(--t-base, .15s); }
.chat-fail { color: #b42318; font-size: var(--fs-sm, .95rem); }
/* wrong-answer report (under an answer) */
.chat-report { margin-top: .5rem; }
.chat-report-btn { color: var(--muted, #8b90a0); }
.chat-report-btn:hover { color: #b42318; border-color: #fca5a5; }
.chat-report-panel { margin-top: .5rem; padding: .7rem .8rem; border: 1px solid var(--border, #e3e6ec); border-radius: .7rem;
  background: var(--surface-2, #f7f8fa); display: flex; flex-direction: column; gap: .6rem; }
.chat-report-reasons { display: flex; flex-wrap: wrap; gap: .4rem; }
.chat-report-chip { font: inherit; font-size: var(--fs-xs, .8rem); padding: .3rem .6rem; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border-strong, #c9cdd6); background: var(--surface, #fff); color: var(--ink, #1a1c22); }
.chat-report-chip.is-on { background: var(--chip-bg, #ede9fe); border-color: var(--chip-ink, #5b21b6); color: var(--chip-ink, #5b21b6); font-weight: 700; }
.chat-report-note { font: inherit; font-size: var(--fs-sm, .9rem); padding: .5rem .6rem; border-radius: .6rem;
  border: 1px solid var(--border, #e3e6ec); resize: vertical; width: 100%; box-sizing: border-box; }
.chat-report-row { display: flex; gap: .5rem; align-items: center; }
.chat-report-send { font: inherit; font-size: var(--fs-xs, .8rem); font-weight: 700; padding: .4rem .9rem; border-radius: .6rem;
  cursor: pointer; border: 0; background: var(--chip-ink, #5b21b6); color: #fff; }
.chat-report-send:disabled { opacity: .6; pointer-events: none; }
.chat-report-done { display: inline-flex; align-items: center; gap: .35rem; color: #15803d; font-size: var(--fs-xs, .8rem); }
.chat-beta-notice { text-align: center; font-size: var(--fs-xs, .76rem); color: var(--muted, #8b90a0);
  padding: .4rem .8rem .2rem; line-height: 1.5; }
.chat-prep { color: var(--muted, #8b90a0); font-size: var(--fs-sm, .95rem); font-style: italic; }

/* ---- math (KaTeX) + tables + rules in GPT-5.5 answers ---- */
.md-math--inline { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.md-math--block { direction: ltr; text-align: center; margin: .7em 0; overflow-x: auto; overflow-y: hidden; padding: .15em 0; }
.md-math--raw { font-family: ui-monospace, "Cascadia Code", Menlo, monospace; background: var(--mist, #f1f2f5);
  padding: .04em .3em; border-radius: 4px; font-size: .94em; }
.md-math--block.md-math--raw { display: block; padding: .5em .7em; white-space: pre-wrap; text-align: start; }
.md .katex { font-size: 1.06em; }
.md .katex-display { margin: .4em 0; }
.md-hr { border: 0; border-top: 1px solid var(--border, #e3e6ec); margin: 1em 0; }
.md-table-wrap { overflow-x: auto; margin: .7em 0; -webkit-overflow-scrolling: touch; }
.md-table { border-collapse: collapse; width: 100%; font-size: var(--fs-sm, .95rem); }
.md-table th, .md-table td { border: 1px solid var(--border, #e3e6ec); padding: .45em .7em; text-align: start; vertical-align: top; }
.md-table thead th { background: var(--mist, #f4f5f8); font-weight: 700; }
.md-table tbody tr:nth-child(even) { background: color-mix(in srgb, var(--mist, #f4f5f8) 45%, transparent); }

/* ---- model selector dropdown (Tutor 1 / Tutor 1.5) ---- */
.model-select { position: relative; display: inline-flex; }
.home-composer__chip.is-model { cursor: pointer; font: inherit; gap: .2rem; align-items: center;
  font-size: var(--fs-xs, .72rem); padding: .2rem .45rem; color: #000; }
.home-composer__chip.is-model svg { color: #000; }
.model-menu { position: absolute; bottom: calc(100% + 6px); inset-inline-start: 0; min-width: 138px;
  background: var(--surface, #fff); border: 1px solid var(--border, #e3e6ec); border-radius: var(--r-md, 10px);
  box-shadow: var(--sh-lg, 0 12px 28px rgba(20,20,40,.16)); padding: .22rem; z-index: 40; }
.model-menu[hidden] { display: none; }
.model-menu__item { display: flex; align-items: center; gap: .4rem; width: 100%; font: inherit;
  font-size: var(--fs-xs, .78rem); text-align: start; background: transparent; border: 0; border-radius: 7px;
  padding: .38rem .45rem; cursor: pointer; color: #000; }
.model-menu__item svg { color: #000; }
.model-menu__item + .model-menu__item { margin-top: .1rem; }
.model-menu__item:hover:not(.is-disabled) { background: var(--mist, #f4f5f8); }
.model-menu__item.is-active { font-weight: 700; }
.model-menu__item.is-disabled { opacity: .55; cursor: not-allowed; }
.model-menu__soon { margin-inline-start: auto; font-size: .64rem; color: var(--muted, #8b90a0);
  background: var(--mist, #f1f2f5); border-radius: 999px; padding: .08rem .4rem; }
.composer-attach { color: var(--muted, #8b90a0); }
.composer-attach:hover { color: var(--ink, #1a1c22); }
.composer-plus { width: 40px; height: 40px; min-width: 40px; padding: 0; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; }

/* ---- image attachment (solve from photo) ---- */
.composer-attach-preview { display: flex; align-items: center; gap: .55rem; margin-bottom: .5rem;
  padding: .4rem .55rem; background: var(--mist, #f4f5f8); border: 1px solid var(--border, #e3e6ec); border-radius: 12px; }
.composer-attach-preview[hidden] { display: none; }
.composer-attach-thumb { width: 38px; height: 38px; object-fit: cover; border-radius: 8px; flex: none; }
.composer-attach-name { font-size: var(--fs-xs, .78rem); color: var(--muted, #6b7280); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.composer-attach-x { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px;
  border: 0; background: transparent; color: var(--muted, #8b90a0); border-radius: 50%; cursor: pointer; flex: none; }
.composer-attach-x:hover { background: var(--surface, #fff); color: var(--ink, #1a1c22); }
.msg__image { display: block; max-width: min(280px, 70vw); max-height: 320px; width: auto; height: auto;
  border-radius: 12px; margin-bottom: .4rem; }
.msg__text { white-space: pre-wrap; word-break: break-word; }
