/* ─── Design Tokens ───────────────────────────────────── */
:root {
  --bg:          #0d1117;
  --bg-elevated: #161b22;
  --bg-card:     #1c2128;
  --bg-input:    #0d1117;
  --bg-hover:    #21262d;
  --border:      #30363d;
  --border-muted:#21262d;

  --text:        #e6edf3;
  --text-muted:  #8b949e;
  --text-subtle: #6e7681;

  --accent:      #58a6ff;
  --accent-soft: rgba(88,166,255,0.15);
  --accent-hover:#79c0ff;

  --green:       #3fb950;
  --green-soft:  rgba(63,185,80,0.15);
  --orange:      #d29922;
  --orange-soft: rgba(210,153,34,0.15);
  --red:         #f85149;
  --red-soft:    rgba(248,81,73,0.15);
  --yellow:      #e3b341;
  --yellow-soft: rgba(227,179,65,0.15);
  --gray:        #6e7681;
  --gray-soft:   rgba(110,118,129,0.15);

  --radius-sm:   6px;
  --radius:      10px;
  --radius-lg:   14px;
  --sidebar-w:   220px;
  --font-mono:   "SFMono-Regular", "Consolas", "Liberation Mono", monospace;
}

/* ─── Reset ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

h1,h2,h3,h4,h5,h6 { margin: 0; font-weight: 600; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Layout Shell ────────────────────────────────────── */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ─── Sidebar ─────────────────────────────────────────── */
.sidebar {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px;
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-icon { color: var(--accent); font-size: 20px; }

/* ─── Nav ─────────────────────────────────────────────── */
.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }

.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.nav-icon { font-size: 12px; color: inherit; }

/* ─── Sidebar Section ─────────────────────────────────── */
.sidebar-section { display: flex; flex-direction: column; gap: 10px; }
.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 6px; padding-top: 12px; border-top: 1px solid var(--border); }
.btn-block { width: 100%; justify-content: center; }

.section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-subtle);
  padding: 0 4px;
}

/* ─── Content ─────────────────────────────────────────── */
.content {
  padding: 28px 32px;
  min-width: 0;
}

/* ─── Topbar ──────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.page-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

.status-bar {
  flex-shrink: 0;
  max-width: 480px;
  padding: 7px 14px;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ─── Card ────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.card-head {
  margin-bottom: 16px;
}

.card-title {
  font-size: 15px;
  color: var(--text);
  margin-bottom: 4px;
}

.card-sub { font-size: 13px; color: var(--text-muted); }

/* ─── Stats Grid ──────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
}

.stat-label {
  font-size: 12px;
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  font-family: var(--font-mono);
  line-height: 1.1;
}

.stat-meta { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

/* ─── Install Panel ───────────────────────────────────── */
.install-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.install-item {
  background: var(--bg-elevated);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.install-item-wide { grid-column: span 2; }

.install-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-subtle);
  margin-bottom: 8px;
}

.install-item pre {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.6;
}

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  width: auto;
}

.copy-btn:hover { background: var(--bg-hover); color: var(--text); }

/* ─── Overview Install Cols ──────────────────────────── */
.install-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pre-wrap {
  position: relative;
  background: var(--bg-elevated);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pre-wrap pre {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.6;
}

.overview-meta-row {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

/* ─── Toast ────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 13px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.18s, transform 0.18s;
  z-index: 1000;
}
.toast.toast-show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ─── Node Grid ───────────────────────────────────────── */
.node-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.node-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
}

.node-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.node-name { font-size: 15px; font-weight: 600; }
.node-card-name { font-size: 15px; font-weight: 600; }
.node-card-url { font-size: 12px; color: var(--text-muted); font-family: var(--font-mono); margin-bottom: 12px; }
.node-card-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.node-card-usage { display: flex; flex-wrap: wrap; gap: 10px; font-size: 11px; color: var(--text-muted); margin-bottom: 4px; min-height: 16px; }
.node-stat { display: flex; align-items: center; }
.logs-content { background: var(--bg-elevated); border-radius: var(--radius); padding: 12px; font-size: 12px; font-family: var(--font-mono); max-height: 400px; overflow-y: auto; white-space: pre-wrap; word-break: break-all; margin: 0; color: var(--text); }
.modal-box-lg { max-width: 700px; width: 90vw; }
.node-badge { display: flex; align-items: center; }
.node-url { font-size: 12px; color: var(--text-muted); font-family: var(--font-mono); margin-bottom: 12px; }
.node-id-tag {
  font-size: 11px;
  color: var(--text-subtle);
  font-family: var(--font-mono);
  background: var(--bg-elevated);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius-sm);
  padding: 2px 8px;
}

/* ─── Users ───────────────────────────────────────────── */
.users-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
  align-items: start;
}

.create-panel { position: sticky; top: 28px; }

