:root {
  color-scheme: light;
  --bg: #f8fafc;
  --canvas: #f8fafc;
  --panel: #ffffff;
  --surface: #ffffff;
  --sidebar: #eef2f7;
  --text: #171717;
  --muted: #6b7280;
  --line: #d9dde3;
  --soft: #eceff3;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --accent-soft: rgba(15, 118, 110, 0.12);
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.09);
  --shadow-soft: 0 12px 34px rgba(15, 23, 42, 0.07);
  --header-bg: rgba(255, 255, 255, 0.78);
  --citation-bg: #f8fafc;
  --danger: #b42318;
  --ok: #16703c;
  --warn: #9a6700;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #080808;
  --canvas: #080808;
  --panel: #111111;
  --surface: #181818;
  --sidebar: #0f0f0f;
  --text: #f4f4f5;
  --muted: #a1a1aa;
  --line: #2a2a2a;
  --soft: #242424;
  --accent: #2dd4bf;
  --accent-dark: #5eead4;
  --accent-soft: rgba(45, 212, 191, 0.11);
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  --shadow-soft: 0 12px 30px rgba(0, 0, 0, 0.18);
  --header-bg: rgba(8, 8, 8, 0.72);
  --citation-bg: #151515;
  --danger: #f87171;
  --ok: #86efac;
  --warn: #facc15;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 56% -10%, color-mix(in srgb, var(--accent-soft) 42%, transparent), transparent 34rem),
    var(--bg);
}

body.info-page {
  min-height: 100vh;
  overflow: auto;
}

.hidden {
  display: none !important;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
}

h2 {
  font-size: 24px;
}

h3 {
  font-size: 14px;
}

p,
label,
.empty,
dd {
  color: var(--muted);
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.mobile-chat-bar,
.mobile-sidebar-backdrop {
  display: none;
}

.admin-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.admin-login-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 20px;
}

.admin-login-card {
  display: grid;
  gap: 12px;
  width: min(380px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
}

.admin-login-card strong {
  color: var(--accent-dark);
}

.admin-login-card a {
  color: var(--muted);
  font-size: 13px;
}

.admin-sidebar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 100vh;
  overflow-y: auto;
  padding: 12px;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
}

.admin-main {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  min-width: 0;
}

.admin-dashboard-main {
  overflow: hidden;
}

.admin-nav {
  gap: 18px;
}

.admin-menu {
  display: grid;
  gap: 6px;
}

.admin-nav-button {
  width: 100%;
  justify-content: flex-start;
  border-color: transparent;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.admin-nav-button.active,
.admin-nav-button:hover {
  border-color: var(--line);
  background: var(--panel);
}

.admin-nav-footer {
  display: grid;
  gap: 8px;
  margin-top: auto;
}

.admin-topbar {
  display: flex;
  align-items: center;
  min-height: 72px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
}

.admin-topbar p {
  margin-top: 4px;
}

.admin-view {
  display: none;
  min-height: 0;
  overflow-y: auto;
  padding: 22px 24px;
}

.admin-view.is-active {
  display: grid;
  align-content: start;
  gap: 18px;
}

.admin-view-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

.admin-chat-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  min-height: 0;
}

.admin-chat-layout .chat-results {
  min-height: 58vh;
  max-height: calc(100vh - 230px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.admin-side-panel {
  display: grid;
  align-content: start;
  gap: 16px;
}

.admin-side-panel > section,
.admin-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--panel);
}

.admin-composer {
  position: sticky;
  bottom: 0;
}

.admin-list {
  display: grid;
  gap: 10px;
}

.admin-list.empty {
  color: var(--muted);
}

.admin-list .item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel);
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 420px);
  gap: 16px;
  align-items: start;
}

.admin-grid-wide {
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
}

.admin-card .tool-results {
  max-height: 520px;
  white-space: pre-wrap;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
  padding: 12px 8px;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 40px;
  padding: 6px 8px;
}

.brand a,
.brand a:visited {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--accent);
  font-size: 16px;
  font-weight: 950;
  letter-spacing: -0.03em;
  text-decoration: none;
}

