/* ============================================================
   ProEng — Estudio de Tiempos · styles.css
   Paleta: Blanco / Negro / Naranja
   Mobile-First: base = teléfono, escala hacia arriba
   Breakpoints:
     sm  ≥ 480px   (teléfono grande / landscape)
     md  ≥ 768px   (tablet)
     lg  ≥ 1024px  (laptop / desktop pequeño)
     xl  ≥ 1280px  (desktop)
   ============================================================ */


/* ============================================================
   0 · TOKENS DE DISEÑO
   ============================================================ */
:root {
  /* Colores — Blanco / Negro / Naranja */
  --bg:        #f5f3f0;
  --surface:   #ffffff;
  --surface2:  #f9f8f6;
  --surface3:  #f0eeeb;
  --border:    #e4e0da;
  --border2:   #d4d0c8;
  --accent:    #ff6b2c;
  --accent2:   #e85a1b;
  --accent3:   #d14800;
  --accent4:   #ff8f5e;
  --text:      #1a1714;
  --muted:     #8c857a;
  --muted2:    #6b6560;
  --danger:    #d93025;
  --warn:      #e6a200;
  --green:     #1a8a4a;

  /* Tipografía */
  --font-body:    'Plus Jakarta Sans', sans-serif;
  --font-mono:    'DM Mono', monospace;
  --font-display: 'Syne', sans-serif;
  --font-num:     'Barlow Condensed', sans-serif;

  /* Espaciado base — mobile */
  --pad:       14px;
  --gap:       12px;
  --radius:    12px;
  --header-h:  54px;

  /* Tamaños cronómetro — mobile */
  --crono-seg-size: 3.8rem;
  --crono-ms-size:  2.4rem;
  --crono-sep-size: 2.9rem;
  --crono-sep-sm:   2rem;
}


/* ============================================================
   1 · RESET
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-y: scroll;
}

a             { color: inherit; text-decoration: none; }
img           { max-width: 100%; display: block; }
button, input,
select, textarea { font-family: inherit; }

::-webkit-scrollbar          { width: 5px; height: 5px; }
::-webkit-scrollbar-track    { background: transparent; }
::-webkit-scrollbar-thumb    { background: var(--border2); border-radius: 3px; }


/* ============================================================
   2 · APP SHELL + SIDEBAR
   ============================================================ */

/* Shell: sidebar + content side by side */
.app-shell {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
}

/* ── CONTENT AREA ── */
.content-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  transition: margin-left 0.28s cubic-bezier(.4,0,.2,1);
}

/* ── SIDEBAR ── */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  height: 100%;
  width: 240px;
  background: #111009;
  border-right: 1px solid #2a261f;
  z-index: 200;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.28s cubic-bezier(.4,0,.2,1);
  will-change: transform;
}

/* Sidebar visible en mobile (clase JS) */
.sidebar.is-open {
  transform: translateX(0);
}

/* ── SIDEBAR INNER ── */
.sidebar-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
}

/* ── HEADER DEL SIDEBAR ── */
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  height: 54px;
  border-bottom: 1px solid #2a261f;
  flex-shrink: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Botón cerrar solo aparece en mobile */
.btn-sidebar-close {
  background: transparent;
  border: none;
  color: #6b6560;
  cursor: pointer;
  padding: 6px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}
