@font-face { font-family: 'Zarid Sans'; font-weight: 300; font-style: normal; font-display: swap;
  src: url('fonts/29LTZaridSansAL-Light.woff2') format('woff2'); }
@font-face { font-family: 'Zarid Sans'; font-weight: 400; font-style: normal; font-display: swap;
  src: url('fonts/29LTZaridSansAL-Regular.woff2') format('woff2'); }
@font-face { font-family: 'Zarid Sans'; font-weight: 700; font-style: normal; font-display: swap;
  src: url('fonts/29LTZaridSansAL-Bold.woff2') format('woff2'); }

:root {
  --surface: #ffffff;
  --surface-2: #f6f8fa;
  --ink: #182339;
  --ink-soft: #586072;
  --ink-faint: #757d8c;
  --rule: #ecedf0;
  --accent: #1d4a9b;
  --accent-soft: #e7edf5;
  --accent-line: #dce5f1;
  --gold: #c0a44b;
  --gold-soft: #f7f1de;

  --font: 'Zarid Sans', 'Segoe UI', system-ui, sans-serif;
  --text-xs: 0.8125rem; --text-sm: 0.9375rem; --text-base: 1rem;
  --text-lg: 1.125rem;

  --s-1: 0.25rem; --s-2: 0.5rem; --s-3: 0.75rem; --s-4: 1rem;
  --s-6: 1.5rem; --s-8: 2rem; --s-12: 3rem;

  --radius: 16px; --radius-sm: 12px; --radius-xs: 10px;
  --shadow: 0 1px 2px rgba(24,35,57,.04), 0 10px 30px rgba(24,35,57,.05);
  --w: 60rem;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--surface); color: var(--ink);
  font-family: var(--font); font-size: var(--text-base); line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