.brand a::before {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background:
    radial-gradient(circle at 34% 30%, #ffffff, transparent 18%),
    linear-gradient(135deg, var(--accent-dark), var(--accent));
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 9%, transparent);
  content: "";
}

.brand a:hover {
  color: var(--accent-dark);
}

.brand strong {
  font-weight: inherit;
}

#apiStatus {
  border: 1px solid color-mix(in srgb, var(--ok) 28%, transparent);
  background: color-mix(in srgb, var(--ok) 14%, var(--panel));
  color: color-mix(in srgb, var(--ok) 78%, var(--text));
  opacity: 0.82;
}

:root[data-theme="dark"] #apiStatus {
  background: rgba(134, 239, 172, 0.08);
  border-color: rgba(134, 239, 172, 0.16);
  color: rgba(190, 242, 100, 0.84);
  opacity: 0.72;
}

.new-chat,
.ghost-button,
.ghost-link {
  width: 100%;
  text-align: left;
}

.new-chat {
  min-height: 42px;
  border-radius: 12px;
}

.ghost-link {
  display: block;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.55);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.sidebar-section,
.sidebar-menu {
  border-radius: 14px;
}

.sidebar-section {
  display: grid;
  gap: 8px;
  padding: 8px 0;
}

.chat-sidebar-section {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
}

.section-title {
  padding: 0 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.sidebar-menu {
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(217, 221, 227, 0.8);
}

.app-shell > .sidebar .sidebar-menu,
.case-drawer {
  display: none;
}

.auth-panel .tool-results {
  max-height: none;
}

.sidebar-account {
  flex: 0 0 auto;
  margin-top: 8px;
  border-top: 1px solid color-mix(in srgb, var(--line) 68%, transparent);
  padding-top: 12px;
}

.account-state {
  display: grid;
  gap: 2px;
  overflow-wrap: anywhere;
  padding: 8px 10px;
  border: 1px solid color-mix(in srgb, var(--line) 72%, transparent);
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
}

.account-state span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.account-state strong {
  font-size: 13px;
}

.account-state.empty {
  color: var(--muted);
}

.muted-inline {
  color: var(--muted);
  font-weight: 700;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.58);
  backdrop-filter: blur(10px);
}

.modal-card {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 16px;
  width: min(460px, 100%);
  max-height: min(720px, calc(100vh - 40px));
  overflow-y: auto;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background:
    radial-gradient(circle at top right, var(--accent-soft), transparent 18rem),
    var(--panel);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.34);
}

.modal-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.modal-close {
  width: auto;
  min-width: 38px;
  padding: 7px 10px;
  text-align: center;
}

.modal-form {
  display: grid;
  gap: 12px;
}

.experience-card {
  width: min(620px, 100%);
}

.experience-support {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 14px;
  border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--line));
  border-radius: 18px;
  background:
    radial-gradient(circle at bottom right, color-mix(in srgb, var(--accent-soft) 70%, transparent), transparent 12rem),
    color-mix(in srgb, var(--surface) 72%, transparent);
}

.experience-support strong {
  display: block;
  margin-bottom: 4px;
  color: var(--text);
}

.experience-support p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.experience-support a {
  color: var(--accent);
  font-size: 13px;
  font-weight: 900;
}

.experience-support figure {
  display: grid;
  gap: 6px;
  justify-items: center;
  margin: 0;
}