.btn-sidebar-close:hover { color: #ffffff; background: #27241e; }

/* ── NAVEGACIÓN ── */
.sidebar-nav {
  flex: 1;
  padding: 16px 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-section-label {
  font-family: var(--font-mono);
  font-size: 0.52rem;
  text-transform: uppercase;
  letter-spacing: 1.8px;
  color: #4d4740;
  padding: 0 8px;
  margin-bottom: 6px;
  display: block;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  color: #9c958a;
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background 0.14s, color 0.14s;
  text-decoration: none;
  white-space: nowrap;
}
.sidebar-item svg { flex-shrink: 0; opacity: 0.7; }
.sidebar-item:hover {
  background: #1e1b16;
  color: #e0d8d0;
}
.sidebar-item:hover svg { opacity: 1; }

.sidebar-item--active {
  background: rgba(255, 107, 44, 0.12);
  color: var(--accent);
  border: 1px solid rgba(255, 107, 44, 0.2);
}
.sidebar-item--active svg { opacity: 1; }
.sidebar-item--active:hover { background: rgba(255, 107, 44, 0.18); }

/* ── FOOTER DEL SIDEBAR ── */
.sidebar-footer {
  padding: 10px;
  border-top: 1px solid #2a261f;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
}

.sidebar-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: #ffffff;
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-user-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.sidebar-user-name {
  font-size: 0.76rem;
  font-weight: 700;
  color: #d4cfc8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-role {
  font-family: var(--font-mono);
  font-size: 0.55rem;
  color: #4d4740;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.sidebar-item--logout { color: #6b6560; }
.sidebar-item--logout:hover { color: var(--danger); background: rgba(217, 48, 37, 0.08); }

/* ── OVERLAY MOBILE ── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 190;
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.28s;
}
.sidebar-overlay.is-visible {
  display: block;
  opacity: 1;
}

/* ── TOGGLE BUTTON (hamburguesa) ── */
.btn-sidebar-toggle {
  background: transparent;
  border: 1px solid #3d3830;
  color: #9c958a;
  border-radius: 8px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.btn-sidebar-toggle:hover { color: #ffffff; border-color: #6b6560; }

/* ── DESKTOP: sidebar siempre visible ≥ 1024px ── */
@media (min-width: 1024px) {
  .sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    transform: translateX(0);
    flex-shrink: 0;
  }

  .sidebar-overlay { display: none !important; }

  .btn-sidebar-close { display: none; }

  /* El toggle colapsa/expande en desktop */
  .app-shell.sidebar-collapsed .sidebar { transform: translateX(-100%); position: fixed; }
  .app-shell.sidebar-collapsed .content-area { margin-left: 0; }
}

/* ── Sidebar dark-mode adjustments ── */
[data-theme="dark"] .sidebar { background: #0a0907; border-right-color: #1e1b16; }
[data-theme="dark"] .sidebar-head { border-bottom-color: #1e1b16; }
[data-theme="dark"] .sidebar-footer { border-top-color: #1e1b16; }
[data-theme="dark"] .sidebar-item:hover { background: #141210; }


/* ============================================================
   3 · HEADER
   ============================================================ */
.app-header {
  height: var(--header-h);
  background: var(--text);
  border-bottom: 1px solid #2a261f;
  display: flex;
  align-items: center;
  padding: 0 var(--pad);
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
}

.logo-icon {
  width: 28px;
  height: 28px;
  background: var(--accent);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.logo-icon svg { width: 14px; height: 14px; }

.logo-text {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: -0.3px;
  color: #ffffff;
}
.logo-text em { color: var(--accent); font-style: normal; }

/* Módulo del header — oculto en mobile */
.header-module {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: #9c958a;
  letter-spacing: 0.3px;
  display: none;
}

.header-actions {
  display: flex;
  gap: 6px;
  margin-left: auto;
  align-items: center;
  flex-shrink: 0;
}

/* Mobile: solo icono, sin texto */
.header-actions .btn-ghost .btn-label { display: none; }

/* Header ghost buttons — light on dark */
.header-actions .btn-ghost {
  border-color: #3d3830;
  color: #b0a99e;
}
.header-actions .btn-ghost:not(:disabled):hover {
  color: #ffffff;
  border-color: #6b6560;
}


/* ============================================================
   3 · BOTONES
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: 9px;
  border: none;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 700;
  font-family: var(--font-body);
  transition: all 0.16s;
  white-space: nowrap;
  line-height: 1;
  min-height: 44px;
  min-width: 44px;
}
.btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  transform: none !important;
  filter: none !important;
  box-shadow: none !important;
}

.btn-accent              { background: var(--accent); color: #ffffff; }
.btn-accent:not(:disabled):active  { filter: brightness(0.9); }
.btn-accent:not(:disabled):hover   { filter: brightness(1.08); }

.btn-ghost               { background: transparent; color: var(--muted2); border: 1px solid var(--border2); }
.btn-ghost:not(:disabled):hover    { color: var(--text); border-color: var(--muted); }
.btn-ghost:not(:disabled):active   { background: var(--surface3); }

.btn-lap {
  background: rgba(255, 107, 44, 0.1);
  color: var(--accent);
  border: 1px solid rgba(255, 107, 44, 0.3);
}
.btn-lap:not(:disabled):hover      { background: rgba(255, 107, 44, 0.18); }
.btn-lap:not(:disabled):active     { background: rgba(255, 107, 44, 0.25); }

.btn-danger {
  background: rgba(217, 48, 37, 0.08);
  color: var(--danger);
  border: 1px solid rgba(217, 48, 37, 0.25);
}
.btn-danger:not(:disabled):hover   { background: rgba(217, 48, 37, 0.15); }
.btn-danger:not(:disabled):active  { background: rgba(217, 48, 37, 0.22); }

.btn-sm  { padding: 7px 12px; font-size: 0.72rem; min-height: 36px; }
.btn-xs  { padding: 5px 9px;  font-size: 0.66rem; min-height: 30px; }


/* ============================================================
   4 · LAYOUT PRINCIPAL — columna única en mobile
   ============================================================ */
.app-main {
  flex: 1;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
      -ms-flex-direction: column;
          flex-direction: column;
  gap: var(--gap);
  padding: var(--pad);
  width: 100%;
  max-width: 1500px;
  margin: 0 auto;
}

.app-main--full {
  max-width: 100%;
}

.col-left,
.col-right {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  min-width: 0;
}


/* ============================================================
   5 · CARDS
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--pad);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.card-title {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--muted);
  margin-bottom: 14px;
}
.card-title-icon { font-size: 0.85rem; }

.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  margin-bottom: 14px;
  gap: 8px;
}
.card-title-row .card-title { margin-bottom: 0; }


/* ============================================================
   6 · FORMULARIO DE DATOS
   ============================================================ */
.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-label {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.form-label-unit { font-size: 0.56rem; opacity: 0.7; }

.form-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 12px;
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.16s, box-shadow 0.16s;
  width: 100%;
  -webkit-appearance: none;
}
.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 107, 44, 0.1);
}
.form-input::placeholder          { color: var(--muted); }
input[type="number"]::-webkit-inner-spin-button { opacity: 0.5; }


/* ============================================================
   7 · CRONÓMETRO
   ============================================================ */
.card-cronometro {
  position: relative;
  overflow: hidden;
  background: #111114;
  border-color: #2a2a30;
  color: #ffffff;
}

.card-cronometro .card-title { color: #888892; }

.card-cronometro::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent);
  border-radius: var(--radius) var(--radius) 0 0;
  transition: background 0.3s;
}
.card-cronometro.running::before { animation: crono-top-pulse 1s ease-in-out infinite; }
.card-cronometro.paused::before  { background: var(--warn); }

@keyframes crono-top-pulse {
  0%,100% { opacity: 1; }
  50%      { opacity: 0.4; }
}

.vuelta-badge {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  background: rgba(255, 107, 44, 0.15);
  color: var(--accent);
  border: 1px solid rgba(255, 107, 44, 0.3);
  padding: 2px 8px;
  border-radius: 20px;
  white-space: nowrap;
}
.vuelta-badge strong { font-weight: 700; }

/* ── DISPLAY PRINCIPAL ── */
.crono-display {
  text-align: center;
  padding: 18px 0 8px;
}

.crono-time {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 1px;
  line-height: 1;
}

.crono-seg {
  font-family: var(--font-num);
  font-size: var(--crono-seg-size);
  font-weight: 800;
  color: #f5f3f0;
  letter-spacing: -2px;
  min-width: 2ch;
  text-align: center;
  transition: color 0.3s;
  white-space: nowrap;
}

.crono-sep {
  font-family: var(--font-num);
  font-size: var(--crono-sep-size);
  font-weight: 400;
  color: #505060;
  padding-bottom: 4px;
  user-select: none;
  line-height: 1;
}
.crono-sep-small {
  font-size: var(--crono-sep-sm);
  padding-bottom: 2px;
}

.crono-ms {
  font-family: var(--font-num);
  font-size: var(--crono-ms-size);
  font-weight: 700;
  color: #777788;
  letter-spacing: -1px;
  min-width: 2ch;
  text-align: center;
  transition: color 0.3s;
  white-space: nowrap;
}

.card-cronometro.running .crono-seg,
.card-cronometro.running .crono-ms { color: var(--accent); }
.card-cronometro.paused  .crono-seg,
.card-cronometro.paused  .crono-ms { color: var(--warn); }

.crono-labels {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
  margin-top: 4px;
}
.crono-labels span {
  font-family: var(--font-mono);
  font-size: 0.5rem;
  color: #666672;
  text-transform: uppercase;
  letter-spacing: 2px;
  min-width: 2ch;
  text-align: center;
}
.crono-labels span:nth-child(2),
.crono-labels span:nth-child(4) { min-width: 8px; }

/* ── Δ CICLO ── */
.crono-diff-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 10px 0 6px;
  padding: 9px 14px;
  background: #1c1c22;
  border-radius: 8px;
  border: 1px solid #32323c;
}
.crono-diff-label {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: #888892;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.crono-diff {
  font-family: var(--font-num);
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--accent4);
  letter-spacing: -0.5px;
}

/* ── ESTADO ── */
.crono-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-size: 0.75rem;
  color: #888892;
  margin-bottom: 16px;
}
.status-dot {
  width: 8px;
  height: 8px;
  min-width: 8px;
  border-radius: 50%;
  background: #555564;
  transition: background 0.3s;
  flex-shrink: 0;
}
.status-dot.running {
  background: var(--accent);
  animation: dot-pulse 1s ease-in-out infinite;
}
.status-dot.paused { background: var(--warn); }

@keyframes dot-pulse {
  0%,100% { box-shadow: 0 0 0 0   rgba(255, 107, 44, 0.5); }
  50%      { box-shadow: 0 0 0 5px rgba(255, 107, 44, 0); }
}

/* ── CONTROLES ── */
.crono-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: nowrap;
}
.btn-lap  { flex: 2; }
.crono-btn {
  flex: 1;
  justify-content: center;
  padding: 13px 8px;
  font-size: 0.8rem;
}
.crono-controls-sm          { gap: 8px; margin-bottom: 0; }
.crono-controls-sm .btn     { flex: 1; justify-content: center; }

/* Ghost/danger buttons inside dark stopwatch */
.card-cronometro .btn-ghost {
  border-color: #32323c;
  color: #8888a0;
}
.card-cronometro .btn-ghost:not(:disabled):hover {
  color: #ffffff;
  border-color: #5a5a70;
}
.card-cronometro .btn-ghost:not(:disabled):active { background: #1c1c24; }

.card-cronometro .btn-danger {
  background: rgba(217, 48, 37, 0.1);
  border-color: rgba(217, 48, 37, 0.3);
}


/* ============================================================
   8 · ESTADÍSTICAS
   ============================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stat-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 11px 13px;
}
.stat-label {
  font-family: var(--font-mono);
  font-size: 0.57rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 3px;
}
.stat-val {
  font-family: var(--font-num);
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.5px;
  line-height: 1.1;
}
.stat-val.c-green   { color: var(--green); }
.stat-val.c-danger  { color: var(--danger); }
.stat-val.c-accent4 { color: var(--accent); }


/* ============================================================
   9 · TABLA DE VUELTAS
   ============================================================ */
.card-table { padding: var(--pad); }

.badge-muted {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  background: var(--surface3);
  color: var(--muted2);
  border: 1px solid var(--border);
  padding: 3px 9px;
  border-radius: 20px;
  white-space: nowrap;
}

.db-feedback {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.78rem;
  margin-bottom: 12px;
  font-weight: 600;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.db-feedback.success { background: rgba(26, 138, 74, 0.08); border: 1px solid rgba(26, 138, 74, 0.25); color: var(--green); }
.db-feedback.error   { background: rgba(217, 48, 37, 0.08); border: 1px solid rgba(217, 48, 37, 0.25); color: var(--danger); }

/* Scroll horizontal suave en mobile */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 9px;
  border: 1px solid var(--border);
}

/* En la página de tabla, el scroll interno no necesita borde extra (ver regla en sección full-page layout) */
.app-main--full .table-scroll {
  border-radius: 0;
  border-left:   none;
  border-right:  none;
  border-top:    none;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}
.data-table thead tr       { background: var(--surface3); border-bottom: 1px solid var(--border); }
.data-table th {
  font-family: var(--font-mono);
  font-size: 0.57rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--muted);
  padding: 12px 16px;
  text-align: left;
  white-space: nowrap;
}
.th-action { width: 40px; }
.data-table td {
  padding: 12px 16px;
  font-size: 0.82rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td      { background: rgba(255, 107, 44, 0.04); }

.data-table td.mono-cell {
  font-family: var(--font-num);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text);
}
.data-table td.date-cell {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--muted2);
  white-space: nowrap;
}
.data-table td.takt-cell {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--muted2);
}

