:root {
  color-scheme: dark;
  --bg: #070b14;
  --surface: #0f172a;
  --surface-2: #1e293b;
  --border: rgba(255, 255, 255, 0.08);
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #8b5cf6;
  --accent-2: #6366f1;
  --danger: #f43f5e;
  --user: #1e1b4b;
  --assistant: #0f172a;
  --ok: #10b981;
  --warn: #f59e0b;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

body.shell-page.chat-page {
  background: #070b14;
}

button,
textarea {
  font: inherit;
}

button {
  min-height: 32px;
}

.shell-page .app {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.chat-toolbar {
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(10, 15, 26, 0.92);
}

.chat-toolbar-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 0;
}

.chat-toolbar h1 {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 720;
}

.subtitle {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.link,
.ghost-btn {
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  background: #0f172a;
  text-decoration: none;
  font-size: 0.84rem;
  padding: 0.34rem 0.6rem;
  cursor: pointer;
}

.link:hover,
.ghost-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.pill {
  font-size: 0.75rem;
  padding: 0.22rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  white-space: nowrap;
}

.pill--ok { color: var(--ok); border-color: #3d7650; }
.pill--warn { color: var(--warn); border-color: #876c31; }
.pill--pending { color: var(--muted); }

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(240px, 300px) minmax(0, 1fr);
}

.sidebar {
  border-right: 1px solid var(--border);
  background: #070b14;
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow-y: auto;
}

.panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: 0.75rem;
}

.panel h2 {
  margin: 0 0 0.65rem;
  font-size: 0.83rem;
  font-weight: 720;
  color: var(--text);
}

.kv {
  display: grid;
  gap: 0.55rem;
  margin: 0;
}

.kv div {
  display: grid;
  gap: 0.12rem;
}

.kv dt,
.list-item span {
  color: var(--muted);
  font-size: 0.76rem;
}

.kv dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 0.86rem;
}

.quick-list,
.list {
  display: grid;
  gap: 0.45rem;
}

.quick-list button,
.list-item {
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #0f172a;
  color: var(--text);
  padding: 0.48rem 0.55rem;
  cursor: pointer;
}

.quick-list button:hover,
.list-item:hover {
  border-color: var(--accent);
}

.list-item {
  display: grid;
  gap: 0.16rem;
}

.list-item strong {
  overflow-wrap: anywhere;
  font-size: 0.84rem;
}

.list--empty {
  color: var(--muted);
  font-size: 0.84rem;
}

.chat {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1rem 6rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.msg {
  max-width: 100%;
  padding: 0.82rem 0.92rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  line-height: 1.5;
}

.msg--user {
  align-self: flex-end;
  background: var(--user);
  max-width: min(82%, 720px);
}

.msg--assistant {
  align-self: stretch;
  background: var(--assistant);
}

.msg--error {
  border-color: #8e4444;
  background: #2a1717;
}

.msg-role {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.msg-body :first-child { margin-top: 0; }
.msg-body :last-child { margin-bottom: 0; }

.msg-body h2 {
  font-size: 1rem;
  margin: 0 0 0.55rem;
}

.msg-body a {
  color: var(--accent);
}

.msg-body pre {
  background: #070b14;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  overflow-x: auto;
}

.msg-body code {
  font-family: var(--mono);
  font-size: 0.88em;
}

.msg-body details {
  margin-top: 0.55rem;
  color: var(--muted);
}

.html-preview {
  margin-top: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: #070b14;
}

.html-preview__label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 0.45rem 0.65rem;
  border-bottom: 1px solid var(--border);
}

.html-preview__frame {
  display: block;
  width: 100%;
  min-height: 280px;
  border: 0;
  background: #fff;
}

.block-actions,
.uri-actions {
  display: flex;
  gap: 0.45rem;
  margin-top: 0.45rem;
  flex-wrap: wrap;
}

.uri-action-group {
  display: inline-flex;
  gap: 0.25rem;
  align-items: center;
  flex-wrap: wrap;
}

.block-actions button,
.uri-actions button {
  font-size: 0.76rem;
  padding: 0.18rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #0f172a;
  color: var(--text);
  cursor: pointer;
}

.block-actions button:hover,
.uri-actions button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.uri-chip {
  max-width: 100%;
  overflow-wrap: anywhere;
}

.plan-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.55rem;
}

.plan-actions button {
  border: 1px solid var(--accent);
  background: rgba(139, 92, 246, 0.12);
  color: var(--accent);
  border-radius: 6px;
  padding: 0.3rem 0.55rem;
  font-size: 0.82rem;
  cursor: pointer;
}

.plan-actions button:hover {
  background: rgba(139, 92, 246, 0.22);
}

.mic-btn {
  min-width: 2.4rem;
}

.mic-btn.is-recording {
  border-color: #e85d5d;
  color: #ffb4b4;
  animation: mic-pulse 1.2s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.voice-engine-label select {
  margin-left: 0.25rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.8rem;
}

.composer {
  position: sticky;
  bottom: 0;
  background: linear-gradient(transparent, var(--bg) 20%);
  padding: 0.75rem 1rem 1rem;
}

#chat-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem;
}

#prompt {
  width: 100%;
  resize: vertical;
  min-height: 3rem;
  max-height: 12rem;
  border: none;
  background: transparent;
  color: var(--text);
  outline: none;
}

#prompt::placeholder {
  color: #64748b;
}

.composer-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.35rem;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.85rem;
}

#send-btn {
  border: none;
  border-radius: 7px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 720;
  padding: 0.45rem 0.9rem;
  cursor: pointer;
}

#send-btn:hover {
  background: #a78bfa;
}

#send-btn:disabled,
.ghost-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

@media (max-width: 820px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 42vh;
  }
}

@media (max-width: 640px) {
  .header {
    align-items: stretch;
    flex-direction: column;
  }

  .msg--user {
    max-width: 100%;
  }

  .composer-bar {
    align-items: stretch;
    flex-direction: column;
  }

  #send-btn {
    width: 100%;
  }
}
