/* ───────────────────────── design tokens ───────────────────────── */
:root {
  --bg:        #07090e;
  --bg-2:      #0c1118;
  --surface:   #11161f;
  --surface-2: #161c27;
  --border:    #1d2533;
  --border-2:  #283142;
  --text:      #e7ecf3;
  --muted:     #8b95a7;
  --muted-2:   #5a6377;

  --accent:    #5bd3ee;       /* primary cyan */
  --accent-2:  #2bb3d6;
  --accent-glow: rgba(91,211,238,.18);

  --green:     #5dd39e;
  --amber:     #efb851;
  --red:       #ee6e6e;

  --radius:    12px;
  --radius-sm: 8px;

  --shadow-1: 0 1px 0 rgba(255,255,255,.02) inset, 0 12px 24px rgba(0,0,0,.35);
  --shadow-glow: 0 0 0 1px rgba(91,211,238,.25), 0 12px 32px rgba(91,211,238,.18);

  --font-display: "Space Grotesk", sans-serif;
  --font-body:    "IBM Plex Sans", -apple-system, system-ui, sans-serif;
  --font-mono:    "IBM Plex Mono", ui-monospace, "SF Mono", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: .005em;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; }

.mono { font-family: var(--font-mono); }
.muted { color: var(--muted); }

/* ───────────────────────── brand mark ───────────────────────── */
.brand { display: inline-flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 600; color: var(--text); }
.brand-name { font-size: 19px; letter-spacing: -.01em; }
.brand-name-accent { color: var(--accent); }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, #5bd3ee 0%, #2278a8 100%);
  position: relative; box-shadow: 0 4px 12px rgba(91,211,238,.25), inset 0 1px 0 rgba(255,255,255,.2);
}
.brand-mark::before {
  content: ""; position: absolute; inset: 6px; border-radius: 4px;
  background: linear-gradient(180deg, #0a1118, #0a1118), linear-gradient(180deg, #5bd3ee, #2278a8);
  background-origin: border-box; background-clip: padding-box, border-box;
  border: 2px solid transparent;
}
.brand-mark::after {
  content: ""; position: absolute; left: 12px; top: 8px;
  width: 4px; height: 12px; background: var(--accent); border-radius: 2px;
}

/* ───────────────────────── login page ───────────────────────── */
.login-page { background:
  radial-gradient(800px 600px at -10% 110%, rgba(91,211,238,.10), transparent 60%),
  radial-gradient(600px 400px at 100% 0%, rgba(91,211,238,.05), transparent 70%),
  var(--bg);
}
.login-shell { display: grid; grid-template-columns: 1fr 1fr; min-height: 100vh; }
.login-aside {
  padding: 28px 40px; display: flex; flex-direction: column; justify-content: space-between;
  border-right: 1px solid var(--border);
  background:
    linear-gradient(180deg, rgba(91,211,238,.02), transparent 40%),
    repeating-linear-gradient(0deg, rgba(255,255,255,.015) 0 1px, transparent 1px 80px),
    repeating-linear-gradient(90deg, rgba(255,255,255,.015) 0 1px, transparent 1px 80px);
}
.aside-bottom { max-width: 460px; }
.hero { font-family: var(--font-display); font-weight: 600; font-size: 38px; line-height: 1.1; letter-spacing: -.02em; margin: 22px 0 16px; }
.hero .accent { color: var(--accent); }
.hero-sub { color: var(--muted); margin: 0 0 24px; max-width: 440px; }
.hero-bullets { display: flex; gap: 22px; color: var(--muted); font-size: 13px; }
.hero-bullets span { display: inline-flex; align-items: center; gap: 7px; }
.hero-bullets .ic { width: 16px; height: 16px; color: var(--accent); }

.status-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px; border: 1px solid var(--border-2);
  background: var(--surface); border-radius: 999px; font-size: 13px; color: var(--text);
}
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot-online   { background: var(--green); box-shadow: 0 0 0 3px rgba(93,211,158,.18); }
.dot-active   { background: var(--accent);box-shadow: 0 0 0 3px rgba(91,211,238,.18); }
.dot-expiring { background: var(--amber); box-shadow: 0 0 0 3px rgba(239,184,81,.18); }
.dot-disabled { background: var(--muted-2); }
.dot-expired  { background: var(--red);   box-shadow: 0 0 0 3px rgba(238,110,110,.18); }
.dot-pending  { background: var(--amber); }
.dot-stale    { background: var(--amber); }