.row-num {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  background: var(--surface3);
  color: var(--muted2);
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: 5px;
  display: inline-block;
}

.data-table tr.row-outlier td           { background: rgba(217, 48, 37, 0.04); }
.data-table tr.row-outlier td.mono-cell { color: var(--danger); }
.data-table tr.row-best    td.mono-cell { color: var(--green); }

.btn-delete {
  width: 32px;
  height: 32px;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  transition: 0.15s;
}
/* En dispositivos táctiles el botón siempre es visible */
@media (hover: none) {
  .btn-delete { color: var(--muted); }
}
/* En desktop aparece al hover */
.data-table tbody tr:hover .btn-delete { color: var(--muted2); }
.btn-delete:hover,
.btn-delete:focus-visible {
  background: rgba(217, 48, 37, 0.08) !important;
  color: var(--danger) !important;
}

.empty-row td      { border: none !important; background: transparent !important; }
.empty-state       { text-align: center; padding: 32px 16px; color: var(--muted); }
.empty-icon        { font-size: 2.2rem; display: block; margin-bottom: 10px; opacity: 0.4; }
.empty-state p     { font-size: 0.8rem; line-height: 1.6; }
.empty-state strong{ color: var(--muted2); }


/* ============================================================
   10 · GRÁFICA
   ============================================================ */
