:root {
  color-scheme: light;
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0efeb;
  --text: #171717;
  --muted: #6b6862;
  --border: #dedbd4;
  --border-strong: #c9c4ba;
  --accent: #171717;
  --accent-text: #ffffff;
  --danger: #b42318;
  --ok: #16794c;
  --shadow: 0 18px 48px rgba(20, 20, 20, 0.08);
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input { font: inherit; }
button { cursor: pointer; }

.login-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 18px;
}

.login-card {
  width: min(360px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  display: grid;
  gap: 12px;
  box-shadow: var(--shadow);
}

.login-brand { margin-bottom: 8px; }
.login-card label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.login-card input {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  padding: 13px;
  font-size: 16px;
}
.login-card button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 12px;
  padding: 12px;
  font-weight: 650;
}
.login-error { margin: 0; color: var(--danger); }

.app-shell {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
}

.sidebar,
.chat-shell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
}

.sidebar {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--text);
  color: var(--surface);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
}

.brand strong {
  display: block;
  font-size: 14px;
  line-height: 1.2;
}

.brand span,
.eyebrow,
.system-card small,
.system-card p,
.sidebar-note p {
  color: var(--muted);
}

.brand span {
  display: block;
  font-size: 12px;
}

.system-card,
.sidebar-note,
.history-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: var(--surface-2);
}

.mode-tabs {
  display: grid;
  gap: 7px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-2);
}

.mode-tab,
.text-button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  border-radius: 10px;
  padding: 10px 11px;
  text-align: left;
}

.mode-tab {
  width: 100%;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-weight: 650;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease, transform 140ms ease;
}

.mode-tab span { pointer-events: none; }

.mode-tab::after {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: transparent;
}

.mode-tab:hover {
  background: var(--surface);
  color: var(--text);
}

.mode-tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.mode-tab.active {
  border-color: var(--border-strong);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 0 rgba(20, 20, 20, 0.04);
}

.mode-tab.active::after { background: var(--accent); }

.history-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.history-heading strong {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.text-button {
  padding: 5px 8px;
  font-size: 12px;
  background: var(--surface);
  border-color: var(--border);
}

.history-list {
  max-height: 260px;
  overflow: auto;
  display: grid;
  gap: 7px;
}

.history-item {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: 9px;
  text-align: left;
}

.history-item strong,
.history-item span,
.history-item small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item strong { font-size: 13px; }
.history-item span,
.history-item small,
.empty-history { color: var(--muted); font-size: 12px; }
.history-item.same-mode { border-color: var(--border-strong); }

.notification-list {
  display: grid;
  gap: 7px;
  margin: 8px 0;
  max-height: 130px;
  overflow: auto;
}

.notification-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  padding: 8px;
  color: var(--muted);
  font-size: 12px;
}

.notification-item strong {
  display: block;
  color: var(--text);
  font-size: 12px;
  margin-bottom: 2px;
}

.full { width: 100%; text-align: center; }

.system-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 650;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--ok);
}

.status-dot.warn { background: var(--danger); }

.system-card p,
.sidebar-note p {
  margin: 10px 0 4px;
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.system-card small {
  display: block;
  font-size: 12px;
  line-height: 1.45;
}

.sidebar-note strong {
  display: block;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chat-shell {
  min-width: 0;
  min-height: calc(100dvh - 36px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chat-header {
  min-height: 64px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow {
  margin: 0 0 2px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.secondary-button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 11px;
}
.messages {
  flex: 1;
  overflow: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.typing-indicator {
  margin: 0 18px 12px;
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.typing-indicator[hidden] { display: none; }

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

.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-pulse {
  0%, 80%, 100% { opacity: 0.35; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

.message {

  max-width: min(680px, 86%);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 11px 13px;
  background: var(--surface);
}

.message.user {
  align-self: flex-end;
  background: #ece9e2;
  border-color: var(--border-strong);
}

.message.assistant { align-self: flex-start; }

.message .role {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.message p {
  margin: 0;
  line-height: 1.5;
  white-space: pre-wrap;
}

.message small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}

.composer {
  padding: 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 10px;
}

.talk-button,
.text-form button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 12px;
  font-weight: 650;
}

.talk-button {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  touch-action: none;
}

.talk-button.recording {
  background: var(--danger);
  border-color: var(--danger);
}

.talk-button:disabled,
.text-form button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.mic-icon {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: currentColor;
}

.text-form {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.text-form input {
  min-width: 0;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  padding: 0 13px;
  outline: none;
  font-size: 16px;
}

.text-form input:focus { border-color: var(--text); }
.text-form button { padding: 0 15px; }

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0f1115;
    --surface: #17191f;
    --surface-2: #1e2129;
    --text: #f4f4f5;
    --muted: #a1a1aa;
    --border: #2b2f38;
    --border-strong: #3a3f4b;
    --accent: #f4f4f5;
    --accent-text: #111318;
    --shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
  }

  .message.user { background: #242832; }
}

@media (max-width: 820px) {
  .app-shell {
    padding: 0;
    display: block;
  }

  .sidebar {
    display: block;
    border: 0;
    border-radius: 0;
    border-bottom: 1px solid var(--border);
    padding: max(10px, env(safe-area-inset-top)) 10px 10px;
  }

  .brand,
  .system-card,
  .sidebar-note { display: none; }

  .mode-tabs {
    grid-template-columns: repeat(3, 1fr);
  }

  .mode-tab {
    justify-content: center;
    text-align: center;
    padding: 10px 6px;
    font-size: 14px;
  }

  .mode-tab::after { display: none; }

  .history-card {
    margin-top: 8px;
    padding: 8px;
  }

  .history-list {
    max-height: 104px;
    grid-template-columns: 1fr;
  }

  .chat-shell {
    min-height: 100dvh;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .chat-header {
    padding-top: max(14px, env(safe-area-inset-top));
  }

  .messages { padding: 14px; }

  .composer {
    grid-template-columns: 1fr;
    padding: 10px max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }

  .talk-button { min-height: 52px; }
  .message { max-width: 92%; }
}

@media (display-mode: standalone) and (max-width: 820px) {
  .chat-header {
    padding-top: max(18px, env(safe-area-inset-top));
  }
}
