/* ==========================================================================
   AI AGI Namecheap Builder — design system
   One shell, one journey. Tokens → primitives → shell → components → views.
   CSP-safe: no external assets, inline style/script permitted by policy.
   ========================================================================== */

:root {
  color-scheme: dark;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* surfaces */
  --bg: #0b1220;
  --bg-grad: radial-gradient(1200px 600px at 80% -10%, #1e293b 0%, transparent 55%), linear-gradient(160deg, #0b1220 0%, #0f172a 60%, #111a34 100%);
  --surface: rgba(17, 25, 44, .82);
  --surface-2: rgba(2, 6, 23, .55);
  --border: rgba(148, 163, 184, .18);
  --border-strong: rgba(148, 163, 184, .34);

  /* text */
  --text: #e6edf7;
  --text-dim: #9fb0c9;
  --text-faint: #6b7c98;

  /* brand + intent */
  --brand: #6366f1;
  --brand-2: #8b5cf6;
  --accent: #38bdf8;
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;

  --radius: 16px;
  --radius-sm: 10px;
  --radius-lg: 22px;
  --gap: 18px;
  --shadow: 0 20px 60px rgba(2, 6, 23, .45);
  --ring: 0 0 0 3px rgba(99, 102, 241, .35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.15; letter-spacing: -.02em; }
p { margin: 0; color: var(--text-dim); line-height: 1.6; }
small { color: var(--text-faint); }
hr { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }

/* ---------- App shell ---------------------------------------------------- */
.appbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 20px;
  padding: 12px clamp(16px, 4vw, 40px);
  background: rgba(11, 18, 32, .72);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -.02em; white-space: nowrap; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: 0 6px 18px rgba(99, 102, 241, .5);
  display: grid; place-items: center; font-size: 15px;
}
.brand small { display: block; font-weight: 500; color: var(--text-faint); letter-spacing: 0; }

/* stepper navigation = the journey */
.stepper { display: flex; align-items: center; gap: 4px; margin: 0 auto; flex-wrap: wrap; }
.step {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 999px; cursor: pointer;
  color: var(--text-dim); font-weight: 650; font-size: 14px;
  border: 1px solid transparent; background: transparent;
  transition: background .15s, color .15s, border-color .15s;
}
.step .num {
  width: 20px; height: 20px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-size: 12px; font-weight: 800;
  background: rgba(148, 163, 184, .16); color: var(--text-dim);
}
.step:hover { color: var(--text); background: rgba(148, 163, 184, .08); }
.step.active { color: #fff; background: rgba(99, 102, 241, .16); border-color: rgba(99, 102, 241, .5); }
.step.active .num { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; }
.step.disabled { opacity: .4; pointer-events: none; }
.step.util { margin-left: 8px; border-left: 1px solid var(--border); border-radius: 0 999px 999px 0; padding-left: 16px; }

/* session widget */
.session { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-faint); box-shadow: 0 0 0 3px rgba(148,163,184,.12); }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(52, 211, 153, .18); }
.dot.off { background: var(--danger); box-shadow: 0 0 0 3px rgba(248, 113, 113, .18); }
.session .who { font-size: 13px; color: var(--text-dim); max-width: 200px; overflow: hidden; text-overflow: ellipsis; }

/* context bar — the shared working repo, always visible */
.contextbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px clamp(16px, 4vw, 40px);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.contextbar .ctx-label { color: var(--text-faint); }
.contextbar .ctx-repo { font-weight: 700; color: var(--text); }
.contextbar code { font-family: var(--mono); font-size: 13px; color: var(--accent); }

/* ---------- Layout ------------------------------------------------------- */
.wrap { width: min(1200px, calc(100vw - 32px)); margin: 0 auto; padding: 28px 0 96px; }
.view { display: block; }
.view[hidden] { display: none; }

.view-head { margin-bottom: 22px; }
.view-head .eyebrow { display: inline-flex; align-items: center; gap: 8px; color: var(--brand-2); font-weight: 800; font-size: 12px; letter-spacing: .12em; text-transform: uppercase; }
.view-head h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); margin: 8px 0 10px; }
.view-head p { max-width: 68ch; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--gap); }
.grid.one { grid-template-columns: 1fr; }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-2 { grid-column: 1 / -1; }

/* ---------- Card --------------------------------------------------------- */
.card {
  border: 1px solid var(--border);
  background: var(--surface);
  backdrop-filter: blur(12px);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow);
}
.card > h2 { font-size: 1.15rem; margin-bottom: 6px; display: flex; align-items: center; gap: 10px; }
.card > .hint { font-size: 13px; color: var(--text-faint); margin-bottom: 14px; }
.card .stepno {
  width: 22px; height: 22px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-size: 12px; font-weight: 800; background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff;
}

