:root {
  --bg: #0b0f17;
  --panel: #121826;
  --panel-alt: #182032;
  --border: #253047;
  --text: #e6edf7;
  --muted: #8b9bb4;
  --cyan: #38bdf8;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --violet: #a78bfa;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
  background: #0e1420ee;
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 8px var(--amber);
}
.brand-dot.live { background: var(--green); box-shadow: 0 0 10px var(--green); }
.brand-title { font-weight: 700; letter-spacing: .06em; font-size: 14px; }
.brand-sub { font-size: 11px; color: var(--muted); }

.cluster-ticker { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.ticker-item { display: flex; flex-direction: column; }
.ticker-label { font-size: 10px; text-transform: uppercase; color: var(--muted); letter-spacing: .05em; }
.ticker-value { font-weight: 600; font-variant-numeric: tabular-nums; }
.progress-rail { width: 110px; height: 6px; background: #1e293b; border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--cyan), var(--green)); transition: width .4s; }

.accent-cyan { color: var(--cyan); }
.accent-green { color: var(--green); }
.pos { color: var(--green); }
.neg { color: var(--red); }
.warn { color: var(--amber); }

.tabs { display: flex; gap: 6px; }
.tab-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  padding: 7px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
}
.tab-btn:hover { color: var(--text); background: var(--panel); }
.tab-btn.active {
  color: var(--cyan);
  background: #132238;
  border-color: #1f3b5c;
}
.badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 99px;
  background: #1e293b;
  color: var(--cyan);
  font-size: 11px;
  margin-left: 4px;
}

