:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1c2733;
  --muted: #64748b;
  --primary: #0f4c81;
  --primary-dark: #0b3a63;
  --accent: #d63a3a;
  --border: #e2e8f0;
  --ok: #1a7f4e;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e141b;
    --card: #1a222c;
    --text: #e8eef4;
    --muted: #92a2b3;
    --primary: #3d7ab5;
    --primary-dark: #2d5f91;
    --border: #2b3642;
  }
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-text-size-adjust: 100%;
}
.hidden { display: none !important; }
.view { max-width: 560px; margin: 0 auto; padding: 16px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.small-text { font-size: 0.85rem; }

/* Login */
#login-view { display: flex; min-height: 90vh; align-items: center; justify-content: center; }
.login-box { text-align: center; width: 100%; max-width: 320px; }
.logo {
  width: 72px; height: 72px; margin: 0 auto 12px;
  background: var(--primary); color: #fff; border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
  font-size: 2.2rem; font-weight: 700;
}
.login-box h1 { margin-bottom: 4px; }
.login-box form { margin-top: 20px; display: flex; flex-direction: column; gap: 10px; }
.login-box input {
  padding: 14px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--card); color: var(--text); font-size: 1rem;
}
.error { color: var(--accent); margin-top: 10px; }

/* Header */
header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
header h1 { font-size: 1.25rem; }

/* Paneles */
.panel {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; margin-bottom: 14px;
}

/* Botones */
.btn {
  border: none; border-radius: var(--radius); padding: 12px 18px;
  font-size: 0.95rem; font-weight: 600; cursor: pointer;
  background: var(--border); color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:active { background: var(--primary-dark); }
.btn.secondary { background: #1faa59; color: #fff; }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn.small { padding: 6px 12px; font-size: 0.8rem; }
.btn.full { width: 100%; }
.btn.round { width: 52px; height: 52px; border-radius: 50%; padding: 0; font-size: 1.1rem; }
.btn:disabled { opacity: 0.5; }

/* Grabación */
.rec-controls { display: flex; align-items: center; justify-content: center; gap: 24px; margin: 18px 0; }
.record-btn {
  width: 92px; height: 92px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--primary); display: flex; align-items: center; justify-content: center;
  transition: background 0.2s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.record-btn:active { transform: scale(0.96); }
.record-btn.recording { background: var(--accent); animation: pulse 1.6s infinite; }
.record-btn.paused { background: #b98a1c; animation: none; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(214, 58, 58, 0.45); }
  70% { box-shadow: 0 0 0 18px rgba(214, 58, 58, 0); }
  100% { box-shadow: 0 0 0 0 rgba(214, 58, 58, 0); }
}
.mic-icon {
  width: 30px; height: 30px; display: block;
  background: #fff;
  -webkit-mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 14a3 3 0 0 0 3-3V5a3 3 0 0 0-6 0v6a3 3 0 0 0 3 3Zm5-3a5 5 0 0 1-10 0H5a7 7 0 0 0 6 6.92V21h2v-3.08A7 7 0 0 0 19 11h-2Z"/></svg>') center / contain no-repeat;
  mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 14a3 3 0 0 0 3-3V5a3 3 0 0 0-6 0v6a3 3 0 0 0 3 3Zm5-3a5 5 0 0 1-10 0H5a7 7 0 0 0 6 6.92V21h2v-3.08A7 7 0 0 0 19 11h-2Z"/></svg>') center / contain no-repeat;
}
.record-btn.recording .mic-icon,
.record-btn.paused .mic-icon {
  -webkit-mask: none; mask: none; background: #fff; border-radius: 6px; width: 26px; height: 26px;
}
.timer { font-size: 2rem; font-variant-numeric: tabular-nums; text-align: center; margin-bottom: 4px; }
.tone-row { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 6px; }
.tone-row select {
  padding: 8px 10px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--card); color: var(--text); font-size: 16px;
}

/* Procesando */
.spinner {
  width: 38px; height: 38px; margin: 10px auto 14px;
  border: 4px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Resultado */
.result-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.result-head h2 { font-size: 1.05rem; }
#message-box {
  width: 100%; min-height: 160px; resize: vertical;
  padding: 12px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--bg); color: var(--text);
  font-size: 1rem; line-height: 1.45; font-family: inherit;
}
.btn-row { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; min-width: 100px; }

.refine-box { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 14px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 10px; }
.chip {
  border: 1px solid var(--border); background: transparent; color: var(--text);
  border-radius: 999px; padding: 6px 12px; font-size: 0.82rem; cursor: pointer;
}
.chip:active { background: var(--border); }
.refine-row { display: flex; gap: 8px; }
.refine-row input {
  flex: 1; padding: 12px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--card); color: var(--text); font-size: 16px;
}

#transcript-details { margin-top: 16px; }
#transcript-details summary { cursor: pointer; font-size: 0.85rem; }
.transcript { margin-top: 8px; font-size: 0.9rem; color: var(--muted); white-space: pre-wrap; }

/* Historial */
#history-list { list-style: none; }
#history-list li {
  padding: 10px 4px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px; cursor: pointer;
}
#history-list li:last-child { border-bottom: none; }
.hist-text { flex: 1; min-width: 0; }
.hist-date { font-size: 0.72rem; color: var(--muted); }
.hist-preview {
  font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.hist-del { background: none; border: none; color: var(--muted); font-size: 1rem; cursor: pointer; padding: 6px; }

/* Toast */
.toast {
  position: fixed; bottom: calc(30px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 20px; border-radius: 999px; font-size: 0.9rem;
  z-index: 50; opacity: 0.95;
}
