/* ===========================================================================
   Tenant Provisioner — design system
   Dark slate sidebar (both themes) + theme-aware content area.
   =========================================================================== */
:root {
  --sidebar-bg: #0e1622;
  --sidebar-fg: #aeb9c9;
  --sidebar-fg-dim: #6b7891;
  --sidebar-active-bg: rgba(79, 158, 234, .16);

  --ground: #f4f7fb;
  --panel: #ffffff;
  --panel-2: #f8fafd;
  --ink: #10151d;
  --soft: #56657c;
  --line: #e4e9f1;
  --accent: #1a73c7;
  --accent-2: #145aa0;
  --accent-soft: #e9f1fb;

  --ok: #1f9d63; --ok-soft: #e4f4ec;
  --warn: #b8860b; --warn-soft: #f8efd8;
  --err: #cc3b3b; --err-soft: #fbe8e8;

  --mono: "SFMono-Regular", "JetBrains Mono", Consolas, ui-monospace, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16,21,29,.04), 0 4px 16px rgba(16,21,29,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --ground: #0a0e15; --panel: #131a25; --panel-2: #0f151f;
    --ink: #e9eff8; --soft: #8e9cb2; --line: #222d3c;
    --accent: #4f9eea; --accent-2: #6fb0f0; --accent-soft: #16263a;
    --ok: #46b883; --ok-soft: #12271d; --warn: #d6a323; --warn-soft: #2a2410;
    --err: #e06666; --err-soft: #2a1414;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.35);
  }
}
:root[data-theme="light"] {
  --ground: #f4f7fb; --panel: #fff; --panel-2: #f8fafd; --ink: #10151d;
  --soft: #56657c; --line: #e4e9f1; --accent: #1a73c7; --accent-2: #145aa0;
  --accent-soft: #e9f1fb; --ok: #1f9d63; --ok-soft: #e4f4ec; --warn: #b8860b;
  --warn-soft: #f8efd8; --err: #cc3b3b; --err-soft: #fbe8e8;
}
:root[data-theme="dark"] {
  --ground: #0a0e15; --panel: #131a25; --panel-2: #0f151f; --ink: #e9eff8;
  --soft: #8e9cb2; --line: #222d3c; --accent: #4f9eea; --accent-2: #6fb0f0;
  --accent-soft: #16263a; --ok: #46b883; --ok-soft: #12271d; --warn: #d6a323;
  --warn-soft: #2a2410; --err: #e06666; --err-soft: #2a1414;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--ground); color: var(--ink);
  font-family: var(--sans); line-height: 1.5; -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ---- app shell ---- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--sidebar-bg); color: var(--sidebar-fg);
  display: flex; flex-direction: column; gap: 8px; padding: 20px 14px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 6px 8px 18px; }
