/* ==========================================================================
   NILMZ web explorer - base.css
   Dark, glassy, lightweight theme. All styling lives here (no inline styles).
   ========================================================================== */

:root {
  --bg: #0b1020;
  --bg-elev: rgba(17, 24, 45, 0.72);
  --bg-input: rgba(15, 23, 42, 0.85);
  --border: rgba(148, 163, 184, 0.16);
  --border-strong: rgba(148, 163, 184, 0.3);
  --text: #e2e8f0;
  --text-2: #cbd5e1;
  --muted: #94a3b8;
  --accent: #748ffc;
  --accent-2: #38d9a9;
  --accent-3: #ffa94d;
  --accent-grad: linear-gradient(135deg, #748ffc 0%, #38d9a9 100%);
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 10px 40px -12px rgba(0, 0, 0, 0.55);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: 72px;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

.bg-glow {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(900px 500px at 12% -10%, rgba(116, 143, 252, 0.22), transparent 60%),
    radial-gradient(700px 420px at 95% 5%, rgba(56, 217, 169, 0.14), transparent 60%),
    radial-gradient(800px 600px at 50% 110%, rgba(247, 131, 172, 0.08), transparent 60%);
}

.container {
  width: min(1240px, 100% - 2.5rem);
  margin-inline: auto;
}

.mono {
  font-family: var(--mono);
  font-size: 0.86em;
}

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

a {
  color: var(--accent);
}

/* ---------- Hero ---------- */
.hero {
  padding: 1.1rem 0 2.2rem;
}

.hero-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  text-decoration: none;
  color: var(--text);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
}

.brand-tag {
  font-weight: 800;
  letter-spacing: 0.08em;
  font-size: 0.9rem;
}

.hero-body {
  padding-top: 2.6rem;
  animation: rise 0.7s var(--ease) both;
}

.hero-title {
  font-size: clamp(2rem, 4.6vw, 3.4rem);
  line-height: 1.08;
  letter-spacing: -0.035em;
  font-weight: 800;
  margin: 0 0 0.8rem;
  background: linear-gradient(120deg, #ffffff 10%, #a5b4fc 55%, #63e6be 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero-subtitle {
  max-width: 760px;
  color: var(--text-2);
  font-size: 1.06rem;
  margin: 0 0 1.6rem;
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.8rem;
  margin: 0 0 1.4rem;
  max-width: 820px;
}

.stat {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.95rem;
  backdrop-filter: blur(10px);
  transition: border-color 0.25s var(--ease), transform 0.25s var(--ease);
}

.stat:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
}

.stat dt {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat dd {
  margin: 0.15rem 0 0;
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.load-status {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  color: var(--muted);
  font-size: 0.88rem;
  transition: opacity 0.6s var(--ease);
}

.load-status.is-done {
  opacity: 0;
  pointer-events: none;
}

.load-status.is-error {
  color: #ff8787;
}

.load-bar {
  width: 220px;
  height: 6px;
  border-radius: 99px;
  background: rgba(148, 163, 184, 0.15);
  overflow: hidden;
}

.load-bar-fill {
  height: 100%;
  width: 0;
  background: var(--accent-grad);
  transition: width 0.2s linear;
}

/* ---------- Navigation Tabs ---------- */
.tabs {
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  background: rgba(11, 16, 32, 0.88);
  border-bottom: 1px solid var(--border);
  margin-bottom: 2rem;
}

.tabs-inner {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding: 0.65rem 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
}

.tabs-inner::-webkit-scrollbar {
  display: none;
}

.tab {
  display: inline-flex;
  align-items: center;
  padding: 0.45rem 0.95rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  border-radius: 99px;
  white-space: nowrap;
  transition: all 0.2s var(--ease);
  border: 1px solid transparent;
}

.tab:hover {
  color: var(--text);
  background: rgba(148, 163, 184, 0.1);
  border-color: var(--border);
}

.tab.is-active,
.tab:active {
  color: #ffffff;
  background: rgba(116, 143, 252, 0.18);
  border-color: var(--accent);
}

/* ---------- Language switch / segmented buttons ---------- */
.lang-switch,
.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border-radius: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
}

.seg-btn {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 7px;
  padding: 0.38rem 0.8rem;
  cursor: pointer;
  transition: color 0.2s var(--ease), background 0.2s var(--ease);
}

.seg-btn:hover {
  color: var(--text);
}

.seg-btn.is-active {
  color: #0b1020;
  background: var(--accent-grad);
}

.seg-btn:focus-visible,
.btn:focus-visible,
.input:focus-visible,
.tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Tabs ---------- */
.tabs {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(11, 16, 32, 0.78);
  backdrop-filter: blur(14px) saturate(140%);
  border-block: 1px solid var(--border);
}

.tabs-inner {
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.tab {
  position: relative;
  padding: 0.85rem 0.95rem;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  transition: color 0.2s var(--ease);
}

.tab::after {
  content: "";
  position: absolute;
  left: 0.95rem;
  right: 0.95rem;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent-grad);
  transform: scaleX(0);
  transition: transform 0.3s var(--ease);
}

.tab:hover,
.tab.is-active {
  color: var(--text);
}

.tab.is-active::after {
  transform: scaleX(1);
}

/* ---------- Panels ---------- */
main {
  padding: 2rem 0 3rem;
}

.panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.6rem 1.6rem 1.4rem;
  margin-bottom: 1.6rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  animation: rise 0.6s var(--ease) both;
}

.panel-head {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 1.1rem;
}

.panel-index {
  flex: none;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--accent);
  border: 1px solid rgba(116, 143, 252, 0.35);
  background: rgba(116, 143, 252, 0.08);
  border-radius: 8px;
  padding: 0.25rem 0.5rem;
  margin-top: 0.25rem;
}

