/* Aquila manager UI - mobile-first, night-sky, no frameworks. */

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.sky {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: var(--sky);
  background-color: var(--bg);
}

::selection { background: var(--accent-soft); color: var(--text); }

.skip-link {
  position: absolute;
  top: -48px;
  left: var(--space-4);
  z-index: 50;
  padding: 10px 16px;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: var(--btn-ink);
  font-weight: 700;
  font-size: 0.85rem;
}
.skip-link:focus { top: var(--space-2); text-decoration: none; }

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ── Type scale ─────────────────────────────────────────────────────────── */

h1, h2, h3 {
  font-family: var(--font-display);
  line-height: 1.12;
  letter-spacing: -0.02em;
  margin: 0 0 var(--space-2);
  text-wrap: balance;
}
h1 { font-size: clamp(1.75rem, 1.35rem + 2.2vw, 2.7rem); letter-spacing: -0.03em; }
h2 { font-size: clamp(1.12rem, 1.02rem + 0.5vw, 1.32rem); }
h3 { font-size: 1.05rem; }
p { margin: 0 0 var(--space-3); }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); font-size: 0.84rem; }
.hidden { display: none !important; }
.mono { font-family: var(--font-mono); font-size: 0.82rem; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.eyebrow {
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: 0.7rem;
  font-weight: 700;
  margin-bottom: var(--space-2);
}
.hero { padding: var(--space-5) 0 var(--space-4); }
.hero h1 { max-width: 22ch; }
.hero .muted { max-width: 58ch; }

/* ── Chrome ─────────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--line);
  background: var(--overlay);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  color: var(--text);
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: 0.18em;
  font-size: 0.8rem;
}
.brand:hover { text-decoration: none; }
.brand-mark { color: var(--accent); font-size: 0.9rem; line-height: 1; }
.topnav { display: flex; align-items: center; gap: var(--space-2); font-size: 0.9rem; }
.topnav a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 var(--space-2); }

.shell {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4) var(--space-7);
  flex: 1;
}

.footer {
  border-top: 1px solid var(--line);
  padding: var(--space-5) var(--space-4);
  text-align: center;
  color: var(--text-faint);
  font-size: 0.82rem;
}
.footer p { margin: 0; }

/* ── Cards & sections ───────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: clamp(18px, 4vw, 28px);
  margin-bottom: var(--space-4);
}
.card > :last-child { margin-bottom: 0; }
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}
.card-head h2, .card-head h3, .card-head p { margin: 0; }

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin: var(--space-6) 0 var(--space-3);
}
.section-head h1, .section-head h2 { margin-bottom: 0; }
.section-head .faint { margin: 0; }

.grid {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
}

.steps {
  list-style: none;
  counter-reset: step;
  margin: 0 0 var(--space-4);
  padding: 0;
  display: grid;
  gap: var(--space-3);
}
.steps li {
  counter-increment: step;
  position: relative;
  padding-left: 38px;
  color: var(--text-muted);
  font-size: 0.94rem;
  line-height: 1.5;
}
.steps li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 1px;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-full);
  border: 1px solid var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-size: 0.76rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* ── Buttons ────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: var(--btn-ink, #0b1226);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.92rem;
  padding: 10px 20px;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
    transform var(--dur-fast) var(--ease);
}
.btn:hover { background: var(--accent-strong); text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(0.99); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--line);
}
.btn-ghost:hover { background: var(--surface-2); border-color: var(--line-strong); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger-line); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-small { padding: 6px 14px; font-size: 0.82rem; }

/* ── Forms ──────────────────────────────────────────────────────────────── */

.field { display: block; margin-bottom: var(--space-3); }
.field span {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text-muted);
  margin-bottom: 6px;
}
input, select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  min-height: 46px;
  padding: 10px 12px;
}
input::placeholder { color: var(--text-faint); }
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}
.otp-form { display: flex; gap: var(--space-2); align-items: flex-end; flex-wrap: wrap; }
.otp-form .field { flex: 1 1 160px; margin-bottom: 0; }
.otp-form .btn { flex: 1 1 140px; }

.form-error { color: var(--danger); font-size: 0.88rem; margin-top: var(--space-3); }
.helper { color: var(--text-faint); font-size: 0.82rem; margin: var(--space-2) 0 0; }

/* ── Badges ─────────────────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: var(--radius-full);
  padding: 4px 11px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text-muted);
  white-space: nowrap;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-running { color: var(--success); border-color: var(--success-line); background: var(--success-soft); }
.badge-stopped { color: var(--text-faint); }
.badge-error { color: var(--danger); border-color: var(--danger-line); background: var(--danger-soft); }
.badge-provisioning, .badge-created { color: var(--warning); border-color: var(--warning-line); }

/* ── Bots ───────────────────────────────────────────────────────────────── */

