/* ==========================================================================
   Branded API Gateway — administration panel styles
   Plain CSS, no framework. Theming is driven entirely by custom properties
   on :root[data-theme]; admin.js swaps the attribute and persists the choice.
   ========================================================================== */

:root {
  color-scheme: dark;

  /* Dark palette (default) */
  --bg: #05070c;
  --surface: #0a0d12;
  --surface-raised: #161d2b;
  --surface-hover: #1c2537;
  --border: #232c3d;
  --border-strong: #33405a;

  --text: #e8edf6;
  --text-muted: #96a1b6;
  --text-faint: #6b7789;

  --accent: #5b9dff;
  --accent-hover: #79b0ff;
  --accent-contrast: #04070d;

  --ok-bg: rgba(52, 199, 123, 0.14);
  --ok-fg: #4ade9b;
  --warn-bg: rgba(245, 184, 65, 0.14);
  --warn-fg: #f5c04f;
  --bad-bg: rgba(248, 96, 96, 0.14);
  --bad-fg: #ff8080;
  --muted-bg: rgba(150, 161, 182, 0.12);
  --muted-fg: #a7b2c4;

  --danger: #e5484d;
  --danger-hover: #f25c60;

  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --radius: 10px;
  --radius-sm: 6px;
  --maxw: 1180px;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, "Liberation Mono", monospace;
}

:root[data-theme="light"] {
  color-scheme: light;

  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-raised: #eef2f8;
  --surface-hover: #e6ecf5;
  --border: #d9e0eb;
  --border-strong: #bcc7d8;

  --text: #16202f;
  --text-muted: #5a6678;
  --text-faint: #7c889a;

  --accent: #1f63d6;
  --accent-hover: #1a55b8;
  --accent-contrast: #ffffff;

  --ok-bg: rgba(20, 145, 85, 0.12);
  --ok-fg: #12805a;
  --warn-bg: rgba(176, 116, 5, 0.13);
  --warn-fg: #8a5c05;
  --bad-bg: rgba(190, 40, 45, 0.11);
  --bad-fg: #b02a2f;
  --muted-bg: rgba(90, 102, 120, 0.1);
  --muted-fg: #5a6678;

  --danger: #c22a2f;
  --danger-hover: #a92227;

  --shadow: 0 10px 24px rgba(22, 32, 47, 0.09);
}

/* ------------------------------------------------------------------ reset */

*,
*::before,
*::after { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.2; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.02rem; }

p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code, .code { font-family: var(--mono); font-size: 0.86em; }

.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;
}

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--accent); color: var(--accent-contrast);
  padding: 0.6rem 1rem; border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus { left: 0; }

/* ----------------------------------------------------------------- topbar */

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0.65rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.brand {
  display: inline-flex; align-items: center; gap: 0.55rem;
  color: var(--text); font-weight: 650; white-space: nowrap;
}
.brand:hover { text-decoration: none; }

.brand-mark {
  width: 20px; height: 20px; border-radius: 6px; flex: none;
  background: linear-gradient(135deg, var(--accent), #8f6bff);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 45%, transparent);
}
.brand-mark-lg { width: 34px; height: 34px; border-radius: 10px; }

.brand-text { font-size: 0.95rem; }

.nav { display: flex; gap: 0.15rem; flex-wrap: wrap; }
.nav a {
  padding: 0.4rem 0.7rem; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: 0.9rem; font-weight: 500;
}
.nav a:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--surface-raised); color: var(--text); }

.topbar-actions {
  margin-left: auto; display: flex; align-items: center; gap: 0.5rem;
}

.inline-form { display: inline; margin: 0; }

/* ------------------------------------------------------------------ pages */

.page {
  width: 100%; max-width: var(--maxw);
  margin: 0 auto; padding: 1.75rem 1.25rem 3rem;
  flex: 1;
}

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 1rem; margin-bottom: 1.35rem;
}
.page-sub { color: var(--text-muted); font-size: 0.92rem; margin-top: 0.25rem; }

