  * { box-sizing: border-box; margin: 0; padding: 0; }
  body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #f5f7fa;
    color: #1f2937;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
  }
  #app-body {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }
  header {
    background: linear-gradient(135deg, #0f766e 0%, #0891b2 100%);
    color: white;
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  }
  header h1 { font-size: 22px; letter-spacing: 0.5px; }
  header .patient-info {
    background: rgba(255,255,255,0.15);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 14px;
  }
  nav.main-menu {
    background: white;
    padding: 12px 24px;
    display: flex;
    gap: 10px;
    border-bottom: 1px solid #e5e7eb;
    flex-wrap: wrap;
  }
  nav.main-menu button {
    padding: 10px 18px;
    border: 1px solid #0f766e;
    background: white;
    color: #0f766e;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
  }
  nav.main-menu button:hover { background: #0f766e; color: white; }
  nav.main-menu button.active { background: #0f766e; color: white; }
  /* ── SIDEBAR ─────────────────────────────────────────────────── */
  #sidebar {
    width: 260px;
    min-width: 220px;
    max-width: 260px;
    background: white;
    border-right: 1px solid #e5e7eb;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: width 0.2s, min-width 0.2s;
  }
  #sidebar.collapsed { width: 44px; min-width: 44px; }
  #sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-bottom: 1px solid #e5e7eb;
    font-size: 12px;
    font-weight: 700;
    color: #6b7280;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    overflow: hidden;
  }
  #sidebar-toggle:hover { background: #f9fafb; }
  #sidebar-toggle .toggle-icon { font-size: 14px; flex-shrink: 0; }
  #sidebar-content { flex: 1; overflow-y: auto; padding-bottom: 12px; }
  .sidebar-patient {
    border-bottom: 1px solid #f3f4f6;
  }
  .sidebar-patient-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px 8px 12px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: #1f2937;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.15s;
  }
  .sidebar-patient-header:hover { background: #f9fafb; }
  .sidebar-patient-header.active { color: #0f766e; }
  .sidebar-patient-header .chevron {
    font-size: 10px;
    color: #9ca3af;
    flex-shrink: 0;
    transition: transform 0.2s;
  }
  .sidebar-patient-header.open .chevron { transform: rotate(90deg); }
  .sidebar-patient-name { flex: 1; overflow: hidden; text-overflow: ellipsis; }
  .sidebar-races { display: none; }
  .sidebar-races.open { display: block; }
  .sidebar-race {
    padding: 6px 12px 6px 28px;
    font-size: 12px;
    color: #4b5563;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border-left: 2px solid transparent;
    transition: all 0.15s;
  }
  .sidebar-race:hover { background: #f0fdfa; color: #0f766e; border-left-color: #0f766e; }
  .sidebar-race.active { background: #f0fdfa; color: #0f766e; border-left-color: #0f766e; font-weight: 600; }
  .sidebar-no-races { padding: 4px 12px 8px 28px; font-size: 11px; color: #9ca3af; font-style: italic; }
  .sidebar-add-race {
    padding: 5px 12px 8px 28px;
    font-size: 11px;
    color: #0f766e;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
  }
  .sidebar-add-race:hover { text-decoration: underline; }
  #sidebar.collapsed #sidebar-content { display: none; }
  #sidebar.collapsed #sidebar-toggle .toggle-label { display: none; }

  /* ── PREVIEW MODE BANNER ──────────────────────────────────────── */
  #previewBanner {
    background: #fef3c7;
    border-bottom: 2px solid #f59e0b;
    padding: 8px 20px;
    display: none;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    color: #92400e;
    flex-wrap: wrap;
  }
  #previewBanner.visible { display: flex; }
  #previewBanner strong { color: #78350f; }
  #previewBanner .exit-preview {
    background: #92400e;
    color: white;
    border: none;
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    font-weight: 600;
    margin-left: auto;
  }
  #previewBanner .exit-preview:hover { background: #78350f; }

  main { padding: 24px; flex: 1; min-width: 0; overflow-y: auto; }
  .card {
    background: white;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    margin-bottom: 20px;
  }
  .card h2 { margin-bottom: 16px; color: #0f766e; font-size: 20px; }
  .card h3 { margin: 16px 0 10px; color: #374151; font-size: 16px; }
  button.primary {
    background: #0f766e;
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
  }
  button.primary:hover { background: #115e59; }
  button.secondary {
    background: white;
    color: #0f766e;
    border: 1px solid #0f766e;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
  }
  button.secondary:hover { background: #f0fdfa; }
  button.danger {
    background: #dc2626;
    color: white;
    border: none;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
  }
  button.danger:hover { background: #b91c1c; }
  button.tiny {
    padding: 4px 8px;
    font-size: 12px;
    border-radius: 4px;
    border: 1px solid #d1d5db;
    background: white;
    cursor: pointer;
  }
  button.tiny.danger-small {
    background: #fee2e2;
    color: #b91c1c;
    border-color: #fecaca;
  }
  input, select, textarea {
    padding: 9px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    width: 100%;
    font-family: inherit;
  }
  input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: #0f766e;
    box-shadow: 0 0 0 3px rgba(15,118,110,0.1);
  }
  label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 500;
    color: #374151;
  }
  .form-row { margin-bottom: 14px; }
  .form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
  }
  table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
    font-size: 13px;
  }
  th {
    background: #0f766e;
    color: white;
    padding: 10px 8px;
    text-align: left;
    font-weight: 500;
    position: sticky;
    top: 0;
  }
  td {
    padding: 8px;
    border-bottom: 1px solid #e5e7eb;
    vertical-align: middle;
  }
  tr:hover td { background: #f9fafb; }
  .table-container {
    max-height: 600px;
    overflow: auto;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
  }
  /* ── Toast notification ── */
  #nm-toast {
    position: fixed;
    bottom: 24px; right: 24px;
    padding: 10px 18px;
    border-radius: 10px;
    font-size: 13px; font-weight: 600;
    max-width: 360px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
  }
  #nm-toast.show { opacity: 1; }
  #nm-toast.info  { background:#f0fdf4; color:#166534; border:1px solid #86efac; }
  #nm-toast.error { background:#fef2f2; color:#991b1b; border:1px solid #fca5a5; }
  .modal-backdrop {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 100;
    padding: 20px;
  }
  .modal-backdrop.show { display: flex; }
  .modal {
    background: white;
    border-radius: 12px;
    padding: 24px;
    max-width: 760px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
  }
  .modal h2 { margin-bottom: 16px; color: #0f766e; }
  .patient-list, .race-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 12px;
    margin-top: 14px;
  }
  .list-item {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 14px;
    cursor: pointer;
    transition: all 0.2s;
  }
  .list-item:hover {
    border-color: #0f766e;
    box-shadow: 0 2px 6px rgba(15,118,110,0.15);
  }
  .list-item h4 { color: #0f766e; margin-bottom: 4px; font-size: 15px; }
  .list-item p { color: #6b7280; font-size: 12px; }
  .race-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 2px solid #0f766e;
  }
  .tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 16px;
    border-bottom: 1px solid #e5e7eb;
  }
  .tab {
    padding: 10px 16px;
    cursor: pointer;
    border: none;
    background: none;
    color: #6b7280;
    font-size: 14px;
    font-weight: 500;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
  }
  .tab.active { color: #0f766e; border-bottom-color: #0f766e; }
  .empty-state { text-align: center; padding: 40px 20px; color: #6b7280; }
  .empty-state p { margin-bottom: 16px; }
  .stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
  }
  .stat {
    background: #f0fdfa;
    border-left: 4px solid #0f766e;
    padding: 12px 14px;
    border-radius: 6px;
  }
  .stat .label { font-size: 11px; color: #6b7280; text-transform: uppercase; letter-spacing: 0.5px; }
  .stat .value { font-size: 20px; font-weight: 600; color: #0f766e; margin-top: 2px; }
  input.cell-input {
    padding: 4px 6px;
    font-size: 13px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    width: 90%;
  }
  select.cell-select {
    padding: 4px 6px;
    font-size: 13px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    width: 100%;
  }
  .actions-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 14px;
    align-items: center;
  }
  .upload-area {
    border: 2px dashed #0f766e;
    border-radius: 10px;
    padding: 30px;
    text-align: center;
    background: #f0fdfa;
    cursor: pointer;
    transition: background 0.2s;
  }
  .upload-area:hover { background: #ccfbf1; }
  .upload-area input { display: none; }
  .badge {
    display: inline-block;
    background: #0f766e;
    color: white;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 11px;
    margin-left: 6px;
  }
  .badge.user { background: #c2410c; }
  .badge.web { background: #0369a1; }
  .badge.cat-run_fast   { background: #16a34a; color:#111; }
  .badge.cat-run_pace   { background: #ca8a04; color:#111; }
  .badge.cat-light_trot { background: #ea580c; }
  .badge.cat-power_hike { background: #dc2626; }
  .badge.cat-climb      { background: #7c3aed; }
  input.pace-input { font-family: ui-monospace, monospace; text-align: center; letter-spacing: 1px; max-width: 110px; }
  .nut-params-bar { display:flex; gap:16px; flex-wrap:wrap; align-items:center; background:#f0fdfa; border:1px solid #99f6e4; border-radius:8px; padding:12px 16px; margin-bottom:14px; }
  .nut-params-bar .nut-item { font-size:14px; }
  .nut-params-bar .nut-item strong { color:#0f766e; }
  .req-cell { font-family:ui-monospace,monospace; font-size:12px; line-height:1.6; }
  .nut-req  { color:#374151; font-weight:600; }
  .nut-sep  { color:#9ca3af; font-size:11px; margin:0 1px; }
  .nut-pre  { color:#0f766e; font-weight:700; }
  .diff-ok { color:#059669; font-size:11px; font-weight:600; }
  .diff-bad { color:#dc2626; font-size:11px; font-weight:600; }
  .caffeine-badge { display:inline-block; background:#7c3aed; color:white; padding:2px 8px; border-radius:12px; font-size:11px; }
  tfoot td { background:#f0fdfa; font-weight:600; border-top:2px solid #0f766e; }
  .supp-diff-row td { background:#fffbeb; font-size:12px; color:#6b7280; }
  .muted { color: #6b7280; font-size: 13px; }
  .hidden { display: none !important; }
  .gain-pos { color: #059669; font-weight: 500; }
  .gain-neg { color: #dc2626; font-weight: 500; }
  .action-bar {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 18px;
  }
  .checkbox-row { display: flex; align-items: center; gap: 8px; }
  .checkbox-row input { width: auto; }
  .filter-box { margin-left: auto; display: flex; gap: 8px; align-items: center; }
  .filter-box select { min-width: 210px; }
  pre.raw {
    background: #f9fafb; padding: 10px; border-radius: 6px;
    max-height: 220px; overflow: auto; white-space: pre-wrap;
    font-size: 12px; color: #374151; border: 1px solid #e5e7eb;
  }
  details summary { cursor: pointer; padding: 4px 0; }
  .progress-bar {
    height: 6px; background: #e5e7eb; border-radius: 3px;
    margin-top: 8px; overflow: hidden;
  }
  .progress-bar > div {
    height: 100%; background: #0f766e; width: 0; transition: width 0.3s;
  }
  .chart-wrap {
    background: white; border: 1px solid #e5e7eb; border-radius: 10px;
    padding: 10px; margin-bottom: 18px;
    overflow-x: auto; overflow-y: hidden;
  }
  .chart-wrap svg { display: block; touch-action: pan-x pan-y; user-select: none; }
  /* Zoom control bar above the chart */
  .chart-zoom-bar {
    display: flex; align-items: center; gap: 8px;
    margin-bottom: 8px; padding: 6px 8px;
    background: #f8fafc; border: 1px solid #e5e7eb; border-radius: 8px;
    font-size: 12px; color: #374151;
    flex-wrap: wrap;
  }
  .chart-zoom-bar .zoom-label {
    font-weight: 600; color: #0f766e; min-width: 70px; text-align: center;
  }
  .chart-zoom-bar button {
    padding: 3px 10px; font-size: 13px; font-weight: 700;
    border: 1px solid #d1d5db; border-radius: 6px; cursor: pointer;
    background: white; color: #374151; line-height: 1.4;
    transition: background 0.15s;
  }
  .chart-zoom-bar button:hover { background: #f0fdf4; border-color: #86efac; color: #0f766e; }
  .chart-zoom-bar button.active { background: #0f766e; color: white; border-color: #0f766e; }
  .tramo-handle { cursor: ew-resize; transition: fill 0.15s; }
  .tramo-handle:hover { fill: #047857; }
  .tramo-poly { transition: fill-opacity 0.15s, stroke-width 0.15s; }
  .tramo-poly.hovered { fill-opacity: 1 !important; stroke: #111827 !important; stroke-width: 1.8 !important; }
  tr[data-tramo-id] { cursor: default; }
  tr[data-tramo-id].tramo-highlighted { background: rgba(16,185,129,0.08); }
  .cat-legend {
    display: flex; gap: 12px; flex-wrap: wrap;
    margin-top: 8px; font-size: 12px; color: #374151;
  }
  .cat-legend .dot {
    display: inline-block; width: 12px; height: 12px; border-radius: 2px;
    margin-right: 4px; vertical-align: middle;
  }
  .time-stack {
    display: flex; flex-direction: column; gap: 2px;
    font-family: ui-monospace, monospace; font-size: 12px;
  }
  .time-stack .opt  { color: #059669; }
  .time-stack .real { color: #0f766e; font-weight: 600; }
  .time-stack .pes  { color: #dc2626; }
  .inline-form {
    background: #f0fdfa; padding: 14px; border-radius: 8px;
    margin-bottom: 14px; border: 1px solid #99f6e4;
  }
  .inline-form h4 { color: #0f766e; margin-bottom: 10px; font-size: 14px; }
  .chart-tooltip {
    position: absolute; background: white; border: 1px solid #d1d5db;
    border-radius: 6px; padding: 6px 10px; font-size: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1); pointer-events: none;
    z-index: 50; white-space: nowrap;
  }

  /* ── LOGIN OVERLAY ─────────────────────────────────────────── */
  #loginOverlay {
    position: fixed; inset: 0; z-index: 9999;
    background: linear-gradient(135deg, #0f766e 0%, #0891b2 100%);
    display: flex; align-items: center; justify-content: center;
  }
  .login-box {
    background: white; border-radius: 16px; padding: 40px 48px;
    width: 400px; max-width: 95vw;
    box-shadow: 0 24px 60px rgba(0,0,0,0.3);
  }
  .login-logo { font-size: 28px; font-weight: 700; color: #0f766e; margin-bottom: 4px; }
  .login-sub { color: #6b7280; font-size: 13px; margin-bottom: 28px; }
  .login-field { margin-bottom: 16px; }
  .login-field label { display: block; font-size: 13px; font-weight: 600; color: #374151; margin-bottom: 6px; }
  .login-field input {
    width: 100%; padding: 10px 14px; border: 1.5px solid #d1d5db;
    border-radius: 8px; font-size: 15px; outline: none; transition: border 0.2s;
  }
  .login-field input:focus { border-color: #0f766e; }
  .login-error {
    background: #fee2e2; color: #dc2626; padding: 10px 14px;
    border-radius: 8px; font-size: 13px; margin-bottom: 16px; display: none;
  }
  .login-error.show { display: block; }
  .login-btn {
    width: 100%; padding: 12px; background: #0f766e; color: white;
    border: none; border-radius: 8px; font-size: 15px; font-weight: 600;
    cursor: pointer; transition: background 0.2s; margin-top: 8px;
  }
  .login-btn:hover { background: #115e59; }

  /* ── SESSION BAR EN HEADER ─────────────────────────────────── */
  #sessionBar { display: flex; align-items: center; gap: 10px; }
  .session-user { font-size: 13px; opacity: 0.85; }
  .mode-toggle {
    display: flex; background: rgba(255,255,255,0.15);
    border-radius: 20px; padding: 2px; gap: 2px;
  }
  .mode-toggle button {
    padding: 4px 14px; border: none; border-radius: 18px;
    font-size: 12px; font-weight: 500; cursor: pointer;
    background: transparent; color: white; transition: all 0.2s;
  }
  .mode-toggle button.active { background: white; color: #0f766e; }
  .btn-logout {
    background: rgba(255,255,255,0.15); color: white;
    border: 1px solid rgba(255,255,255,0.3); padding: 5px 12px;
    border-radius: 8px; font-size: 12px; cursor: pointer; transition: background 0.2s;
  }
  .btn-logout:hover { background: rgba(255,255,255,0.28); }

  /* ── MODO PACIENTE ─────────────────────────────────────────── */
  .mode-patient-banner {
    background: #ecfdf5; border: 1px solid #6ee7b7; border-radius: 8px;
    padding: 8px 16px; display: flex; align-items: center; gap: 8px;
    font-size: 13px; color: #065f46; margin-bottom: 16px;
  }
  .patient-race-list {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(260px,1fr));
    gap: 14px; margin-top: 16px;
  }
  .patient-race-card {
    background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 10px;
    padding: 18px 20px; cursor: pointer; transition: all 0.2s;
  }
  .patient-race-card:hover { border-color: #0f766e; background: #f0fdfa; box-shadow: 0 2px 8px rgba(15,118,110,0.12); }
  .patient-race-card .race-name { font-weight: 600; color: #111827; font-size: 15px; }
  .patient-race-card .race-meta { color: #6b7280; font-size: 13px; margin-top: 5px; }
  /* ── READ-ONLY MODE ─────────────────────────────────────────── */
  .readonly-mode input, .readonly-mode select, .readonly-mode textarea {
    pointer-events: none !important;
    background: #f9fafb !important;
    color: #6b7280 !important;
    cursor: default !important;
  }
  /* Hide ALL interactive elements in read-only mode */
  .readonly-mode button,
  .readonly-mode .action-bar,
  .readonly-mode .actions-row,
  .readonly-mode .nut-params-bar { display: none !important; }
  /* Re-show tab switcher buttons — navigation only */
  .readonly-mode button.tab { display: inline-flex !important; }
  /* Re-show chart zoom controls — user explicitly allowed to change zoom */
  .readonly-mode .chart-zoom-bar { display: flex !important; }
  .readonly-mode .chart-zoom-bar button { display: inline-flex !important; }
  /* Keep stat grid and summary info visible */
  .readonly-mode .stat-grid { pointer-events: none; }

  /* ── GESTIÓN DE USUARIOS (Admin) ───────────────────────────── */
  .user-card {
    background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 8px;
    padding: 12px 16px; display: flex; align-items: center; gap: 12px;
    flex-wrap: wrap;
  }
  .user-badge {
    padding: 2px 10px; border-radius: 12px; font-size: 11px; font-weight: 600;
  }
  .user-badge.admin { background: #fef3c7; color: #92400e; }
  .user-badge.nutricionista { background: #dbeafe; color: #1e40af; }
  .access-config-section {
    background: #f0fdfa; border: 1px solid #99f6e4; border-radius: 8px;
    padding: 14px; margin-top: 12px;
  }
  .access-config-section h4 { color: #0f766e; font-size: 13px; margin-bottom: 10px; }
