:root {
  color-scheme: light;
  --bg: #F7F9FC;
  --card: #FFFFFF;
  --card-soft: rgba(255, 255, 255, 0.86);
  --text: #0F172A;
  --text-soft: #334155;
  --muted: #64748B;
  --border: rgba(15, 23, 42, 0.10);
  --border-strong: rgba(15, 23, 42, 0.16);
  --primary: #2563EB;
  --primary-2: #3B82F6;
  --green: #16A34A;
  --yellow: #D97706;
  --red: #DC2626;
  --shadow: 0 24px 70px rgba(15, 23, 42, 0.10), 0 2px 8px rgba(15, 23, 42, 0.04);
  --shadow-soft: 0 12px 38px rgba(15, 23, 42, 0.08);
  --ring: 0 0 0 4px rgba(37, 99, 235, 0.16);
  --sidebar-width: 300px;
  --right-width: 320px;
  --content-max: 1080px;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0F172A;
  --card: #1E293B;
  --card-soft: rgba(30, 41, 59, 0.84);
  --text: #F8FAFC;
  --text-soft: #CBD5E1;
  --muted: #94A3B8;
  --border: rgba(248, 250, 252, 0.10);
  --border-strong: rgba(248, 250, 252, 0.18);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.36), 0 2px 8px rgba(0, 0, 0, 0.20);
  --shadow-soft: 0 12px 38px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }

html {
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  width: 100%;
  height: 100vh;
  min-height: 100vh;
  height: 100dvh;
  min-height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  font-family: "Geist", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 10% 8%, rgba(59, 130, 246, 0.18), transparent 30%),
    radial-gradient(circle at 88% 16%, rgba(37, 99, 235, 0.13), transparent 34%),
    var(--bg);
  font-feature-settings: "liga", "kern";
}

button, input, textarea {
  font: inherit;
  font-size: 16px;
}

button, a, textarea, input { -webkit-tap-highlight-color: transparent; }

button:focus-visible,
a:focus-visible,
textarea:focus-visible,
input:focus-visible {
  outline: 2px solid var(--primary-2);
  outline-offset: 2px;
  box-shadow: var(--ring);
}

[hidden] { display: none !important; }

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

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(24px + env(safe-area-inset-top)) calc(18px + env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) calc(18px + env(safe-area-inset-left));
  overflow-y: auto;
  overscroll-behavior: contain;
  background:
    radial-gradient(circle at 22% 16%, rgba(37, 99, 235, 0.18), transparent 32%),
    radial-gradient(circle at 78% 26%, rgba(59, 130, 246, 0.16), transparent 36%),
    var(--bg);
}

.login-bg {
  position: absolute;
  inset: 12%;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.08);
  filter: blur(70px);
  pointer-events: none;
}

.login-card {
  position: relative;
  width: min(100%, 460px);
  border: 1px solid var(--border);
  border-radius: 32px;
  padding: 34px;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
  text-align: center;
}

.login-avatar-wrap {
  width: 116px;
  height: 116px;
  aspect-ratio: 1 / 1;
  margin: 0 auto 18px;
  padding: 4px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 22px 48px rgba(37, 99, 235, 0.24);
  overflow: hidden;
}

.login-avatar,
.brand-avatar,
.avatar-assistant,
.mobile-header-avatar {
  display: block;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  object-position: center;
  border-radius: 50%;
}

