:root {
  --bg: #0d1117; --bg2: #161b22; --bg3: #21262d; --bg4: #2d333b;
  --border: #30363d; --txt: #e6edf3; --muted: #8b949e;
  --accent: #3b82f6; --accent2: #2563eb;
  --ok: #3fb950; --warn: #d29922; --danger: #f85149;
  --user: #1f6feb22; --ai: #161b22;
  --radius: 8px;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "SF Mono", SFMono-Regular, ui-monospace, Consolas, "Liberation Mono", Menlo, monospace;
  --topbar-h: 44px; --activity-w: 48px;
}
html[data-theme="light"] {
  --bg: #ffffff; --bg2: #f6f8fa; --bg3: #eaeef2; --bg4: #dfe3e8;
  --border: #d0d7de; --txt: #1f2328; --muted: #636c76;
  --user: #3b82f611; --ai: #f6f8fa;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--txt); font-family: var(--sans);
  font-size: 13px; overflow: hidden; display: flex; flex-direction: column;
}
button { font-family: inherit; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ===================== Top bar ===================== */
#topbar {
  height: var(--topbar-h); flex-shrink: 0; display: flex; align-items: center;
  gap: 6px; padding: 0 10px; background: var(--bg2); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; margin-right: 6px; }
.brand .logo {
  width: 26px; height: 26px; border-radius: 7px; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-family: var(--mono);
  font-size: 13px; font-weight: 700;
}
.brand-name b { color: var(--accent); font-weight: 700; }
.tb-spacer { flex: 1; }
.tb-btn {
  background: var(--bg3); border: 1px solid var(--border); color: var(--txt);
  height: 30px; padding: 0 10px; border-radius: 7px; cursor: pointer; font-size: 12.5px;
  display: flex; align-items: center; gap: 5px;
}
.tb-btn:hover { background: var(--bg4); border-color: var(--accent); }
.tb-btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.tb-btn.accent:hover { background: var(--accent2); }
.gh-ico { width: 1.15em; height: 1.15em; fill: currentColor; display: inline-block; vertical-align: -0.15em; flex: none; }
.act .gh-ico { width: 1em; height: 1em; }
#btnProject { font-weight: 600; }
@media (max-width: 900px) { .tb-btn span { display: none; } }

/* ===================== Workbench ===================== */
#workbench { flex: 1; display: flex; min-height: 0; }
#activitybar {
  width: var(--activity-w); flex-shrink: 0; background: var(--bg2);
  border-right: 1px solid var(--border); display: flex; flex-direction: column; align-items: center;
  padding-top: 6px; gap: 2px;
}
.act {
  width: 40px; height: 40px; background: none; border: none; color: var(--muted);
  font-size: 20px; cursor: pointer; border-left: 2px solid transparent; border-radius: 0;
}
.act:hover { color: var(--txt); }
.act.active { color: var(--txt); border-left-color: var(--accent); }
.act-spacer { flex: 1; }

#sidepanel {
  width: 260px; flex-shrink: 0; background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}
.panel { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.panel-head {
  height: 34px; flex-shrink: 0; display: flex; align-items: center; justify-content: space-between;
  padding: 0 8px 0 12px; font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); font-weight: 600;
}
.panel-actions { display: flex; gap: 2px; }
.panel-actions button, #previewPane button {
  background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px;
  width: 26px; height: 26px; border-radius: 5px;
}
.panel-actions button:hover { background: var(--bg3); color: var(--txt); }
.scroll { flex: 1; overflow-y: auto; padding: 8px 10px; }

/* File tree */
.tree { flex: 1; overflow-y: auto; padding: 2px 4px 12px; user-select: none; }
.node { display: flex; align-items: center; gap: 5px; padding: 3px 6px; border-radius: 5px; cursor: pointer; white-space: nowrap; }
.node:hover { background: var(--bg3); }
.node.active { background: var(--bg4); }
.node .twist { width: 12px; text-align: center; color: var(--muted); flex-shrink: 0; }
.node .nicon { flex-shrink: 0; }
.node .nname { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.node .nact { opacity: 0; background: none; border: none; color: var(--muted); cursor: pointer; padding: 0 3px; }
.node:hover .nact { opacity: .8; }
.node .nact:hover { color: var(--txt); }
.node.dragover { box-shadow: inset 0 0 0 1px var(--accent); }
.tree-empty { color: var(--muted); padding: 14px 10px; font-size: 12.5px; line-height: 1.6; }

/* ===================== Center / editor ===================== */
.splitter { width: 5px; flex-shrink: 0; cursor: col-resize; background: transparent; }
.splitter:hover, .splitter.dragging { background: var(--accent); }
#center { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.tabbar { height: 36px; flex-shrink: 0; display: flex; align-items: stretch; background: var(--bg2); border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab {
  display: flex; align-items: center; gap: 7px; padding: 0 10px; border-right: 1px solid var(--border);
  cursor: pointer; color: var(--muted); font-size: 12.5px; white-space: nowrap; max-width: 200px;
}
.tab:hover { background: var(--bg3); }
.tab.active { background: var(--bg); color: var(--txt); }
.tab .tname { overflow: hidden; text-overflow: ellipsis; }
.tab .dirty { color: var(--accent); }
.tab .tclose { background: none; border: none; color: var(--muted); cursor: pointer; border-radius: 4px; width: 18px; height: 18px; }
.tab .tclose:hover { background: var(--bg4); color: var(--txt); }
#editorArea { flex: 1; position: relative; display: flex; min-height: 0; }
#editor { flex: 1; min-width: 0; }
.editor-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; background: var(--bg); color: var(--muted); }
.editor-empty .ee-logo { font-family: var(--mono); font-size: 46px; color: var(--accent); }
.editor-empty h2 { margin: 6px 0; color: var(--txt); }
.editor-empty p { margin: 4px 0; max-width: 380px; }

