:root {
  --bg: #0B0C0E;
  --surface: #13151A;
  --surface-2: #1C1F26;
  --border: rgba(255, 255, 255, 0.08);
  --text: #E8EAED;
  --muted: #9AA0A6;
  --primary: #A8C7FA;
  --on-primary: #062E6F;
  --user-bubble: #1D3557;
  --user-text: #EAF2FF;
  --claude-accent: #D99B72;
  --danger: #F28B82;
  --warn: #FDD663;
  --ok: #81C995;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

[data-theme="light"] {
  --bg: #FDFCFB;
  --surface: #F4F5F7;
  --surface-2: #E8EAED;
  --border: rgba(0, 0, 0, 0.09);
  --text: #1F1F1F;
  --muted: #5F6368;
  --primary: #1A73E8;
  --on-primary: #FFFFFF;
  --user-bubble: #D3E3FD;
  --user-text: #041E49;
  --claude-accent: #BD5D38;
  --danger: #D93025;
  --warn: #E37400;
  --ok: #188038;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.14);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overflow: hidden;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.85rem; }
.error-text { color: var(--danger); font-size: 0.85rem; margin-top: 8px; }
.full-width { width: 100%; }

/* Auth Screen */
.auth-screen {
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-card {
  width: 100%;
  max-width: 390px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
  text-align: center;
}
.auth-logo {
  width: 54px; height: 54px; border-radius: 16px;
  background: linear-gradient(135deg, #1A73E8, #6C47FF);
  color: #fff; font-weight: 700; font-size: 26px;
  display: inline-flex; align-items: center; justify-content: center;
  margin-bottom: 12px;
}
.auth-card h1 { margin: 0 0 6px; font-size: 1.35rem; }
.auth-card input {
  width: 100%; margin: 16px 0 12px; padding: 13px 14px;
  border-radius: 14px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font-size: 0.95rem;
}

/* Buttons */
.primary-btn {
  background: var(--primary); color: var(--on-primary);
  border: none; border-radius: 14px; padding: 12px 16px;
  font-weight: 600; font-size: 0.95rem; cursor: pointer;
}
.outlined-btn {
  background: transparent; color: var(--text);
  border: 1px solid var(--border); border-radius: 14px; padding: 10px 14px;
  font-weight: 500; cursor: pointer;
}
.icon-btn {
  background: transparent; border: none; color: var(--text);
  width: 40px; height: 40px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn.small { width: 34px; height: 34px; }
.text-btn {
  background: transparent; border: none; color: var(--muted);
  font-weight: 600; font-size: 0.85rem; padding: 6px 10px;
  border-radius: 10px; cursor: pointer;
}
.text-btn.accent { color: var(--primary); }
.text-btn.danger { color: var(--danger); }

/* Layout Shell */
.app-shell {
  display: flex;
  height: 100dvh;
  width: 100vw;
  position: relative;
  overflow: hidden;
}

.backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55);
  z-index: 40; backdrop-filter: blur(2px);
}

/* Navigation Drawer */
.drawer {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: min(84vw, 330px);
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 50;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) 10px env(safe-area-inset-bottom);
  transform: translateX(-105%);
  transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.drawer.open { transform: translateX(0); }

@media (min-width: 960px) {
  .drawer { position: static; transform: none; z-index: 1; }
  .backdrop { display: none !important; }
  #menu-btn { display: none; }
}

.drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 4px 6px;
}
.brand-row { display: flex; align-items: center; gap: 10px; }
.mini-logo {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, #1A73E8, #6C47FF);
  color: #fff; font-weight: 700; display: inline-flex;
  align-items: center; justify-content: center;
}
.brand-title { font-weight: 700; font-size: 1.15rem; }

.drawer-search-wrap {
  position: relative; margin: 6px 2px 8px;
}
.search-ico {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--muted); pointer-events: none;
}
.drawer-search-wrap input {
  width: 100%; padding: 9px 12px 9px 36px;
  border-radius: 20px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font-size: 0.9rem;
}

.workspace-chips {
  display: flex; gap: 6px; overflow-x: auto; padding: 2px 2px 8px;
  scrollbar-width: none;
}
.workspace-chips::-webkit-scrollbar { display: none; }
.ws-chip {
  white-space: nowrap; border: 1px solid var(--border);
  background: transparent; color: var(--muted);
  padding: 5px 12px; border-radius: 16px; font-size: 0.82rem; font-weight: 500;
  cursor: pointer;
}
.ws-chip.active {
  background: var(--primary); color: var(--on-primary); border-color: transparent;
}

.conv-list {
  flex: 1; overflow-y: auto; padding: 4px 0;
}
.bucket-label {
  font-size: 0.74rem; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.04em;
  padding: 10px 10px 4px;
}
.conv-row {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; border-radius: 12px; cursor: pointer;
}
.conv-row:hover, .conv-row.active { background: var(--surface-2); }
.conv-meta { flex: 1; min-width: 0; }
.conv-title {
  font-size: 0.9rem; font-weight: 500; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.conv-preview {
  font-size: 0.77rem; color: var(--muted); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.spinner {
  width: 14px; height: 14px; border: 2px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 0.8s linear infinite; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.drawer-footer {
  border-top: 1px solid var(--border); padding-top: 10px;
}
.usage-mini-card {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 14px; padding: 10px 12px; color: var(--text);
  cursor: pointer; text-align: left;
}
.usage-mini-top {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 0.82rem; font-weight: 500; margin-bottom: 6px;
}
.conn-label { display: inline-flex; align-items: center; gap: 6px; }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.conn-dot.offline { background: var(--danger); }
.progress-track {
  width: 100%; height: 6px; background: rgba(255,255,255,0.08);
  border-radius: 4px; overflow: hidden;
}
[data-theme="light"] .progress-track { background: rgba(0,0,0,0.08); }
.progress-fill {
  height: 100%; background: var(--primary); border-radius: 4px; transition: width 0.25s;
}
.progress-fill.amber { background: var(--warn); }
.progress-fill.coral { background: var(--danger); }
.drawer-footer-actions {
  display: flex; justify-content: space-between; margin-top: 6px;
}

/* Main Column */
.main-column {
  flex: 1; display: flex; flex-direction: column; min-width: 0;
  height: 100dvh; background: var(--bg);
}

.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.title-pill {
  flex: 1; min-width: 0; background: transparent; border: none;
  color: var(--text); text-align: left; padding: 4px 6px;
  border-radius: 12px; cursor: pointer; display: flex; flex-direction: column;
}
.title-pill:active { background: var(--surface); }
.topbar-title {
  font-weight: 600; font-size: 0.98rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-model { font-size: 0.74rem; color: var(--primary); font-weight: 500; }
.topbar-actions { display: flex; align-items: center; gap: 2px; }

.warning-banner {
  background: rgba(251, 140, 0, 0.16);
  color: var(--warn);
  padding: 6px 14px; font-size: 0.82rem;
  display: flex; justify-content: space-between; align-items: center;
}
.error-banner {
  background: rgba(229, 57, 53, 0.18);
  color: var(--danger);
  padding: 8px 14px; font-size: 0.84rem;
}

/* Messages */
.chat-scroll {
  flex: 1; overflow-y: auto; padding: 14px 14px 18px;
  scroll-behavior: smooth;
}
.empty-state {
  max-width: 440px; margin: 14vh auto 0; text-align: center; padding: 16px;
}
.empty-badge {
  display: inline-block; padding: 6px 14px; border-radius: 20px;
  background: var(--surface-2); color: var(--primary);
  font-weight: 700; margin-bottom: 10px;
}
.empty-state h2 { margin: 4px 0 8px; font-size: 1.4rem; }

.messages-list {
  max-width: 780px; margin: 0 auto;
  display: flex; flex-direction: column; gap: 16px;
}
.msg-user-wrap { display: flex; justify-content: flex-end; }
.msg-user {
  max-width: 85%; background: var(--user-bubble); color: var(--user-text);
  padding: 10px 15px; border-radius: 20px 20px 6px 20px;
  white-space: pre-wrap; word-break: break-word;
}

.msg-assistant { max-width: 100%; }
.thinking-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 8px 12px; margin-bottom: 10px;
}
.thinking-box summary {
  cursor: pointer; font-size: 0.82rem; font-weight: 600; color: var(--muted);
}
.thinking-body {
  margin-top: 8px; font-size: 0.83rem; color: var(--muted);
  white-space: pre-wrap; word-break: break-word;
}

.md-body { word-break: break-word; overflow-wrap: anywhere; }
.md-body p { margin: 0 0 10px; }
.md-body p:last-child { margin-bottom: 0; }
.md-body h1, .md-body h2, .md-body h3, .md-body h4 { margin: 14px 0 6px; line-height: 1.3; }
.md-body ul, .md-body ol { padding-left: 20px; margin: 6px 0 10px; }
.md-body blockquote {
  margin: 8px 0; padding: 4px 12px;
  border-left: 3px solid var(--primary); color: var(--muted);
}
.md-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86em; background: var(--surface-2);
  padding: 2px 5px; border-radius: 6px;
}
.code-block-wrap {
  margin: 10px 0; border-radius: 14px; overflow: hidden;
  border: 1px solid var(--border); background: #0d1017;
}
.code-block-hdr {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 12px; background: rgba(255,255,255,0.05);
  font-size: 0.76rem; color: #9aa0a6;
}
.copy-code-btn {
  background: transparent; border: none; color: #a8c7fa;
  font-size: 0.76rem; font-weight: 600; cursor: pointer;
}
.code-block-wrap pre {
  margin: 0; padding: 12px; overflow-x: auto;
  font-size: 0.84rem; line-height: 1.45; color: #e6edf3;
}
.code-block-wrap pre code { background: transparent; padding: 0; }
.table-scroll { overflow-x: auto; margin: 10px 0; }
.md-body table { border-collapse: collapse; width: 100%; font-size: 0.86rem; }
.md-body th, .md-body td {
  border: 1px solid var(--border); padding: 6px 10px; text-align: left;
}
.md-body th { background: var(--surface-2); }

.streaming-slot {
  max-width: 780px; margin: 14px auto 0;
  display: flex; flex-direction: column; gap: 8px;
}
.streaming-pill {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 0.82rem; color: var(--primary); font-weight: 600;
}

.artifacts-bar {
  max-width: 780px; margin: 12px auto 0;
  display: flex; gap: 8px; flex-wrap: wrap;
}
.artifact-chip {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); padding: 8px 13px; border-radius: 14px;
  font-size: 0.85rem; font-weight: 500; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.artifact-chip.plan { border-color: var(--claude-accent); color: var(--claude-accent); }

/* Composer */
.composer-dock {
  padding: 4px 10px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg);
}
.paste-offer, .pending-attachments {
  max-width: 780px; margin: 0 auto 6px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; overflow-x: auto;
}
.att-chip {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 12px; padding: 6px 10px; min-width: 140px;
  display: flex; flex-direction: column; gap: 4px;
}
.att-chip-top {
  display: flex; justify-content: space-between; align-items: center; gap: 6px;
  font-size: 0.8rem;
}
.composer-pill {
  max-width: 780px; margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 26px;
  padding: 8px 10px 6px 14px;
  box-shadow: var(--shadow);
}
.composer-pill textarea {
  width: 100%; border: none; outline: none; resize: none;
  background: transparent; color: var(--text);
  font: inherit; max-height: 180px; overflow-y: auto;
  padding: 4px 0 6px;
}
.composer-controls {
  display: flex; justify-content: space-between; align-items: center;
}
.composer-left { display: flex; align-items: center; gap: 6px; }
.mode-pill {
  border: 1px solid var(--border); background: var(--surface-2);
  border-radius: 16px; padding: 5px 11px; font-size: 0.76rem;
  font-weight: 700; letter-spacing: 0.03em; cursor: pointer;
}
.mode-pill.readonly { color: var(--primary); }
.mode-pill.plan { color: var(--ok); }
.mode-pill.auto { color: var(--warn); }
.mode-pill.agent { color: var(--danger); }

.send-btn {
  width: 38px; height: 38px; border-radius: 50%; border: none;
  background: var(--primary); color: var(--on-primary);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.send-btn.stop { background: var(--danger); color: #fff; }

/* Bottom Sheets */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 80;
}
.bottom-sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 90;
  max-height: 88dvh; background: var(--surface);
  border-radius: 24px 24px 0 0; border-top: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 8px 16px calc(18px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow);
}
@media (min-width: 720px) {
  .bottom-sheet {
    max-width: 680px; margin: 0 auto; border-radius: 24px; bottom: 24px;
  }
}
.sheet-handle {
  width: 40px; height: 4px; border-radius: 2px;
  background: var(--border); margin: 4px auto 12px;
}
.sheet-content { overflow-y: auto; flex: 1; }
.sheet-header {
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px; margin-bottom: 12px;
}
.sheet-title { font-size: 1.05rem; font-weight: 700; }
.sheet-list-btn {
  width: 100%; text-align: left; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 14px;
  padding: 12px 14px; color: var(--text); margin-bottom: 8px;
  font-size: 0.92rem; font-weight: 500; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center;
}
.sheet-list-btn.active { border-color: var(--primary); color: var(--primary); }
.meter-card {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 16px; padding: 14px; margin-bottom: 12px;
}
.meter-row-top {
  display: flex; justify-content: space-between; font-size: 0.88rem; margin: 8px 0 5px;
}
.plan-actions {
  display: flex; gap: 8px; margin-top: 14px; padding-top: 10px;
  border-top: 1px solid var(--border);
}
.plan-actions button { flex: 1; }