.experience-support img {
  width: 104px;
  height: 104px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

.experience-support figcaption {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.rating-field {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
}

.rating-field legend {
  flex-basis: 100%;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.rating-field label {
  display: inline-grid;
  cursor: pointer;
}

.rating-field input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.rating-field span {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 76%, transparent);
  color: var(--text);
  font-weight: 950;
  transition:
    background 0.16s ease,
    border-color 0.16s ease,
    transform 0.16s ease;
}

.rating-field label:hover span,
.rating-field input:focus-visible + span {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.rating-field input:checked + span {
  border-color: var(--accent);
  background: var(--accent);
  color: #042f2e;
}

.active-chat {
  background: color-mix(in srgb, var(--panel) 84%, var(--accent-soft));
}

.chat-item-menu {
  position: relative;
  z-index: 20;
}

.chat-item-menu summary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  color: color-mix(in srgb, var(--text) 72%, var(--muted));
  cursor: pointer;
  list-style: none;
}

.chat-item-menu summary::-webkit-details-marker {
  display: none;
}

.chat-item-menu summary:hover {
  background: var(--soft);
  color: var(--text);
}

.chat-item-menu > div {
  position: absolute;
  right: 0;
  top: 32px;
  z-index: 100;
  display: grid;
  min-width: 140px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.chat-item-menu button {
  width: 100%;
  padding: 9px 10px;
  border-radius: 8px;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  opacity: 1;
}

.chat-item-menu button:hover {
  background: var(--soft);
}

.sidebar-menu > summary,
.sub-menu > summary {
  cursor: pointer;
  font-weight: 800;
}

.sidebar-menu > summary {
  padding: 10px;
}

.sub-menu {
  border-top: 1px solid var(--line);
  padding: 10px 0 0;
}

.sub-menu > summary {
  margin-bottom: 10px;
  color: var(--accent-dark);
}

.menu-form,
.sidebar-menu > label {
  display: grid;
  gap: 9px;
  padding: 0 10px 10px;
}

.menu-form > label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
}

.menu-form > label:has(input[type="checkbox"]) {
  display: flex;
  align-items: center;
  color: var(--text);
}

.sidebar-list,
.tool-results,
.list,
.results {
  display: grid;
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
  padding: 0 2px;
}

.sidebar-list {
  align-content: start;
  flex: 1 1 auto;
  grid-auto-rows: max-content;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  padding: 2px 3px 2px 2px;
  scrollbar-width: thin;
}

.sidebar-list .item {
  position: relative;
  overflow: visible;
}

.sidebar-list.empty {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  padding: 16px;
  border: 1px dashed var(--line);
  border-radius: 16px;
  color: var(--muted);
  text-align: center;
}

.chat-main {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  min-width: 0;
  background:
    radial-gradient(circle at top right, color-mix(in srgb, var(--accent-soft) 26%, transparent), transparent 34rem),
    var(--bg);
}

.chat-header {
  display: flex;
  justify-content: center;
  border-bottom: 0;
  background: color-mix(in srgb, var(--header-bg) 72%, transparent);
  backdrop-filter: blur(16px);
}

.chat-header > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: min(920px, 100%);
  padding: 12px 22px 8px;
}

.chat-header h1 {
  font-size: 16px;
  letter-spacing: -0.02em;
}

.chat-header p {
  margin-top: 3px;
  font-size: 13px;
}

.theme-toggle {
  flex: 0 0 auto;
  border: 1px solid color-mix(in srgb, var(--line) 72%, transparent);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  box-shadow: none;
}

.theme-toggle:hover {
  background: var(--soft);
}

.sidebar-theme-toggle {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 9px;
  width: 100%;
  min-height: 38px;
  padding: 8px 12px;
  border-radius: 12px;
  color: var(--muted);
  font-size: 13px;
}

.button-icon {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  color: var(--accent-dark);
  font-size: 15px;
}

.sidebar-links {
  display: grid;
  flex: 0 0 auto;
  gap: 8px;
  margin-top: 0;
  padding: 12px 0 0;
  border-top: 1px solid var(--line);
}

.sidebar-links a {
  color: var(--muted);
  font-size: 13px;
}

.info-page {
  min-height: 100vh;
  padding: 48px 20px;
  background: var(--canvas);
}

.info-page > main {
  width: min(820px, 100%);
  margin: 0 auto;
}

.info-page header {
  display: grid;
  gap: 12px;
  margin-bottom: 32px;
}

.info-page h1 {
  font-size: clamp(30px, 5vw, 48px);
}

.info-page section {
  margin: 24px 0;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
}

.support-qr-section {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px;
  align-items: center;
}

.support-qr {
  display: grid;
  gap: 10px;
  justify-items: center;
  margin: 0;
}

.support-qr img {
  width: min(220px, 56vw);
  height: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
  box-shadow: var(--shadow-soft);
}

.support-qr figcaption {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.info-page li + li {
  margin-top: 8px;
}

.chat-results {
  display: grid;
  align-content: start;
  gap: 26px;
  overflow-y: auto;
  padding: 28px 24px 136px;
  scroll-behavior: smooth;
}

.chat-results > * {
  width: min(820px, 100%);
  justify-self: center;
}

.chat-timeline {
  position: fixed;
  top: 50%;
  right: 12px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transform: translateY(-50%);
}

.timeline-mark {
  width: 20px;
  height: 2px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 44%, transparent);
  box-shadow: none;
  opacity: 0.62;
}

.timeline-mark.user {
  width: 14px;
}

.timeline-mark.assistant {
  width: 22px;
}

.timeline-mark:hover,
.timeline-mark.active {
  background: var(--accent);
  opacity: 1;
  transform: none;
}

.scroll-latest {
  position: fixed;
  right: calc(50% - 130px);
  bottom: 118px;
  z-index: 40;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--line) 80%, transparent);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  color: var(--text);
  box-shadow: var(--shadow-soft);
}

