:root {
  color-scheme: light;
  --paper: #fafbf9;
  --rail-bg: #f1f3ef;
  --surface: #ffffff;
  --ink: #202621;
  --muted: #585f59;
  --accent: #235b43;
  --action: #245b43;
  --action-hover: #194b35;
  --action-ink: #fff;
  --tint: #e5ece6;
  --hover: #e8ede8;
  --line: #dfe4de;
  --control-line: #c9d3ca;
  --focus: #347656;
  --error: #96332c;
  --shadow: #15281d0a;
  --bar-size: 60px;
  --chat-width: 696px;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #131614;
  --rail-bg: #191c19;
  --surface: #1d211e;
  --ink: #eef0ec;
  --muted: #aeb7af;
  --accent: #a7d7ba;
  --action: #9bd3b2;
  --action-hover: #b6e3c7;
  --action-ink: #102c1e;
  --tint: #24362c;
  --hover: #252b26;
  --line: #2a302b;
  --control-line: #3d4940;
  --focus: #7ab995;
  --error: #ffada2;
  --shadow: #00000025;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-padding-block: calc(var(--bar-size) + 16px) 165px; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 1rem/1.6 system-ui, "Segoe UI", sans-serif; }
[hidden] { display: none !important; }
a { color: var(--accent); text-underline-offset: .2em; }
button, textarea, input { font: inherit; }
button { color: inherit; cursor: pointer; }
button:disabled { cursor: wait; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

.site-shell {
  --rail-size: 222px;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: var(--rail-size) minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  grid-template-areas: "rail bar" "rail main";
}
.site-shell[data-nav="closed"] { --rail-size: 0px; }
.site-shell main { grid-area: main; min-width: 0; }
.topbar {
  grid-area: bar;
  position: sticky;
  inset-block-start: 0;
  z-index: 2;
  min-height: var(--bar-size);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px clamp(14px, 2.5vw, 30px);
  border-block-end: 1px solid var(--line);
  background: var(--paper);
}
.bar-leading, .bar-actions { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand { display: inline-flex; width: fit-content; align-items: center; gap: 9px; color: var(--ink); text-decoration: none; }
.brand img { display: block; flex: none; border-radius: 8px; }
.brand strong { font-weight: 650; line-height: 1.4; white-space: nowrap; }
.compact-brand { display: none; }
[data-nav="closed"] .compact-brand { display: inline-flex; }

.rail {
  grid-area: rail;
  position: sticky;
  inset-block-start: 0;
  align-self: start;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 19px 14px 14px;
  border-inline-end: 1px solid var(--line);
  background: var(--rail-bg);
  overflow: auto;
}
.rail-brand { margin-inline: 7px; min-height: 30px; }
.rail-nav { display: flex; flex: 1; flex-direction: column; gap: 16px; margin-top: 24px; }
.new-chat, .rail-link {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font-size: .875rem;
  text-align: start;
  text-decoration: none;
}
.new-chat { border-color: var(--line); background: var(--tint); color: var(--accent); font-weight: 650; }
.rail-links { display: grid; gap: 1px; margin-top: auto; padding-top: 8px; border-top: 1px solid var(--line); }
.rail-link { color: var(--muted); }
.new-chat:hover, .rail-link:hover, .rail-link[aria-current="page"] { background: var(--hover); color: var(--ink); }
.chat-history { min-width: 0; color: var(--muted); }
.chat-history h2 { margin: 0 7px 5px; font-size: .79rem; font-weight: 650; }
.chat-history p { margin: 4px 7px; font-size: .8rem; }
#chat-history-list {
  display: grid;
  padding: 3px;
  margin: 0;
  list-style: none;
  max-height: min(47vh, 420px);
  overflow: auto;
}
.history-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 1px; border-radius: 8px; }
.history-open, .history-delete { min-height: 38px; border: 0; border-radius: 7px; background: transparent; color: inherit; }
.history-open {
  min-width: 0;
  overflow: hidden;
  padding: 6px 8px;
  text-align: start;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: .875rem;
}
.history-delete { width: 34px; padding: 0; font-size: 1.15rem; }
.history-open[aria-current="true"] { background: var(--tint); color: var(--ink); }
.history-open:hover, .history-delete:hover { background: var(--hover); color: var(--ink); }

.icon-button {
  display: grid;
  place-items: center;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
}
.icon-button:hover { border-color: var(--line); background: var(--hover); color: var(--ink); }
.icon-menu, .icon-plus, .icon-book, .icon-lock, .icon-article { position: relative; display: inline-block; flex: none; }
.icon-menu { width: 17px; height: 14px; border: 1.5px solid; border-radius: 3px; }
.icon-menu::after { content: ""; position: absolute; inset-block: 0; inset-inline-start: 4px; border-inline-start: 1.5px solid; }
.icon-plus { width: 15px; height: 15px; }
.icon-plus::before, .icon-plus::after { content: ""; position: absolute; background: currentColor; border-radius: 2px; }
.icon-plus::before { inset: 7px 1px; }
.icon-plus::after { inset: 1px 7px; }
.icon-book { width: 14px; height: 16px; border: 1.4px solid; border-radius: 3px; }
.icon-book::after { content: ""; position: absolute; inset: auto 1px 3px; border-block-start: 1.4px solid; }
.icon-article { width: 14px; height: 16px; border: 1.4px solid; border-radius: 3px; }
.icon-article::after { content: ""; position: absolute; inset: 4px 2px; border-block: 1.4px solid; }
.icon-lock { width: 14px; height: 10px; margin-block-start: 5px; border: 1.4px solid; border-radius: 3px; }
.icon-lock::before { content: ""; position: absolute; inset: -7px 2px auto; height: 6px; border: 1.4px solid; border-block-end: 0; border-radius: 5px 5px 0 0; }
.icon-moon { width: 14px; height: 14px; border-radius: 50%; box-shadow: -4px 4px currentColor; transform: translate(2px, -2px); }
.icon-sun { display: none; font-size: 1.24rem; line-height: 1; }
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: block; }
.languages { display: flex; align-items: center; padding: 2px; border: 1px solid var(--line); border-radius: 9px; }
.languages a {
  display: grid;
  min-height: 32px;
  place-items: center;
  padding: 3px 10px;
  border-radius: 6px;
  color: var(--muted);
  font-size: .875rem;
  text-decoration: none;
}
.languages a:hover { color: var(--ink); }
.languages a[aria-current="page"] { background: var(--hover); color: var(--ink); font-weight: 600; }

