:root {
  --bg: #0a0a0f;
  --bg-elevated: #12121a;
  --bg-hover: #1a1a26;
  --bg-active: #22223a;
  --surface: #16161f;
  --border: #2a2a3a;
  --text: #e4e4ec;
  --text-muted: #8888a0;
  --text-dim: #55556a;
  --accent: #6b8afd;
  --accent-hover: #8ba2ff;
  --accent-bg: rgba(107,138,253,.1);
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --code-bg: #1a1a28;
  --sidebar-w: 280px;
  --font: 'Manrope', system-ui, sans-serif;
  --mono: 'JetBrains Mono', monospace;
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.6; -webkit-font-smoothing: antialiased; }

.app { display: flex; height: var(--app-h, 100dvh); overflow: hidden; }

/* === SIDEBAR === */
.sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--bg-elevated); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; transition: transform .2s;
}
.sidebar-head {
  padding: 16px; display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font-weight: 700; font-size: 18px; letter-spacing: -.5px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px rgba(52,211,153,.15); }
.conv-list { flex: 1; overflow-y: auto; padding: 8px; }
.conv-item {
  padding: 10px 12px; border-radius: var(--radius-sm); cursor: pointer;
  font-size: 13px; color: var(--text-muted); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; transition: background .15s;
  display: flex; align-items: center; justify-content: space-between;
}
.conv-item:hover { background: var(--bg-hover); color: var(--text); }
.conv-item.active { background: var(--bg-active); color: var(--text); }
.conv-item .conv-delete {
  opacity: 0; border: none; background: none; color: var(--text-dim);
  cursor: pointer; font-size: 14px; padding: 2px 4px; transition: opacity .15s;
}
.conv-item:hover .conv-delete { opacity: 1; }
.conv-item .conv-delete:hover { color: var(--danger); }
.sidebar-foot { padding: 12px 16px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 8px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; }
.user-name { font-size: 13px; color: var(--text-muted); }

/* === SIDEBAR TOGGLE (mobile) === */
.sidebar-toggle {
  position: fixed; top: 12px; left: 12px; z-index: 100;
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text-muted); padding: 8px; cursor: pointer; display: none;
}
.sidebar-toggle svg { width: 20px; height: 20px; }

/* === MAIN === */
.main {
  flex: 1; display: flex; flex-direction: column; position: relative;
  background: var(--bg); min-width: 0;
}
.messages {
  flex: 1; overflow-y: auto; padding: 24px 0;
  scroll-behavior: smooth; overscroll-behavior: contain;
}

/* === MESSAGES === */
.msg { padding: 4px 24px; max-width: 800px; margin: 0 auto; width: 100%; }
.msg + .msg { margin-top: 8px; }
.msg.user { }
.msg.assistant { }
.msg-role {
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px;
  margin-bottom: 4px; color: var(--text-dim);
}
.msg.user .msg-role { color: var(--accent); }
.msg-content {
  font-size: 15px; line-height: 1.7; word-wrap: break-word;
}
.msg.user .msg-content { color: var(--text); }
.msg.assistant .msg-content { color: var(--text); }

/* Code blocks */
.msg-content pre {
  background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 16px; overflow-x: auto; font-family: var(--mono); font-size: 13px;
  margin: 8px 0; line-height: 1.5;
}
.msg-content code {
  font-family: var(--mono); font-size: 13px;
  background: var(--code-bg); padding: 2px 6px; border-radius: 4px;
}
.msg-content pre code { background: none; padding: 0; }

/* Tool calls */
.tool-call {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px;
  background: var(--accent-bg); border-radius: var(--radius-sm); margin: 6px 0;
  font-size: 13px; color: var(--accent); font-family: var(--mono);
}
.tool-call::before { content: '⚡'; }

/* Message actions */
.msg-actions {
  margin-top: 6px; display: flex; gap: 8px;
}
.msg-actions button {
  background: none; border: 1px solid var(--border); border-radius: 6px;
  color: var(--text-dim); font-size: 12px; padding: 3px 10px; cursor: pointer;
  transition: all .15s;
}
.msg-actions button:hover { color: var(--text); border-color: var(--text-dim); }

