:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --border: #d9e0e6;
  --text: #1f2a33;
  --muted: #64748b;
  --accent: #1a5276;
  --accent-2: #0f766e;
  --danger: #b91c1c;
  --warning: #b45309;
  --success: #047857;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.045);
  --radius: 12px;
  --toggle-off: #c8d1d9;
  --toggle-knob: #ffffff;
  --focus-ring: rgba(26, 82, 118, 0.18);
  --mono-bg: #f8fafc;
  --plot-bg: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161c;
    --panel: #1a222b;
    --panel-soft: #141b22;
    --border: #2d3945;
    --text: #e6edf3;
    --muted: #9fb0bf;
    --accent: #5fa8d3;
    --accent-2: #2dd4bf;
    --danger: #f87171;
    --warning: #fbbf24;
    --success: #34d399;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.24);
    --toggle-off: #44515d;
    --toggle-knob: #f4f7fa;
    --focus-ring: rgba(95, 168, 211, 0.22);
    --mono-bg: #141b22;
    --plot-bg: #1a222b;
  }
}

/* -------------------------------------------------------------------------- */
/* Base                                                                       */
/* -------------------------------------------------------------------------- */

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

code,
pre {
  font-family:
    ui-monospace,
    SFMono-Regular,
    Menlo,
    Monaco,
    Consolas,
    monospace;
}

code {
  font-size: 0.9em;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

/* -------------------------------------------------------------------------- */
/* App layout                                                                 */
/* -------------------------------------------------------------------------- */

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

.sidebar {
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel) 96%, transparent);
  padding: 16px;
}

.main-content {
  min-width: 0;
  padding: 16px;
  display: grid;
  grid-template-rows: auto auto auto;
  gap: 12px;
  align-content: start;
}

/* -------------------------------------------------------------------------- */
/* Sidebar                                                                    */
/* -------------------------------------------------------------------------- */

.app-brand {
  margin-bottom: 16px;
}

.app-brand h1 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: -0.03em;
}

.app-brand p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

.sidebar-section,
.details-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}

.sidebar-section {
  padding: 13px;
}

.section-title {
  margin: 0 0 11px;
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--text);
}

.control {
  display: grid;
  gap: 7px;
  margin-bottom: 13px;
}

.control:last-child {
  margin-bottom: 0;
}

label {
  font-size: 0.86rem;
  font-weight: 700;
}

small {
  color: var(--muted);
  line-height: 1.35;
  font-size: 0.78rem;
}

/* -------------------------------------------------------------------------- */
/* Inputs                                                                     */
/* -------------------------------------------------------------------------- */

input[type="file"],
input[type="number"],
input[type="text"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--panel-soft);
  color: var(--text);
}

input[type="number"] {
  min-width: 0;
}

input:focus,
button:focus {
  outline: none;
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.status-box {
  padding: 9px 10px;
  border-radius: 10px;
  background: var(--panel-soft);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.86rem;
}

.warning-box {
  margin-top: 10px;
  padding: 10px 11px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--warning) 45%, var(--border));
  background: color-mix(in srgb, var(--warning) 12%, transparent);
  font-size: 0.84rem;
  line-height: 1.35;
}

.warning-box strong {
  color: var(--warning);
}

/* -------------------------------------------------------------------------- */
/* Segmented controls                                                         */
/* -------------------------------------------------------------------------- */

.segmented-control {
  display: grid;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--panel-soft);
}

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

.segmented-control input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-control label {
  margin: 0;
  padding: 9px 8px;
  text-align: center;
  font-size: 0.86rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  border-right: 1px solid var(--border);
  transition:
    background 0.15s ease,
    color 0.15s ease;
}

.segmented-control label:last-of-type {
  border-right: 0;
}

.segmented-control input[type="radio"]:checked + label {
  background: var(--accent);
  color: #ffffff;
}

@media (prefers-color-scheme: dark) {
  .segmented-control input[type="radio"]:checked + label {
    color: #11161c;
  }
}

/* -------------------------------------------------------------------------- */
/* Range controls                                                             */
/* -------------------------------------------------------------------------- */

.range-header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
}

.range-value {
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
  font-family:
    ui-monospace,
    SFMono-Regular,
    Menlo,
    Monaco,
    Consolas,
    monospace;
}

input[type="range"] {
  appearance: none;
  -webkit-appearance: none;
  height: 6px;
  border-radius: 999px;
  background: #d6dee6;
  outline: none;
  width: 100%;
  accent-color: var(--accent);
}

@media (prefers-color-scheme: dark) {
  input[type="range"] {
    background: #33414d;
  }
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 0;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 0;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

/* -------------------------------------------------------------------------- */
/* Slider + number controls                                                   */
/* -------------------------------------------------------------------------- */

.slider-number-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 70px;
  gap: 8px;
  align-items: center;
}