/* ---------- Forms -------------------------------------------------------- */
form { display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-weight: 650; font-size: 14px; color: #dbe4f3; }
input, textarea, select {
  width: 100%; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 11px 13px; background: rgba(2, 6, 23, .6); color: var(--text); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input:focus, textarea:focus, select:focus { border-color: var(--brand); box-shadow: var(--ring); }
textarea { min-height: 110px; resize: vertical; font-family: inherit; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .row { grid-template-columns: 1fr; } }

/* ---------- Buttons ------------------------------------------------------ */
button {
  border: 0; border-radius: var(--radius-sm); padding: 11px 16px; cursor: pointer;
  color: #fff; font-weight: 750; letter-spacing: .01em;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: 0 8px 22px rgba(99, 102, 241, .3);
  transition: transform .08s, filter .15s, box-shadow .15s;
}
button:hover { filter: brightness(1.07); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; filter: grayscale(.3); }
button.secondary { background: rgba(148, 163, 184, .14); border: 1px solid var(--border-strong); box-shadow: none; color: var(--text); }
button.ghost { background: transparent; border: 1px solid var(--border-strong); box-shadow: none; color: var(--text-dim); }
button.danger { background: linear-gradient(135deg, #ef4444, #b91c1c); box-shadow: 0 8px 22px rgba(239, 68, 68, .28); }
button.sm { padding: 7px 11px; font-size: 13px; border-radius: 8px; }
.btnrow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ---------- Pills / badges ---------------------------------------------- */
.badges { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.badge { border: 1px solid rgba(99, 102, 241, .4); background: rgba(99, 102, 241, .14); color: #c7d2fe; padding: 6px 11px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.status-pill { padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.status-succeeded { background: rgba(52, 211, 153, .18); color: #6ee7b7; }
.status-failed, .status-rolled_back { background: rgba(248, 113, 113, .18); color: #fca5a5; }
.status-running, .status-dispatched { background: rgba(56, 189, 248, .18); color: #7dd3fc; }
.status-queued { background: rgba(148, 163, 184, .2); color: #cbd5e1; }
.status-cancelled { background: rgba(251, 191, 36, .18); color: #fcd34d; }
.persona-pill { padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; background: rgba(99,102,241,.18); color: #c7d2fe; }

/* ---------- Key/value status list --------------------------------------- */
.kv { display: grid; gap: 0; }
.kv div { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.kv div:last-child { border-bottom: 0; }
.kv span { color: var(--text-faint); }
.kv strong { font-weight: 700; }

/* ---------- List rows (targets, runs, sessions) ------------------------- */
.rowitem { padding: 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); margin-bottom: 10px; }
.rowitem:last-child { margin-bottom: 0; }
.runrow { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin-bottom: 8px; }
.sessionrow { display: flex; justify-content: space-between; gap: 8px; align-items: center; cursor: pointer; padding: 11px; border-radius: var(--radius-sm); border: 1px solid var(--border); margin-bottom: 8px; transition: border-color .15s, background .15s; }
.sessionrow:hover { background: rgba(148, 163, 184, .08); }
.sessionrow.active { background: rgba(99, 102, 241, .16); border-color: rgba(99, 102, 241, .5); }

/* ---------- Empty states ------------------------------------------------- */
.empty { text-align: center; padding: 28px 16px; color: var(--text-faint); border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); }
.empty .icn { font-size: 26px; opacity: .6; display: block; margin-bottom: 6px; }

/* ---------- Gate (signed-out overlay per view) -------------------------- */
.gate { display: grid; place-items: center; padding: 40px 16px; text-align: center; gap: 10px; color: var(--text-dim); }
.gate .icn { font-size: 34px; }

/* ---------- Chat (assistant) -------------------------------------------- */
.chat { display: flex; flex-direction: column; gap: 10px; max-height: 460px; overflow: auto; padding: 12px; background: var(--surface-2); border-radius: var(--radius-sm); border: 1px solid var(--border); }
.msg { padding: 9px 13px; border-radius: 12px; max-width: 86%; white-space: pre-wrap; word-break: break-word; font-size: 14px; line-height: 1.45; }
.msg-user { align-self: flex-end; background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; }
.msg-assistant { align-self: flex-start; background: rgba(30, 41, 59, .9); color: #e2e8f0; border: 1px solid var(--border); }
.msg-meta { font-size: 11px; opacity: .6; margin-top: 4px; }

/* ---------- Analysis report --------------------------------------------- */
.report h3 { margin: 16px 0 6px; font-size: 15px; color: var(--accent); }
.report ul { margin: 0; padding-left: 20px; color: var(--text-dim); }
.report li { margin: 3px 0; }

/* ---------- Live log ----------------------------------------------------- */
.logview { background: #05070f; color: #9fe6ff; font-family: var(--mono); font-size: 12.5px; max-height: 300px; overflow: auto; padding: 12px; border-radius: var(--radius-sm); white-space: pre-wrap; word-break: break-word; border: 1px solid var(--border); }

/* ---------- Console drawer (global activity/output) --------------------- */
.consolebtn {
  position: fixed; right: 18px; bottom: 18px; z-index: 40;
  padding: 10px 15px; border-radius: 999px; box-shadow: var(--shadow);
  display: inline-flex; align-items: center; gap: 8px;
}
.drawer {
  position: fixed; right: 0; bottom: 0; z-index: 41;
  width: min(560px, 100vw); max-height: 60vh;
  background: rgba(11, 18, 32, .96); backdrop-filter: blur(16px);
  border: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: var(--shadow); display: flex; flex-direction: column;
  transform: translateY(105%); transition: transform .22s ease;
}
.drawer.open { transform: translateY(0); }
.drawer header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.drawer header h3 { font-size: 14px; }
.output { margin: 0; overflow: auto; padding: 14px 16px; white-space: pre-wrap; word-break: break-word; font-family: var(--mono); font-size: 12.5px; color: #bfe3ff; flex: 1; }

/* ---------- Responsive --------------------------------------------------- */
@media (max-width: 900px) {
  .grid, .grid.three { grid-template-columns: 1fr; }
  .stepper { order: 3; width: 100%; justify-content: flex-start; overflow-x: auto; }
  .appbar { flex-wrap: wrap; }
}

.updatebox { margin-top: 8px; padding: 10px 12px; border: 1px dashed var(--line, #c9d3e0); border-radius: 8px; }
.updatebox ul { margin: 6px 0 0 18px; }
.dnsbanner { margin: 8px 0 12px; padding: 10px 12px; border-left: 4px solid #d9822b; background: rgba(217, 130, 43, 0.08); border-radius: 6px; }
.dnsbanner p { margin: 4px 0 0; }
