:root {
  /* Modern Financial Theme */
  --bg: oklch(0.99 0.005 85);
  --bg-gradient: linear-gradient(135deg, oklch(0.99 0.005 85) 0%, oklch(0.96 0.01 240) 100%);
  --panel: oklch(1 0 0 / 0.95);
  --panel-solid: oklch(1 0 0);
  --text: oklch(0.15 0.01 240);
  --muted: oklch(0.55 0.01 240);
  --primary: oklch(0.75 0.15 85);
  --primary-700: oklch(0.65 0.18 85);
  --primary-600: oklch(0.55 0.2 85);
  --border: oklch(0.92 0.01 240);
  --glass: blur(20px) saturate(120%);
  --shadow: 0 4px 24px oklch(0.15 0.01 240 / 0.08);
  --shadow-lg: 0 8px 40px oklch(0.15 0.01 240 / 0.12);
}

.dark {
  --bg: oklch(0.08 0.01 240);
  --bg-gradient: linear-gradient(135deg, oklch(0.08 0.01 240) 0%, oklch(0.12 0.01 240) 100%);
  --panel: oklch(0.1 0.01 240 / 0.95);
  --panel-solid: oklch(0.1 0.01 240);
  --text: oklch(0.95 0.01 240);
  --muted: oklch(0.65 0.01 240);
  --primary: oklch(0.75 0.15 85);
  --primary-700: oklch(0.65 0.18 85);
  --primary-600: oklch(0.55 0.2 85);
  --border: oklch(0.2 0.01 240);
  --glass: blur(20px) saturate(120%);
  --shadow: 0 4px 24px oklch(0 0 0 / 0.25);
  --shadow-lg: 0 8px 40px oklch(0 0 0 / 0.35);
}

html,
body {
  height: 100%;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

body {
  margin: 0;
  background: var(--bg);
  background-image: var(--bg-gradient);
  color: var(--text);
  overflow-y: auto;
  scroll-behavior: smooth;
  line-height: 1.6;
}

/* Service status styles */
.service-info {
  margin-top: 20px;
  padding: 16px;
  background: var(--panel);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.service-info h4 {
  margin: 0 0 12px 0;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.status-info {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.status-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
}

.status-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

.status-value {
  font-size: 12px;
  color: var(--text);
  font-weight: 600;
  font-family: "JetBrains Mono", monospace;
}

/* Remove old controls */
.controls {
  display: none;
}

#chart-container {
  width: 100%;
  height: 100vh;
  position: relative;
  background: var(--panel);
  border-radius: 16px;
  margin: 16px;
  width: calc(100% - 32px);
  height: calc(100vh - 32px);
  box-shadow: var(--shadow-lg);
  backdrop-filter: var(--glass);
  border: 1px solid var(--border);
  overflow: hidden;
}

/* SR Channels overlay */
#channels-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 12;
  border-radius: 16px;
  overflow: hidden;
}

.sr-band {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px solid oklch(0.6 0.2 140 / 0.4);
  border-bottom: 1px solid oklch(0.6 0.2 140 / 0.4);
  transition: all 0.2s ease;
}

.sr-band.support {
  background: oklch(0.6 0.2 140 / 0.1);
  border-color: oklch(0.6 0.2 140 / 0.5);
}

.sr-band.resistance {
  background: oklch(0.65 0.2 25 / 0.1);
  border-color: oklch(0.65 0.2 25 / 0.5);
}

/* Modern Loader */
.loader.hidden {
  display: none;
}
.loader {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  backdrop-filter: var(--glass);
  background: var(--bg) / 0.8;
  z-index: 50;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.loader-text {
  margin-top: 16px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
}

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

/* Tooltip button next to field headers */
.modern-tooltip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--primary) / 0.1;
  color: var(--primary);
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid var(--primary) / 0.2;
  padding: 0;
  flex-shrink: 0;
}

