:root {
    --brand: #6678ff;
    --brand-dark: #4c5de0;
    --brand-soft: #eef0ff;
    --ink: #0d0d12;
    --muted: #666b7d;
    --line: #e4e6ef;
    --bg: #f5f6fb;
    --surface: #fff;
    --ok: #12805c;
    --ok-soft: #e3f6ee;
    --bad: #c4314b;
    --bad-soft: #fdeaee;
    --radius: 10px;
    --display: "Jost", "Century Gothic", "Futura", system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: var(--ink);
    background: var(--bg);
}
h1, h2, h3 { font-family: var(--display); font-weight: 600; line-height: 1.2; margin: 0; }
h1 { font-size: 28px; }
h2 { font-size: 18px; margin-bottom: 12px; }
h3 { font-size: 15px; margin: 22px 0 10px; }
a { color: var(--brand-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
p { margin: 0 0 12px; }
small { font-size: 12.5px; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.neg { color: var(--bad); }
.pos { color: var(--ok); }

/* ---------- Formularios ---------- */
label { display: block; font-size: 13.5px; font-weight: 600; }
label small { display: block; font-weight: 400; color: var(--muted); margin-top: 4px; }
input, select, textarea {
    display: block; width: 100%; margin-top: 6px; padding: 10px 12px;
    font: inherit; font-weight: 400; color: var(--ink);
    background: var(--surface); border: 1px solid #cfd3e1; border-radius: 8px;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible, button:focus-visible {
    outline: 3px solid rgba(102, 120, 255, .35); outline-offset: 1px; border-color: var(--brand);
}
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.check input { width: auto; margin: 0; }
.stack > * + * { margin-top: 16px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }

.btn {
    display: inline-block; padding: 10px 18px; border: 1px solid var(--brand); border-radius: 8px;
    background: var(--brand); color: #fff; font: inherit; font-weight: 600; cursor: pointer; text-align: center;
}
.btn:hover { background: var(--brand-dark); border-color: var(--brand-dark); text-decoration: none; }
.btn-ghost { background: transparent; color: var(--brand-dark); border-color: #cfd3e1; }
.btn-ghost:hover { background: var(--brand-soft); border-color: var(--brand); }
button.link { background: none; border: 0; padding: 0; font: inherit; color: var(--brand-dark); cursor: pointer; }
button.link:hover { text-decoration: underline; }

.alert { padding: 11px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.alert-ok { background: var(--ok-soft); color: #0b5c41; }
.alert-error { background: var(--bad-soft); color: #96223a; }

textarea { resize: vertical; min-height: 80px; line-height: 1.45; }
textarea.mono, pre.raw { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
pre.raw { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px; overflow-x: auto; white-space: pre-wrap; word-break: break-word; margin: 0; }
input[type=file] { padding: 8px; }
.alert-info { background: var(--brand-soft); color: #2e3a9c; }
.alert a { color: inherit; text-decoration: underline; }
.fine { font-size: 13px; margin-top: 14px; }
.msg { background: var(--bg); border-radius: 8px; padding: 14px; overflow-wrap: anywhere; }
.actions { display: flex; gap: 12px; flex-wrap: wrap; }
.tag-bad { background: var(--bad-soft); color: #96223a; }
.tag-wait { background: var(--brand-soft); color: #2e3a9c; }
.search select { margin-top: 0; }

/* ---------- Ingreso ---------- */
body.auth { display: grid; grid-template-columns: minmax(340px, 480px) 1fr; min-height: 100vh; background: var(--surface); }
.auth-form { padding: 56px 48px; display: flex; flex-direction: column; justify-content: center; }
.auth-logo { height: auto; margin: 0 0 40px -10px; }
.auth-form h1 { margin-bottom: 6px; }
.auth-form .btn { width: 100%; padding: 12px; }
.auth-side {
    background: var(--brand); color: #fff; display: flex; align-items: flex-end; padding: 64px;
    background-image: linear-gradient(135deg, rgba(255,255,255,.14) 0 25%, transparent 25% 50%, rgba(255,255,255,.08) 50% 75%, transparent 75%);
}
.auth-side div { max-width: 460px; }
.auth-side h2 { font-size: 34px; margin-bottom: 14px; }
.auth-side p { font-size: 17px; opacity: .92; }

/* ---------- Portal ---------- */
body.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
    background: var(--surface); border-right: 1px solid var(--line); padding: 18px 14px;
    display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { display: block; margin-bottom: 22px; }
.brand img { display: block; height: auto; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a { padding: 9px 12px; border-radius: 8px; color: var(--ink); font-weight: 500; }
.sidebar nav a:hover { background: var(--bg); text-decoration: none; }
.sidebar nav a.active { background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; }
.who { margin-top: auto; padding: 14px 12px 4px; border-top: 1px solid var(--line); font-size: 13.5px; }
.who strong, .who span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who span { color: var(--muted); margin-bottom: 8px; }

.main { padding: 32px 36px 56px; min-width: 0; max-width: 1180px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.back { font-size: 13.5px; display: inline-block; margin-bottom: 4px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin-bottom: 20px; }
.card.narrow { max-width: 520px; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; align-items: start; }
.cols .card { margin-bottom: 20px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.stat span { display: block; font-size: 13px; color: var(--muted); }
.stat strong { display: block; font-family: var(--display); font-size: 26px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); }
.stat-main { background: var(--brand); border-color: var(--brand); color: #fff; }
.stat-main span, .stat-main small { color: rgba(255,255,255,.9); }

.table-wrap { overflow-x: auto; margin: 0 -6px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 6px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.tag { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; }
.tag-on { background: var(--ok-soft); color: #0b5c41; }
.tag-off { background: #eceef4; color: var(--muted); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.empty { color: var(--muted); padding: 14px 0; margin: 0; }
.facts { margin: 0; display: grid; gap: 12px; }
.facts dt { font-size: 13px; color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; }
.search { display: flex; gap: 10px; margin-bottom: 14px; max-width: 460px; }
.search input { margin-top: 0; }
.pager { display: flex; gap: 16px; justify-content: center; align-items: center; margin-top: 16px; font-size: 14px; color: var(--muted); }

@media (max-width: 820px) {
    body.auth { grid-template-columns: 1fr; }
    .auth-side { display: none; }
    .auth-form { padding: 40px 24px; }
    body.app { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
    .sidebar nav { flex-direction: row; flex-wrap: wrap; }
    .who { margin-top: 12px; }
    .main { padding: 22px 16px 40px; }
}

/* ---------- Chatbot ---------- */
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.thread { display: flex; flex-direction: column; gap: 8px; max-width: 640px; }
.bubble { margin: 0; padding: 9px 12px; border-radius: 12px; max-width: 85%; overflow-wrap: anywhere; }
.bubble-user { background: var(--brand); color: #fff; align-self: flex-end; }
.bubble-bot { background: var(--bg); border: 1px solid var(--line); align-self: flex-start; }

.inline-form { display: flex; gap: 8px; width: 100%; }
.inline-form input { margin-top: 0; }
.inline-form .btn { white-space: nowrap; }

/* ---------- Reportes y gráficas ---------- */
.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filters label { min-width: 150px; }
.card > .page-head { margin-bottom: 10px; }
.card > .page-head h2 { margin: 0; }
.hero strong { font-family: var(--display); font-size: 30px; font-weight: 600; font-variant-numeric: tabular-nums; margin-right: 6px; }
.chart { margin: 0; }
.stackbar { display: block; width: 100%; height: 28px; margin: 6px 0 14px; }
.legend { max-width: 520px; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 8px; vertical-align: -1px; }
/* Los colores acompañan siempre a su etiqueta y cifra en la tabla; nunca van solos. */
.seg-entregado    { fill: #0ca30c; background: #0ca30c; }
.seg-enviado      { fill: #6678ff; background: #6678ff; }
.seg-no_entregado { fill: #ec835a; background: #ec835a; }
.seg-fallido      { fill: #d03b3b; background: #d03b3b; }
.seg-revisar      { fill: #fab219; background: #fab219; }
.seg-en_cola      { fill: #b9bdcc; background: #b9bdcc; }
.seg-cancelado    { fill: #6b7084; background: #6b7084; }
.keybox { font-size: 15px; user-select: all; }

/* ---------- Celulares y tabletas: botones grandes y de colores ---------- */
@media (max-width: 1024px) {
    body.app { grid-template-columns: 1fr; }
    body { font-size: 16px; }
    .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 14px 16px 16px; }
    .brand { margin-bottom: 14px; }
    .sidebar nav { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
    .sidebar nav a {
        display: flex; align-items: center; justify-content: center; text-align: center;
        min-height: 60px; padding: 10px 8px; border-radius: 14px; font-weight: 600; font-size: 15px; line-height: 1.2;
        color: #1b1d29; background: #eef0ff; border: 2px solid transparent;
    }
    .sidebar nav a:nth-child(9n+1) { background: #dfe3ff; }
    .sidebar nav a:nth-child(9n+2) { background: #d3f3e4; }
    .sidebar nav a:nth-child(9n+3) { background: #ffe3c9; }
    .sidebar nav a:nth-child(9n+4) { background: #e9dcff; }
    .sidebar nav a:nth-child(9n+5) { background: #cfeafb; }
    .sidebar nav a:nth-child(9n+6) { background: #fff0b8; }
    .sidebar nav a:nth-child(9n+7) { background: #ffd9e1; }
    .sidebar nav a:nth-child(9n+8) { background: #d5f0f0; }
    .sidebar nav a:nth-child(9n+9) { background: #e6e8ef; }
    .sidebar nav a:hover { text-decoration: none; filter: brightness(.97); }
    .sidebar nav a.active { background: var(--brand); color: #fff; border-color: var(--brand-dark); box-shadow: 0 4px 12px rgba(102,120,255,.35); }
    .who { margin-top: 14px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 0 0; font-size: 15px; }
    .who span { margin-bottom: 0; }
    .who form { margin-left: auto; }
    .who button.link { min-height: 44px; padding: 8px 16px; border: 1px solid #cfd3e1; border-radius: 10px; font-weight: 600; }

    .main { padding: 22px 18px 48px; max-width: none; }
    h1 { font-size: 26px; }
    .card { padding: 18px; border-radius: 14px; }
    .cols { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }

    .btn { min-height: 52px; padding: 14px 22px; border-radius: 12px; font-size: 17px; box-shadow: 0 3px 10px rgba(102,120,255,.28); }
    .btn-ghost { box-shadow: none; background: var(--brand-soft); border-color: var(--brand); border-width: 2px; }
    input, select, textarea { min-height: 50px; padding: 13px 14px; font-size: 16px; border-radius: 10px; }
    .check { min-height: 44px; }
    .check input { min-height: 0; width: 22px; height: 22px; }
    input[type=file] { padding: 11px; }
    label { font-size: 15px; }
    button.link { min-height: 40px; padding: 6px 4px; font-weight: 600; }
    .tag { padding: 4px 12px; font-size: 13.5px; }
    .back { font-size: 15px; padding: 6px 0; }
    th, td { padding: 12px 8px; }
    .pager a { display: inline-block; padding: 12px 16px; border-radius: 10px; background: var(--brand-soft); font-weight: 600; }

    .stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
    .stat { border-radius: 14px; border-width: 0; padding: 16px 18px; }
    .stat strong { font-size: 24px; }
    .stat:nth-child(4n+1) { background: #dfe3ff; }
    .stat:nth-child(4n+2) { background: #d3f3e4; }
    .stat:nth-child(4n+3) { background: #ffe3c9; }
    .stat:nth-child(4n+4) { background: #e9dcff; }
    .stat span, .stat small { color: #3c4050; }
    .stat.stat-main { background: var(--brand); }
    .stat.stat-main span, .stat.stat-main small { color: #fff; }
    .stackbar { height: 36px; }

    body.auth { grid-template-columns: 1fr; }
    .auth-side { display: none; }
    .auth-form { padding: 40px 24px; max-width: 560px; margin: 0 auto; width: 100%; }
}
@media (max-width: 600px) {
    .sidebar nav { grid-template-columns: repeat(3, 1fr); gap: 8px; }
    .sidebar nav a { min-height: 54px; font-size: 14px; padding: 8px 6px; }
    .main { padding: 18px 14px 40px; }
    .page-head .btn, .actions .btn, .actions form, form .btn, .filters .btn, .filters label, .search .btn { width: 100%; }
    .actions { flex-direction: column; }
    .search { flex-direction: column; max-width: none; }
    .inline-form { flex-direction: column; }
    .who form { margin-left: 0; width: 100%; }
    .who button.link { width: 100%; }
}

/* ---------- Fondo de las pantallas de ingreso ---------- */
body.auth { background: #2b3160 url("auth-bg.svg") center / cover no-repeat fixed; }
.auth-form { background: var(--surface); box-shadow: 0 0 40px rgba(13,13,18,.25); }
.auth-side { background: linear-gradient(to top, rgba(22,25,52,.88) 0, rgba(22,25,52,.35) 45%, rgba(22,25,52,0) 75%); }
.auth-side h2, .auth-side p { text-shadow: 0 1px 12px rgba(13,13,18,.5); }
@media (max-width: 1024px) {
    body.auth { display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
    .auth-form { flex: 0 1 520px; border-radius: 20px; padding: 36px 28px; margin: 0; min-height: 0; box-shadow: 0 18px 50px rgba(13,13,18,.4); }
    .auth-logo { margin-bottom: 28px; }
}

/* ---------- Registro ---------- */
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.newacct { margin-top: 26px; padding-top: 20px; border-top: 1px solid var(--line); font-size: 14px; }
.newacct .btn { display: block; width: 100%; margin-top: 10px; }
body.auth { align-items: stretch; }
.auth-form { overflow-y: auto; }
@media (min-width: 1025px) { .auth-form { max-height: 100vh; justify-content: flex-start; padding-top: 44px; padding-bottom: 44px; } .auth-form > :first-child { margin-top: auto; } .auth-form > :last-child { margin-bottom: auto; } }
.tag-new { background: #fff0b8; color: #6b4a00; }

/* ---------- Reportes del administrador ---------- */
tr.total td { font-weight: 700; border-top: 2px solid var(--ink); border-bottom: 0; background: var(--bg); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 0; }

/* ---------- Portada del cliente: canales y productos ---------- */
.section-title { margin: 26px 0 12px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 8px; }
.tile { display: flex; flex-direction: column; gap: 6px; min-height: 124px; padding: 20px; border-radius: 16px; color: #1b1d29; border: 2px solid transparent; position: relative; }
.tile:hover { text-decoration: none; border-color: var(--brand); }
.tile strong { font-family: var(--display); font-size: 20px; font-weight: 600; }
.tile span { font-size: 14px; color: #3c4050; }
.tile em { margin-top: auto; font-style: normal; font-size: 12.5px; font-weight: 600; background: rgba(255,255,255,.75); border-radius: 999px; padding: 2px 10px; align-self: flex-start; }
.tile-sms { background: #dfe3ff; } .tile-wa { background: #d3f3e4; } .tile-bot { background: #cfeafb; }
.tile-rep { background: #ffe3c9; } .tile-camp { background: #e9dcff; } .tile-adm { background: #e6e8ef; }
.checklist { margin: 0 0 12px; padding-left: 20px; } .checklist li { margin-bottom: 8px; }
.stat strong.small { font-size: 17px; }

th.grp { text-align: center; background: var(--bg); color: var(--ink); }
th.gl, td.gl { border-left: 2px solid var(--line); }
