/* Server Monitor UI
   Dense, dark, system-font interface for operational monitoring. */

:root {
  color-scheme: dark;

  --bg-void: #0a0b0d;
  --bg-base: #0f1115;
  --bg-surface: #171a21;
  --bg-surface-hover: #1d222b;
  --bg-elevated: #222733;
  --bg-inset: #0c0e12;
  --bg-input: #11141a;
  --bg-overlay: rgba(8, 9, 11, 0.78);

  --text-primary: #f1f5f9;
  --text-secondary: #aab4c3;
  --text-muted: #6f7a8a;
  --text-on-accent: #07100e;
  --text-link: #37d7bf;

  --border-default: #2a303b;
  --border-subtle: #202631;
  --border-focus: #37d7bf;
  --border-error: #ff5d73;
  --border-highlight: rgba(255, 255, 255, 0.06);

  --accent: #37d7bf;
  --accent-hover: #54e2cf;
  --accent-muted: rgba(55, 215, 191, 0.12);

  --status-ok: #34d399;
  --status-ok-muted: rgba(52, 211, 153, 0.12);
  --status-warn: #fbbf24;
  --status-warn-muted: rgba(251, 191, 36, 0.12);
  --status-critical: #fb5b72;
  --status-critical-muted: rgba(251, 91, 114, 0.12);
  --status-neutral: #7b8495;

  --bar-track: #090b0f;
  --bar-normal: #37d7bf;
  --bar-elevated: #8b9cff;
  --bar-warn: #fbbf24;
  --bar-critical: #fb5b72;

  --color-ok: var(--status-ok);
  --color-ok-subtle: var(--status-ok-muted);
  --color-warn: var(--status-warn);
  --color-warn-subtle: var(--status-warn-muted);
  --color-critical: var(--status-critical);
  --color-critical-subtle: var(--status-critical-muted);
  --color-waiting: var(--status-neutral);
  --color-accent: var(--accent);
  --color-accent-hover: var(--accent-hover);
  --color-accent-subtle: var(--accent-muted);
  --bar-ok: var(--bar-normal);
  --bg-surface-elevated: var(--bg-elevated);

  --font-sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  --font-display: var(--font-sans);
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", ui-monospace, monospace;

  --nav-height: 56px;
  --page-padding: 24px;
  --card-padding: 16px;
  --card-gap: 16px;

  --radius-sm: 6px;
  --radius-md: 8px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.28);
  --shadow-md: 0 10px 24px rgba(0, 0, 0, 0.28);
  --shadow-focus: 0 0 0 3px rgba(55, 215, 191, 0.22);
}

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

html {
  font-size: 14px;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-sans);
  line-height: 1.45;
  letter-spacing: 0;
}

a {
  color: var(--text-link);
  text-decoration: none;
}

a:hover {
  color: var(--accent-hover);
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-muted,
.muted { color: var(--text-muted); }
.ml-1 { margin-left: 4px; }
.ml-2 { margin-left: 8px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.hidden { display: none !important; }

.nav {
  position: sticky;
  top: 0;
  z-index: 200;
  height: var(--nav-height);
  background: rgba(18, 21, 27, 0.96);
  border-bottom: 1px solid var(--border-default);
  backdrop-filter: blur(10px);
}

.nav-inner {
  max-width: 1440px;
  height: 100%;
  margin: 0 auto;
  padding: 0 var(--page-padding);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.nav-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--text-primary);
  font-weight: 760;
  font-size: 19px;
}

.nav-brand:hover {
  color: var(--text-primary);
}

.nav-brand-icon {
  color: var(--accent);
  font-size: 15px;
  line-height: 1;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 11px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
}

.nav-link:hover,
.nav-link.active {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.nav-link-primary {
  margin-left: 4px;
  background: var(--accent);
  color: var(--text-on-accent) !important;
  border: 1px solid var(--accent);
}

.nav-link-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: var(--text-on-accent) !important;
}

.main {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px var(--page-padding) 40px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.page-header-left,
.page-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.page-title {
  margin: 0;
  color: var(--text-primary);
  font-size: 20px;
  font-weight: 760;
  line-height: 1.2;
}

.page-subtitle {
  color: var(--text-secondary);
  font-size: 13px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease, transform 120ms ease;
}

.btn:hover {
  text-decoration: none;
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible,
.form-input:focus,
.settings-section input:focus,
.settings-section select:focus,
.settings-section textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: var(--shadow-focus);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--text-on-accent);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: var(--text-on-accent);
}

.btn-secondary {
  background: var(--bg-elevated);
  border-color: var(--border-default);
  color: var(--text-secondary);
}

.btn-secondary:hover {
  background: #2a303d;
  color: var(--text-primary);
}

.btn:disabled,
.btn:disabled:hover {
  cursor: not-allowed;
  opacity: 0.55;
}

.btn-danger {
  background: transparent;
  border-color: rgba(251, 91, 114, 0.45);
  color: var(--status-critical);
}

.btn-danger:hover {
  background: var(--status-critical-muted);
  border-color: var(--status-critical);
}

.btn-sm {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.btn-full {
  width: 100%;
}

.server-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: var(--card-gap);
}

.server-card {
  min-height: 154px;
  padding: var(--card-padding);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
  transition: background-color 120ms ease, border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}

.server-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: transparent;
}

