/* ===========================================================================
   VPS Dashboard - design system
   Dark by default, light theme via [data-theme="light"] on <html>.
   No external CSS/font dependency: the panel must work on a locked-down VPS.
   =========================================================================== */

:root {
  --bg: #0b1017;
  --bg-alt: #111823;
  --surface: #151d2a;
  --surface-2: #1b2533;
  --surface-hover: #202b3c;
  --border: #253145;
  --border-soft: #1c2534;

  --text: #e6edf6;
  --text-dim: #9aa8bd;
  --text-faint: #6b7a91;

  --accent: #4f9cf9;
  --accent-soft: rgba(79, 156, 249, 0.14);

  --ok: #34d399;
  --ok-soft: rgba(52, 211, 153, 0.14);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, 0.14);
  --error: #f87171;
  --error-soft: rgba(248, 113, 113, 0.14);
  --idle: #64748b;
  --idle-soft: rgba(100, 116, 139, 0.16);

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --mono: ui-monospace, "JetBrains Mono", "Cascadia Code", Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

[data-theme="light"] {
  --bg: #f3f5f9;
  --bg-alt: #ffffff;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --surface-hover: #eef2f8;
  --border: #d9e0ea;
  --border-soft: #e7ecf3;

  --text: #16202e;
  --text-dim: #566378;
  --text-faint: #8493a8;

  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.10);
  --ok: #059669;
  --ok-soft: rgba(5, 150, 105, 0.12);
  --warn: #b45309;
  --warn-soft: rgba(180, 83, 9, 0.12);
  --error: #dc2626;
  --error-soft: rgba(220, 38, 38, 0.10);
  --idle: #64748b;
  --idle-soft: rgba(100, 116, 139, 0.12);
  --shadow: 0 8px 24px rgba(15, 30, 55, 0.10);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

/* --- Layout ------------------------------------------------------------- */
.app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: .2px; }
.brand .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--ok); box-shadow: 0 0 0 4px var(--ok-soft);
}
.brand .dot.stale { background: var(--warn); box-shadow: 0 0 0 4px var(--warn-soft); }
.brand .dot.down { background: var(--error); box-shadow: 0 0 0 4px var(--error-soft); }

.topbar .spacer { flex: 1; }
.topbar-meta { display: flex; align-items: center; gap: 14px; color: var(--text-dim); font-size: 12.5px; }
.topbar-meta b { color: var(--text); font-weight: 600; }

.tabs {
  display: flex;
  gap: 4px;
  padding: 0 12px;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: thin;
}
.tab {
  appearance: none;
  border: 0;
  background: none;
  color: var(--text-dim);
  padding: 11px 14px;
  font-size: 13.5px;
  font-weight: 550;
  font-family: inherit;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 7px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab .count {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 20px; padding: 0 7px; font-size: 11px; font-weight: 600;
}
.tab .count.alarm { background: var(--error-soft); border-color: transparent; color: var(--error); }

main { flex: 1; padding: 18px; max-width: 1600px; width: 100%; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

/* --- Cards / panels ----------------------------------------------------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel + .panel { margin-top: 16px; }
.panel-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 14px; border-bottom: 1px solid var(--border-soft);
  background: var(--surface-2);
}
.panel-head h2 { margin: 0; font-size: 14px; font-weight: 650; }
.panel-head .spacer { flex: 1; }
.panel-body { padding: 14px; }

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px;
}
.stat .label { color: var(--text-dim); font-size: 11.5px; text-transform: uppercase; letter-spacing: .6px; }
.stat .value { font-size: 22px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .sub { color: var(--text-faint); font-size: 12px; }
.stat.ok .value { color: var(--ok); }
.stat.error .value { color: var(--error); }
.stat.warn .value { color: var(--warn); }

.bar { height: 5px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: 8px; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width .4s ease; }
.bar.warn > span { background: var(--warn); }
.bar.error > span { background: var(--error); }

/* --- Controls ----------------------------------------------------------- */
.btn {
  appearance: none;
  font-family: inherit;
  font-size: 13px;
  font-weight: 550;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-hover); border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.1); }