/* Preview */
#previewPane { width: 45%; flex-shrink: 0; border-left: 1px solid var(--border); display: flex; flex-direction: column; background: #fff; }
.preview-head { height: 32px; flex-shrink: 0; display: flex; align-items: center; gap: 6px; padding: 0 8px; background: var(--bg2); border-bottom: 1px solid var(--border); color: var(--muted); font-size: 12px; }
.preview-head span { font-weight: 600; }
.preview-head input { flex: 1; background: var(--bg); border: 1px solid var(--border); color: var(--txt); border-radius: 5px; padding: 3px 6px; font-family: var(--mono); font-size: 11.5px; }
#previewFrame { flex: 1; border: none; background: #fff; width: 100%; }

/* ===================== Chat ===================== */
#chat { width: 380px; flex-shrink: 0; background: var(--bg2); border-left: 1px solid var(--border); display: flex; flex-direction: column; min-width: 0; }
.chat-head { height: 40px; flex-shrink: 0; display: flex; align-items: center; gap: 6px; padding: 0 10px; border-bottom: 1px solid var(--border); }
.chat-title { font-weight: 600; font-size: 13px; }
#modelSelect { flex: 1; min-width: 0; background: var(--bg3); border: 1px solid var(--border); color: var(--txt); border-radius: 6px; padding: 4px 6px; font-size: 11.5px; }
.chat-head .ghost { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 15px; }
.chat-head .ghost:hover { color: var(--txt); }
.chat-messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.cmsg { display: flex; flex-direction: column; gap: 4px; }
.cmsg .who { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.cmsg .who .model { opacity: .7; }
.cmsg .bubble { line-height: 1.55; overflow-wrap: break-word; }
.cmsg.user .bubble { background: var(--user); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }
.cmsg .bubble p { margin: 0 0 8px; }
.cmsg .bubble p:last-child { margin: 0; }
.cmsg .bubble ul, .cmsg .bubble ol { margin: 0 0 8px; padding-left: 20px; }
.cmsg .bubble h1, .cmsg .bubble h2, .cmsg .bubble h3 { margin: 10px 0 6px; line-height: 1.3; }
.cmsg .bubble a { color: var(--accent); }
.cmsg .bubble :not(pre) > code { background: var(--bg4); padding: 1px 5px; border-radius: 4px; font-family: var(--mono); font-size: .88em; }
.codeblock { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin: 0 0 8px; }
.codeblock .cb-head { display: flex; align-items: center; gap: 6px; background: var(--bg3); padding: 4px 8px; font-size: 11px; color: var(--muted); }
.codeblock .cb-lang { flex: 1; font-family: var(--mono); }
.codeblock .cb-act { background: var(--bg4); border: 1px solid var(--border); color: var(--txt); border-radius: 5px; padding: 2px 7px; cursor: pointer; font-size: 11px; }
.codeblock .cb-act:hover { border-color: var(--accent); }
.codeblock pre { margin: 0; padding: 10px; overflow-x: auto; background: var(--bg); }
.codeblock code { font-family: var(--mono); font-size: 12px; }
.cursor { display: inline-block; width: 7px; height: 14px; background: var(--txt); vertical-align: text-bottom; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.chat-status { padding: 0 12px; font-size: 11.5px; color: var(--warn); }
.chat-status:empty { display: none; }

.composer { flex-shrink: 0; border-top: 1px solid var(--border); padding: 8px; display: flex; align-items: flex-end; gap: 6px; }
.ctx-toggle { display: flex; align-items: center; gap: 3px; font-size: 11px; color: var(--muted); white-space: nowrap; align-self: center; }
#chatInput { flex: 1; resize: none; background: var(--bg3); border: 1px solid var(--border); color: var(--txt); border-radius: 8px; padding: 8px; font-family: var(--sans); font-size: 13px; max-height: 160px; }
#chatInput:focus { outline: none; border-color: var(--accent); }
#chatSend { background: var(--accent); border: none; color: #fff; width: 34px; height: 34px; border-radius: 8px; cursor: pointer; font-size: 15px; flex-shrink: 0; }
#chatSend:hover { background: var(--accent2); }
#chatSend:disabled { opacity: .5; cursor: default; }

.chat-welcome { color: var(--muted); text-align: center; margin: auto; padding: 20px; line-height: 1.6; }
.chat-welcome b { color: var(--txt); }

/* ===================== Modals ===================== */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal { background: var(--bg2); border: 1px solid var(--border); border-radius: 14px; width: 100%; max-width: 560px; max-height: 88vh; overflow: hidden; display: flex; flex-direction: column; box-shadow: 0 18px 50px rgba(0,0,0,.5); }
.modal.wide { max-width: 780px; }
.modal-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 15px; flex: 1; }
.modal-head .x { background: none; border: none; color: var(--muted); font-size: 20px; cursor: pointer; }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.modal .sub { color: var(--muted); font-size: 12.5px; margin: 0 0 14px; line-height: 1.6; }
label.field { display: block; margin-bottom: 12px; font-size: 12.5px; }
label.field span { display: block; color: var(--muted); margin-bottom: 4px; }
.inp, select.inp { width: 100%; background: var(--bg); border: 1px solid var(--border); color: var(--txt); border-radius: 8px; padding: 9px 10px; font-family: var(--sans); font-size: 13px; }
.inp:focus { outline: none; border-color: var(--accent); }
.inp.mono { font-family: var(--mono); font-size: 12px; }
.btn { background: var(--bg3); border: 1px solid var(--border); color: var(--txt); border-radius: 8px; padding: 9px 16px; cursor: pointer; font-size: 13px; }
.btn:hover { background: var(--bg4); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent2); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }

/* Skills / templates cards */
.tpl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tpl-card { border: 1px solid var(--border); border-radius: 10px; padding: 12px; cursor: pointer; background: var(--bg); }
.tpl-card:hover { border-color: var(--accent); }
.tpl-card.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.tpl-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tpl-card .tpl-ico { font-size: 22px; line-height: 0; display: flex; align-items: center; gap: 6px; }
.tpl-card .tpl-ico svg { width: 26px; height: 26px; display: block; flex: none; }
.tpl-tag { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  padding: 2px 7px; border-radius: 999px; border: 1px solid transparent; white-space: nowrap; }
.tpl-tag.frontend { color: #3b82f6; background: rgba(59, 130, 246, .12); border-color: rgba(59, 130, 246, .3); }
.tpl-tag.backend { color: #10b981; background: rgba(16, 185, 129, .12); border-color: rgba(16, 185, 129, .3); }
.tpl-tag.fullstack { color: #8b5cf6; background: rgba(139, 92, 246, .12); border-color: rgba(139, 92, 246, .3); }
.tpl-tag.starter { color: #94a3b8; background: rgba(148, 163, 184, .12); border-color: rgba(148, 163, 184, .3); }
.tpl-card .tpl-name { font-weight: 600; margin: 4px 0 2px; }
.tpl-card .tpl-desc { color: var(--muted); font-size: 12px; line-height: 1.5; }
.skill-row { display: flex; align-items: flex-start; gap: 9px; padding: 8px 4px; border-bottom: 1px solid var(--border); }
.skill-row:last-child { border-bottom: none; }
.skill-row input { margin-top: 3px; }
.skill-row .s-name { font-weight: 600; }
.skill-row .s-desc { color: var(--muted); font-size: 12px; line-height: 1.5; }
.section-title { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 600; margin: 4px 0 8px; }

/* Provider settings rows */
.prov-row { display: flex; align-items: center; gap: 8px; padding: 8px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; }
.prov-row .p-name { flex: 1; font-weight: 600; }
.prov-row .p-badge { font-size: 10.5px; padding: 2px 6px; border-radius: 20px; background: var(--bg3); color: var(--muted); }
.prov-row .p-badge.on { background: #3fb95022; color: var(--ok); }
.prov-row input.k { width: 150px; }

/* Sidepanel content (skills/github) */
.sp-block { margin-bottom: 14px; }
.sp-block h4 { margin: 0 0 6px; font-size: 12.5px; }
.gh-status { font-size: 12px; color: var(--muted); margin-bottom: 8px; line-height: 1.6; }
.gh-status b { color: var(--txt); }
.repo-item { padding: 7px 8px; border: 1px solid var(--border); border-radius: 7px; margin-bottom: 5px; cursor: pointer; font-size: 12.5px; }
.repo-item:hover { border-color: var(--accent); }
.repo-item.sel { border-color: var(--accent); background: var(--bg3); }
.repo-item .r-priv { font-size: 10px; color: var(--muted); }
.step { display: flex; gap: 8px; margin-bottom: 8px; font-size: 12.5px; line-height: 1.5; }
.step .n { flex-shrink: 0; width: 20px; height: 20px; border-radius: 50%; background: var(--bg3); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; }
.log-line { font-family: var(--mono); font-size: 11.5px; padding: 1px 0; color: var(--muted); }
.log-line.ok { color: var(--ok); }
.log-line.err { color: var(--danger); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--bg3); border: 1px solid var(--border); color: var(--txt); padding: 10px 16px; border-radius: 10px; z-index: 200; box-shadow: 0 8px 30px rgba(0,0,0,.4); font-size: 13px; }
.toast.err { border-color: var(--danger); }
.toast.ok { border-color: var(--ok); }
