:root {
  --bg-primary: #060a14;
  --bg-secondary: #0c1221;
  --bg-card: #111827;
  --bg-card-hover: #162031;
  --bg-input: #0f172a;
  --border: #1e293b;
  --border-light: #2a3a50;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-indigo: #6366f1;
  --accent-violet: #8b5cf6;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-red: #ef4444;
  --accent-sky: #0ea5e9;
  --ring-size: 188.5;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
  --transition: 0.2s ease;
}

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

html { font-size: 14px; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Header ─────────────────────────────────────────── */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 60px;
  background: rgba(6, 10, 20, 0.85);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.header-left, .header-right { display: flex; align-items: center; gap: 1rem; }
.header-center { flex: 1; display: flex; justify-content: center; }

.logo { display: flex; align-items: center; gap: 0.6rem; }
.logo-text {
  font-size: 1.3rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-indigo), var(--accent-violet));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.02em;
}

.cluster-select {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 2rem 0.5rem 1rem;
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  min-width: 240px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2394a3b8' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  transition: border-color var(--transition);
}
.cluster-select:hover { border-color: var(--accent-indigo); }
.cluster-select:focus { outline: none; border-color: var(--accent-indigo); box-shadow: 0 0 0 3px rgba(99,102,241,.15); }

.refresh-group { display: flex; align-items: center; gap: 0.5rem; }
.refresh-label { font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; }
.countdown { font-family: 'JetBrains Mono', monospace; color: var(--accent-indigo); }

/* Toggle */
.toggle { position: relative; width: 36px; height: 20px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--border); border-radius: 20px; transition: var(--transition);
}
.toggle-slider::before {
  content: ''; position: absolute; left: 2px; top: 2px;
  width: 16px; height: 16px; border-radius: 50%; background: white;
  transition: var(--transition);
}
.toggle input:checked + .toggle-slider { background: var(--accent-indigo); }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); }

/* ── Cache status ──────────────────────────────────── */
.cache-status {
  font-size: 0.72rem;
  font-family: 'JetBrains Mono', monospace;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  white-space: nowrap;
}
.cache-status.ready {
  color: var(--accent-emerald);
  background: rgba(16,185,129,.1);
}
.cache-status.loading-status {
  color: var(--accent-amber);
  background: rgba(245,158,11,.1);
  animation: pulse 2s ease-in-out infinite;
}
.cache-status.error {
  color: var(--accent-red);
  background: rgba(239,68,68,.1);
}
.cache-status.auth-expired {
  color: #f97316;
  background: rgba(249,115,22,.15);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

.auth-expired-banner {
  display: flex; align-items: flex-start; gap: 1rem;
  padding: 1.5rem; border-radius: var(--radius);
  background: rgba(249,115,22,.08); border: 1px solid rgba(249,115,22,.3);
  color: #f97316; grid-column: 1 / -1;
}
.auth-expired-banner svg { flex-shrink: 0; margin-top: 2px; }
.auth-expired-banner h3 { font-size: 1rem; font-weight: 600; margin-bottom: 0.4rem; color: #fb923c; }
.auth-expired-banner p { font-size: 0.85rem; color: var(--text-secondary); line-height: 1.5; }
.auth-expired-hint { margin-top: 0.5rem; font-size: 0.8rem !important; color: var(--text-muted) !important; }

.loading-sub {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 0.25rem;
}

/* ── Buttons ────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.5rem 1rem; border: none; border-radius: var(--radius-sm);
  font-family: inherit; font-size: 0.85rem; font-weight: 500;
  cursor: pointer; transition: all var(--transition); white-space: nowrap;
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent-indigo), var(--accent-violet));
  color: white;
}
.btn-primary:hover { filter: brightness(1.15); transform: translateY(-1px); }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; }
.btn-icon {
  background: none; border: none; color: var(--text-secondary); cursor: pointer;
  font-size: 1.5rem; line-height: 1; padding: 0.25rem; transition: color var(--transition);
}
.btn-icon:hover { color: white; }
.btn-danger {
  background: transparent; border: 1px solid var(--accent-red);
  color: var(--accent-red); padding: 0.3rem 0.6rem; border-radius: var(--radius-xs);
  font-size: 0.75rem; cursor: pointer; transition: all var(--transition);
}
.btn-danger:hover { background: var(--accent-red); color: white; }

/* ── Main ───────────────────────────────────────────── */
.main { padding: 1.5rem; max-width: 1480px; margin: 0 auto; }

.hidden { display: none !important; }

/* ── Empty State ────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: calc(100vh - 120px); text-align: center; gap: 1rem;
}
.empty-icon { opacity: 0.5; margin-bottom: 0.5rem; }
.empty-state h2 { font-size: 1.5rem; font-weight: 600; }
.empty-state p { color: var(--text-secondary); max-width: 360px; }

/* ── Loading ────────────────────────────────────────── */
.loading {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: calc(100vh - 120px); gap: 1rem;
}
.spinner {
  width: 40px; height: 40px; border: 3px solid var(--border);
  border-top-color: var(--accent-indigo); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Summary Section ────────────────────────────────── */
.summary-section {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 2rem;
}
.summary-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem;
  display: flex; align-items: center; gap: 1rem;
  transition: all var(--transition); position: relative; overflow: hidden;
}
.summary-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent-indigo), transparent);
  opacity: 0; transition: opacity var(--transition);
}
.summary-card:hover { border-color: var(--border-light); transform: translateY(-2px); box-shadow: var(--shadow); }
.summary-card:hover::before { opacity: 1; }