.workspace, .privacy-page, .source-page, .blog-page { width: min(calc(100% - 48px), var(--chat-width)); margin-inline: auto; }
.workspace:not(.has-turns) {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: calc(100vh - var(--bar-size));
  min-height: calc(100dvh - var(--bar-size));
  padding-block: 26px clamp(112px, 19vh, 180px);
}
.welcome { margin: 0 0 21px; }
.welcome h1 {
  margin: 0;
  font-size: clamp(1.8rem, 3vw, 2.48rem);
  font-weight: 650;
  line-height: 1.28;
  letter-spacing: -.034em;
  text-wrap: balance;
}
:root[lang="ar"] .welcome h1 { letter-spacing: normal; line-height: 1.42; }
.ask-form { min-width: 0; }
.compose {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 79px;
  padding: 10px;
  border: 1px solid var(--control-line);
  border-radius: 15px;
  background: var(--surface);
  box-shadow: 0 3px 12px var(--shadow);
}
.compose:focus-within { border-color: var(--focus); }
.compose textarea {
  flex: 1;
  width: 100%;
  min-width: 0;
  min-height: 52px;
  max-height: 170px;
  padding: 7px 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.45;
  resize: none;
  text-align: start;
  field-sizing: content;
}
.compose textarea::placeholder { color: var(--muted); opacity: 1; }
.compose textarea:focus-visible { outline: none; }
.send {
  flex: none;
  min-height: 42px;
  padding: 7px 15px;
  border: 0;
  border-radius: 8px;
  background: var(--action);
  color: var(--action-ink);
  font-size: .9rem;
  font-weight: 650;
}
.send:hover { background: var(--action-hover); }
.send:disabled { opacity: .66; }
.status { padding-inline: 3px; margin: 8px 0 0; color: var(--muted); font-size: .875rem; }
.status.error { color: var(--error); }
.suggestions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 14px; }
.suggestion {
  display: inline-flex;
  align-items: center;
  min-height: 37px;
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: .875rem;
}
.suggestion:hover { border-color: var(--control-line); background: var(--hover); color: var(--ink); }
.notice { margin: 8px auto 0; color: var(--muted); font-size: .79rem; text-align: center; }
.workspace:not(.has-turns) .notice { position: absolute; inset-inline: 0; inset-block-end: 18px; }
.sr-only { position: absolute; width: 1px; height: 1px; clip-path: inset(50%); overflow: hidden; white-space: nowrap; }

