:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f0f3f8;
  --border: #e2e7ef;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-contrast: #ffffff;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --fail: #b91c1c;
  --fail-bg: #fee2e2;
  --info-bg: #dbeafe;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .05);
  --radius: 12px;
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1120; --surface: #111a2e; --surface-2: #17223a; --border: #24314d;
    --text: #e5ecf6; --muted: #94a3b8; --primary: #3b82f6; --primary-hover: #60a5fa;
    --ok: #4ade80; --ok-bg: #12301f; --warn: #fbbf24; --warn-bg: #3a2c0b;
    --fail: #f87171; --fail-bg: #3b1515; --info-bg: #172a4d;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1120; --surface: #111a2e; --surface-2: #17223a; --border: #24314d;
  --text: #e5ecf6; --muted: #94a3b8; --primary: #3b82f6; --primary-hover: #60a5fa;
  --ok: #4ade80; --ok-bg: #12301f; --warn: #fbbf24; --warn-bg: #3a2c0b;
  --fail: #f87171; --fail-bg: #3b1515; --info-bg: #172a4d;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--primary); }
.mono { font-family: var(--mono); font-size: .92em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.1rem; }

/* ---------- layout ---------- */
.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: 1180px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; white-space: nowrap; }
.brand img { width: 28px; height: 28px; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  padding: 7px 12px; border-radius: 8px; color: var(--muted); text-decoration: none;
  white-space: nowrap; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--info-bg); color: var(--primary); }
.top-actions { display: flex; align-items: center; gap: 8px; }
.user-chip { color: var(--muted); font-size: .9rem; }
main { max-width: 1180px; margin: 0 auto; padding: 24px 16px 64px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 16px; }

@media (max-width: 960px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-2 { grid-template-columns: 1fr; } }
@media (max-width: 720px) {
  .topbar-inner { flex-wrap: wrap; gap: 8px; }
  .nav { order: 3; flex-basis: 100%; }
  .user-chip { display: none; }
  main { padding-top: 16px; }
}

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.hero { display: flex; gap: 20px; align-items: center; justify-content: space-between; flex-wrap: wrap; padding: 22px; }
.hero-ip { font-family: var(--mono); font-size: 1.7rem; font-weight: 600; word-break: break-all; }
.hero-meta { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.hero-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tile .label { color: var(--muted); font-size: .85rem; margin-bottom: 6px; }
.tile .value { font-size: 1.15rem; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.tile .sub { color: var(--muted); font-size: .85rem; margin-top: 4px; }

/* ---------- badges & dots ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: .82rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.fail { background: var(--fail-bg); color: var(--fail); }
.badge.info { background: var(--info-bg); color: var(--primary); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-bg); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-bg); }
.dot.fail { background: var(--fail); box-shadow: 0 0 0 3px var(--fail-bg); }

/* ---------- buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 550;
  cursor: pointer; transition: background .15s, border-color .15s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-contrast); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--fail); }
.btn.danger.solid { background: var(--fail); border-color: var(--fail); color: #fff; }
.btn.lg { padding: 12px 22px; font-size: 1.02rem; border-radius: 11px; }
.btn.sm { padding: 4px 10px; font-size: .85rem; border-radius: 7px; }
.btn.icon { padding: 6px 8px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn svg { width: 16px; height: 16px; }

label.field { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; font-weight: 550; }
input[type=text], input[type=password], select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 9px; padding: 9px 12px; width: 100%; min-width: 0;
}
input:focus, select:focus, .btn:focus-visible, .nav a:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--primary) 55%, transparent); outline-offset: 1px; border-color: var(--primary);
}
.form-row { display: grid; grid-template-columns: 2fr 1fr 2fr auto; gap: 12px; align-items: end; }
@media (max-width: 860px) { .form-row { grid-template-columns: 1fr 1fr; } .form-row .btn { grid-column: 1 / -1; } }
@media (max-width: 480px) { .form-row { grid-template-columns: 1fr; } }
.hint { font-size: .85rem; color: var(--muted); font-weight: 400; }
.alert { padding: 10px 14px; border-radius: 10px; font-size: .92rem; }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.fail { background: var(--fail-bg); color: var(--fail); }
.alert.info { background: var(--info-bg); color: var(--primary); }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; margin: 0 -18px -18px; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { text-align: left; padding: 11px 18px; border-top: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); }
td.actions { text-align: right; white-space: nowrap; }
.ip-cell { display: flex; align-items: center; gap: 6px; }
tr.mine td:first-child { box-shadow: inset 3px 0 0 var(--primary); }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }

@media (max-width: 720px) {
  table.responsive thead { display: none; }
  table.responsive tr { display: block; border-top: 1px solid var(--border); padding: 10px 16px; }
  table.responsive td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 4px 0; text-align: right; }
  table.responsive td::before { content: attr(data-label); color: var(--muted); font-size: .85rem; text-align: left; }
  table.responsive td.actions { justify-content: flex-end; padding-top: 8px; }
  table.responsive td.actions::before { content: none; }
  table.responsive td .ip-cell { justify-content: flex-end; }
}

/* ---------- lists ---------- */
.activity { list-style: none; margin: 0; padding: 0; }
.activity li { display: flex; gap: 12px; padding: 9px 0; border-top: 1px solid var(--border); font-size: .92rem; }
.activity li:first-child { border-top: 0; }
.activity .when { color: var(--muted); white-space: nowrap; font-size: .85rem; min-width: 92px; }
.activity .what { min-width: 0; overflow-wrap: anywhere; }

.checks { list-style: none; margin: 0; padding: 0; }
.checks li { display: flex; gap: 14px; align-items: flex-start; padding: 14px 0; border-top: 1px solid var(--border); }
.checks li:first-child { border-top: 0; }
.checks .dot { margin-top: 7px; }
.checks .name { font-weight: 600; }
.checks .detail { color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(2, 6, 23, .55); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
  width: 100%; max-width: 440px; padding: 22px; display: flex; flex-direction: column; gap: 14px;
  max-height: calc(100vh - 32px); overflow: auto;
}
.modal p { margin: 0; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.choice-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.choice {
  border: 1px solid var(--border); border-radius: 10px; padding: 12px; cursor: pointer; text-align: center;
  font-weight: 600; background: var(--surface); color: var(--text); font: inherit;
}
.choice:hover { background: var(--surface-2); }
.choice.selected { border-color: var(--primary); background: var(--info-bg); color: var(--primary); }

/* ---------- toasts ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary);
  border-radius: 10px; box-shadow: var(--shadow); padding: 11px 14px; font-size: .92rem;
  animation: toast-in .18s ease-out;
}
.toast.ok { border-left-color: var(--ok); }
.toast.fail { border-left-color: var(--fail); }
.toast.warn { border-left-color: var(--warn); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 16px; padding: 28px; }
.login-card .brand { justify-content: center; font-size: 1.15rem; }
.login-card .btn { width: 100%; }
.theme-corner { position: fixed; top: 12px; right: 12px; }

.pager { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