.login-avatar {
  width: 100%;
  height: 100%;
  border: 2px solid color-mix(in srgb, var(--primary) 16%, #fff);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.38);
}

.login-card h1 {
  margin: 18px 0 10px;
  font-size: clamp(2rem, 7vw, 3rem);
  line-height: 1;
  letter-spacing: -0.06em;
}

.login-card p {
  margin: 0 auto 22px;
  max-width: 340px;
  color: var(--muted);
  line-height: 1.5;
}

.login-card input {
  width: 100%;
  min-height: 54px;
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  padding: 0 16px;
  color: var(--text);
  background: var(--card);
  outline: none;
}

.login-button {
  width: 100%;
  min-height: 54px;
  margin-top: 12px;
  border: 0;
  border-radius: 18px;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 18px 34px rgba(37, 99, 235, 0.25);
  cursor: pointer;
  font-weight: 700;
  transition: transform 180ms ease, filter 180ms ease;
}

.login-button:hover { transform: translateY(-1px); }
.login-button:active { transform: scale(0.985); }
.login-button:disabled { opacity: 0.68; cursor: not-allowed; filter: grayscale(0.25); }

.login-error {
  min-height: 22px;
  margin: 12px 0 0 !important;
  color: var(--red) !important;
  font-size: 14px;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  width: 100%;
  height: 100vh;
  min-height: 100vh;
  height: 100dvh;
  min-height: 100dvh;
  overflow: hidden;
}

.sidebar {
  position: relative;
  z-index: 20;
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 100vh;
  height: 100dvh;
  min-height: 100dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: calc(24px + env(safe-area-inset-top)) 22px calc(24px + env(safe-area-inset-bottom));
  border-right: 1px solid var(--border);
  background: color-mix(in srgb, var(--card) 90%, transparent);
  backdrop-filter: blur(24px);
}

.brand-block { padding: 4px 4px 24px; }

.brand-row {
  display: flex;
  align-items: center;
  gap: 13px;
}

.brand-avatar {
  width: 58px;
  height: 58px;
  border: 2px solid rgba(37, 99, 235, 0.18);
  box-shadow: 0 14px 30px rgba(37, 99, 235, 0.18);
}

.brand-kicker {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.brand-block h1,
.topbar h2 {
  margin: 0;
  letter-spacing: -0.045em;
  line-height: 1.05;
}

.brand-block h1 { font-size: 20px; font-weight: 700; }

.brand-description {
  margin: 16px 0 14px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.mvp-badge,
.chip,
.mini-label {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  gap: 6px;
  border-radius: 999px;
  border: 1px solid rgba(37, 99, 235, 0.18);
  background: rgba(37, 99, 235, 0.09);
  color: var(--primary);
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
}

.nav-list {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 14px;
  padding: 10px 12px;
  color: var(--text-soft);
  background: transparent;
  text-decoration: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 560;
  transition: background 180ms ease, color 180ms ease, transform 180ms ease;
}

.nav-item span {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.nav-item em {
  margin-left: auto;
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(37, 99, 235, 0.10);
  color: var(--text);
}

.nav-item:active { transform: scale(0.985); }
.nav-item:disabled { cursor: not-allowed; opacity: 0.68; }

.sidebar-footer {
  margin-top: auto;
  padding-top: 18px;
}

.profile-card,
.mini-card,
.chat-card {
  border: 1px solid var(--border);
  background: var(--card-soft);
  box-shadow: var(--shadow-soft);
}

.profile-card {
  display: flex;
  align-items: center;
  gap: 12px;
  border-radius: 20px;
  padding: 12px;
}

.profile-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.profile-card strong { font-size: 14px; }

.avatar {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 50%;
  font-weight: 700;
}

.avatar-user {
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), #60A5FA);
}

.avatar-assistant {
  border: 2px solid color-mix(in srgb, var(--primary) 18%, var(--card));
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.14);
}

.mobile-header-avatar {
  display: none;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border: 2px solid color-mix(in srgb, var(--primary) 22%, var(--card));
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.14);
}

.main-panel {
  min-width: 0;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  min-height: 78px;
  padding: calc(18px + env(safe-area-inset-top)) 32px 18px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: blur(20px);
}

.top-eyebrow {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.topbar h2 { font-size: 24px; font-weight: 700; }

.theme-toggle,
.mobile-menu,
.send-button {
  border: 0;
  cursor: pointer;
  transition: transform 180ms ease, background 180ms ease, box-shadow 180ms ease;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 15px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
  font-weight: 650;
}

.theme-toggle:hover { transform: translateY(-1px); box-shadow: var(--shadow-soft); }

.chat-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--right-width);
  grid-template-rows: minmax(0, 1fr);
  gap: 18px;
  min-height: 0;
  height: 0;
  flex: 1 1 0;
  padding: 18px;
  overflow: hidden;
}

.chat-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: auto;
  max-height: 100%;
  align-self: stretch;
  border-radius: 30px;
  overflow: hidden;
}

.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 38px clamp(24px, 7vw, 86px) 26px;
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar { width: 10px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--muted) 28%, transparent); border-radius: 999px; }