.scroll-latest:hover {
  background: var(--soft);
}

.welcome-card {
  display: grid;
  gap: 14px;
  margin-top: min(15vh, 120px);
  text-align: center;
}

.welcome-card::before {
  justify-self: center;
  width: 66px;
  height: 66px;
  border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--line));
  border-radius: 24px;
  background:
    radial-gradient(circle at 36% 28%, rgba(255, 255, 255, 0.95), transparent 12%),
    radial-gradient(circle at 72% 70%, color-mix(in srgb, var(--accent) 42%, transparent), transparent 26%),
    linear-gradient(135deg, color-mix(in srgb, var(--panel) 40%, var(--accent-soft)), var(--panel));
  box-shadow: 0 24px 80px color-mix(in srgb, var(--accent) 24%, transparent);
  content: "";
}

.welcome-card span {
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.welcome-card p {
  max-width: 640px;
  justify-self: center;
  line-height: 1.55;
}

.chat-answer {
  display: grid;
  gap: 10px;
}

.answer-body {
  display: grid;
  gap: 14px;
}

.answer-body p,
.answer-body ul {
  margin: 0;
}

.answer-body ul {
  padding-left: 20px;
}

.answer-body li + li {
  margin-top: 5px;
}

.answer-section {
  display: grid;
  gap: 10px;
}

.answer-lead {
  color: var(--text);
  font-size: 16px;
  font-weight: 640;
}

.answer-point {
  padding-left: 12px;
  border-left: 3px solid var(--accent);
  color: var(--text);
}

.chat-message {
  max-width: 760px;
  border-radius: 24px;
  padding: 13px 16px;
  line-height: 1.58;
}

.message-meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
}

.loading-progress-text {
  color: var(--text);
}

.stream-answer-preview {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--text);
  white-space: pre-wrap;
}

.user-message {
  justify-self: end;
  max-width: min(680px, 74%);
  background: color-mix(in srgb, var(--soft) 88%, var(--panel));
  border: 0;
}

.user-message-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.user-message-text {
  min-width: 0;
}

.message-edit-button {
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
  opacity: 0;
}

.user-message:hover .message-edit-button,
.message-edit-button:focus-visible {
  opacity: 1;
}

.message-edit-button:hover {
  background: color-mix(in srgb, var(--line) 38%, transparent);
  color: var(--text);
  transform: none;
}

