* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0b1322;
  --surface: #101b2e;
  --surface-2: #16233b;
  --line: #1d2c47;
  --line-hover: #2a3b5f;
  --text: #e7ecf6;
  --text-dim: #8fa0bf;
  --text-faint: #5c6f95;
  --accent: #4fd1b4;
  --ok: #3dd68c;
  --warn: #f5b544;
  --down: #f0616d;
  --radius: 8px;
  --font-display: "Space Grotesk", system-ui, sans-serif;
  --font-body: "Inter", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", monospace;
}

html { color-scheme: dark; }

body {
  font-family: var(--font-body);
  background:
    radial-gradient(900px 480px at 85% -10%, rgba(79, 209, 180, 0.06), transparent 60%),
    radial-gradient(700px 420px at -10% 110%, rgba(88, 110, 200, 0.07), transparent 55%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 1320px; margin: 0 auto; padding: 0 20px; width: 100%; }
main.wrap { flex: 1 0 auto; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(16, 27, 46, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; }
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}
.brand em { font-style: normal; color: var(--text-dim); font-weight: 500; }
.brand-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
}
body.is-operational .brand-dot { animation: pulse 2.6s ease-out infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(79, 209, 180, 0.45); }
  70% { box-shadow: 0 0 0 9px rgba(79, 209, 180, 0); }
  100% { box-shadow: 0 0 0 0 rgba(79, 209, 180, 0); }
}
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

