:root {
  --bg: #0b1411;
  --bg-2: #0f1a16;
  --surface: #122019;
  --surface-2: #16271f;
  --border: #1f3329;
  --border-2: #2a463a;
  --text: #e8f2ec;
  --muted: #8aa89a;
  --muted-2: #6f8d80;
  --accent: #4fe3b5;
  --accent-ink: #06231b;
  --danger: #ff6b6b;
  --danger-bg: #2a1414;
  --info: #5bc8ff;
  --info-bg: #0e2330;
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "Cascadia Code", Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { font-weight: 600; letter-spacing: -0.01em; margin: 0; }
.muted { color: var(--muted); }

/* ---- Brand ------------------------------------------------------------- */
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-mark { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; color: var(--text); }
.brand-badge {
  font-size: 10px; font-weight: 700; letter-spacing: 0.18em;
  color: var(--accent-ink); background: var(--accent);
  padding: 2px 7px; border-radius: 999px;
}

/* ---- Auth pages -------------------------------------------------------- */
.auth-body {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(1200px 600px at 50% -20%, #11251d 0%, transparent 60%),
    var(--bg);
  padding: 24px;
}
.auth-wrap { width: 100%; max-width: 400px; }
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 30px 30px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.45);
}
.auth-card .brand { justify-content: center; margin-bottom: 22px; }
.auth-title { font-size: 19px; margin-bottom: 4px; text-align: center; }
.auth-sub { color: var(--muted); text-align: center; margin: 0 0 18px; font-size: 13.5px; }
.auth-foot { text-align: center; color: var(--muted-2); font-size: 12px; margin-top: 18px; }
.auth-alt { text-align: center; margin-top: 16px; }

label { display: block; font-size: 12.5px; color: var(--muted); margin: 14px 0 6px; font-weight: 500; }
input[type=email], input[type=password], input[type=text] {
  width: 100%; padding: 11px 13px; font-size: 15px; font-family: var(--font);
  color: var(--text); background: var(--bg-2);
  border: 1px solid var(--border-2); border-radius: var(--radius-sm); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,227,181,0.15); }
.code-input { text-align: center; letter-spacing: 0.5em; font-size: 22px; font-family: var(--mono); }
.hint { color: var(--muted-2); font-size: 12px; margin: 8px 0 0; }