.summary-icon {
  width: 48px; height: 48px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.summary-icon.cpu { background: rgba(99,102,241,.12); color: var(--accent-indigo); }
.summary-icon.memory { background: rgba(139,92,246,.12); color: var(--accent-violet); }
.summary-icon.storage { background: rgba(16,185,129,.12); color: var(--accent-emerald); }
.summary-icon.info { background: rgba(14,165,233,.12); color: var(--accent-sky); }

.summary-body { flex: 1; min-width: 0; }
.summary-label { display: block; font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.35rem; }
.summary-value { display: block; font-size: 1.15rem; font-weight: 600; }
.summary-sub { display: block; font-size: 0.75rem; color: var(--text-secondary); margin-top: 0.15rem; }

.summary-rows { display: flex; flex-direction: column; gap: 0.2rem; }
.summary-metric-line {
  display: flex; align-items: center; gap: 0.35rem;
  font-family: 'JetBrains Mono', monospace; font-size: 0.78rem;
}
.sml-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.sml-dot.dot-used { background: var(--accent-indigo); }
.sml-dot.dot-req { background: #d97706; }
.sml-label { color: var(--text-muted); font-size: 0.68rem; width: 30px; flex-shrink: 0; }
.sml-value { color: var(--text-primary); font-weight: 500; flex: 1; }
.sml-pct { color: var(--text-secondary); font-size: 0.72rem; }
.summary-alloc { display: block; font-size: 0.68rem; color: var(--text-muted); margin-top: 0.25rem; }

.summary-ring { width: 68px; height: 68px; position: relative; flex-shrink: 0; }
.summary-ring svg { width: 100%; height: 100%; }
.ring-progress { transition: stroke-dashoffset 0.8s ease; }
.ring-req { transition: stroke-dashoffset 0.8s ease; }
.ring-text {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 600; font-family: 'JetBrains Mono', monospace;
  color: var(--text-secondary);
}

/* ── Section ────────────────────────────────────────── */
.section { margin-bottom: 2rem; }
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem;
}
.section-header h2 { font-size: 1.15rem; font-weight: 600; }
.badge {
  background: var(--accent-indigo); color: white; padding: 0.15rem 0.6rem;
  border-radius: 20px; font-size: 0.75rem; font-weight: 600;
}
.sort-group { display: flex; align-items: center; gap: 0.5rem; }
.sort-group label { font-size: 0.8rem; color: var(--text-muted); }
.select-small {
  background: var(--bg-input); color: var(--text-primary); border: 1px solid var(--border);
  border-radius: var(--radius-xs); padding: 0.35rem 1.5rem 0.35rem 0.6rem;
  font-size: 0.8rem; font-family: inherit; cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='8' height='5' viewBox='0 0 8 5' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l3 3 3-3' stroke='%2394a3b8' stroke-width='1.2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
}

/* ── Node Grid ──────────────────────────────────────── */
.nodes-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 1rem;
}
.node-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem;
  transition: all var(--transition); cursor: pointer;
}
.node-card:hover { border-color: var(--border-light); box-shadow: var(--shadow); }
.node-card.expanded {
  border-color: var(--accent-indigo);
}

