:root {
  --bg: #0b0f14;
  --panel: #121923;
  --panel-2: #16202c;
  --line: #22303f;
  --text: #e9eff7;
  --muted: #93a4b8;
  --green: #16c47f;
  --green-dark: #0f9d64;
  --red: #ef4444;
  --blue: #3b82f6;
  --amber: #f59e0b;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body { min-height: 100dvh; }

button, input, select, textarea { font: inherit; color: inherit; }

button { cursor: pointer; touch-action: manipulation; }

:focus-visible { outline: 3px solid #7dd3fc; outline-offset: 2px; }

.muted { color: var(--muted); }
.small { font-size: 13px; line-height: 1.4; }
.error { color: #fca5a5; margin: 10px 0 0; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-size: 18px;
}

.brand-mark {
  width: 18px;
  height: 18px;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--green), #22d3ee);
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #4b5563;
  transition: background .2s;
}
.dot.live { background: var(--green); box-shadow: 0 0 0 4px rgba(22,196,127,.16); }

.screen { padding: calc(16px + var(--safe-t)) 16px calc(24px + var(--safe-b)); }

.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 24px;
}

.login-card label {
  display: block;
  margin: 22px 0 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

input[type="password"], input[type="text"], select, textarea {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 17px;
}

textarea { resize: vertical; min-height: 140px; line-height: 1.4; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 6px 0 12px;
  background: linear-gradient(var(--bg) 70%, transparent);
}

.top-actions { display: flex; align-items: center; gap: 8px; }

select { width: auto; padding: 10px 12px; font-size: 14px; }

.icon-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.icon-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: var(--text);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.resumen {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0 14px;
  scrollbar-width: none;
}
.resumen::-webkit-scrollbar { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(22,196,127,.12);
  border: 1px solid rgba(22,196,127,.35);
  color: #a7f3d0;
  font-size: 13px;
  font-weight: 700;
}
.chip.ghost {
  background: var(--panel);
  border-color: var(--line);
  color: var(--muted);
  font-weight: 600;
}

.lista { display: grid; gap: 10px; }

.card {
  width: 100%;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: grid;
  gap: 8px;
  transition: transform .08s ease, border-color .15s;
}
.card:active { transform: scale(.985); }
.card.p1 { border-left-color: var(--red); }
.card.p2 { border-left-color: var(--amber); }
.card.p3 { border-left-color: var(--blue); }
.card.vencido { border-left-color: #a855f7; }

.card-top { display: flex; align-items: center; gap: 8px; }
.card-top .chip { padding: 4px 9px; font-size: 12px; }
.card-age { margin-left: auto; color: var(--muted); font-size: 12px; font-weight: 600; }

.card-cliente { font-weight: 800; font-size: 16px; }
.card-msg {
  color: var(--text);
  font-size: 15px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-draft {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.vacio { text-align: center; padding: 18vh 20px; }
.vacio h2 { margin: 14px 0 6px; font-size: 24px; }
.vacio-check {
  width: 74px;
  height: 74px;
  margin: 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(22,196,127,.12);
  border: 1px solid rgba(22,196,127,.35);
}
.vacio-check svg {
  width: 34px; height: 34px; fill: none; stroke: var(--green);
  stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round;
}

.btn {
  border: 1px solid transparent;
  border-radius: 14px;
  padding: 14px 18px;
  font-weight: 800;
  font-size: 16px;
  background: var(--panel-2);
  color: var(--text);
  min-height: 52px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn:active { transform: scale(.98); }
.btn.big { min-height: 56px; font-size: 17px; }
.btn.primary { background: var(--green); color: #04140d; }
.btn.green { background: var(--green); color: #04140d; }
.btn.red { background: var(--red); color: #fff; }
.btn.blue { background: var(--blue); color: #fff; }
.btn.amber { background: var(--amber); color: #1c1200; }
.btn.ghost { background: var(--panel-2); border-color: var(--line); color: var(--text); }
.btn:disabled { opacity: .45; }

.modo {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding: calc(10px + var(--safe-t)) 14px calc(10px + var(--safe-b));
  height: 100dvh;
}

.modo-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.modo-meta { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.modo-meta::-webkit-scrollbar { display: none; }

.modo-body { flex: 1; overflow-y: auto; padding: 10px 0; }

.bloque { padding: 12px 0; border-bottom: 1px solid var(--line); }
.bloque:last-child { border-bottom: 0; }
.bloque-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 8px;
}

.texto-pregunta { margin: 0; font-size: 20px; line-height: 1.4; color: #dbe6f3; }
.texto-borrador { margin: 0; font-size: 23px; line-height: 1.38; font-weight: 650; letter-spacing: -0.01em; }

.motivo {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(245,158,11,.1);
  border: 1px solid rgba(245,158,11,.35);
  color: #fcd34d;
  font-size: 14px;
  font-weight: 600;
}

.modo-acciones {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 6px 0;
}

.modo-decision {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding-top: 6px;
}
.modo-decision .btn {
  min-height: 82px;
  font-size: 21px;
  border-radius: 18px;
}

.voz-estado {
  position: fixed;
  left: 50%;
  bottom: calc(12px + var(--safe-b));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  background: #0f1720;
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  z-index: 35;
  pointer-events: none;
}
.pulse {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--green);
  animation: pulse 1.1s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .35; transform: scale(.7); }
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--bg);
  padding: calc(14px + var(--safe-t)) 16px calc(20px + var(--safe-b));
  overflow-y: auto;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.sheet h2 { margin: 0; font-size: 22px; }

.editor-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.editor-tools .btn:last-child { grid-column: span 2; min-height: 58px; font-size: 18px; }

.switch {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  margin-bottom: 10px;
  font-weight: 600;
}
.switch input {
  width: 26px;
  height: 26px;
  accent-color: var(--green);
  flex: 0 0 auto;
}

.range-label { display: block; margin: 18px 0 10px; color: var(--muted); font-weight: 600; }
input[type="range"] { width: 100%; accent-color: var(--green); }
#btnSalir { width: 100%; margin-top: 22px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + var(--safe-b));
  transform: translateX(-50%);
  background: #0f1720;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 18px;
  font-weight: 700;
  font-size: 14px;
  z-index: 60;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
  pointer-events: none;
}
.toast.ok { border-color: rgba(22,196,127,.5); color: #a7f3d0; }
.toast.bad { border-color: rgba(239,68,68,.5); color: #fecaca; }

.vistas {
  display: flex;
  gap: 6px;
  padding: 0 0 10px;
}

.vista {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 10px;
  font-weight: 800;
  font-size: 14px;
  color: var(--muted);
}
.vista.activa {
  background: var(--panel-2);
  border-color: rgba(22,196,127,.45);
  color: var(--text);
}

#buscar { margin: 0 0 12px; }

.estado-linea {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}
.estado-linea.warn {
  background: rgba(245,158,11,.1);
  border-color: rgba(245,158,11,.35);
  color: #fcd34d;
}
.estado-linea.bad {
  background: rgba(239,68,68,.1);
  border-color: rgba(239,68,68,.35);
  color: #fecaca;
}
.estado-linea.ok {
  background: rgba(22,196,127,.1);
  border-color: rgba(22,196,127,.35);
  color: #a7f3d0;
}

.chip.ok {
  background: rgba(22,196,127,.12);
  border-color: rgba(22,196,127,.35);
  color: #a7f3d0;
}
.chip.bad {
  background: rgba(239,68,68,.12);
  border-color: rgba(239,68,68,.35);
  color: #fecaca;
}
.chip.warn {
  background: rgba(245,158,11,.12);
  border-color: rgba(245,158,11,.35);
  color: #fcd34d;
}

.card.hist { border-left-color: var(--line); }

.motivos {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 12px 0;
}
.motivo-btn { min-height: 48px; font-size: 14px; padding: 8px 10px; }
#notaRechazo { margin-bottom: 12px; }

#btnTomar { width: 100%; margin-top: 10px; }
#btnReintentar { width: 100%; margin-top: 10px; }

@media (max-height: 640px) {
  .texto-borrador { font-size: 20px; }
  .texto-pregunta { font-size: 18px; }
  .modo-decision .btn { min-height: 68px; font-size: 19px; }
  .modo-acciones .btn { min-height: 46px; }
}

@media (min-width: 720px) {
  .screen { max-width: 720px; margin: 0 auto; }
  .modo, .sheet { max-width: 720px; margin: 0 auto; left: 0; right: 0; }
}