/* Page tabs */
.nav-tabs { display: flex; align-items: center; gap: 4px; }
.nav-tab {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  text-decoration: none;
  padding: 7px 12px;
  border-radius: 6px;
  border: 1px solid var(--line);
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.nav-tab:hover { color: var(--text-dim); background: var(--surface-2); }
.nav-tab.active {
  color: var(--accent);
  border-color: rgba(79, 209, 180, 0.35);
  background: rgba(79, 209, 180, 0.08);
}

/* Buttons */
.ghost-btn, .refresh-btn {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.ghost-btn:hover, .refresh-btn:hover { color: var(--text); border-color: var(--line-hover); background: var(--surface-2); }
button:disabled { opacity: 0.55; cursor: not-allowed; }

.nav-refresh-btn {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  color: #ffd27f;
  background: rgba(245, 181, 68, 0.12);
  border: 1px solid rgba(245, 181, 68, 0.45);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.nav-refresh-btn:hover { color: #ffe3ad; border-color: rgba(245, 181, 68, 0.7); background: rgba(245, 181, 68, 0.22); }

.logout-btn {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  color: #ff9aa2;
  background: rgba(240, 97, 109, 0.12);
  border: 1px solid rgba(240, 97, 109, 0.45);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.logout-btn:hover { color: #ffb9bf; border-color: rgba(240, 97, 109, 0.7); background: rgba(240, 97, 109, 0.22); }

/* Status strip */
.strip {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 26px 0 8px;
}
.strip-label {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text);
}
.strip-meta { font-family: var(--font-mono); font-size: 11px; color: var(--text-faint); margin-left: auto; }

/* Categories */
.category { margin: 20px 0; }
.category-header { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.category-name {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text);
}
.category-phrase {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
}
.category-phrase.operational { color: var(--ok); }
.category-phrase.degraded { color: var(--warn); }
.category-phrase.down { color: var(--down); }

/* Signal bars (signature motif) */
.signal { display: inline-flex; align-items: flex-end; gap: 3px; }
.signal i { width: 3px; border-radius: 1px; background: var(--line-hover); }
.signal i:nth-child(1) { height: 5px; }
.signal i:nth-child(2) { height: 8px; }
.signal i:nth-child(3) { height: 11px; }
.signal i:nth-child(4) { height: 14px; }
.signal i:nth-child(5) { height: 17px; }
.signal i.on { background: currentColor; }
.signal.operational { color: var(--ok); }
.signal.degraded { color: var(--warn); }
.signal.down { color: var(--down); }

/* Grid + cards */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line-hover);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  transition: border-color 0.15s, transform 0.15s;
}
.card:hover { border-color: var(--line-hover); transform: translateY(-1px); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.card.operational { border-left-color: var(--ok); }
.card.degraded { border-left-color: var(--warn); }
.card.down { border-left-color: var(--down); }
.card-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card-status { display: inline-flex; align-items: center; gap: 6px; }
.card-name { font-family: var(--font-display); font-size: 14px; font-weight: 600; color: var(--text); }
.card-meta { font-family: var(--font-mono); font-size: 11px; color: var(--text-faint); }

.info-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  color: var(--text-faint);
  transition: color 0.15s;
}
.card.degraded .info-dot { color: var(--warn); }
.card.down .info-dot { color: var(--down); }
.card:hover .info-dot, .card:focus-visible .info-dot { color: var(--text); }

/* Non-operational cards reveal the error inside the card on hover */
.card.has-error { cursor: pointer; }
.card.has-error:hover, .card.has-error:focus-visible {
  border-color: var(--line-hover);
  transform: translateY(-1px);
}
.card.has-error.degraded:hover, .card.has-error.degraded:focus-visible {
  border-color: rgba(245, 181, 68, 0.55);
  box-shadow: 0 0 0 3px rgba(245, 181, 68, 0.12);
}
.card.has-error.down:hover, .card.has-error.down:focus-visible {
  border-color: rgba(240, 97, 109, 0.55);
  box-shadow: 0 0 0 3px rgba(240, 97, 109, 0.14);
}
.card-reveal {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  background: var(--surface);
  display: flex;
  align-items: center;
  padding: 14px 16px;
  z-index: 1;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1), transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.2s;
  pointer-events: none;
}
.card-reveal-text {
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.5;
  color: var(--text);
  word-break: break-word;
}
.card.has-error.degraded .card-reveal-text { color: var(--warn); }
.card.has-error.down .card-reveal-text { color: var(--down); }
.card.has-error:hover .card-reveal, .card.has-error:focus-visible .card-reveal,
.card.has-error.copied .card-reveal {
  opacity: 1;
  visibility: visible;
  transform: none;
}
.card.has-error.copied .card-reveal {
  background: #0d2c20;
  border: 1px solid rgba(61, 214, 140, 0.4);
  pointer-events: none;
}
.card.has-error.copied .card-reveal-text { color: var(--ok); font-weight: 600; }
.card-error {
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.5;
  color: var(--down);
  word-break: break-word;
}

.chip {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.chip.operational { color: var(--ok); background: rgba(61, 214, 140, 0.12); }
.chip.degraded { color: var(--warn); background: rgba(245, 181, 68, 0.12); }
.chip.down { color: var(--down); background: rgba(240, 97, 109, 0.14); }

.load-error {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--down);
  text-align: center;
  padding: 48px 0;
}

/* Instance health page */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin: 18px 0;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stat-label {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
}
.stat-value {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  color: var(--text);
  word-break: break-word;
}
.stat-value.ok { color: var(--ok); }
.stat-value.warn { color: var(--warn); }
.stat-value.bad { color: var(--down); }
.stat-value.dim { color: var(--text-dim); }
.meter-row { display: flex; flex-direction: column; gap: 6px; }
.meter-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.meter-title { font-family: var(--font-display); font-size: 14px; font-weight: 600; color: var(--text); }
.meter-sub { font-family: var(--font-mono); font-size: 11px; color: var(--text-faint); }
.meter {
  height: 10px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.5s cubic-bezier(0.16, 1, 0.3, 1), background 0.5s;
}
.meter-fill.ok { background: var(--ok); }
.meter-fill.warn { background: var(--warn); }
.meter-fill.bad { background: var(--down); }
.mono-list { display: flex; flex-direction: column; gap: 8px; margin: 18px 0; }
.mono-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
}
.mono-item .k { color: var(--text-faint); }
.mono-item .v { color: var(--text); text-align: right; word-break: break-word; }

/* Reset code recipients */
.btn-count {
  margin-left: 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-faint);
}

.panel {
  width: min(440px, calc(100vw - 32px));
  padding: 0;
  margin: auto;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}