.footer {
  border-top: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 0.8rem;
  padding: 1rem 1.25rem;
  text-align: center;
}
.footer-sep { margin: 0 0.5rem; }

/* ------------------------------------------------------------------- grid */

.grid { display: grid; gap: 1rem; }
.grid-dashboard { grid-template-columns: repeat(auto-fit, minmax(255px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.15rem;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card-wide { grid-column: 1 / -1; }

.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.75rem; margin-bottom: 0.85rem;
}
.card-sub { color: var(--text-muted); font-size: 0.88rem; margin-bottom: 0.9rem; }
.card-actions { margin-top: 1rem; display: flex; gap: 0.5rem; flex-wrap: wrap; }

.card-danger { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.card-attention { border-color: color-mix(in srgb, var(--warn-fg) 45%, var(--border)); }

.count {
  font-size: 0.78rem; font-weight: 600; color: var(--text-muted);
  background: var(--muted-bg); border-radius: 999px; padding: 0.15rem 0.55rem;
}

/* -------------------------------------------------------------- key/value */

.kv { margin: 0; display: grid; gap: 0.55rem; }
.kv > div {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 1rem; padding-bottom: 0.55rem;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
}
.kv > div:last-child { border-bottom: 0; padding-bottom: 0; }
.kv dt { color: var(--text-muted); font-size: 0.85rem; flex: none; }
.kv dd { margin: 0; font-weight: 550; text-align: right; overflow-wrap: anywhere; }
.kv-inline { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.kv-inline > div { flex-direction: column; align-items: flex-start; gap: 0.15rem; }
.kv-inline dd { text-align: left; }

.muted { color: var(--text-muted); font-weight: 400; font-size: 0.88rem; }
.empty { color: var(--text-faint); font-size: 0.9rem; padding: 0.5rem 0; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

/* ----------------------------------------------------------------- badges */

.badge {
  display: inline-flex; align-items: center; gap: 0.35rem;
  font-size: 0.76rem; font-weight: 650; letter-spacing: 0.02em;
  padding: 0.2rem 0.6rem; border-radius: 999px; white-space: nowrap;
  text-transform: uppercase;
}
.badge::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor;
}
.badge-ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge-warn { background: var(--warn-bg); color: var(--warn-fg); }
.badge-bad { background: var(--bad-bg); color: var(--bad-fg); }
.badge-muted { background: var(--muted-bg); color: var(--muted-fg); }

/* ------------------------------------------------------------------ table */

.table-wrap { overflow-x: auto; margin: 0 -1.15rem; padding: 0 1.15rem; }
.table-scroll { max-height: 26rem; overflow-y: auto; }

.table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.table th, .table td {
  padding: 0.55rem 0.7rem; text-align: left; vertical-align: top;
  border-bottom: 1px solid var(--border);
}
.table th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface);
  color: var(--text-muted); font-size: 0.76rem; font-weight: 650;
  text-transform: uppercase; letter-spacing: 0.04em;
  white-space: nowrap;
}
.table tbody tr:hover { background: var(--surface-hover); }
.table tbody tr:last-child td { border-bottom: 0; }
.row-critical td { color: var(--bad-fg); }

/* ------------------------------------------------------------------ forms */

.form { display: grid; gap: 0.9rem; }
.form-grid { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); align-items: start; }
.form-grid .form-actions { grid-column: 1 / -1; }

.field { display: grid; gap: 0.3rem; }
.field-label { font-size: 0.85rem; font-weight: 600; }
.optional { color: var(--text-faint); font-weight: 400; }
.field-help { color: var(--text-muted); font-size: 0.79rem; }
.field-help-warn { color: var(--warn-fg); font-weight: 600; }

.input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  padding: 0.5rem 0.65rem;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.input::placeholder { color: var(--text-faint); }
.input:hover { border-color: var(--text-faint); }
.input:focus-visible,
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent);
}

