:root {
  --bg: #101418;
  --bg-raise: #171d23;
  --bg-panel: #1d242c;
  --line: #2a333d;
  --text: #e8eef3;
  --text-dim: #93a1ad;
  --accent: #35c28f;
  --accent-dim: #23795b;
  --warn: #e8b04b;
  --danger: #e06459;
  --mono: "Cascadia Code", "JetBrains Mono", Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 18px;
  background: var(--bg-raise);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-mark { color: var(--accent); font-size: 18px; }
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: 0.3px; }
.brand-tag { color: var(--text-dim); font-size: 12px; }

.meter { margin-left: auto; min-width: 220px; }
.meter-row { display: flex; align-items: baseline; gap: 6px; font-size: 12px; }
.meter-label { color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.6px; font-size: 10px; }
.meter-value { font-weight: 700; font-family: var(--mono); }
.meter-cap { color: var(--text-dim); }
.meter-bar { height: 4px; background: var(--line); border-radius: 2px; margin-top: 4px; overflow: hidden; }
.meter-fill { height: 100%; width: 0%; background: var(--accent); border-radius: 2px; transition: width 0.3s; }
.meter-fill.hot { background: var(--warn); }
.meter-fill.over { background: var(--danger); }
.meter-wasted { font-size: 11px; color: var(--text-dim); margin-top: 3px; }

/* ---------- layout ---------- */
.layout { flex: 1; display: flex; min-height: 0; }

.chat {
  width: 380px;
  min-width: 300px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--bg-raise);
}
.messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }

.msg { padding: 10px 12px; border-radius: 10px; font-size: 13.5px; line-height: 1.5; }
.msg.system { background: var(--bg-panel); color: var(--text-dim); border: 1px dashed var(--line); }
.msg.user { background: var(--accent-dim); color: #eafff6; align-self: flex-end; max-width: 90%; }
.msg.assistant { background: var(--bg-panel); border: 1px solid var(--line); }
.msg .hint { margin-top: 6px; font-size: 12px; }
.msg .cost-line { display: block; margin-top: 6px; font-size: 11px; color: var(--text-dim); font-family: var(--mono); }
.msg.failed { border-color: var(--danger); }
.msg.failed .cost-line { color: var(--danger); }
.msg.working { color: var(--text-dim); font-style: italic; }

.template-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.template-card {
  background: var(--bg-panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px; color: var(--text); display: flex; flex-direction: column; gap: 6px;
}
.template-card:hover { border-color: var(--accent); }
.template-card .t-main {
  background: none; border: none; padding: 0; margin: 0; text-align: left; cursor: pointer; color: inherit; font: inherit; width: 100%;
}
.template-card .t-icon { font-size: 18px; }
.template-card .t-name { font-size: 12.5px; font-weight: 700; margin-top: 3px; }
.template-card .t-desc { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.template-card .t-use-prompt {
  align-self: flex-start; background: none; border: none; padding: 0; margin: 0;
  font-size: 10.5px; color: var(--text-dim); cursor: pointer; text-decoration: underline; text-underline-offset: 2px;
}
.template-card .t-use-prompt:hover { color: var(--accent); }

.stuck-banner {
  margin: 0 14px 8px;
  padding: 8px 10px;
  font-size: 12px;
  border-radius: 8px;
  background: rgba(232, 176, 75, 0.12);
  border: 1px solid var(--warn);
  color: var(--warn);
}

.composer { padding: 12px 14px; border-top: 1px solid var(--line); }
.composer textarea {
  width: 100%;
  resize: vertical;
  background: var(--bg-panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  font-size: 13.5px;
  font-family: inherit;
}
.composer textarea:focus { outline: 1px solid var(--accent); }
.composer-row { display: flex; align-items: center; margin-top: 8px; gap: 10px; }
.estimate { font-size: 12px; color: var(--text-dim); font-family: var(--mono); flex: 1; }
.estimate.blocked { color: var(--danger); }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--bg-panel);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #06281c; font-weight: 700; }
.btn.primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.ghost { background: transparent; }
.btn.small { padding: 3px 9px; font-size: 11.5px; }

/* ---------- workspace ---------- */
.workspace { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.tabs { display: flex; gap: 2px; padding: 8px 12px 0; border-bottom: 1px solid var(--line); background: var(--bg-raise); }
.tab {
  background: none; border: none; color: var(--text-dim);
  padding: 8px 16px; font-size: 13px; cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.sec-badge {
  display: inline-block; min-width: 16px; padding: 0 4px; margin-left: 4px;
  border-radius: 8px; font-size: 10px; line-height: 16px; text-align: center;
}
.sec-badge.pass { background: var(--accent); color: #06281c; }
.sec-badge.fail { background: var(--danger); color: #fff; }

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

#panel-preview { background: #fff; }
#previewFrame { flex: 1; width: 100%; border: none; background: #fff; }

.empty { margin: auto; color: var(--text-dim); font-size: 14px; padding: 40px; text-align: center; }
#panel-preview .empty { color: #8a949c; }

.panel-toolbar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--bg-raise); }
.publish-url { font-size: 12px; font-family: var(--mono); color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.publish-url a { color: var(--accent); }
.code {
  flex: 1; overflow: auto; padding: 14px;
  font-family: var(--mono); font-size: 12px; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word;
  background: var(--bg-panel); color: #cfe3d8;
}

/* ---------- versions ---------- */
.versions-split { flex: 1; display: flex; min-height: 0; }
.version-list { list-style: none; width: 260px; overflow-y: auto; border-right: 1px solid var(--line); }
.version-item { padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 12.5px; }
.version-item:hover, .version-item.selected { background: var(--bg-panel); }
.version-item .v-title { font-weight: 600; margin-bottom: 3px; }
.version-item .v-meta { color: var(--text-dim); font-size: 11px; font-family: var(--mono); }
.version-item .v-actions { margin-top: 6px; }
.version-item.current .v-title::after { content: " • current"; color: var(--accent); font-weight: 400; }
.diff-view { flex: 1; overflow: auto; padding: 12px; font-family: var(--mono); font-size: 11.5px; line-height: 1.5; }
.diff-line { white-space: pre-wrap; word-break: break-word; padding: 0 6px; }
.diff-line.add { background: rgba(53, 194, 143, 0.13); color: #9fe8cd; }
.diff-line.del { background: rgba(224, 100, 89, 0.13); color: #f0a9a2; text-decoration: line-through; }
.diff-line.ctx { color: var(--text-dim); }
.diff-gap { color: var(--text-dim); text-align: center; padding: 2px; }
.diff-summary { padding: 6px; margin-bottom: 8px; color: var(--text-dim); font-family: "Segoe UI", system-ui, sans-serif; font-size: 12.5px; }

/* ---------- security ---------- */
#securityReport { flex: 1; padding: 18px; overflow: auto; }
.sec-verdict { font-size: 15px; font-weight: 700; margin-bottom: 14px; }
.sec-verdict.pass { color: var(--accent); }
.sec-verdict.fail { color: var(--danger); }
.sec-item { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; font-size: 13px; }
.sec-item.ok { border-left: 3px solid var(--accent); }
.sec-item.bad { border-left: 3px solid var(--danger); }
.sec-item.warn { border-left: 3px solid var(--warn); }
.sec-item .sec-advice { color: var(--text-dim); font-size: 12px; margin-top: 4px; }

/* ---------- build health ---------- */
#panel-health { flex: 1; display: none; min-height: 0; overflow: auto; }
#panel-health.active { display: flex; flex-direction: column; }
#healthReport { flex: 1; padding: 18px; overflow: auto; }
.health-overall { font-size: 16px; font-weight: 700; margin-bottom: 16px; }
.health-overall.good { color: var(--accent); }
.health-overall.warn { color: var(--warn); }
.health-overall.bad { color: var(--danger); }
.health-row { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; }
.health-row .h-icon { font-size: 16px; line-height: 1.4; }
.health-row .h-body { flex: 1; }
.health-row .h-title { font-weight: 600; font-size: 13.5px; }
.health-row .h-detail { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.health-row .h-action { font-size: 11.5px; margin-top: 6px; }
.health-note { font-size: 11.5px; color: var(--text-dim); margin-top: 14px; padding: 10px 12px; border: 1px dashed var(--line); border-radius: 8px; }

/* ---------- launch check ---------- */
#panel-launchcheck { flex: 1; display: none; min-height: 0; overflow: auto; }
#panel-launchcheck.active { display: flex; flex-direction: column; }
.lc-status { font-size: 12px; color: var(--text-dim); }
#launchCheckReport { flex: 1; padding: 18px; overflow: auto; }
.lc-shots { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 16px; }
.lc-shot { flex: 1; min-width: 220px; max-width: 360px; }
.lc-shot .lc-shot-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }
.lc-shot img { width: 100%; border-radius: 8px; border: 1px solid var(--line); display: block; }

/* ---------- settings modal ---------- */
dialog {
  margin: auto; border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg-raise); color: var(--text); min-width: 420px; padding: 0;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.settings { padding: 22px; display: flex; flex-direction: column; gap: 16px; }
.settings h2 { font-size: 16px; }
.settings label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; }
.settings input {
  background: var(--bg-panel); border: 1px solid var(--line); border-radius: 8px;
  color: var(--text); padding: 9px 10px; font-size: 13px; font-family: var(--mono);
}
.settings .hint { color: var(--text-dim); font-size: 11.5px; font-weight: 400; }
.settings-actions { display: flex; gap: 10px; justify-content: flex-end; }
.managed-box { background: var(--bg-panel); border: 1px solid var(--accent-dim); border-radius: 10px; padding: 14px; }
.managed-box .btn { font-size: 12.5px; padding: 6px 12px; }