.card-chart     { min-height: 200px; }
.chart-export-btns { display: flex; gap: 6px; flex-shrink: 0; }

.chart-container {
  position: relative;
  height: 190px;
}

.chart-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 36px 20px;
  color: var(--muted);
}
.chart-empty p { font-size: 0.78rem; text-align: center; }


/* ============================================================
   11 · TOAST
   ============================================================ */
.toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--text);
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 0.78rem;
  font-weight: 600;
  transition: transform 0.3s cubic-bezier(.4,0,.2,1), opacity 0.3s;
  z-index: 999;
  max-width: calc(100vw - 32px);
  text-align: center;
  pointer-events: none;
  opacity: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}
.toast.show    { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.success { border: 1px solid rgba(26, 138, 74, 0.4);  color: var(--green); }
.toast.error   { border: 1px solid rgba(217, 48, 37, 0.4);  color: var(--danger); }
.toast.info    { border: 1px solid #3d3830;                  color: #b0a99e; }


/* ============================================================
   12 · ANIMACIONES
   ============================================================ */
@keyframes rowIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.row-new { animation: rowIn 0.25s ease forwards; }



/* ============================================================
   13 · BREAKPOINTS — Mobile-First

   Base (sin @media)  320–479px  teléfono pequeño
   sm  ≥ 480px        teléfono grande / landscape
   md  ≥ 768px        tablet
   lg  ≥ 1024px       laptop
   xl  ≥ 1280px       desktop
   ============================================================ */


/* ── sm ≥ 480px  ─────────────────────────────────────────── */
@media (min-width: 480px) {
  :root {
    --pad:            16px;
    --gap:            14px;
    --crono-seg-size: 4.4rem;
    --crono-ms-size:  2.8rem;
    --crono-sep-size: 3.4rem;
    --crono-sep-sm:   2.3rem;
  }

  /* 2 columnas en el formulario */
  .form-grid { grid-template-columns: 1fr 1fr; }

  .chart-container { height: 210px; }
}


/* ── md ≥ 768px  (tablet) ───────────────────────────────── */
@media (min-width: 768px) {
  :root {
    --pad:            18px;
    --gap:            16px;
    --header-h:       58px;
    --crono-seg-size: 5rem;
    --crono-ms-size:  3.2rem;
    --crono-sep-size: 3.8rem;
    --crono-sep-sm:   2.6rem;
  }

  /* Logo más grande */
  .logo-icon     { width: 30px; height: 30px; }
  .logo-icon svg { width: 15px; height: 15px; }
  .logo-text     { font-size: 1rem; }

  /* Módulo visible en header */
  .header-module { display: block; }

  /* Texto en botones del header */
  .header-actions .btn-ghost .btn-label { display: inline; }
  .header-actions { gap: 8px; }
  .app-header     { padding: 0 20px; gap: 14px; }

  /* Layout de dos columnas */
  .app-main {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: var(--gap);
    align-items: start;
  }

  .chart-container { height: 220px; }

  /* Inputs más compactos en tablet */
  .form-input { padding: 10px 12px; font-size: 0.9rem; }
}


/* ── lg ≥ 1024px  (laptop) ──────────────────────────────── */
@media (min-width: 1024px) {
  :root {
    --pad:            20px;
    --gap:            18px;
    --crono-seg-size: 5.4rem;
    --crono-ms-size:  3.5rem;
    --crono-sep-size: 4.2rem;
    --crono-sep-sm:   2.9rem;
  }

  .app-main { grid-template-columns: 360px 1fr; }

  /* Hover animado disponible en desktop */
  .btn-accent:not(:disabled):hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(255, 107, 44, 0.25);
  }
  .btn-lap:not(:disabled):hover {
    box-shadow: 0 4px 14px rgba(255, 107, 44, 0.15);
  }

  .chart-container { height: 240px; }
  .form-input { padding: 9px 12px; font-size: 0.84rem; }

  .data-table th,
  .data-table td { padding: 10px 12px; }
}


/* ── xl ≥ 1280px  (desktop) ────────────────────────────── */
@media (min-width: 1280px) {
  :root {
    --crono-seg-size: 5.8rem;
    --crono-ms-size:  3.8rem;
    --crono-sep-size: 4.5rem;
    --crono-sep-sm:   3.1rem;
  }

  .app-main { grid-template-columns: 390px 1fr; }
  .chart-container { height: 260px; }
  .data-table td.mono-cell { font-size: 1.05rem; }
}


/* ── Ultra-wide ≥ 1600px ────────────────────────────────── */
@media (min-width: 1600px) {
  .app-main { grid-template-columns: 420px 1fr; }
}


/* ============================================================
   15 · MODO NOCHE (DARK MODE)
   ============================================================ */

/* Icono de luna oculto en modo claro; sol oculto en modo oscuro */
.icon-moon { display: none; }
[data-theme="dark"] .icon-moon { display: block; }
[data-theme="dark"] .icon-sun  { display: none; }

/* Botón solo-icono en mobile */
.btn-icon-only { padding: 0 10px; }

/* Tokens oscuros */
[data-theme="dark"] {
  --bg:      #0f0d0b;
  --surface: #1a1714;
  --surface2:#211e19;
  --surface3:#27241e;
  --border:  #3d3830;
  --border2: #4d4740;
  --text:    #f5f3f0;
  --muted:   #9c958a;
  --muted2:  #b0a99e;
  --green:   #2db362;
  --danger:  #f04438;
  --warn:    #f5a623;
}

/* Header — siempre oscuro pero más profundo en dark mode */
[data-theme="dark"] .app-header {
  background: #0a0907;
  border-bottom-color: #1e1b16;
}

/* Cronómetro — fondo fijo oscuro en ambos modos */
[data-theme="dark"] .card-cronometro {
  background: #0d0d12;
  border-color: #22222c;
}

/* Toast — fondo oscuro */
[data-theme="dark"] .toast {
  background: #111009;
}

/* Scrollbar en dark */
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: var(--border2); }

