:root {
  color-scheme: dark;
  --bg-page: #040510;
  --bg-surface: #080b1c;
  --bg-elevated: rgba(13, 18, 42, 0.92);
  --bg-glass: rgba(12, 16, 36, 0.82);
  --border-soft: rgba(129, 140, 248, 0.22);
  --border-strong: rgba(99, 102, 241, 0.48);
  --text-primary: #e8ebff;
  --text-secondary: rgba(226, 232, 240, 0.72);
  --text-muted: rgba(148, 163, 184, 0.7);
  --accent-primary: #6366f1;
  --accent-secondary: #22d3ee;
  --accent-tertiary: #f97316;
  --accent-neutral: rgba(129, 140, 248, 0.2);
  --success: #4ade80;
  --warning: #facc15;
  --error: #fb7185;
  --focus-ring: rgba(99, 102, 241, 0.45);
  --card-gradient: var(--surface-gradient-primary);
  --glass-gradient: linear-gradient(135deg, rgba(14, 20, 48, 0.9), rgba(30, 58, 138, 0.62));
  --transition: 0.18s ease;
}

@font-face {
  font-family: "SourceSansPro";
  src: url("../../assets/fonts/source-sans-pro/SourceSansPro-Regular.otf") format("opentype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "SourceSansPro";
  src: url("../../assets/fonts/source-sans-pro/SourceSansPro-Semibold.otf") format("opentype");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "SourceSansPro";
  src: url("../../assets/fonts/source-sans-pro/SourceSansPro-Bold.otf") format("opentype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

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

html, body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  font-family: "Inter", "SourceSansPro", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  line-height: 1.6;
  color: var(--text-primary);
  background:
    radial-gradient(circle at 18% 20%, rgba(88, 132, 255, 0.22), transparent 58%),
    radial-gradient(circle at 82% 18%, rgba(48, 196, 255, 0.16), transparent 55%),
    radial-gradient(circle at 70% 84%, rgba(60, 120, 235, 0.14), transparent 60%),
    var(--bg-page);
  -webkit-font-smoothing: antialiased;
}

body.has-mobile-nav-open {
  overflow: hidden;
}

.hidden {
  display: none !important;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  max-width: 100%;
  display: block;
}

main {
  display: block;
}

.global-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  --nav-padding: clamp(1.5rem, 4vw, 3rem);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: nowrap;
  gap: clamp(0.6rem, 1vw, 1rem);
  padding: 1rem var(--nav-padding);
  background: linear-gradient(135deg, rgba(14, 20, 48, 0.96), rgba(24, 30, 68, 0.92));
  border-bottom: 1px solid rgba(129, 140, 248, 0.28);
  box-shadow: 0 20px 40px rgba(3, 7, 18, 0.55);
  backdrop-filter: blur(16px);
}

.global-nav__brand {
  display: inline-flex;
  align-items: center;
  gap: clamp(0.7rem, 1vw, 1rem);
  margin-right: clamp(0.65rem, 2vw, 1.5rem);
  text-decoration: none;
  color: inherit;
  flex: 0 1 auto;
  min-width: 0;
}

.global-nav__menu-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 1.2rem;
  border-radius: 999px;
  border: 1px solid rgba(129, 140, 248, 0.35);
  background: rgba(12, 16, 36, 0.85);
  color: #f8faff;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition), box-shadow var(--transition);
  margin-left: auto;
}

.global-nav__menu-toggle:hover,
.global-nav__menu-toggle:focus-visible {
  outline: none;
  background: rgba(18, 22, 48, 0.95);
  border-color: rgba(129, 140, 248, 0.6);
  box-shadow: 0 12px 24px rgba(99, 102, 241, 0.25);
}

.global-nav__menu-toggle-icon {
  position: relative;
  display: block;
  width: 18px;
  height: 2px;
  background: currentColor;
  border-radius: 999px;
  transition: transform var(--transition), background var(--transition);
}

.global-nav__menu-toggle-icon::before,
.global-nav__menu-toggle-icon::after {
  content: "";
  position: absolute;
  left: 0;
  width: 18px;
  height: 2px;
  background: currentColor;
  border-radius: 999px;
  transition: transform var(--transition), opacity var(--transition);
}

.global-nav__menu-toggle-icon::before {
  transform: translateY(-6px);
}

.global-nav__menu-toggle-icon::after {
  transform: translateY(6px);
}

