/* ========== CSS Custom Properties (Themes) ========== */
:root,
[data-theme="dark"] {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #1c2128;
  --bg-hover: #252c35;
  --border: #30363d;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --accent: #4a8cff;
  --accent-hover: #5a9aff;
  --healthy: #238636;
  --healthy-bg: rgba(35,134,54,.15);
  --warning: #d29922;
  --warning-bg: rgba(210,153,34,.15);
  --critical: #f85149;
  --critical-bg: rgba(248,81,73,.15);
  --offline: #6e7681;
  --offline-bg: rgba(110,118,129,.15);
  --maintenance: #8957e5;
  --maintenance-bg: rgba(137,87,229,.15);
  --bar-bg: #21262d;
  --bar-healthy: #238636;
  --bar-warning: #d29922;
  --bar-critical: #f85149;
  --shadow: 0 1px 3px rgba(0,0,0,.3);
  --radius: 8px;
  --radius-sm: 4px;
}

[data-theme="light"] {
  --bg-primary: #f6f8fa;
  --bg-secondary: #ffffff;
  --bg-tertiary: #ffffff;
  --bg-hover: #f0f2f5;
  --border: #d0d7de;
  --text-primary: #1f2328;
  --text-secondary: #656d76;
  --text-muted: #8b949e;
  --accent: #0969da;
  --accent-hover: #0550ae;
  --healthy: #1a7f37;
  --healthy-bg: rgba(26,127,55,.1);
  --warning: #9a6700;
  --warning-bg: rgba(154,103,0,.1);
  --critical: #cf222e;
  --critical-bg: rgba(207,34,46,.1);
  --offline: #6e7681;
  --offline-bg: rgba(110,118,129,.1);
  --maintenance: #8250df;
  --maintenance-bg: rgba(130,80,223,.1);
  --bar-bg: #e1e4e8;
  --bar-healthy: #1a7f37;
  --bar-warning: #9a6700;
  --bar-critical: #cf222e;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
}

/* ========== Reset & Base ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ========== Login Page ========== */
.login-body { justify-content: center; align-items: center; }

.login-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 32px;
  color: var(--text-primary);
}

.login-logo svg { color: var(--accent); }

.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
}

.form-group input:focus { border-color: var(--accent); }

.login-error {
  color: var(--critical);
  font-size: 13px;
  margin-bottom: 12px;
  padding: 8px 12px;
  background: var(--critical-bg);
  border-radius: var(--radius-sm);
}

.btn-primary {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}

.login-card .btn-primary { width: 100%; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }

.btn-secondary {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s;
}

.btn-secondary:hover { background: var(--bg-hover); }

/* ========== Sidebar ========== */
.sidebar {
  width: 220px;
  min-height: 100vh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 0;
  flex-shrink: 0;
  transition: width .25s ease;
  overflow: hidden;
  position: relative;
}

.sidebar.collapsed { width: 56px; }

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 20px 16px;
  font-weight: 700;
  font-size: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
  white-space: nowrap;
}

.sidebar.collapsed .sidebar-logo {
  padding: 0 4px 20px;
  gap: 0;
  justify-content: center;
}

.sidebar-logo svg { color: var(--accent); flex-shrink: 0; }
.sidebar.collapsed .sidebar-logo > svg { display: none; }

.sidebar-label {
  opacity: 1;
  transition: opacity .2s ease;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar.collapsed .sidebar-label { opacity: 0; pointer-events: none; width: 0; }

.sidebar-toggle {
  margin-left: auto;
  flex-shrink: 0;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .12s, color .12s;
  padding: 0;
}

.sidebar-toggle:hover { background: var(--bg-hover); color: var(--text-primary); }
.sidebar-toggle svg { transition: transform .25s ease; }
.sidebar.collapsed .sidebar-toggle svg { transform: rotate(180deg); }

.sidebar-nav { padding: 8px 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background .12s, color .12s;
  white-space: nowrap;
}

.nav-item svg { flex-shrink: 0; }

.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active { color: var(--accent); background: var(--bg-hover); }

.sidebar-health {
  margin-top: auto;
  padding: 16px;
  border-top: 1px solid var(--border);
  overflow: hidden;
}

.sidebar.collapsed .sidebar-health { padding: 8px; }
.sidebar.collapsed .health-label,
.sidebar.collapsed .health-row,
.sidebar.collapsed .health-counts { display: none; }

.health-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: .5px;
  margin-bottom: 12px;
}