.assistant-message {
  justify-self: start;
  width: min(820px, 100%);
  max-width: min(820px, 100%);
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.assistant-message strong {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.chat-citations {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.answer-suggestions {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid color-mix(in srgb, var(--line) 68%, transparent);
}

.suggestions-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.suggestion-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.suggestion-chip {
  width: auto;
  min-height: 34px;
  padding: 7px 11px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--accent) 42%, var(--line));
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  color: var(--text);
  font-size: 13px;
  font-weight: 750;
  box-shadow: none;
}

.suggestion-chip:hover,
.suggestion-chip:focus-visible {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 18%, var(--panel));
  transform: translateY(-1px);
}

.answer-details {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0;
  background: color-mix(in srgb, var(--panel) 56%, transparent);
}

.answer-details > summary {
  cursor: pointer;
  padding: 11px 13px;
  color: var(--accent-dark);
  font-weight: 800;
}

.answer-details > *:not(summary) {
  margin: 0 12px 12px;
}

.chat-citation {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  border-left: 3px solid var(--accent);
  background: var(--citation-bg);
  color: var(--text);
  font-size: 13px;
}

.dev-chat {
  max-height: 360px;
}

.dev-message {
  display: grid;
  gap: 4px;
  border-radius: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  line-height: 1.4;
}

.dev-message.user {
  background: var(--soft);
}

.dev-message strong {
  font-size: 12px;
}

.citation-number {
  color: var(--accent-dark);
  font-weight: 900;
}

.case-drawer {
  padding: 0 20px 10px;
}

