:root {
  color-scheme: dark;
  --bg: #0a0d12;
  --bg-2: #10151d;
  --panel: rgba(18, 23, 31, 0.92);
  --panel-2: rgba(22, 28, 38, 0.96);
  --field: rgba(7, 10, 15, 0.72);
  --text: #eef3f8;
  --muted: #9aa7b5;
  --line: rgba(154, 167, 181, 0.18);
  --line-strong: rgba(154, 167, 181, 0.28);
  --primary: #3dd6c6;
  --primary-2: #5ea1ff;
  --good: #3ddc97;
  --bad: #ff647c;
  --warn: #f4c95d;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.34);
  --radius: 10px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #0c1118 0%, var(--bg) 42%, #090b10 100%);
  color: var(--text);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select { font: inherit; }
a { color: inherit; text-decoration: none; }

.app-shell { display: grid; grid-template-columns: 264px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 20px;
  border-right: 1px solid var(--line);
  background: rgba(8, 11, 16, 0.92);
}
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 26px; }
.brand-mark {
  display: grid; place-items: center;
  width: 42px; height: 42px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--warn));
  color: #071014;
  font-weight: 900;
  box-shadow: 0 12px 28px rgba(61, 214, 198, 0.18);
}
.brand-title { font-size: 17px; font-weight: 850; letter-spacing: 0; }
.brand-subtitle { color: var(--muted); font-size: 12px; }
.nav-stack { display: grid; gap: 6px; margin-bottom: 22px; }
.nav-item {
  padding: 10px 11px;
  border-radius: 8px;
  color: var(--muted);
  border: 1px solid transparent;
  font-weight: 750;
}
.nav-item:hover, .nav-item.active {
  color: var(--text);
  background: rgba(61, 214, 198, 0.10);
  border-color: rgba(61, 214, 198, 0.24);
}
.sidebar-card {
  margin-top: auto;
  padding: 14px;
  border: 1px solid var(--line);
  background: rgba(16, 21, 29, 0.78);
  border-radius: var(--radius);
}
.sidebar-card-title { font-weight: 700; margin-bottom: 12px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; color: var(--muted); }
.switch input { display: none; }
.switch span {
  position: relative; display: block; width: 46px; height: 26px; border-radius: 99px;
  background: rgba(148, 163, 184, .25); border: 1px solid var(--line);
}
.switch span::after {
  content: ""; position: absolute; width: 20px; height: 20px; border-radius: 50%; top: 2px; left: 3px;
  background: #fff; transition: transform .2s ease;
}
.switch input:checked + span { background: linear-gradient(135deg, var(--primary), var(--primary-2)); }
.switch input:checked + span::after { transform: translateX(18px); }

