:root {
  --bg: #0d1117;
  --bg-2: #161b22;
  --bg-3: #21262d;
  --border: #30363d;
  --fg: #e6edf3;
  --muted: #8b949e;
  --accent: #d97757;
  --accent-2: #f0a58a;
  --danger: #f85149;
  --ok: #3fb950;
  --radius: 10px;
  font-size: 15px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.view { height: 100vh; height: 100dvh; }
.center { display: flex; align-items: center; justify-content: center; padding: 20px; }

/* ---------- cards / auth ---------- */
.card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}
.auth-card { width: 100%; max-width: 380px; text-align: center; }
.brand { font-weight: 700; font-size: 1.25rem; display: flex; align-items: center; gap: 8px; justify-content: center; }
.brand.small { font-size: 1rem; justify-content: flex-start; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.hint { font-size: 0.8rem; color: var(--muted); margin: 10px 0 0; }
.lbl { display: block; text-align: left; font-size: 0.8rem; color: var(--muted); margin: 14px 0 4px; }

/* ---------- inputs / buttons ---------- */
.input {
  width: 100%; padding: 11px 12px; background: var(--bg); color: var(--fg);
  border: 1px solid var(--border); border-radius: 8px; font-size: 0.95rem;
}
.input:focus { outline: none; border-color: var(--accent); }
.btn {
  cursor: pointer; border: 1px solid var(--border); background: var(--bg-3); color: var(--fg);
  padding: 9px 14px; border-radius: 8px; font-size: 0.9rem; font-weight: 500;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #2b333c; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a1005; font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); }
.btn.big { width: 100%; padding: 12px; margin-top: 8px; font-size: 1rem; }
.btn.small { padding: 6px 10px; font-size: 0.8rem; }
.btn.ghost { background: transparent; }
.btn.link { background: none; border: none; color: var(--accent); padding: 8px; }
.btn.link:hover { text-decoration: underline; background: none; }
.icon-btn {
  cursor: pointer; background: transparent; border: 1px solid transparent; color: var(--fg);
  font-size: 1rem; border-radius: 6px; width: 30px; height: 30px; line-height: 1;
}
.icon-btn:hover { background: var(--bg-3); }
.msg { min-height: 20px; font-size: 0.85rem; margin-top: 12px; }
.msg.err { color: var(--danger); }
.msg.ok { color: var(--ok); }

/* ---------- app layout ---------- */
#view-app { display: flex; }
.sidebar {
  width: 230px; min-width: 230px; background: var(--bg-2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 14px;
}
.side-head { display: flex; justify-content: space-between; align-items: center; margin: 18px 0 6px; font-size: 0.75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.project-list { list-style: none; margin: 0; padding: 0; flex: 1; overflow-y: auto; }
.project-list li {
  padding: 9px 10px; border-radius: 8px; cursor: pointer; font-size: 0.9rem;
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
}
.project-list li:hover { background: var(--bg-3); }
.project-list li.active { background: var(--accent); color: #1a1005; font-weight: 600; }
.project-list li .pj-del { opacity: 0; font-size: 0.85rem; }
.project-list li:hover .pj-del { opacity: .6; }
.project-list li .missing { color: var(--danger); font-size: 0.7rem; }
.side-foot { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }

.workspace { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: flex-start; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--bg-2);
}
.current-project { font-weight: 600; font-size: 0.95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.global-usage { margin-left: auto; font-size: 0.72rem; font-family: ui-monospace, monospace; color: var(--muted); white-space: nowrap; }
.tabs { display: flex; gap: 4px; }
.tab { background: transparent; border: none; color: var(--muted); padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 0.9rem; }
.tab.active { background: var(--bg-3); color: var(--fg); }

.tabpane { flex: 1; display: none; min-height: 0; }
.tabpane.active { display: flex; flex-direction: column; }

/* ---------- terminal ---------- */
.term-toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.term-status { margin-left: auto; font-size: 0.75rem; color: var(--muted); }
.term-status.on { color: var(--ok); }
.terminal-host { flex: 1; min-height: 0; padding: 6px 4px 4px 10px; background: #000; }

/* ---------- Claude chat (multi-session) ---------- */
.chat-layout { flex: 1; display: flex; min-height: 0; }
.chat-rail { width: 230px; min-width: 230px; border-right: 1px solid var(--border); background: var(--bg-2); display: flex; flex-direction: column; padding: 10px; overflow-y: auto; }
.chat-new { width: 100%; margin-bottom: 8px; }
.rail-section { font-size: 0.7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 12px 4px 4px; display: flex; align-items: center; justify-content: space-between; }
.chat-list { list-style: none; margin: 0; padding: 0; }
.chat-list.history { flex: 1; }
.chat-item { display: flex; align-items: center; gap: 6px; padding: 7px 8px; border-radius: 8px; cursor: pointer; }
.chat-item:hover { background: var(--bg-3); }
.chat-item.active { background: var(--accent); color: #1a1005; }
.chat-item.active .ci-sub { color: #5a3a1a; }
.ci-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ci-title { font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci-sub { font-size: 0.68rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci-close { opacity: 0; font-size: 0.8rem; }
.chat-item:hover .ci-close { opacity: .6; }
.hist-empty { padding: 6px 8px; font-size: 0.78rem; list-style: none; }

.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-header { display: flex; align-items: center; gap: 10px; padding: 9px 14px; border-bottom: 1px solid var(--border); }
.chat-title { font-weight: 600; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-usage { margin-left: auto; font-size: 0.72rem; font-family: ui-monospace, monospace; }
.chat-header .term-status { margin-left: 8px; }
.chat-rail-toggle { display: none; }
.chat-log { flex: 1; overflow-y: auto; }
.chat-messages { display: flex; flex-direction: column; gap: 12px; padding: 16px; min-height: 100%; box-sizing: border-box; }
.chat-empty { max-width: 560px; margin: 24px auto; text-align: center; line-height: 1.6; }
.chat-divider { text-align: center; color: var(--muted); font-size: 0.72rem; margin: 4px 0; position: relative; }
.chat-divider span { background: var(--bg); padding: 0 10px; }
.chat-divider::before { content: ''; position: absolute; left: 0; right: 0; top: 50%; border-top: 1px dashed var(--border); z-index: -1; }
.msg { max-width: 820px; width: fit-content; }
.msg.user { align-self: flex-end; background: var(--accent); color: #1a1005; padding: 9px 13px; border-radius: 12px 12px 2px 12px; }
.msg.user .msg-who { display: none; }
.msg.claude { align-self: flex-start; }
.msg.error { align-self: flex-start; color: var(--danger); border: 1px solid var(--danger); padding: 8px 12px; border-radius: 10px; }
.msg-who { font-size: 0.7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 4px; }
.md { font-size: 0.92rem; line-height: 1.6; }
.md-text { white-space: pre-wrap; word-break: break-word; }
.md code { background: var(--bg-3); padding: 1px 5px; border-radius: 4px; font-family: ui-monospace, monospace; font-size: 0.85em; }
.md pre { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; overflow-x: auto; font-size: 0.82rem; }
.msg.tool { align-self: flex-start; display: flex; align-items: center; gap: 8px; background: var(--bg-2); border: 1px solid var(--border); padding: 6px 10px; border-radius: 8px; font-size: 0.8rem; }
.tool-name { color: var(--accent-2); font-weight: 600; white-space: nowrap; }
.tool-arg { color: var(--muted); font-family: ui-monospace, monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg.tool-result { align-self: flex-start; max-width: 820px; }
.msg.tool-result .tool-name { color: var(--muted); }
.msg.tool-result pre { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; margin: 4px 0 0; overflow-x: auto; font-size: 0.78rem; max-height: 220px; overflow-y: auto; }
.thinking { color: var(--muted); font-size: 0.85rem; }
.thinking summary { cursor: pointer; }
.msg.typing .dots { color: var(--muted); letter-spacing: 2px; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: .3; } 50% { opacity: 1; } }
.chat-input { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); }
.chat-attachments { display: flex; flex-wrap: wrap; gap: 6px; }
.chat-attachments:empty { display: none; }
.attach-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--bg-3); border: 1px solid var(--border); border-radius: 6px; padding: 3px 8px; font-size: 0.75rem; }
.attach-x { cursor: pointer; opacity: .6; }
.attach-x:hover { opacity: 1; }
.chat-input textarea { resize: none; background: var(--bg); color: var(--fg); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-family: inherit; font-size: 0.92rem; line-height: 1.4; max-height: 160px; }
.chat-input textarea:focus { outline: none; border-color: var(--accent); }
.composer-actions { display: flex; align-items: center; gap: 8px; }
.composer-select { background: var(--bg-3); color: var(--fg); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; font-size: 0.8rem; }
.composer-spacer { flex: 1; }

@media (max-width: 720px) {
  .chat-rail { position: absolute; z-index: 20; height: 100%; transform: translateX(-100%); transition: transform .2s; }
  .chat-rail.open { transform: translateX(0); }
  .chat-rail-toggle { display: inline-flex; }
  .chat-main { position: relative; }
}

/* ---------- files ---------- */
.files-layout { flex: 1; display: flex; min-height: 0; }
.file-tree-col { width: 300px; min-width: 220px; border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.tree-toolbar { display: flex; gap: 4px; padding: 8px; border-bottom: 1px solid var(--border); }
.file-tree { flex: 1; overflow: auto; padding: 8px; font-size: 0.85rem; }
.tree-node { padding: 3px 6px; border-radius: 6px; cursor: pointer; white-space: nowrap; display: flex; align-items: center; gap: 5px; }
.tree-node:hover { background: var(--bg-3); }
.tree-node.sel { background: var(--accent); color: #1a1005; }
.tree-children { margin-left: 14px; border-left: 1px solid var(--border); padding-left: 4px; }
.tree-node .caret { width: 10px; display: inline-block; color: var(--muted); }
.tree-node .heavy { color: var(--muted); font-style: italic; }

.file-edit-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.editor-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.editor-path { font-size: 0.8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor {
  flex: 1; width: 100%; resize: none; border: none; padding: 12px 14px;
  background: var(--bg); color: var(--fg); font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.85rem; line-height: 1.5; tab-size: 2;
}
.editor:focus { outline: none; }

/* ---------- modal / toast ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal { width: 100%; max-width: 420px; }
.modal h3 { margin: 0 0 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--bg-3); border: 1px solid var(--border); padding: 10px 18px; border-radius: 8px;
  font-size: 0.85rem; z-index: 60; box-shadow: 0 6px 24px rgba(0,0,0,.4);
}
.toast.err { border-color: var(--danger); color: var(--accent-2); }
.settings-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 0.85rem; gap: 8px; }
.settings-row .meta { color: var(--muted); font-size: 0.75rem; }
.token-box { word-break: break-all; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px; font-family: ui-monospace, monospace; font-size: 0.8rem; margin: 8px 0; }

/* ---------- mobile ---------- */
@media (max-width: 720px) {
  .sidebar { position: fixed; z-index: 30; height: 100%; transform: translateX(-100%); transition: transform .2s; }
  #view-app.nav-open .sidebar { transform: translateX(0); }
  .file-tree-col { width: 44%; min-width: 140px; }
  .menu-toggle { display: inline-flex !important; }
}
.menu-toggle { display: inline-flex; background: transparent; border: none; color: var(--fg); font-size: 1.3rem; cursor: pointer; margin-right: 6px; }
#view-app.sidebar-collapsed .sidebar { display: none; }
.rail-section.collapsible { cursor: pointer; user-select: none; }
.rail-section .caret { display: inline-block; transition: transform .15s; font-size: 0.7rem; }
.rail-section.collapsed .caret { transform: rotate(-90deg); }
@media (max-width: 720px) { .global-usage { display: none; } }