.server-card.status-stale::before { background: var(--status-warn); }
.server-card.status-offline::before { background: var(--status-critical); }
.server-card.status-waiting::before { background: var(--status-neutral); }

.server-card.status-offline {
  background: linear-gradient(90deg, rgba(251, 91, 114, 0.09), var(--bg-surface) 48%);
}

.server-card:hover {
  background: var(--bg-surface-hover);
  border-color: #394151;
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.server-card[data-href] {
  cursor: pointer;
}

.server-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}

.server-card-name {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  font-size: 15px;
  font-weight: 760;
}

.server-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.server-card-lastseen {
  margin-bottom: 12px;
  color: var(--text-muted);
  font-size: 12px;
}

.server-card-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 14px;
}

.metric-mini {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto auto;
  align-items: center;
  gap: 4px 8px;
  min-width: 0;
}

.metric-mini-label {
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 700;
}

.metric-mini-value {
  grid-column: 2;
  grid-row: 1;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.metric-mini .progress-bar-track {
  grid-column: 1 / -1;
  grid-row: 2;
  width: 100%;
  min-width: 0;
}

.server-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: 11px;
}

.card-footer-net,
.card-footer-containers {
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-footer-net {
  font-family: var(--font-mono);
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: var(--status-neutral);
}

.status-dot-online,
.status-dot-docker-running { background: var(--status-ok); }
.status-dot-stale,
.status-dot-docker-restarting { background: var(--status-warn); }
.status-dot-offline,
.status-dot-docker-exited,
.status-dot-docker-stopped,
.status-dot-docker-unhealthy { background: var(--status-critical); }
.status-dot-waiting { background: var(--status-neutral); }

.status-dot-online,
.status-dot-docker-running {
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.12);
}

.status-dot-offline,
.status-dot-docker-unhealthy {
  box-shadow: 0 0 0 3px rgba(251, 91, 114, 0.12);
}

.status-badge,
[class^="badge-"] {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.badge-online,
.status-badge-online { background: var(--status-ok-muted); color: var(--status-ok); }
.badge-stale,
.status-badge-stale { background: var(--status-warn-muted); color: var(--status-warn); }
.badge-offline,
.status-badge-offline { background: var(--status-critical-muted); color: var(--status-critical); }
.badge-waiting,
.status-badge-waiting { background: rgba(123, 132, 149, 0.14); color: var(--text-secondary); }
.badge-warn,
.badge-alert { background: var(--status-warn-muted); color: var(--status-warn); }
.badge-alert { min-height: 20px; padding: 0 7px; }

.progress-bar-track,
.stat-box-bar {
  height: 7px;
  background: var(--bar-track);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar-fill,
.stat-box-bar-fill {
  height: 100%;
  min-width: 2px;
  border-radius: 999px;
  transition: width 220ms ease, background-color 220ms ease;
}

.threshold-ok,
.progress-bar-fill.threshold-ok,
.stat-box-bar-fill.threshold-ok { color: var(--bar-normal); }
.threshold-elevated,
.progress-bar-fill.threshold-elevated,
.stat-box-bar-fill.threshold-elevated { color: var(--bar-elevated); }
.threshold-warn,
.progress-bar-fill.threshold-warn,
.stat-box-bar-fill.threshold-warn { color: var(--bar-warn); }
.threshold-critical,
.progress-bar-fill.threshold-critical,
.stat-box-bar-fill.threshold-critical { color: var(--bar-critical); }

.progress-bar-fill.threshold-ok,
.stat-box-bar-fill.threshold-ok { background: var(--bar-normal); }
.progress-bar-fill.threshold-elevated,
.stat-box-bar-fill.threshold-elevated { background: var(--bar-elevated); }
.progress-bar-fill.threshold-warn,
.stat-box-bar-fill.threshold-warn { background: var(--bar-warn); }
.progress-bar-fill.threshold-critical,
.stat-box-bar-fill.threshold-critical { background: var(--bar-critical); }

@keyframes bar-pulse-critical {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.72; }
}

.progress-bar-fill.pulse-critical,
.stat-box-bar-fill.pulse-critical {
  animation: bar-pulse-critical 1.4s ease-in-out infinite;
}

.empty-state {
  display: grid;
  place-items: center;
  gap: 10px;
  min-height: 320px;
  padding: 44px 20px;
  border: 1px dashed var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  text-align: center;
}

.empty-state-icon {
  color: var(--accent);
  font-size: 28px;
}

.empty-state-title {
  margin: 0;
  font-size: 18px;
}

.empty-state-desc {
  margin: 0 0 8px;
  color: var(--text-secondary);
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  margin-bottom: 18px;
  color: var(--text-secondary);
  font-size: 13px;
}

.breadcrumb-link {
  color: var(--text-secondary);
}

.breadcrumb-link:hover {
  color: var(--accent);
}

.breadcrumb-sep {
  color: var(--text-muted);
}

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border-default);
  overflow-x: auto;
}