.brand-mark { width: 30px; height: 30px; color: var(--accent-2); stroke-width: 1.7; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { color: #fff; font-size: 15px; }
.brand-text span { color: var(--sidebar-fg-dim); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }

.nav { display: flex; flex-direction: column; gap: 3px; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 9px;
  color: var(--sidebar-fg); text-decoration: none; font-size: 14px; font-weight: 500;
  transition: background .12s, color .12s;
}
.nav a svg { width: 18px; height: 18px; }
.nav a:hover { background: rgba(255,255,255,.05); color: #fff; }
.nav a.active { background: var(--sidebar-active-bg); color: #fff; }

.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 8px; }
.mode-badge {
  font-family: var(--mono); font-size: 11px; font-weight: 600; letter-spacing: .05em;
  padding: 4px 9px; border-radius: 6px; align-self: flex-start;
  background: rgba(214,163,35,.18); color: #e8c250; border: 1px solid rgba(214,163,35,.35);
}
.mode-badge.live { background: rgba(70,184,131,.18); color: #6fdca9; border-color: rgba(70,184,131,.4); }
.side-hint { font-family: var(--mono); font-size: 10.5px; color: var(--sidebar-fg-dim); }
.user-slot { display: flex; flex-direction: column; gap: 2px; padding: 8px; border-radius: 8px; background: rgba(255,255,255,.04); }
.user-name { color: #fff; font-size: 13px; font-weight: 600; }
.user-logout { color: var(--sidebar-fg-dim); font-size: 12px; text-decoration: none; }
.user-logout:hover { color: #fff; }

/* ---- main ---- */
.main { min-width: 0; }
.view { max-width: 1060px; margin: 0 auto; padding: 34px 34px 80px; }

.page-head { margin-bottom: 26px; }
.page-head .eyebrow { font-family: var(--mono); font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); margin: 0 0 6px; }
.page-head h1 { font-size: 27px; margin: 0 0 6px; letter-spacing: -.01em; }
.page-head p { color: var(--soft); margin: 0; max-width: 64ch; }
.breadcrumb { display: inline-flex; gap: 8px; align-items: center; font-size: 13px; color: var(--soft); margin-bottom: 14px; text-decoration: none; }
.breadcrumb:hover { color: var(--accent); }

/* ---- stat tiles ---- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 26px; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.stat .label { font-size: 12.5px; color: var(--soft); text-transform: uppercase; letter-spacing: .05em; display: flex; align-items: center; gap: 8px; }
.stat .label svg { width: 15px; height: 15px; color: var(--accent); }
.stat .value { font-size: 30px; font-weight: 700; margin-top: 8px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat .value small { font-size: 14px; font-weight: 500; color: var(--soft); }

/* ---- cards / grids ---- */
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--soft); margin: 6px 0 14px; }
.tenant-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.tenant-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); text-decoration: none; color: inherit;
  display: flex; flex-direction: column; gap: 12px; transition: transform .12s, border-color .12s, box-shadow .12s;
}
.tenant-card:hover { transform: translateY(-2px); border-color: var(--accent); box-shadow: 0 6px 22px rgba(26,115,199,.14); }
.tenant-card .tc-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.tenant-card .tc-name { font-size: 17px; font-weight: 650; }
.tenant-card .tc-region { font-family: var(--mono); font-size: 12px; color: var(--soft); margin-top: 2px; }
.tenant-card .tc-res { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px;
  padding: 4px 9px; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--line); color: var(--soft);
}
.chip svg { width: 13px; height: 13px; color: var(--accent); }
.tenant-card .tc-foot { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--soft); border-top: 1px solid var(--line); padding-top: 12px; }

/* ---- status badge ---- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600;
  padding: 4px 10px; border-radius: 99px; text-transform: capitalize; letter-spacing: .01em;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.provisioned, .badge.ok { color: var(--ok); background: var(--ok-soft); }
.badge.awaiting, .badge.warn { color: var(--warn); background: var(--warn-soft); }
.badge.failed, .badge.err { color: var(--err); background: var(--err-soft); }

/* ---- detail: resource inventory ---- */
.detail-head { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; margin-bottom: 8px; }
.detail-head h1 { font-size: 26px; margin: 0; }
.meta-row { display: flex; flex-wrap: wrap; gap: 18px; color: var(--soft); font-size: 13.5px; margin-bottom: 24px; }
.meta-row b { color: var(--ink); font-weight: 600; }
.meta-row .mono { font-family: var(--mono); }