.main { padding: 22px; min-width: 0; }
.panel, .kpi-card, .chart-card {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel { padding: 18px; margin-bottom: 16px; }
.glow { position: relative; overflow: hidden; }
.glow::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-top: 1px solid rgba(61, 214, 198, .32);
}
.hero { display: flex; align-items: center; justify-content: space-between; gap: 24px; min-height: 132px; }
.eyebrow { margin: 0 0 7px; color: var(--primary); text-transform: uppercase; letter-spacing: .11em; font-size: 11px; font-weight: 850; }
h1, h2 { margin: 0; letter-spacing: 0; line-height: 1.08; }
h1 { font-size: clamp(30px, 4vw, 52px); max-width: 780px; }
h2 { font-size: 24px; }
.hero-copy { color: var(--muted); max-width: 760px; margin: 11px 0 0; font-size: 15px; }
.hero-actions, .toolbar { display: flex; align-items: end; gap: 10px; flex-wrap: wrap; }
.toolbar.compact label { min-width: 160px; }
.hero-signal-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.signal-chip {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #d7e1ec;
  background: rgba(154, 167, 181, .08);
  padding: 6px 9px;
  font-size: 12px;
  font-weight: 800;
}
.signal-chip.good { color: #c7f9dd; border-color: rgba(61, 220, 151, .22); background: rgba(61, 220, 151, .09); }
.signal-chip.warn { color: #fde9a8; border-color: rgba(244, 201, 93, .24); background: rgba(244, 201, 93, .10); }

.kpi-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi-card { padding: 15px; background: var(--panel-2); position: relative; overflow: hidden; }
.kpi-card::before { content: ""; position: absolute; inset: 0 0 auto; height: 3px; background: var(--primary); opacity: .85; }
.kpi-card:nth-child(2)::before { background: var(--primary-2); }
.kpi-card:nth-child(3)::before { background: var(--warn); }
.kpi-card:nth-child(4)::before { background: var(--bad); }
.kpi-card:nth-child(5)::before { background: var(--good); }
.kpi-label { display: block; color: var(--muted); font-size: 11px; margin-bottom: 8px; font-weight: 850; text-transform: uppercase; letter-spacing: .07em; }
.kpi-card strong { display: block; font-size: 28px; letter-spacing: 0; }
.kpi-card small { color: var(--muted); }

.section-head { display: flex; justify-content: space-between; gap: 18px; align-items: start; margin-bottom: 16px; }
.btn {
  border: 0; color: #071014; font-weight: 850; cursor: pointer;
  padding: 10px 13px; border-radius: 8px;
  transition: transform .15s ease, opacity .15s ease, border-color .15s ease, background .15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn.primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #061015; }
.btn.secondary { background: rgba(148, 163, 184, 0.12); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: rgba(251, 113, 133, .14); color: #fecdd3; border: 1px solid rgba(251, 113, 133, .26); }
.btn.full { width: 100%; }
.icon-btn { border: 0; background: rgba(148, 163, 184, .12); color: var(--text); width: 38px; height: 38px; border-radius: 8px; cursor: pointer; font-size: 24px; }

label { display: grid; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 650; }
input, select {
  width: 100%;
  background: var(--field);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 11px;
  outline: none;
}
select[multiple] { min-height: 160px; }
#chartMeter { min-height: 112px; }
input:focus, select:focus { border-color: rgba(110, 231, 249, .55); box-shadow: 0 0 0 4px rgba(110, 231, 249, .08); }

.check-label {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  background: rgba(110,231,249,.07);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}
.check-label input { width: 18px; height: 18px; accent-color: var(--primary); }
.check-label span { color: var(--text); font-size: 13px; font-weight: 750; }

.chip-grid { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 16px; }
.chip {
  border: 1px solid var(--line); background: rgba(148, 163, 184, .09); color: var(--text);
  padding: 8px 10px; border-radius: 999px; cursor: pointer; font-weight: 800;
}
.chip.active { border-color: rgba(61, 214, 198, .62); background: rgba(61, 214, 198, .13); color: #d6fffa; }
.chart-meta-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: start; }
.selection-summary {
  display: inline-flex; align-items: center; margin: 12px 0 16px;
  color: #d7e1ec; background: rgba(61,214,198,.08); border: 1px solid rgba(61,214,198,.20);
  border-radius: 999px; padding: 7px 10px; font-weight: 800; font-size: 12px;
  white-space: nowrap;
}
.custom-picker { display: grid; grid-template-columns: minmax(260px, 420px) 1fr; gap: 14px; align-items: stretch; }
.custom-help {
  color: var(--muted);
  max-width: 620px;
  border: 1px solid var(--line);
  background: rgba(7, 10, 15, .36);
  border-radius: 8px;
  padding: 12px;
}
.chart-control-panel .toolbar.compact {
  display: grid;
  grid-template-columns: minmax(220px, 1.45fr) repeat(4, minmax(130px, .8fr)) auto;
  align-items: end;
  width: min(100%, 1120px);
}
.chart-control-panel .toolbar.compact label { min-width: 0; }
.chart-control-panel .btn.primary { min-height: 40px; }

.chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; }
.chart-grid.compact { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.chart-grid.focus { grid-template-columns: 1fr; }
.chart-card { padding: 14px; min-height: 500px; background: rgba(18, 23, 31, .96); }
.chart-grid.compact .chart-card { min-height: 430px; }
.chart-grid.compact .chart { height: 276px; }
.chart-top { display: flex; justify-content: space-between; gap: 14px; align-items: start; margin-bottom: 8px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.chart-title { font-size: 18px; font-weight: 850; letter-spacing: 0; }
.chart-subtitle { color: var(--muted); margin-top: 3px; }
.chart-unit { color: var(--primary); font-weight: 850; border: 1px solid rgba(61, 214, 198, .24); padding: 5px 9px; border-radius: 999px; background: rgba(61,214,198,.08); }
.drop-summary {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  margin: 10px 0;
}
.drop-summary strong { font-size: 13px; }
.drop-summary span { color: var(--muted); font-size: 12px; text-align: right; }
.drop-summary.ok { background: rgba(52, 211, 153, .08); border-color: rgba(52, 211, 153, .18); }
.drop-summary.ok strong { color: #bbf7d0; }
.drop-summary.warn { background: rgba(251, 113, 133, .11); border-color: rgba(251, 113, 133, .28); }
.drop-summary.warn strong { color: #fecdd3; }
.chart-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0 10px;
}
.chart-grid.compact .chart-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stat-pill {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(2, 6, 23, .34);
  padding: 7px 9px;
}
.stat-pill span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .07em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat-pill strong {
  display: block;
  color: #f8fafc;
  font-size: 13px;
  font-weight: 850;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chart { width: 100%; height: 342px; }
.empty-state {
  border: 1px dashed rgba(148, 163, 184, .28); border-radius: 8px;
  padding: 24px; color: var(--muted); text-align: center; background: rgba(2, 6, 23, .35);
}

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.table-wrap.tall { max-height: 620px; }
table { width: 100%; border-collapse: collapse; min-width: 780px; }
th, td { padding: 12px 13px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: #cbd5e1; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; background: rgba(2, 6, 23, .42); position: sticky; top: 0; z-index: 1; }
td { color: #e5eefc; }
tr:hover td { background: rgba(148, 163, 184, .045); }
.muted { color: var(--muted); }
.status-pill { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 5px 8px; font-size: 12px; font-weight: 800; }
.status-pill.ok { color: #bbf7d0; background: rgba(52,211,153,.12); }
.status-pill.err { color: #fecdd3; background: rgba(251,113,133,.14); }
.status-pill.disabled { color: #fde68a; background: rgba(251,191,36,.12); }
.action-row { display: flex; gap: 8px; flex-wrap: wrap; }

.meter-dialog {
  width: min(760px, calc(100vw - 28px));
  border: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.96);
  color: var(--text);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 0;
}
.meter-dialog::backdrop { background: rgba(0,0,0,.64); backdrop-filter: blur(4px); }
.meter-dialog form { padding: 22px; }
.dialog-head { display: flex; justify-content: space-between; gap: 14px; align-items: start; margin-bottom: 18px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.toast {
  position: fixed; right: 22px; bottom: 22px; max-width: 440px;
  background: rgba(15, 23, 42, 0.96); border: 1px solid var(--line); color: var(--text);
  padding: 13px 15px; border-radius: 8px; box-shadow: var(--shadow); z-index: 10;
}

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .nav-stack { grid-template-columns: repeat(4, 1fr); }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart-grid, .chart-grid.compact { grid-template-columns: 1fr; }
  .chart-control-panel .toolbar.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; }
  .chart-meta-row { grid-template-columns: 1fr; }
  .selection-summary { justify-self: start; margin-top: -6px; white-space: normal; }
}
@media (max-width: 720px) {
  .main { padding: 14px; }
  .hero, .section-head { align-items: stretch; flex-direction: column; }
  .kpi-grid, .custom-picker, .form-grid { grid-template-columns: 1fr; }
  .chart-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .nav-stack { grid-template-columns: 1fr 1fr; }
  .toolbar.compact label { min-width: 100%; }
  .chart-control-panel .toolbar.compact { grid-template-columns: 1fr; }
  .drop-summary { align-items: start; flex-direction: column; }
  .drop-summary span { text-align: left; }
}
