:root {
  --bg: #0b1120;
  --bg-elev: #111827;
  --bg-card: #162033;
  --bg-input: #0f172a;
  --border: #26354d;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --accent: #38bdf8;
  --accent-strong: #0284c7;
  --success: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.32);
}

html[data-theme="light"] {
  --bg: #f1f5f9;
  --bg-elev: #ffffff;
  --bg-card: #ffffff;
  --bg-input: #f8fafc;
  --border: #cbd5e1;
  --text: #0f172a;
  --text-muted: #475569;
  --accent: #0284c7;
  --accent-strong: #0369a1;
  --success: #059669;
  --warn: #d97706;
  --danger: #dc2626;
  --shadow: 0 6px 20px rgba(15, 23, 42, 0.08);
}

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

html, body {
  margin: 0;
  padding: 0;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.brand-title {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
}

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

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

.nav-btn {
  appearance: none;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.nav-btn:hover {
  background: rgba(56, 189, 248, 0.08);
  color: var(--text);
}

.nav-btn.active {
  background: rgba(56, 189, 248, 0.14);
  border-color: rgba(56, 189, 248, 0.35);
  color: var(--text);
  font-weight: 600;
}

.nav-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.nav-pill {
  margin-left: auto;
  background: var(--warn);
  color: #0f172a;
  font-weight: 700;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.watcher-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.status-led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}

.status-led.off {
  background: var(--text-muted);
}

/* Main Workspace */
.main-area {
  padding: 24px 28px 48px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.view-section {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

.section-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
}

.section-header h1, .hero-card h1 {
  margin: 0 0 4px;
  font-size: 22px;
  letter-spacing: -0.02em;
}

h2 {
  margin: 0 0 10px;
  font-size: 16px;
}

h3 {
  margin: 0 0 6px;
  font-size: 14px;
}

p {
  margin: 0 0 8px;
}

.muted {
  color: var(--text-muted);
}

.tiny {
  font-size: 12px;
}

/* Grids & Cards */
.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.card, .hero-card, .stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.hero-card {
  background: linear-gradient(145deg, var(--bg-card), var(--bg-elev));
  padding: 24px;
}

.stat-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
}

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

.card-title-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.card-title-row h2 {
  margin: 0;
}

/* Meters */
.meter {
  width: 100%;
  height: 8px;
  background: var(--bg-input);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.meter-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.25s ease;
}

/* Buttons & Inputs */
.header-actions, .btn-group, .action-row, .hub-download-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--bg-elev);
  color: var(--text);
  transition: opacity 0.15s, border-color 0.15s, background 0.15s;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
  opacity: 0.92;
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--accent);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.16);
  border-color: var(--danger);
  color: #fca5a5;
}

html[data-theme="light"] .btn-danger {
  color: var(--danger);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-lg {
  padding: 11px 18px;
  font-size: 14px;
}

.icon-btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  align-items: center;
}

.input-text, .input-select, .input-area {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 11px;
  font-size: 13px;
  min-width: 0;
}

.input-text {
  flex: 1 1 210px;
}

.input-sm {
  flex: 0 1 240px;
  padding: 6px 10px;
}

.input-area {
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  margin-bottom: 10px;
}

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

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  cursor: pointer;
}

/* Sub-tabs */
.subtab-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
}

.subtab-btn {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.subtab-btn.active {
  background: var(--accent-strong);
  border-color: var(--accent);
  color: #ffffff;
}

/* Tables & Lists */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th, .data-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

.data-table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.path-cell {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  color: var(--text-muted);
  overflow-wrap: anywhere;
  word-break: break-word;
  max-width: 420px;
}

.stack-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.list-item {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 12px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.code-box {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.code-box code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
  word-break: break-word;
  min-width: 0;
  flex: 1 1 180px;
}

.log-pre {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  max-height: 210px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Badges & Banners */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.badge-high, .badge-ok {
  background: rgba(16, 185, 129, 0.16);
  color: #34d399;
}

.badge-warn, .badge-med {
  background: rgba(245, 158, 11, 0.18);
  color: #fbbf24;
}

.badge-danger {
  background: rgba(239, 68, 68, 0.18);
  color: #f87171;
}

.badge-info {
  background: rgba(56, 189, 248, 0.16);
  color: var(--accent);
}

html[data-theme="light"] .badge-high, html[data-theme="light"] .badge-ok { color: #047857; }
html[data-theme="light"] .badge-warn, html[data-theme="light"] .badge-med { color: #b45309; }
html[data-theme="light"] .badge-danger { color: #b91c1c; }

.alert-banner {
  background: rgba(245, 158, 11, 0.14);
  border: 1px solid var(--warn);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.toast {
  position: fixed;
  bottom: 18px;
  right: 18px;
  max-width: min(420px, calc(100vw - 32px));
  background: var(--bg-elev);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 11px 15px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 120;
  font-size: 13px;
}

.toast.error {
  border-color: var(--danger);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  z-index: 100;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: min(760px, calc(100vw - 24px));
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.modal-header, .modal-footer {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.modal-footer {
  border-bottom: none;
  border-top: 1px solid var(--border);
  justify-content: flex-end;
}

.modal-body {
  padding: 14px 18px;
  overflow-y: auto;
  flex: 1;
}

/* Responsive Breakpoints down to 375px */
@media (max-width: 1024px) {
  .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid-3 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 12px 14px;
    gap: 10px;
  }
  .nav-list {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
  }
  .nav-btn {
    padding: 7px 10px;
    font-size: 12px;
  }
  .sidebar-footer {
    display: none;
  }
  .main-area {
    padding: 16px 14px 40px;
  }
  .grid-2, .grid-4 {
    grid-template-columns: 1fr;
  }
}