.modern-tooltip:hover,
.modern-tooltip.is-touch-active {
  background: var(--primary);
  color: white;
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.tooltip-flyout {
  position: fixed;
  background: var(--panel-solid);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  max-width: min(360px, calc(100vw - 64px));
  font-size: 12px;
  font-weight: 500;
  line-height: 1.6;
  z-index: 4000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  text-align: left;
  white-space: normal;
  word-break: break-word;
}

.tooltip-flyout.is-visible {
  opacity: 1;
}

.tooltip-flyout::after {
  content: "";
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  border: 8px solid transparent;
}

.tooltip-flyout--top::after {
  top: 100%;
  border-top-color: var(--panel-solid);
  border-bottom: none;
}

.tooltip-flyout--bottom::after {
  bottom: 100%;
  border-bottom-color: var(--panel-solid);
  border-top: none;
}

/* Modern Settings Buttons */
.settings-buttons {
  position: fixed;
  top: 24px;
  left: 24px;
  z-index: 40;
  display: flex;
  gap: 12px;
}

.settings-toggle {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  cursor: pointer;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  font-size: 14px;
  transition: all 0.2s ease;
  backdrop-filter: var(--glass);
}

.settings-toggle:hover {
  background: var(--primary);
  color: white;
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary);
}

.settings-toggle.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  box-shadow: var(--shadow-lg);
}

/* Modern Drawer */
.drawer {
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  width: 360px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  backdrop-filter: var(--glass);
  transform: translateX(0);
  transition: transform 0.3s ease;
  z-index: 45;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.drawer.closed {
  transform: translateX(-100%);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px;
  background: var(--panel-solid);
  border-bottom: 1px solid var(--border);
}

.drawer-title {
  font-weight: 600;
  font-size: 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
}

.drawer-close {
  background: transparent;
  color: var(--muted);
  border: none;
  cursor: pointer;
  font-size: 20px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: all 0.2s ease;
}

.drawer-close:hover {
  background: var(--border);
  color: var(--text);
}

.drawer-body {
  padding: 24px;
  overflow: auto;
  flex: 1;
  scrollbar-width: none;
}

.drawer-body > * {
  scrollbar-width: auto;
}

.drawer-body::-webkit-scrollbar {
  display: none;
}

.drawer-body > *::-webkit-scrollbar {
  display: initial;
}


.drawer-body label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.field-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.drawer-body input[type="number"] {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  outline: none;
  transition: all 0.2s ease;
  height: 40px;
  box-sizing: border-box;
  font-size: 14px;
  -moz-appearance: textfield;
  appearance: textfield;
}

.drawer-body input[type="number"]::-webkit-outer-spin-button,
.drawer-body input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.drawer-body input[type="number"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary) / 0.1;
  background: var(--panel);
}

/* Modern Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 28px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--border);
  border: 1px solid var(--border);
  transition: .3s;
  border-radius: 999px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 3px;
  top: 50%;
  transform: translateY(-50%);
  background: white;
  border-radius: 50%;
  transition: .3s;
  box-shadow: var(--shadow);
}

input:checked + .slider {
  background: var(--primary);
  border-color: var(--primary);
}

input:checked + .slider:before {
  transform: translate(20px, -50%);
}

/* Modern Drawer Actions */
.drawer-actions {
  display: flex;
  gap: 12px;
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  justify-content: center;
  align-items: center;
}

.drawer-actions .link-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 14px;
  font-weight: 500;
}

.drawer-actions .link-btn:hover {
  background: var(--border);
  color: var(--text);
}

.drawer-actions #reload-btn {
  background: var(--primary);
  color: white;
  border: 1px solid var(--primary);
  border-radius: 8px;
  padding: 10px 20px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.2s ease;
}

.drawer-actions #reload-btn:hover {
  background: var(--primary-700);
  border-color: var(--primary-700);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.drawer-actions #reload-btn:active {
  transform: translateY(0);
}

/* Modern Drawer Backdrop */
.drawer-backdrop.hidden {
  display: none;
}
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: var(--bg) / 0.6;
  z-index: 40;
  backdrop-filter: var(--glass);
}

/* Modern Scrollbars */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--primary) / 0.6 var(--border);
}


*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

*::-webkit-scrollbar-thumb {
  background: var(--primary) / 0.8;
  border-radius: 10px;
}

*::-webkit-scrollbar-track {
  background: var(--border) / 0.3;
}

/* Responsive Design */
@media (max-width: 768px) {
  .drawer {
    width: 320px;
  }

  .settings-toggle span {
    display: none;
  }

  #chart-container {
    margin: 8px;
    width: calc(100% - 16px);
    height: calc(100vh - 16px);
    border-radius: 12px;
  }

}

@media (max-width: 480px) {
  .drawer {
    width: 100%;
  }

  .settings-buttons {
    top: 16px;
    left: 16px;
  }
}