h2 {
  margin: 0 0 0.35rem;
  font-size: 1.38rem;
  letter-spacing: -0.02em;
}

h3 {
  margin: 2rem 0 0.35rem;
  font-size: 1.08rem;
  letter-spacing: -0.01em;
}

.prose {
  color: var(--text-2);
  margin: 0 0 0.9rem;
  max-width: 980px;
  font-size: 0.95rem;
}

.prose b {
  color: var(--text);
}

/* ---------- Controls ---------- */
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.9rem 1.4rem;
  padding: 0.9rem 1rem;
  margin-bottom: 0.9rem;
  border-radius: var(--radius-sm);
  background: rgba(11, 16, 32, 0.45);
  border: 1px solid var(--border);
}

.controls-sticky {
  position: sticky;
  top: 52px;
  z-index: 10;
  backdrop-filter: blur(14px);
  background: rgba(11, 16, 32, 0.82);
}

.control {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.control-grow {
  flex: 1 1 260px;
}

.control-label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.control-label output {
  color: var(--accent-2);
  text-transform: none;
  letter-spacing: 0;
  margin-left: 0.3rem;
}

.input {
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.65rem;
  min-width: 0;
  transition: border-color 0.2s var(--ease);
}

.input:hover {
  border-color: var(--border-strong);
}

.input:disabled {
  opacity: 0.45;
}

.input.is-invalid {
  border-color: #ff8787;
}

.input-narrow {
  width: 6.5rem;
}

.input-num {
  width: 8.5rem;
}

select.input {
  padding-right: 1.8rem;
  max-width: 100%;
}

.range-pair {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.range {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 99px;
  background: linear-gradient(90deg, rgba(116, 143, 252, 0.55), rgba(56, 217, 169, 0.55));
  outline: none;
  cursor: pointer;
}

.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
  box-shadow: 0 0 0 4px rgba(116, 143, 252, 0.18);
  transition: transform 0.15s var(--ease);
}

.range::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.range::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-2);
  padding-bottom: 0.4rem;
}

.toggle input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.toggle-track {
  position: relative;
  width: 38px;
  height: 22px;
  border-radius: 99px;
  background: rgba(148, 163, 184, 0.25);
  transition: background 0.25s var(--ease);
}

.toggle-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.25s var(--ease);
}

.toggle input:checked + .toggle-track {
  background: var(--accent-2);
}

.toggle input:checked + .toggle-track::after {
  transform: translateX(16px);
}

.toggle input:focus-visible + .toggle-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  background: rgba(116, 143, 252, 0.12);
  border: 1px solid rgba(116, 143, 252, 0.4);
  border-radius: 8px;
  padding: 0.45rem 0.9rem;
  cursor: pointer;
  transition: background 0.2s var(--ease), transform 0.15s var(--ease);
}

.btn:hover {
  background: rgba(116, 143, 252, 0.24);
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.5;
  cursor: progress;
}

.btn-chip {
  font-size: 0.78rem;
  padding: 0.3rem 0.65rem;
  border-radius: 99px;
}

/* ---------- Chips / stats ---------- */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  list-style: none;
  padding: 0;
  margin: 0 0 0.9rem;
}

.chips li {
  font-size: 0.82rem;
  color: var(--text-2);
  background: rgba(148, 163, 184, 0.08);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 0.28rem 0.75rem;
}

.chips b {
  color: var(--accent-2);
  font-variant-numeric: tabular-nums;
}

.chip-text {
  font-size: 0.85rem;
  color: var(--text-2);
}

.chip-text b {
  color: var(--accent-2);
}

.verify-row,
.appliance-jumps {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.9rem;
}

