:root {
  --bg: #f6f7f9;
  --fg: #17202a;
  --muted: #5b6672;
  --card: #ffffff;
  --line: #d9dee5;
  --brand: #0b5c8e;
  --brand-light: #e6f0f8;
  --brand-fg: #ffffff;
  --user: #0b5c8e;
  --focus: #ffbf47;
  --shadow: 0 10px 40px -10px rgba(0, 0, 0, .10);
  --composer: rgba(255, 255, 255, .72);
  font-family: Inter, "Noto Sans Arabic", system-ui, "Segoe UI", Tahoma, Arial, sans-serif;
  font-size: 16px;
}

html.dark {
  --bg: #0f1419;
  --fg: #e8edf2;
  --muted: #9aa6b2;
  --card: #1a2129;
  --line: #2a333d;
  --brand: #4aa3df;
  --brand-light: #17354b;
  --brand-fg: #06131c;
  --user: #17658f;
  --composer: rgba(15, 23, 42, .72);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background-color .3s ease, color .3s ease;
}
body.embed { min-width: 280px; }
button, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.ambient-bg { position: fixed; inset: 0; z-index: -1; pointer-events: none; overflow: hidden; }
.ambient-bg::before, .ambient-bg::after { content: ""; position: absolute; border-radius: 999px; filter: blur(1px); pointer-events: none; }
.ambient-bg::before { width: 52rem; height: 30rem; top: -18rem; inset-inline-start: -12rem; background: rgba(14, 116, 144, .09); }
.ambient-bg::after { width: 40rem; height: 26rem; top: -14rem; inset-inline-end: -10rem; background: rgba(30, 64, 175, .07); }
html.dark .ambient-bg { background: radial-gradient(1200px 700px at 15% -10%, rgba(14,116,144,.26), transparent 62%), radial-gradient(900px 540px at 85% 0%, rgba(30,64,175,.20), transparent 58%), linear-gradient(180deg, #0b1226, #060b16); }

.institutional-header {
  position: sticky;
  top: 0;
  z-index: 50;
  flex-shrink: 0;
  width: 100%;
  background: color-mix(in srgb, var(--card) 90%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 75%, transparent);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.header-inner { width: min(1152px, 100%); height: 4.15rem; margin: 0 auto; padding: 0 1rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.brand-lockup { min-width: 0; display: flex; align-items: center; gap: .75rem; }
.brand-mark { width: 2.7rem; height: 2.7rem; flex: 0 0 auto; padding: .25rem; overflow: hidden; display: inline-flex; align-items: center; justify-content: center; background: rgba(255,255,255,.95); border: 1px solid var(--line); border-radius: .85rem; box-shadow: inset 0 1px 2px rgba(0,0,0,.06); }
.brand-mark img { width: 100%; height: 100%; object-fit: contain; }
.brand-copy { min-width: 0; display: flex; flex-direction: column; }
.brand-copy h1 { overflow: hidden; margin: 0; font-size: .98rem; font-weight: 750; line-height: 1.25; text-overflow: ellipsis; white-space: nowrap; }
.brand-copy span { overflow: hidden; margin-top: .16rem; color: var(--muted); font-size: .72rem; font-weight: 600; letter-spacing: .035em; text-overflow: ellipsis; white-space: nowrap; }
.header-actions { display: flex; align-items: center; gap: .25rem; flex-shrink: 0; }
.header-button, .new-session { min-height: 2.35rem; display: inline-flex; align-items: center; justify-content: center; gap: .45rem; padding: .45rem .65rem; border: 1px solid transparent; border-radius: .75rem; color: var(--muted); background: transparent; font-size: .76rem; font-weight: 700; transition: background-color .2s, color .2s, border-color .2s; }
.header-button:hover { color: var(--fg); background: color-mix(in srgb, var(--line) 45%, transparent); }
.header-button.icon-only { width: 2.35rem; padding: .45rem; }
.new-session { color: var(--brand-fg); background: var(--brand); box-shadow: 0 4px 12px rgba(11,92,142,.18); }
.new-session:hover { filter: brightness(1.08); }
.plus-icon { font-size: 1.35rem; font-weight: 400; line-height: .75; }
.lang-icon { font-size: .93rem; font-weight: 700; color: var(--brand); }
.info-icon { width: 1.05rem; height: 1.05rem; display: inline-flex; align-items: center; justify-content: center; border: 1.5px solid currentColor; border-radius: 50%; font-family: Georgia, serif; font-size: .75rem; font-weight: 700; line-height: 1; }
.icon-only::before, .close-button::before, .modal-close::before, .send-button::before, .stop-button::before { display: block; font-size: 1.1rem; line-height: 1; }
#theme::before { content: "☾"; }
html.dark #theme::before { content: "☀"; color: #f4c95d; }
.close-button::before, .modal-close::before { content: "×"; font-size: 1.45rem; font-weight: 300; }

.chat-scroll-area { min-height: 0; flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 1.25rem 1rem 12rem; scroll-behavior: smooth; -webkit-overflow-scrolling: touch; scrollbar-gutter: stable; }
.welcome, .msg { width: min(100%, 64rem); margin-inline: auto; }
.welcome { display: flex; flex-direction: column; align-items: center; padding: 1.5rem .25rem 2rem; text-align: center; }
.assistant-avatar { position: relative; display: inline-flex; align-items: center; justify-content: center; overflow: hidden; flex: 0 0 auto; background: #fff; border: 1px solid var(--line); box-shadow: 0 18px 36px -18px rgba(15,118,169,.28); }
.assistant-avatar img { position: relative; z-index: 1; width: 100%; height: 100%; object-fit: cover; }
.assistant-avatar-lg { width: 5.5rem; height: 5.5rem; margin-bottom: 1rem; border-radius: 1.7rem; }
.assistant-avatar-sm { width: 2rem; height: 2rem; border-radius: .7rem; }
.welcome h2 { margin: 0 0 .55rem; color: var(--fg); font-size: clamp(1.65rem, 4vw, 2.75rem); font-weight: 800; letter-spacing: -.025em; }
.welcome > p { max-width: 42rem; margin: 0 0 2.4rem; color: var(--muted); font-size: clamp(.82rem, 1.5vw, 1.05rem); line-height: 1.8; }
.starter-grid { width: 100%; max-width: 48rem; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; text-align: start; }
.starter-card { min-height: 5rem; display: flex; align-items: center; gap: .9rem; padding: 1rem; color: var(--fg); background: color-mix(in srgb, var(--card) 92%, transparent); border: 1px solid color-mix(in srgb, var(--line) 75%, transparent); border-radius: 1rem; box-shadow: var(--shadow); text-align: start; transition: transform .2s, border-color .2s, background-color .2s; }
.starter-card:hover { transform: translateY(-3px); border-color: color-mix(in srgb, var(--brand) 45%, var(--line)); background: var(--card); }
.starter-card-icon { width: 2.65rem; height: 2.65rem; flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); background: color-mix(in srgb, var(--line) 35%, transparent); border-radius: .75rem; font-size: 1.15rem; }
.starter-card:hover .starter-card-icon { color: var(--brand-fg); background: var(--brand); }
.starter-card span:last-child { font-size: .86rem; font-weight: 700; line-height: 1.45; }

.msg { display: flex; flex-direction: column; gap: .45rem; margin-bottom: 1.5rem; animation: message-in .25s ease-out both; }
.msg.user { align-items: flex-end; }
.msg.bot { align-items: flex-start; }
.msg-meta { display: flex; align-items: center; gap: .5rem; padding-inline: .25rem; color: var(--muted); font-size: .68rem; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
.msg.user .msg-meta { flex-direction: row-reverse; }
.msg-meta .user-avatar { width: 2rem; height: 2rem; display: inline-flex; align-items: center; justify-content: center; color: var(--brand-fg); background: var(--fg); border-radius: .7rem; font-size: 1rem; }
.message-row { width: 100%; display: flex; }
.msg.user .message-row { justify-content: flex-end; }
.message-bubble { position: relative; min-width: 3.5rem; overflow-wrap: anywhere; max-width: min(86%, 48rem); padding: .85rem 1rem; line-height: 1.75; border: 1px solid var(--line); border-radius: 1rem; box-shadow: var(--shadow); }
.msg.user .message-bubble { color: #fff; background: var(--user); border-color: transparent; border-start-end-radius: .35rem; }
.msg.bot .message-bubble { color: var(--fg); background: color-mix(in srgb, var(--card) 92%, transparent); border-start-start-radius: .35rem; backdrop-filter: blur(12px); }
.message-bubble p { margin: 0 0 .55rem; }
.message-bubble p:last-child { margin-bottom: 0; }
.message-bubble ul { margin: .25rem 0 .55rem; padding-inline-start: 1.25rem; }
.message-bubble li { margin: .25rem 0; }
.msg.user .message-bubble p { color: #fff; }
.msg.problem .message-bubble { color: #7a4100; background: #fff4e5; border-color: #f0b37e; }
html.dark .msg.problem .message-bubble { color: #ffd9a8; background: #3a2a12; border-color: #8a5a22; }
.problem-copy { font-weight: 650; }
.retry { margin-top: .8rem; padding: .45rem .85rem; color: inherit; background: color-mix(in srgb, var(--card) 70%, transparent); border: 1px solid currentColor; border-radius: .7rem; font-size: .84rem; font-weight: 700; }
.retry:hover { background: color-mix(in srgb, var(--card) 95%, transparent); }
.typing { display: inline-flex; align-items: center; gap: .35rem; padding: .25rem .15rem; }
.typing span { width: .48rem; height: .48rem; display: block; border-radius: 50%; background: var(--brand); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }
@keyframes message-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.assistant-link { color: var(--brand); font-weight: 700; text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--brand) 35%, transparent); text-underline-offset: .2rem; }
.source-toggle { display: inline-flex; align-items: center; gap: .35rem; margin-top: 1rem; padding: .4rem .65rem; color: var(--fg); background: color-mix(in srgb, var(--line) 35%, transparent); border: 1px solid var(--line); border-radius: .65rem; font-size: .72rem; font-weight: 750; }
.source-toggle:hover { color: var(--brand); border-color: var(--brand); }
.source-list { display: none; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; margin-top: .75rem; }
.source-list.open { display: grid; }
.source-card { min-width: 0; padding: .7rem; background: color-mix(in srgb, var(--card) 70%, transparent); border: 1px solid var(--line); border-radius: .75rem; font-size: .72rem; }
.source-card strong, .source-card span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-card strong { margin-bottom: .25rem; font-size: .78rem; }
.source-card span { color: var(--muted); }
.feedback { display: flex; align-items: center; gap: .35rem; margin-top: .85rem; padding-top: .7rem; border-top: 1px solid var(--line); }
.feedback button { width: 2rem; height: 2rem; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); background: transparent; border: 1px solid transparent; border-radius: .55rem; font-size: 1rem; transition: color .2s, background-color .2s; }
.feedback button:hover { color: var(--fg); background: color-mix(in srgb, var(--line) 60%, transparent); }
.feedback button.active-up { color: var(--brand); background: var(--brand-light); }
.feedback button.active-down { color: #c94b4b; background: #fff0f0; }
html.dark .feedback button.active-down { background: #4b2028; }
.feedback button:disabled { opacity: .6; }
.feedback-result { color: var(--muted); font-size: .72rem; font-weight: 650; }
.feedback { flex-wrap: wrap; }
.feedback-comment { flex: 1 0 100%; display: flex; gap: .35rem; }
.feedback-comment[hidden] { display: none; }
.feedback-comment input { flex: 1; min-width: 0; padding: .35rem .55rem; font: inherit; font-size: .8rem; color: var(--fg); background: transparent; border: 1px solid var(--line); border-radius: .55rem; }
.feedback .feedback-comment button { width: auto; padding: 0 .7rem; font-size: .8rem; border-color: var(--line); }

.input-area { flex-shrink: 0; z-index: 40; padding: .85rem 1rem calc(env(safe-area-inset-bottom, 0px) + .75rem); background: var(--composer); border-top: 1px solid color-mix(in srgb, var(--line) 85%, transparent); box-shadow: 0 -10px 30px -18px rgba(0,0,0,.25); backdrop-filter: blur(18px); }
.composer { width: min(100%, 64rem); margin: 0 auto; display: flex; align-items: flex-end; gap: .65rem; }
.composer textarea { width: 100%; min-height: 3.65rem; max-height: 12rem; flex: 1; resize: none; overflow-y: auto; padding: .9rem 1rem; color: var(--fg); background: var(--card); border: 2px solid var(--line); border-radius: 1rem; line-height: 1.55; transition: border-color .2s, background-color .2s; }
.composer textarea:focus { outline: none; border-color: var(--brand); }
.composer textarea::placeholder { color: var(--muted); }
.composer-actions { display: flex; align-items: center; gap: .45rem; padding-bottom: .35rem; }
.send-button, .stop-button { width: 2.45rem; height: 2.45rem; display: inline-flex; align-items: center; justify-content: center; color: var(--brand-fg); background: var(--brand); border: 1px solid color-mix(in srgb, var(--brand) 70%, #000); border-radius: .75rem; box-shadow: 0 4px 12px rgba(11,92,142,.18); }
.send-button:hover, .stop-button:hover { filter: brightness(1.08); }
.send-button:disabled { opacity: .48; filter: none; }
.send-button::before { content: "➤"; font-size: 1.25rem; transform: translateX(-.05rem); }
html[dir="rtl"] .send-button::before { transform: scaleX(-1) translateX(-.05rem); }
.stop-button { color: var(--fg); background: color-mix(in srgb, var(--card) 90%, transparent); border-color: var(--line); }
.stop-button::before { content: "■"; font-size: .85rem; }
.composer-meta { width: min(100%, 64rem); min-height: 1.25rem; margin: .2rem auto 0; padding-inline: .25rem; color: var(--muted); font-size: .7rem; }
/* Suggested questions after the first message: a labelled pill that stays put
   under the thumb, and a panel that grows upward from it (chat area shrinks,
   nothing is overlaid on the latest answer). */
.suggest-bar { width: min(100%, 64rem); margin: 0 auto .55rem; display: flex; }
.suggest-toggle { min-height: 2.75rem; display: inline-flex; align-items: center; gap: .5rem; padding: .5rem 1rem; color: var(--brand); background: var(--card); border: 1px solid color-mix(in srgb, var(--brand) 40%, var(--line)); border-radius: 999px; box-shadow: var(--shadow); font-size: .86rem; font-weight: 750; transition: background-color .2s, border-color .2s; }
.suggest-toggle:hover, .suggest-toggle[aria-expanded="true"] { background: var(--brand-light); border-color: var(--brand); }
.suggest-toggle svg { flex: 0 0 auto; }
.suggest-chevron { width: .45rem; height: .45rem; margin-inline-start: .15rem; border-top: 2px solid currentColor; border-left: 2px solid currentColor; transform: translateY(.12rem) rotate(45deg); transition: transform .2s; }
.suggest-toggle[aria-expanded="true"] .suggest-chevron { transform: translateY(-.12rem) rotate(225deg); }
#chat-suggestions { width: min(100%, 64rem); max-width: none; max-height: min(42vh, 21rem); margin: 0 auto .45rem; padding: .5rem; gap: .4rem; overflow-y: auto; overscroll-behavior: contain; background: var(--card); border: 1px solid var(--brand); border-radius: 1rem; box-shadow: var(--shadow); animation: message-in .18s ease-out both; }
#chat-suggestions .starter-card { min-height: 2.75rem; gap: .6rem; padding: .5rem .7rem; background: color-mix(in srgb, var(--brand-light) 55%, var(--card)); border-color: transparent; border-radius: .7rem; box-shadow: none; }
#chat-suggestions .starter-card:hover { transform: none; border-color: var(--brand); }
#chat-suggestions .starter-card-icon { display: none; }
#chat-suggestions .starter-card span:last-child { font-size: .84rem; font-weight: 650; line-height: 1.45; }
.char-count-warning { color: #b23a3a; font-weight: 750; }
.brand-footer { display: flex; align-items: center; justify-content: center; gap: .5rem; margin-top: .25rem; color: var(--muted); font-size: .7rem; font-weight: 650; opacity: .85; }
.brand-footer-logo { width: 1.9rem; height: 1.9rem; display: inline-flex; align-items: center; justify-content: center; overflow: hidden; background: #fff; border: 1px solid var(--line); border-radius: .45rem; }
.brand-footer-logo img { width: 100%; height: 100%; object-fit: cover; transform: scale(2); }

.modal-backdrop { position: fixed; inset: 0; z-index: 70; display: flex; align-items: center; justify-content: center; padding: 1rem; background: rgba(15,23,42,.38); backdrop-filter: blur(5px); }
.about-modal { width: min(100%, 30rem); padding: 1.25rem; color: var(--fg); background: color-mix(in srgb, var(--card) 96%, transparent); border: 1px solid var(--line); border-radius: 1.5rem; box-shadow: 0 24px 80px rgba(0,0,0,.25); }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.modal-header h2 { margin: 0 0 .5rem; font-size: 1.3rem; }
.modal-header p { margin: 0 0 1.25rem; color: var(--muted); font-size: .85rem; line-height: 1.7; }
.modal-close { width: 2.25rem; height: 2.25rem; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); background: transparent; border: 0; border-radius: .65rem; }
.modal-close:hover { color: var(--fg); background: color-mix(in srgb, var(--line) 45%, transparent); }
.about-card { padding: .9rem; background: color-mix(in srgb, var(--line) 20%, transparent); border: 1px solid var(--line); border-radius: 1rem; }
.about-card h3 { display: flex; align-items: center; gap: .45rem; margin: 0 0 .65rem; font-size: .88rem; }
.about-card ul { margin: 0; padding-inline-start: 1.2rem; color: var(--muted); font-size: .82rem; line-height: 1.7; }
.about-note { margin: 1rem 0 0; color: var(--muted); font-size: .77rem; line-height: 1.65; }
.modal-footer { display: flex; gap: .55rem; justify-content: flex-end; margin-top: 1.2rem; padding-top: .9rem; border-top: 1px solid var(--line); }
.secondary-button, .primary-button { min-height: 2.3rem; display: inline-flex; align-items: center; justify-content: center; padding: .45rem .8rem; border-radius: .7rem; font-size: .78rem; font-weight: 750; text-decoration: none; }
.secondary-button { color: var(--fg); background: var(--card); border: 1px solid var(--line); }
.primary-button { color: var(--brand-fg); background: var(--brand); border: 1px solid var(--brand); }

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--muted) 28%, transparent); border-radius: 999px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .01ms !important; } }
@media (max-width: 700px) {
  .header-inner { height: 3.7rem; padding-inline: .65rem; gap: .4rem; }
  .brand-mark { width: 2.35rem; height: 2.35rem; }
  .brand-copy h1 { font-size: .78rem; }
  .brand-copy span { font-size: .62rem; }
  .header-actions { gap: .1rem; }
  .header-button, .new-session { padding-inline: .45rem; font-size: .7rem; }
  .about-button { display: none; }
  .header-button.icon-only { width: 2.1rem; }
  .new-session { min-height: 2.1rem; }
  .new-session #new-session-label { display: none; }
  .welcome { padding-top: .6rem; }
  .welcome h2 { font-size: 1.65rem; }
  .welcome > p { margin-bottom: 1.45rem; font-size: .8rem; line-height: 1.7; }
  .starter-grid { gap: .55rem; }
  .starter-card { min-height: 4.6rem; gap: .55rem; padding: .6rem; border-radius: .85rem; }
  .starter-card-icon { width: 2rem; height: 2rem; font-size: .95rem; }
  .starter-card span:last-child { font-size: .69rem; }
  .chat-scroll-area { padding-inline: .7rem; padding-bottom: 11rem; }
  .message-bubble { max-width: 92%; padding: .75rem .85rem; font-size: .9rem; }
  .input-area { padding-inline: .65rem; }
  .composer textarea { min-height: 3.35rem; padding: .8rem .85rem; }
  .source-list { grid-template-columns: 1fr; }
  #chat-suggestions { grid-template-columns: 1fr; }
  .brand-footer { display: none; }
}
@media (max-width: 390px) {
  .brand-copy { max-width: 8rem; }
  .header-button:not(.icon-only) .lang-icon { display: none; }
  .welcome h2 { font-size: 1.45rem; }
  .starter-card { min-height: 4.2rem; }
}