.res-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.res-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow);
}
.res-card .rc-head { display: flex; align-items: center; gap: 11px; padding: 15px 16px; border-bottom: 1px solid var(--line); }
.res-card .rc-icon { width: 38px; height: 38px; border-radius: 9px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.res-card .rc-icon svg { width: 20px; height: 20px; }
.res-card .rc-title { font-weight: 650; font-size: 14.5px; }
.res-card .rc-kind { font-family: var(--mono); font-size: 11px; color: var(--soft); text-transform: uppercase; letter-spacing: .05em; }
.res-card .rc-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.kv { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.kv .k { color: var(--soft); }
.kv .v { font-family: var(--mono); font-size: 12.5px; text-align: right; word-break: break-all; }
.kv .v a { color: var(--accent); text-decoration: none; }
.kv .v a:hover { text-decoration: underline; }
.db-list { display: flex; flex-direction: column; gap: 6px; }
.db-item { display: flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 12.5px; padding: 7px 10px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; }
.db-item svg { width: 14px; height: 14px; color: var(--accent); }

/* ---- tabs ---- */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tab {
  background: transparent; color: var(--soft); border: 0; border-bottom: 2px solid transparent;
  padding: 10px 14px; font-size: 13.5px; font-weight: 600; border-radius: 8px 8px 0 0; cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px;
}
.tab:hover { color: var(--ink); background: var(--panel-2); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab svg { width: 16px; height: 16px; }
.tab .tab-badge { font-family: var(--mono); font-size: 10px; background: var(--err); color: #fff; border-radius: 99px; padding: 1px 6px; }
.tab-panel { display: none; flex-direction: column; gap: 16px; }
.tab-panel.active { display: flex; }

/* ---- checkboxes / switches ---- */
.check { flex-direction: row; align-items: center; gap: 9px; font-weight: 500; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.switch-row { display: flex; flex-wrap: wrap; gap: 16px; }

/* ---- repeatable key/value + name rows ---- */
.rows { display: flex; flex-direction: column; gap: 8px; }
.kv-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; }
.name-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.row-del { padding: 0 12px; background: var(--panel-2); color: var(--err); border: 1px solid var(--line); border-radius: 8px; font-size: 16px; line-height: 1; }
.row-del:hover { background: var(--err-soft); }
.add-row { align-self: flex-start; background: transparent; color: var(--accent); border: 1px dashed var(--accent); padding: 8px 12px; font-size: 13px; }
.add-row:hover { background: var(--accent-soft); }

/* ---- per-database config block ---- */
.db-block { border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: var(--panel-2); display: flex; flex-direction: column; gap: 10px; }
.db-block .db-grid { display: grid; grid-template-columns: 1.3fr 1fr 0.8fr 1fr; gap: 8px; }
@media (max-width: 640px) { .db-block .db-grid { grid-template-columns: 1fr 1fr; } }
.db-block .db-num { font-family: var(--mono); font-size: 11px; color: var(--soft); text-transform: uppercase; letter-spacing: .05em; }
.field-note { font-size: 12px; color: var(--soft); background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; }
.conditional { display: none; }
.conditional.show { display: contents; }

/* ---- new-tenant layout: form + live preview ---- */
.new-layout { display: grid; grid-template-columns: 1fr 320px; gap: 22px; align-items: start; }
@media (max-width: 900px) { .new-layout { grid-template-columns: 1fr; } }

.preview { position: sticky; top: 24px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.preview .pv-head { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 9px; }
.preview .pv-head svg { color: var(--accent); }
.preview .pv-head strong { font-size: 14px; }
.preview .pv-head span { font-size: 11.5px; color: var(--soft); margin-left: auto; font-family: var(--mono); }
.preview .pv-body { padding: 6px 0; }
.pv-row { display: flex; align-items: center; gap: 10px; padding: 9px 16px; }
.pv-row svg { width: 16px; height: 16px; color: var(--accent); flex: none; }
.pv-row .pv-k { font-size: 11px; color: var(--soft); text-transform: uppercase; letter-spacing: .04em; width: 66px; flex: none; }
.pv-row .pv-v { font-family: var(--mono); font-size: 12px; word-break: break-all; }
.pv-row .pv-v.dim { color: var(--soft); font-style: italic; }
.pv-sub { padding: 2px 16px 10px 42px; display: flex; flex-wrap: wrap; gap: 6px; }
.pv-sub code { font-family: var(--mono); font-size: 11.5px; background: var(--panel-2); border: 1px solid var(--line); padding: 2px 7px; border-radius: 6px; }

/* ---- availability indicator ---- */
.field-status { font-weight: 400; font-size: 12px; display: inline-flex; align-items: center; gap: 5px; }
.field-status.ok { color: var(--ok); }
.field-status.taken, .field-status.bad { color: var(--err); }
.field-status.checking { color: var(--soft); }

/* ---- password field ---- */
.pw-wrap { display: flex; gap: 8px; }
.pw-wrap input { flex: 1; }
.pw-btn { padding: 0 12px; background: var(--panel-2); color: var(--soft); border: 1px solid var(--line); border-radius: 8px; font-size: 12.5px; font-weight: 500; white-space: nowrap; }
.pw-btn:hover { background: var(--ground); color: var(--ink); }
.db-fields { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 520px) { .db-fields { grid-template-columns: 1fr; } }

/* ---- forms ---- */
form.provision { display: flex; flex-direction: column; gap: 16px; }
fieldset {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin: 0;
  background: var(--panel); box-shadow: var(--shadow);
}
legend { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--soft); padding: 0 8px; font-weight: 600; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; font-weight: 600; }
.hint { font-weight: 400; color: var(--soft); font-size: 12px; }
input, select {
  font: inherit; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--ground); color: var(--ink);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }

button {
  font: inherit; font-weight: 600; cursor: pointer; padding: 12px 18px; border: 0;
  border-radius: 9px; background: var(--accent); color: #fff; font-size: 14.5px;
}
button:hover { background: var(--accent-2); }
button:disabled { opacity: .55; cursor: progress; }
button.ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
button.ghost:hover { background: var(--accent-soft); }
.btn-row { display: flex; gap: 10px; }

.errors {
  background: var(--err-soft); border: 1px solid var(--err); color: var(--err);
  border-radius: 10px; padding: 12px 14px; font-size: 14px;
}
.errors ul { margin: 6px 0 0; padding-left: 18px; }

/* ---- deployment / approval / progress ---- */
.status-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.stepper { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; font-size: 12.5px; }
.step { display: flex; align-items: center; gap: 7px; color: var(--soft); }
.step .dot { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; font-size: 11px; }
.step.active { color: var(--ink); font-weight: 600; }
.step.active .dot { border-color: var(--accent); color: var(--accent); }
.step.done { color: var(--ok); }
.step.done .dot { border-color: var(--ok); background: var(--ok); color: #fff; }
.step .sep { width: 22px; height: 2px; background: var(--line); }

.bar { height: 9px; background: var(--ground); border: 1px solid var(--line); border-radius: 99px; overflow: hidden; }
.fill { height: 100%; width: 0; background: var(--accent); transition: width .5s ease; }
.fill.warn { background: var(--warn); }
.fill.ok { background: var(--ok); }
.fill.err { background: var(--err); }
.statusText { font-family: var(--mono); font-size: 13px; color: var(--soft); margin: 12px 0 0; }
.runlink { display: inline-block; margin-top: 8px; font-size: 13.5px; }

.approval { margin-top: 16px; border: 1px solid var(--warn); border-radius: var(--radius); padding: 16px; background: var(--warn-soft); }
.approval-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.approval-sub { color: var(--soft); font-size: 13px; }
.plan { margin-top: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px; font-family: var(--mono); font-size: 12.5px; overflow-x: auto; white-space: pre; }
.approval-actions { display: flex; gap: 10px; margin-top: 14px; }
.approval-actions button { flex: 1; }
button.approve { background: var(--ok); }
button.approve:hover { filter: brightness(1.05); }
button.reject { background: transparent; color: var(--err); border: 1px solid var(--err); }
button.reject:hover { background: var(--err-soft); }

/* ---- misc ---- */
.empty { text-align: center; color: var(--soft); padding: 48px 20px; border: 1px dashed var(--line); border-radius: var(--radius); }
.empty svg { width: 34px; height: 34px; color: var(--soft); margin-bottom: 10px; }
.spinner { width: 26px; height: 26px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } .fill { transition: none; } .tenant-card { transition: none; } }

/* ---- responsive ---- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; gap: 10px; }
  .brand { padding: 4px 8px; }
  .nav { flex-direction: row; margin-left: auto; }
  .side-foot { margin: 0; flex-direction: row; align-items: center; }
  .side-hint { display: none; }
  .view { padding: 22px 18px 60px; }
}

/* ---- stack chooser (SFA / DMS) ---- */
.stack-choice { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stack-card {
  display: block; cursor: pointer; padding: 14px 16px;
  border: 1.5px solid var(--line); border-radius: var(--radius);
  background: var(--panel); transition: border-color .15s, background .15s;
}
.stack-card:hover { border-color: var(--accent); }
.stack-card.selected { border-color: var(--accent); background: var(--accent-soft); }
.stack-card.disabled { cursor: not-allowed; opacity: .6; }
.stack-card.disabled:hover { border-color: var(--line); }
.sc-title { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; }
.sc-title svg { width: 18px; height: 18px; color: var(--accent); }
.sc-sub { color: var(--soft); font-size: 13px; margin-top: 6px; }
@media (max-width: 640px) { .stack-choice { grid-template-columns: 1fr; } }