/* Transición suave al cambiar de tema */
body,
.app-header,
.card,
.card-cronometro,
.form-input,
.data-table thead tr,
.data-table td,
.stat-item,
.badge-muted,
.crono-diff-wrap,
.toast {
  transition: background 0.25s, border-color 0.25s, color 0.2s;
}


/* ============================================================
   14 · LANDSCAPE EN TELÉFONO
       Pantalla alta < 500px → cronómetro compacto vertical
   ============================================================ */
@media (max-height: 500px) and (orientation: landscape) {
  :root {
    --crono-seg-size: 3rem;
    --crono-ms-size:  1.9rem;
    --crono-sep-size: 2.3rem;
    --crono-sep-sm:   1.6rem;
    --header-h:       48px;
  }

  .crono-display    { padding: 8px 0 4px; }
  .crono-diff-wrap  { margin: 6px 0 4px; padding: 5px 12px; }
  .crono-status     { margin-bottom: 10px; }
  .crono-btn        { padding: 9px 8px; }
  .card-cronometro  { padding-bottom: 12px; }

  /* En landscape con dos columnas se ve mejor el layout */
  .app-main {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 10px;
    align-items: start;
  }
}


/* ============================================================
   16 · TABLA PRINCIPAL — ESTUDIOS
   ============================================================ */