.global-nav--menu-open .global-nav__menu-toggle-icon {
  background: transparent;
}

.global-nav--menu-open .global-nav__menu-toggle-icon::before {
  transform: rotate(45deg);
}

.global-nav--menu-open .global-nav__menu-toggle-icon::after {
  transform: rotate(-45deg);
}

.global-nav__logo {
  height: clamp(44px, 8vw, 58px);
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 8px 16px rgba(3, 7, 18, 0.55));
}

.global-nav__brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  min-width: 0;
}

.global-nav__overline {
  font-family: "Inter", "Segoe UI", Roboto, sans-serif;
  font-size: clamp(0.6rem, 0.7vw, 0.72rem);
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: rgba(232, 235, 255, 0.62);
}

.global-nav__title {
  font-family: "Inter", "Segoe UI", Roboto, sans-serif;
  font-size: clamp(0.98rem, 1.1vw + 0.7rem, 1.35rem);
  font-weight: 600;
  color: #f8faff;
  white-space: normal;
}

.global-nav__menu {
  position: absolute;
  top: calc(100% + 0.55rem);
  left: auto;
  right: var(--nav-padding);
  width: min(360px, calc(100% - 2 * var(--nav-padding)));
  display: none;
  flex-direction: column;
  align-items: stretch;
  gap: 0.75rem;
  list-style: none;
  margin: 0;
  padding: 1.1rem 1.4rem 1.6rem;
  background: linear-gradient(135deg, rgba(14, 20, 48, 0.96), rgba(24, 30, 68, 0.92));
  border: 1px solid rgba(129, 140, 248, 0.32);
  border-radius: 20px;
  box-shadow: 0 26px 48px rgba(5, 9, 24, 0.6);
  backdrop-filter: blur(12px);
  z-index: 120;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}

.global-nav--menu-open .global-nav__menu {
  display: flex;
}

.global-nav__item {
  position: relative;
  width: 100%;
}

.global-nav__link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.55rem clamp(0.85rem, 1.2vw, 1.2rem);
  border-radius: 999px;
  font-size: clamp(0.85rem, 0.55vw + 0.7rem, 1.05rem);
  font-weight: 500;
  color: rgba(232, 235, 255, 0.9);
  border: 1px solid transparent;
  transition: background var(--transition), color var(--transition), border-color var(--transition), box-shadow var(--transition);
  width: 100%;
  text-align: left;
}

.global-nav__link:hover,
.global-nav__link:focus-visible {
  color: #f8faff;
  background: rgba(129, 140, 248, 0.2);
  border-color: rgba(129, 140, 248, 0.45);
  box-shadow: 0 12px 24px rgba(99, 102, 241, 0.25);
  outline: none;
}

.global-nav__link--active {
  background: rgba(129, 140, 248, 0.25);
  border-color: rgba(129, 140, 248, 0.6);
  color: #f8faff;
  box-shadow: 0 12px 24px rgba(99, 102, 241, 0.3);
}

.global-nav__toggle {
  background: none;
  cursor: pointer;
}

.global-nav__caret {
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid rgba(232, 235, 255, 0.8);
  transition: transform 0.2s ease;
  margin-top: 2px;
  margin-left: auto;
}

.global-nav__item--open .global-nav__caret {
  transform: rotate(-180deg);
}

.global-nav__dropdown {
  display: none;
  flex-direction: column;
  gap: 0.45rem;
  width: 100%;
  margin-top: 0.4rem;
  padding: 0.6rem;
  background: rgba(10, 14, 34, 0.9);
  border: 1px solid rgba(129, 140, 248, 0.22);
  border-radius: 16px;
  box-shadow: inset 0 0 0 1px rgba(3, 7, 18, 0.4);
}

.global-nav__item--open .global-nav__dropdown {
  display: flex;
}

.global-nav__dropdown-link {
  display: block;
  padding: 0.65rem 1rem;
  border-radius: 12px;
  font-size: 0.95rem;
  color: rgba(232, 235, 255, 0.92);
  transition: background var(--transition), color var(--transition);
}

.global-nav__dropdown-link:hover,
.global-nav__dropdown-link:focus-visible {
  background: rgba(129, 140, 248, 0.25);
  color: #f8faff;
  outline: none;
}

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 3rem 1.5rem 4.5rem;
  display: flex;
  flex-direction: column;
  gap: clamp(2rem, 4vw, 3rem);
}

