    /* ═══════════════════════════════════════════════════════════════
       TOKENS DE DISEÑO — SISTEMA DE TEMAS CLARO / OSCURO
    ═══════════════════════════════════════════════════════════════ */
    :root {
      --bg-body: #0f0f11;
      --bg-card: #18181b;
      --border-color: #27272a;
      --text-primary: #e4e4e7;
      --text-secondary: #a1a1aa;
      --text-muted: #71717a;
      --accent-color: #c8102e;
      --accent-hover: #a50d24;
      --accent-light: rgba(200, 16, 46, 0.15);
      --success-color: #15803d;
      --success-hover: #166534;
      --danger-border: #7f1d1d;
      --danger-text: #f87171;
      --danger-light: rgba(127, 29, 29, 0.13);
    }

    body.light-mode {
      --bg-body: #ffffff;
      --bg-card: #f3f4f6;
      --border-color: #e5e7eb;
      --text-primary: #1f2937;
      --text-secondary: #4b5563;
      --text-muted: #6b7280;
      --accent-light: rgba(200, 16, 46, 0.08);
    }

    /* ─── RESET & BASE ─────────────────────────────────────────── */
    *,
    *::before,
    *::after {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
    }

    body {
      font-family: 'Inter', system-ui, -apple-system, "Segoe UI", sans-serif;
      background: var(--bg-body);
      color: var(--text-primary);
      font-size: 13px;
      height: 100vh;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      transition: background .15s, color .15s;
    }

    /* ─── TITLEBAR ─────────────────────────────────────────────── */
    #titlebar {
      background: var(--bg-card);
      padding: 9px 16px;
      border-bottom: 1px solid var(--border-color);
      display: flex;
      align-items: center;
      justify-content: space-between;
      flex-shrink: 0;
      gap: 8px;
      transition: background .15s, border-color .15s;
    }

    .titlebar-left {
      display: flex;
      align-items: center;
      gap: 8px;
    }

    .titlebar-right {
      display: flex;
      align-items: center;
      gap: 8px;
    }

    .titlebar-sub {
      font-size: 11px;
      color: var(--text-muted);
      font-weight: 400;
      padding-left: 10px;
      border-left: 1px solid var(--border-color);
      transition: color .15s;
    }

    body.light-mode .brand-blast {
      color: #111827 !important;
    }

    body.light-mode .brand-pilot {
      color: #4b5563 !important;
    }

    /* ─── TABS ──────────────────────────────────────────────────── */
    #tabs {
      display: none;
      background: var(--bg-card);
      border-bottom: 1px solid var(--border-color);
      flex-shrink: 0;
      align-items: center;
      gap: 0;
      transition: background .15s, border-color .15s;
    }

    #tabs.visible {
      display: flex;
    }

    .tab {
      padding: 9px 16px;
      font-size: 12px;
      font-weight: 500;
      cursor: pointer;
      border-bottom: 2px solid transparent;
      color: var(--text-muted);
      transition: all .15s;
      user-select: none;
      background: none;
      border-top: none;
      border-left: none;
      border-right: none;
    }

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

    .tab.active {
      color: var(--text-primary);
      border-bottom-color: var(--accent-color);
    }

    /* ─── PANELS ─────────────────────────────────────────────────── */
    #app {
      flex: 1;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      min-height: 0;
    }

    /* ─── HOME ─────────────────────────────────────────────────── */
    #home {
      flex: 1;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 32px;
      padding: 32px;
      overflow-y: auto;
    }

    .home-title {
      font-family: 'Outfit', sans-serif;
      font-size: 24px;
      font-weight: 800;
      color: var(--text-primary);
      text-align: center;
      letter-spacing: -0.3px;
    }

    .home-title span {
      color: var(--accent-color);
    }

    .home-subtitle {
      font-size: 13px;
      color: var(--text-muted);
      text-align: center;
    }

    .home-cards {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(280px, 380px));
      gap: 20px;
      justify-content: center;
      width: 100%;
      max-width: 900px;
    }

    .module-card {
      background: var(--bg-card);
      border: 2px solid var(--border-color);
      border-radius: 14px;
      padding: 28px 24px;
      cursor: pointer;
      transition: all .2s;
      display: flex;
      flex-direction: column;
      gap: 12px;
    }

    .module-card:hover {
      border-color: var(--accent-color);
      box-shadow: 0 0 0 1px rgba(200, 16, 46, 0.25), 0 8px 30px rgba(0, 0, 0, 0.35);
      transform: translateY(-2px);
    }

    .module-card-icon {
      font-size: 32px;
      line-height: 1;
    }

    .module-card-title {
      font-family: 'Outfit', sans-serif;
      font-size: 17px;
      font-weight: 700;
      color: var(--text-primary);
    }

    .module-card-desc {
      font-size: 12px;
      color: var(--text-secondary);
      line-height: 1.6;
    }

    .module-card-tag {
      display: inline-block;
      padding: 2px 10px;
      border-radius: 20px;
      font-size: 10px;
      font-weight: 600;
      letter-spacing: 0.5px;
      background: var(--accent-light);
      color: var(--accent-color);
      border: 1px solid rgba(200, 16, 46, 0.2);
      align-self: flex-start;
    }

    .module-card-features {
      display: flex;
      flex-direction: column;
      gap: 5px;
      margin-top: 4px;
    }

    .module-feature {
      display: flex;
      align-items: center;
      gap: 8px;
      font-size: 11px;
      color: var(--text-secondary);
    }

    .module-feature::before {
      content: '→';
      color: var(--accent-color);
      font-size: 10px;
    }

    /* ─── MAIN LAYOUT (Módulos activos) ─────────────────────────── */
    #module-view {
      flex: 1;
      display: none;
      flex-direction: column;
      overflow: hidden;
      min-height: 0;
    }

    #module-view.active {
      display: flex;
    }

    .module-container {
      flex: 1;
      display: flex;
      overflow: hidden;
      min-height: 0;
    }

    /* ─── SIDEBAR ────────────────────────────────────────────────── */
    #sidebar {
      width: 280px;
      min-width: 280px;
      background: var(--bg-body);
      border-right: 1px solid var(--border-color);
      display: flex;
      flex-direction: column;
      overflow-y: auto;
      overflow-x: hidden;
      padding-bottom: 12px;
      transition: background .15s, border-color .15s;
    }

    .side-panel {
      background: var(--bg-card);
      border: 1px solid var(--border-color);
      border-radius: 8px;
      padding: 14px;
      margin: 10px 10px 0 10px;
      transition: border-color .2s, box-shadow .2s;
    }

    .side-panel:hover {
      border-color: rgba(200, 16, 46, 0.25);
    }

    .side-title {
      font-size: 10px;
      font-weight: 700;
      letter-spacing: 0.8px;
      text-transform: uppercase;
      color: var(--text-secondary);
      margin-bottom: 12px;
      padding-bottom: 6px;
      border-bottom: 1px solid var(--border-color);
      display: flex;
      justify-content: space-between;
      align-items: center;
    }

    /* Import Drop */
    .import-drop {
      border: 1px dashed var(--text-muted);
      border-radius: 8px;
      padding: 22px 12px;
      text-align: center;
      cursor: pointer;
      transition: all .2s;
      background: var(--bg-body);
      margin-bottom: 8px;
    }

    .import-drop:hover,
    .import-drop.over {
      border-color: var(--accent-color);
      background: var(--accent-light);
    }

    .import-drop p {
      font-size: 11px;
      color: var(--text-muted);
      margin-top: 6px;
    }

    .import-drop strong {
      color: var(--text-primary);
      font-size: 12px;
    }

    /* File info */
    .file-info {
      font-size: 11px;
      padding: 10px;
      background: var(--bg-body);
      border: 1px solid var(--border-color);
      border-radius: 6px;
      margin-top: 6px;
      color: var(--text-secondary);
      display: none;
      line-height: 1.5;
      word-break: break-all;
    }

    .file-info strong {
      color: var(--accent-color);
    }

    /* Param rows */
    .param-row {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 6px;
    }

    .param-label {
      font-size: 11px;
      color: var(--text-secondary);
      flex: 1;
      padding-right: 8px;
    }

    .param-desc {
      font-size: 10px;
      color: var(--text-muted);
      margin: -2px 0 8px;
      line-height: 1.4;
    }

    .param-input {
      background: var(--bg-body);
      border: 1px solid var(--border-color);
      color: var(--text-primary);
      padding: 5px 7px;
      border-radius: 6px;
      width: 78px;
      font-size: 12px;
      outline: none;
      text-align: right;
      transition: border-color .15s;
    }

    .param-input:focus {
      border-color: var(--accent-color);
    }

    .param-input:hover {
      border-color: var(--text-muted);
    }

    /* KPIs */
    .kpi-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 6px;
      margin-top: 6px;
    }

    .kpi-card {
      background: var(--bg-body);
      border: 1px solid var(--border-color);
      border-radius: 6px;
      padding: 8px 10px;
      transition: border-color .15s;
    }

    .kpi-card:hover {
      border-color: var(--text-muted);
    }

    .kpi-val {
      font-family: 'Outfit', sans-serif;
      font-size: 15px;
      font-weight: 700;
      color: var(--text-primary);
      margin-top: 2px;
    }

    .kpi-lbl {
      font-size: 9px;
      color: var(--text-muted);
      text-transform: uppercase;
      letter-spacing: 0.5px;
    }

    /* Progress */
    .progress-wrap {
      margin-top: 10px;
      display: none;
    }

    .progress-bar-bg {
      width: 100%;
      background: var(--border-color);
      border-radius: 4px;
      height: 5px;
      overflow: hidden;
      margin-top: 5px;
    }

    .progress-bar-fill {
      height: 100%;
      background: var(--accent-color);
      width: 0%;
      transition: width .1s;
    }

    .progress-text {
      font-size: 10px;
      color: var(--text-secondary);
      text-align: right;
    }

    /* ─── BUTTONS ─────────────────────────────────────────────────── */
    .btn {
      padding: 7px 14px;
      font-size: 12px;
      font-weight: 500;
      border-radius: 6px;
      cursor: pointer;
      border: 1px solid var(--border-color);
      background: transparent;
      color: var(--text-secondary);
      transition: all .15s;
      white-space: nowrap;
      display: inline-flex;
      align-items: center;
      gap: 6px;
      font-family: 'Inter', sans-serif;
    }

    .btn:hover {
      background: var(--border-color);
      color: var(--text-primary);
    }

    .btn:disabled {
      opacity: .4;
      cursor: not-allowed;
    }

    .btn-primary {
      background: var(--accent-color);
      border-color: var(--accent-color);
      color: #fff !important;
    }

    .btn-primary:hover {
      background: var(--accent-hover);
      border-color: var(--accent-hover);
    }

    .btn-primary:disabled {
      background: rgba(200, 16, 46, .25);
      border-color: transparent;
    }

    .btn-success {
      background: var(--success-color);
      border-color: var(--success-color);
      color: #fff !important;
    }

    .btn-success:hover {
      background: var(--success-hover);
    }

    .btn-danger {
      border-color: var(--danger-border);
      color: var(--danger-text);
    }

    .btn-danger:hover {
      background: var(--danger-light);
    }

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

    .btn-sm {
      padding: 4px 10px;
      font-size: 11px;
    }

    .btn-mini {
      padding: 3px 9px;
      font-size: 10px;
      border-radius: 4px;
      background: var(--border-color);
      border: 1px solid transparent;
      color: var(--text-primary);
      cursor: pointer;
      transition: all .15s;
      font-family: 'Inter', sans-serif;
    }

    .btn-mini:hover {
      background: var(--text-muted);
      color: #fff;
    }

    .btn-mini.active {
      background: var(--accent-color);
      color: #fff;
    }

    .btn-mini:disabled {
      opacity: .4;
      cursor: not-allowed;
    }

    /* ─── CONTENT AREA ──────────────────────────────────────────── */
    #content {
      flex: 1;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      min-height: 0;
      position: relative;
      background: var(--bg-body);
    }

    /* Empty state */
    .empty-state {
      position: absolute;
      inset: 0;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      color: var(--text-muted);
      font-size: 13px;
      text-align: center;
      padding: 20px;
      gap: 12px;
    }

    .empty-icon {
      font-size: 48px;
      opacity: .6;
      animation: pulse 3s infinite ease-in-out;
    }

    @keyframes pulse {

      0%,
      100% {
        transform: scale(1);
        opacity: .45;
      }

      50% {
        transform: scale(1.06);
        opacity: .85;
      }
    }

    /* Plot containers */
    .plot-wrap {
      position: absolute;
      inset: 0;
      display: none;
    }

    .plot-wrap.active {
      display: block;
    }

    #m2-plot-3d.active {
      display: flex;
      justify-content: center;
      align-items: center;
    }

    #m2-dual-3d {
      display: flex;
      width: 100%;
      height: 100%;
      justify-content: center;
      align-items: center;
      gap: 8px;
      box-sizing: border-box;
      padding: 4px;
    }

    #m2-div-contour,
    #m2-div-surface {
      height: 100%;
      width: auto;
      aspect-ratio: 1;
      max-width: calc(50% - 4px);
      min-width: 0;
      flex-shrink: 0;
    }

    /* Tema claro en el FFT: el gráfico se dibuja siempre en estilo oscuro y aquí se invierte
       para obtener fondo claro. hue-rotate(180deg) conserva los matices de la escala de colores.
       Solo aplica al FFT, no a la superficie/contornos PPV 3D. */
    body.light-mode #m2-div-fft {
      filter: invert(1) hue-rotate(180deg);
    }

    #m1-plot-din.active {
      display: flex;
      flex-direction: column;
      height: 100%;
      gap: 12px;
      padding: 16px 20px;
      box-sizing: border-box;
    }

    .plot-div {
      width: 100%;
      height: 100%;
    }

    /* Panel de análisis scrollable */
    .analysis-scroll-wrap {
      position: absolute;
      inset: 0;
      overflow-y: auto;
      overflow-x: hidden;
      display: none;
    }

    .analysis-scroll-wrap.active {
      display: block;
    }

    .analysis-inner {
      padding: 20px 24px 32px;
    }

    .analysis-section-title {
      font-size: 13px;
      font-weight: 700;
      color: var(--text-primary);
      margin: 0 0 14px;
      padding-bottom: 8px;
      border-bottom: 1px solid var(--border-color);
      display: flex;
      align-items: center;
      gap: 8px;
    }

    .analysis-accent {
      color: var(--accent-color);
    }

    /* Cut range display */
    .range-inputs {
      display: flex;
      gap: 8px;
      align-items: center;
      margin-top: 6px;
    }

    .range-input-group {
      display: flex;
      flex-direction: column;
      gap: 3px;
      flex: 1;
    }

    .range-label {
      font-size: 10px;
      color: var(--text-muted);
    }

    .range-input {
      background: var(--bg-body);
      border: 1px solid var(--border-color);
      color: var(--text-primary);
      padding: 5px 8px;
      border-radius: 6px;
      font-size: 12px;
      outline: none;
      width: 100%;
      transition: border-color .15s;
    }

    .range-input:focus {
      border-color: var(--accent-color);
    }

    /* Presets row */
    .preset-row {
      display: flex;
      gap: 4px;
      align-items: center;
      margin-bottom: 10px;
    }

    .preset-label {
      font-size: 10px;
      color: var(--text-muted);
      margin-right: 4px;
    }

    /* ─── SCROLLBARS ─────────────────────────────────────────────── */
    ::-webkit-scrollbar {
      width: 5px;
      height: 5px;
    }

    ::-webkit-scrollbar-thumb {
      background: var(--border-color);
      border-radius: 3px;
    }

    ::-webkit-scrollbar-thumb:hover {
      background: var(--text-muted);
    }

    /* ─── SEPARADORES ───────────────────────────────────────────── */
    .divider {
      border: none;
      border-top: 1px solid var(--border-color);
      margin: 8px 0;
    }

    /* Theme toggle */
    #btn-theme-toggle {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 28px;
      height: 28px;
      padding: 0;
      border-radius: 50%;
      font-size: 14px;
      cursor: pointer;
      background: transparent;
      border: 1px solid var(--border-color);
      transition: all .15s;
    }

    #btn-theme-toggle:hover {
      background: var(--border-color);
    }

    /* Back button */
    #btn-back {
      font-size: 11px;
      padding: 4px 10px;
      border-radius: 6px;
      border: 1px solid var(--border-color);
      background: transparent;
      color: var(--text-muted);
      cursor: pointer;
      transition: all .15s;
      display: none;
      align-items: center;
      gap: 5px;
    }

    #btn-back.visible {
      display: flex;
    }

    #btn-back:hover {
      background: var(--border-color);
      color: var(--text-primary);
    }

    /* Fade animation */
    @keyframes fadeInUp {
      from {
        opacity: 0;
        transform: translateY(10px);
      }

      to {
        opacity: 1;
        transform: translateY(0);
      }
    }

    .fadein {
      animation: fadeInUp .25s ease;
    }

    /* ─── DRAG HANDLES (barras de recorte arrastrables) ─────────── */
    .crop-handle-overlay {
      position: absolute;
      inset: 0;
      pointer-events: none;
      /* la capa no bloquea el hover de Plotly */
      z-index: 20;
    }

    .crop-drag-handle {
      position: absolute;
      top: 0;
      bottom: 0;
      width: 14px;
      transform: translateX(-7px);
      cursor: ew-resize;
      pointer-events: all;
      user-select: none;
    }

    /* Línea vertical visible */
    .crop-drag-handle::after {
      content: '';
      position: absolute;
      left: 6px;
      top: 0;
      bottom: 0;
      width: 2px;
    }

    .crop-drag-handle.h-start::after {
      background: #c8102e;
      box-shadow: 0 0 6px rgba(200, 16, 46, .5);
    }

    .crop-drag-handle.h-end::after {
      background: #f59e0b;
      box-shadow: 0 0 6px rgba(245, 158, 11, .5);
    }

    /* Etiqueta flotante */
    .crop-drag-handle::before {
      content: attr(data-label);
      position: absolute;
      left: 50%;
      transform: translateX(-50%);
      top: 10px;
      font-size: 9px;
      font-weight: 700;
      letter-spacing: .4px;
      padding: 1px 5px;
      border-radius: 3px;
      pointer-events: none;
      white-space: nowrap;
      font-family: 'Inter', sans-serif;
    }

    .crop-drag-handle.h-start::before {
      background: #c8102e;
      color: #fff;
    }

    .crop-drag-handle.h-end::before {
      background: #f59e0b;
      color: #000;
    }