/* Layout de columna única para la página de tabla — ancho completo */
.app-main--full {
  display: flex !important;
  flex-direction: column;
  gap: 0;                /* el gap lo manejan los hijos con margin */
  max-width: none;
  width: 100%;
  padding-left: 0;
  padding-right: 0;
}

/* Hero y filtros alineados con el contenido de la tabla */
.app-main--full .page-hero,
.app-main--full .filter-bar {
  padding-left:  10%;
  padding-right: 10%;
  margin-bottom: var(--gap);
}

/* Card de tabla: contenida con márgenes laterales del 10% */
.app-main--full .card-table {
  margin-left:   10%;
  margin-right:  10%;
  margin-bottom: var(--gap);
  border-radius: var(--radius);
  box-shadow:    0 1px 3px rgba(0,0,0,0.04);
  padding:       var(--pad);
}

/* La tabla se extiende de borde a borde dentro del card */
.app-main--full .table-scroll {
  margin-left:  calc(-1 * var(--pad));
  margin-right: calc(-1 * var(--pad));
  border-radius: 0 0 var(--radius) var(--radius);
  border-left:  none;
  border-right: none;
  border-top:   none;
  overflow-x:   auto;
}

/* ── PAGE HERO ── */
.page-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  padding: 4px 0 2px;
}

