:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --panel: #12151a;
  --panel2: #181c22;
  --line: #282e37;
  --text: #f4f5f7;
  --muted: #9199a6;
  --accent: #a5ffcd;
  --danger: #ff8a8a;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; background: var(--bg); color: var(--text); }
button, input, textarea, select { font: inherit; }
.hidden { display: none !important; }
button { border: 0; border-radius: 10px; background: var(--accent); color: #07110c; font-weight: 700; padding: 11px 16px; cursor: pointer; }
button:disabled { opacity: .45; cursor: not-allowed; }
.secondary { background: var(--panel2); color: var(--text); border: 1px solid var(--line); }
.text-button, .icon { background: transparent; color: var(--muted); padding: 8px; }

.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; overflow: auto; }
.login-card { width: min(100%, 380px); padding: 32px; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; box-shadow: 0 24px 80px #0008; }
.mark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; background: var(--accent); color: #07110c; font-weight: 900; }
.login-card h1 { margin: 20px 0 6px; }
.login-card p { color: var(--muted); margin: 0 0 24px; }
.login-card label, dialog label { display: grid; gap: 8px; color: var(--muted); }
input, select, textarea { width: 100%; background: #0f1216; color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 12px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: #5c8971; box-shadow: 0 0 0 2px #5c897122; }
.login-card button { width: 100%; margin-top: 16px; }
.error { display: block; color: var(--danger); min-height: 20px; margin-top: 10px; }

.app { height: 100dvh; max-height: 100dvh; overflow: hidden; display: grid; grid-template-columns: 280px minmax(0, 1fr); }
.sidebar { height: 100dvh; overflow: hidden; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.sidebar header, .topbar { height: 64px; flex: 0 0 64px; display: flex; align-items: center; padding: 0 18px; border-bottom: 1px solid var(--line); }
.sidebar header { justify-content: space-between; }
.new-chat { margin: 16px; }
.chat-list { min-height: 0; overflow-y: auto; overscroll-behavior: contain; flex: 1; padding: 0 8px; }
.chat-item { display: block; width: 100%; text-align: left; background: transparent; color: var(--text); font-weight: 500; padding: 12px; border-radius: 9px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item:hover, .chat-item.active { background: var(--panel2); }
.chat-item small { display: block; color: var(--muted); margin-top: 4px; }
.sidebar footer { padding: 10px 12px; border-top: 1px solid var(--line); }

.chat-shell { height: 100dvh; min-height: 0; min-width: 0; overflow: hidden; display: grid; grid-template-rows: 64px minmax(0, 1fr) auto auto; }
.topbar { justify-content: space-between; background: #0b0d10e8; backdrop-filter: blur(12px); }
.topbar div { min-width: 0; }
.topbar strong, .topbar small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar small { color: var(--muted); margin-top: 3px; }
.status { font-size: 12px; color: var(--muted); }
.status.online { color: var(--accent); }
.messages { min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; padding: 28px max(20px, calc((100% - 820px) / 2)); scroll-behavior: smooth; scrollbar-gutter: stable; }
.empty { min-height: 100%; display: grid; place-items: center; color: var(--muted); }
.message { margin: 0 0 22px; }
.message .meta { font-size: 12px; color: var(--muted); margin-bottom: 7px; }
.message .bubble { line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.message.user .bubble { background: var(--panel2); border: 1px solid var(--line); border-radius: 14px; padding: 13px 15px; }
.message.system .bubble { color: var(--danger); }
.message.streaming .bubble:after { content: '▋'; display: inline-block; margin-left: 2px; color: var(--accent); animation: blink 1s steps(1) infinite; }
.badge { display: inline-block; margin-left: 6px; padding: 2px 6px; border: 1px solid #795c33; border-radius: 999px; color: #ffd28e; font-size: 10px; }

.activity { min-height: 38px; padding: 7px max(20px, calc((100% - 820px) / 2)); border-top: 1px solid var(--line); display: flex; gap: 7px; overflow-x: auto; overflow-y: hidden; }
.tool-chip { flex: 0 0 auto; display: flex; align-items: center; gap: 6px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 11px; background: var(--panel); }
.tool-chip.active { color: var(--text); border-color: #4c735e; }
.tool-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.tool-chip.active .tool-dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); animation: pulse 1.2s infinite; }

.composer { flex: 0 0 auto; padding: 10px max(16px, calc((100% - 840px) / 2)) max(12px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--bg); }
.run-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 9px; }
.mode-switch { display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--line); border-radius: 11px; background: var(--panel); }
.mode-option { padding: 6px 11px; border-radius: 8px; background: transparent; color: var(--muted); font-size: 12px; font-weight: 600; }
.mode-option:hover { color: var(--text); background: var(--panel2); }
.mode-option.active { background: var(--accent); color: #07110c; }
.config-toggle { min-width: 0; max-width: 50%; display: flex; align-items: center; gap: 7px; padding: 7px 10px; border: 1px solid var(--line); background: transparent; color: var(--muted); font-size: 11px; font-weight: 600; }
.config-toggle span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.config-toggle:hover, .config-toggle[aria-expanded="true"] { color: var(--text); background: var(--panel); }
.config-toggle .chevron { transition: transform .18s; }
.config-toggle[aria-expanded="true"] .chevron { transform: rotate(180deg); }
.config-panel { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0 0 9px; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); box-shadow: 0 12px 32px #0005; }
.config-panel label { min-width: 0; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .05em; }
.config-panel select { height: 36px; margin-top: 5px; padding: 7px 30px 7px 9px; font-size: 12px; text-transform: none; letter-spacing: 0; background: var(--bg); }
.composer textarea { resize: none; max-height: 160px; min-height: 48px; }
.composer-actions { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.composer-actions button { margin-left: auto; }
.composer-actions .secondary + button { margin-left: 0; }
.elevated { flex: 1; font-size: 12px; color: var(--muted); display: flex; gap: 7px; align-items: center; }
.elevated input { width: auto; accent-color: #efb15d; }

@keyframes blink { 50% { opacity: 0; } }
@keyframes pulse { 50% { opacity: .4; } }

dialog { width: min(92vw, 440px); border: 1px solid var(--line); border-radius: 16px; background: var(--panel); color: var(--text); padding: 24px; }
dialog::backdrop { background: #000a; }
dialog form { display: grid; gap: 18px; }
dialog h2 { margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }
.mobile { display: none; }

@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .mobile { display: block; }
  .sidebar { position: fixed; z-index: 10; inset: 0 18% 0 0; width: auto; transform: translateX(-105%); transition: .2s; box-shadow: 20px 0 80px #000; }
  .sidebar.open { transform: translateX(0); }
  .topbar { padding: 0 10px; }
  .topbar > div { flex: 1; margin: 0 8px; }
  .messages { padding: 18px 14px; scrollbar-gutter: auto; }
  .activity { padding-inline: 12px; }
  .composer { padding: 8px 10px max(8px, env(safe-area-inset-bottom)); }
  .run-toolbar { gap: 6px; margin-bottom: 7px; }
  .mode-switch { flex: 1; }
  .mode-option { flex: 1; min-width: 0; padding: 6px 5px; font-size: 11px; }
  .config-toggle { max-width: 42%; padding: 7px 8px; }
  .config-panel { grid-template-columns: 1fr 1fr; gap: 8px; padding: 9px; }
  .config-panel label:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .composer textarea { max-height: 120px; }
  .status { font-size: 0; }
  .status:after { content: '●'; font-size: 12px; }
  .message { margin-bottom: 18px; }
}

@media (max-width: 390px) {
  .mode-option { font-size: 10px; }
  .config-toggle { max-width: 38%; }
  .config-toggle .chevron { display: none; }
}
