:root {
  color-scheme: light;
  --navy: #102a43;
  --navy-soft: #243b53;
  --teal: #147d92;
  --teal-dark: #0b6474;
  --teal-pale: #e8f5f6;
  --orange: #d97732;
  --orange-pale: #fff2e5;
  --ink: #172f46;
  --muted: #71879b;
  --line: #dce6ee;
  --canvas: #f4f8fb;
  --surface: #ffffff;
  --success: #16834e;
  --danger: #b42318;
  --warn: #a15c08;
  --shadow: 0 18px 55px rgba(16, 42, 67, .09);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--canvas);
  font: 15px/1.55 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .68; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.app {
  display: flex;
  flex-direction: column;
  width: min(100%, 1040px);
  height: 100%;
  min-height: 620px;
  margin: 0 auto;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 70px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .96);
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  color: #fff;
  background: linear-gradient(135deg, #efa766, var(--orange));
  border-radius: 12px;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: -.08em;
}
.brand-name { color: var(--navy); font-size: 16px; font-weight: 850; letter-spacing: -.03em; }
.brand-subtitle { display: block; margin-top: -2px; color: var(--muted); font-size: 10px; }
.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border-radius: 99px;
  padding: 6px 10px;
  font-size: 10px;
  font-weight: 800;
}
.status.ok { color: var(--success); background: #e7f7ee; }
.status.error { color: var(--danger); background: #fdeceb; }
.status.neutral { color: var(--muted); background: #eef3f7; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.chat-history {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 22px;
  overflow-y: auto;
  padding: 34px clamp(20px, 8vw, 105px) 30px;
  background: linear-gradient(180deg, #fbfdfe 0%, #fff 100%);
}
.empty-space { flex: 1; min-height: 12px; }
.message { display: flex; align-items: flex-start; gap: 11px; max-width: 790px; }
.message.user-message { align-self: flex-end; flex-direction: row-reverse; }
.avatar {
  display: grid;
  place-items: center;
  width: 31px;
  height: 31px;
  flex: none;
  color: #fff;
  background: linear-gradient(135deg, #efa766, var(--orange));
  border-radius: 10px;
  font-size: 10px;
  font-weight: 900;
}
.user-message .avatar { color: var(--teal-dark); background: var(--teal-pale); }
.message-body { min-width: 0; }
.message-label {
  display: block;
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.user-message .message-label { text-align: right; }
.bubble {
  padding: 12px 15px;
  color: var(--navy-soft);
  background: #f3f7fa;
  border: 1px solid #e7eef3;
  border-radius: 5px 16px 16px 16px;
  font-size: 14px;
  white-space: pre-wrap;
}
.user-message .bubble {
  color: #194859;
  background: var(--teal-pale);
  border-color: #d6eeee;
  border-radius: 16px 5px 16px 16px;
}
.loading-message .bubble { color: var(--muted); font-style: italic; }
.voice-reply .bubble { background: #fff8f0; border-color: #f5e5d3; }
.voice-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 7px;
  padding: 3px 7px;
  color: var(--orange);
  background: var(--orange-pale);
  border-radius: 99px;
  font-size: 9px;
  font-weight: 850;
  letter-spacing: .07em;
  text-transform: uppercase;
}
.answer-status {
  display: inline-block;
  margin-bottom: 7px;
  padding: 3px 7px;
  color: var(--success);
  background: #e7f7ee;
  border-radius: 99px;
  font-size: 9px;
  font-weight: 850;
  letter-spacing: .07em;
  text-transform: uppercase;
}
.answer-status.refused { color: var(--danger); background: #fdeceb; }
.answer-status.partial { color: var(--warn); background: #fff2d9; }
.evidence-block { margin-top: 9px; color: var(--muted); font-size: 10px; }
.approval-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 11px; }
.approval-button {
  padding: 7px 13px;
  color: #fff;
  background: var(--teal);
  border: 1px solid var(--teal);
  border-radius: 10px;
  font-size: 12px;
  font-weight: 750;
}
.approval-button:hover { background: var(--teal-dark); }
.approval-button.secondary { color: var(--danger); background: #fff; border-color: #f0c9c5; }
.approval-button.secondary:hover { background: #fdeceb; }

.composer-wrap {
  padding: 15px clamp(16px, 6vw, 75px) 21px;
  border-top: 1px solid var(--line);
  background: #fff;
}
.composer {
  display: flex;
  align-items: flex-end;
  gap: 9px;
  padding: 8px;
  background: #fff;
  border: 1px solid #cfdde7;
  border-radius: 16px;
  box-shadow: 0 7px 22px rgba(16, 42, 67, .06);
}
.text-input {
  flex: 1;
  min-width: 0;
  height: 43px;
  padding: 0 9px;
  color: var(--ink);
  background: transparent;
  border: 0;
  outline: 0;
  font-size: 14px;
}
.text-input::placeholder { color: #94a8b8; }
.text-input:focus { box-shadow: none; }
.send-button, .voice-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 43px;
  border-radius: 11px;
  font-size: 12px;
  font-weight: 850;
  transition: transform .16s, box-shadow .16s, background .16s;
}
.send-button {
  min-width: 77px;
  padding: 0 14px;
  color: #fff;
  background: var(--teal);
  border: 0;
}
.voice-button {
  min-width: 151px;
  padding: 0 15px;
  color: var(--teal-dark);
  background: var(--teal-pale);
  border: 1px solid #cde8ea;
}
.send-button:hover, .voice-button:hover { transform: translateY(-1px); box-shadow: 0 8px 16px rgba(16, 42, 67, .13); }
.send-button:hover { background: var(--teal-dark); }
.voice-button:hover { background: #d9f0f1; }
.voice-button.active { color: #fff; background: var(--orange); border-color: var(--orange); }
.voice-icon { font-size: 17px; line-height: 1; }
.voice-button.active .voice-icon { animation: mic-pulse 1.2s infinite; }
.composer-hint { margin: 8px 3px 0; color: var(--muted); font-size: 10px; text-align: center; }
.composer-hint kbd { padding: 2px 5px; background: #f3f6f8; border: 1px solid var(--line); border-radius: 4px; font-size: 9px; }
.voice-bar { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 0 0 6px; }
.voice-status-line { min-height: 17px; margin: 5px 0 0; color: var(--orange); font-size: 10px; font-weight: 750; text-align: center; }
.voice-status-line:empty { display: none; }
.interrupt-button {
  padding: 5px 12px;
  color: #fff;
  background: var(--orange);
  border: 0;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 800;
}
.interrupt-button:hover { background: #bf6322; }
.interrupt-button[hidden] { display: none; }
.language-select {
  height: 43px;
  max-width: 132px;
  padding: 0 8px;
  color: var(--teal-dark);
  background: #fff;
  border: 1px solid #cde8ea;
  border-radius: 11px;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
}
.source-list { margin: 9px 0 0; padding-left: 18px; font-size: 12px; }
.source-list li { margin: 2px 0; }
.source-list a { color: var(--teal-dark); overflow-wrap: anywhere; }
@keyframes mic-pulse { 50% { transform: scale(1.17); } }

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(420px, calc(100vw - 44px));
  padding: 11px 14px;
  color: #fff;
  background: var(--navy);
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 11px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: .2s;
}
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 680px) {
  .app { min-height: 100%; }
  .topbar { min-height: 62px; padding: 0 16px; }
  .brand-subtitle { display: none; }
  .status { padding: 5px 8px; font-size: 9px; }
  .chat-history { padding: 24px 15px 24px; }
  .bubble { font-size: 13px; }
  .composer-wrap { padding: 11px 12px 16px; }
  .composer { flex-wrap: wrap; }
  .text-input { flex-basis: calc(100% - 18px); order: 1; }
  .language-select { order: 2; flex: 0 0 96px; }
  .voice-button { order: 2; flex: 1; min-width: 0; }
  .send-button { order: 2; flex: 0 0 78px; }
  .composer-hint { display: none; }
}
@media (max-width: 390px) {
  .brand-name { font-size: 15px; }
  .message { max-width: 96%; }
  .voice-button { font-size: 11px; }
}

/* Sign-in gate and account controls */
.topbar-end { display: flex; align-items: center; gap: 12px; }

.account { display: flex; align-items: center; gap: 8px; }
.account-name { color: var(--muted); font-size: 11px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--navy);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 650;
  cursor: pointer;
}
.account-button:hover { background: var(--teal-pale); border-color: var(--teal); }

.sign-in-gate {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 56px 24px;
  text-align: center;
}
.sign-in-title { margin: 0; color: var(--navy); font-size: 20px; font-weight: 850; letter-spacing: -.03em; }
.sign-in-message { margin: 0; max-width: 420px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.sign-in-button {
  margin-top: 4px;
  border: 0;
  background: var(--teal);
  color: #fff;
  border-radius: 10px;
  padding: 11px 22px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.sign-in-button:hover { background: var(--teal-dark); }
.sign-in-gate[hidden], .account[hidden] { display: none; }
/* The chat history sets its own display, which would otherwise beat the UA's
   [hidden] rule and leave the gate stacked on top of the signed-out page. */
.chat-history[hidden] { display: none; }