.node-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.node-header-right { display: flex; align-items: center; gap: 0.5rem; }
.node-name { display: flex; align-items: center; gap: 0.5rem; }
.node-name h3 {
  font-size: 0.95rem; font-weight: 600; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 240px;
}
.expand-chevron {
  color: var(--text-muted); transition: transform 0.2s ease;
  flex-shrink: 0;
}
.node-card.expanded .expand-chevron { transform: rotate(180deg); color: var(--accent-indigo); }

.status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.status-dot.ready { background: var(--accent-emerald); box-shadow: 0 0 6px rgba(16,185,129,.5); }
.status-dot.not-ready { background: var(--accent-red); box-shadow: 0 0 6px rgba(239,68,68,.5); }

.node-roles { display: flex; gap: 0.3rem; }
.role-badge {
  background: rgba(99,102,241,.12); color: var(--accent-indigo);
  padding: 0.15rem 0.5rem; border-radius: 4px; font-size: 0.7rem; font-weight: 500;
}

.node-metrics { display: flex; flex-direction: column; gap: 0.75rem; }

.metric-row { display: flex; flex-direction: column; gap: 0.25rem; }
.metric-label {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 0.75rem;
}
.metric-label span:first-child { color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.metric-label span:last-child { font-family: 'JetBrains Mono', monospace; color: var(--text-secondary); }

.bar-group { display: flex; flex-direction: column; gap: 3px; }

.bar-line { display: flex; align-items: center; gap: 0.5rem; }
.bar-line-label {
  font-size: 0.65rem; color: var(--text-muted); width: 62px; flex-shrink: 0;
  text-align: right; font-family: 'JetBrains Mono', monospace;
}
.bar-line-label .bar-pct { color: var(--text-secondary); font-weight: 500; }
.bar-line .bar-track { flex: 1; }

.bar-track {
  height: 7px; background: var(--bg-primary); border-radius: 4px;
  overflow: hidden; position: relative;
}
.bar-fill {
  height: 100%; border-radius: 4px; transition: width 0.8s ease;
  position: relative;
}
.bar-fill::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent 50%, rgba(255,255,255,0.08));
}
.bar-fill.cpu { background: linear-gradient(90deg, #6366f1, #818cf8); }
.bar-fill.memory { background: linear-gradient(90deg, #8b5cf6, #a78bfa); }
.bar-fill.storage { background: linear-gradient(90deg, #10b981, #34d399); }
.bar-fill.req { background: linear-gradient(90deg, #d97706, #f59e0b); }
.bar-fill.warn { background: linear-gradient(90deg, #f59e0b, #fbbf24) !important; }
.bar-fill.danger { background: linear-gradient(90deg, #ef4444, #f87171) !important; }
.bar-fill.req.warn { background: linear-gradient(90deg, #d97706, #f59e0b) !important; filter: brightness(1.1); }
.bar-fill.req.danger { background: linear-gradient(90deg, #dc2626, #ef4444) !important; }

.metric-detail {
  display: flex; align-items: center; gap: 0.2rem;
  font-size: 0.7rem; font-family: 'JetBrains Mono', monospace;
  color: var(--text-secondary);
}
.detail-sep { color: var(--text-muted); opacity: 0.5; }

.node-footer {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 0.75rem; padding-top: 0.75rem; border-top: 1px solid var(--border);
  font-size: 0.75rem; color: var(--text-muted);
}

/* ── Pod Table ──────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius);
}
.pod-table { width: 100%; border-collapse: collapse; }
.pod-table th {
  text-align: left; padding: 0.75rem 1rem; font-size: 0.7rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted);
  background: var(--bg-secondary); border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
}
.pod-table th.num { text-align: right; }
.pod-table td {
  padding: 0.6rem 1rem; font-size: 0.82rem; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.pod-table td.num { text-align: right; font-family: 'JetBrains Mono', monospace; font-size: 0.78rem; }
.pod-table tbody tr { transition: background var(--transition); }
.pod-table tbody tr:hover { background: var(--bg-card-hover); }
.pod-table tbody tr:last-child td { border-bottom: none; }

.pod-name {
  max-width: 280px; overflow: hidden; text-overflow: ellipsis;
  font-weight: 500;
}
.ns-badge {
  background: rgba(99,102,241,.1); color: var(--accent-indigo);
  padding: 0.15rem 0.45rem; border-radius: 4px; font-size: 0.72rem;
}
.status-badge { padding: 0.15rem 0.45rem; border-radius: 4px; font-size: 0.72rem; font-weight: 500; }
.status-badge.running { background: rgba(16,185,129,.12); color: var(--accent-emerald); }
.status-badge.pending { background: rgba(245,158,11,.12); color: var(--accent-amber); }
.status-badge.other { background: rgba(100,116,139,.12); color: var(--text-muted); }

/* ── Modal ──────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.6); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
}
.modal {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); width: 520px; max-width: 90vw;
  max-height: 80vh; display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1.1rem; font-weight: 600; }
.modal-body { padding: 1.5rem; overflow-y: auto; }

.upload-zone {
  border: 2px dashed var(--border); border-radius: var(--radius-sm);
  padding: 2rem; text-align: center; cursor: pointer;
  transition: all var(--transition); display: flex; flex-direction: column;
  align-items: center; gap: 0.75rem;
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--accent-indigo); background: rgba(99,102,241,.05);
}
.upload-zone p { color: var(--text-secondary); font-size: 0.85rem; }
.upload-zone .link { color: var(--accent-indigo); text-decoration: underline; cursor: pointer; }

.upload-notice {
  display: flex; align-items: flex-start; gap: 0.5rem;
  margin-top: 0.75rem; padding: 0.6rem 0.75rem;
  background: rgba(99,102,241,.06); border: 1px solid rgba(99,102,241,.15);
  border-radius: var(--radius-sm); font-size: 0.78rem; color: var(--text-muted);
  line-height: 1.45;
}
.upload-notice svg { flex-shrink: 0; margin-top: 1px; color: var(--accent-indigo); opacity: 0.7; }
.upload-notice code {
  font-family: "JetBrains Mono", monospace; font-size: 0.72rem;
  background: rgba(99,102,241,.1); padding: 0.1rem 0.3rem; border-radius: 3px;
}

.config-list { margin-top: 1.5rem; display: flex; flex-direction: column; gap: 0.75rem; }
.config-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1rem; background: var(--bg-secondary);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.config-item-info { display: flex; flex-direction: column; gap: 0.15rem; }
.config-item-name { font-weight: 500; font-size: 0.9rem; }
.config-item-contexts { font-size: 0.75rem; color: var(--text-muted); }

/* ── Node Pods (expandable) ─────────────────────────── */
.node-pods {
  margin-top: 1rem; padding-top: 1rem;
  border-top: 1px solid var(--border);
  animation: fadeIn 0.25s ease both;
  max-height: 420px; overflow: auto;
}
.np-table {
  width: 100%; border-collapse: collapse; font-size: 0.75rem;
  font-family: "JetBrains Mono", monospace;
}
.np-table thead th {
  text-align: left; color: var(--text-muted); font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.04em; font-size: 0.65rem;
  padding: 0.35rem 0.5rem; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg-card); z-index: 1;
}
.np-table thead th.num, .np-table td.num { text-align: right; }
.np-table tbody tr { transition: background 0.15s ease; }
.np-table tbody tr:hover { background: rgba(255,255,255,.03); }
.np-table td {
  padding: 0.3rem 0.5rem; border-bottom: 1px solid rgba(255,255,255,.04);
  color: var(--text-secondary); white-space: nowrap;
}
.np-name {
  display: inline-block; max-width: 200px; overflow: hidden;
  text-overflow: ellipsis; color: var(--text-primary);
}
.np-empty { color: var(--text-muted); font-size: 0.85rem; text-align: center; padding: 1rem 0; }

/* ── Responsive ─────────────────────────────────────── */
@media (max-width: 1100px) {
  .summary-section { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  .header { flex-wrap: wrap; height: auto; padding: 0.75rem 1rem; gap: 0.5rem; }
  .header-center { order: 3; flex-basis: 100%; justify-content: flex-start; }
  .cluster-select { min-width: 0; width: 100%; }
  .summary-section { grid-template-columns: 1fr; }
  .nodes-grid { grid-template-columns: 1fr; }
  .header-right { gap: 0.5rem; }
}
@media (max-width: 480px) {
  .main { padding: 1rem; }
  .refresh-group { display: none; }
}

/* ── Animations ─────────────────────────────────────── */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.fade-in { animation: fadeIn 0.4s ease both; }
.node-card { animation: fadeIn 0.4s ease both; }
.node-card:nth-child(2) { animation-delay: 50ms; }
.node-card:nth-child(3) { animation-delay: 100ms; }
.node-card:nth-child(4) { animation-delay: 150ms; }
.node-card:nth-child(5) { animation-delay: 200ms; }
.node-card:nth-child(6) { animation-delay: 250ms; }
