:root {
  --bg: #edf3fa;
  --ink: #09111f;
  --muted: #5e6d82;
  --panel: rgba(255, 255, 255, 0.82);
  --panel-strong: #ffffff;
  --accent: #005bbb;
  --accent-2: #4db7ff;
  --line: rgba(121, 150, 184, 0.24);
  --shadow: 0 30px 80px rgba(9, 25, 48, 0.16);
  --shadow-soft: 0 18px 40px rgba(9, 25, 48, 0.1);
}

/* Application layout overrides are at the end of this stylesheet. */

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Yu Gothic UI', Meiryo, sans-serif;
  background:
    radial-gradient(960px 560px at 8% 0%, #d9e9fb 0%, transparent 58%),
    radial-gradient(780px 500px at 96% 12%, #d8f6ff 0%, transparent 60%),
    linear-gradient(180deg, #f8fbff 0%, #edf3fa 38%, #e7eff8 100%), var(--bg);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 18px;
}

body[data-app-ready='false'] .shell {
  visibility: hidden;
}

.startup-error { display: none; }
.status-page-header {
  padding: max(16px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) 16px max(20px, env(safe-area-inset-left));
}
.status-brand { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: .06em; line-height: 1.2; }
.status-brand span { display: block; color: var(--muted); font-size: 13px; font-weight: 500; letter-spacing: .04em; }
.startup-error-content {
  flex: 1;
  display: grid;
  place-items: center;
  min-width: 0;
  padding: 24px max(20px, env(safe-area-inset-right)) max(32px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
}
.startup-error-card {
  width: min(480px, 100%);
  min-width: 0;
  padding: clamp(24px, 5vw, 40px);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  overflow-wrap: anywhere;
}

body[data-app-ready='error'] .shell {
  display: none;
}

body[data-app-ready='error'] { overflow-y: auto; }
body[data-app-ready='error'] .startup-error {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.startup-error h1 {
  margin: 0 0 12px;
  font-size: clamp(24px, 4vw, 30px);
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: -.02em;
}

.startup-error-card > p {
  margin: 0 0 28px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.8;
}

.shell {
  width: min(1500px, 100%);
  min-height: calc(100vh - 36px);
  display: grid;
  gap: 18px;
  align-content: start;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 4px 0;
  animation: rise 500ms ease-out;
}

.app-title {
  margin: 0;
  font-family: inherit;
  font-size: clamp(28px, 4vw, 44px);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.card {
  position: relative;
  background: var(--panel);
  backdrop-filter: blur(18px);
  border-radius: 28px;
  border: none;
  box-shadow: 0 24px 60px rgba(9, 25, 48, 0.1);
  padding: 18px 18px 18px;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  gap: 0;
  height: calc(100vh - 110px);
  min-height: 0;
  animation: rise 600ms ease-out;
  overflow: hidden;
}

.conversation-pane {
  min-width: 0;
  padding: 4px 18px 4px 4px;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.conversation-pane .btn {
  width: 100%;
}

.main-pane {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding-left: 18px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 18px;
}

.row {
  display: grid;
  gap: 12px;
}

.row.split {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

label {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
}

.icon-label {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #7b8ea8;
}

.icon-label svg {
  width: 18px;
  height: 18px;
  display: block;
}

.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;
}

select {
  width: 100%;
  border-radius: 14px;
  border: 1px solid transparent;
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  background: rgba(255, 255, 255, 0.8);
  transition:
    border-color 200ms ease,
    box-shadow 200ms ease;
}

select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 102, 193, 0.2);
}

textarea {
  width: 100%;
  min-height: 84px;
  border-radius: 18px;
  border: 1px solid transparent;
  padding: 0;
  font-size: 16px;
  resize: none;
  font-family: inherit;
  background: transparent;
  transition:
    border-color 200ms ease,
    box-shadow 200ms ease;
}

textarea:focus {
  outline: none;
  box-shadow: none;
}

.actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
}

.action-buttons {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.btn {
  appearance: none;
  border: none;
  padding: 12px 20px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  transition:
    transform 180ms ease,
    box-shadow 180ms ease;
  box-shadow: 0 14px 28px rgba(0, 91, 187, 0.22);
}

.btn svg {
  width: 16px;
  height: 16px;
  display: block;
}

.icon-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn.secondary {
  background: #e9f2ff;
  color: var(--accent);
  box-shadow: none;
  border: 1px solid #cfe1fb;
}

.btn.is-stop {
  background: #fff1ec;
  color: #b34d2e;
  box-shadow: none;
  border: 1px solid #ffcdbd;
}

.btn .stop-icon,
.btn.is-stop .send-icon {
  display: none;
}

.btn.is-stop .stop-icon {
  display: block;
}

.is-hidden {
  display: none !important;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.6;
  box-shadow: none;
}

.status {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #cbd8e6;
  background: linear-gradient(180deg, #fbfdff 0%, #eef5fc 100%);
  color: var(--muted);
  flex: 0 0 auto;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.status::before {
  content: '○';
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
}

.status[data-state='busy'] {
  border-color: #bfd8fb;
  background: #eaf3ff;
  color: var(--accent);
}

.status[data-state='busy']::before {
  content: '↻';
  animation: spin 900ms linear infinite;
}

.status[data-state='success'] {
  border-color: #bfe4cc;
  background: #edf9f1;
  color: #1f8a46;
}

.status[data-state='success']::before {
  content: '✓';
}

.status[data-state='warning'] {
  border-color: #ffd8b0;
  background: #fff6ea;
  color: #b56a0d;
}

.status[data-state='warning']::before {
  content: '■';
}

.status[data-state='error'] {
  border-color: #f5c2c7;
  background: #fff1f3;
  color: #c1364b;
}

.status[data-state='error']::before {
  content: '!';
}

.control-bar {
  display: grid;
  gap: 14px;
  grid-template-columns:
    minmax(180px, 220px)
    minmax(260px, 360px)
    minmax(220px, 260px);
  align-items: end;
  padding: 2px 6px 0;
  border-radius: 0;
  background: transparent;
  border: none;
}

.control-field {
  display: grid;
  gap: 6px;
}

.control-field.inline-field {
  grid-template-columns: 32px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.control-field.is-hidden {
  display: none;
}

.chat-window {
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.26), rgba(241, 247, 255, 0.48)), rgba(255, 255, 255, 0.18);
  padding: 14px 8px 232px;
  min-height: 0;
  height: 100%;
  max-height: none;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  padding: 32px 12px;
}

.message {
  display: flex;
}

.message.user {
  justify-content: flex-end;
}

.message.assistant {
  justify-content: flex-start;
}

.bubble {
  max-width: min(78%, 920px);
  padding: 14px 18px;
  border-radius: 22px;
  font-size: 16px;
  line-height: 1.6;
  white-space: pre-wrap;
  box-shadow: 0 10px 26px rgba(9, 25, 48, 0.08);
}

.bubble.pending {
  opacity: 0.7;
  font-style: italic;
}

.bubble.user {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border-bottom-right-radius: 8px;
}

.bubble.assistant {
  background: rgba(255, 255, 255, 0.84);
  border: none;
  border-bottom-left-radius: 10px;
  color: var(--ink);
  white-space: normal;
  line-height: 1.6;
}

.bubble.assistant h1,
.bubble.assistant h2,
.bubble.assistant h3 {
  margin-top: 0.6em;
}

.bubble.assistant p {
  margin: 0 0 0.8em;
}

.bubble.assistant code {
  background: #f0ede3;
  padding: 2px 6px;
  border-radius: 6px;
}

.bubble.assistant pre {
  background: #f0ede3;
  padding: 12px;
  border-radius: 10px;
  overflow: auto;
}

.thinking-block {
  margin: 0 0 12px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: #f9fcff;
  overflow: hidden;
}

.thinking-summary {
  appearance: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  padding: 10px 12px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  user-select: none;
}

.thinking-summary::before {
  content: '>';
  display: inline-block;
  margin-right: 8px;
  transition: transform 160ms ease;
}

.thinking-block[data-open='true'] .thinking-summary::before {
  transform: rotate(90deg);
}

.thinking-body {
  padding: 0 12px 12px;
  border-top: 1px dashed var(--line);
  color: var(--muted);
  font-size: 14px;
  display: none;
}

.thinking-block[data-open='true'] .thinking-body {
  display: block;
}

.usage {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px dashed var(--line);
  background: #eef5ff;
  font-size: 12px;
  color: var(--muted);
  display: inline-flex;
  gap: 10px;
  flex-wrap: wrap;
}

.usage strong {
  font-weight: 600;
  color: var(--ink);
}

.citation {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
  margin-left: 2px;
}

.citation:hover {
  text-decoration: underline;
}

.sources {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
  display: grid;
  gap: 4px;
}

.sources-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
}

.source-list {
  display: grid;
  gap: 4px;
}

.source-card {
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #ffffff;
  padding: 10px 12px;
}

.source-link {
  list-style: none;
  appearance: none;
  border: none;
  background: none;
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
  text-align: left;
  display: inline-block;
}

.source-link::-webkit-details-marker {
  display: none;
}

.source-link::marker {
  content: '';
}

.source-details {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
  font-size: 12px;
  color: var(--muted);
  white-space: pre-wrap;
  display: none;
  gap: 6px;
}

.source-card[open] .source-details {
  display: grid;
}

.source-link-url {
  color: var(--accent);
  word-break: break-all;
}

.source-score {
  font-size: 11px;
  color: var(--muted);
}

.composer {
  position: absolute;
  left: 50%;
  width: min(980px, calc(100% - 48px));
  transform: translateX(-50%);
  bottom: 18px;
  padding: 18px 18px 16px;
  border-radius: 24px;
  border: none;
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(20px);
  box-shadow: 0 20px 40px rgba(9, 25, 48, 0.1);
  z-index: 2;
}

.composer textarea {
  padding: 4px 84px 0 4px;
}

.composer-status {
  position: absolute;
  top: 16px;
  right: 16px;
}

.hint {
  color: var(--muted);
  font-size: 12px;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 820px) {
  body {
    padding: 12px;
  }

  .app-header {
    padding-inline: 2px;
  }

  .app-title {
    font-size: 28px;
  }

  .card {
    height: calc(100vh - 88px);
    padding: 14px;
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 14px;
  }

  .conversation-pane {
    padding: 0 0 14px;
    border-right: none;
    border-bottom: 1px solid var(--line);
    display: grid;
    grid-template-columns: minmax(132px, 180px) minmax(0, 1fr) minmax(110px, 140px);
    align-items: center;
    gap: 12px;
  }

  .main-pane {
    padding-left: 0;
  }

  .control-bar {
    grid-template-columns: 1fr;
  }

  .composer {
    left: 50%;
    width: calc(100% - 28px);
    transform: translateX(-50%);
    bottom: 14px;
    padding: 16px;
  }

  .chat-window {
    padding: 10px 10px 236px;
  }

  .bubble {
    max-width: 100%;
  }

  .actions {
    align-items: flex-start;
  }
}

/* Full-height chat workspace. Keep message/rendering classes shared with the API client. */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --ink: #192a3a;
  --muted: #586978;
  --panel: #f3f6f8;
  --panel-strong: #ffffff;
  --accent: #005bbb;
  --line: #d9e2e9;
  --code-bg: #edf2f6;
  --user-bg: #e7f0fa;
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #151c24;
  --ink: #e3ebf3;
  --muted: #a5b5c5;
  --panel: #10171e;
  --panel-strong: #1e2833;
  --accent: #7cbaff;
  --line: #344453;
  --code-bg: #263341;
  --user-bg: #243b53;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #151c24; --ink: #e3ebf3; --muted: #a5b5c5;
    --panel: #10171e; --panel-strong: #1e2833; --accent: #7cbaff;
    --line: #344453; --code-bg: #263341; --user-bg: #243b53;
  }
}
html, body { height: 100%; overflow: hidden; }
body { padding: 0; min-height: 0; display: block; background: var(--bg); }
button, select, textarea { font: inherit; }
button { touch-action: manipulation; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
[hidden] { display: none !important; }
.shell { width: 100%; height: 100vh; height: var(--viewport-height, 100dvh); min-height: 0; display: block; }
.card {
  height: 100%; padding: 0; border-radius: 0; box-shadow: none;
  background: var(--bg); backdrop-filter: none; animation: none;
  grid-template-columns: 264px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr);
}
.conversation-pane {
  display: flex; flex-direction: column; align-items: stretch; gap: 14px; min-height: 0;
  padding: max(18px, env(safe-area-inset-top)) 16px max(14px, env(safe-area-inset-bottom));
  background: var(--panel); border-right: 1px solid var(--line); border-bottom: 0;
  overflow-y: auto; overscroll-behavior: contain;
}
.sidebar-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.app-title { font-family: inherit; font-size: 22px; letter-spacing: .06em; line-height: 1.35; }
.app-title span { display: block; font-size: 13px; font-weight: 500; letter-spacing: .04em; text-transform: none; color: var(--muted); }
.conversation-pane .icon-btn { width: 44px; flex: 0 0 44px; font-size: 26px; }
.btn { background: #005bbb; border: 1px solid transparent; border-radius: 12px; box-shadow: none; min-height: 44px; }
.btn.secondary { background: var(--panel-strong); color: var(--ink); border-color: var(--line); }
.btn:hover:not(:disabled) { filter: brightness(.94); }
.btn.is-stop { background: #923d30; color: #fff; border-color: transparent; }
.control-bar { display: grid; grid-template-columns: minmax(0, 1fr); padding: 0; gap: 12px; order: 1; }
.sidebar-header { order: -2; }
#newChat { order: -1; }
#startChat { order: 2; }
.sidebar-note { order: 3; margin: -6px 0 0; font-size: 11px; color: var(--muted); line-height: 1.5; }
.history-field { order: 4; padding-top: 14px; border-top: 1px solid var(--line); }
.sidebar-footer { order: 5; margin-top: auto; padding-top: 16px; display: grid; gap: 8px; }
.control-field.inline-field { display: flex; flex-direction: column; align-items: stretch; gap: 8px; }
.icon-label { width: auto; height: auto; justify-content: flex-start; gap: 8px; font-size: 12px; text-transform: none; letter-spacing: .02em; color: var(--muted); }
.icon-label .sr-only { position: static; width: auto; height: auto; margin: 0; clip: auto; overflow: visible; white-space: normal; }
select { color: var(--ink); background: var(--panel-strong); border: 1px solid var(--line); border-radius: 10px; min-height: 44px; font-size: 14px; }
select:disabled { opacity: .65; cursor: not-allowed; }
.conversation-pane .control-field.inline-field { gap: 6px; }
.conversation-pane .btn { min-height: 40px; padding: 8px 12px; font-size: 14px; border-radius: 10px; }
.conversation-pane .icon-btn { width: 40px; height: 40px; flex-basis: 40px; padding: 0; font-size: 24px; }
.conversation-pane select { min-height: 40px; padding: 8px 10px; font-size: 13px; border-radius: 8px; }
.sidebar-rail { display: none; flex-direction: column; gap: 8px; padding: 12px 8px; background: var(--panel); border-right: 1px solid var(--line); }
#openSidebar { width: 44px; height: 44px; }
#railNewChat { font-size: 26px; width: 44px; height: 44px; }
.card.sidebar-collapsed { grid-template-columns: 60px minmax(0, 1fr); }
.sidebar-collapsed .conversation-pane { display: none; }
.sidebar-collapsed .sidebar-rail { display: flex; }
.sidebar-backdrop { display: none; }
.main-pane { padding: 0; display: grid; grid-template-rows: minmax(0, 1fr) auto; gap: 0; overflow: hidden; }
.chat-window {
  border-radius: 0; background: transparent; height: auto;
  padding: 40px max(28px, calc((100% - 820px) / 2)) 28px;
  gap: 28px; overflow-x: hidden; overscroll-behavior: contain;
}
.empty-state { margin: auto 0; padding: 32px 0; text-align: left; }
.empty-eyebrow { color: var(--accent); font-size: 11px; font-weight: 600; letter-spacing: .14em; }
.empty-state h2 { color: var(--ink); font-size: clamp(24px, 3vw, 36px); line-height: 1.35; letter-spacing: -.03em; font-weight: 500; margin: 16px 0 12px; }
.empty-state p { margin: 0; line-height: 1.7; }
.bubble { min-width: 0; overflow-wrap: anywhere; box-shadow: none; max-width: 100%; line-height: 1.8; }
.bubble.user { max-width: 85%; padding: 12px 18px; background: var(--user-bg); color: var(--ink); border-radius: 18px 18px 4px 18px; }
.bubble.assistant { width: 100%; background: transparent; padding: 0; line-height: 1.8; }
.bubble.assistant code, .bubble.assistant pre { background: var(--code-bg); }
.bubble.assistant pre { max-width: 100%; white-space: pre; }
.bubble.assistant table { display: block; overflow-x: auto; max-width: 100%; border-collapse: collapse; }
.bubble.assistant th, .bubble.assistant td { border: 1px solid var(--line); padding: 8px 12px; }
.bubble.assistant a { color: var(--accent); }
.bubble.assistant img { max-width: 100%; height: auto; }
.answer-body.plain-text, .thinking-body.plain-text { white-space: pre-wrap; }
.thinking-block, .source-card, .usage { background: var(--panel); }
.katex-display { overflow-x: auto; overflow-y: hidden; }
.composer {
  position: relative; left: auto; bottom: auto; transform: none;
  width: min(820px, calc(100% - 56px)); margin: 0 auto max(24px, env(safe-area-inset-bottom));
  padding: 10px 12px; display: grid; grid-template-columns: minmax(0, 1fr) 28px 44px;
  align-items: end; gap: 8px; border: 1px solid var(--line); border-radius: 20px;
  background: var(--panel-strong); backdrop-filter: none; box-shadow: 0 4px 20px #00000008;
}
.composer:focus-within { border-color: var(--accent); }
.composer textarea { grid-column: 1; grid-row: 1; padding: 10px 4px; min-height: 44px; height: 44px; max-height: min(180px, 30dvh); line-height: 24px; color: var(--ink); border: 0; border-radius: 0; overflow-y: hidden; }
.composer textarea::placeholder { color: var(--muted); }
.composer-status { grid-column: 2; grid-row: 1; position: static; height: 44px; display: flex; align-items: center; }
.status { width: 26px; height: 26px; box-shadow: none; background: var(--panel); color: var(--muted); border-color: var(--line); }
.actions { grid-column: 3; grid-row: 1; }
.action-buttons, .actions { gap: 0; }
#send { width: 44px; height: 44px; }
.startup-error #startupRetry { width: 100%; min-height: 44px; padding: 12px 20px; border-radius: 12px; line-height: 1.5; }
@media (max-width: 820px) {
  .card, .card.sidebar-collapsed { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); gap: 0; padding: 0; }
  .conversation-pane { position: absolute; inset: 0 auto 0 0; width: min(288px, calc(100% - 48px)); z-index: 5; box-shadow: 16px 0 60px #0003; gap: 14px; }
  .sidebar-backdrop:not([hidden]) { display: block; position: absolute; inset: 0; border: 0; background: #0006; z-index: 4; }
  .sidebar-rail { position: absolute; top: env(safe-area-inset-top, 0px); left: env(safe-area-inset-left, 0px); z-index: 3; flex-direction: row; background: transparent; border: 0; padding: 8px; }
  .chat-window { padding: max(56px, calc(env(safe-area-inset-top) + 56px)) 16px 16px; gap: 16px; }
  .composer { width: calc(100% - 24px); margin-bottom: max(12px, env(safe-area-inset-bottom)); padding: 8px; gap: 6px; border-radius: 18px; }
  .bubble { font-size: 15px; line-height: 1.6; }
  .bubble.assistant { line-height: 1.6; }
  .bubble.user { max-width: 90%; padding: 10px 14px; }
  .bubble.assistant p { margin: 0 0 .6em; }
  .bubble.assistant p:last-child { margin-bottom: 0; }
  .bubble.assistant ul, .bubble.assistant ol { margin: .5em 0; padding-left: 1.5em; }
  .bubble.assistant li > p { margin-bottom: .3em; }
  .bubble.assistant h1, .bubble.assistant h2, .bubble.assistant h3 { margin: .6em 0 .35em; line-height: 1.35; }
  .bubble.assistant pre { margin: .6em 0; }
  .empty-state h2 { font-size: 28px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Application interface controls. */
:root {
  --ui-control-size: 44px;
  --ui-source-color: #005bbb;
}
:root[data-theme='dark'] { --ui-source-color: #8bbcff; }
body { font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Yu Gothic UI', Meiryo, sans-serif; }
.app-title { font-family: inherit; }

/* Sidebar: identical row sizes and spacing in expanded and collapsed views */
.conversation-pane {
  gap: 8px;
  padding-top: max(12px, env(safe-area-inset-top));
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}
.sidebar-rail {
  padding-top: max(12px, env(safe-area-inset-top));
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}
.sidebar-header { height: var(--ui-control-size); flex: 0 0 var(--ui-control-size); }
.sidebar-header .app-title { line-height: 1.2; }
.conversation-pane #closeSidebar {
  width: var(--ui-control-size);
  height: var(--ui-control-size);
  min-height: var(--ui-control-size);
  flex-basis: var(--ui-control-size);
}
.sidebar-rail > button { flex-shrink: 0; }
.document-source-field {
  order: -2;
  position: relative;
  height: var(--ui-control-size);
  flex: 0 0 var(--ui-control-size);
}
.document-source-field::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -4px;
  height: 1px;
  background: var(--line);
}
.conversation-pane #documentSource, #railDocumentSource {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  width: var(--ui-control-size);
  height: var(--ui-control-size);
  min-height: var(--ui-control-size);
  padding: 0;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.2;
  background: transparent;
  color: var(--ui-source-color);
  border: 0;
  box-shadow: none;
}
#railDocumentSource { align-self: center; }
.document-source-toggle svg { width: 28px; height: 28px; flex-shrink: 0; }
.document-source-code {
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}
.conversation-pane #documentSource:hover:not(:disabled), #railDocumentSource:hover:not(:disabled) {
  color: var(--accent);
}
.conversation-pane #newChat {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  height: var(--ui-control-size);
  flex: 0 0 var(--ui-control-size);
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
}
.conversation-pane #newChat:hover:not(:disabled) { color: var(--accent); }
.new-question-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--ui-control-size);
  height: var(--ui-control-size);
  flex: 0 0 var(--ui-control-size);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-strong);
  color: var(--ink);
  font-size: 26px;
  line-height: 1;
  font-weight: 400;
}
.sidebar-footer { justify-items: start; }
.conversation-pane #legalLink, #railLegalLink {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--ui-control-size);
  height: var(--ui-control-size);
  min-height: var(--ui-control-size);
  flex: 0 0 var(--ui-control-size);
  padding: 9px;
  border-radius: 10px;
  text-decoration: none;
}
.legal-icon svg { width: 24px; height: 24px; }
#railLegalLink { margin-top: auto; align-self: center; }
.conversation-pane .control-field:has(select:enabled) .icon-label {
  color: var(--ink);
}
.conversation-pane .control-field:has(select:disabled) .icon-label {
  color: var(--muted);
  opacity: .65;
}
.conversation-pane #logoutBtn, #railLogoutBtn {
  width: var(--ui-control-size);
  height: var(--ui-control-size);
  min-height: var(--ui-control-size);
  padding: 9px;
  border-radius: 10px;
}
#logoutBtn svg, #railLogoutBtn svg { width: 24px; height: 24px; }
#railLogoutBtn { align-self: center; }

