:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #f0f3f2;
  --border: #e1e6e4;
  --text: #17201c;
  --muted: #5d6b65;
  --brand: #0f8a5f;
  --brand-strong: #0b6e4b;
  --brand-soft: #e2f4ec;
  --accent: #6c5ce7;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --warn: #b7791f;
  --warn-soft: #fdf3e1;
  --info-soft: #e8eefc;
  --bubble: #d9fdd3;
  --chat-bg: #efe7de;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 20, .06), 0 4px 16px rgba(16, 24, 20, .06);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1412;
    --surface: #161d1a;
    --surface-2: #1d2622;
    --border: #2a3530;
    --text: #e7eeea;
    --muted: #93a39b;
    --brand: #2bbf86;
    --brand-strong: #49d29c;
    --brand-soft: #173a2c;
    --danger: #ef6b5b;
    --danger-soft: #3a1d1a;
    --warn: #e3a948;
    --warn-soft: #3a2e17;
    --info-soft: #1d2540;
    --bubble: #1f5c47;
    --chat-bg: #0c1311;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg.icon { width: 1.15em; height: 1.15em; flex: none; vertical-align: -.2em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: .25rem;
  padding: 1.25rem .9rem;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.05rem; padding: 0 .5rem 1.25rem; color: var(--text); }
.brand-logo { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: linear-gradient(135deg, var(--brand), #13b981); color: #fff; }
.nav a {
  display: flex; align-items: center; gap: .7rem;
  padding: .6rem .75rem; border-radius: 10px;
  color: var(--muted); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--brand-soft); color: var(--brand-strong); }
.sidebar-foot { margin-top: auto; padding: .75rem .5rem 0; border-top: 1px solid var(--border); }
.sidebar-foot form { margin: 0; }
.main { padding: 2rem clamp(1rem, 4vw, 3rem) 6rem; max-width: 1100px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.page-head p { margin: 0; }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; z-index: 20; bottom: 0; top: auto; left: 0; right: 0; height: auto;
    flex-direction: row; padding: .35rem .5rem calc(.35rem + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--border);
  }
  .brand, .sidebar-foot { display: none; }
  .nav { display: flex; width: 100%; justify-content: space-around; }
  .nav a { flex-direction: column; gap: .15rem; font-size: .72rem; padding: .4rem .5rem; }
  .nav a svg.icon { width: 1.35em; height: 1.35em; }
  .mobile-top { display: flex !important; }
  .main { padding-top: 1rem; }
}
.mobile-top { display: none; align-items: center; justify-content: space-between; padding: .75rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border); }
.mobile-top form { margin: 0; }

