:root {
  --bg: #0e1116;
  --panel: #151a22;
  --panel-2: #1b2230;
  --border: #262f3f;
  --text: #dce3ec;
  --muted: #8a97a8;
  --accent: #4f8cff;
  --accent-2: #2dd4a7;
  --error: #ff6b6b;
  --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
.hidden { display: none !important; }
button { cursor: pointer; font: inherit; }

/* login */
#login-view {
  height: 100%; display: flex; align-items: center; justify-content: center;
}
.login-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 40px 36px; width: 340px; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.login-box h1 { margin: 0; font-size: 34px; letter-spacing: 2px; }
.login-sub { color: var(--muted); margin: 4px 0 24px; font-size: 13px; }
.login-box input {
  width: 100%; margin-bottom: 12px; padding: 11px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
}
.login-box button {
  width: 100%; padding: 11px; border: none; border-radius: 8px;
  background: var(--accent); color: white; font-weight: 600;
}
.error { color: var(--error); font-size: 13px; margin-top: 10px; min-height: 16px; }

/* layout */
#app-view { display: grid; grid-template-columns: 260px 1fr 0fr; height: 100%; }
#app-view.files-open { grid-template-columns: 260px 1fr 320px; }
.sidebar {
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 14px; gap: 10px;
}
.mode-toggle { display: flex; gap: 6px; }
.mode-btn {
  flex: 1; padding: 8px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--muted); font-weight: 600; font-size: 13px;
}
.mode-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.new-chat {
  padding: 10px; border-radius: 8px; border: 1px solid var(--border);
  background: transparent; color: var(--text); font-weight: 600;
}
.new-chat:hover { border-color: var(--accent); }
.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.conv-item {
  padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 13px;
  color: var(--muted); display: flex; justify-content: space-between; gap: 6px;
  align-items: center;
}
.conv-item:hover { background: var(--panel-2); }
.conv-item.active { background: var(--panel-2); color: var(--text); }
.conv-title {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;
}
.conv-del { opacity: 0; color: var(--muted); border: none; background: none; font-size: 14px; }
.conv-item:hover .conv-del { opacity: 1; }
.conv-del:hover { color: var(--error); }
.sidebar-footer {
  display: flex; justify-content: space-between; align-items: center;
  border-top: 1px solid var(--border); padding-top: 10px; font-size: 13px;
}
.link-btn { border: none; background: none; color: var(--accent); font-size: 13px; }

/* main / chat */
.main { display: flex; flex-direction: column; height: 100%; min-width: 0; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 18px; border-bottom: 1px solid var(--border);
}
.mode-label { font-size: 12px; color: var(--muted); letter-spacing: 1px; text-transform: uppercase; }
.chat-scroll { flex: 1; overflow-y: auto; }
.messages { max-width: 860px; margin: 0 auto; padding: 20px 18px 30px; display: flex; flex-direction: column; gap: 18px; }
.msg { display: flex; flex-direction: column; gap: 6px; max-width: 100%; }
.msg.user { align-items: flex-end; }
.msg .bubble {
  padding: 11px 15px; border-radius: 12px; background: var(--panel-2);
  border: 1px solid var(--border); overflow-wrap: anywhere;
}
.msg.user .bubble { background: #1d2a44; border-color: #2a3d63; }
.msg .who { font-size: 11px; color: var(--muted); margin: 0 4px; }
.msg .bubble p { margin: 0 0 8px; } .msg .bubble p:last-child { margin: 0; }
.msg .bubble pre {
  background: #0a0d12; padding: 12px; border-radius: 8px; overflow-x: auto;
  font-family: var(--mono); font-size: 13px;
}
.msg .bubble code { font-family: var(--mono); font-size: 13px; }
.msg .bubble :not(pre) > code { background: #0a0d12; padding: 1px 5px; border-radius: 4px; }
.msg .bubble ul, .msg .bubble ol { margin: 6px 0; padding-left: 22px; }
.msg .bubble a { color: var(--accent); }
details.thinking { margin: 0 4px; }
details.thinking summary {
  cursor: pointer; font-size: 12px; color: var(--muted); user-select: none;
}
details.thinking .think-body {
  margin-top: 6px; font-size: 13px; color: var(--muted);
  background: var(--panel); border-left: 2px solid var(--border);
  padding: 8px 12px; border-radius: 0 8px 8px 0; white-space: pre-wrap;
}
.tool-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 4px; }
.tool-chip {
  font-family: var(--mono); font-size: 11px; color: var(--accent-2);
  background: rgba(45, 212, 167, .08); border: 1px solid rgba(45, 212, 167, .25);
  border-radius: 999px; padding: 2px 10px;
}
.tool-chip.running { color: var(--muted); border-color: var(--border); }
.chat-form {
  display: flex; gap: 10px; padding: 12px 18px 16px;
  border-top: 1px solid var(--border); background: var(--bg);
}
.chat-form textarea {
  flex: 1; resize: none; padding: 11px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  font: inherit;
}
.chat-form textarea:focus { outline: none; border-color: var(--accent); }
#chat-send {
  padding: 0 22px; border: none; border-radius: 10px;
  background: var(--accent); color: #fff; font-weight: 600;
}
#chat-send:disabled { opacity: .5; }

/* files panel */
.files-panel {
  background: var(--panel); border-left: 1px solid var(--border);
  overflow-y: auto; padding: 12px;
}
.files-header {
  display: flex; justify-content: space-between; align-items: center;
  font-family: var(--mono); font-size: 12px; color: var(--muted);
  margin-bottom: 8px; border-bottom: 1px solid var(--border); padding-bottom: 8px;
}
.files-list { display: flex; flex-direction: column; gap: 2px; }
.file-row {
  display: flex; justify-content: space-between; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: 12.5px; padding: 5px 8px; border-radius: 6px;
  cursor: pointer; color: var(--text);
}
.file-row:hover { background: var(--panel-2); }
.file-row .del { opacity: 0; border: none; background: none; color: var(--muted); }
.file-row:hover .del { opacity: 1; }
.file-row .del:hover { color: var(--error); }
#file-preview {
  margin-top: 12px; font-family: var(--mono); font-size: 12px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px; white-space: pre-wrap; max-height: 50vh; overflow-y: auto;
}

@media (max-width: 900px) {
  #app-view, #app-view.files-open { grid-template-columns: 220px 1fr; }
  .files-panel { position: fixed; right: 0; top: 0; bottom: 0; width: 320px; z-index: 5; }
}