/* ---- Buttons ----------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--font); font-size: 14px; font-weight: 600; cursor: pointer;
  padding: 11px 18px; border-radius: var(--radius-sm); border: 1px solid transparent;
  transition: filter .15s, background .15s, border-color .15s;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.06); }
.btn-block { width: 100%; margin-top: 20px; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border-2); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-link { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 0; }
.btn-link:hover { color: var(--accent); }

/* ---- Alerts ------------------------------------------------------------ */
.alert { border-radius: var(--radius-sm); padding: 10px 13px; font-size: 13.5px; margin-bottom: 16px; border: 1px solid transparent; }
.alert-error { background: var(--danger-bg); color: #ffb4b4; border-color: #4a2020; }
.alert-info { background: var(--info-bg); color: #bfe6ff; border-color: #1c3a4a; }

/* ---- App shell --------------------------------------------------------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 244px; flex-shrink: 0; background: var(--bg-2);
  border-right: 1px solid var(--border); padding: 22px 16px;
  display: flex; flex-direction: column; gap: 22px;
}
.sidebar .brand { padding: 0 8px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; flex-direction: column; gap: 1px;
  padding: 9px 12px; border-radius: var(--radius-sm); color: var(--text);
  border: 1px solid transparent; transition: background .12s, border-color .12s;
}
.nav-item:hover { background: var(--surface); }
.nav-item.active { background: var(--surface-2); border-color: var(--border-2); }
.nav-item.active .nav-label { color: var(--accent); }
.nav-label { font-size: 14px; font-weight: 600; }
.nav-sub { font-size: 11px; color: var(--muted-2); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 28px; border-bottom: 1px solid var(--border); background: var(--bg-2);
}
.topbar-title { font-size: 15px; font-weight: 600; color: var(--muted); }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.who { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.25; }
.who-email { font-size: 13px; }
.who-role { font-size: 11px; color: var(--muted-2); text-transform: capitalize; }
.logout-form { margin: 0; }

.content { padding: 28px; max-width: 1100px; width: 100%; }
.page-head { margin-bottom: 22px; }
.page-head h1 { font-size: 22px; margin-bottom: 4px; }

/* ---- Cards ------------------------------------------------------------- */
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; }
.card-title { font-size: 12.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.card-metric { font-size: 30px; font-weight: 700; margin: 10px 0 6px; color: var(--text); }
.card-foot { font-size: 12.5px; margin: 0; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 22px; }
.panel-title { font-size: 15px; margin-bottom: 12px; }
.check-list { margin: 0; padding-left: 0; list-style: none; display: grid; gap: 8px; }
.check-list li { position: relative; padding-left: 24px; color: var(--muted); font-size: 14px; }
.check-list li::before { content: "✓"; position: absolute; left: 0; color: var(--accent); font-weight: 700; }

.empty-state { text-align: center; padding: 44px 22px; }
.empty-title { font-size: 16px; font-weight: 600; margin: 0 0 6px; }

/* ---- Metrics extras ---------------------------------------------------- */
.metric-sub { font-size: 16px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.metric-arrow { color: var(--muted-2); margin: 0 8px; font-weight: 400; }
.mono { font-family: var(--mono); font-size: 13px; }
.cap { text-transform: capitalize; }
.note { font-size: 12px; font-weight: 400; margin-left: 8px; }

/* ---- Panels with header ------------------------------------------------ */
.panel { margin-bottom: 20px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.panel-head .panel-title { margin: 0; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }

/* ---- Search bar -------------------------------------------------------- */
.search-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.search-bar input { max-width: 340px; }

/* ---- Tables ------------------------------------------------------------ */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table thead th {
  text-align: left; font-size: 11px; font-weight: 600; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--muted-2); padding: 0 12px 10px; border-bottom: 1px solid var(--border);
}
.table th.num, .table td.num { text-align: right; }
.table tbody td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table.compact td, .table.compact th { padding: 7px 10px; font-size: 13px; }
.row-link { cursor: pointer; transition: background .1s; }
.row-link:hover { background: var(--surface-2); }
.tname { display: block; font-weight: 600; color: var(--text); }
.row-link:hover .tname { color: var(--accent); }
.tid { font-family: var(--mono); font-size: 11px; color: var(--muted-2); }
.nowrap { white-space: nowrap; }
.empty-row { text-align: center; padding: 20px; }

/* ---- Add-on chips ------------------------------------------------------ */
.addons-cell { white-space: nowrap; }
.addon-chip { display: inline-block; font-size: 10.5px; font-weight: 600; line-height: 1.4;
  padding: 1px 6px; margin: 1px 3px 1px 0; border-radius: 5px;
  background: var(--surface-2); border: 1px solid var(--border-2); color: var(--accent); }

/* ---- Pills ------------------------------------------------------------- */
.pill { display: inline-block; font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 999px; text-transform: capitalize; }
.pill-active { background: rgba(79,227,181,0.14); color: var(--accent); }
.pill-paused { background: rgba(138,168,154,0.16); color: var(--muted); }
.pill-past_due { background: rgba(255,107,107,0.15); color: #ff9b9b; }
.pill-canceled { background: rgba(255,107,107,0.10); color: #d98a8a; }
.pill-deleting { background: rgba(255,107,107,0.22); color: #ffb4b4; }

/* ---- Danger zone ------------------------------------------------------- */
.danger-zone { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.danger-title { font-size: 13px; font-weight: 600; color: var(--danger); margin: 0 0 10px; }
.warn-line { font-size: 13px; color: #ffb4b4; background: var(--danger-bg);
  border: 1px solid #4a2020; border-radius: var(--radius-sm); padding: 10px 12px; margin: 0 0 12px; }
.dz-label { display: block; font-size: 12.5px; color: var(--muted); margin: 10px 0 0; }
.dz-label input { margin-top: 5px; max-width: 240px; }
.scheduled-zone { background: var(--danger-bg); border: 1px solid #4a2020;
  border-radius: var(--radius-sm); padding: 14px 16px; }
.scheduled-zone p { margin: 0 0 12px; font-size: 13.5px; }

/* ---- Usage bar --------------------------------------------------------- */
.bar { height: 5px; background: var(--bg-2); border-radius: 999px; overflow: hidden; margin: 0 0 4px auto; width: 120px; }
.bar-fill { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.bar-fill.bar-hot { background: var(--danger); }
.bar-label { font-size: 11px; color: var(--muted-2); }

/* ---- Detail page ------------------------------------------------------- */
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; }
.detail-head-right { display: flex; align-items: center; gap: 12px; }
.mrr-tag { font-size: 13px; font-weight: 600; color: var(--accent); }
.crumb { color: var(--muted); }
.spec { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; margin: 0; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.spec > div { background: var(--surface); padding: 12px 16px; }
.spec dt { font-size: 11.5px; color: var(--muted-2); text-transform: uppercase; letter-spacing: 0.04em; margin: 0 0 3px; }
.spec dd { margin: 0; font-size: 14px; word-break: break-word; }
.col-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.kb-preview {
  font-family: var(--mono); font-size: 12.5px; line-height: 1.6; color: var(--muted);
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 16px; max-height: 320px; overflow: auto; white-space: pre-wrap; margin: 0;
}
@media (max-width: 860px) { .col-2, .spec { grid-template-columns: 1fr; } }

.ext-link { font-size: 12px; }

/* ---- Costs ------------------------------------------------------------- */
.cost-good { color: var(--accent); }
.cost-warn { color: #f0c040; }
.cost-bad { color: var(--danger); }
.cost-caveat { font-size: 12px; line-height: 1.6; margin-top: 16px; }

/* ---- Health ------------------------------------------------------------ */
.health-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.health-item { display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.health-name { font-weight: 600; font-size: 14px; }
.alert-inline { color: var(--danger); font-weight: 600; }

/* ---- Comprehensive detail view ---------------------------------------- */
.card-metric.small { font-size: 18px; }
.mono-sm { font-family: var(--mono); font-size: 11.5px; word-break: break-all; }
.wrap-cell { white-space: normal; max-width: 360px; }
.sub-title { font-size: 13px; font-weight: 600; color: var(--muted); margin: 18px 0 8px; }
.scroll-table { max-height: 360px; overflow: auto; }
.scroll-table thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; }
details.raw { margin-bottom: 8px; }
details.raw > summary { cursor: pointer; font-size: 13px; color: var(--accent); margin-bottom: 10px;
  list-style: none; display: inline-block; }
details.raw > summary::-webkit-details-marker { display: none; }
details.raw > summary::before { content: "▸ "; }
details.raw[open] > summary::before { content: "▾ "; }

/* ---- Phase 4: edit form + actions ------------------------------------- */
.alert-success { background: rgba(79,227,181,0.12); color: var(--accent); border-color: rgba(79,227,181,0.3); }
.alert-temp { background: var(--surface-2); border-color: var(--border-2); color: var(--text); }
.temp-pass { display: inline-block; margin-left: 6px; font-family: var(--mono); font-size: 15px;
  background: var(--bg-2); border: 1px solid var(--border-2); border-radius: var(--radius-sm);
  padding: 4px 10px; color: var(--accent); user-select: all; }

.edit-form .field-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 18px; margin-bottom: 16px; }
.edit-form label { display: block; font-size: 12.5px; color: var(--muted); margin: 0; font-weight: 500; }
.edit-form label input[type=text], .edit-form label input[type=email] { margin-top: 6px; }
.edit-form label select { margin-top: 6px; width: 100%; padding: 10px 12px; font-size: 15px;
  font-family: var(--font); color: var(--text); background: var(--bg-2);
  border: 1px solid var(--border-2); border-radius: var(--radius-sm); }
.edit-form label.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); align-self: end; padding-bottom: 10px; }
.edit-form label.check input { width: auto; margin: 0; }
@media (max-width: 760px) { .edit-form .field-grid { grid-template-columns: 1fr; } }

.actions-row { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-start; }
.btn-danger { background: transparent; color: #ff9b9b; border-color: #4a2020; }
.btn-danger:hover { background: var(--danger-bg); }
details.confirm > summary { list-style: none; cursor: pointer; }
details.confirm > summary::-webkit-details-marker { display: none; }
details.confirm[open] > summary { color: var(--accent); border-color: var(--accent); }
.confirm-body { margin-top: 10px; padding: 14px; background: var(--surface-2);
  border: 1px solid var(--border-2); border-radius: var(--radius-sm); max-width: 340px; }
.confirm-body p { margin: 0 0 10px; font-size: 13px; }