.container { padding: 14px 20px 32px; max-width: 1760px; margin: 0 auto; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.preset-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.preset-title { color: var(--muted); font-weight: 600; }
.chip {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 99px;
  font-size: 12px;
  cursor: pointer;
}
.chip:hover { border-color: var(--cyan); color: var(--cyan); }
.active-fleet-picker { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.active-fleet-picker label { color: var(--muted); font-size: 12px; }

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 10px;
}
.fgroup { display: flex; flex-direction: column; gap: 4px; }
.fgroup label { font-size: 11px; color: var(--muted); }
.fgroup input, .fgroup select, .fleet-form input, .active-fleet-picker select {
  background: #0d1320;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 6px 8px;
  font-size: 12px;
}
.fcheck { justify-content: flex-end; gap: 6px; }
.fcheck label { display: flex; align-items: center; gap: 6px; color: var(--text); font-size: 12px; }

.btn-primary {
  background: #0284c7; color: #fff; border: none; border-radius: 6px;
  padding: 7px 12px; font-weight: 600; cursor: pointer;
}
.btn-primary:hover { background: #0ea5e9; }
.btn-secondary {
  background: #1e293b; color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 12px; cursor: pointer; font-weight: 600;
}
.btn-secondary:hover { border-color: var(--cyan); }
.btn-ghost {
  background: transparent; color: var(--muted); border: 1px solid var(--border);
  border-radius: 5px; padding: 4px 9px; cursor: pointer; font-size: 12px;
}
.btn-ghost:hover { color: var(--text); border-color: var(--cyan); }
.btn-danger {
  background: #3f151b; color: #fca5a5; border: 1px solid #7f1d1d;
  border-radius: 5px; padding: 4px 8px; cursor: pointer; font-size: 11px;
}

.table-meta {
  display: flex; justify-content: space-between; align-items: center;
  margin: 8px 0; color: var(--muted);
}
.pager { display: flex; align-items: center; gap: 8px; }

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: auto;
  max-height: 70vh;
}

.data-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.data-table th {
  position: sticky; top: 0; z-index: 2;
  background: #151d2e;
  color: var(--muted);
  text-align: left;
  padding: 7px 7px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  text-transform: uppercase;
  white-space: nowrap;
  cursor: pointer;
}
.data-table th.num, .data-table td.num { text-align: right; }
.data-table td {
  padding: 6px 7px;
  border-bottom: 1px solid #1d2638;
  white-space: nowrap;
  font-size: 12px;
}
.data-table td:first-child { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.data-table td:first-child .muted { overflow: hidden; text-overflow: ellipsis; }
.data-table tbody tr:hover { background: #1a2438; cursor: pointer; }
.data-table th.sorted-desc::after { content: " ▼"; color: var(--cyan); }
.data-table th.sorted-asc::after { content: " ▲"; color: var(--cyan); }
.pill {
  display: inline-block; padding: 2px 6px; border-radius: 4px;
  font-size: 11px; font-weight: 600; background: #1e293b; color: var(--muted);
}
.pill-5pm { background: #0f2f21; color: var(--green); }
.pill-hold { background: #2c2112; color: var(--amber); }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
}
.card h3 { margin: 0 0 8px; font-size: 15px; }
.muted { color: var(--muted); font-size: 12px; }
.section-grid { display: flex; flex-direction: column; gap: 14px; }

.node-actions-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.nodes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(430px, 1fr)); gap: 14px; }
.node-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
}
.node-card.online { border-color: #1d4d3a; }
.node-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; }
.node-name { font-size: 15px; font-weight: 700; }
.node-status-tag { padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 700; }
.node-status-tag.online { background: #0f3a24; color: var(--green); }
.node-status-tag.offline { background: #2d1b20; color: var(--red); }
.node-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 10px 0; }
.stat-mini { background: #0d1320; padding: 6px 8px; border-radius: 5px; }
.stat-mini .k { font-size: 10px; color: var(--muted); text-transform: uppercase; }
.stat-mini .v { font-weight: 700; margin-top: 2px; }

.slots-list { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; max-height: 220px; overflow-y: auto; }
.slot-row {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  background: #0d1320; border: 1px solid #1e293b; border-radius: 5px;
  padding: 5px 8px; font-size: 11px;
}
.slot-id { color: var(--cyan); font-weight: 700; min-width: 48px; }
.slot-job { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot-el { color: var(--muted); font-variant-numeric: tabular-nums; flex-shrink: 0; }

.fleet-layout { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 16px; }
.fleet-form { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.fleet-form input { width: 100%; min-width: 0; }
.row2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 6px; }
.fleets-list { display: flex; flex-direction: column; gap: 8px; }
.fleet-item-card {
  background: #0d1320; border: 1px solid var(--border); border-radius: 6px;
  padding: 10px; cursor: pointer;
}
.fleet-item-card.selected { border-color: var(--cyan); background: #132238; }

.modal { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-backdrop { position: fixed; inset: 0; background: #000000aa; }
.modal-dialog {
  position: relative; z-index: 61;
  width: min(1280px, 95vw);
  max-height: 92vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
}
.modal-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; gap: 12px; }
.modal-header h2 { margin: 0; font-size: 18px; }
.modal-actions { display: flex; gap: 8px; }
.kpi-strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-bottom: 14px; }
.kpi-card { background: #0d1320; border: 1px solid #1e293b; border-radius: 6px; padding: 8px 10px; }
.kpi-card .k { font-size: 10px; color: var(--muted); text-transform: uppercase; }
.kpi-card .v { font-size: 15px; font-weight: 700; margin-top: 2px; }
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.chart-card { background: #0d1320; border: 1px solid #1e293b; border-radius: 8px; padding: 10px; }
.chart-card.wide { grid-column: span 2; }
.chart-title { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.chart-box { width: 100%; height: 240px; }
.ledger-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }

.pill-ro { background: #2d2010; color: var(--amber); border: 1px solid #92400e; margin-left: 6px; vertical-align: middle; }
.hidden { display: none !important; }
body.readonly-mode .write-only { display: none !important; }
.mobile-only { display: none; }
.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.mobile-runs-list { display: none; flex-direction: column; gap: 10px; }
.mrun-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  cursor: pointer;
}
.mrun-card:active { border-color: var(--cyan); background: #172133; }
.mrun-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 6px; }
.mrun-np { text-align: right; font-variant-numeric: tabular-nums; }
.mrun-sub { font-size: 11px; color: var(--muted); margin-bottom: 8px; line-height: 1.35; }
.mrun-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.mrun-cell { background: #0d1320; border-radius: 5px; padding: 5px 7px; }
.mrun-cell .k { font-size: 9px; text-transform: uppercase; color: var(--muted); }
.mrun-cell .v { font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 1px; }

@media (max-width: 860px) {
  .topbar { padding: 10px 12px; gap: 10px; }
  .brand-title { font-size: 13px; }
  .cluster-ticker { width: 100%; display: grid; grid-template-columns: auto auto minmax(0, 1fr); gap: 8px 14px; }
  .progress-rail { grid-column: span 3; width: 100%; }
  .tabs { width: 100%; overflow-x: auto; padding-bottom: 2px; gap: 4px; scrollbar-width: none; }
  .tabs::-webkit-scrollbar, .preset-bar::-webkit-scrollbar { display: none; }
  .tab-btn { flex: 1 0 auto; padding: 7px 10px; font-size: 12px; }
  .container { padding: 10px 10px 28px; }
  .mobile-only { display: inline-flex; align-items: center; }
  .preset-title { display: none; }
  .preset-bar { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .chip { flex: 0 0 auto; white-space: nowrap; }
  .filter-grid { display: none; grid-template-columns: 1fr 1fr; }
  .filter-grid.open { display: grid; }
  .table-meta { flex-direction: column; align-items: flex-start; gap: 8px; }
  .table-wrap { display: none; }
  .mobile-runs-list { display: flex; }
  .nodes-grid { grid-template-columns: minmax(0, 1fr); }
  .node-card { min-width: 0; }
  .node-stats { grid-template-columns: repeat(2, 1fr); }
  .node-actions-bar { flex-direction: column; align-items: flex-start; gap: 8px; }
  .slot-row { flex-wrap: wrap; gap: 3px 8px; }
  .slot-id { order: 1; }
  .slot-el { order: 2; margin-left: auto; }
  .slot-job { order: 3; flex: 1 1 100%; white-space: normal; word-break: break-word; line-height: 1.3; }
  .fleet-layout { grid-template-columns: 1fr; }
  .modal-dialog { width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; padding: 12px; }
  .modal-header { flex-direction: column; gap: 8px; }
  .charts-grid { grid-template-columns: 1fr; }
  .chart-card.wide { grid-column: span 1; }
  .chart-box { height: 210px; }
  .kpi-strip { grid-template-columns: repeat(2, 1fr); }
}