.card {
  background: var(--card-gradient);
  border-radius: 22px;
  padding: clamp(1.9rem, 3vw, 2.6rem);
  box-shadow: 0 28px 60px rgba(3, 7, 18, 0.65);
  border: 1px solid var(--border-soft);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  gap: clamp(1.4rem, 2.6vw, 2rem);
}

.page-footer {
  text-align: center;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  font-size: 0.95rem;
}

.footer-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  color: var(--text-muted);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--success), #16a34a);
  box-shadow: 0 0 0 6px rgba(34, 197, 94, 0.18);
  display: inline-block;
}

/* Dataset summary */
.dataset-card {
  padding: clamp(1.5rem, 3vw, 2.2rem);
}

.dataset-info,
.header-dataset-info {
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}

.dataset-placeholder {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
  text-align: center;
}

.header-dataset-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: clamp(1rem, 2vw, 1.4rem);
  width: 100%;
}

.header-stat-item {
  background: rgba(12, 16, 36, 0.76);
  border: 1px solid rgba(129, 140, 248, 0.28);
  border-radius: 18px;
  padding: 1.1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  box-shadow: inset 0 0 0 1px rgba(3, 7, 18, 0.35);
}

.header-stat-label {
  font-size: 0.8rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.header-stat-number {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* Tab navigation */
.explorer-shell {
  gap: 1.8rem;
  padding: clamp(1.5rem, 3vw, 2rem);
}

.tab-navigation {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  background: none;
  padding: 0;
  margin: 0;
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 1.4rem;
  border-radius: 999px;
  border: 1px solid rgba(129, 140, 248, 0.35);
  background: rgba(12, 16, 36, 0.72);
  color: var(--text-secondary);
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition), transform var(--transition), box-shadow var(--transition);
}

.tab:hover {
  background: rgba(129, 140, 248, 0.25);
  color: #f8faff;
  border-color: rgba(129, 140, 248, 0.55);
  transform: translateY(-1px);
  box-shadow: 0 16px 32px rgba(12, 16, 36, 0.5);
}

.tab.active {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border-color: transparent;
  color: #f8faff;
  box-shadow: 0 20px 40px rgba(34, 211, 238, 0.25);
}

.tab-icon {
  width: 22px;
  height: 22px;
  object-fit: contain;
  filter: drop-shadow(0 6px 12px rgba(3, 7, 18, 0.45));
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Analysis cards */
.unified-analysis-card {
  background: var(--bg-glass);
  border: 1px solid rgba(129, 140, 248, 0.24);
  border-radius: 20px;
  padding: clamp(1.6rem, 2.5vw, 2.2rem);
  box-shadow: inset 0 0 0 1px rgba(3, 7, 18, 0.45);
  display: flex;
  flex-direction: column;
  gap: clamp(1.5rem, 2.6vw, 2rem);
}

.card-header {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.card-header h3 {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 600;
  color: #f8faff;
}

.header-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.help-toggle-btn,
.export-pdf-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border-radius: 999px;
  padding: 0.6rem 1.2rem;
  border: 1px solid rgba(129, 140, 248, 0.38);
  background: rgba(129, 140, 248, 0.18);
  color: var(--text-primary);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform var(--transition), box-shadow var(--transition);
}

.help-toggle-btn:hover,
.export-pdf-btn:hover,
.help-toggle-btn:focus-visible,
.export-pdf-btn:focus-visible {
  outline: none;
  background: rgba(129, 140, 248, 0.28);
  border-color: rgba(129, 140, 248, 0.55);
  box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.22);
}

.help-toggle-btn.active {
  background: rgba(99, 102, 241, 0.4);
  border-color: rgba(99, 102, 241, 0.6);
}

.instruction-text {
  margin: 0;
  padding: 1rem 1.4rem;
  border-left: 4px solid var(--accent-tertiary);
  border-radius: 0 16px 16px 0;
  background: rgba(249, 115, 22, 0.1);
  color: var(--text-primary);
  font-size: 0.95rem;
  line-height: 1.6;
  display: none;
}

.instruction-text.visible {
  display: block;
  animation: fadeInDown 0.3s ease;
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.control-group {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  background: rgba(12, 16, 36, 0.7);
  border: 1px solid rgba(129, 140, 248, 0.24);
  border-radius: 18px;
  padding: 1.4rem 1.6rem;
}

.control label {
  display: block;
  font-size: 0.85rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.45rem;
}

select,
input[type="number"],
input[type="text"],
textarea {
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(129, 140, 248, 0.35);
  background: rgba(12, 16, 36, 0.72);
  color: var(--text-primary);
  padding: 0.65rem 0.85rem;
  font-size: 1rem;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

select:focus,
input:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent-secondary);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.2);
  background: rgba(12, 16, 36, 0.86);
}