.btn.danger { color: var(--error); border-color: var(--error-soft); background: var(--error-soft); }
.btn.danger:hover:not(:disabled) { background: var(--error); color: #fff; border-color: var(--error); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 8px; font-size: 12px; }
.btn.icon { padding: 5px 7px; }

input, select, textarea {
  font-family: inherit;
  font-size: 13px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-alt);
  color: var(--text);
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
input[type="checkbox"] { width: auto; accent-color: var(--accent); }
textarea { resize: vertical; font-family: var(--mono); font-size: 12.5px; line-height: 1.55; }
label { display: block; font-size: 12.5px; color: var(--text-dim); margin-bottom: 5px; font-weight: 550; }
.field { margin-bottom: 14px; }
.field .hint { font-size: 11.5px; color: var(--text-faint); margin-top: 4px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar .search { flex: 1; min-width: 180px; max-width: 340px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.seg button {
  appearance: none; border: 0; background: var(--surface-2); color: var(--text-dim);
  font-family: inherit; font-size: 12.5px; padding: 6px 12px; cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--border); }
.seg button.active { background: var(--accent); color: #fff; }

/* --- Tables ------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; font-weight: 600; font-size: 11.5px; letter-spacing: .5px;
  text-transform: uppercase; color: var(--text-faint);
  padding: 9px 12px; border-bottom: 1px solid var(--border);
  background: var(--surface-2); position: sticky; top: 0; white-space: nowrap;
}
td { padding: 9px 12px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.clickable { cursor: pointer; }
td.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 12.5px; }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn { margin-left: 4px; }

.empty { padding: 36px 16px; text-align: center; color: var(--text-faint); }
.empty .big { font-size: 15px; color: var(--text-dim); margin-bottom: 6px; }

/* --- Badges ------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 20px; font-size: 11.5px; font-weight: 600;
  border: 1px solid transparent; white-space: nowrap;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.error { background: var(--error-soft); color: var(--error); }
.badge.pending { background: var(--warn-soft); color: var(--warn); }
.badge.idle { background: var(--idle-soft); color: var(--idle); }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.badge.group { background: var(--surface-2); border-color: var(--border); color: var(--text-dim); }
.badge.group .dot { background: var(--g, var(--idle)); }

.mono { font-family: var(--mono); font-size: 12.5px; }
.dim { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

/* --- Modal -------------------------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(4, 8, 14, .72);
  backdrop-filter: blur(2px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; z-index: 100; overflow-y: auto;
}
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  width: 100%; max-width: 760px; margin: auto 0;
}
.modal.wide { max-width: 1100px; }
.modal.narrow { max-width: 460px; }
.modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 650; }
.modal-head .spacer { flex: 1; }
.modal-body { padding: 16px; max-height: calc(100vh - 220px); overflow-y: auto; }
.modal-foot {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 12px 16px; border-top: 1px solid var(--border); background: var(--surface-2);
  flex-wrap: wrap;
}

/* --- Toasts ------------------------------------------------------------- */
#toasts {
  position: fixed; right: 16px; bottom: 16px; z-index: 200;
  display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px));
}
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); padding: 10px 14px; box-shadow: var(--shadow);
  font-size: 13px; animation: slide-in .2s ease;
}
.toast.ok { border-left-color: var(--ok); }
.toast.error { border-left-color: var(--error); }
.toast.warn { border-left-color: var(--warn); }
.toast .title { font-weight: 600; margin-bottom: 2px; }
.toast .msg { color: var(--text-dim); font-size: 12.5px; white-space: pre-wrap; word-break: break-word; }
@keyframes slide-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* --- Logs --------------------------------------------------------------- */
.logs {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-family: var(--mono); font-size: 12px; line-height: 1.6;
  max-height: 440px; overflow: auto; padding: 8px 0;
}
.log-line { display: flex; gap: 10px; padding: 1px 12px; white-space: pre-wrap; word-break: break-word; }
.log-line:hover { background: var(--surface-2); }
.log-line .ts { color: var(--text-faint); flex: 0 0 auto; }
.log-line .lvl { flex: 0 0 62px; font-weight: 600; }
.log-line.p0 .lvl, .log-line.p1 .lvl, .log-line.p2 .lvl, .log-line.p3 .lvl { color: var(--error); }
.log-line.p4 .lvl { color: var(--warn); }
.log-line.p5 .lvl, .log-line.p6 .lvl { color: var(--text-dim); }
.log-line.p7 .lvl { color: var(--text-faint); }
.log-line .msg { flex: 1; }