.case-drawer details {
  width: min(880px, 100%);
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.case-drawer summary {
  cursor: pointer;
  padding: 10px 12px;
  font-weight: 800;
}

.case-drawer .tool-results {
  max-height: 260px;
  padding: 0 12px 12px;
}

.composer {
  position: fixed;
  right: max(20px, calc((100vw - 260px - 860px) / 2));
  bottom: 18px;
  left: max(280px, calc(260px + (100vw - 260px - 860px) / 2));
  z-index: 30;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  width: auto;
  margin: 0;
  padding: 9px;
  border: 1px solid color-mix(in srgb, var(--line) 74%, transparent);
  border-radius: 28px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: 0 16px 56px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(20px);
}

.composer-input {
  display: grid;
  gap: 8px;
}

.composer-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.composer-actions {
  justify-content: flex-end;
  align-content: end;
}

.composer-submit {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  padding: 0;
  color: #042f2e;
  box-shadow:
    0 10px 22px color-mix(in srgb, var(--accent) 28%, transparent),
    inset 0 0 0 1px color-mix(in srgb, #fff 18%, transparent);
}

.composer-submit svg {
  width: 25px;
  height: 25px;
  fill: currentColor;
}

.composer-submit.is-generating {
  background: color-mix(in srgb, var(--text) 92%, var(--surface));
  color: var(--bg);
  box-shadow:
    0 10px 22px rgba(0, 0, 0, 0.24),
    inset 0 0 0 1px color-mix(in srgb, var(--bg) 35%, transparent);
}

.composer-submit.is-generating svg {
  width: 28px;
  height: 28px;
}

.composer-submit.is-generating:hover {
  background: color-mix(in srgb, var(--text) 82%, var(--surface));
}

.composer textarea {
  min-height: 44px;
  max-height: 150px;
  resize: none;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.composer textarea:focus {
  border-color: transparent;
  box-shadow: none;
}

label {
  display: grid;
  gap: 5px;
  font-size: 12px;
  font-weight: 800;
}

input,
textarea,
select,
button {
  font: inherit;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid color-mix(in srgb, var(--line) 82%, transparent);
  border-radius: 15px;
  padding: 9px 10px;
  color: var(--text);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
}

input:focus,
textarea:focus,
select:focus {
  border-color: color-mix(in srgb, var(--accent) 52%, var(--line));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-soft) 80%, transparent);
  outline: 0;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 9px 13px;
  background: var(--accent);
  color: #042f2e;
  font-weight: 800;
  cursor: pointer;
  transition:
    background 0.16s ease,
    border-color 0.16s ease,
    transform 0.16s ease,
    opacity 0.16s ease;
}

button:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

button.secondary,
.ghost-button {
  border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  background: color-mix(in srgb, var(--panel) 42%, transparent);
  color: var(--text);
}

button.secondary:hover,
.ghost-button:hover {
  background: var(--soft);
}

.new-chat:hover {
  background: var(--accent-dark);
  color: var(--bg);
}

button.danger {
  background: var(--danger);
  color: #fff;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.row-actions,
.actions {
  display: flex;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 8px;
}

.chat-answer .actions {
  margin-top: 4px;
}

.chat-answer .actions button {
  min-height: 32px;
  padding: 6px 10px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  box-shadow: none;
}

.chat-answer .actions button:hover {
  background: var(--soft);
  color: var(--text);
}

.item {
  border: 1px solid color-mix(in srgb, var(--line) 72%, transparent);
  border-radius: 12px;
  padding: 9px;
  background: transparent;
}

.sidebar .item {
  padding: 10px;
}

.sidebar .investigation-item {
  min-height: 44px;
  border-color: transparent;
  border-left: 0;
  border-radius: 10px;
  background: transparent;
  box-shadow: none;
}

.sidebar .investigation-item:hover {
  border-color: transparent;
  background: var(--soft);
  transform: none;
}

.sidebar .investigation-item strong {
  display: -webkit-box;
  overflow: hidden;
  color: var(--text);
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.sidebar .investigation-item.active-chat {
  border-color: transparent;
  background: color-mix(in srgb, var(--soft) 76%, var(--accent-soft));
  box-shadow: inset 3px 0 0 var(--accent);
  outline: 0;
}

.item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.pill {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border-radius: 999px;
  padding: 3px 8px;
  background: color-mix(in srgb, var(--soft) 80%, transparent);
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  white-space: nowrap;
}

.pill.completed,
.pill.ok {
  background: #e7f6ec;
  color: var(--ok);
}

.pill.failed,
.pill.error {
  background: #fdecec;
  color: var(--danger);
}

.pill.pending,
.pill.running {
  background: #fff4d6;
  color: var(--warn);
}

dl {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 5px 8px;
  margin: 8px 0 0;
  font-size: 12px;
}

dt {
  font-weight: 900;
}

dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.result-kind {
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.result-text {
  margin-top: 6px;
  color: var(--text);
  line-height: 1.42;
}

.claim-item,
.citation-item,
.draft-answer,
.source-page,
.topic-page,
.investigation-page,
.investigation-item {
  border-left: 4px solid var(--accent);
}

.bundle-group {
  border-left: 4px solid #7c3aed;
}

.bundle-row {
  padding: 8px 0;
  border-top: 1px solid var(--line);
  color: var(--text);
}

.error-text {
  color: var(--danger);
}

@media (max-width: 860px) {
  html,
  body {
    height: 100dvh;
    overflow: hidden;
  }

  .mobile-chat-bar {
    position: sticky;
    top: 0;
    z-index: 80;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 8px;
    align-items: center;
    padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
    border-bottom: 1px solid var(--line);
    background: color-mix(in srgb, var(--sidebar) 96%, transparent);
    backdrop-filter: blur(18px);
  }

  .mobile-brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    color: var(--accent);
    font-weight: 950;
    letter-spacing: -0.03em;
    text-decoration: none;
  }

  .mobile-brand::before {
    flex: 0 0 auto;
    width: 20px;
    height: 20px;
    border-radius: 999px;
    background:
      radial-gradient(circle at 34% 30%, #ffffff, transparent 18%),
      linear-gradient(135deg, var(--accent-dark), var(--accent));
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 9%, transparent);
    content: "";
  }

  .mobile-new-chat {
    width: auto;
    min-height: 36px;
    padding: 7px 12px;
    border-radius: 999px;
    white-space: nowrap;
  }

  .mobile-menu-toggle {
    display: inline-grid;
    place-items: center;
    width: 40px;
    height: 36px;
    padding: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--text);
  }

  .mobile-sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 85;
    display: block;
    border: 0;
    border-radius: 0;
    background: rgba(0, 0, 0, 0.42);
    box-shadow: none;
  }

  .app-shell,
  .admin-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr);
    height: calc(100dvh - 54px - env(safe-area-inset-top));
    min-height: 0;
  }

  .admin-sidebar {
    height: auto;
    max-height: min(58vh, 560px);
    overflow-y: auto;
    overscroll-behavior: contain;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 90;
    display: flex;
    width: min(320px, 86vw);
    height: 100dvh;
    max-height: none;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: calc(12px + env(safe-area-inset-top)) 10px calc(12px + env(safe-area-inset-bottom));
    border-right: 1px solid var(--line);
    border-bottom: 0;
    box-shadow: 24px 0 70px rgba(0, 0, 0, 0.38);
    transform: translateX(-105%);
    transition: transform 180ms ease;
  }

  body.mobile-menu-open .sidebar {
    transform: translateX(0);
  }

  .brand {
    grid-column: 1 / -1;
    min-height: 32px;
    padding: 0 4px;
  }

  .brand a,
  .brand a:visited {
    font-size: 15px;
  }

  .brand a::before {
    width: 20px;
    height: 20px;
  }

  #apiStatus {
    padding: 2px 7px;
    font-size: 10px;
  }

  .new-chat {
    min-height: 38px;
    padding: 8px 12px;
  }

  .sidebar-theme-toggle {
    justify-content: center;
    width: 100%;
    min-height: 38px;
    padding: 0 12px;
  }

  .sidebar-theme-toggle span:not(.button-icon) {
    display: inline;
  }

  .chat-sidebar-section {
    max-height: none;
    min-height: 150px;
    padding: 8px 0;
  }

  .chat-sidebar-section .section-title {
    padding: 0 4px;
    font-size: 10px;
  }

  .sidebar-list {
    display: grid;
    flex: 1 1 auto;
    gap: 8px;
    max-height: none;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 2px;
  }

  .sidebar-list.empty {
    min-height: 42px;
    padding: 8px;
  }

  .sidebar .investigation-item {
    flex: 0 0 auto;
    min-height: 38px;
    padding: 8px 10px;
  }

  .sidebar .investigation-item strong {
    -webkit-line-clamp: 1;
  }

  .sidebar-account {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
    margin-top: 0;
    padding-top: 6px;
  }

  .sidebar-account .section-title {
    display: none;
  }

  .auth-panel form {
    grid-column: 1 / -1;
  }

  .account-state {
    min-height: 0;
    padding: 6px 8px;
    font-size: 12px;
  }

  .account-state span {
    font-size: 9px;
  }

  #logoutButton {
    min-height: 34px;
    padding: 6px 10px;
  }

  .sidebar-links {
    display: grid;
  }

  .chat-main {
    height: 100%;
    min-height: 0;
    overflow: hidden;
  }

  .admin-main {
    height: auto;
    min-height: 58vh;
  }

  .chat-results {
    height: 100%;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 16px 12px 112px;
    gap: 18px;
  }

  .chat-results > * {
    width: 100%;
  }

  .message-edit-button {
    opacity: 0.78;
  }

  .admin-chat-layout,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .composer {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 8px;
    right: 10px;
    bottom: 10px;
    left: 10px;
    max-height: none;
    overflow: hidden;
    padding: 8px;
    border-radius: 24px;
  }

  .composer textarea {
    min-height: 40px;
    max-height: 108px;
    padding: 9px 4px;
  }

  .composer-actions {
    justify-content: flex-end;
  }

  .composer-actions button[type="submit"] {
    min-height: 42px;
    padding: 9px 14px;
  }

  .case-drawer {
    display: none;
  }

  .chat-timeline {
    display: none;
  }

  .scroll-latest {
    right: 50%;
    bottom: 94px;
    transform: translateX(50%);
  }

  .support-qr-section {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 430px) {
  .sidebar .investigation-item {
    flex-basis: 150px;
  }

  .chat-results {
    padding-bottom: 112px;
  }

  .composer {
    border-radius: 22px;
  }

  .experience-support {
    grid-template-columns: 1fr;
  }
}