.time-series-controls {
  display: grid;
  gap: 1.2rem;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.variable-card {
  background: rgba(12, 16, 36, 0.7);
  border: 1px solid rgba(129, 140, 248, 0.24);
  border-radius: 16px;
  padding: 1.2rem 1.3rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.variable-card-title {
  margin: 0;
  font-size: 1rem;
  color: var(--text-primary);
  font-weight: 600;
}

.variable-card-content {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.axis-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.axis-checkbox input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent-primary);
}

.smoothing-dropdown {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  color: var(--text-muted);
}

.smoothing-dropdown span {
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chart-section {
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}

.chart-container {
  background: rgba(12, 16, 36, 0.72);
  border: 1px solid rgba(129, 140, 248, 0.2);
  border-radius: 18px;
  padding: clamp(1.4rem, 2.5vw, 2rem);
  box-shadow: inset 0 0 0 1px rgba(3, 7, 18, 0.4);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 460px;
}

#distribution-tab .chart-container {
  min-height: 560px;
}

#optimization-tab .chart-container {
  min-height: 520px;
}

#timeseries-tab .chart-container {
  min-height: 500px;
}

.chart-subtitle {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.chart-zoom-hint {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
  text-align: center;
}

canvas {
  width: 100% !important;
  height: 440px !important;
  max-height: 440px !important;
  min-height: 440px !important;
}

#correlationChart {
  height: 460px !important;
  max-height: 460px !important;
  min-height: 460px !important;
}

#timeSeriesChart {
  height: 500px !important;
  max-height: 500px !important;
  min-height: 500px !important;
}

#distributionChart {
  height: 520px !important;
  max-height: 520px !important;
  min-height: 520px !important;
}

#optimizationChart {
  height: 500px !important;
  max-height: 500px !important;
  min-height: 500px !important;
}

.empty-state {
  text-align: center;
  padding: 2.4rem;
  background: rgba(12, 16, 36, 0.6);
  border-radius: 16px;
  border: 1px dashed rgba(129, 140, 248, 0.3);
  color: var(--text-muted);
  font-style: italic;
}

.empty-state p {
  margin: 0;
  font-size: 1rem;
}

.unified-content {
  display: grid;
  gap: 1.6rem;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.optimization-layout {
  grid-template-columns: minmax(200px, 0.28fr) minmax(520px, 0.72fr);
  align-items: stretch;
}

.optimization-layout .correlation-matrix {
  max-width: 260px;
}

.stats-panel,
.correlation-matrix {
  background: rgba(12, 16, 36, 0.72);
  border: 1px solid rgba(129, 140, 248, 0.24);
  border-radius: 18px;
  padding: 1.6rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  height: 100%;
}

.stats-panel h4,
.correlation-matrix h4 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--text-primary);
  font-weight: 600;
}

.stats-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.stat-item-enhanced {
  background: rgba(12, 16, 36, 0.68);
  border-radius: 14px;
  border: 1px solid rgba(129, 140, 248, 0.24);
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  box-shadow: inset 0 0 0 1px rgba(3, 7, 18, 0.38);
}

.stat-item-enhanced.count {
  border-color: rgba(99, 102, 241, 0.45);
}

.stat-item-enhanced.range {
  border-color: rgba(34, 211, 238, 0.35);
}

.stat-item-enhanced.quartile {
  border-color: rgba(249, 115, 22, 0.35);
}

.stat-label-enhanced {
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.stat-value-enhanced {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text-primary);
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.chart-title-section h4 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text-primary);
}

.correlation-button {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.6rem;
  border: 1px solid rgba(129, 140, 248, 0.28);
  border-radius: 14px;
  padding: 0.75rem 1rem;
  background: rgba(12, 16, 36, 0.68);
  color: var(--text-secondary);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform var(--transition), box-shadow var(--transition);
}