/* ---------- Componentes ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; }
.card + .card { margin-top: 1rem; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: .75rem; margin-bottom: .75rem; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 1rem; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: 1.4fr 1fr; }
@media (max-width: 900px) { .grid-3, .grid-2 { grid-template-columns: 1fr; } }

.stat { display: flex; align-items: center; gap: .9rem; }
.stat-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-strong); }
.stat-icon.violet { background: var(--info-soft); color: var(--accent); }
.stat-value { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .6rem 1rem; border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none !important;
  background: var(--brand); color: #fff; transition: background .15s, transform .05s;
}
.btn:hover { background: var(--brand-strong); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--border); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: .35rem .65rem; font-size: .85rem; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-link { background: none; border: 0; color: var(--muted); padding: .25rem; font: inherit; cursor: pointer; display: inline-flex; gap: .4rem; align-items: center; }
.btn-link:hover { color: var(--text); }

.badge { display: inline-flex; align-items: center; gap: .35rem; padding: .15rem .6rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok, .badge.active, .badge.sent { background: var(--brand-soft); color: var(--brand-strong); }
.badge.paused, .badge.skipped, .badge.unknown, .badge.pending { background: var(--warn-soft); color: var(--warn); }
.badge.failed, .badge.off { background: var(--danger-soft); color: var(--danger); }
.badge.completed { background: var(--info-soft); color: var(--accent); }

.alert { padding: .75rem 1rem; border-radius: 10px; margin-bottom: 1rem; background: var(--info-soft); }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- Formularios ---------- */
label { display: block; font-weight: 600; margin-bottom: .35rem; }
.field { margin-bottom: 1rem; }
.hint { font-size: .82rem; color: var(--muted); margin-top: .3rem; }
input[type=text], input[type=password], input[type=date], input[type=time], input[type=number], input[type=search], select, textarea {
  width: 100%; font: inherit; color: var(--text);
  padding: .6rem .75rem; border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, .chip:focus-within, .option:focus-within {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 25%, transparent);
}
textarea { min-height: 170px; resize: vertical; }
input[type=number] { max-width: 110px; }
.inline { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.inline > label { margin: 0; font-weight: 500; }

.chips { display: flex; flex-wrap: wrap; gap: .45rem; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.chip span {
  display: inline-block; padding: .45rem .8rem; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); font-weight: 500; font-size: .9rem; user-select: none; cursor: pointer;
}
.chip input:checked + span { background: var(--brand); border-color: var(--brand); color: #fff; }

.options { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .6rem; }
.option { position: relative; border: 1px solid var(--border); border-radius: 12px; padding: .75rem .85rem; cursor: pointer; background: var(--surface); transition: border-color .15s, background .15s; }
.option input { position: absolute; opacity: 0; inset: 0; cursor: pointer; margin: 0; }
.option strong { display: block; font-size: .95rem; }
.option small { color: var(--muted); }
.option:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }

.time-list { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.time-item { display: inline-flex; align-items: center; gap: .25rem; }
.time-item input { width: auto; }

/* ---------- Login ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background:
  radial-gradient(circle at 15% 20%, color-mix(in srgb, var(--brand) 18%, transparent), transparent 45%),
  radial-gradient(circle at 85% 80%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 40%), var(--bg); }
.auth-card { width: 100%; max-width: 400px; padding: 2rem; }
.auth-card .brand { justify-content: center; padding-bottom: 1rem; font-size: 1.2rem; }

/* ---------- Asistente ---------- */
.stepper { display: flex; gap: .5rem; margin-bottom: 1.25rem; counter-reset: step; }
.stepper button {
  flex: 1; display: flex; align-items: center; gap: .6rem; padding: .7rem .9rem;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--muted);
  font: inherit; font-weight: 600; cursor: pointer; text-align: left;
}
.stepper button::before {
  counter-increment: step; content: counter(step);
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--surface-2); font-size: .85rem;
}
.stepper button.active { border-color: var(--brand); color: var(--text); }
.stepper button.active::before, .stepper button.done::before { background: var(--brand); color: #fff; }
.stepper button.done::before { content: "✓"; }
@media (max-width: 600px) { .stepper button { font-size: 0; gap: 0; justify-content: center; } .stepper button::before { font-size: .85rem; } }

.wizard-actions { display: flex; justify-content: space-between; gap: .75rem; margin-top: 1.25rem; }
.wizard-layout { display: grid; grid-template-columns: 1fr 340px; gap: 1rem; align-items: start; }
@media (max-width: 960px) { .wizard-layout { grid-template-columns: 1fr; } }
.sticky { position: sticky; top: 1rem; }

/* Vista previa estilo chat */
.phone { border-radius: 18px; overflow: hidden; border: 1px solid var(--border); box-shadow: var(--shadow); }
.phone-head { display: flex; align-items: center; gap: .6rem; padding: .7rem .9rem; background: var(--brand-strong); color: #fff; }
.phone-head .avatar { width: 34px; height: 34px; border-radius: 50%; background: rgba(255,255,255,.25); display: grid; place-items: center; }
.phone-head strong { display: block; font-size: .95rem; line-height: 1.2; }
.phone-head small { opacity: .8; }
.phone-body { background: var(--chat-bg); min-height: 260px; padding: 1rem .8rem; display: flex; flex-direction: column; align-items: flex-end; }
.bubble {
  max-width: 92%; background: var(--bubble); color: var(--text); border-radius: 10px 0 10px 10px; padding: .4rem .55rem .25rem;
  box-shadow: 0 1px 1px rgba(0,0,0,.12); white-space: pre-wrap; word-wrap: break-word; position: relative; font-size: .93rem;
}
.bubble img { display: block; max-width: 100%; border-radius: 7px; margin-bottom: .3rem; }
.bubble .doc { display: flex; align-items: center; gap: .5rem; padding: .55rem; border-radius: 7px; background: rgba(0,0,0,.06); margin-bottom: .3rem; font-size: .85rem; }
.bubble .meta { display: block; text-align: right; font-size: .68rem; color: var(--muted); margin-top: .1rem; }
.bubble code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88em; }
.bubble-empty { color: var(--muted); font-style: italic; }

.dropzone {
  border: 2px dashed var(--border); border-radius: 12px; padding: 1.1rem; text-align: center; color: var(--muted);
  cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--brand); background: var(--brand-soft); }