.tab {
  min-height: 38px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.tab:hover {
  color: var(--text-primary);
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat-box {
  min-height: 112px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
}

.stat-box-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.stat-box-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 800;
}

.stat-box-trend {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
}

.stat-box-trend.trend-up { color: var(--status-warn); }
.stat-box-trend.trend-down { color: var(--status-ok); }

.stat-box-value {
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 34px;
  font-weight: 760;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.stat-box-sub {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.35;
}

.sparkline-section {
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--border-subtle);
}

.sparkline-canvas {
  display: block;
  width: 100%;
  height: 26px;
}

.sparkline-empty {
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 11px;
}

.core-grid {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.core-entry {
  display: grid;
  grid-template-columns: 30px minmax(70px, 1fr) 50px;
  gap: 8px;
  align-items: center;
}

.core-label,
.core-value {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
}

.core-value {
  text-align: right;
}

.core-entry .progress-bar-track {
  height: 5px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 18px 0 10px;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 760;
}

.section-header-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-header h3 {
  margin: 0;
  font-size: 14px;
}

.data-table,
.info-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th,
.info-table th {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border-default);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 800;
  text-align: left;
}

.data-table td,
.info-table td {
  padding: 10px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  vertical-align: middle;
}

.data-table tr:last-child td,
.info-table tr:last-child td {
  border-bottom: none;
}

.info-table td:first-child {
  width: 170px;
  color: var(--text-muted);
}

.docker-row.docker-exited td,
.docker-row.docker-stopped td,
.port-local td {
  color: var(--text-muted);
}

.docker-row.docker-unhealthy {
  background: var(--status-critical-muted);
}

.docker-summary {
  margin-bottom: 10px;
  color: var(--text-secondary);
  font-size: 13px;
}

.docker-divider td {
  height: 1px !important;
  padding: 0 !important;
  border-bottom: 1px dashed var(--border-default) !important;
}

.port-public { color: var(--text-primary); }
.port-local { color: var(--text-muted); }
.exposure-dot-public { color: var(--status-critical); font-size: 8px; }
.exposure-dot-local { color: var(--status-neutral); font-size: 8px; }

.form-container {
  display: flex;
  justify-content: center;
  padding: 12px 0;
}

.form-card,
.settings-section,
.alert-form,
.chart-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.form-card {
  width: 100%;
  max-width: 520px;
  padding: 22px;
}

.form-title {
  margin: 0 0 18px;
  font-size: 20px;
  font-weight: 760;
}

.form-group {
  margin-bottom: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.form-label,
.form-group > label,
.settings-section label[for] {
  display: block;
  margin-bottom: 6px;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 760;
}

.required { color: var(--status-critical); }
.optional {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
}

.form-input,
.settings-section input[type="text"],
.settings-section input[type="password"],
.settings-section input[type="number"],
.settings-section input[type="email"],
.settings-section select,
.settings-section textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  transition: border-color 120ms ease, box-shadow 120ms ease, background-color 120ms ease;
}

.form-input::placeholder,
.settings-section input::placeholder,
.settings-section textarea::placeholder {
  color: #818a99;
}

.form-input:hover,
.settings-section input[type="text"]:hover,
.settings-section input[type="password"]:hover,
.settings-section input[type="number"]:hover,
.settings-section input[type="email"]:hover,
.settings-section select:hover,
.settings-section textarea:hover {
  border-color: #3a4250;
}

.form-hint,
.settings-section p.text-muted {
  display: block;
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 12px;
}

.form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.alert,
.alert-success {
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 13px;
}

.alert-error {
  background: var(--status-critical-muted);
  border: 1px solid rgba(251, 91, 114, 0.45);
  color: var(--status-critical);
}

.alert-success {
  background: var(--status-ok-muted);
  border: 1px solid rgba(52, 211, 153, 0.45);
  color: var(--status-ok);
}

.token-section,
.install-section {
  margin: 16px 0;
}

.token-label,
.install-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  color: var(--text-secondary);
  font-size: 12px;
}