.message {
  display: flex;
  gap: 14px;
  width: min(100%, var(--content-max));
  margin: 0 auto 20px;
  animation: fadeUp 240ms ease both;
}

.user-message { flex-direction: row-reverse; }

.message-content {
  min-width: 0;
  max-width: min(820px, 84%);
}

.bubble {
  border-radius: 24px;
  padding: 16px 18px;
  line-height: 1.62;
  font-size: 15.5px;
  white-space: normal;
  word-break: break-word;
}

.bubble.plain-text { white-space: pre-wrap; }
.bubble p { margin: 0 0 10px; }
.bubble p:last-child { margin-bottom: 0; }

.user-bubble {
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 14px 34px rgba(37, 99, 235, 0.26);
  border-top-right-radius: 9px;
}

.assistant-bubble {
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
  border-top-left-radius: 9px;
}

.welcome-bubble {
  padding: 22px 24px;
  font-size: 16px;
}

.hello {
  font-size: 24px;
  font-weight: 750;
  letter-spacing: -0.035em;
}

.meta-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.chip {
  padding: 5px 9px;
  border-color: var(--border);
  background: color-mix(in srgb, var(--card) 74%, rgba(37, 99, 235, 0.10));
  color: var(--text-soft);
  font-size: 11px;
  box-shadow: none;
}

.chip.documented { color: var(--green); border-color: color-mix(in srgb, var(--green) 28%, transparent); background: color-mix(in srgb, var(--green) 10%, var(--card)); }
.chip.partial { color: var(--yellow); border-color: color-mix(in srgb, var(--yellow) 28%, transparent); background: color-mix(in srgb, var(--yellow) 10%, var(--card)); }
.chip.hypothesis { color: var(--red); border-color: color-mix(in srgb, var(--red) 24%, transparent); background: color-mix(in srgb, var(--red) 8%, var(--card)); }

.typing {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  min-width: 64px;
}

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--muted);
  animation: pulseDot 1s ease-in-out infinite;
}

.typing span:nth-child(2) { animation-delay: 140ms; }
.typing span:nth-child(3) { animation-delay: 280ms; }

.composer {
  position: relative;
  flex: 0 0 auto;
  padding: 16px clamp(18px, 7vw, 86px) calc(22px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: linear-gradient(to top, var(--card) 76%, color-mix(in srgb, var(--card) 78%, transparent));
  backdrop-filter: blur(18px);
}

.composer-inner {
  width: min(100%, var(--content-max));
  margin: 0 auto;
}

.composer-box {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  border: 1px solid var(--border-strong);
  border-radius: 26px;
  background: var(--card);
  padding: 10px 10px 10px 18px;
  box-shadow: var(--shadow-soft);
  transition: box-shadow 180ms ease, border-color 180ms ease;
}

.composer-box:focus-within {
  border-color: color-mix(in srgb, var(--primary) 48%, var(--border));
  box-shadow: var(--ring), var(--shadow-soft);
}

.composer-box textarea {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  min-height: 28px;
  max-height: 190px;
  resize: none;
  border: 0;
  border-radius: 0;
  padding: 9px 0;
  line-height: 1.45;
  color: var(--text);
  background: transparent;
  outline: none;
}

.composer-box textarea::placeholder,
.login-card input::placeholder { color: color-mix(in srgb, var(--muted) 74%, transparent); }

.send-button {
  display: grid;
  place-items: center;
  flex: 0 0 46px;
  width: 46px;
  height: 46px;
  border-radius: 17px;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 12px 26px rgba(37, 99, 235, 0.28);
}

.send-button svg { width: 20px; height: 20px; }
.send-button:hover { transform: translateY(-1px); }
.send-button:active { transform: translateY(0) scale(0.96); }
.send-button:disabled { cursor: not-allowed; opacity: 0.58; filter: grayscale(0.35); }

.composer-hint {
  margin: 9px 2px 0;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.insight-panel {
  display: grid;
  align-content: start;
  gap: 14px;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.mini-card {
  border-radius: 24px;
  padding: 19px;
}

.status-card {
  display: flex;
  gap: 12px;
}

.status-orb {
  width: 12px;
  height: 12px;
  margin-top: 5px;
  border-radius: 999px;
  background: var(--green);
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--green) 12%, transparent);
}

.mini-card strong,
.mini-card h3 {
  display: block;
  margin: 0 0 8px;
  letter-spacing: -0.025em;
}

.mini-card p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.52;
}