.app-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 0.4rem;
}

.app-dot-0 {
  background: #b197fc;
}

.app-dot-1 {
  background: #38d9a9;
}

.app-dot-2 {
  background: #f783ac;
}

/* ---------- Cards & plots ---------- */
.cards {
  display: grid;
  gap: 1.1rem;
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(11, 16, 32, 0.4);
  padding: 0.9rem 0.9rem 0.4rem;
  transition: border-color 0.3s var(--ease);
}

.card:hover {
  border-color: var(--border-strong);
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  padding: 0 0.3rem 0.4rem;
}

.card-title {
  font-weight: 700;
  font-size: 1.02rem;
}

.card-meta {
  color: var(--muted);
  font-size: 0.84rem;
}

.card-apps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-left: auto;
}

.card-apps li {
  display: inline-flex;
  align-items: center;
}

.plot {
  width: 100%;
  min-height: 560px;
  border-radius: var(--radius-sm);
}

.plot-card {
  min-height: 640px;
}

.plot-tall {
  min-height: 620px;
}

.plot-xl {
  min-height: 880px;
}

.plot-info {
  margin: 0 0 0.4rem;
  color: var(--muted);
}

.skeleton {
  background: linear-gradient(
    100deg,
    rgba(148, 163, 184, 0.04) 20%,
    rgba(148, 163, 184, 0.1) 40%,
    rgba(148, 163, 184, 0.04) 60%
  );
  background-size: 200% 100%;
  animation: shimmer 1.6s linear infinite;
}

.is-busy {
  opacity: 0.6;
  transition: opacity 0.15s var(--ease);
}

/* ---------- Method ---------- */
.method .equation {
  overflow-x: auto;
  padding: 0.6rem 0;
}

.table-wrap {
  overflow-x: auto;
  margin: 0.6rem 0 1rem;
}

.method-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.method-table th,
.method-table td {
  text-align: left;
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.method-table thead th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.method-table tbody th {
  color: var(--text);
  white-space: nowrap;
}

.katex {
  font-size: 1.04em;
}

/* ---------- Footer ---------- */
.footer {
  border-top: 1px solid var(--border);
  padding: 1.6rem 0 2.4rem;
  font-size: 0.85rem;
  color: var(--text-2);
}

.footer p {
  margin: 0.3rem 0;
}

/* ---------- Animations ---------- */
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

/* ---------- Global Experiment & Appliance Event Filter ---------- */
.panel-filter {
  border: 1px solid rgba(116, 143, 252, 0.4);
  background: linear-gradient(135deg, rgba(20, 28, 55, 0.8) 0%, rgba(13, 20, 38, 0.75) 100%);
  box-shadow: 0 12px 36px -10px rgba(116, 143, 252, 0.18), var(--shadow);
}

.controls-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 1.4rem;
  align-items: flex-start;
}

.controls-filter-range {
  margin-top: 0.6rem;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1rem;
}

.control-actions {
  display: flex;
  align-items: flex-end;
  padding-bottom: 0.2rem;
}

.event-pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}

.event-pill {
  font: inherit;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-2);
  background: rgba(148, 163, 184, 0.08);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 0.35rem 0.75rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.2s var(--ease);
}

.event-pill:hover {
  border-color: var(--accent);
  color: var(--text);
  background: rgba(116, 143, 252, 0.14);
  transform: translateY(-1px);
}

.event-pill.is-active {
  border-color: var(--accent-2);
  color: #ffffff;
  background: rgba(56, 217, 169, 0.2);
  box-shadow: 0 0 12px rgba(56, 217, 169, 0.28);
}

.event-pill:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.filter-readout-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 0.25rem;
  font-size: 0.85rem;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .hero-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .controls-filter {
    flex-direction: column;
    gap: 0.8rem;
  }
  .controls-filter .control {
    width: 100%;
  }
  .controls-filter-range {
    flex-direction: column;
    gap: 0.8rem;
  }
  .controls-filter-range .control {
    width: 100%;
  }
  .range-pair {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
  }
  .range-pair .range {
    flex: 1;
    min-width: 0;
  }
  .range-pair .input-num {
    width: 85px;
    flex-shrink: 0;
  }
  .control-actions {
    width: 100%;
  }
  .control-actions .btn {
    width: 100%;
    min-height: 44px;
    justify-content: center;
  }
  .event-pill {
    padding: 0.45rem 0.85rem;
    font-size: 0.82rem;
    min-height: 38px;
  }
  .panel {
    padding: 1.1rem 0.9rem;
  }
  .panel-index {
    display: none;
  }
  .controls-sticky {
    position: static;
  }
  .plot-tall {
    min-height: 900px;
  }
  .card-apps {
    margin-left: 0;
  }
}