.panel[open] { animation: panel-in 0.22s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes panel-in {
  from { opacity: 0; transform: translateY(10px) scale(0.96); }
  to { opacity: 1; transform: none; }
}
.panel::backdrop {
  background: rgba(6, 12, 24, 0.66);
  backdrop-filter: blur(3px);
  animation: backdrop-in 0.22s ease;
}
@keyframes backdrop-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 22px 14px;
  border-bottom: 1px solid var(--line);
}
.panel-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.panel-sub { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.panel-close {
  background: transparent;
  border: none;
  color: var(--text-faint);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}
.panel-close:hover { color: var(--text); background: var(--surface-2); }
.panel .recipients-card {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 18px 22px 22px;
}
.recipients-count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  margin-bottom: 12px;
}
.recipient-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}
.recipient-list:empty { display: none; }
.recipient-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  padding: 7px 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.recipient-remove {
  background: transparent;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
}
.recipient-remove:hover { color: var(--down); background: rgba(240, 97, 109, 0.12); }
.recipient-add { display: flex; gap: 8px; }
.recipient-add input {
  flex: 1;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: var(--font-body);
}
.recipient-add input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79, 209, 180, 0.15); }
.recipients-card .card-error { margin-top: 10px; margin-bottom: 0; }

/* Footer */
.footer {
  border-top: 1px solid var(--line);
  padding: 18px 0;
  font-size: 12px;
  color: var(--text-faint);
  text-align: center;
  margin-top: 48px;
}
.footer a { color: var(--accent); text-decoration: none; }
.footer a:hover { text-decoration: underline; }

/* Auth pages */.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 32px;
}
.brand-row { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; }
.brand-word { font-family: var(--font-display); font-size: 16px; font-weight: 700; color: var(--text); }
.brand-word em { font-style: normal; color: var(--text-dim); font-weight: 500; }
.auth-title { font-family: var(--font-display); font-size: 22px; font-weight: 600; }
.auth-sub { font-size: 13px; color: var(--text-dim); margin: 6px 0 22px; }
.auth-form { display: flex; flex-direction: column; gap: 6px; }
.auth-form label { font-size: 12px; font-weight: 500; color: var(--text-dim); }
.auth-form input {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 11px;
  font-size: 14px;
  margin-bottom: 14px;
  font-family: var(--font-body);
}
.auth-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79, 209, 180, 0.15); }
.field-wrap { position: relative; margin-bottom: 14px; }
.field-wrap input { width: 100%; padding-right: 40px; margin-bottom: 0; }
.field-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  pointer-events: none;
  line-height: 0;
}
.field-icon svg { width: 16px; height: 16px; }
.field-icon + input { padding-left: 34px; }
.pw-toggle {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-faint);
  line-height: 0;
}
.pw-toggle:hover { color: var(--text-dim); }
.pw-toggle svg { width: 18px; height: 18px; }
.pw-toggle .icon-off { display: none; }
.pw-toggle.is-open .icon-on { display: none; }
.pw-toggle.is-open .icon-off { display: inline; }
.primary-btn {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  color: #06121a;
  background: var(--accent);
  border: none;
  border-radius: 6px;
  padding: 10px 12px;
  cursor: pointer;
  margin-top: 4px;
  transition: background 0.15s;
}
.primary-btn:hover { background: #6ae0c5; }
.auth-error {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--down);
  margin-bottom: 6px;
}
.auth-error.ok { color: var(--ok); }
.auth-info { font-size: 13px; color: var(--text-dim); margin-bottom: 18px; line-height: 1.5; }
.auth-info span { color: var(--text); }
.auth-link {
  display: inline-block;
  margin-top: 20px;
  font-size: 13px;
  color: var(--text-dim);
  text-decoration: none;
}
.auth-link:hover { color: var(--accent); }

@media (max-width: 560px) {
  .strip-meta { display: none; }
  .category-phrase { display: none; }
  .topbar-inner { padding: 12px 16px; }
  .wrap { padding: 0 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .brand-dot, .card, .panel, .panel::backdrop { animation: none; transition: none; }
}