.eyebrow {
  margin: 0; color: var(--accent);
  font-size: var(--text-xs); font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
}
html[lang="ar"] .eyebrow { letter-spacing: 0; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- header ---------- */
.topbar { border-block-end: 1px solid var(--rule); background: var(--surface); }
.topbar-inner {
  max-width: var(--w); margin-inline: auto; padding: var(--s-4) var(--s-6);
  display: flex; align-items: center; gap: var(--s-4);
}
.logo { block-size: 24px; inline-size: auto; margin-inline-end: auto; }
.langbtn {
  min-height: 32px; padding: 0 var(--s-4); border: 0; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  font: 700 var(--text-sm)/1 var(--font); cursor: pointer;
  transition: background .15s ease;
}
.langbtn:hover { background: var(--accent-line); }
.langbtn { unicode-bidi: plaintext; }
:is(a, button, input, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

main { max-width: var(--w); margin-inline: auto; padding: var(--s-8) var(--s-6); }
.page-head { margin-block-end: var(--s-4); }

/* ---------- chat ---------- */
.chat {
  position: relative; display: flex; flex-direction: column;
  block-size: min(60vh, 560px); overflow: hidden;
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.chat::before {
  content: ""; position: absolute; inset-block: 0; left: 0;
  inline-size: 4px; background: var(--accent);
}
.chat-head {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-4) var(--s-6); border-block-end: 1px solid var(--rule);
}
.avatar {
  inline-size: 36px; block-size: 36px; border-radius: var(--radius-xs); flex: none;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  font-size: var(--text-xs); font-weight: 700;
}
.handler-name { font-weight: 700; font-size: var(--text-lg); letter-spacing: -0.01em; unicode-bidi: plaintext; }

.transcript {
  flex: 1; overflow-y: auto; padding: var(--s-6);
  display: flex; flex-direction: column; gap: var(--s-4);
  scroll-behavior: smooth;
}
@media (prefers-reduced-motion: reduce) { .transcript { scroll-behavior: auto; } }
.transcript > * { flex: none; }
.msg { display: flex; gap: var(--s-3); max-width: 42rem; }
.msg-body {
  padding: var(--s-3) var(--s-4); border-radius: 14px;
  border: 1px solid var(--rule); background: var(--surface-2);
}
.msg-body p { margin: 0 0 var(--s-2); }
.msg-body p:last-child { margin-block-end: 0; }
.msg-time { display: block; font-size: var(--text-xs); color: var(--ink-faint); margin-block-start: var(--s-1); }
.msg-me { margin-inline-start: auto; flex-direction: row-reverse; }
.msg-me .msg-body { background: var(--accent-soft); border-color: var(--accent-line); }
.msg-me .msg-time { text-align: end; }
.msg-me .avatar { background: var(--surface-2); color: var(--ink-soft); }

.source {
  display: inline-flex; align-items: center; gap: var(--s-2);
  margin-block-start: var(--s-2); padding: var(--s-1) var(--s-3);
  border: 1px solid var(--rule); border-radius: 999px;
  background: var(--surface); font-size: var(--text-xs); font-weight: 700;
  color: var(--accent); text-decoration: none; max-inline-size: 100%;
}
.source:hover { background: var(--accent-soft); }
.source svg { flex: none; }
.source span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 400; color: var(--ink-soft); }

.sysline {
  display: flex; align-items: center; gap: var(--s-3);
  color: var(--ink-faint); font-size: var(--text-xs); font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase;
}
html[lang="ar"] .sysline { letter-spacing: 0; }
.sysline::before, .sysline::after { content: ""; block-size: 1px; background: var(--rule); flex: 1; }

.bcard {
  position: relative; border: 1px solid var(--rule); border-radius: var(--radius-sm);
  background: var(--surface); overflow: hidden;
}
.bcard::before {
  content: ""; position: absolute; inset-block: 0; left: 0;
  inline-size: 4px; background: var(--accent);
}
.bcard-top {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-3) var(--s-4) var(--s-3) calc(var(--s-4) + 4px);
  border-block-end: 1px solid var(--rule);
}
.bcard-id { font-weight: 700; font-size: var(--text-sm); letter-spacing: .02em; }
.bcard-label { color: var(--ink-faint); font-size: var(--text-xs); }
.pill {
  margin-inline-start: auto; padding: 3px var(--s-3); border-radius: 999px;
  font-size: var(--text-xs); font-weight: 700; white-space: nowrap;
  background: var(--accent-soft); color: var(--accent);
}
.pill-high { background: var(--gold-soft); color: #8a7327; }
.bcard dl {
  margin: 0; padding: var(--s-4) var(--s-4) var(--s-3) calc(var(--s-4) + 4px);
  display: grid; grid-template-columns: auto 1fr; gap: var(--s-2) var(--s-4); font-size: var(--text-sm);
}
.bcard dt { color: var(--ink-faint); }
.bcard dd { margin: 0; }
.bcard-foot { padding: 0 var(--s-4) var(--s-4) calc(var(--s-4) + 4px); }
.bcard-foot a { color: var(--accent); font-size: var(--text-sm); font-weight: 700; text-decoration: none; }
.bcard-foot a:hover { text-decoration: underline; }

.typing { display: inline-flex; gap: 4px; align-items: center; block-size: 20px; }
.typing i { inline-size: 5px; block-size: 5px; border-radius: 50%; background: var(--ink-faint); animation: blip 1.1s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .16s; } .typing i:nth-child(3) { animation-delay: .32s; }
@keyframes blip { 0%,80%,100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }
@media (prefers-reduced-motion: reduce) { .typing i { animation: none; opacity: .5; } }

.composer { border-block-start: 1px solid var(--rule); padding: var(--s-4) var(--s-6); background: var(--surface); }
.composer-row { display: flex; gap: var(--s-3); align-items: flex-end; }
textarea {
  width: 100%; min-height: 46px; padding: var(--s-3) var(--s-4); resize: none; max-height: 140px;
  border: 1px solid var(--rule); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
  font: var(--text-base)/1.5 var(--font);
}
textarea:hover { border-color: var(--accent-line); }
textarea:focus { border-color: var(--accent); outline: none; }
textarea::placeholder { color: var(--ink-faint); }
.btn-send {
  flex: none; min-height: 46px; padding: 0 var(--s-6); border: 0;
  border-radius: var(--radius-sm); background: var(--accent); color: #fff;
  font: 700 var(--text-sm)/1 var(--font); cursor: pointer;
  transition: background .15s ease;
}
.btn-send:hover { background: #163b7d; }
.btn-send:disabled { opacity: .45; cursor: not-allowed; }
.composer-note { margin: var(--s-3) 0 0; font-size: var(--text-xs); color: var(--ink-faint); }

footer {
  max-width: var(--w); margin-inline: auto;
  padding: var(--s-6) var(--s-6) var(--s-12);
}
footer p { margin: 0; color: var(--ink-faint); font-size: var(--text-xs); line-height: 1.6; max-width: 68ch; }
footer p + p { margin-block-start: var(--s-2); }

@media (max-width: 720px) {
  main { padding: var(--s-8) var(--s-4) var(--s-6); }
  .topbar-inner, .composer, .chat-head, .transcript { padding-inline: var(--s-4); }
  footer { padding-inline: var(--s-4); }
  .chat { block-size: min(72vh, 520px); }
  .msg { max-width: 100%; }
}

/* ---------- sign-in gate & account controls ---------- */
.whoami {
  font-size: var(--text-xs); color: var(--ink-faint);
  max-inline-size: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.signout {
  min-height: 32px; padding: 0 var(--s-3); border: 0; border-radius: 999px;
  background: transparent; color: var(--ink-faint);
  font: 700 var(--text-xs)/1 var(--font); cursor: pointer;
}
.signout:hover { background: var(--surface-2); color: var(--ink); }

.gate {
  position: relative; background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: var(--s-8) var(--s-6); text-align: start;
}
.gate::before {
  content: ""; position: absolute; inset-block: 0; left: 0;
  inline-size: 4px; background: var(--accent);
}
.gate-title { margin: 0 0 var(--s-2); font-size: var(--text-lg); font-weight: 700; }
.gate-text { margin: 0 0 var(--s-6); color: var(--ink-soft); max-inline-size: 46ch; }
.gate-error { margin: var(--s-4) 0 0; color: var(--danger, #9c4a3c); font-size: var(--text-sm); }
#gsi { min-block-size: 44px; }

@media (max-width: 560px) {
  .whoami { display: none; }
  .signout { padding-inline: var(--s-2); }
}
