:root {
  --bg: #14111c;
  --bg-2: #1c1828;
  --card: #221d31;
  --border: #342b48;
  --text: #e8e4f0;
  --muted: #9a93ad;
  --primary: #c9a850;
  --primary-d: #a98a36;
  --danger: #e0574e;
  --ok: #4caf7d;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.login-card h1 { margin: 0; font-size: 1.6rem; text-align: center; }
.login-card h1 span { color: var(--primary); }
.login-sub { margin: 0 0 0.5rem; text-align: center; color: var(--muted); font-size: 0.9rem; }
.login-card label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.85rem; color: var(--muted); }
.login-card input {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  color: var(--text);
  font-size: 1rem;
}
.login-card input:focus { outline: none; border-color: var(--primary); }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  font-size: 0.9rem;
  cursor: pointer;
  transition: filter 0.15s;
}
.btn:hover { filter: brightness(1.15); }
.btn-sm { padding: 0.4rem 0.7rem; font-size: 0.82rem; }
.btn-primary { background: var(--primary); border-color: var(--primary-d); color: #1b1408; font-weight: 600; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
.btn-ghost { background: transparent; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.25rem;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 1.15rem; }
.brand span { color: var(--primary); }
.topbar-right { display: flex; align-items: center; gap: 1rem; }
.env-select { display: flex; align-items: center; gap: 0.5rem; font-size: 0.82rem; color: var(--muted); }
.env-select select {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
}

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 0.25rem; padding: 0.6rem 1.25rem 0; background: var(--bg-2); }
.tab {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 0.6rem 1rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  font-size: 0.92rem;
}
.tab.is-active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- Content ---------- */
.content { padding: 1.5rem 1.25rem; max-width: 1100px; margin: 0 auto; }
.panel { display: none; }
.panel.is-active { display: block; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; gap: 1rem; flex-wrap: wrap; }
.panel-head h2 { margin: 0; font-size: 1.2rem; }
.panel-actions { display: flex; align-items: center; gap: 0.6rem; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg-btn { background: var(--bg-2); border: none; color: var(--muted); padding: 0.4rem 0.8rem; cursor: pointer; font-size: 0.82rem; }
.seg-btn.is-active { background: var(--primary); color: #1b1408; }

.status-bar { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.8rem; }
.proc-chip { background: var(--card); border: 1px solid var(--border); border-radius: 20px; padding: 0.25rem 0.7rem; font-size: 0.78rem; }
.proc-chip.online { border-color: var(--ok); }
.proc-chip.stopped, .proc-chip.errored { border-color: var(--danger); color: var(--danger); }

.log-output {
  background: #0d0b13;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 60vh;
  overflow: auto;
  margin: 0;
}
.log-line-err { color: var(--danger); }

.updates-output { display: flex; flex-direction: column; gap: 1rem; }
.update-card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 1rem; }
.update-card h3 { margin: 0 0 0.5rem; font-size: 1rem; }
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; flex-wrap: wrap; }
.badge { display: inline-block; padding: 0.2rem 0.6rem; border-radius: 20px; font-size: 0.78rem; font-weight: 600; }
.badge.behind { background: var(--danger); color: #fff; }
.badge.uptodate { background: var(--ok); color: #06281a; }
.dep-list { margin: 0.5rem 0 0; padding: 0; list-style: none; font-family: var(--mono); font-size: 0.8rem; }
.dep-list li { padding: 0.2rem 0; border-bottom: 1px solid var(--border); }
.dep-list li:last-child { border-bottom: none; }

.bk-table { width: 100%; border-collapse: collapse; margin-top: 0.5rem; }
.bk-table th, .bk-table td { text-align: left; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--border); font-size: 0.85rem; }
.bk-table th { color: var(--muted); font-weight: 500; }
.bk-table td.file { font-family: var(--mono); font-size: 0.8rem; }

.warn-box { background: rgba(224, 87, 78, 0.12); border: 1px solid var(--danger); border-radius: 10px; padding: 0.9rem 1rem; font-size: 0.88rem; margin-bottom: 1rem; }

/* ---------- Info / guide box ---------- */
.info-box {
  background: rgba(201, 168, 80, 0.08);
  border: 1px solid var(--primary-d);
  border-radius: 10px;
  padding: 0.5rem 1rem;
  font-size: 0.88rem;
  margin-bottom: 1rem;
}
.info-box > summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--primary);
  padding: 0.4rem 0;
  list-style-position: inside;
}
.info-box > summary:hover { filter: brightness(1.15); }
.info-box[open] > summary { margin-bottom: 0.5rem; border-bottom: 1px solid var(--border); padding-bottom: 0.6rem; }
.info-note { margin: 0.6rem 0; color: var(--text); line-height: 1.55; }
.info-note code { font-family: var(--mono); font-size: 0.82rem; background: var(--bg-2); padding: 0.1rem 0.35rem; border-radius: 4px; }
.info-steps { margin: 0.6rem 0; padding-left: 1.2rem; line-height: 1.6; display: flex; flex-direction: column; gap: 0.35rem; }
.cmd-block {
  background: #0d0b13;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 0.85rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0.3rem 0 0.9rem;
  overflow: auto;
}
.rebuild-row { display: flex; align-items: center; gap: 0.8rem; margin-top: 1.2rem; flex-wrap: wrap; }
.rebuild-hint { color: var(--muted); font-size: 0.8rem; }

