:root {
  --bg: #0b1220;
  --card: #111a2b;
  --card2: #0d1524;
  --line: #1f2b40;
  --text: #e6edf6;
  --muted: #8a98ad;
  --accent: #10b981;
  --accent-2: #34d399;
  --accent-ink: #052e22;
  --warn: #f5a524;
  --bad: #ef5350;
  --info: #60a5fa;
  --radius: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: radial-gradient(1200px 600px at 10% -10%, #10302a 0%, transparent 60%), var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.center { text-align: center; }
kbd {
  font: 11px ui-monospace, monospace;
  padding: 1px 5px;
  border-radius: 5px;
  border: 1px solid rgba(255,255,255,.25);
  background: rgba(0,0,0,.2);
  margin-left: 4px;
}

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px max(16px, env(safe-area-inset-left));
  background: rgba(11,18,32,.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { border-radius: 10px; flex: none; }
.brand h1 { font-size: 17px; color: var(--accent-2); }
.brand p { margin: 0; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpis { display: flex; align-items: center; gap: 14px; }
.kpi { text-align: right; }
.kpi b { display: block; font-size: 18px; }
.kpi small { color: var(--muted); font-size: 11px; }

/* Layout */
.layout {
  max-width: 1180px; margin: 0 auto; padding: 16px;
  display: grid; grid-template-columns: 1fr; gap: 16px;
}
@media (min-width: 960px) {
  .layout { grid-template-columns: 1fr 1fr; padding: 24px; gap: 20px; }
  .span2 { grid-column: span 2; }
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  display: flex; flex-direction: column; gap: 14px;
  min-width: 0;
}
.card h2 { font-size: 17px; display: flex; align-items: center; gap: 10px; }
.num {
  display: inline-grid; place-items: center;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  font-size: 13px; font-weight: 800;
}
.row { display: flex; align-items: center; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.gap { gap: 10px; }
.nomb { margin: 0; }
.hint { margin: 0; font-size: 13px; color: var(--muted); }

/* Drop zone */
.drop {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 22px 14px; text-align: center;
  border: 2px dashed #2a3a56; border-radius: 14px;
  background: var(--card2);
  cursor: pointer; transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--accent); background: #0f1f22; }
.drop.busy { pointer-events: none; opacity: .7; border-color: var(--accent); }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop-icon { font-size: 26px; }

/* Selector de cuenta */
.account-pick { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.account-label { font-size: 12px; color: var(--muted); font-weight: 600; margin-right: 4px; }
.acc { position: relative; cursor: pointer; }
.acc input { position: absolute; opacity: 0; pointer-events: none; }
.acc span { display: inline-block; padding: 9px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card2); color: var(--muted); font-weight: 650; font-size: 14px; }
.acc input:checked + span { border-color: var(--accent); background: #0c2a20; color: var(--accent-2); }
.acc input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Fields */
.grid3 { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 560px) { .grid3 { grid-template-columns: repeat(3, 1fr); } }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; }
input[type=text], input[type=number], input[type=search], select, textarea {
  width: 100%;
  background: var(--card2); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font: inherit; font-size: 16px; /* evita zoom en iOS */
}
@media (min-width: 960px) { input, select, textarea { font-size: 14px !important; } }
textarea { resize: vertical; min-height: 160px; line-height: 1.55; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.search { max-width: 280px; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.stats div { background: var(--card2); border: 1px solid var(--line); border-radius: 12px; padding: 8px 6px; text-align: center; }
.stats b { display: block; font-size: 18px; }
.stats span { font-size: 11px; color: var(--muted); }
.stats .ok b { color: var(--accent-2); }
.stats .warn b { color: var(--warn); }
.stats .bad b { color: var(--bad); }
.stats .mute b { color: var(--muted); }

.check { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--muted); cursor: pointer; }
.check input { margin-top: 3px; accent-color: var(--accent); width: 16px; height: 16px; flex: none; }

/* Avisos de revisión */
.issues { border: 1px solid #5a4214; background: #241b0a; border-radius: 12px; padding: 12px 14px; font-size: 14px; }
.issues p { margin: 0 0 6px; color: #ffd28a; font-weight: 600; }
.issues summary { cursor: pointer; color: #f6cf72; font-size: 13px; }
.issues ul { margin: 8px 0 0; padding-left: 18px; max-height: 220px; overflow: auto; color: #e7d3a8; font-size: 13px; display: grid; gap: 4px; }
.issues li b { color: #fff; font-weight: 600; }
.qrow .reason { display: block; font-size: 12px; color: #f6cf72; }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid #22573f; background: #0c2a20; color: var(--accent-2);
  border-radius: 999px; padding: 4px 10px; font-size: 12px; font-family: ui-monospace, monospace;
  cursor: pointer;
}
.chip:hover { background: #10392b; }
.warn-text { color: var(--warn); text-align: right; }

/* Image */
.image-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.image-box { display: flex; align-items: center; gap: 10px; }
.image-box img { height: 56px; border-radius: 8px; border: 1px solid var(--line); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: 12px;
  border: 1px solid var(--line); background: #18233a; color: var(--text);
  font: inherit; font-weight: 650; cursor: pointer; user-select: none;
  transition: transform .05s, background .15s, opacity .15s;
  text-decoration: none; white-space: nowrap;
}
.btn:hover:not(:disabled) { background: #1f2d49; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.sm { padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.btn.big { padding: 13px 20px; font-size: 16px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover:not(:disabled) { background: var(--accent-2); }
.btn.success { background: #134e3a; border-color: #1f7a5a; color: #c9f7e4; }
.btn.success:hover:not(:disabled) { background: #186147; }
.btn.danger { background: transparent; border-color: #5b2427; color: #ff9b97; }
.btn.danger:hover:not(:disabled) { background: #2a1415; }
.btn.ghost { background: transparent; }
.danger-text { color: #ff9b97; }
.link { background: none; border: 0; color: var(--info); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }

/* Current contact */
.empty-state { padding: 26px 12px; text-align: center; color: var(--muted); background: var(--card2); border-radius: 12px; border: 1px dashed var(--line); }
.current { display: flex; flex-direction: column; gap: 12px; background: var(--card2); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.cur-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.cur-who { min-width: 0; }
.cur-who h3 { font-size: 18px; color: var(--accent-2); overflow-wrap: anywhere; }
.cur-who p { margin: 2px 0 0; }
.pill { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: #18233a; color: var(--muted); white-space: nowrap; }
.bubble {
  background: #0f2e25; border: 1px solid #1d4d3d; border-radius: 4px 14px 14px 14px;
  padding: 12px 14px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px;
  max-height: 240px; overflow: auto;
}
.bubble .missing { background: #4a3410; color: #ffd28a; border-radius: 4px; padding: 0 3px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions .btn { flex: 1 1 130px; }
.actions .big { flex: 1 1 100%; }
@media (min-width: 720px) { .actions .big { flex: 2 1 220px; } }
.progress { height: 6px; background: #18233a; border-radius: 99px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .3s; }

/* Tabs & queue */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: thin; }
.tab {
  flex: none; border: 1px solid var(--line); background: transparent; color: var(--muted);
  border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 13px; cursor: pointer;
}
.tab span { opacity: .8; margin-left: 2px; }
.tab.active { background: #18233a; color: var(--text); border-color: #2c3d5c; }
.queue { display: flex; flex-direction: column; gap: 6px; max-height: 460px; overflow: auto; }
.qrow {
  display: grid; grid-template-columns: 42px 1fr auto auto; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 10px; background: var(--card2); border: 1px solid transparent;
}
.qrow.is-current { border-color: var(--accent); }
.qrow .idx { color: var(--muted); font-size: 12px; text-align: right; }
.qrow .who { min-width: 0; }
.qrow .who b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qrow .who span { font-size: 12px; color: var(--muted); }
.badge { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.b-pendiente { background: #1c2740; color: #a9b8d0; }
.b-abierto { background: #102a44; color: #8cc4ff; }
.b-enviado { background: #0f3a2b; color: #6ee7b7; }
.b-omitido { background: #3a2f12; color: #f6cf72; }
.b-no_contactar { background: #3a1416; color: #ff9b97; }
.b-invalido, .b-duplicado, .b-sin_whatsapp { background: #2a2a2a; color: #a3a3a3; }
@media (max-width: 560px) {
  .qrow { grid-template-columns: 1fr auto auto; gap: 8px; }
  .qrow .idx { display: none; }
  .brand p { display: none; }
  .kpis { gap: 10px; }
  .kpi b { font-size: 16px; }
  .kpi small { font-size: 10px; display: block; line-height: 1.1; }
  .stats { grid-template-columns: repeat(3, 1fr); }
  kbd { display: none; }
}

.footer-actions { display: flex; flex-wrap: wrap; gap: 8px; border-top: 1px solid var(--line); padding-top: 12px; }

.note ul { margin: 0; padding-left: 18px; color: var(--muted); font-size: 14px; display: grid; gap: 6px; }

a.btn.is-disabled { opacity: .45; cursor: not-allowed; }

/* Barra de último envío */
.lastbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
  background: #0f3a2b; border: 1px solid #1f7a5a; color: #c9f7e4; border-radius: 12px; padding: 10px 12px; font-size: 14px; }
.lastbar small { color: #8fe0bf; }
.lastbar.confirm { background: #102a44; border-color: #2f6db0; color: #dbeafe; }
.lastbar.confirm small { color: #9cc7f5; }
.lastbar.confirm .btn.danger { background: #2a1415; }
.lastbar-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.lastbar .btn.ghost { border-color: #1f7a5a; color: #c9f7e4; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; background: rgba(3,7,15,.7); backdrop-filter: blur(3px); }
.modal-card { width: min(440px, 100%); background: var(--card); border: 1px solid #2c3d5c; border-radius: 16px; padding: 20px; box-shadow: 0 20px 50px rgba(0,0,0,.5); }
.modal-card h3 { font-size: 17px; margin-bottom: 8px; }
.modal-card p { margin: 0 0 16px; color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; }
.modal-card textarea { margin-bottom: 14px; min-height: 140px; font-size: 12px !important; font-family: ui-monospace, monospace; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #1b2740; color: var(--text); border: 1px solid #2c3d5c;
  padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: min(92vw, 520px);
  box-shadow: 0 10px 30px rgba(0,0,0,.4); transition: opacity .2s, transform .2s; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }


/* ================= Footer ================= */
.site-footer {
  max-width: 1180px; margin: 8px auto 0; padding: 18px 16px calc(28px + env(safe-area-inset-bottom));
  text-align: center; border-top: 1px solid var(--line); color: var(--muted); font-size: 14px;
}
.site-footer p { margin: 2px 0; }
.site-footer strong { color: var(--accent-2); }

/* ================= 100% responsive ================= */
html, body { max-width: 100%; overflow-x: clip; }
img { max-width: 100%; }
.card > *, .current > *, .layout > * { min-width: 0; }
.brand > div { min-width: 0; }
.brand h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card h2 { font-size: clamp(16px, 2.2vw, 18px); }
.bubble a, .bubble { word-break: break-word; }

/* Tablet */
@media (min-width: 640px) and (max-width: 959px) {
  .layout { padding: 20px; gap: 18px; max-width: 760px; }
  .stats { grid-template-columns: repeat(5, 1fr); }
}

/* Celular */
@media (max-width: 639px) {
  .topbar { padding: 10px 12px; gap: 8px; }
  .brand img { width: 32px; height: 32px; }
  .brand h1 { font-size: 16px; }
  .layout { padding: 12px; gap: 12px; }
  .card { padding: 14px; border-radius: 14px; gap: 12px; }
  .search { max-width: none; width: 100%; }
  .account-pick { display: grid; grid-template-columns: 1fr 1fr; }
  .account-label { grid-column: span 2; }
  .acc span { display: block; text-align: center; padding: 10px 6px; font-size: 13px; }
  .footer-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .footer-actions .btn { white-space: normal; text-align: center; line-height: 1.25; }
  .modal { align-items: end; padding: 10px; }
  .modal-card { border-radius: 18px; padding: 18px; }
  .modal-actions { display: grid; grid-template-columns: 1fr; }
  .modal-actions .btn { width: 100%; }
  .lastbar { flex-direction: column; align-items: stretch; }
  .lastbar-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .lastbar-actions .btn { white-space: normal; }
  .lastbar-actions .btn:first-child:nth-last-child(3) { grid-column: span 2; }
  .cur-who h3 { font-size: 17px; }
  .bubble { font-size: 14px; max-height: 200px; }
  .actions .btn { flex: 1 1 calc(50% - 4px); }
  .actions .big { flex-basis: 100%; }
  .installBtn .lbl, #installBtn .lbl { display: none; }
}

/* Celular muy angosto (≤360 px) */
@media (max-width: 360px) {
  .kpi small { font-size: 9px; }
  .kpi b { font-size: 14px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stats div:first-child { grid-column: span 2; }
  .footer-actions { grid-template-columns: 1fr; }
  .actions .btn { flex-basis: 100%; }
}

/* Pantallas grandes */
@media (min-width: 1400px) {
  .layout { max-width: 1320px; }
  .site-footer { max-width: 1320px; }
}

/* Botones táctiles cómodos */
@media (pointer: coarse) {
  .btn, .tab, .chip { min-height: 40px; }
  .btn.sm { min-height: 38px; }
}