.workspace.has-turns {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - var(--bar-size));
  min-height: calc(100dvh - var(--bar-size));
  padding-block-start: 26px;
}
.has-turns .composer-dock {
  position: sticky;
  inset-block-end: 0;
  z-index: 1;
  margin-block-start: auto;
  padding-block: 14px max(10px, env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, transparent, var(--paper) 10px);
}
.has-turns .compose { min-height: 58px; padding: 6px; }
.has-turns .compose textarea { min-height: 42px; padding: 9px 9px; }
.conversation { display: flex; flex-direction: column; gap: 27px; min-height: 100px; }
.turn { overflow-wrap: anywhere; }
.turn.user {
  align-self: flex-end;
  max-width: 86%;
  padding: 10px 15px;
  border-radius: 13px;
  background: var(--tint);
  white-space: pre-wrap;
  text-align: start;
}
.turn.answer { width: 100%; padding-block: 3px 10px; }
.turn-label { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; color: var(--ink); font-size: .875rem; font-weight: 650; }
.turn-label::before { content: ""; width: 24px; height: 24px; border-radius: 6px; background: url("/web-assets/icon.png") center / cover; }
.answer-text { font-size: 1rem; line-height: 1.78; }
.answer-text:dir(rtl) { line-height: 1.9; }
.answer-text p, .answer-text ul, .answer-text h2 { margin: 0 0 12px; }
.answer-text :last-child { margin-bottom: 0; }
.answer-text h2 { font-size: 1.1em; }
.answer-text ul { padding-inline-start: 22px; }
.ref-link { display: inline; padding: .04rem .34rem; border: 1px solid var(--line); border-radius: 5px; background: var(--tint); color: var(--accent); font-size: .8rem; font-weight: 650; }
.ref-link:hover { background: var(--hover); }
.answer-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin-block-start: 11px; }
.answer-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 38px;
  min-height: 38px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: .82rem;
}
.answer-action:hover { border-color: var(--line); background: var(--hover); color: var(--ink); }
.answer-action-status { margin: 0 4px; color: var(--muted); font-size: .82rem; }
.action-icon { position: relative; display: inline-block; flex: none; width: 17px; height: 17px; }
.action-icon::before, .action-icon::after { content: ""; position: absolute; }
.icon-copy::before { inset: 1px auto auto 1px; width: 10px; height: 10px; border-top: 1.4px solid; border-left: 1.4px solid; border-top-left-radius: 3px; }
.icon-copy::after { inset: auto 1px 1px auto; width: 10px; height: 11px; border: 1.4px solid; border-radius: 3px; }
.icon-share::before { inset: 1px 1px auto auto; width: 4px; height: 4px; border-radius: 50%; background: currentColor; box-shadow: -10px 6px currentColor, 0 12px currentColor; }
.icon-share::after {
  inset: 3px 3px 3px 4px;
  background:
    linear-gradient(to top right, transparent 44%, currentColor 48% 55%, transparent 59%) top / 100% 50% no-repeat,
    linear-gradient(to bottom right, transparent 44%, currentColor 48% 55%, transparent 59%) bottom / 100% 50% no-repeat;
}
.refs { margin-top: 15px; padding-top: 9px; border-top: 1px solid var(--line); }
.refs summary { width: fit-content; cursor: pointer; color: var(--accent); font-size: .875rem; font-weight: 650; }
.refs ol { margin: 8px 0 0; padding: 0; list-style: none; }
.refs li { margin-top: 6px; padding: 8px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.refs a { font-weight: 600; }
.refs small { display: block; color: var(--muted); font-size: .82rem; }

.privacy-page, .source-page { margin-block: 34px; }
.privacy-page h1, .source-page h1 { margin: .6em 0; font-size: 1.9rem; line-height: 1.35; }
.source-page h2 { margin: 1.5em 0 .4em; font-size: 1.1rem; }
.source-page h2 + p { margin-top: 0; }
.source-libraries { margin: .65em 0; padding: 0; list-style: none; }
.source-libraries li { margin-block: 7px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
.source-libraries a { font-weight: 650; }
.source-libraries p { margin: 4px 0 0; color: var(--muted); }
.blog-page { margin-block: clamp(28px, 6vw, 58px); line-height: 1.8; overflow-wrap: anywhere; }
.blog-page h1 { margin: .45em 0 .3em; font-size: clamp(1.75rem, 4vw, 2.55rem); line-height: 1.28; text-wrap: balance; }
.blog-page h2 { margin: 0 0 .4em; font-size: clamp(1.1rem, 2.5vw, 1.35rem); line-height: 1.45; }
.blog-page p { margin: .55em 0 1em; }
.blog-page time { color: var(--muted); font-size: .85rem; }
.blog-list { display: grid; gap: 12px; margin: 26px 0 0; padding: 0; list-style: none; }
.blog-list li, .article-references { padding: 18px 20px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.blog-list h2 a { color: var(--accent); }
.blog-list p { margin: 0; color: var(--muted); }
.blog-page .blog-lead { margin-block: 1.15em 1.65em; font-size: 1.08rem; }
.article-prompt { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 22px; padding: 12px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--tint); }
.article-prompt p { margin: 0; font-weight: 650; }
.article-ask { display: inline-flex; align-items: center; min-height: 44px; padding: 7px 14px; border-radius: 8px; background: var(--action); color: var(--action-ink); font-size: .9rem; font-weight: 650; text-decoration: none; }
.article-ask:hover { background: var(--action-hover); }
.article-body section { margin-block: 26px; }
.article-photo { margin: 14px 0 17px; }
.article-photo img { display: block; width: 100%; height: auto; border-radius: 12px; }
.article-photo figcaption { margin-block-start: 5px; color: var(--muted); font-size: .81rem; }
.article-body li + li, .article-references li + li { margin-block-start: .45em; }
.article-body ul, .article-body ol, .article-references ol, .article-footer ul { padding-inline-start: 1.4em; }
.blog-page sup { font-size: .78em; unicode-bidi: isolate; }
.article-references ol { margin-block: 0; }
.article-references li:target { background: var(--tint); }
.article-print { margin-block-start: 18px; min-height: 44px; padding: 7px 15px; border: 1px solid var(--control-line); border-radius: 8px; background: var(--surface); color: var(--accent); font-weight: 650; }
.article-print:hover { background: var(--hover); }
.article-footer { margin-block-start: 28px; }
.article-footer nav { border-block-start: 1px solid var(--line); padding-block-start: 18px; }
.article-footer ul { margin-block: 0; }
.back { font-size: .9rem; font-weight: 600; }
dialog { width: min(92%, 490px); padding: 23px; border: 1px solid var(--control-line); border-radius: 14px; background: var(--surface); color: var(--ink); }
dialog::backdrop { background: #111713a6; }
.dialog-content h2 { margin: 0 0 9px; font-size: 1.35rem; }
.dialog-content p { margin: 0 0 13px; }
.dialog-links { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-bottom: 18px; }
.answer-export textarea {
  width: 100%;
  max-height: 40vh;
  padding: 10px 12px;
  border: 1px solid var(--control-line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  resize: vertical;
}
.dialog-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }
.dialog-secondary { border-color: var(--line); }

@media (max-width: 700px) {
  :root { --bar-size: 59px; }
  .site-shell { display: block; }
  .topbar { padding-inline: 10px; }
  .bar-leading, .bar-actions { gap: 5px; }
  .compact-brand { display: inline-flex; gap: 6px; }
  .compact-brand img { width: 26px; height: 26px; border-radius: 6px; }
  .compact-brand strong { font-size: .9rem; }
  .rail {
    position: sticky;
    inset-block-start: var(--bar-size);
    z-index: 2;
    height: auto;
    padding: 6px 10px;
    border-inline-end: 0;
    border-block-end: 1px solid var(--line);
  }
  .rail-brand { display: none; }
  .rail-nav, .rail-links { display: flex; flex-flow: row wrap; gap: 3px; margin: 0; padding: 0; border: 0; }
  .new-chat, .rail-link { width: auto; padding-inline: 7px; }
  .chat-history { flex: 0 0 100%; padding-block: 7px; }
  #chat-history-list { max-height: min(34vh, 260px); }
  .history-open, .history-delete { min-height: 44px; }
  .history-delete { width: 44px; }
  .languages a { padding-inline: 7px; font-size: .8rem; }
  .workspace, .privacy-page, .source-page, .blog-page { width: calc(100% - 30px); }
  .workspace:not(.has-turns) { justify-content: flex-start; padding-block: clamp(64px, 13vh, 128px) 86px; }
  .welcome { margin-bottom: 17px; }
  .compose { min-height: 74px; }
  .suggestions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .suggestion { justify-content: center; padding-inline: 5px; text-align: center; line-height: 1.35; }
  .send, .suggestion, .icon-button, .answer-action { min-height: 44px; }
  .answer-action { min-width: 44px; }
  .workspace.has-turns { padding-top: 15px; }
  .turn.user { padding: 8px 12px; }
}

@media (max-width: 365px) {
  .compact-brand strong { display: none; }
}

@media print {
  body[data-article] {
    --ink: #111;
    --muted: #444;
    --accent: #111;
    color-scheme: light;
    background: white;
    font-size: 10.5pt;
  }
  body[data-article] .site-shell { display: block; min-height: 0; }
  body[data-article] :is(.topbar, .rail, .back, .article-prompt, .article-print, .article-footer) { display: none; }
  body[data-article] .blog-page { width: auto; margin: 0; }
  body[data-article] .blog-page h1 { font-size: 21pt; }
  body[data-article] .blog-page h2 { font-size: 13pt; break-after: avoid; }
  body[data-article] .article-references { break-inside: avoid; background: white; border-color: #bbb; }
}