/* === TYPING === */
.typing-wrap { padding: 4px 24px; max-width: 800px; margin: 0 auto; width: 100%; }
.typing-bubble { display: flex; align-items: center; gap: 8px; color: var(--text-muted); font-size: 13px; }
.dots { display: flex; gap: 3px; }
.dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--text-dim); animation: blink 1.4s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; }
.dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 100% { opacity: .3; } 50% { opacity: 1; } }

/* === COMPOSER === */
.composer {
  padding: 12px 24px 16px; max-width: 800px; margin: 0 auto; width: 100%;
}
.composer-row {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 12px; transition: border-color .2s;
}
.composer-row:focus-within { border-color: var(--accent); }
.input-wrap { flex: 1; }
.input {
  width: 100%; background: none; border: none; outline: none;
  color: var(--text); font-family: var(--font); font-size: 15px;
  resize: none; max-height: 150px; line-height: 1.5; overflow-y: auto;
}
.input::placeholder { color: var(--text-dim); }
.file-input { display: none; }

/* Upload preview */
.upload-preview {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px;
}
.upload-chip {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-hover); border: 1px solid var(--border); border-radius: 6px;
  padding: 4px 10px; font-size: 12px; color: var(--text-muted);
}
.upload-chip .remove { cursor: pointer; color: var(--text-dim); }
.upload-chip .remove:hover { color: var(--danger); }

/* Drop zone */
.drop-zone {
  position: absolute; inset: 0; background: rgba(107,138,253,.08);
  border: 2px dashed var(--accent); border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.drop-zone-text { font-size: 18px; color: var(--accent); font-weight: 600; }

/* === BUTTONS === */
.icon-btn {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  padding: 6px; border-radius: 8px; display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.icon-btn:hover { color: var(--text); background: var(--bg-hover); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.mic.active { color: var(--danger); animation: pulse 1.5s infinite; }
.icon-btn.send { color: var(--accent); }
.icon-btn.send:hover { color: var(--accent-hover); background: var(--accent-bg); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: none; border-radius: var(--radius-sm); font-family: var(--font);
  font-size: 14px; font-weight: 500; padding: 8px 16px; cursor: pointer; transition: all .15s;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost { background: none; border: 1px solid var(--border); color: var(--text-muted); }

/* === SCROLL === */
.scroll-down {
  position: absolute; bottom: 100px; left: 50%; transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--border); border-radius: 50%;
  width: 36px; height: 36px; cursor: pointer; color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
}
.scroll-down svg { width: 16px; height: 16px; }

/* === APPROVAL === */
.approval-overlay {
  position: absolute; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 60;
}
.approval-card {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; max-width: 420px; width: 90%;
}
.approval-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; font-weight: 600; }
.approval-desc { color: var(--text-muted); font-size: 14px; margin-bottom: 16px; white-space: pre-wrap; }
.approval-actions { display: flex; gap: 8px; }

/* === TOAST === */
.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 20px; font-size: 13px; color: var(--text-muted); z-index: 200;
  transition: opacity .3s;
}

.hidden { display: none !important; }

/* === MOBILE === */
@media (max-width: 768px) {
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 90;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: flex; }
  .sidebar.open ~ .sidebar-toggle { display: none; }
  html, body { height: 100dvh; }
  .msg { padding: 4px 16px; }
  .composer { padding: 6px 12px 8px; }
  .input { max-height: 30dvh; }
  .typing-wrap { padding: 4px 16px; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* Voice mode button */
.icon-btn.voice-start { color: var(--ok); }
.icon-btn.voice-start:hover { color: var(--accent-hover); background: rgba(52,211,153,.1); }

/* Tool call blocks */
.tool-block {
  background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 14px; margin: 6px 0; font-size: 13px;
}
.tool-header { display: flex; align-items: center; gap: 8px; }
.tool-icon { font-size: 14px; }
.tool-name { font-family: var(--mono); font-weight: 500; color: var(--accent); }
.tool-status { font-size: 12px; padding: 1px 8px; border-radius: 4px; }
.tool-status--running { background: rgba(251,191,36,.15); color: var(--warn); }
.tool-status--done { background: rgba(52,211,153,.15); color: var(--ok); }
.tool-args { margin-top: 6px; }
.tool-args code { font-size: 12px; color: var(--text-dim); }
.tool-output { margin-top: 8px; }
.tool-output pre {
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 12px; font-family: var(--mono); font-size: 12px;
  max-height: 200px; overflow: auto; white-space: pre-wrap; color: var(--text-muted);
}

/* Conversation group labels */
.conv-group-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .5px; color: var(--text-dim); padding: 12px 12px 4px;
}
.conv-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }

/* Project switcher */
.project-switcher {
  display: flex; gap: 4px; padding: 8px; flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}
.project-btn {
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text-muted); font-size: 12px; padding: 4px 10px;
  cursor: pointer; transition: all .15s; font-family: var(--font);
}
.project-btn:hover { background: var(--bg-hover); color: var(--text); }
.project-btn.active { background: var(--accent-bg); color: var(--accent); border-color: var(--accent); }

/* Project selector */
.project-select {
  width: calc(100% - 16px); margin: 8px; padding: 8px 12px;
  background: var(--bg-hover); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-family: var(--font); font-size: 13px;
  cursor: pointer; outline: none; appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M7 10l5 5 5-5" fill="none" stroke="%238888a0" stroke-width="2"/></svg>");
  background-repeat: no-repeat; background-position: right 8px center; background-size: 16px;
}
.project-select:hover { border-color: var(--accent); }
.project-select:focus { border-color: var(--accent); }

/* === POLISH === */

/* Search */
.sidebar-search { padding: 8px; }
.search-input {
  width: 100%; padding: 8px 12px;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-family: var(--font); font-size: 13px; outline: none;
}
.search-input::placeholder { color: var(--text-dim); }
.search-input:focus { border-color: var(--accent); }

/* Welcome */
.welcome {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  pointer-events: none;
}
.welcome > * { pointer-events: auto; }
.welcome-icon { font-size: 48px; opacity: .3; }
.welcome-title { font-size: 28px; font-weight: 700; color: var(--text); letter-spacing: -1px; }
.welcome-sub { font-size: 14px; color: var(--text-dim); }
.welcome-hints { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; justify-content: center; }
.hint {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 16px; color: var(--text-muted); font-size: 13px; cursor: pointer;
  font-family: var(--font); transition: all .15s;
}
.hint:hover { background: var(--bg-hover); color: var(--text); border-color: var(--text-dim); }

/* Stop button */
.icon-btn.stop { color: var(--danger); }
.icon-btn.stop:hover { background: rgba(248,113,113,.1); }

/* Sidebar backdrop (mobile) */
.sidebar-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 85;
}

/* Message improvements */
.msg-content h2, .msg-content h3, .msg-content h4 {
  margin: 12px 0 6px; font-weight: 600; color: var(--text);
}
.msg-content h2 { font-size: 18px; }
.msg-content h3 { font-size: 16px; }
.msg-content h4 { font-size: 15px; }
.msg-content ul { padding-left: 20px; margin: 4px 0; }
.msg-content li { margin: 2px 0; }
.msg-content a { color: var(--accent); text-decoration: none; }
.msg-content a:hover { text-decoration: underline; }
.msg-content strong { color: var(--text); }
.msg-content p { margin: 4px 0; }
.msg-content p:empty { display: none; }

/* Conversation items improved */
.conv-item { position: relative; }
.conv-item .conv-time {
  font-size: 11px; color: var(--text-dim); margin-left: auto; padding-left: 8px;
  white-space: nowrap;
}

/* Chat header */
.chat-header {
  display: flex; justify-content: flex-end; padding: 8px 16px;
  border-bottom: 1px solid var(--border);
}

/* === Action chips (interactive suggestions) === */
.action-chips {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: 8px;
}
.action-chip {
  background: var(--accent-bg);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  font-family: var(--font); font-weight: 500;
  cursor: pointer;
  transition: background .15s, color .15s, transform .1s;
  white-space: nowrap;
  line-height: 1.3;
}
.action-chip:hover {
  background: var(--accent);
  color: #fff;
}
.action-chip:active { transform: scale(.97); }
/* Phase 3.1 M2.1: disabled chips (e.g. execute_intent before verdict). */
.action-chip--disabled, .action-chip[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: auto;
}
.action-chip--disabled:hover, .action-chip[disabled]:hover {
  background: transparent;
  color: inherit;
}
.action-chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
@media (max-width: 768px) {
  .action-chip { font-size: 12px; padding: 4px 10px; }
}
