:root {
  color-scheme: light;
  --bg: #ffffff;
  --bg-soft: #f7f7f8;
  --surface: #ffffff;
  --surface-muted: #f3f4f6;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --accent: #644aed;
  --accent-soft: #ede9fe;
  --danger: #b42318;
  --ok: #027a48;
  --shadow-sm: 0 2px 10px rgba(17, 24, 39, 0.06);
  --shadow-md: 0 10px 30px rgba(17, 24, 39, 0.1);
  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-sm: 12px;
  --tap: 44px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Satoshi", "General Sans", "Avenir Next", "Segoe UI", sans-serif;
  line-height: 1.5;
}

input,
button,
textarea {
  font: inherit;
}

button,
input,
textarea {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}

button {
  min-height: var(--tap);
  padding: 10px 14px;
  cursor: pointer;
  transition:
    background-color 140ms ease,
    border-color 140ms ease,
    box-shadow 140ms ease,
    transform 140ms ease;
}

button:hover:not(:disabled) {
  background: var(--surface-muted);
}

button:active:not(:disabled) {
  transform: scale(0.98);
}

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

button.ghost {
  background: var(--surface);
}

input,
textarea {
  width: 100%;
  padding: 10px 12px;
  outline: none;
}

input:focus,
textarea:focus,
button:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(100, 74, 237, 0.2);
}

textarea {
  min-height: var(--tap);
  max-height: 180px;
  resize: none;
}