/* Main conversation controls */
.empty-eyebrow {
  font-size: clamp(22px, 2vw, 28px);
  font-weight: 600;
  letter-spacing: .02em;
  text-transform: none;
}
#themeToggle {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 3;
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 7px;
  border-radius: 10px;
}
#themeToggle svg { width: 18px; height: 18px; }
#themeToggle .theme-sun { display: none; }
:root[data-theme='dark'] #themeToggle .theme-moon { display: none; }
:root[data-theme='dark'] #themeToggle .theme-sun { display: block; }
.chat-window { padding-top: max(60px, calc(env(safe-area-inset-top) + 60px)); }
.composer { grid-template-columns: minmax(0, 1fr) 32px; }
.composer .actions { grid-column: 2; align-self: center; }
.composer-feedback {
  grid-column: 1 / -1;
  grid-row: 2;
  min-width: 0;
  margin: 0;
  padding: 2px 4px 4px;
  color: #a52c25;
  font-size: 13px;
  line-height: 1.6;
  white-space: normal;
  overflow-wrap: anywhere;
}
:root[data-theme='dark'] .composer-feedback { color: #ffb4ab; }
#send { width: 32px; height: 32px; min-height: 32px; padding: 6px; border-radius: 10px; }
#send svg { width: 20px; height: 20px; }

@media (max-width: 820px) {
  .conversation-pane { padding-top: calc(8px + env(safe-area-inset-top)); }
  .sidebar-rail { align-items: center; padding-top: 8px; padding-bottom: 8px; }
  #railLegalLink { margin-top: 0; }
}

/* Session warnings share the same layout on chat and consent screens. */
.session-warning[hidden] { display: none !important; }
.session-warning { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 20px; background: rgba(9,17,31,.55); }
.session-warning-card {
  width: min(520px, 100%);
  max-height: calc(100vh - 40px);
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  padding: clamp(24px, 5vw, 28px);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  color: var(--ink);
  overflow-wrap: anywhere;
}
.session-warning-card h2 { margin: 0 0 18px; font-size: 24px; font-weight: 600; line-height: 1.4; letter-spacing: -.02em; }
.session-warning-card p { margin: 0 0 24px; color: var(--muted); font-size: 15px; line-height: 1.8; }
.session-warning-actions { display: flex; gap: 12px; justify-content: flex-end; flex-wrap: wrap; }
.session-warning-actions button {
  appearance: none;
  min-height: 44px;
  padding: 12px 20px;
  border: 1px solid transparent;
  border-radius: 12px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.5;
  color: #fff;
  background: #005bbb;
  box-shadow: none;
  cursor: pointer;
  touch-action: manipulation;
}
.session-warning-actions #logoutSession, .session-warning-actions #returnToScreen { color: var(--ink); background: var(--panel-strong); border-color: var(--line); }
.session-warning-actions button:hover { filter: brightness(.94); }
@media (max-width: 480px) {
  .session-warning-actions > button { width: 100%; }
}
