:root {
  --bg: #0f172a;
  --bg-2: #1e293b;
  --bg-3: #334155;
  --fg: #f1f5f9;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #0ea5e9;
  --danger: #ef4444;
  --ok: #22c55e;
  --warn: #f59e0b;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.screen { min-height: 100dvh; display: flex; flex-direction: column; }

/* Login / Register / Pending / Boot */
#login-screen, #register-screen, #pending-screen, #boot-screen {
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--bg-2);
  padding: 32px;
  border-radius: var(--radius);
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.login-card h1 { margin: 0 0 8px; }
.muted { color: var(--muted); font-size: 14px; }
.error { color: var(--danger); font-size: 14px; }
#login-form, #register-form { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.login-card input[type="password"],
.login-card input[type="text"] {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--bg-3);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 16px;
  outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.auth-switch { font-size: 14px; color: var(--muted); margin-top: 14px; }
.auth-switch a { color: var(--accent); text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }
.login-card button { width: 100%; }
#pending-logout { background: var(--bg-3); color: var(--fg); margin-top: 16px; }
button {
  background: var(--accent);
  color: #00263d;
  border: 0;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
button:hover { background: var(--accent-2); }

/* App */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 8px;
}
header h1 { margin: 0; font-size: 22px; letter-spacing: 0.5px; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.user-pill {
  background: var(--bg-2);
  color: var(--muted);
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid var(--bg-3);
}
.user-pill.admin { color: var(--warn); border-color: var(--warn); }
.icon-btn {
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  padding: 6px 10px;
  border-radius: 8px;
}
.icon-btn:hover { color: var(--fg); background: var(--bg-2); }

.tabs {
  display: flex;
  gap: 6px;
  padding: 0 20px;
  border-bottom: 1px solid var(--bg-3);
}
.tab {
  background: transparent;
  color: var(--muted);
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 500;
}
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

main {
  flex: 1;
  overflow-y: auto;
  padding: 12px 20px 200px;
}
.view { display: none; }
.view.active { display: block; }

.empty {
  text-align: center;
  color: var(--muted);
  margin-top: 80px;
  font-size: 15px;
}

.group {
  margin-top: 20px;
}
.group-header {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.group-header .count {
  background: var(--bg-2);
  color: var(--muted);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
}

.item {
  background: var(--bg-2);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  transition: background 0.15s;
}
.item:hover { background: var(--bg-3); }
.item.done .item-text {
  text-decoration: line-through;
  color: var(--muted);
}

.check {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border: 2px solid var(--bg-3);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
  background: transparent;
  padding: 0;
}
.check:hover { border-color: var(--accent); }
.item.done .check {
  background: var(--ok);
  border-color: var(--ok);
}
.item.done .check::after {
  content: "✓";
  color: white;
  font-size: 14px;
  font-weight: 700;
}

.item-text {
  flex: 1;
  font-size: 15px;
  line-height: 1.4;
  word-break: break-word;
}

.item-delete {
  background: transparent;
  color: var(--muted);
  border: 0;
  padding: 4px 8px;
  font-size: 16px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}
.item:hover .item-delete { opacity: 1; }
.item-delete:hover { color: var(--danger); }

/* Mic bar */
.mic-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 16px 20px 28px;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  z-index: 10;
  padding-bottom: max(28px, env(safe-area-inset-bottom));
}
.text-form {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 560px;
}
#text-input {
  flex: 1;
  background: var(--bg-2);
  color: var(--fg);
  border: 1px solid var(--bg-3);
  border-radius: 24px;
  padding: 10px 18px;
  font-size: 15px;
  outline: none;
}
#text-input:focus { border-color: var(--accent); }
.send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 18px;
  padding: 0;
}
.mic-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.level-meter {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 56px;
  width: 110px;
  justify-content: flex-end;
}
.level-meter.mirror { justify-content: flex-start; flex-direction: row-reverse; }
.level-meter span {
  display: block;
  width: 5px;
  height: 6px;
  background: var(--bg-3);
  border-radius: 3px;
  transition: height 0.06s linear, background 0.12s;
}
/* Cuando hay nivel, los spans crecen via JS asignando --lvl */
.level-meter span.on { background: var(--accent); }
.level-meter span.hot { background: var(--warn); }
.level-meter span.peak { background: var(--danger); }
.level-meter.active span { background: var(--bg-3); }
@media (max-width: 480px) {
  .level-meter { width: 70px; }
  .level-meter span:nth-child(n+8) { display: none; }
}
.mic-btn {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--accent);
  color: #00263d;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 20px rgba(56, 189, 248, 0.4);
  transition: transform 0.1s, background 0.15s;
  padding: 0;
}
.mic-btn:hover { background: var(--accent-2); }
.mic-btn:active { transform: scale(0.96); }
.mic-btn.listening {
  background: var(--danger);
  color: white;
  animation: pulse 1.2s infinite;
  box-shadow: 0 6px 20px rgba(239, 68, 68, 0.4);
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}
.mic-status {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

.transcript {
  position: fixed;
  bottom: 130px;
  left: 20px;
  right: 20px;
  background: var(--bg-2);
  border: 1px solid var(--bg-3);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 15px;
  color: var(--fg);
  text-align: center;
  z-index: 9;
  max-width: 560px;
  margin: 0 auto;
}

.toast {
  position: fixed;
  bottom: 200px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ok);
  color: white;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  z-index: 20;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  max-width: 90%;
  text-align: center;
}
.toast.error { background: var(--danger); }
.toast.fade-out { opacity: 0; transition: opacity 0.4s; }

@media (max-width: 480px) {
  header h1 { font-size: 20px; }
  main { padding: 12px 14px 200px; }
  .tabs { padding: 0 14px; }
  .user-pill { display: none; }
}

/* Modal admin */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); }
.modal-card {
  position: relative;
  background: var(--bg-2);
  border-radius: var(--radius);
  width: min(540px, 92vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--bg-3);
}
.modal-header h2 { margin: 0; font-size: 18px; }
.admin-users { padding: 12px 20px 20px; overflow-y: auto; }
.admin-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--bg-3);
}
.admin-row:last-child { border-bottom: 0; }
.admin-info { flex: 1; }
.admin-username { font-weight: 600; font-size: 15px; }
.admin-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.admin-actions { display: flex; gap: 6px; }
.btn-sm {
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 8px;
  border: 0;
  cursor: pointer;
  font-weight: 500;
}
.btn-approve { background: var(--ok); color: white; }
.btn-approve:hover { filter: brightness(1.1); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover { background: var(--danger); color: white; }
.badge {
  display: inline-block;
  font-size: 11px;
  padding: 1px 8px;
  border-radius: 8px;
  margin-left: 6px;
  font-weight: 600;
}
.badge.admin { background: var(--warn); color: white; }
.badge.pending { background: var(--bg-3); color: var(--muted); }
.badge.ok { background: var(--ok); color: white; }