.form-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ----------------------------------------------------------------- buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 0.35rem;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  font: inherit; font-weight: 600; font-size: 0.88rem;
  padding: 0.48rem 0.9rem;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent);
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary {
  background: var(--surface-raised); color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) { background: var(--surface-hover); }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }

.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.btn-block { width: 100%; }

/* ------------------------------------------------------------------ flash */

.flash-region { max-width: var(--maxw); margin: 0 auto; padding: 0 1.25rem; width: 100%; }

.flash {
  display: flex; align-items: flex-start; gap: 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.85rem;
  margin-top: 1rem;
  font-size: 0.88rem;
  background: var(--surface-raised);
}
.flash-text { flex: 1; }
.flash-close {
  background: none; border: 0; color: inherit; cursor: pointer;
  font-size: 1.1rem; line-height: 1; padding: 0 0.15rem; opacity: 0.7;
}
.flash-close:hover { opacity: 1; }

.flash-error { background: var(--bad-bg); border-color: color-mix(in srgb, var(--bad-fg) 45%, transparent); color: var(--bad-fg); }
.flash-info { background: var(--muted-bg); }
.flash-success { background: var(--ok-bg); border-color: color-mix(in srgb, var(--ok-fg) 45%, transparent); color: var(--ok-fg); }

.callout {
  border-radius: var(--radius-sm);
  padding: 0.8rem 0.9rem;
  font-size: 0.88rem;
  border: 1px solid var(--border-strong);
  background: var(--surface-raised);
}
.callout-warn { background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn-fg) 45%, transparent); color: var(--warn-fg); }

/* ------------------------------------------------------------------ login */

.auth-body {
  justify-content: center; align-items: center; padding: 2rem 1rem;
  background:
    radial-gradient(900px 500px at 15% -10%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 70%),
    var(--bg);
}

.auth-card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 2rem 1.75rem;
  box-shadow: var(--shadow);
}
.auth-head { text-align: center; margin-bottom: 1.5rem; }
.auth-head h1 { margin-top: 0.85rem; font-size: 1.35rem; }
.auth-sub { color: var(--text-muted); font-size: 0.88rem; margin-top: 0.3rem; }
.auth-form { gap: 1rem; }
.auth-foot { margin-top: 1.5rem; text-align: center; color: var(--text-faint); font-size: 0.78rem; }
.auth-card .flash { margin: 0 0 1rem; }
.auth-card .callout { margin-top: 0.5rem; }

/* ----------------------------------------------------------------- secret */

.secret-reveal {
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
  background: var(--bg); border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm); padding: 0.75rem 0.85rem;
}
.secret-value {
  flex: 1; min-width: 0; overflow-wrap: anywhere;
  font-size: 0.92rem; color: var(--ok-fg); user-select: all;
}

/* -------------------------------------------------------------- htmx ux */

.htmx-request .btn,
.htmx-request.btn { opacity: 0.6; pointer-events: none; }

.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-flex; }

#restart-result .flash { margin-top: 0.75rem; }

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

/* ------------------------------------------------------------ responsive */

@media (max-width: 860px) {
  .topbar-inner { flex-wrap: wrap; gap: 0.6rem; }
  .nav { order: 3; width: 100%; overflow-x: auto; padding-top: 0.35rem; }
  .nav a { white-space: nowrap; }
  .topbar-actions { margin-left: auto; }
}

@media (max-width: 560px) {
  body { font-size: 14px; }
  .page { padding: 1.25rem 0.9rem 2.5rem; }
  .topbar-inner { padding: 0.55rem 0.9rem; }
  .brand-text { display: none; }
  h1 { font-size: 1.3rem; }
  .card { padding: 0.95rem 0.9rem; }
  .table-wrap { margin: 0 -0.9rem; padding: 0 0.9rem; }
  .kv > div { flex-direction: column; align-items: flex-start; gap: 0.1rem; }
  .kv dd { text-align: left; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .flash-region { padding: 0 0.9rem; }
}
