:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #16a34a;
  --primary-dark: #15803d;
  --primary-soft: #dcfce7;
  --blue: #2563eb;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .06);
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--blue); }
[hidden] { display: none !important; }

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 19px; letter-spacing: -.02em; }
.brand img { width: 34px; height: 34px; }
.nav { display: flex; gap: 4px; margin-left: 12px; }
.nav button {
  border: 0; background: none; padding: 8px 14px; border-radius: 10px; cursor: pointer;
  color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 8px;
}
.nav button:hover { background: var(--surface-2); color: var(--text); }
.nav button.active { background: var(--primary-soft); color: var(--primary-dark); }
.nav svg { width: 18px; height: 18px; }
.topbar .spacer { flex: 1; }
main { max-width: 1200px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; margin: 0; letter-spacing: -.02em; }
.page-head .spacer { flex: 1; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--border); background: var(--surface); padding: 9px 16px;
  border-radius: 10px; cursor: pointer; font-weight: 600; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: #fecaca; }
.btn-ghost { border-color: transparent; background: none; }
.btn-sm { padding: 6px 10px; font-size: 13.5px; border-radius: 8px; }
.btn-lg { padding: 12px 22px; font-size: 16px; }
.icon-btn { border: 0; background: none; padding: 8px; border-radius: 8px; cursor: pointer; display: inline-flex; color: var(--muted); }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }

/* ---------- WhatsApp pill ---------- */
.wa-pill {
  display: inline-flex; align-items: center; gap: 8px; padding: 7px 12px; border-radius: 999px;
  font-weight: 600; font-size: 13.5px; border: 1px solid var(--border); background: var(--surface); cursor: pointer;
}
.wa-pill .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.wa-pill.ok { background: var(--ok-soft); border-color: #bbf7d0; color: var(--primary-dark); }
.wa-pill.ok .dot { background: var(--ok); }
.wa-pill.bad { background: var(--danger-soft); border-color: #fecaca; color: var(--danger); }
.wa-pill.bad .dot { background: var(--danger); animation: pulse 1.4s infinite; }
.wa-pill.wait .dot { background: var(--warn); animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.banner {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 12px; margin-bottom: 18px;
  background: var(--danger-soft); color: #991b1b; border: 1px solid #fecaca; font-weight: 500;
}
.banner.warn { background: var(--warn-soft); color: #92400e; border-color: #fde68a; }
.banner .spacer { flex: 1; }

/* ---------- Tarjetas ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty h3 { color: var(--text); margin: 8px 0 6px; }
.empty .big { font-size: 42px; }

/* ---------- Calendario ---------- */
.cal-toolbar { display: flex; align-items: center; gap: 8px; }
.cal-toolbar h2 { margin: 0 8px; font-size: 20px; min-width: 180px; }
.cal { overflow: hidden; }
.cal-head, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-head div { padding: 10px; font-size: 12.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--border); }
.cal-day {
  min-height: 118px; padding: 6px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
  cursor: pointer; display: flex; flex-direction: column; gap: 4px; transition: background .12s; min-width: 0;
}
.cal-day:nth-child(7n) { border-right: 0; }
.cal-day:hover { background: var(--surface-2); }
.cal-day.other { background: #fafbfd; }
.cal-day.other .num { color: #c0c8d4; }
.cal-day.past { background: #fbfcfd; }
.cal-day .num { font-size: 13px; font-weight: 700; color: var(--muted); width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; }
.cal-day.today .num { background: var(--primary); color: #fff; }
.chip {
  display: flex; align-items: center; gap: 5px; padding: 3px 7px; border-radius: 6px; font-size: 12.5px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #fff; min-width: 0;
}
.chip span { overflow: hidden; text-overflow: ellipsis; }
.chip .st { flex: none; font-size: 11px; }
.chip.pausada { opacity: .45; }
.more { font-size: 12px; color: var(--muted); font-weight: 600; padding-left: 4px; }

.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-top: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* Agenda (celular) */
.agenda { display: none; }
.agenda-day { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.agenda-day:last-child { border-bottom: 0; }
.agenda-day h4 { margin: 0 0 8px; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.agenda-day h4 .tag { font-size: 11.5px; background: var(--primary); color: #fff; padding: 1px 8px; border-radius: 99px; }
.agenda-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); margin-bottom: 6px; cursor: pointer; }
.agenda-item .bar { width: 4px; align-self: stretch; border-radius: 4px; }
.agenda-item .info { flex: 1; min-width: 0; }
.agenda-item .t { font-weight: 600; }
.agenda-item .s { font-size: 13px; color: var(--muted); }

/* ---------- Estado ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.badge.enviado { background: var(--ok-soft); color: var(--primary-dark); }
.badge.pendiente { background: #e0e7ff; color: #3730a3; }
.badge.error, .badge.no_enviado, .badge.problema { background: var(--danger-soft); color: #b91c1c; }
.badge.sin_grupo { background: var(--warn-soft); color: #92400e; }
.badge.pausada { background: #f1f5f9; color: var(--muted); }

/* ---------- Promos ---------- */
.tabs { display: inline-flex; background: #e9edf4; padding: 4px; border-radius: 12px; gap: 2px; }
.tabs button { border: 0; background: none; padding: 7px 14px; border-radius: 9px; cursor: pointer; font-weight: 600; color: var(--muted); }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.promo-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 16px; }
.promo-card { display: flex; flex-direction: column; overflow: hidden; }
.promo-card .top { display: flex; gap: 12px; padding: 16px 16px 12px; }
.promo-card .thumb { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; flex: none; background: var(--surface-2); }
.promo-card .color { width: 6px; border-radius: 6px; flex: none; }
.promo-card h3 { margin: 0 0 4px; font-size: 16.5px; }
.promo-card .msg { color: var(--muted); font-size: 13.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-line; }
.promo-card .meta { padding: 0 16px 12px; display: grid; gap: 6px; font-size: 13.5px; }
.promo-card .meta div { display: flex; gap: 8px; align-items: flex-start; }
.promo-card .meta svg { width: 16px; height: 16px; color: var(--muted); flex: none; margin-top: 2px; }
.progress { height: 6px; background: #eef2f7; border-radius: 6px; overflow: hidden; margin: 0 16px 14px; }
.progress div { height: 100%; background: var(--ok); }
.promo-card .actions { display: flex; gap: 4px; padding: 8px 10px; border-top: 1px solid var(--border); background: var(--surface-2); margin-top: auto; flex-wrap: wrap; }

/* ---------- Locales ---------- */
.list { overflow: hidden; }
.row { display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.row:last-child { border-bottom: 0; }
.row .avatar { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-weight: 800; background: var(--primary-soft); color: var(--primary-dark); flex: none; }
.row .info { flex: 1; min-width: 0; }
.row .t { font-weight: 600; }
.row .s { font-size: 13.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Tabla ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: top; }
th { font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }

/* ---------- Modal ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 50; display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow-y: auto; animation: fade .15s;
}
.modal { background: var(--surface); border-radius: 18px; width: 100%; max-width: 560px; box-shadow: 0 20px 60px rgba(0,0,0,.25); animation: pop .18s; }
.modal.wide { max-width: 980px; }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 19px; flex: 1; }
.modal-body { padding: 22px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 22px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 18px 18px; flex-wrap: wrap; }
.modal-foot .spacer { flex: 1; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: translateY(10px) scale(.98); opacity: 0; } }

/* ---------- Formulario ---------- */
.field { margin-bottom: 18px; }
.field > label, .label { display: block; font-weight: 700; margin-bottom: 7px; font-size: 14px; }
.hint { font-size: 13px; color: var(--muted); font-weight: 400; }
.input, textarea.input, select.input {
  width: 100%; padding: 10px 12px; border: 1px solid #cfd7e3; border-radius: 10px; background: #fff; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(22, 163, 74, .15); }
textarea.input { resize: vertical; min-height: 130px; }
.step { display: flex; gap: 14px; padding-bottom: 22px; }
.step .n { flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: #fff; font-weight: 800; display: grid; place-items: center; font-size: 14px; }
.step .c { flex: 1; min-width: 0; }
.step h3 { margin: 3px 0 12px; font-size: 16px; }
.form-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 28px; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; box-shadow: 0 0 0 1px var(--border); }
.swatch.active { border-color: #fff; box-shadow: 0 0 0 2px var(--text); }

.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  border: 1.5px solid #cfd7e3; background: #fff; padding: 7px 13px; border-radius: 999px; cursor: pointer; font-weight: 600; font-size: 14px;
  display: inline-flex; align-items: center; gap: 6px; user-select: none; transition: all .12s;
}
.pill:hover { border-color: var(--primary); }
.pill.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.pill.all { border-style: dashed; }
.pill.all.on { border-style: solid; }
.row-inline { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row-inline .input { width: auto; }

.drop {
  border: 2px dashed #cfd7e3; border-radius: 12px; padding: 16px; text-align: center; color: var(--muted); cursor: pointer; transition: all .15s;
}
.drop svg { width: 28px; height: 28px; }
.drop:hover, .drop.over { border-color: var(--primary); background: #f0fdf4; color: var(--primary-dark); }
.img-prev { position: relative; display: inline-block; }
.img-prev img { max-width: 100%; max-height: 180px; border-radius: 10px; display: block; }
.img-prev button { position: absolute; top: 6px; right: 6px; background: rgba(0,0,0,.6); color: #fff; border: 0; border-radius: 50%; width: 28px; height: 28px; cursor: pointer; }

/* mini calendario del formulario */
.mini-cal { border: 1px solid var(--border); border-radius: 12px; padding: 10px; user-select: none; }
.mini-cal .mh { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }

.mini-cal .g { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.mini-cal .wd { font-size: 11.5px; text-align: center; color: var(--muted); font-weight: 700; padding: 3px 0; }
.mini-cal .d {
  aspect-ratio: 1; display: grid; place-items: center; border-radius: 9px; font-size: 13.5px; font-weight: 600; cursor: pointer; border: 0; background: none; padding: 0;
}
.mini-cal .d:hover:not(:disabled) { background: #f0fdf4; }
.mini-cal .d.sel { background: var(--primary); color: #fff; }
.mini-cal .d.today { box-shadow: inset 0 0 0 2px var(--primary); }
.mini-cal .d:disabled { color: #cbd5e1; cursor: default; }
.mini-cal .d.empty { visibility: hidden; }
.summary { margin-top: 10px; padding: 10px 12px; background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 10px; font-size: 13.5px; color: #14532d; }
.summary.zero { background: var(--surface-2); border-color: var(--border); color: var(--muted); }

/* vista previa WhatsApp */
.wa-preview { background: #efeae2; border-radius: 14px; padding: 16px; min-height: 140px; background-image: radial-gradient(#e2dbd0 1px, transparent 1px); background-size: 16px 16px; }
.wa-preview .head { font-size: 12.5px; color: #54656f; margin-bottom: 8px; font-weight: 600; }
.bubble { background: #d9fdd3; border-radius: 10px 0 10px 10px; padding: 6px 8px 4px; max-width: 92%; margin-left: auto; box-shadow: 0 1px 1px rgba(0,0,0,.1); font-size: 14px; word-wrap: break-word; }
.bubble img { width: 100%; border-radius: 7px; display: block; margin-bottom: 4px; }
.bubble .txt { white-space: pre-wrap; padding: 0 2px; }
.bubble .time { text-align: right; font-size: 11px; color: #667781; }

/* ---------- Detalle de día ---------- */
.day-promo { border: 1px solid var(--border); border-radius: 12px; margin-bottom: 12px; overflow: hidden; }
.day-promo .h { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: var(--surface-2); }
.day-promo .h .bar { width: 5px; height: 26px; border-radius: 4px; }
.day-promo .h .t { font-weight: 700; flex: 1; }
.day-promo .loc { display: flex; align-items: center; gap: 10px; padding: 9px 14px; border-top: 1px solid var(--border); font-size: 14px; }
.day-promo .loc .nm { flex: 1; }
.day-promo .loc .err { font-size: 12.5px; color: var(--danger); }

/* ---------- WhatsApp modal ---------- */
.qr-box { text-align: center; }
.qr-box img { width: 260px; height: 260px; border-radius: 12px; border: 1px solid var(--border); }
.steps-list { text-align: left; margin: 16px auto 0; max-width: 380px; padding-left: 20px; }
.steps-list li { margin-bottom: 6px; }
.group-list { max-height: 360px; overflow: auto; border: 1px solid var(--border); border-radius: 12px; }
.group-item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.group-item:last-child { border-bottom: 0; }
.group-item:hover { background: var(--surface-2); }
.group-item.sel { background: #f0fdf4; }
.group-item .s { font-size: 12.5px; color: var(--muted); }
.group-item input { width: 18px; height: 18px; accent-color: var(--primary); }

/* ---------- Toast ---------- */
.toasts { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #0f172a; color: #fff; padding: 11px 18px; border-radius: 12px; font-weight: 500; box-shadow: 0 8px 30px rgba(0,0,0,.25); animation: pop .2s; max-width: 90vw; }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--primary-dark); }

.spinner { width: 18px; height: 18px; border: 2.5px solid rgba(0,0,0,.15); border-top-color: currentColor; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; justify-content: center; padding: 50px; color: var(--muted); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #f0fdf4, #eff6ff); }
.login { width: 100%; max-width: 380px; padding: 32px; }
.login .brand { justify-content: center; font-size: 26px; margin-bottom: 4px; }
.login .brand img { width: 48px; height: 48px; }
.login p.sub { text-align: center; color: var(--muted); margin: 0 0 24px; }
.login .btn { width: 100%; }
.login .error { color: var(--danger); font-size: 14px; margin-bottom: 12px; text-align: center; }

/* ---------- Bottom nav (celular) ---------- */
.bottom-nav { display: none; }
.fab { display: none; }

@media (max-width: 860px) {
  .form-grid { grid-template-columns: 1fr; gap: 0; }
  .nav { display: none; }
  .topbar { padding: 10px 16px; }
  main { padding: 16px 16px 96px; }
  .bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: var(--surface);
    border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottom-nav button { flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11.5px; font-weight: 600; color: var(--muted); padding: 6px 0; cursor: pointer; }
  .bottom-nav button.active { color: var(--primary-dark); }
  .bottom-nav svg { width: 22px; height: 22px; }
  .desktop-only { display: none !important; }
  .fab {
    display: flex; position: fixed; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 31; width: 58px; height: 58px; border-radius: 18px;
    background: var(--primary); color: #fff; border: 0; align-items: center; justify-content: center; box-shadow: 0 8px 24px rgba(22,163,74,.4); cursor: pointer;
  }
  .fab svg { width: 28px; height: 28px; }
  .cal-wrap { display: none; }
  .agenda { display: block; }
  .overlay { padding: 0; }
  .modal { border-radius: 0; min-height: 100vh; max-width: none; }
  .modal-foot { border-radius: 0; position: sticky; bottom: 0; }
  .promo-list { grid-template-columns: 1fr; }
  .page-head h1 { font-size: 21px; }
  .cal-toolbar h2 { min-width: 0; font-size: 18px; }
  .wa-pill .lbl { display: none; }
  th:nth-child(4), td:nth-child(4) { display: none; }
}