.token-box,
.install-cmd {
  background: var(--bg-inset);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
}

.token-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
}

.token-value {
  flex: 1;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 13px;
  word-break: break-all;
}

.install-cmd {
  padding: 12px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 12px;
  overflow-x: auto;
  white-space: pre;
}

.settings-page-header {
  margin-bottom: 16px;
}

.settings-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.settings-summary-card {
  min-height: 92px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
}

.settings-summary-label,
.settings-summary-note {
  color: var(--text-muted);
  font-size: 12px;
}

.settings-summary-card strong {
  color: var(--text-primary);
  font-size: 20px;
  font-weight: 760;
}

.settings-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 16px;
  align-items: start;
  margin-bottom: 16px;
}

.settings-notification-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.settings-sidebar {
  display: grid;
  gap: 16px;
}

.settings-section {
  max-width: none;
  margin: 0;
  padding: 20px;
}

.detail-section-stack {
  display: grid;
  gap: 22px;
}

.detail-settings-stack {
  max-width: 920px;
}

.settings-section-primary {
  min-height: 100%;
}

.settings-section-compact {
  padding: 18px;
}

.settings-section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.settings-section-header h2 {
  margin: 0;
  color: var(--text-primary);
  font-size: 18px;
  font-weight: 760;
}

.settings-section-header p {
  margin: 5px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}

.settings-section h3 {
  margin: 0;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 760;
}

.settings-block {
  padding-top: 18px;
  margin-top: 18px;
  border-top: 1px solid var(--border-subtle);
}

.settings-block:first-of-type {
  padding-top: 0;
  margin-top: 0;
  border-top: none;
}

.settings-block-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.settings-block-heading span {
  color: var(--text-muted);
  font-size: 12px;
}

.settings-option-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.settings-option,
.settings-toggle {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 13px;
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  cursor: pointer;
}

.settings-option:hover,
.settings-toggle:hover,
.settings-choice:hover {
  border-color: #3a4250;
  background: #141820;
}

.settings-option input,
.settings-toggle input,
.settings-choice input {
  width: 16px;
  height: 16px;
  margin-top: 2px;
  accent-color: var(--accent);
  flex: 0 0 auto;
}

