:root {
  --bg: #0f172a;
  --bg-soft: #1e293b;
  --card: #1e293b;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --danger: #f43f5e;
  --danger-soft: #4c1d24;
  --success: #22c55e;
  --record: #ef4444;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 600px at 50% -10%, #1e293b 0%, var(--bg) 55%);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

/* Mobile first: contenedor a ancho completo */
.app {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 20px) 18px calc(env(safe-area-inset-bottom) + 28px);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.app-header { text-align: center; margin-top: 6px; }
.app-header h1 { font-size: 1.5rem; margin: 0; letter-spacing: -.02em; }
.app-header .sub { margin: 6px 0 0; color: var(--muted); font-size: .95rem; }

.section-title { font-size: 1rem; margin: 0 0 10px; color: var(--muted); font-weight: 600; }

/* Tarjeta de estado */
.status-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 20px;
  text-align: center;
}

.indicator {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 1rem;
  color: var(--muted);
}
.indicator .dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--muted);
  transition: background .2s ease;
}
.indicator.recording .dot { background: var(--record); animation: pulse 1.1s infinite; }
.indicator.recording { color: var(--text); }
.indicator.paused .dot { background: #f59e0b; }
.indicator.processing .dot { background: var(--accent); animation: pulse 1.1s infinite; }

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(239, 68, 68, .6); }
  70%  { box-shadow: 0 0 0 12px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.timer {
  font-size: 2.6rem;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  letter-spacing: .02em;
  margin: 12px 0 14px;
}

.meter {
  height: 8px;
  border-radius: 999px;
  background: #0b1220;
  overflow: hidden;
  border: 1px solid var(--border);
}
.meter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--success), var(--accent));
  transition: width .08s linear;
}

/* Controles */
.controls { display: flex; flex-direction: column; align-items: center; gap: 16px; }

.record-btn {
  width: 128px; height: 128px;
  border-radius: 50%;
  border: none;
  background: var(--record);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 12px 28px rgba(239, 68, 68, .35);
  transition: transform .08s ease, background .2s ease, box-shadow .2s ease;
  touch-action: manipulation;
}
.record-btn:active { transform: scale(.96); }
.record-btn .mic { width: 40px; height: 40px; fill: currentColor; }
.record-btn.recording {
  background: #f59e0b;
  box-shadow: 0 12px 28px rgba(245, 158, 11, .4);
}
.record-btn:disabled { opacity: .5; cursor: not-allowed; }

.secondary {
  display: flex;
  gap: 12px;
  width: 100%;
}
.btn {
  flex: 1;
  padding: 15px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--bg-soft);
  color: var(--text);
  transition: transform .08s ease, opacity .2s ease, background .2s ease;
  touch-action: manipulation;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-process { background: var(--accent); color: #082f49; border-color: transparent; }
.btn-delete  { background: var(--danger-soft); color: #fecdd3; border-color: transparent; }

/* Reproductor */
.playback, .result {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.playback audio { width: 100%; }

.playback-list { display: flex; flex-direction: column; gap: 14px; }
.segment { display: flex; flex-direction: column; gap: 6px; }
.segment-head { display: flex; align-items: center; }
.segment-label { font-size: .82rem; color: var(--muted); font-weight: 600; word-break: break-word; }
.segment-row { display: flex; align-items: center; gap: 10px; }
.segment-row audio { flex: 1 1 auto; min-width: 0; }
.btn-seg {
  flex: 0 0 auto;
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  font-size: .9rem;
  cursor: pointer;
  touch-action: manipulation;
}
.btn-seg:active { transform: scale(.97); }
.btn-seg:disabled { opacity: .45; cursor: not-allowed; }

.btn-import {
  width: 100%;
  background: transparent;
  color: var(--accent);
  border: 1px dashed var(--accent);
}
.btn-import:disabled { opacity: .45; cursor: not-allowed; }

.editable-tag { font-size: .72rem; color: var(--accent); font-weight: 600; }

/* Resultado */
.result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.result-head .section-title { margin: 0; }
.btn-copy {
  padding: 8px 16px;
  border-radius: 10px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}
.btn-copy:active { transform: scale(.97); }

#transcript {
  width: 100%;
  min-height: 160px;
  resize: vertical;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #0b1220;
  color: var(--text);
  padding: 14px;
  font-size: 1rem;
  line-height: 1.5;
  font-family: inherit;
}
.saved {
  margin: 10px 0 0;
  font-size: .82rem;
  color: var(--muted);
  word-break: break-word;
}

.hint {
  text-align: center;
  min-height: 1.2em;
  margin: 0;
  font-size: .9rem;
}
.hint.error { color: var(--danger); }
.hint.ok { color: var(--success); }

/* En pantallas grandes centramos con más aire */
@media (min-width: 640px) {
  .app { padding-top: 40px; }
  .app-header h1 { font-size: 1.75rem; }
}

/* ============================================================
   Añadidos: acciones de cabecera, arrastrar y soltar, modales
   ============================================================ */
.head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.btn-mini {
  padding: 7px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font-weight: 600;
  font-size: .82rem;
  cursor: pointer;
  touch-action: manipulation;
}
.btn-mini:active { transform: scale(.97); }
.btn-mini:disabled { opacity: .45; cursor: not-allowed; }
.btn-mini-danger { border-color: var(--danger); color: #fecdd3; background: var(--danger-soft); }
.btn-mini-accent { border-color: transparent; background: var(--accent); color: #082f49; }

.drag-hint { margin: -4px 0 10px; font-size: .78rem; color: var(--muted); }

/* Arrastrar y soltar */
.segment {
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 6px;
  transition: background .15s ease, border-color .15s ease, opacity .15s ease;
}
.segment.dragging { opacity: .45; }
.segment.drag-over { border-color: var(--accent); background: rgba(56, 189, 248, .08); }
.segment-head { gap: 8px; }
.drag-handle {
  cursor: grab;
  user-select: none;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0b1220;
  touch-action: none;
}
.drag-handle:active { cursor: grabbing; }
.seg-move { display: flex; gap: 4px; margin-left: auto; }
.seg-move button {
  width: 26px; height: 26px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0b1220;
  color: var(--muted);
  cursor: pointer;
  font-size: .8rem;
  line-height: 1;
  padding: 0;
}
.seg-move button:disabled { opacity: .35; cursor: not-allowed; }

/* Modales */
.modal {
  position: fixed; inset: 0;
  background: rgba(2, 6, 23, .72);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal[hidden] { display: none; }
.modal-box {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.modal-box h3 { margin: 0 0 8px; font-size: 1.05rem; }
.modal-sub { margin: 0 0 14px; color: var(--muted); font-size: .85rem; }
.modal-sub code { color: var(--accent); }
.modal-box input[type="text"] {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #0b1220;
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

.records-list { display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow-y: auto; }
.record-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #0b1220;
}
.record-item .rec-name { font-weight: 600; font-size: .92rem; word-break: break-word; }
.record-item .rec-meta { font-size: .75rem; color: var(--muted); margin-top: 3px; }
.records-empty { color: var(--muted); font-size: .88rem; text-align: center; padding: 18px 0; }

.seg-move .seg-del { border-color: var(--danger); color: #fecdd3; background: var(--danger-soft); }
.seg-move .seg-del:hover { background: var(--danger); color: #fff; }