.slider-number-row input[type="number"],
.slider-number-row input[type="text"] {
  padding: 7px 8px;
  text-align: right;
  font-family:
    ui-monospace,
    SFMono-Regular,
    Menlo,
    Monaco,
    Consolas,
    monospace;
  font-size: 0.82rem;
}

/* -------------------------------------------------------------------------- */
/* Range inputs                                                               */
/* -------------------------------------------------------------------------- */

.range-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* -------------------------------------------------------------------------- */
/* Toggle switches                                                            */
/* -------------------------------------------------------------------------- */

.toggle-list {
  display: grid;
  gap: 8px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 38px;
  cursor: pointer;
  user-select: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  background: var(--panel-soft);
}

.toggle-row > span:first-child {
  flex: 1 1 auto;
  font-size: 0.86rem;
  font-weight: 700;
}

.toggle-row small {
  display: block;
  margin-top: 1px;
  font-weight: 400;
}

.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 26px;
  flex: 0 0 auto;
}

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

.switch .slider {
  position: absolute;
  inset: 0;
  background: var(--toggle-off);
  border-radius: 999px;
  transition:
    background 0.2s ease,
    box-shadow 0.2s ease;
}

.switch .slider::before {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: var(--toggle-knob);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.22);
  transition: transform 0.2s ease;
}

.switch input:checked + .slider {
  background: var(--accent);
}

.switch input:checked + .slider::before {
  transform: translateX(18px);
}

/* -------------------------------------------------------------------------- */
/* Buttons                                                                    */
/* -------------------------------------------------------------------------- */

.button-stack {
  display: grid;
  gap: 8px;
}

.btn {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--panel-soft);
  color: var(--text);
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    transform 0.05s ease;
}

.btn:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
}

.btn:active {
  transform: translateY(1px);
}

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

.btn.secondary {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #ffffff;
  font-weight: 800;
}

.btn.subtle {
  background: var(--panel-soft);
}

.btn.full {
  width: 100%;
  margin-top: 8px;
}

@media (prefers-color-scheme: dark) {
  .btn.primary,
  .btn.secondary {
    color: #11161c;
  }
}

/* -------------------------------------------------------------------------- */
/* Details / info / peaks                                                     */
/* -------------------------------------------------------------------------- */

.details-panel {
  overflow: hidden;
}

.details-panel summary {
  cursor: pointer;
  padding: 12px 14px;
  font-size: 0.9rem;
  font-weight: 800;
  user-select: none;
  background: var(--panel-soft);
  border-bottom: 1px solid var(--border);
}

.details-panel:not([open]) summary {
  border-bottom: 0;
}

.details-body {
  padding: 12px 14px;
}

.mono-box {
  margin: 0;
  white-space: pre-wrap;
  font-size: 0.78rem;
  line-height: 1.45;
  background: var(--mono-bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px;
  max-height: 220px;
  overflow: auto;
}

/* -------------------------------------------------------------------------- */
/* Main plot area                                                             */
/* -------------------------------------------------------------------------- */

.plot-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 0;
}

.plot-header h2 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: -0.03em;
}

.plot-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.plot-card {
  min-width: 0;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.plot-area {
  min-height: 620px;
  position: relative;
  background: var(--plot-bg);
  overflow: hidden;
}

/* -------------------------------------------------------------------------- */
/* Analysis panels below plot                                                 */
/* -------------------------------------------------------------------------- */

.analysis-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.analysis-panel {
  margin-bottom: 0;
  align-self: start;
}

/* -------------------------------------------------------------------------- */
/* Plotly modebar                                                             */
/* -------------------------------------------------------------------------- */

.js-plotly-plot .plotly .modebar {
  background: transparent !important;
}

.js-plotly-plot .plotly .modebar-btn {
  background: transparent !important;
}

.js-plotly-plot .plotly .modebar-btn svg {
  fill: var(--muted) !important;
}

.js-plotly-plot .plotly .modebar-btn:hover svg {
  fill: var(--text) !important;
}

/* -------------------------------------------------------------------------- */
/* Toast                                                                      */
/* -------------------------------------------------------------------------- */

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 9999;
  max-width: 340px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--text);
  color: var(--panel);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  font-size: 0.9rem;
  line-height: 1.35;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* -------------------------------------------------------------------------- */
/* Responsive                                                                 */
/* -------------------------------------------------------------------------- */

@media (max-width: 1100px) {
  .analysis-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .main-content {
    padding: 14px;
  }

  .plot-area {
    min-height: 520px;
  }
}

@media (max-width: 600px) {
  .sidebar,
  .main-content {
    padding: 12px;
  }

  .plot-header {
    flex-direction: column;
  }

  .range-inputs {
    grid-template-columns: 1fr;
  }

  .slider-number-row {
    grid-template-columns: 1fr;
  }

  .plot-area {
    min-height: 440px;
  }

  .toast {
    right: 14px;
    left: 14px;
    bottom: 14px;
    max-width: none;
  }
}