.app-shell {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  height: 56px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.topbar-title-wrap {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.topbar-title-wrap h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.2;
  max-width: min(56vw, 280px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-chevron {
  color: #6b7280;
  flex-shrink: 0;
}

.icon-btn {
  width: var(--tap);
  min-width: var(--tap);
  height: var(--tap);
  padding: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
}

.chat-main {
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr auto;
  background: var(--bg);
}

.meta {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.status-row {
  margin-top: 8px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.status-pill {
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: #fafafa;
  padding: 4px 8px;
}

.status-pill.online {
  border-color: #a7f3d0;
  color: var(--ok);
  background: #f0fdf4;
}

.status-pill.connecting {
  border-color: #c4b5fd;
  color: var(--accent);
  background: #f5f3ff;
}

.status-pill.offline {
  border-color: #fecaca;
  color: var(--danger);
  background: #fef2f2;
}

.messages {
  min-height: 0;
  overflow: auto;
  padding: 24px 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  background: var(--bg);
  scroll-behavior: smooth;
}

.empty-state {
  margin: auto;
  max-width: 44ch;
  text-align: center;
  color: #9ca3af;
  font-size: 15px;
  padding: 36px 14px;
}

.bubble {
  max-width: min(90%, 74ch);
  border-radius: 20px;
  padding: 9px 12px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 17px;
  line-height: 1.62;
  opacity: 0;
  transform: translateY(4px);
  animation: bubble-in 160ms ease forwards;
}

.bubble.assistant {
  align-self: flex-start;
  background: transparent;
  border: 0;
  padding: 0;
  max-width: min(96%, 78ch);
}

.bubble.user {
  align-self: flex-end;
  background: #f3f4f6;
  border: 1px solid #eceff3;
  font-size: 16px;
  line-height: 1.56;
}

.bubble.system {
  align-self: center;
  background: #fff7ed;
  border: 1px solid #fed7aa;
}

.bubble.typing {
  align-self: flex-start;
  padding: 4px 2px;
}

.bubble-actions {
  margin-top: 7px;
  display: inline-flex;
  gap: 4px;
}

.bubble-action {
  width: 28px;
  min-width: 28px;
  height: 28px;
  min-height: 28px;
  border-radius: 999px;
  border-color: transparent;
  background: transparent;
  color: #9ca3af;
}

.bubble-action:hover:not(:disabled) {
  color: #6b7280;
  background: #f3f4f6;
}

.typing-dots {
  display: inline-flex;
  gap: 6px;
}

.typing-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9ca3af;
  animation: blink 900ms infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
  animation-delay: 120ms;
}

.typing-dots span:nth-child(3) {
  animation-delay: 240ms;
}

.bubble-meta {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.bubble-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message-text {
  white-space: pre-wrap;
  line-height: 1.5;
}

.inline-code {
  font-family: var(--mono);
  background: #f3f4f6;
  border-radius: 4px;
  padding: 1px 4px;
  font-size: 0.95em;
}

.code-block {
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #1f2937;
  background: #0f172a;
  color: #e2e8f0;
}

.code-block--shell {
  border-color: #34d399;
  background: #0b1f16;
}

.code-block--script {
  border-color: #60a5fa;
  background: #0b1628;
}

.code-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  font-size: 11px;
  background: rgba(15, 23, 42, 0.9);
  color: #cbd5f5;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.code-block--shell .code-block-header {
  background: rgba(16, 185, 129, 0.15);
  color: #d1fae5;
}

.code-block--script .code-block-header {
  background: rgba(59, 130, 246, 0.16);
  color: #dbeafe;
}

.code-block-label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.code-copy-btn {
  border: none;
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 11px;
  background: rgba(255, 255, 255, 0.1);
  color: inherit;
  cursor: pointer;
}

.code-copy-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

.code-block pre {
  margin: 0;
  padding: 10px 12px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
}

.bubble-attachments {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bubble-attachment-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.bubble-attachment-label {
  font-size: 12px;
  color: var(--text-muted);
}

.bubble-attachment-link {
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
}

.bubble-attachment-link:hover {
  text-decoration: underline;
}

.composer {
  position: sticky;
  bottom: 0;
  z-index: 10;
  border-top: 1px solid #f1f3f5;
  background: #ffffff;
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
}

.quick-row {
  margin-bottom: 7px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.command-chip {
  min-height: 34px;
  border-radius: 999px;
  background: #f8fafc;
  font-size: 12px;
  white-space: nowrap;
  padding: 6px 10px;
}

.pending-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 8px;
}

.pending-attachment {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 8px;
  background: #f9fafb;
  font-size: 12px;
}

.pending-attachment button {
  width: 22px;
  min-width: 22px;
  height: 22px;
  min-height: 22px;
  padding: 0;
}

.attachment-row {
  margin-bottom: 8px;
}

.input-row {
  display: grid;
  grid-template-columns: var(--tap) 1fr var(--tap) var(--tap) var(--tap);
  gap: 6px;
  align-items: end;
  padding: 7px;
  border: 1px solid #e5e7eb;
  border-radius: 999px;
  background: #f9fafb;
  box-shadow: var(--shadow-sm);
}

.composer-action {
  box-shadow: none;
  background: #ffffff;
  border-color: #e5e7eb;
}

#messageInput {
  border: 0;
  background: transparent;
  padding: 10px 2px;
  min-height: 44px;
  max-height: 136px;
}

#messageInput:focus {
  border-color: transparent;
  box-shadow: none;
}

.send-btn {
  background: #f3f4f6;
  color: #9ca3af;
  border-color: #e5e7eb;
}

.send-btn.active {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

.voice-btn.active {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

.voice-mode-btn {
  background: var(--accent);
  border-color: var(--accent);
}

.voice-mode-btn span {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #ffffff;
}

.voice-mode-btn.active {
  box-shadow: 0 0 0 3px rgba(100, 74, 237, 0.2);
}

.voice-mode-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(241, 245, 249, 0.82);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: grid;
  place-items: center;
  padding: 18px;
}

.voice-mode-sheet {
  width: min(100%, 440px);
  border-radius: 26px;
  border: 1px solid #e2e8f0;
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.16);
  padding: 32px 22px calc(24px + env(safe-area-inset-bottom));
  text-align: center;
}

.voice-mode-eyebrow {
  margin: 0;
  color: #475569;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 600;
}

.voice-mode-status {
  margin: 10px 0 8px;
  font-size: clamp(28px, 7vw, 42px);
  line-height: 1.05;
}

.voice-mode-meta {
  margin: 0;
  color: #64748b;
  font-size: 14px;
}

.voice-mode-stop-btn {
  margin-top: 30px;
  width: 100%;
  min-height: 58px;
  border-radius: 999px;
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  font-size: 19px;
  font-weight: 600;
}

.shortcut-hint {
  margin-top: 8px;
  font-size: 11px;
}

.settings-panel {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: block;
  background: rgba(15, 23, 42, 0.18);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.settings-drawer {
  width: min(82vw, 390px);
  height: 100dvh;
  overflow: auto;
  border-right: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  padding: 10px 12px calc(14px + env(safe-area-inset-bottom));
  transform: translateX(-104%);
  transition: transform 220ms ease;
}

.settings-panel:not(.hidden) .settings-drawer {
  transform: translateX(0);
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.settings-header h3 {
  margin: 0;
  font-size: 18px;
}

.drawer-search {
  margin-bottom: 12px;
}

.drawer-sections {
  display: flex;
  gap: 7px;
  margin-bottom: 12px;
  overflow-x: auto;
}

.drawer-section {
  min-height: 32px;
  border-radius: 999px;
  font-size: 11px;
  letter-spacing: 0.01em;
  white-space: nowrap;
  padding: 5px 11px;
  background: #f5f6f8;
  border-color: #eceff3;
}

.drawer-section.active {
  border-color: #c4b5fd;
  background: var(--accent-soft);
  color: var(--accent);
}

.panel {
  border: 1px solid #edf0f2;
  border-radius: var(--radius-md);
  padding: 12px;
  background: var(--surface);
}

.panel + .panel {
  margin-top: 10px;
}

.panel h4 {
  margin: 0;
  font-size: 14px;
}

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.field-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}

.field-row > * {
  flex: 1;
}

.field-row > button {
  flex: 0 0 auto;
}

.settings-foldout summary {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}

.settings-foldout[open] summary {
  margin-bottom: 8px;
}

.palette {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(15, 23, 42, 0.18);
  display: grid;
  place-items: start center;
  padding: 10vh 12px 12px;
}

.palette-panel {
  width: min(620px, 100%);
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-md);
  padding: 12px;
}

.palette-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.palette-list {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  max-height: 48vh;
  overflow: auto;
}

.palette-item {
  text-align: left;
  background: #f8fafc;
}

.palette-item.hidden {
  display: none;
}

.toast-stack {
  position: fixed;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 60;
  display: grid;
  gap: 8px;
}

.toast {
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  background: #ffffff;
  color: var(--text);
  box-shadow: var(--shadow-sm);
  padding: 10px 12px;
  animation: toast-in 180ms ease;
}

.toast.error {
  border-color: #fecaca;
  background: #fef2f2;
}

.skeleton-line {
  height: 12px;
  width: 60%;
  margin-bottom: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, #f3f4f6, #e5e7eb, #f3f4f6);
  background-size: 200% 100%;
  animation: shimmer 1.1s linear infinite;
}

.skeleton-line.wide {
  width: 85%;
}

.hidden {
  display: none !important;
}

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

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

@keyframes bubble-in {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (min-width: 880px) {
  .app-shell {
    max-width: 920px;
    margin: 0 auto;
    border-left: 1px solid #f3f4f6;
    border-right: 1px solid #f3f4f6;
  }

  .messages {
    padding-left: 20px;
    padding-right: 20px;
  }

  .composer {
    padding-left: 16px;
    padding-right: 16px;
  }
}