.health-row { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 8px; }
.health-row span:last-child { font-weight: 700; }

.health-bar-container {
  height: 4px;
  background: var(--bar-bg);
  border-radius: 2px;
  margin-bottom: 10px;
  overflow: hidden;
}

.health-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width .5s ease;
}

.health-counts {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  align-items: center;
}

.dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.dot-healthy { background: var(--healthy); }
.dot-warning { background: var(--warning); }
.dot-critical { background: var(--critical); }
.dot-offline { background: var(--offline); }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}

.sidebar.collapsed .sidebar-footer { justify-content: center; padding: 12px 8px; }

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .12s, color .12s;
}

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

/* ========== Main Content ========== */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 24px 32px;
  min-width: 0;
}

.main-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
}

.main-header h1 { font-size: 24px; font-weight: 700; margin-top: 4px; }

.live-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: .5px;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--healthy);
  display: inline-block;
  animation: pulse 2s infinite;
}

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 260px;
}

.search-box svg { color: var(--text-muted); flex-shrink: 0; }

.search-box input {
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  width: 100%;
}

.search-box input::placeholder { color: var(--text-muted); }

/* ========== Filters ========== */
.filters { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }

.filter-btn {
  padding: 6px 16px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.filter-btn:hover { border-color: var(--text-muted); color: var(--text-primary); }

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

.filter-count {
  background: rgba(255,255,255,.2);
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
}

.filter-btn:not(.active) .filter-count { background: var(--bg-hover); }

/* ========== Table ========== */
.table-container { flex: 1; overflow-x: auto; }

.node-table { width: 100%; border-collapse: collapse; table-layout: fixed; }

.node-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: .5px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  user-select: none;
}

.node-table th.sortable {
  cursor: pointer;
  transition: color .12s;
}

.node-table th.sortable:hover { color: var(--text-primary); }

.node-table th.sortable.sort-asc .sort-icon::after { content: ' \2191'; }
.node-table th.sortable.sort-desc .sort-icon::after { content: ' \2193'; }

.col-node { width: 22%; }
.col-status { width: 11%; }
.col-cpu { width: 17%; }
.col-network { width: 17%; }
.col-ram { width: 13%; }
.col-disk { width: 13%; }
.col-actions { width: 7%; text-align: center; }

.node-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  vertical-align: middle;
}

.node-table tbody tr { transition: background .1s; }
.node-table tbody tr:hover { background: var(--bg-hover); }

.loading-cell {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 12px !important;
}

.node-info-name { font-weight: 600; color: var(--text-primary); }
.node-info-flag { margin-right: 4px; }
.node-info-ip { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.node-info-latency { font-size: 11px; color: var(--text-muted); }

.node-info-panel {
  display: inline-block;
  max-width: 180px;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .4px;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--bg-hover);
  border: 1px solid var(--border);
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Status badges */
.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .3px;
  white-space: nowrap;
}

.status-healthy { background: var(--healthy-bg); color: var(--healthy); }
.status-warning { background: var(--warning-bg); color: var(--warning); }
.status-critical { background: var(--critical-bg); color: var(--critical); }
.status-offline { background: var(--offline-bg); color: var(--offline); }
.status-maintenance { background: var(--maintenance-bg); color: var(--maintenance); }

/* Metric cell with sparkline */
.metric-cell { display: flex; align-items: center; gap: 10px; }

.metric-sparkline { width: 80px; height: 28px; flex-shrink: 0; }

.metric-value { font-weight: 600; font-size: 14px; white-space: nowrap; }
.metric-value.val-healthy { color: var(--text-primary); }
.metric-value.val-warning { color: var(--warning); }
.metric-value.val-critical { color: var(--critical); }

.network-sub { font-size: 11px; color: var(--text-muted); margin-top: 1px; }

/* Progress bar metric */
.bar-metric { display: flex; align-items: center; gap: 10px; }

.progress-bar-track {
  flex: 1;
  height: 6px;
  background: var(--bar-bg);
  border-radius: 3px;
  overflow: hidden;
  min-width: 50px;
}

.progress-bar-fill { height: 100%; border-radius: 3px; transition: width .5s ease; }

.bar-label {
  font-weight: 600;
  font-size: 13px;
  min-width: 42px;
  text-align: right;
  white-space: nowrap;
}