.msg { border-radius: 8px; padding: 0.6rem 0.8rem; font-size: 0.85rem; margin: 0.6rem 0; white-space: pre-line; }
.msg-error { background: rgba(224, 87, 78, 0.15); border: 1px solid var(--danger); color: #ffb4ae; }
.msg-ok { background: rgba(76, 175, 125, 0.15); border: 1px solid var(--ok); color: #a6e8c6; }

/* ---------- Claude assistant ---------- */
.ai-status { font-size: 0.82rem; color: var(--muted); margin-bottom: 0.6rem; }
.ai-status .ok { color: var(--ok); }
.ai-status .bad { color: var(--danger); }
.ai-transcript {
  background: #0d0b13;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  min-height: 240px;
  max-height: 55vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.ai-empty { color: var(--muted); font-size: 0.88rem; text-align: center; margin: auto; }
.ai-msg { border-radius: 10px; padding: 0.6rem 0.8rem; font-size: 0.88rem; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.ai-msg.user { background: var(--bg-2); border: 1px solid var(--border); align-self: flex-end; max-width: 85%; }
.ai-msg.assistant { background: rgba(201, 168, 80, 0.08); border: 1px solid var(--primary-d); align-self: flex-start; max-width: 95%; }
.ai-tool { font-family: var(--mono); font-size: 0.76rem; color: var(--muted); align-self: flex-start; padding: 0.2rem 0.5rem; border-left: 2px solid var(--primary-d); }
.ai-result { font-size: 0.78rem; color: var(--muted); align-self: center; font-style: italic; }
.ai-form { display: flex; gap: 0.6rem; margin-top: 0.8rem; align-items: flex-end; }
.ai-form textarea {
  flex: 1;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  color: var(--text);
  font-size: 0.92rem;
  font-family: inherit;
  resize: vertical;
}
.ai-form textarea:focus { outline: none; border-color: var(--primary); }

/* ---------- Terminal ---------- */
.term-cwd { font-family: var(--mono); font-size: 0.78rem; color: var(--muted); }
.term-unlock { display: flex; gap: 0.6rem; align-items: center; max-width: 380px; }
.term-unlock input {
  flex: 1;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  color: var(--text);
  font-size: 1rem;
  letter-spacing: 0.1em;
}
.term-unlock input:focus { outline: none; border-color: var(--primary); }

.term-console { display: flex; flex-direction: column; gap: 0.6rem; }
.term-output {
  background: #0d0b13;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.5;
  white-space: pre;
  overflow: auto;
  margin: 0;
  height: 360px;
  min-height: 160px;
  resize: vertical; /* drag the bottom edge to resize */
}
.term-cmd { color: var(--primary); font-weight: 600; }
.term-err { color: var(--danger); }
.term-form { display: flex; gap: 0.5rem; align-items: center; }
.term-prompt { font-family: var(--mono); color: var(--primary); font-weight: 700; }
.term-input {
  flex: 1;
  background: #0d0b13;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.85rem;
}
.term-input:focus { outline: none; border-color: var(--primary); }

@media (max-width: 560px) {
  .topbar { flex-direction: column; gap: 0.7rem; align-items: flex-start; }
  .content { padding: 1rem; }
}