.bot-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  transition: border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.bot-card:hover { border-color: var(--line-strong); transform: translateY(-2px); }
.bot-card header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-2);
}
.bot-card h3 { margin: 0 0 3px; font-size: 1.12rem; }
.persona-key {
  color: var(--text-faint);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}
.bot-card .muted { font-size: 0.92rem; margin-bottom: 0; }
.bot-cost {
  font-size: 0.84rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  margin-bottom: 0;
}
.cost-bar {
  display: block;
  height: 4px;
  border-radius: var(--radius-full);
  background: var(--surface-3);
  overflow: hidden;
  margin-top: var(--space-2);
}
.cost-bar i {
  display: block;
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--accent);
  transition: width var(--dur) var(--ease);
}
.cost-bar i.is-over { background: var(--danger); }
.bot-error {
  color: var(--danger);
  font-size: 0.85rem;
  background: var(--danger-soft);
  border: 1px solid var(--danger-line);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  margin-bottom: 0;
}
.bot-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: auto;
  padding-top: var(--space-3);
  border-top: 1px solid var(--line);
}

/* ── Spend strip ────────────────────────────────────────────────────────── */

.spend-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4) var(--space-5);
}
.spend-strip .cell { min-width: 0; }
.spend-strip .cell:first-child { grid-column: 1 / -1; }
.stat-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 4px;
}
.spend-total {
  font-size: clamp(1.5rem, 4.5vw, 1.9rem);
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  margin: 0;
  line-height: 1.1;
}
.spend-strip .cell:first-child .spend-total { color: var(--accent); }

/* ── Empty state ────────────────────────────────────────────────────────── */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-2);
  padding: var(--space-6) var(--space-4);
}
.empty-state h3 { margin: 0; font-size: 1.15rem; }
.empty-state p { margin: 0; max-width: 42ch; font-size: 0.92rem; }
.empty-mark {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-full);
  border: 1px solid var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-size: 1.25rem;
  margin-bottom: var(--space-2);
}
.empty-state .btn { margin-top: var(--space-3); }

/* ── Chat ───────────────────────────────────────────────────────────────── */

.chat-log {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  min-height: 160px;
  max-height: 340px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-3);
  margin-bottom: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.chat-msg {
  max-width: 88%;
  padding: 9px 13px;
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  line-height: 1.5;
  white-space: pre-wrap;
}
.chat-msg.user {
  align-self: flex-end;
  background: var(--accent-2-soft);
  border: 1px solid var(--accent-2-line);
  border-bottom-right-radius: var(--radius-sm);
}
.chat-msg.assistant {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-bottom-left-radius: var(--radius-sm);
}
.chat-msg.error {
  align-self: flex-start;
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid var(--danger-line);
}
.chat-form { display: flex; gap: var(--space-2); align-items: stretch; }
.chat-form input { flex: 1; }

/* ── Tables ─────────────────────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th {
  color: var(--text-faint);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  padding-top: 0;
}
th.num, td.num { text-align: right; }
tbody tr { transition: background var(--dur-fast) var(--ease); }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
.table-empty { color: var(--text-faint); padding: var(--space-2) 0; margin: 0; }

/* ── Persona cards / link list ──────────────────────────────────────────── */

.persona-card h3 { margin-bottom: 4px; }
.persona-card .muted { margin-bottom: 0; font-size: 0.92rem; }

.link-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); }
.link-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
}
.link-list li:last-child { border-bottom: 0; }
.link-list .mono { color: var(--text-faint); }

/* ── Toast ──────────────────────────────────────────────────────────────── */

.toast-stack {
  position: fixed;
  bottom: var(--space-4);
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: min(92vw, 420px);
  pointer-events: none;
}
.toast {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 0.9rem;
  box-shadow: var(--shadow-pop);
  animation: toast-in var(--dur) var(--ease);
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.divider { height: 1px; background: var(--gold-line); border: 0; margin: var(--space-6) 0; }

/* ── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 560px) {
  .card > .btn,
  .card form .btn[type="submit"] { width: 100%; }
}

@media (min-width: 720px) {
  .shell { padding: var(--space-6) var(--space-5) var(--space-8); }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .spend-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .spend-strip .cell:first-child { grid-column: auto; }
  .spend-strip .cell + .cell {
    border-left: 1px solid var(--line);
    padding-left: var(--space-5);
  }
  .steps li { font-size: 0.95rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