.page-hero-text { display: flex; flex-direction: column; gap: 4px; }

.page-title {
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.5px;
  line-height: 1.1;
}

.page-sub {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.5;
}

.btn-new-study {
  gap: 8px;
  padding: 11px 18px;
  font-size: 0.8rem;
  white-space: nowrap;
}

/* ── FILTER BAR ── */
.filter-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 180px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.filter-search { padding-left: 34px; }

.filter-select {
  width: auto;
  min-width: 160px;
  cursor: pointer;
}

/* ── STATUS BADGES ── */
.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-family: var(--font-mono);
  font-size: 0.58rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  white-space: nowrap;
}

.status-badge--borrador {
  background: var(--surface3);
  color: var(--muted2);
  border: 1px solid var(--border2);
}

.status-badge--en-progreso {
  background: rgba(255, 107, 44, 0.1);
  color: var(--accent);
  border: 1px solid rgba(255, 107, 44, 0.28);
}

.status-badge--completado {
  background: rgba(26, 138, 74, 0.08);
  color: var(--green);
  border: 1px solid rgba(26, 138, 74, 0.25);
}

/* ── ACTION BUTTONS ── */
.td-actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}

.btn-action {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: 0.15s;
  color: transparent;
}

@media (hover: none) { .btn-action { color: var(--muted); } }

.data-table tbody tr:hover .btn-action { color: var(--muted2); }

.btn-edit:hover, .btn-edit:focus-visible {
  background: rgba(255, 107, 44, 0.1) !important;
  color: var(--accent) !important;
}

.btn-del:hover, .btn-del:focus-visible {
  background: rgba(217, 48, 37, 0.08) !important;
  color: var(--danger) !important;
}

/* ── MODAL ── */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.52);
  z-index: 300;
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(3px);
}

.modal-backdrop.is-open {
  display: flex;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.18);
  animation: modalIn 0.22s cubic-bezier(.4,0,.2,1) forwards;
}

.modal--sm { max-width: 360px; }

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.3px;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
}
.modal-close:hover { color: var(--text); background: var(--surface3); }

.modal-body {
  padding: 18px 20px;
}

.modal-body .form-grid { grid-template-columns: 1fr 1fr; gap: 12px; }

.confirm-text {
  font-size: 0.82rem;
  color: var(--muted2);
  line-height: 1.6;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--border);
}

/* Dark mode adjustments for modal */
[data-theme="dark"] .modal {
  background: var(--surface);
  border-color: var(--border);
}

/* Dark mode for page-title */
[data-theme="dark"] .page-title { color: var(--text); }


/* ── FILAS CLICKEABLES ── */
.data-table tbody tr.tr-clickable {
  cursor: pointer;
}
.data-table tbody tr.tr-clickable:hover td {
  background: rgba(255, 107, 44, 0.05);
}
.data-table tbody tr.tr-clickable:active td {
  background: rgba(255, 107, 44, 0.1);
}

