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

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface2: #263347;
  --border: #334155;
  --text: #e2e8f0;
  --text-muted: #64748b;
  --text-dim: #94a3b8;
  --accent: #38bdf8;
  --accent-dim: #0ea5e9;
  --green: #4ade80;
  --green-bg: #14532d;
  --red: #f87171;
  --red-bg: #450a0a;
  --yellow: #fbbf24;
  --purple: #a78bfa;
  --radius: 10px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: 220px;
  min-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  padding: 20px 0;
}
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 24px;
  font-weight: 700;
  font-size: 1rem;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.logo-icon { font-size: 1.3rem; }
nav { display: flex; flex-direction: column; gap: 2px; padding: 0 10px; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text-dim);
  text-decoration: none;
  cursor: pointer;
  font-size: 0.88rem;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: rgba(56,189,248,0.12); color: var(--accent); }
.nav-icon { font-size: 1rem; width: 18px; text-align: center; }
.sidebar-footer { padding: 12px 20px; border-top: 1px solid var(--border); }
.hub-link { color: var(--text-muted); text-decoration: none; font-size: 0.8rem; }
.hub-link:hover { color: var(--text-dim); }

/* ── Main ── */
.main { flex: 1; padding: 32px; overflow-y: auto; }
.view { display: none; }
.view.active { display: block; }

/* ── Page header ── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}
.page-header h1 { font-size: 1.4rem; font-weight: 700; }
.page-header p { color: var(--text-muted); font-size: 0.85rem; margin-top: 2px; }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 7px; border: none; font-size: 0.83rem; font-weight: 500; cursor: pointer; transition: all 0.15s; }
.btn-primary { background: var(--accent); color: #0f172a; }
.btn-primary:hover { background: #7dd3fc; }
.btn-secondary { background: transparent; color: var(--text-dim); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--surface2); color: var(--text); }
.btn-danger { background: var(--red-bg); color: var(--red); border: 1px solid #7f1d1d; }
.btn-danger:hover { background: #7f1d1d; }
.btn-icon { background: transparent; border: 1px solid var(--border); color: var(--text-dim); padding: 5px 9px; border-radius: 6px; cursor: pointer; font-size: 0.82rem; transition: all 0.15s; }
.btn-icon:hover { background: var(--surface2); color: var(--text); border-color: var(--text-muted); }
.btn-icon.danger:hover { border-color: var(--red); color: var(--red); background: var(--red-bg); }
.btn-icon.success:hover { border-color: var(--green); color: var(--green); }
.btn-icon:disabled { opacity: 0.4; pointer-events: none; }

/* ── Cards grid ── */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: border-color 0.15s;
}
.card:hover { border-color: #475569; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.card-title { font-weight: 600; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-sub { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }
.card-url { font-size: 0.78rem; color: var(--accent); text-decoration: none; }
.card-url:hover { text-decoration: underline; }
.badge { display: inline-block; font-size: 0.68rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; text-transform: uppercase; letter-spacing: 0.4px; flex-shrink: 0; }
.badge-on { background: var(--green-bg); color: var(--green); }
.badge-off { background: var(--red-bg); color: var(--red); }
.badge-web { background: #1e3a5f; color: #7dd3fc; }
.badge-service { background: #2d1a5f; color: var(--purple); }
.card-desc { font-size: 0.82rem; color: var(--text-dim); line-height: 1.5; }
.card-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.tag { background: var(--bg); color: #7dd3fc; font-size: 0.7rem; padding: 2px 8px; border-radius: 99px; border: 1px solid #1e40af; }
.card-ports { font-size: 0.78rem; color: var(--text-muted); }
.card-ports code { background: var(--bg); padding: 1px 5px; border-radius: 4px; color: var(--purple); }
.card-actions { display: flex; gap: 6px; flex-wrap: wrap; padding-top: 4px; border-top: 1px solid var(--border); }

/* ── Table ── */
.table-wrap { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 11px 16px; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); border-bottom: 1px solid var(--border); background: var(--surface2); }
td { padding: 12px 16px; font-size: 0.86rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
td code { background: var(--bg); padding: 2px 6px; border-radius: 4px; font-size: 0.8rem; color: #7dd3fc; }
td a { color: var(--text-dim); text-decoration: none; }
td a:hover { color: var(--accent); }
.empty-state { text-align: center; color: var(--text-muted); padding: 48px 0; }

/* ── SSH Key card ── */
.key-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.key-name { font-weight: 600; font-size: 0.88rem; }
.key-comment { font-size: 0.78rem; color: var(--text-muted); }
.key-pub { font-family: monospace; font-size: 0.72rem; color: var(--text-dim); background: var(--bg); padding: 8px; border-radius: 6px; word-break: break-all; line-height: 1.5; }
.config-item { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; }
.config-host { font-weight: 600; color: var(--accent); font-size: 0.88rem; }
.config-detail { font-size: 0.78rem; color: var(--text-muted); margin-top: 4px; }

/* ── System stats ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 28px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.stat-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 8px; }
.stat-value { font-size: 1.6rem; font-weight: 700; color: var(--text); }
.stat-sub { font-size: 0.78rem; color: var(--text-muted); margin-top: 4px; }

/* ── Modals ── */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.65); z-index: 200; align-items: center; justify-content: center; padding: 20px; }
.modal-overlay.open { display: flex; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 26px; width: 100%; max-width: 500px; max-height: 90vh; overflow-y: auto; }
.modal-wide { max-width: 760px; }
.modal h3 { font-size: 1.05rem; margin-bottom: 18px; display: flex; align-items: center; justify-content: space-between; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 1rem; cursor: pointer; }
.modal-close:hover { color: var(--text); }
.modal p { font-size: 0.85rem; color: var(--text-dim); margin-bottom: 16px; }
.modal label { display: block; font-size: 0.78rem; color: var(--text-muted); margin: 12px 0 5px; }
.modal input, .modal select, .modal textarea {
  width: 100%; padding: 9px 12px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 7px; color: var(--text); font-size: 0.88rem;
  transition: border-color 0.15s;
}
.modal input:focus, .modal select:focus { outline: none; border-color: var(--accent); }
.modal-btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* ── Mini tabs ── */
.tabs-mini { display: flex; gap: 4px; margin-bottom: 16px; background: var(--bg); padding: 4px; border-radius: 8px; }
.tab-mini { flex: 1; padding: 6px; background: transparent; border: none; color: var(--text-muted); font-size: 0.82rem; border-radius: 6px; cursor: pointer; transition: all 0.15s; }
.tab-mini.active { background: var(--surface2); color: var(--text); }

/* ── Log box ── */
.log-box {
  background: #020617; border-radius: 8px; padding: 12px;
  font-family: monospace; font-size: 0.75rem; line-height: 1.7;
  height: 240px; overflow-y: auto; white-space: pre-wrap;
  color: var(--text-dim); border: 1px solid var(--border);
  margin-top: 12px;
}
.log-box-tall { height: 440px; }
.log-err { color: var(--red); }
.log-ok { color: var(--green); }

/* ── Misc ── */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.section-header h2 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); }
.loading { opacity: 0.5; pointer-events: none; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; bottom: 24px; right: 24px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 18px; font-size: 0.85rem; z-index: 999; animation: toast-in 0.2s ease; }
.toast.success { border-color: var(--green); color: var(--green); }
.toast.error { border-color: var(--red); color: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.copy-btn { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 0.8rem; padding: 2px 6px; }
.copy-btn:hover { color: var(--accent); }
.gap { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