.settings-option span,
.settings-toggle span {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.settings-option strong,
.settings-toggle strong,
.settings-choice span {
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 760;
}

.settings-option small,
.settings-toggle small {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.35;
}

.settings-choice-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.settings-choice {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.notification-card {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.notification-card > form {
  margin-bottom: 16px;
}

.notification-header {
  align-items: center;
}

.settings-status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  color: var(--text-secondary);
  background: rgba(123, 132, 149, 0.14);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.settings-status-pill.is-enabled {
  background: var(--status-ok-muted);
  color: var(--status-ok);
}

.settings-status-pill.is-disabled {
  background: rgba(123, 132, 149, 0.14);
  color: var(--text-muted);
}

.settings-status-pill.is-online {
  background: var(--status-ok-muted);
  color: var(--status-ok);
}

.settings-status-pill.is-stale {
  background: var(--status-warn-muted);
  color: var(--status-warn);
}

.settings-status-pill.is-offline {
  background: rgba(255, 77, 106, 0.12);
  color: var(--status-critical);
}

.settings-status-pill.is-waiting {
  background: rgba(123, 132, 149, 0.14);
  color: var(--text-muted);
}

.availability-section {
  display: grid;
  gap: 18px;
}

.availability-section > form {
  margin: 0;
}

.availability-summary-grid,
.availability-result-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.availability-result-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
}

.availability-summary-item {
  min-height: 88px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.availability-summary-item span {
  color: var(--text-muted);
  font-size: 12px;
}

.availability-summary-item strong {
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 760;
}

.availability-result-block {
  display: grid;
  gap: 10px;
}

.availability-result-block h3 {
  color: var(--text-primary);
}

.availability-table {
  width: 100%;
  cursor: default;
}

.availability-table td:first-child {
  min-width: 150px;
}

.availability-toggle {
  margin: 0;
}

.availability-empty {
  padding: 18px;
  text-align: left;
}

.settings-meta-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: -4px 0 16px;
}

.settings-meta-row span {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: 11px;
}

.settings-toggle {
  margin-bottom: 16px;
}

.form-group-full {
  grid-column: 1 / -1;
}

.settings-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding-top: 16px;
  margin-top: auto;
  border-top: 1px solid var(--border-subtle);
}

.settings-last-status {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.35;
}

.settings-inline-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.checkbox-group,
.radio-group {
  display: grid;
  gap: 10px;
  margin: 14px 0;
}

.checkbox-label,
.radio-label {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  width: fit-content;
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
}

.checkbox-label input,
.radio-label input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.danger-zone {
  border-color: rgba(251, 91, 114, 0.35);
}

.danger-zone h3 {
  color: var(--status-critical);
}

.error-page {
  padding: 80px 20px;
  text-align: center;
}

.error-code {
  margin-bottom: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 72px;
  font-weight: 800;
  line-height: 1;
}

.error-message {
  margin-bottom: 24px;
  color: var(--text-secondary);
  font-size: 18px;
}

.empty-section {
  padding: 16px;
  border: 1px dashed var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 13px;
}

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg-void);
}

.login-container {
  width: 100%;
  max-width: 410px;
  padding: 24px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 22px;
}

.login-title {
  margin: 0 0 18px;
  font-size: 22px;
}

.login-subtitle {
  margin: -8px 0 18px;
  color: var(--text-muted);
}

.login-error {
  padding: 10px 12px;
  margin-bottom: 16px;
  background: var(--status-critical-muted);
  border: 1px solid rgba(251, 91, 114, 0.45);
  border-radius: var(--radius-sm);
  color: var(--status-critical);
  font-size: 13px;
}

.charts-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.charts-label {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 760;
}

