:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --status-good: #0ca30c;
  --status-critical: #d03b3b;
  --status-good-bg: rgba(12, 163, 12, 0.10);
  --status-critical-bg: rgba(208, 59, 59, 0.10);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-2: #d95926;
    --status-good: #0ca30c;
    --status-critical: #e66767;
    --status-good-bg: rgba(12, 163, 12, 0.16);
    --status-critical-bg: rgba(230, 103, 103, 0.16);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5;
  --series-2: #d95926;
  --status-good: #0ca30c;
  --status-critical: #e66767;
  --status-good-bg: rgba(12, 163, 12, 0.16);
  --status-critical-bg: rgba(230, 103, 103, 0.16);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--series-1); flex-shrink: 0; }

.btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-primary);
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { background: var(--gridline); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
  padding: 20px 20px 16px;
}
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; padding: 8px 12px; flex: 1; }
.sidebar-nav a {
  display: block;
  padding: 9px 12px;
  border-radius: 7px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
}
.sidebar-nav a:hover { background: var(--gridline); color: var(--text-primary); }
.sidebar-nav a.active { background: var(--series-1); color: #ffffff; }
.sidebar-nav a.admin-only { display: none; }

.sidebar-footer {
  padding: 14px 16px 18px;
  border-top: 1px solid var(--border);
}
.sidebar-user {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main-area { flex: 1; min-width: 0; }

.topbar {
  display: flex;
  align-items: center;
  padding: 18px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 600; }

.container { max-width: 1100px; padding: 28px 32px 64px; }

@media (max-width: 860px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; flex-wrap: wrap; }
  .sidebar-brand { padding: 14px 16px; }
  .sidebar-nav { flex-direction: row; flex-wrap: wrap; padding: 0 12px; }
  .sidebar-footer { border-top: none; padding: 10px 16px; display: flex; align-items: center; gap: 10px; }
  .sidebar-user { margin-bottom: 0; }
  .container { padding: 20px 16px 48px; }
  .topbar { padding: 16px; }
}

.summary-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}
.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
}
.stat-tile .label { font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.stat-tile .value { font-size: 28px; font-weight: 600; }

.group-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 24px 0 10px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
}

.btn-primary {
  background: var(--series-1);
  border-color: var(--series-1);
  color: #ffffff;
  font-weight: 600;
}
.btn-primary:hover { background: var(--series-1); opacity: 0.9; }

.host-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 10px;
  display: grid;
  grid-template-columns: 1fr auto auto auto 140px auto;
  align-items: center;
  gap: 18px;
}
@media (max-width: 780px) {
  .host-card { grid-template-columns: 1fr; }
}

.host-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}
.icon-btn:hover { background: var(--gridline); color: var(--text-primary); }

.host-name-block .name { font-weight: 600; font-size: 14px; }
.host-name-block .ip { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.status-badge.up { color: var(--status-good); background: var(--status-good-bg); }
.status-badge.down { color: var(--status-critical); background: var(--status-critical-bg); }
.status-badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.host-card.is-down { border-color: rgba(208, 59, 59, 0.35); }
.down-detail {
  font-size: 11px;
  color: var(--status-critical);
  margin-top: 5px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cause-cell {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-secondary);
}

.uptime-col { text-align: right; font-size: 12px; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.uptime-col .num { font-size: 15px; font-weight: 600; color: var(--text-primary); display: block; }

.latency-col { text-align: right; font-size: 12px; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.latency-col .num { font-size: 15px; font-weight: 600; color: var(--text-primary); display: block; }

.spark { display: block; }
.spark line.baseline { stroke: var(--gridline); stroke-width: 1; }

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px 30px;
  width: 320px;
}
.login-card h1 { font-size: 17px; margin: 0 0 4px; }
.login-card p { font-size: 13px; color: var(--text-secondary); margin: 0 0 20px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.field input {
  width: 100%;
  padding: 9px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--page);
  color: var(--text-primary);
  font-size: 14px;
}
.field input:focus { outline: 2px solid var(--series-1); outline-offset: 1px; }
.login-btn {
  width: 100%;
  padding: 10px;
  border-radius: 6px;
  border: none;
  background: var(--series-1);
  color: white;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
}
.login-error {
  font-size: 12px;
  color: var(--status-critical);
  margin-top: 10px;
  min-height: 16px;
}

.admin-panel {
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--gridline);
  font-size: 13px;
}
.role-tag {
  font-size: 11px;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 1px 8px;
  border-radius: 999px;
}
.add-user-form {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.add-user-form input, .add-user-form select {
  padding: 7px 9px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--page);
  color: var(--text-primary);
  font-size: 13px;
}

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(11, 11, 11, 0.45);
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 420px;
  padding: 24px 26px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.modal-header h2 { font-size: 16px; margin: 0; }
.modal-close {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 4px;
}
.modal-close:hover { color: var(--text-primary); }

.field-checkbox label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
}
.field-checkbox input { width: 15px; height: 15px; }