.file-pill { display: flex; align-items: center; gap: .6rem; padding: .6rem .8rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.file-pill .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.toolbar { display: flex; gap: .25rem; margin-bottom: .4rem; flex-wrap: wrap; }
.toolbar button { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: .25rem .6rem; cursor: pointer; font: inherit; font-size: .85rem; color: var(--text); }
.toolbar button:hover { background: var(--surface-2); }
.counter { text-align: right; font-size: .78rem; color: var(--muted); }

.group-list { max-height: 360px; overflow: auto; border: 1px solid var(--border); border-radius: 12px; }
.group-item { display: flex; align-items: center; gap: .75rem; padding: .7rem .9rem; border-bottom: 1px solid var(--border); cursor: pointer; position: relative; }
.group-item:last-child { border-bottom: 0; }
.group-item:hover { background: var(--surface-2); }
.group-item input { position: absolute; opacity: 0; }
.group-item:has(input:checked) { background: var(--brand-soft); }
.group-avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); font-weight: 700; flex: none; }
.group-item:has(input:checked) .group-avatar { background: var(--brand); color: #fff; }

.summary { padding: .9rem 1rem; border-radius: 12px; background: var(--brand-soft); color: var(--brand-strong); font-weight: 600; }
.next-list { list-style: none; padding: 0; margin: .75rem 0 0; }
.next-list li { display: flex; align-items: center; gap: .5rem; padding: .35rem 0; border-bottom: 1px dashed var(--border); font-size: .9rem; }
.next-list li:last-child { border: 0; }
details.advanced { border-top: 1px solid var(--border); margin-top: 1rem; padding-top: .75rem; }
details.advanced summary { cursor: pointer; font-weight: 600; color: var(--muted); }
.exdates { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .5rem; }
.exdates .badge::before { display: none; }
.exdates button { background: none; border: 0; color: inherit; cursor: pointer; padding: 0 0 0 .2rem; font-size: 1rem; line-height: 1; }

/* ---------- Listas y tablas ---------- */
.list { display: flex; flex-direction: column; gap: .75rem; }
.msg-card { display: grid; grid-template-columns: 1fr auto; gap: .75rem 1rem; align-items: start; }
.msg-card h3 { margin: 0 0 .25rem; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.msg-meta { display: flex; flex-wrap: wrap; gap: .25rem 1rem; color: var(--muted); font-size: .87rem; }
.msg-meta span { display: inline-flex; align-items: center; gap: .3rem; }
.msg-preview { margin-top: .5rem; color: var(--muted); font-size: .9rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.msg-actions { display: flex; gap: .4rem; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 700px) { .msg-card { grid-template-columns: 1fr; } .msg-actions { justify-content: flex-start; } }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .65rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
td.err { color: var(--danger); font-size: .82rem; max-width: 320px; }
.tabs { display: flex; gap: .35rem; flex-wrap: wrap; margin-bottom: 1rem; }
.tabs a { padding: .35rem .8rem; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); font-size: .88rem; }
.tabs a.active { background: var(--text); color: var(--surface); border-color: var(--text); text-decoration: none; }
.pager { display: flex; justify-content: center; gap: .5rem; margin-top: 1rem; align-items: center; }

.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.empty svg.icon { width: 42px; height: 42px; stroke-width: 1.5; margin-bottom: .5rem; color: var(--brand); }

/* ---------- WhatsApp / QR ---------- */
.wa-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; align-items: center; }
@media (max-width: 820px) { .wa-layout { grid-template-columns: 1fr; } }
.qr-box {
  width: min(300px, 100%); aspect-ratio: 1; margin: 0 auto; border-radius: 16px; background: #fff;
  display: grid; place-items: center; padding: 14px; border: 1px solid var(--border); position: relative; overflow: hidden;
}
.qr-box img { width: 100%; height: 100%; image-rendering: pixelated; }
.qr-box .overlay { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; background: rgba(255,255,255,.92); color: #17201c; padding: 1rem; }
.qr-progress { height: 4px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin: .9rem auto 0; width: min(300px, 100%); }
.qr-progress div { height: 100%; background: var(--brand); width: 100%; transition: width 1s linear; }
.steps { counter-reset: s; list-style: none; padding: 0; margin: 0; }
.steps li { counter-increment: s; display: flex; gap: .75rem; padding: .55rem 0; }
.steps li::before { content: counter(s); flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-strong); font-weight: 700; font-size: .85rem; }
.connected-hero { text-align: center; padding: 1.5rem 1rem; }
.check-anim { width: 88px; height: 88px; margin: 0 auto 1rem; border-radius: 50%; background: var(--brand); display: grid; place-items: center; color: #fff; animation: pop .45s cubic-bezier(.2, 1.4, .4, 1); }
.check-anim svg.icon { width: 44px; height: 44px; stroke-width: 3; }
@keyframes pop { from { transform: scale(.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--brand); animation: spin .8s linear infinite; margin: 0 auto .5rem; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Toast y modal ---------- */
.toast-area { position: fixed; right: 1rem; bottom: 1rem; z-index: 50; display: flex; flex-direction: column; gap: .5rem; }
@media (max-width: 820px) { .toast-area { left: 1rem; right: 1rem; bottom: auto; top: calc(.75rem + env(safe-area-inset-top)); } }
.toast { background: var(--text); color: var(--surface); padding: .7rem 1rem; border-radius: 10px; box-shadow: var(--shadow); animation: slide .25s ease-out; max-width: 380px; }
.toast.error { background: var(--danger); color: #fff; }
@keyframes slide { from { transform: translateY(10px); opacity: 0; } }
dialog { border: 0; border-radius: var(--radius); padding: 1.5rem; max-width: 420px; width: calc(100% - 2rem); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(10, 15, 13, .55); }
dialog .actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.25rem; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
.mt { margin-top: 1rem; }
.grow { flex: 1; min-width: 0; }
.grid > .card + .card, .list > .card + .card { margin-top: 0; }
.inline input[type=date], .inline input[type=time], .inline select { width: auto; }
.next-list li { text-transform: none; }

/* ---------- Varios adjuntos ---------- */
.att-list { display: flex; flex-direction: column; gap: .4rem; margin-bottom: .6rem; }
.att-list:empty { display: none; }
.att-item { display: flex; align-items: center; gap: .6rem; padding: .45rem .55rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.att-num { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); font-size: .75rem; font-weight: 700; color: var(--muted); flex: none; }
.att-thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; flex: none; background: var(--surface); display: grid; place-items: center; color: var(--muted); }
.att-info { flex: 1; min-width: 0; }
.att-info .name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.att-actions { display: flex; gap: .1rem; }
.att-actions button { background: none; border: 0; padding: .3rem; border-radius: 6px; cursor: pointer; color: var(--muted); font: inherit; line-height: 1; }
.att-actions button:hover:not(:disabled) { background: var(--surface); color: var(--text); }
.att-actions button:disabled { opacity: .3; cursor: default; }
.bubbles { display: flex; flex-direction: column; align-items: flex-end; gap: .35rem; width: 100%; }
.bubble-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; margin-bottom: .3rem; }
.bubble-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; margin: 0; }
.bubble-grid .more { position: relative; }
.bubble-grid .more span { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.5); color: #fff; font-size: 1.4rem; font-weight: 700; border-radius: 6px; }

.upload-progress { margin-top: 1rem; padding: .75rem .9rem; border-radius: 12px; background: var(--brand-soft); color: var(--brand-strong); }
.upload-bar { height: 8px; border-radius: 8px; background: color-mix(in srgb, var(--brand) 18%, transparent); overflow: hidden; margin-bottom: .4rem; }
.upload-bar div { height: 100%; width: 0; background: var(--brand); transition: width .2s ease; }
.att-item.added { animation: pop .35s ease-out; }
#att-count::before { display: none; }