.policy-list {
  margin: 12px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.mobile-menu {
  display: none;
  position: fixed;
  z-index: 40;
  top: calc(16px + env(safe-area-inset-top));
  left: calc(16px + env(safe-area-inset-left));
  width: 44px;
  height: 44px;
  border-radius: 15px;
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
}

.mobile-menu span {
  display: block;
  width: 18px;
  height: 2px;
  margin: 4px auto;
  border-radius: 2px;
  background: var(--text);
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 15;
  background: rgba(15, 23, 42, 0.34);
  backdrop-filter: blur(4px);
}

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

@keyframes pulseDot {
  0%, 80%, 100% { opacity: 0.38; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-4px); }
}

@media (min-width: 1500px) {
  :root { --content-max: 1120px; --right-width: 340px; }
  .chat-layout { padding: 22px 26px; }
}

@media (max-width: 1180px) {
  .chat-layout { grid-template-columns: minmax(0, 1fr); }
  .insight-panel { display: none; }
}

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

  .app-shell {
    grid-template-columns: 1fr;
    height: 100vh;
    height: 100svh;
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
  }

  .mobile-menu { display: block; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 320px);
    height: 100vh;
    height: 100dvh;
    min-height: 100dvh;
    transform: translateX(-105%);
    transition: transform 220ms ease;
    box-shadow: var(--shadow);
    padding-top: calc(78px + env(safe-area-inset-top));
    padding-bottom: calc(28px + env(safe-area-inset-bottom));
    padding-left: calc(22px + env(safe-area-inset-left));
  }

  .sidebar.open { transform: translateX(0); }

  .main-panel {
    height: 100vh;
    height: 100svh;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  .topbar {
    padding: calc(14px + env(safe-area-inset-top)) 16px 14px calc(72px + env(safe-area-inset-left));
    min-height: calc(68px + env(safe-area-inset-top));
  }

  .mobile-header-avatar { display: block; }

  .topbar h2 { font-size: 20px; }
  .chat-layout { padding: 0; min-height: 0; overflow: hidden; }

  .chat-card {
    height: auto;
    max-height: 100%;
    min-height: 0;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }

  .messages {
    min-height: 0;
    padding: 22px calc(16px + env(safe-area-inset-right)) 18px calc(16px + env(safe-area-inset-left));
  }

  .message {
    width: 100%;
    gap: 10px;
    margin-bottom: 17px;
  }

  .message-content { max-width: calc(100% - 44px); }

  .composer {
    padding: 12px calc(12px + env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
  }

  .composer-box {
    min-height: 58px;
    border-radius: 22px;
    padding: 8px 8px 8px 15px;
  }

  .send-button {
    flex-basis: 44px;
    width: 44px;
    height: 44px;
    border-radius: 16px;
  }

  .composer-hint { text-align: left; }
}

@media (max-width: 520px) {
  .top-eyebrow { display: none; }
  .theme-label { display: none; }
  .theme-toggle { width: 44px; padding: 0; justify-content: center; }
  .bubble { font-size: 14.5px; padding: 14px 15px; }
  .welcome-bubble { padding: 18px 17px; }
  .hello { font-size: 22px; }
  .avatar { width: 34px; height: 34px; border-radius: 50%; }
  .login-card { padding: 26px 20px; border-radius: 28px; }
  .login-avatar-wrap { width: 96px; height: 96px; border-radius: 50%; }
  .login-avatar { border-radius: 50%; }
}

@media (max-height: 620px) and (max-width: 860px) {
  .topbar { min-height: calc(58px + env(safe-area-inset-top)); padding-top: calc(10px + env(safe-area-inset-top)); padding-bottom: 10px; }
  .messages { padding-top: 14px; padding-bottom: 12px; }
  .composer { padding-top: 8px; padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .composer-hint { display: none; }
  .login-card { padding-top: 22px; padding-bottom: 22px; }
  .login-avatar-wrap { width: 84px; height: 84px; margin-bottom: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