.modal-error {
  font-size: 12px;
  color: var(--status-critical);
  min-height: 16px;
  margin-bottom: 4px;
}

.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.host-name-block a { color: var(--text-primary); text-decoration: none; }
.host-name-block a:hover .name { text-decoration: underline; }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 22px;
  margin-bottom: 18px;
}

.breadcrumb {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 18px;
}
.breadcrumb a { color: var(--series-1); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  flex-wrap: wrap;
  gap: 12px;
}
.detail-header h2 { margin: 0 0 4px; font-size: 20px; }
.detail-header .ip { font-size: 13px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.range-tabs { display: flex; gap: 4px; background: var(--page); border: 1px solid var(--border); border-radius: 8px; padding: 3px; }
.range-tabs button {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.range-tabs button.active { background: var(--surface-1); color: var(--text-primary); box-shadow: 0 1px 2px rgba(0,0,0,0.08); }

.linechart { display: block; width: 100%; height: auto; }
.linechart .baseline { stroke: var(--gridline); stroke-width: 1; }
.linechart .gridline { stroke: var(--gridline); stroke-width: 1; }
.linechart .axis-label { fill: var(--text-muted); font-size: 10px; }
.linechart .down-band { fill: var(--status-critical); opacity: 0.08; }

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0 10px 10px;
  border-bottom: 1px solid var(--border);
}
.table td { padding: 11px 10px; border-bottom: 1px solid var(--gridline); font-variant-numeric: tabular-nums; }
.table tr:last-child td { border-bottom: none; }
.table td.num { text-align: right; }

.empty-state { color: var(--text-muted); font-size: 13px; padding: 24px 0; text-align: center; }

.filter-row { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.filter-row select {
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  font-size: 13px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--gridline);
}
.toggle-row:last-child { border-bottom: none; }
.toggle-row .label { font-size: 13px; font-weight: 500; }
.toggle-row .hint { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--gridline); border-radius: 999px; transition: 0.15s;
}
.switch .slider::before {
  content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px;
  background: var(--surface-1); border-radius: 50%; transition: 0.15s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.switch input:checked + .slider { background: var(--series-1); }
.switch input:checked + .slider::before { transform: translateX(18px); }

.settings-form .field input[type="text"],
.settings-form .field input[type="url"] { width: 100%; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.save-row { display: flex; align-items: center; gap: 10px; margin-top: 18px; }
.save-msg { font-size: 12px; color: var(--status-good); }
.save-msg.error { color: var(--status-critical); }

.ddos-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--status-critical-bg);
  color: var(--status-critical);
  border-bottom: 1px solid rgba(208, 59, 59, 0.3);
  padding: 10px 32px;
  font-size: 13px;
  font-weight: 600;
}
.ddos-banner a { color: inherit; text-decoration: underline; }

.field-divider { border-top: 1px solid var(--gridline); margin: 16px 0 14px; }
.field-label-row { font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 8px; }

.code-block {
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--text-primary);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 6px 0 12px;
}

.alert-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  color: var(--status-critical);
  background: var(--status-critical-bg);
}

.port-table-wrap { max-height: 320px; overflow-y: auto; }
.threat-row td { color: var(--status-critical); font-weight: 600; }

.bw-legend { display: flex; gap: 16px; font-size: 12px; color: var(--text-secondary); margin-bottom: 10px; }
.bw-legend span { display: inline-flex; align-items: center; gap: 6px; }
.bw-legend .swatch { width: 10px; height: 10px; border-radius: 2px; }