.correlation-button:last-child {
  margin-bottom: 0;
}

.correlation-button:hover {
  border-color: rgba(129, 140, 248, 0.55);
  color: #f8faff;
  transform: translateY(-1px);
  box-shadow: 0 18px 32px rgba(12, 16, 36, 0.55);
}

.correlation-button.active {
  background: rgba(99, 102, 241, 0.35);
  border-color: rgba(99, 102, 241, 0.6);
  color: #f8faff;
}

.variable-name {
  font-weight: 600;
  color: var(--text-primary);
}

.correlation-value {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.correlation-arrow-icon {
  width: 18px;
  height: 18px;
}

.correlation-arrow-icon.positive {
  filter: drop-shadow(0 0 8px rgba(34, 197, 94, 0.55));
}

.correlation-arrow-icon.negative {
  filter: drop-shadow(0 0 8px rgba(248, 113, 113, 0.55));
}

.ai-insights-panel {
  background: rgba(12, 16, 36, 0.7);
  border: 1px solid rgba(129, 140, 248, 0.24);
  border-radius: 18px;
  padding: 1.5rem 1.6rem;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}

.ai-header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.ai-header-top h4 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: #f8faff;
}

.ai-provider-pill {
  display: inline-flex;
  gap: 0.35rem;
  background: rgba(12, 16, 36, 0.75);
  border: 1px solid rgba(129, 140, 248, 0.4);
  padding: 0.3rem;
  border-radius: 999px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.25);
}

.provider-pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.42rem 1.05rem;
  border-radius: 999px;
  border: 1px solid transparent;
  color: rgba(232, 235, 255, 0.65);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.1s ease;
}

.provider-pill input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.provider-pill .pill-text {
  font-size: 0.95rem;
  position: relative;
  padding-left: 1.5rem;
}

.provider-pill:hover {
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-1px);
}

.provider-pill .pill-text::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.45);
  background: transparent;
  transition: all 0.2s ease;
}

/* Clear on/off states using :has for modern browsers */
.provider-pill:has(input:checked) {
  background: linear-gradient(135deg, #22d3ee, #6366f1);
  border-color: rgba(129, 140, 248, 0.6);
  color: #0b1026;
  box-shadow: 0 10px 26px rgba(34, 211, 238, 0.28);
}

.provider-pill:has(input:checked) .pill-text {
  font-weight: 700;
  color: #0b1026;
}

.provider-pill:has(input:checked) .pill-text::before {
  border-color: transparent;
  background: #f8faff;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
}

.provider-pill:not(:has(input:checked)) {
  color: rgba(232, 235, 255, 0.65);
}

.provider-pill:not(:has(input:checked)) .pill-text::before {
  border-color: rgba(255, 255, 255, 0.35);
  background: transparent;
  box-shadow: none;
}

.provider-pill input:checked ~ .pill-text {
  font-weight: 700;
  color: #0b1026;
}

.provider-pill input:checked {
  /* allow label click to toggle */
}

.provider-pill input:checked ~ .pill-text::before {
  border-color: transparent;
}

.ai-instruction-text {
  margin: 0;
  font-size: 0.92rem;
  color: var(--text-muted);
}

.ai-insights-content {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.correlation-bar {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  background: rgba(129, 140, 248, 0.18);
  border-radius: 14px;
  padding: 0.75rem 1rem;
}

.correlation-bar > button {
  margin-left: auto;
}

.correlation-context {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--text-primary);
}

.correlation-label {
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.correlation-display {
  font-weight: 600;
}

.explain-btn-enhanced {
  border-radius: 999px;
  border: 1px solid rgba(129, 140, 248, 0.38);
  padding: 0.7rem 1.35rem;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.35), rgba(34, 211, 238, 0.28));
  color: #f8faff;
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}

.explain-btn-enhanced:hover {
  transform: translateY(-2px);
  border-color: rgba(99, 102, 241, 0.6);
  box-shadow: 0 16px 30px rgba(34, 211, 238, 0.28);
}

/* Notifications */
.notification-container {
  position: fixed;
  top: 90px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  z-index: 1100;
}

.notification {
  min-width: 260px;
  padding: 0.9rem 1.2rem;
  border-radius: 16px;
  border: 1px solid rgba(129, 140, 248, 0.32);
  background: rgba(12, 16, 36, 0.86);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: 0 18px 36px rgba(3, 7, 18, 0.55);
  animation: slideIn 0.3s ease;
}