.charts-window-btns {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.charts-window-btns .btn {
  background: var(--bg-elevated);
  border-color: var(--border-default);
  color: var(--text-secondary);
}

.charts-window-btns .btn.active {
  background: var(--accent-muted);
  border-color: rgba(55, 215, 191, 0.55);
  color: var(--accent);
}

.chart-panel {
  position: relative;
  padding: 16px;
  margin-bottom: 16px;
  overflow: hidden;
}

.chart-title {
  margin-bottom: 12px;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 760;
}

.chart-loading {
  height: 250px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.chart-loading-spinner,
.sse-banner-spinner,
.tab-refresh-spinner {
  border-style: solid;
  border-color: var(--border-default);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.chart-loading-spinner {
  width: 20px;
  height: 20px;
  border-width: 2px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.alert-form {
  padding: 16px;
  margin-bottom: 16px;
}

.form-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.form-row .form-input {
  width: auto;
  min-height: 34px;
}

.drag-handle {
  color: var(--text-muted);
  cursor: grab;
  font-size: 14px;
  opacity: 0.65;
  user-select: none;
}

.drag-handle:hover {
  opacity: 1;
}

.stat-panel {
  transition: opacity 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
}

.stat-panel.dragging {
  opacity: 0.55;
  box-shadow: var(--shadow-md);
}

.stat-panel[draggable="true"] {
  cursor: default;
}

@keyframes value-flash {
  0% { color: var(--text-primary); }
  30% { color: var(--accent); }
  100% { color: var(--text-primary); }
}

.value-updated {
  animation: value-flash 200ms linear forwards;
}

.sse-banner {
  position: fixed;
  left: 50%;
  bottom: 16px;
  z-index: 400;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border: 1px solid var(--status-warn);
  border-radius: var(--radius-sm);
  background: #1f1a12;
  color: var(--status-warn);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(8px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.sse-banner.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.sse-banner[data-state="degraded"] {
  border-color: var(--status-critical);
  background: #23151a;
  color: var(--status-critical);
}

.sse-banner-spinner {
  width: 14px;
  height: 14px;
  border-width: 2px;
  flex: 0 0 auto;
}

.skeleton {
  background: linear-gradient(90deg, var(--bg-surface) 25%, var(--bg-elevated) 50%, var(--bg-surface) 75%);
  background-size: 200% 100%;
  border-radius: 4px;
  animation: skeleton-shimmer 1.5s infinite;
}

@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.server-card-skeleton {
  padding: var(--card-padding);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  pointer-events: none;
}

.skeleton-line {
  height: 12px;
  margin-bottom: 8px;
}

.skeleton-bar {
  height: 7px;
  margin-bottom: 6px;
}

.htmx-indicator {
  position: fixed;
  inset: 0 0 auto;
  height: 2px;
  z-index: 1000;
  background: var(--accent);
  opacity: 0;
  transition: opacity 160ms ease;
}

.htmx-request .htmx-indicator,
.htmx-indicator.htmx-request {
  opacity: 1;
}

.freshness-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  user-select: none;
}

.freshness-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--status-ok);
  flex: 0 0 auto;
}

.freshness-indicator[data-state="fresh"] .freshness-dot { background: var(--status-ok); }
.freshness-indicator[data-state="aging"] .freshness-dot { background: var(--status-warn); }
.freshness-indicator[data-state="stale"] .freshness-dot,
.freshness-indicator[data-state="disconnected"] .freshness-dot { background: var(--status-critical); }
.freshness-indicator[data-state="aging"] .freshness-text { color: var(--status-warn); }
.freshness-indicator[data-state="stale"] .freshness-text,
.freshness-indicator[data-state="disconnected"] .freshness-text { color: var(--status-critical); }

.chart-pause-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 10;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  background: var(--accent-muted);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 760;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}

.chart-panel.paused .chart-pause-badge {
  opacity: 1;
}

@keyframes chart-data-pulse {
  0% { border-left-color: var(--accent); }
  100% { border-left-color: var(--border-default); }
}

.chart-panel.data-arrived {
  animation: chart-data-pulse 600ms ease-out forwards;
}

.tab-refresh-status {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 18px;
  margin-bottom: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
}

.tab-refresh-spinner {
  width: 12px;
  height: 12px;
  border-width: 1.5px;
  opacity: 0;
  transition: opacity 150ms ease;
}

.tab-refresh-status.refreshing .tab-refresh-spinner {
  opacity: 1;
}

.tab-refresh-status.error .tab-refresh-text {
  color: var(--status-warn);
}

.uplot {
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

.uplot .u-title,
.uplot .u-label {
  color: var(--text-secondary);
}

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

@media (max-width: 1024px) {
  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .settings-layout,
  .settings-notification-grid,
  .availability-result-grid {
    grid-template-columns: 1fr;
  }

  .settings-sidebar {
    order: 2;
  }
}

@media (max-width: 760px) {
  :root {
    --page-padding: 16px;
  }

  .nav {
    height: auto;
  }

  .nav-inner {
    min-height: var(--nav-height);
    flex-wrap: wrap;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .nav-brand {
    font-size: 18px;
  }

  .nav-links {
    flex: 1 1 auto;
    justify-content: flex-end;
  }

  .nav-link {
    min-height: 32px;
    padding: 0 8px;
  }

  .page-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .page-header-left {
    flex-wrap: wrap;
  }

  .freshness-indicator {
    margin-left: 0;
  }

  .server-grid,
  .stat-grid {
    grid-template-columns: 1fr;
  }

  .settings-summary-grid,
  .settings-option-grid,
  .availability-summary-grid {
    grid-template-columns: 1fr;
  }

  .settings-block-heading,
  .settings-section-header,
  .settings-card-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .notification-header {
    align-items: flex-start;
  }

  .settings-choice-row,
  .settings-inline-actions,
  .settings-inline-actions form,
  .settings-inline-actions .btn {
    width: 100%;
  }

  .settings-choice {
    width: 100%;
  }

  .server-card {
    min-height: 0;
  }

  .tabs {
    margin-left: calc(var(--page-padding) * -1);
    margin-right: calc(var(--page-padding) * -1);
    padding-left: var(--page-padding);
    padding-right: var(--page-padding);
  }

  .form-card,
  .settings-section,
  .chart-panel,
  .stat-box {
    padding: 14px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-actions {
    justify-content: stretch;
  }

  .form-actions .btn,
  .form-actions form,
  .form-actions form .btn {
    width: 100%;
  }

  .data-table,
  .info-table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  .sparkline-section {
    display: none;
  }
}

@media (max-width: 420px) {
  .main {
    padding-top: 18px;
  }

  .nav-inner {
    gap: 8px;
  }

  .nav-brand-name {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .nav-link-primary {
    margin-left: 0;
  }
}
