:root {
  --bg: #0f172a;
  --panel: #111827;
  --panel-soft: #1f2937;
  --panel-elevated: #162133;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --primary: #38bdf8;
  --primary-soft: rgba(56, 189, 248, 0.16);
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --border: #334155;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, Arial, sans-serif;
  background: radial-gradient(circle at top, #162033 0%, var(--bg) 45%);
  color: var(--text);
}

a { color: var(--text); text-decoration: none; }
button, select, input {
  background: var(--panel-soft);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  transition: border-color 0.18s ease, background-color 0.18s ease, transform 0.18s ease;
}
button { cursor: pointer; }
.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #0ea5e9 0%, #0284c7 100%);
  color: white;
  border: 1px solid rgba(56, 189, 248, 0.65);
  border-radius: 8px;
  padding: 0.6rem 0.85rem;
  transition: border-color 0.18s ease, background-color 0.18s ease, transform 0.18s ease;
}
.button-link:hover { transform: translateY(-1px); }
.button-link.secondary-link {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
button:hover, select:hover, input:hover { border-color: #475569; }
button:hover { transform: translateY(-1px); }
button:not(.secondary) {
  background: linear-gradient(180deg, #0ea5e9 0%, #0284c7 100%);
  border-color: rgba(56, 189, 248, 0.65);
  color: white;
}
button.secondary { background: transparent; }
label { display: flex; flex-direction: column; gap: 0.35rem; color: var(--muted); font-size: 0.92rem; }

.eyebrow {
  margin: 0 0 0.45rem;
  color: #7dd3fc;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.76rem;
  font-weight: 700;
}

.layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: #020617;
  border-right: 1px solid var(--border);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.sidebar-brand {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid rgba(148,163,184,0.12);
}
.sidebar-brand h1 {
  margin: 0;
  font-size: 1.55rem;
}
.sidebar-intro {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.95rem;
}
.sidebar nav { display: flex; flex-direction: column; gap: 0.75rem; }
.sidebar nav a {
  padding: 0.8rem 0.95rem;
  border-radius: 10px;
  background: rgba(255,255,255,0.03);
  border: 1px solid transparent;
}
.sidebar nav a:hover {
  background: var(--primary-soft);
  border-color: rgba(56, 189, 248, 0.22);
}
.sidebar nav a.active {
  background: var(--primary-soft);
  border-color: rgba(56, 189, 248, 0.42);
  color: #e0f2fe;
  box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.12);
}
.content { padding: 2rem; }
.header-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.25rem; }
.header-row h2 {
  margin: 0;
  font-size: 2rem;
}
.header-row > div > p:last-child {
  margin: 0.45rem 0 0;
  color: var(--muted);
  line-height: 1.5;
}
.controls-inline { display: flex; gap: 0.75rem; }
.status-panel { display: flex; flex-direction: column; gap: 0.4rem; align-items: flex-end; }
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 0.9rem;
  font-weight: 600;
}
.status-badge.live, .status-badge.recent { border-color: rgba(34,197,94,0.45); color: #bbf7d0; }
.status-badge.stale { border-color: rgba(245,158,11,0.45); color: #fde68a; }
.status-badge.unknown { border-color: rgba(148,163,184,0.45); color: var(--muted); }
.status-detail, .section-note {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.4;
}
.page-intro {
  margin: -0.2rem 0 1.2rem;
  max-width: 72ch;
}
.grid { display: grid; gap: 1rem; }
.cards { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.two-col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.charts-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card {
  background: linear-gradient(180deg, var(--panel-elevated) 0%, var(--panel) 100%);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.15rem;
  box-shadow: 0 14px 34px rgba(0,0,0,0.22);
}
.stat-card {
  position: relative;
  overflow: hidden;
}
.stat-card::after {
  content: "";
  position: absolute;
  inset: auto -20px -20px auto;
  width: 90px;
  height: 90px;
  background: radial-gradient(circle, rgba(56,189,248,0.2), transparent 70%);
}
.chart-card canvas {
  display: block;
  width: 100%;
  min-height: 220px;
}
.card h3 { margin-top: 0; margin-bottom: 0.35rem; }
.card strong { display: block; font-size: 2rem; margin: 0.4rem 0; }
table { width: 100%; border-collapse: collapse; }
.table-wrap { width: 100%; overflow-x: auto; }
th, td { text-align: left; padding: 0.75rem 0.6rem; border-bottom: 1px solid rgba(148,163,184,0.15); vertical-align: top; }
th {
  color: #cbd5e1;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
tbody tr:hover { background: rgba(148,163,184,0.04); }
.action-group { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.loading-cell, .metric-unavailable { color: var(--muted); font-style: italic; }
.metric-value,
.loading-cell,
.metric-unavailable {
  display: block;
}
.metric-meta {
  display: block;
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.2;
}
.diagnostics-list { display: flex; flex-direction: column; gap: 0.75rem; }
.diagnostic { padding: 0.8rem 1rem; border-radius: 10px; border: 1px solid var(--border); }
.diagnostic.ok { border-color: rgba(34,197,94,0.4); color: #bbf7d0; }
.diagnostic.warning { border-color: rgba(245,158,11,0.4); color: #fde68a; }
.diagnostic.critical, .flash.error, .flash.flash-error { border-color: rgba(239,68,68,0.4); color: #fecaca; }
.section-heading {
  margin-bottom: 0.9rem;
}
.section-heading p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}
.section-heading.compact {
  margin-bottom: 0;
}
.terminal-box {
  background: #020617;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  min-height: 360px;
  overflow: auto;
  white-space: pre-wrap;
}
.panel-header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.facts { list-style: none; padding: 0; margin: 0; }
.facts li { padding: 0.45rem 0; border-bottom: 1px solid rgba(148,163,184,0.12); }
.flash-wrap { margin-bottom: 1rem; }
.flash { padding: 0.8rem 1rem; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 0.75rem; background: rgba(15,23,42,0.55); }
.flash.flash-info { border-color: rgba(56,189,248,0.4); color: #bae6fd; }
.flash.flash-success { border-color: rgba(34,197,94,0.4); color: #bbf7d0; }
.stack-form { display: flex; flex-direction: column; gap: 0.9rem; }
.smarttrade-admin-panel { display: grid; gap: 1rem; }
.smarttrade-admin-meta p { margin: 0 0 0.4rem; }
.smarttrade-admin-callout {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
}
.admin-user-page-card {
  padding: 1.5rem;
}
.admin-user-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(300px, 380px);
  gap: 1.5rem;
  align-items: start;
}
.admin-users-grid {
  align-items: start;
}
.admin-user-copy {
  display: grid;
  gap: 1rem;
}
.admin-user-form-shell {
  display: grid;
  gap: 1rem;
  justify-items: start;
}
.admin-actions-panel {
  width: 100%;
}
.admin-user-form {
  width: 100%;
  max-width: 320px;
  padding: 1rem;
  border: 1px solid rgba(148,163,184,0.16);
  border-radius: 14px;
  background: rgba(2, 6, 23, 0.45);
}
.compact-form label {
  font-size: 0.88rem;
}
.compact-input {
  max-width: 260px;
  padding: 0.5rem 0.7rem;
  font-size: 0.95rem;
}
.compact-actions {
  align-items: center;
}
.password-dialog {
  width: min(420px, calc(100vw - 2rem));
  margin: auto;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: linear-gradient(180deg, var(--panel-elevated) 0%, var(--panel) 100%);
  color: var(--text);
  box-shadow: 0 20px 44px rgba(0,0,0,0.35);
}
.password-dialog::backdrop {
  background: rgba(2, 6, 23, 0.72);
}
.password-dialog-form {
  padding: 1.15rem;
}
.password-dialog-actions {
  justify-content: flex-end;
}
.danger-zone-card {
  border-color: rgba(239,68,68,0.35);
  box-shadow: 0 14px 34px rgba(239,68,68,0.08);
}
.danger-zone-card .section-heading:first-child h3 {
  color: #fecaca;
}
.port-value {
  display: inline;
  font-size: 1rem;
  margin: 0;
}
.scope-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 0.84rem;
  font-weight: 600;
  white-space: nowrap;
}
.scope-badge.local {
  border-color: rgba(34,197,94,0.45);
  color: #bbf7d0;
}
.scope-badge.lan {
  border-color: rgba(245,158,11,0.45);
  color: #fde68a;
}
.scope-badge.internet {
  border-color: rgba(239,68,68,0.45);
  color: #fecaca;
}
.scope-badge.unknown {
  border-color: rgba(148,163,184,0.45);
  color: var(--muted);
}
.hidden { display: none; }

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.login-card {
  width: min(420px, 92vw);
  background: linear-gradient(180deg, var(--panel-elevated) 0%, var(--panel) 100%);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: 0 20px 44px rgba(0,0,0,0.28);
}
.login-card h1 {
  margin: 0;
}
.login-card > p:last-of-type {
  margin: -0.2rem 0 0.25rem;
  color: var(--muted);
  line-height: 1.5;
}
.login-card form { display: flex; flex-direction: column; gap: 1rem; }

@media (max-width: 1100px) {
  .cards, .charts-grid, .two-col { grid-template-columns: 1fr; }
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); }
  .status-panel { align-items: flex-start; }
  .content { padding: 1.25rem; }
}

@media (max-width: 720px) {
  .header-row,
  .panel-header,
  .controls-inline {
    flex-direction: column;
    align-items: stretch;
  }

  .smarttrade-admin-callout,
  .admin-user-layout {
    grid-template-columns: 1fr;
  }

  .admin-user-form {
    max-width: none;
  }

  .compact-input {
    max-width: none;
    width: 100%;
  }
}