/* --- Chart -------------------------------------------------------------- */
.chart { width: 100%; height: 190px; display: block; }
.chart-legend { display: flex; gap: 16px; font-size: 12px; color: var(--text-dim); margin-top: 6px; }
.chart-legend i { display: inline-block; width: 10px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }

/* --- Misc --------------------------------------------------------------- */
.banner {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 14px; border-radius: var(--radius-sm);
  background: var(--warn-soft); border: 1px solid transparent; color: var(--warn);
  font-size: 12.5px; margin-bottom: 14px;
}
.banner.error { background: var(--error-soft); color: var(--error); }
.banner.info { background: var(--accent-soft); color: var(--accent); }
.banner b { font-weight: 650; }

.code-preview {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; font-family: var(--mono); font-size: 12.5px; line-height: 1.6;
  white-space: pre; overflow-x: auto; max-height: 420px; overflow-y: auto; color: var(--text);
}

.kv-list { display: flex; flex-direction: column; gap: 8px; }
.kv-row { display: grid; grid-template-columns: 1fr 1.4fr auto; gap: 8px; align-items: center; }

.secret-box {
  background: var(--ok-soft); border: 1px solid var(--ok); border-radius: var(--radius-sm);
  padding: 12px 14px; margin-top: 12px;
}
.secret-box .pw {
  font-family: var(--mono); font-size: 15px; font-weight: 600; color: var(--text);
  background: var(--bg); padding: 8px 12px; border-radius: var(--radius-sm);
  margin-top: 8px; display: flex; align-items: center; gap: 10px; word-break: break-all;
}

.spin { display: inline-block; width: 13px; height: 13px; border: 2px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-hover), var(--surface-2));
  background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 4px; height: 12px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* --- Login -------------------------------------------------------------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 28px; width: 100%; max-width: 380px;
}
.login-card h1 { margin: 0 0 4px; font-size: 19px; }
.login-card .sub { color: var(--text-dim); font-size: 13px; margin-bottom: 22px; }
.login-error { background: var(--error-soft); color: var(--error); padding: 9px 12px;
  border-radius: var(--radius-sm); font-size: 12.5px; margin-bottom: 14px; }

/* --- Responsive --------------------------------------------------------- */
@media (max-width: 900px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  main { padding: 12px; }
  .topbar { padding: 10px 12px; }
  .topbar-meta .hide-sm { display: none; }
}

@media (max-width: 720px) {
  .stat-row { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
  .kv-row { grid-template-columns: 1fr; }

  /* Tables collapse into stacked cards */
  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr {
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    margin-bottom: 10px; padding: 6px 4px; background: var(--surface);
  }
  table.responsive td { border: 0; padding: 5px 10px; display: flex; justify-content: space-between; gap: 12px; }
  table.responsive td::before {
    content: attr(data-label); color: var(--text-faint); font-size: 11.5px;
    text-transform: uppercase; letter-spacing: .5px; font-weight: 600; flex: 0 0 auto;
  }
  table.responsive td.actions { justify-content: flex-end; flex-wrap: wrap; }
  table.responsive td.actions::before { display: none; }
  td.num { text-align: right; }
  .modal-body { max-height: none; }
  .modal-backdrop { padding: 12px; }
}