.td-center { text-align: center; }


/* ── PAGINACIÓN ── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px 0 2px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

.pagination-info {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--muted);
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.pagination-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.page-btn {
  min-width: 34px;
  height: 34px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--border2);
  background: transparent;
  color: var(--muted2);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.14s;
  white-space: nowrap;
}

.page-btn:not(:disabled):hover {
  color: var(--text);
  border-color: var(--muted);
  background: var(--surface2);
}

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

.page-btn--active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  font-weight: 700;
  pointer-events: none;
}

.pagination-dots {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--muted);
  padding: 0 4px;
  -webkit-user-select: none;
     -moz-user-select: none;
      -ms-user-select: none;
          user-select: none;
}


/* ============================================================
   16 · CROSS-BROWSER COMPATIBILITY
   ============================================================ */

/* Firefox scrollbar */
* { scrollbar-width: thin; scrollbar-color: var(--border2) transparent; }

/* IE/Edge: hide number input arrows */
input[type="number"]::-ms-clear { display: none; }

/* Safari: fix sticky positioning */
.app-header { position: -webkit-sticky; position: sticky; }
.sidebar     { position: -webkit-sticky; position: sticky; }

/* Flexbox prefixes for older Safari */
.card-title-row, .filter-bar, .page-hero,
.estudio-header-actions, .stats-strip {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
}

/* Grid prefixes for IE11 fallback (graceful degradation) */
@supports not (display: grid) {
  .stats-strip   { display: -webkit-box; display: -ms-flexbox; display: flex; -ms-flex-wrap: wrap; flex-wrap: wrap; }
  .stats-strip > * { -ms-flex: 1 1 45%; flex: 1 1 45%; }
}

/* Smooth transitions — respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    -webkit-animation-duration: 0.001ms !important;
            animation-duration: 0.001ms !important;
    -webkit-transition-duration: 0.001ms !important;
            transition-duration: 0.001ms !important;
  }
}

/* iOS tap highlight */
a, button { -webkit-tap-highlight-color: transparent; }

/* Fix for older WebKit: border-radius on table */
.table-scroll { -webkit-border-radius: 9px; border-radius: 9px; }

/* Appearance reset cross-browser */
select.form-input {
  -webkit-appearance: none;
     -moz-appearance: none;
          appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238c857a' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}


/* ============================================================
   17 · ESTUDIO DETALLE — mejoras responsivas y de apariencia
   ============================================================ */

/* Detalle: header badge status más visible */
.estudio-header .status-badge {
  font-size: 0.7rem;
  padding: 4px 10px;
}

/* Detalle: tabla ocupa todo el ancho disponible */
.app-main--full .card-table {
  padding: 0;
}
.app-main--full .card-title-row {
  padding: var(--pad) var(--pad) 0;
}
.app-main--full .data-table {
  min-width: 500px;
}

/* Detalle: stats strip gap en mobile */
@media (max-width: 480px) {
  .stats-strip {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  .estudio-header {
    gap: 12px;
  }
  .estudio-header-num {
    font-size: 2.4rem;
  }
  .estudio-header-actions {
    -ms-flex-wrap: wrap;
        flex-wrap: wrap;
    width: 100%;
  }
  .estudio-header-actions .btn {
    -webkit-box-flex: 1;
        -ms-flex: 1;
            flex: 1;
    justify-content: center;
  }
}

/* Detalle: chart container más alto en pantallas grandes */
@media (min-width: 768px) {
  .app-main--full .chart-container { height: 260px; }
}
@media (min-width: 1024px) {
  .app-main--full .chart-container { height: 300px; }
}

/* Detalle: accent line top card */
.estudio-header {
  border-top: 3px solid var(--accent);
}

/* Stats boxes con mejor sombra en light mode */
.stat-box {
  -webkit-box-shadow: 0 1px 4px rgba(0,0,0,0.06);
          box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  -webkit-transition: -webkit-box-shadow 0.2s, -webkit-transform 0.2s;
          transition: box-shadow 0.2s, transform 0.2s;
}
.stat-box:hover {
  -webkit-box-shadow: 0 4px 12px rgba(0,0,0,0.1);
          box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  -webkit-transform: translateY(-1px);
          transform: translateY(-1px);
}