/* form */
.login-main {
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
  display: flex; align-items: center; justify-content: center; padding: 40px;
}
.login-form { width: min(420px, 100%); display: flex; flex-direction: column; gap: 12px; }
.login-form h2 { font-family: var(--font-display); font-size: 30px; margin: 0; font-weight: 600; letter-spacing: -.01em; }
.field-label { font-size: 12px; color: var(--muted); margin-top: 8px; letter-spacing: .04em; text-transform: uppercase; font-weight: 500; }
.login-form input[type="text"], .login-form input[type="password"], .login-form input:not([type="checkbox"]) {
  width: 100%; padding: 12px 14px; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.login-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.checkbox { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); margin-top: 4px; font-size: 13px; }
.checkbox input { accent-color: var(--accent); }
.btn-primary {
  margin-top: 10px; padding: 12px 16px; border: 0; border-radius: var(--radius-sm);
  background: var(--accent); color: #03161e; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .08s, box-shadow .15s, background .15s;
  box-shadow: 0 6px 16px rgba(91,211,238,.25);
}
.btn-primary:hover { background: #6fdcf3; box-shadow: 0 6px 24px rgba(91,211,238,.4); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary svg { width: 16px; height: 16px; }
.form-footer { margin-top: 14px; display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.form-error { color: var(--red); font-size: 13px; min-height: 1em; }

/* ───────────────────────── app shell ───────────────────────── */
.app-page { background: var(--bg); }
.app-shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  border-right: 1px solid var(--border); padding: 22px 14px 18px;
  display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh;
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
}
.sidebar-brand { padding: 0 8px 18px; }
.nav-section { padding: 14px 10px 4px; color: var(--muted-2); font-size: 11px; text-transform: uppercase; letter-spacing: .12em; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: var(--muted); font-weight: 500; font-size: 14px;
  transition: background .12s, color .12s;
}
.nav-item svg { width: 17px; height: 17px; opacity: .9; }
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active {
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  color: var(--text); box-shadow: inset 0 0 0 1px var(--border-2);
}
.nav-item.active svg { color: var(--accent); }

.sidebar-bottom { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }
.admin-chip { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 8px; background: linear-gradient(135deg, #2bb3d6, #1d6e85); display: grid; place-items: center; font-weight: 600; color: #03161e; font-family: var(--font-display); }
.admin-meta { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.admin-name { font-size: 13px; font-weight: 500; }
.admin-sub { color: var(--muted-2); font-size: 11px; font-family: var(--font-mono); }
.icon-btn { background: transparent; border: 0; color: var(--muted); padding: 6px; border-radius: 6px; display: grid; place-items: center; }
.icon-btn:hover { color: var(--text); background: var(--surface); }
.icon-btn svg { width: 16px; height: 16px; }

/* topbar + page */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 24px;
  padding: 28px 32px 18px;
}
.topbar h1 { font-family: var(--font-display); font-weight: 600; font-size: 26px; letter-spacing: -.01em; margin: 0; }
.topbar-title p { margin: 4px 0 0; }
.page { padding: 0 32px 48px; }

/* ───────────────────────── components ───────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.stat-card {
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px;
  position: relative; overflow: hidden;
}
.stat-card-head { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.stat-card-head .ic-wrap {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: rgba(91,211,238,.08); color: var(--accent);
}
.stat-card-head .ic-wrap svg { width: 16px; height: 16px; }
.stat-card-value { font-family: var(--font-display); font-weight: 600; font-size: 32px; line-height: 1.1; margin-top: 10px; letter-spacing: -.02em; }
.stat-card-meta { color: var(--muted); font-size: 12px; margin-top: 4px; }
.stat-card-trend { position: absolute; top: 16px; right: 18px; color: var(--green); font-size: 12px; font-weight: 500; display: inline-flex; align-items: center; gap: 4px; }
.stat-card-trend.amber { color: var(--amber); }
.stat-card-trend.muted { color: var(--muted); }

/* toolbar above table */
.toolbar {
  display: flex; align-items: center; gap: 10px; margin-bottom: 14px;
  padding: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.toolbar .search { flex: 1; position: relative; }
.toolbar .search input { width: 100%; padding: 10px 12px 10px 36px; background: var(--bg-2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); outline: none; }
.toolbar .search svg { position: absolute; left: 11px; top: 11px; width: 16px; height: 16px; color: var(--muted); }
.toolbar select { padding: 10px 12px; background: var(--bg-2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); outline: none; }
.spacer { flex: 1; }
.btn-secondary {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 14px; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border-2); border-radius: 8px;
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-secondary svg { width: 16px; height: 16px; }

.btn-primary-sm {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px; background: var(--accent); color: #03161e; font-weight: 600;
  border: 0; border-radius: 8px; box-shadow: 0 4px 12px rgba(91,211,238,.25);
}
.btn-primary-sm:hover { background: #6fdcf3; }
.btn-primary-sm svg { width: 16px; height: 16px; }

/* tables */
.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl thead th {
  text-align: left; padding: 12px 18px; color: var(--muted-2);
  font-size: 11px; text-transform: uppercase; letter-spacing: .1em; font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.tbl tbody td { padding: 14px 18px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover { background: rgba(255,255,255,.015); }

.user-cell { display: flex; align-items: center; gap: 12px; }
.user-avatar { width: 30px; height: 30px; border-radius: 8px; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); font-weight: 600; font-family: var(--font-display); font-size: 13px; border: 1px solid var(--border); position: relative; }
.user-avatar .ind { position: absolute; bottom: -2px; right: -2px; width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--surface); }
.user-cell .uname { font-weight: 600; font-size: 14px; }
.user-cell .usub  { color: var(--muted); font-size: 12px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 500;
}
.pill .bars { display: inline-flex; align-items: end; gap: 1.5px; height: 9px; }
.pill .bars i { width: 2px; background: currentColor; border-radius: 1px; }
.pill .bars i:nth-child(1) { height: 30%; }
.pill .bars i:nth-child(2) { height: 60%; }
.pill .bars i:nth-child(3) { height: 100%; }

.pill-online   { color: var(--accent); background: rgba(91,211,238,.10); box-shadow: inset 0 0 0 1px rgba(91,211,238,.20); }
.pill-active   { color: var(--green);  background: rgba(93,211,158,.10); box-shadow: inset 0 0 0 1px rgba(93,211,158,.20); }
.pill-expiring { color: var(--amber);  background: rgba(239,184,81,.10); box-shadow: inset 0 0 0 1px rgba(239,184,81,.22); }
.pill-disabled { color: var(--muted);  background: rgba(139,149,167,.08); box-shadow: inset 0 0 0 1px rgba(139,149,167,.18); }
.pill-expired  { color: var(--red);    background: rgba(238,110,110,.10); box-shadow: inset 0 0 0 1px rgba(238,110,110,.22); }
.pill-pending  { color: var(--amber);  background: rgba(239,184,81,.10); box-shadow: inset 0 0 0 1px rgba(239,184,81,.22); }
.pill-stale    { color: var(--amber);  background: rgba(239,184,81,.10); box-shadow: inset 0 0 0 1px rgba(239,184,81,.22); }
.pill-connected{ color: var(--accent); background: rgba(91,211,238,.10); box-shadow: inset 0 0 0 1px rgba(91,211,238,.20); }

/* usage bar */
.usage { display: flex; align-items: center; gap: 12px; min-width: 220px; }
.usage-bar { flex: 1; height: 5px; border-radius: 999px; background: var(--bg-2); overflow: hidden; position: relative; }
.usage-bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.usage-text { font-family: var(--font-mono); font-size: 12px; color: var(--muted); min-width: 120px; text-align: right; }

.row-actions { display: inline-flex; align-items: center; gap: 6px; }
.flag { font-size: 18px; }

.node-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 14px; overflow: hidden;
}
.node-head {
  display: flex; align-items: center; gap: 12px; padding: 14px 18px;
  border-bottom: 1px solid var(--border); cursor: pointer;
}
.node-head .node-title { font-family: var(--font-display); font-weight: 600; font-size: 15px; }
.node-head .spacer { flex: 1; }
.node-meta { color: var(--muted); font-size: 12px; font-family: var(--font-mono); }
.node-body { padding: 18px; display: none; }
.node-card.open .node-body { display: block; }
.node-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin-bottom: 18px; }
.node-stats .label { font-size: 11px; color: var(--muted-2); text-transform: uppercase; letter-spacing: .1em; font-weight: 600; }
.node-stats .value { font-family: var(--font-mono); font-size: 14px; margin-top: 6px; color: var(--text); }
.cert-box { background: var(--bg-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; font-family: var(--font-mono); font-size: 11px; color: var(--muted); white-space: pre-wrap; word-break: break-all; max-height: 130px; overflow: auto; }

/* drawer */
.drawer-host { position: fixed; inset: 0; pointer-events: none; z-index: 80; }
.drawer-host[data-open] { pointer-events: auto; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(2,5,9,.55); opacity: 0; transition: opacity .2s; }
.drawer-host[data-open] .drawer-backdrop { opacity: 1; }
.drawer {
  position: absolute; right: 0; top: 0; bottom: 0; width: min(560px, 100%);
  background: var(--bg-2); border-left: 1px solid var(--border);
  transform: translateX(100%); transition: transform .2s ease;
  display: flex; flex-direction: column;
}
.drawer-host[data-open] .drawer { transform: translateX(0); }
.drawer-head { padding: 22px; display: flex; align-items: center; gap: 14px; border-bottom: 1px solid var(--border); }
.drawer-body { padding: 22px; overflow: auto; flex: 1; }
.drawer-section { margin-bottom: 22px; }
.drawer-section h4 { font-family: var(--font-display); font-size: 12px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); margin: 0 0 10px; }

.usage-ring {
  width: 96px; height: 96px; position: relative;
  background: conic-gradient(var(--accent) calc(var(--pct,0) * 1%), var(--surface-2) 0);
  border-radius: 50%; display: grid; place-items: center;
}
.usage-ring::after { content: ""; position: absolute; inset: 6px; border-radius: 50%; background: var(--bg-2); }
.usage-ring .inner { position: relative; z-index: 2; text-align: center; }
.usage-ring .num { font-family: var(--font-display); font-weight: 600; font-size: 20px; letter-spacing: -.02em; }
.usage-ring .unit { font-size: 10px; color: var(--muted); }

.sub-url {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  font-family: var(--font-mono); font-size: 12px; color: var(--muted);
}
.sub-url .url-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub-url button {
  border: 1px solid var(--border-2); background: var(--surface-2); color: var(--text);
  padding: 6px 10px; border-radius: 6px; font-size: 12px; display: inline-flex; align-items: center; gap: 6px;
}
.sub-url button:hover { color: var(--accent); border-color: var(--accent); }
.sub-url button svg { width: 13px; height: 13px; }

.download-list { display: flex; flex-direction: column; gap: 6px; }
.download-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
.download-row .flag { font-size: 17px; }
.download-row .meta { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.download-row .meta .t { font-weight: 600; font-size: 13px; }
.download-row .meta .s { color: var(--muted); font-size: 11px; font-family: var(--font-mono); }

/* modal */
.modal-host { position: fixed; inset: 0; z-index: 90; background: rgba(2,5,9,.55); display: grid; place-items: center; padding: 24px; }
.modal-host[hidden] { display: none; }
.modal {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius);
  width: min(520px, 100%); padding: 22px; max-height: 90vh; overflow: auto;
}
.modal h3 { font-family: var(--font-display); margin: 0 0 4px; font-weight: 600; font-size: 18px; }
.modal p.muted { margin: 0 0 18px; font-size: 13px; }
.modal label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted-2); margin: 12px 0 6px; font-weight: 600; }
.modal input, .modal select, .modal textarea {
  width: 100%; padding: 10px 12px; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; outline: none; font-family: inherit;
}
.modal textarea { font-family: var(--font-mono); min-height: 80px; resize: vertical; }
.modal .modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.modal .modal-actions button { padding: 9px 14px; border-radius: 8px; border: 1px solid var(--border-2); background: transparent; color: var(--text); }
.modal .modal-actions .primary { background: var(--accent); color: #03161e; border-color: var(--accent); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); min-height: 44px; }
.chip { padding: 4px 10px; border-radius: 999px; font-size: 12px; background: var(--surface-2); border: 1px solid var(--border-2); color: var(--muted); cursor: pointer; user-select: none; transition: all .12s; }
.chip.on { background: rgba(91,211,238,.10); border-color: rgba(91,211,238,.35); color: var(--accent); }

/* toast */
.toast-host { position: fixed; right: 22px; bottom: 22px; z-index: 95; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 16px; min-width: 240px; box-shadow: 0 12px 30px rgba(0,0,0,.4);
  font-size: 13px; animation: toast-in .2s ease; display: flex; align-items: center; gap: 10px;
}
.toast.ok  { border-color: rgba(93,211,158,.4); }
.toast.err { border-color: rgba(238,110,110,.4); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* utilities */
.empty {
  padding: 60px 20px; text-align: center; color: var(--muted);
  border: 1px dashed var(--border-2); border-radius: var(--radius);
}
.empty h3 { font-family: var(--font-display); color: var(--text); font-weight: 600; margin: 0 0 6px; }
.kbd { font-family: var(--font-mono); background: var(--surface); border: 1px solid var(--border); padding: 2px 6px; border-radius: 4px; font-size: 12px; }

@media (max-width: 1080px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .node-stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .login-shell { grid-template-columns: 1fr; }
  .login-aside { display: none; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}