/* Expandable node detail row */
.node-table tbody tr.node-row { cursor: pointer; }

.node-detail-row td {
  padding: 0 !important;
  border-bottom: 1px solid var(--border);
}

.node-detail-inner {
  max-height: 0;
  overflow: hidden;
  transition: max-height .3s ease, padding .3s ease;
  padding: 0 16px;
}

.node-detail-row.expanded .node-detail-inner {
  max-height: 400px;
  padding: 16px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.detail-card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.detail-card-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: .3px;
  margin-bottom: 4px;
}

.detail-card-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.detail-card-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Maintenance toggle */
.maint-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .12s;
  font-size: 14px;
}

.maint-toggle:hover { background: var(--bg-hover); color: var(--text-primary); }
.maint-toggle.active { background: var(--maintenance-bg); color: var(--maintenance); border-color: var(--maintenance); }

/* ========== Footer ========== */
.main-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0 0;
  border-top: 1px solid var(--border);
  margin-top: 16px;
}

.footer-info { display: flex; align-items: center; gap: 24px; font-size: 13px; color: var(--text-muted); }
.global-status { display: flex; align-items: center; gap: 6px; }
.global-status strong { color: var(--text-primary); }

.footer-controls { display: flex; align-items: center; gap: 16px; }

.per-page-selector {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.per-page-selector select {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  outline: none;
}

.per-page-selector select:focus { border-color: var(--accent); }

.pagination { display: flex; gap: 4px; }

.page-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all .12s;
}

.page-btn:hover { border-color: var(--text-muted); color: var(--text-primary); }
.page-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ========== Settings Page ========== */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.settings-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.settings-card h2 { font-size: 16px; font-weight: 600; margin-bottom: 16px; }
.settings-card-wide { grid-column: 1 / -1; }

.form-row { display: flex; align-items: center; gap: 12px; margin-top: 8px; }

.form-hint { font-size: 12px; color: var(--text-muted); }

.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 14px;
}

.toggle-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.maintenance-list { display: flex; flex-direction: column; gap: 6px; }

.maint-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.maint-item code { font-size: 13px; }

.btn-remove {
  background: none;
  border: none;
  color: var(--critical);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.btn-remove:hover { opacity: .7; }

.maintenance-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
}

.maintenance-input:focus { border-color: var(--accent); }

/* ========== Overview Page ========== */
.overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 32px;
}

.ov-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  transition: transform .12s, box-shadow .12s;
  overflow: hidden;
}

.ov-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,.15); }

.ov-card-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--bg-hover);
  color: var(--text-muted);
}

.ov-card-icon svg { width: 20px; height: 20px; }

.ov-card-accent .ov-card-icon { background: rgba(74,140,255,.15); color: var(--accent); }
.ov-card-healthy .ov-card-icon { background: var(--healthy-bg); color: var(--healthy); }
.ov-card-warning .ov-card-icon { background: var(--warning-bg); color: var(--warning); }
.ov-card-critical .ov-card-icon { background: var(--critical-bg); color: var(--critical); }
.ov-card-offline .ov-card-icon { background: var(--offline-bg); color: var(--offline); }

.ov-card-body { min-width: 0; overflow: hidden; }

.ov-card-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: .5px;
  margin-bottom: 2px;
}

.ov-card-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ov-card-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.overview-section { margin-bottom: 28px; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 14px;
}

.section-header .section-title { margin-bottom: 0; }

.section-link {
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

.section-link:hover { text-decoration: underline; }

.avg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.avg-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.avg-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: .5px;
  min-width: 60px;
}

.avg-bar-wrap { flex: 1; }

.avg-value {
  font-size: 15px;
  font-weight: 700;
  min-width: 48px;
  text-align: right;
  color: var(--text-primary);
}

/* ========== Mobile Menu Button & Overlay ========== */
.mobile-menu-btn {
  display: none;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: background .12s, color .12s;
  flex-shrink: 0;
  padding: 0;
  z-index: 1001;
}

.mobile-menu-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .5);
  z-index: 999;
  opacity: 0;
  transition: opacity .25s ease;
}

.sidebar-backdrop.visible {
  display: block;
  opacity: 1;
}

