:root {
  --brand: #ffc400;
  --brand-ink: #111;
  --brand-soft: #fff6d6;
  --ink: #1c1b18;
  --muted: #6d6a62;
  --line: #e9e6de;
  --bg: #f6f5f1;
  --surface: #fff;
  --dark: #16150f;
  --ok: #1f8a4c;
  --ok-soft: #e6f4ec;
  --fail: #c23b30;
  --fail-soft: #fbe9e7;
  --run: #2f6fdb;
  --run-soft: #e8f0fd;
  --warn: #b7791f;
  --warn-soft: #fdf3e1;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(22, 21, 15, .04), 0 4px 16px rgba(22, 21, 15, .05);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 14px/1.5 Inter, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 15px; font-weight: 650; }
h3 { font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 22px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 18px; border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s, opacity .15s;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-primary:hover:not(:disabled) { background: #f2b900; }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { border-color: #d6d2c6; background: #faf9f6; }
.btn-ghost-dark { background: transparent; border-color: rgba(255, 255, 255, .2); color: #f1efe8; }
.btn-ghost-dark:hover { border-color: rgba(255, 255, 255, .45); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }
.link { background: none; border: 0; padding: 0; color: var(--run); cursor: pointer; font: inherit; }
.link:hover { text-decoration: underline; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted);
}
.icon-btn:hover { color: var(--ink); }
:focus-visible { outline: 2px solid var(--run); outline-offset: 2px; }

/* ── Topbar ──────────────────────────────────────────────── */
.topbar { background: var(--dark); color: #f1efe8; position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1240px; margin: 0 auto; padding: 10px 24px; display: flex; align-items: center; gap: 14px; }
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font-size: 16px; }
.brand b { color: var(--brand); }
.spacer { flex: 1; }
.topbar-meta { font-size: 12.5px; color: #bdb9ad; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px;
  border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill-muted { background: rgba(255, 255, 255, .1); color: #d6d2c6; }
.pill-standby { background: rgba(255, 196, 0, .16); color: var(--brand); }
.pill-failover { background: #ff5b4f; color: #fff; }

/* ── Layout ──────────────────────────────────────────────── */
.wrap { max-width: 1240px; margin: 0 auto; padding: 24px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }

/* ── Hero ────────────────────────────────────────────────── */
.hero { display: grid; grid-template-columns: 1fr auto; gap: 18px 24px; align-items: center; padding: 24px; }
.hero-main { display: flex; align-items: center; gap: 16px; min-width: 0; }
.hero-icon {
  flex: none; width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center;
  font-size: 24px; font-weight: 700; background: #f1efe8; color: var(--muted);
}
.hero-icon.ok { background: var(--ok-soft); color: var(--ok); }
.hero-icon.failed { background: var(--fail-soft); color: var(--fail); }
.hero-icon.running { background: var(--run-soft); color: var(--run); }
.hero-text h1 { font-size: 21px; font-weight: 700; }
.hero-text p { margin: 4px 0 0; }
.hero-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.hero.is-failed { border-color: #f1c4bf; }
.hero.is-running { border-color: #c6d8f7; }

.spinner {
  width: 22px; height: 22px; border-radius: 50%; border: 3px solid currentColor;
  border-right-color: transparent; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.live { grid-column: 1 / -1; border-top: 1px solid var(--line); padding-top: 18px; }
.stepper { list-style: none; margin: 0 0 16px; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.stepper li {
  position: relative; padding: 10px 12px 10px 36px; border-radius: 10px; background: #f7f6f2;
  font-size: 13px; color: var(--muted); min-height: 54px;
}
.stepper li::before {
  content: ""; position: absolute; left: 12px; top: 13px; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid #cfcabd; background: var(--surface);
}
.stepper li b { display: block; color: var(--ink); font-weight: 600; }
.stepper li.done { background: var(--ok-soft); }
.stepper li.done::before { border-color: var(--ok); background: var(--ok); }
.stepper li.failed { background: var(--fail-soft); }
.stepper li.failed::before { border-color: var(--fail); background: var(--fail); }
.stepper li.active { background: var(--run-soft); }
.stepper li.active::before { border-color: var(--run); border-right-color: transparent; animation: spin .8s linear infinite; }
.live-log-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }

/* ── KPI cards ───────────────────────────────────────────── */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 20px; }
.kpi header { font-size: 12.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 26px; font-weight: 700; margin-top: 8px; font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: 8px; }
.kpi-value.ok { color: var(--ok); }
.kpi-value.failed { color: var(--fail); }
.kpi-value.warn { color: var(--warn); }
.kpi-sub { margin-top: 2px; font-size: 12.5px; min-height: 19px; }
.uptime { display: flex; gap: 2px; margin-top: 12px; height: 22px; align-items: stretch; }
.uptime i { flex: 1; border-radius: 2px; background: var(--ok); opacity: .85; }
.uptime i.down { background: var(--fail); opacity: 1; }
.uptime i.none { background: #e4e1d8; }
.meter { margin-top: 12px; height: 8px; border-radius: 999px; background: #eeebe3; overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; background: var(--ok); border-radius: inherit; transition: width .4s; }
.meter span.warn { background: var(--warn); }
.meter span.failed { background: var(--fail); }

/* ── Chart ───────────────────────────────────────────────── */
.legend { font-size: 12.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-left: 8px; }
.dot-ok { background: var(--ok); }
.dot-failed { background: var(--fail); }
.chart { height: 150px; }
.chart svg { width: 100%; height: 100%; display: block; overflow: visible; }
.chart .bar { cursor: pointer; transition: opacity .15s; }
.chart .bar:hover { opacity: .75; }
.chart .bar-ok { fill: var(--ok); }
.chart .bar-failed { fill: var(--fail); }
.chart .grid { stroke: #eeebe3; stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }

/* ── Chips / table ───────────────────────────────────────── */
.chips { display: inline-flex; gap: 6px; padding: 4px; background: #f3f1ec; border-radius: 10px; }
.chip { border: 0; background: transparent; border-radius: 7px; padding: 5px 12px; font: inherit; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; }
.chip.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.table-wrap { overflow-x: auto; margin: 0 -20px; }
.table { width: 100%; border-collapse: collapse; min-width: 860px; }
.table th, .table td { padding: 11px 20px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; background: #fbfaf8; }
.table th.num, .table td.num { text-align: right; }
.table tbody tr { cursor: pointer; transition: background .1s; }
.table tbody tr:hover { background: #fbfaf6; }
.table tbody tr.is-running { background: #f6f9ff; }
.cell-main { font-weight: 600; }
.cell-sub { font-size: 12px; color: var(--muted); }
.table-foot { display: flex; justify-content: center; padding-top: 14px; }
.empty { text-align: center; padding: 36px 0 20px; color: var(--muted); }

.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px;
  border-radius: 999px; font-size: 12px; font-weight: 600;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-failed { background: var(--fail-soft); color: var(--fail); }
.badge-running { background: var(--run-soft); color: var(--run); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: 12px; background: #f1efe8; color: #4a4741; }
.tag-manual { background: var(--brand-soft); color: #7a5b00; }
.tag-failover { background: var(--fail-soft); color: var(--fail); }

/* ── Drawer ──────────────────────────────────────────────── */
.backdrop { position: fixed; inset: 0; background: rgba(22, 21, 15, .35); z-index: 30; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(720px, 100vw); background: var(--surface);
  z-index: 31; transform: translateX(100%); transition: transform .22s ease; display: flex; flex-direction: column;
  box-shadow: -8px 0 32px rgba(22, 21, 15, .15);
}
.drawer.open { transform: none; }
.drawer-head { display: flex; justify-content: space-between; gap: 16px; padding: 20px 24px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { font-size: 19px; margin-top: 8px; }
.drawer-head p { margin: 4px 0 0; }
.drawer-body { padding: 4px 24px 24px; overflow-y: auto; overflow-x: hidden; flex: 1; }
.facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 18px; }
.fact { background: #f8f7f3; border-radius: 10px; padding: 10px 12px; min-width: 0; }
.fact span { display: block; font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.fact b { display: block; font-size: 15px; margin-top: 2px; overflow-wrap: anywhere; }
.fact small { display: block; color: var(--muted); overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; align-items: center; padding: 9px 0; border-bottom: 1px dashed var(--line); }
.timeline li:last-child { border-bottom: 0; }
.timeline .ti { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; color: #fff; font-weight: 700; }
.timeline .ti.ok { background: var(--ok); }
.timeline .ti.failed { background: var(--fail); }
.timeline .ti.running { background: var(--run); }
.timeline .ti.pending { background: #d6d2c6; }
.log-head { display: flex; justify-content: space-between; align-items: center; }
.log-head h3 { margin-bottom: 10px; }
.log-actions { display: flex; gap: 8px; }
.log {
  margin: 0; background: #14130f; color: #e6e3da; border-radius: 10px; padding: 14px 16px;
  font: 12px/1.6 var(--mono); max-height: 460px; overflow: auto; white-space: pre-wrap; word-break: break-word;
}
.log-compact { max-height: 180px; }
.log .l-err { color: #ff8a80; }
.log .l-ok { color: #8fd6a4; }
.log .l-step { color: var(--brand); font-weight: 600; }

/* ── Modal / toasts ──────────────────────────────────────── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(22, 21, 15, .45); z-index: 40; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 14px; padding: 24px; width: min(480px, 100%); box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.modal h2 { font-size: 18px; }
.modal-list { padding-left: 18px; margin: 14px 0 10px; display: grid; gap: 6px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.toasts { position: fixed; bottom: 20px; right: 20px; display: grid; gap: 10px; z-index: 50; }
.toast {
  background: var(--dark); color: #f1efe8; padding: 12px 16px; border-radius: 10px; font-size: 13.5px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .2); border-left: 4px solid var(--brand); max-width: 360px;
  animation: toast-in .2s ease;
}
.toast.ok { border-left-color: #4cc27a; }
.toast.failed { border-left-color: #ff6b5f; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.foot { text-align: center; padding: 4px 0 12px; }

/* ── Login ───────────────────────────────────────────────── */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1200px 600px at 50% -10%, #fff3c4 0%, var(--bg) 60%); }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 28px; }
.login-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.login-title { font-size: 18px; font-weight: 700; }
.field { display: grid; gap: 6px; margin-bottom: 14px; font-size: 13px; font-weight: 600; }
.field input {
  height: 42px; border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; font: inherit; font-weight: 400;
  background: #fdfdfb; transition: border-color .15s, box-shadow .15s;
}
.field input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(255, 196, 0, .25); }
.form-error { color: var(--fail); background: var(--fail-soft); border-radius: 8px; padding: 8px 12px; margin: 0 0 14px; font-size: 13px; }
.login-foot { text-align: center; font-size: 12px; margin: 18px 0 0; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 1024px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .wrap { padding: 14px; gap: 14px; }
  .topbar-inner { padding: 10px 14px; gap: 10px; }
  #refresh-state, #user-name { display: none; }
  .hero { grid-template-columns: 1fr; }
  .hero-actions { align-items: stretch; }
  .kpis { grid-template-columns: 1fr; gap: 14px; }
  .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .drawer-head, .drawer-body { padding-left: 16px; padding-right: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before { animation: none !important; transition: none !important; }
}