.notification.success {
  border-color: rgba(74, 222, 128, 0.55);
  background: rgba(22, 163, 74, 0.28);
}

.notification.error {
  border-color: rgba(249, 113, 113, 0.55);
  background: rgba(248, 113, 113, 0.28);
}

.notification.warning {
  border-color: rgba(250, 204, 21, 0.55);
  background: rgba(250, 204, 21, 0.28);
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(12px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 18, 0.78);
  backdrop-filter: blur(12px);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: clamp(2.5rem, 6vw, 4rem) 1.5rem;
  z-index: 1200;
}

.modal-content {
  background: var(--bg-elevated);
  border-radius: 24px;
  border: 1px solid rgba(129, 140, 248, 0.32);
  width: min(700px, 100%);
  box-shadow: 0 40px 70px rgba(3, 7, 18, 0.75);
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 1.5rem 2rem;
  border-bottom: 1px solid rgba(129, 140, 248, 0.24);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  margin: 0;
  color: var(--text-primary);
  font-size: 1.35rem;
}

.close {
  font-size: 2rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: color var(--transition);
}

.close:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.6rem;
}

.correlation-info h4 {
  margin: 0 0 0.5rem;
  color: var(--text-primary);
}

.correlation-details {
  margin: 0;
  color: var(--text-secondary);
}

.loading-explanation {
  display: flex;
  align-items: center;
  gap: 1rem;
  color: var(--text-secondary);
}

.loading-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(129, 140, 248, 0.25);
  border-top-color: var(--accent-secondary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.explanation-text {
  background: rgba(12, 16, 36, 0.7);
  border: 1px solid rgba(129, 140, 248, 0.24);
  border-radius: 16px;
  padding: 1.2rem 1.4rem;
  color: var(--text-secondary);
  min-height: 120px;
}

.modal-footer {
  padding: 1.5rem 2rem;
  border-top: 1px solid rgba(129, 140, 248, 0.24);
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.disclaimer {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.btn-secondary {
  align-self: flex-end;
  border-radius: 999px;
  padding: 0.65rem 1.4rem;
  border: 1px solid rgba(129, 140, 248, 0.38);
  background: rgba(12, 16, 36, 0.72);
  color: var(--text-primary);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
}

.btn-secondary:hover {
  background: rgba(129, 140, 248, 0.25);
  border-color: rgba(129, 140, 248, 0.55);
  transform: translateY(-1px);
}

/* Responsive adjustments */
@media (min-width: 960px) {
  .study-toolbar__nav {
    justify-content: flex-start;
  }
}

@media (max-width: 900px) {
  .chart-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .optimization-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .page {
    padding: 2.5rem 1.25rem 3.5rem;
  }

  .global-nav__menu {
    width: calc(100% - 2 * var(--nav-padding));
    right: var(--nav-padding);
  }

  .global-nav {
    padding: 0.85rem var(--nav-padding);
  }

  .tab-navigation {
    gap: 0.5rem;
  }

  .tab {
    width: 100%;
    justify-content: center;
  }

  .control-group {
    grid-template-columns: 1fr;
  }

  .time-series-controls {
    grid-template-columns: 1fr;
  }

  .optimization-layout {
    grid-template-columns: 1fr;
  }

  .optimization-layout .correlation-matrix {
    max-width: none;
  }

  .chart-container {
    min-height: 320px;
  }

  canvas {
    height: 360px !important;
    max-height: 360px !important;
    min-height: 360px !important;
  }

  #timeSeriesChart {
    height: 420px !important;
    max-height: 420px !important;
    min-height: 420px !important;
  }

  #distributionChart {
    height: 420px !important;
    max-height: 420px !important;
    min-height: 420px !important;
  }

  #distribution-tab .chart-container {
    min-height: 400px;
  }

  #optimizationChart {
    height: 400px !important;
    max-height: 400px !important;
    min-height: 400px !important;
  }

  #optimization-tab .chart-container {
    min-height: 380px;
  }

  .modal-content {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .hero {
    padding: 1.6rem 1.2rem;
    border-radius: 22px;
  }

  .card {
    padding: 1.6rem 1.4rem;
    border-radius: 20px;
  }

  .header-dataset-stats {
    grid-template-columns: 1fr;
  }
}