/* ========== Responsive ========== */
@media (max-width: 900px) {
  .mobile-menu-btn { display: flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1000;
    height: 100vh;
    width: 260px;
    transform: translateX(-100%);
    transition: transform .3s ease;
    box-shadow: none;
  }

  .sidebar.collapsed { width: 260px; }
  .sidebar.collapsed .sidebar-label { opacity: 1; pointer-events: auto; width: auto; }
  .sidebar.collapsed .sidebar-logo > svg { display: block; }
  .sidebar.collapsed .sidebar-health { padding: 16px; }
  .sidebar.collapsed .health-label,
  .sidebar.collapsed .health-row,
  .sidebar.collapsed .health-counts { display: flex; }
  .sidebar.collapsed .sidebar-footer { justify-content: flex-start; padding: 12px 16px; }

  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, .3);
  }

  .sidebar-toggle { display: none; }

  .main { padding: 16px; }

  .main-header {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
  }

  .header-actions { width: 100%; order: 3; }
  .search-box { width: 100%; }

  .settings-grid { grid-template-columns: 1fr; }

  .overview-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }

  .avg-grid { grid-template-columns: 1fr; }

  .main-footer {
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
  }

  .footer-info {
    flex-direction: column;
    gap: 8px;
  }

  .footer-controls {
    justify-content: space-between;
  }

  .detail-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }

  .filters { gap: 6px; }
  .filter-btn { padding: 5px 12px; font-size: 12px; }
}

@media (max-width: 600px) {
  .main { padding: 12px; }
  .main-header h1 { font-size: 20px; }

  /* ── Overview cards ── */
  .overview-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 20px; }
  .ov-card { padding: 12px; gap: 8px; }
  .ov-card-icon { width: 32px; height: 32px; }
  .ov-card-icon svg { width: 16px; height: 16px; }
  .ov-card-value { font-size: 18px; }
  .ov-card-label { font-size: 9px; }

  .avg-card { padding: 14px 16px; }

  .overview-section { margin-bottom: 20px; }
  .section-header { flex-direction: column; align-items: flex-start; gap: 6px; }

  /* ── Table: hide network, disk, actions columns ── */
  .node-table { table-layout: auto; }
  .col-node, .col-status, .col-cpu, .col-ram { width: auto; }

  .col-network, .col-disk, .col-actions { display: none; }
  .node-table td:nth-child(4),
  .node-table th:nth-child(4),
  .node-table td:nth-child(6),
  .node-table th:nth-child(6),
  .node-table td:nth-child(7),
  .node-table th:nth-child(7) { display: none; }

  /* ── Hide sparklines on mobile ── */
  .metric-sparkline { display: none; }
  .metric-cell { gap: 0; }

  /* ── Hide progress bar track, show just the label ── */
  .bar-metric .progress-bar-track { display: none; }
  .bar-label { min-width: auto; text-align: left; }

  .node-table th { padding: 8px 6px; font-size: 10px; letter-spacing: 0; }
  .node-table td { padding: 10px 6px; font-size: 13px; }

  /* ── Node info: panel badge on own line ── */
  .node-info-name { font-size: 13px; word-break: break-word; }
  .node-info-panel {
    display: block;
    margin-left: 0;
    margin-top: 3px;
    max-width: fit-content;
    font-size: 8px;
  }
  .node-info-ip { font-size: 11px; }
  .node-info-latency { display: none; }

  /* ── Status badge compact ── */
  .status-badge { padding: 2px 6px; font-size: 9px; letter-spacing: 0; }

  /* ── Detail panel ── */
  .detail-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .detail-card { padding: 10px; }
  .detail-card-value { font-size: 16px; }
  .node-detail-row.expanded .node-detail-inner { padding: 12px; }

  /* ── Footer ── */
  .pagination { flex-wrap: wrap; }
  .page-btn { width: 28px; height: 28px; font-size: 12px; }
  .footer-controls { flex-direction: column; gap: 10px; align-items: flex-start; }

  /* ── Settings ── */
  .settings-card { padding: 16px; }
  .settings-card h2 { font-size: 15px; }
  .form-row { flex-direction: column; align-items: stretch; gap: 8px; }
  .form-row .btn-secondary { align-self: flex-start; }

  /* ── Login ── */
  .login-card { padding: 24px 20px; margin: 16px; }
}

@media (max-width: 420px) {
  /* ── Hide RAM column on very small screens ── */
  .node-table td:nth-child(5),
  .node-table th:nth-child(5) { display: none; }

  .overview-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }

  .filters { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
  .filter-btn { flex-shrink: 0; }
}