.list-toolbar {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  margin-bottom: 12px;
}

.search-input, .filter-select {
  height: 34px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.search-input:focus, .filter-select:focus {
  outline: none;
  border-color: var(--accent);
}

.user-list { display: flex; flex-direction: column; gap: 8px; }

.user-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
}

.user-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.user-name { font-size: 15px; font-weight: 600; }
.user-card-name { font-size: 15px; font-weight: 600; }
.user-card-badges { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.user-card-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.user-card-traffic {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-top: 4px;
  margin-bottom: 10px;
}
.user-card-actions { display: flex; flex-wrap: wrap; gap: 6px; }

.user-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.user-meta-item { display: flex; align-items: center; gap: 4px; }

/* ─── Traffic Bar ─────────────────────────────────────── */
.traffic-wrap { margin-bottom: 10px; }

.traffic-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-family: var(--font-mono);
}

.traffic-bar {
  height: 4px;
  background: var(--bg-elevated);
  border-radius: 99px;
  overflow: hidden;
}

.traffic-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--green);
  transition: width 0.3s;
}

.traffic-fill.warn { background: var(--orange); }
.traffic-fill.danger { background: var(--red); }

/* ─── Subscription Box ────────────────────────────────── */
.sub-box {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--bg-elevated);
  border: 1px solid var(--border-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  word-break: break-all;
  white-space: pre-wrap;
  line-height: 1.6;
}

.detail-box {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--bg-elevated);
  border: 1px solid var(--border-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  word-break: break-all;
  white-space: pre-wrap;
  line-height: 1.6;
  max-height: 240px;
  overflow-y: auto;
}

/* ─── Badges ──────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.badge::before { content: "●"; font-size: 8px; }

.badge-active   { background: var(--green-soft);  color: var(--green);  }
.badge-limited  { background: var(--orange-soft); color: var(--orange); }
.badge-expired  { background: var(--red-soft);    color: var(--red);    }
.badge-disabled { background: var(--gray-soft);   color: var(--gray);   }
.badge-on-hold  { background: var(--yellow-soft); color: var(--yellow); }
.badge-running  { background: var(--green-soft);  color: var(--green);  }
.badge-stopped  { background: var(--red-soft);    color: var(--red);    }
.badge-unknown  { background: var(--gray-soft);   color: var(--gray);   }

/* ─── Protocol Badge ──────────────────────────────────── */
.proto-badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--font-mono);
}

/* ─── Action Buttons ──────────────────────────────────── */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

/* ─── Buttons ─────────────────────────────────────────── */
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  width: 100%;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }

.btn-danger { color: var(--red) !important; }
.btn-danger:hover { background: var(--red-soft) !important; border-color: var(--red) !important; }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-nowrap { white-space: nowrap; width: auto; }
.btn-auto { width: auto; }

.btn-icon {
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text); }

/* ─── Forms ───────────────────────────────────────────── */
input, select, textarea {
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}

input::placeholder { color: var(--text-subtle); }
select option { background: var(--bg-card); }

.form-stack { display: flex; flex-direction: column; gap: 8px; }

.form-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.form-row input { flex: 1; }

.form-row-2 {
  display: grid;
  grid-template-columns: 1.4fr 0.6fr;
  gap: 8px;
}

.field-group { display: flex; flex-direction: column; gap: 5px; }

.field-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

/* ─── Stacks / Utils ──────────────────────────────────── */
.btn-stack { display: flex; flex-direction: column; gap: 4px; }
.mt-4 { margin-top: 16px; }
.empty-state { color: var(--text-subtle); font-size: 13px; padding: 24px; text-align: center; }

/* ─── Skeleton ────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-hover) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-lg);
  min-height: 90px;
  border: 1px solid var(--border);
}

.install-item.skeleton { min-height: 70px; }

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ─── Route Container ─────────────────────────────────── */
.route { display: flex; flex-direction: column; gap: 0; }

/* ─── Modal ───────────────────────────────────────────── */
dialog {
  background: none;
  border: none;
  padding: 0;
  max-width: 100vw;
  max-height: 100vh;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(2px);
}

.modal { width: 100%; max-width: 480px; }

.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-title { font-size: 16px; }

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 4px;
}

/* ─── Scrollbar ───────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray); }

/* ─── Responsive ──────────────────────────────────────── */
@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .node-grid { grid-template-columns: 1fr; }
  .users-layout { grid-template-columns: 1fr; }
  .create-panel { position: static; }
  .install-grid { grid-template-columns: 1fr; }
  .install-item-wide { grid-column: span 1; }
}

@media (max-width: 768px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; padding: 12px 16px; }
  .brand { margin-right: auto; }
  .content { padding: 16px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .topbar { flex-direction: column; align-items: flex-start; }
  .list-toolbar { grid-template-columns: 1fr; }
}
