:root {
  --green: #128c7e; --green-d: #075e54; --green-l: #dcf8c6; --bg: #f3f5f7; --card: #fff;
  --text: #1f2933; --muted: #6b7785; --line: #e3e7eb; --red: #c0392b; --amber: #b7791f; --blue: #34b7f1;
  --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
h1 { font-size: 22px; margin: 0; } h2 { font-size: 17px; margin: 0 0 12px; } h3 { font-size: 14px; margin: 8px 0; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
a { color: var(--green); }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12px; } .error { color: var(--red); } .ok-text { color: #1b7f4c; font-weight: 600; }
.pad { padding: 16px; } .spacer { flex: 1; }

.topbar { display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 58px; background: var(--green-d); color: #fff; position: sticky; top: 0; z-index: 10; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand.big { font-size: 20px; justify-content: center; margin-bottom: 8px; color: var(--green-d); }
.logo { width: 30px; height: 30px; border-radius: 50%; background: #25d366; color: #fff; display: grid; place-items: center; font-weight: 800; }
nav { display: flex; gap: 4px; flex: 1; }
nav button { background: transparent; color: #d5ebe7; border: 0; padding: 8px 14px; border-radius: 8px; font-weight: 600; }
nav button.active, nav button:hover { background: rgba(255, 255, 255, .14); color: #fff; }
.topbar .ghost { color: #fff; border-color: rgba(255, 255, 255, .4); }

main { max-width: 1280px; margin: 0 auto; padding: 24px; }
.view { display: none; } .view.active { display: block; }
.view-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 24px; } .grid2.top { align-items: start; }
.grid2 > .card { margin-bottom: 20px; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } .topbar { gap: 8px; padding: 0 12px; overflow-x: auto; } main { padding: 12px; } }

label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 13px; margin-bottom: 12px; }
label small { font-weight: 400; color: var(--muted); }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid #cfd6dc; border-radius: 8px; background: #fff; color: var(--text); min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-ring, rgba(18, 140, 126, .35)); border-color: var(--green); }
button, .button { font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 8px; border: 1px solid #cfd6dc; background: #fff; color: var(--text); cursor: pointer; text-decoration: none; display: inline-block; }
button:hover, .button:hover { background: #f1f4f6; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--green); border-color: var(--green); color: #fff; } button.primary:hover { background: var(--green-d); }
button.ghost { background: transparent; } button.danger { color: var(--red); }
button.small { padding: 4px 10px; font-size: 12px; }
.form-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.form-actions input { width: 240px; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; } .toolbar h2 { margin: 0; }

.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--line); }
.table td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table td.actions { white-space: nowrap; text-align: right; } .table td.actions button { margin-left: 4px; }
.table td.num { text-align: right; font-weight: 600; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; margin-top: 12px; }

.pill { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; background: #eef1f4; color: var(--muted); }
.pill.running { background: #e0f2fe; color: #0369a1; } .pill.done { background: #dcfce7; color: #15803d; }
.pill.paused { background: #fef3c7; color: var(--amber); } .pill.cancelled { background: #fde2e1; color: var(--red); }
.pill.tiny { font-size: 10px; padding: 0 6px; }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 99px; background: #25d366; color: #fff; font-size: 11px; font-weight: 700; text-align: center; line-height: 20px; }
.progress { height: 8px; background: #e8ecef; border-radius: 99px; overflow: hidden; margin-top: 4px; }
.progress > div { height: 100%; background: var(--green); transition: width .4s; }

.mapping { display: flex; flex-direction: column; gap: 8px; }
.map-row { display: grid; grid-template-columns: 110px 110px 1fr 1fr; gap: 6px; align-items: center; }
.map-row .var { font-family: ui-monospace, monospace; font-weight: 700; color: var(--green-d); font-size: 13px; }
.map-row .fixed:not(.hidden) { grid-column: span 2; }

.phone-bg { background: #efeae2; border-radius: var(--radius); padding: 16px; }
.wa-bubble { background: #fff; border-radius: 8px; padding: 8px 10px; max-width: 360px; box-shadow: 0 1px .5px rgba(0, 0, 0, .13); white-space: normal; }
.wa-h { font-weight: 700; margin-bottom: 4px; } .wa-f { color: var(--muted); font-size: 12px; margin-top: 6px; }
.wa-media { background: #dfe5e7; border-radius: 6px; padding: 28px; text-align: center; color: var(--muted); margin-bottom: 6px; }
.wa-btns { border-top: 1px solid var(--line); margin-top: 8px; display: flex; flex-direction: column; }
.wa-btns span { text-align: center; color: #0a84c7; padding: 6px 0; font-weight: 600; } .wa-btns span + span { border-top: 1px solid var(--line); }

.notice { background: #ecfdf5; border: 1px solid #bbf7d0; padding: 12px; border-radius: 8px; margin-top: 12px; }

.stats { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin: 16px 0; }
.stats div { background: var(--bg); border-radius: 8px; padding: 10px; text-align: center; }
.stats b { display: block; font-size: 20px; } .stats span { font-size: 12px; color: var(--muted); } .stats .bad b { color: var(--red); }

/* Bandeja */
.inbox { display: grid; grid-template-columns: 320px 1fr; padding: 0; height: calc(100vh - 130px); min-height: 480px; overflow: hidden; }
.conv-col { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.conv-col > input { margin: 12px; }
.conv-list { overflow-y: auto; flex: 1; }
.conv { padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.conv:hover { background: #f6f8f9; } .conv.active { background: #e7f3f1; }
.conv-top, .conv-bottom { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.ellipsis { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; flex: 1; }
.chat { display: flex; flex-direction: column; min-height: 0; }
.chat-head { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: center; }
.chat-body { flex: 1; overflow-y: auto; border-radius: 0; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 65%; padding: 6px 10px; border-radius: 8px; box-shadow: 0 1px .5px rgba(0, 0, 0, .13); background: #fff; align-self: flex-start; word-wrap: break-word; }
.msg.out { background: var(--green-l); align-self: flex-end; }
.msg .meta { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; }
.msg .meta .read { color: var(--blue); }
.msg .tag { font-size: 10px; font-weight: 700; color: var(--green-d); text-transform: uppercase; }
.chat-input { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.chat-input textarea { flex: 1; resize: none; }
.chat-note { font-size: 12px; color: var(--muted); padding: 0 12px 10px; }
@media (max-width: 900px) { .inbox { grid-template-columns: 1fr; height: auto; } .chat-body { min-height: 360px; } .stats { grid-template-columns: repeat(3, 1fr); } }

.dl { display: grid; grid-template-columns: 160px 1fr; gap: 6px 12px; margin: 0; } .dl dt { color: var(--muted); } .dl dd { margin: 0; }
code { background: #eef1f4; padding: 1px 6px; border-radius: 4px; font-size: 12.5px; }
.env-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 8px; }

.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-box { background: #fff; border-radius: 12px; padding: 24px; width: min(760px, 100%); max-height: 90vh; overflow: auto; position: relative; }
.modal-close { position: absolute; top: 10px; right: 10px; border: 0; font-size: 22px; line-height: 1; padding: 4px 10px; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #1f2933; color: #fff; padding: 12px 18px; border-radius: 8px; z-index: 60; max-width: 90vw; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); }
.toast.error { background: var(--red); }

.login-page { display: grid; place-items: center; min-height: 100vh; }
.login-card { width: min(360px, 92vw); display: flex; flex-direction: column; }

/* ===== v2: usuarios, programación, plantillas, automatización ===== */
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
label.inline { display: inline-flex; flex-direction: row; align-items: center; gap: 6px; font-weight: 500; margin: 0; }
.days { display: inline-flex; gap: 4px; flex-wrap: wrap; margin: 6px 0; }
.day { display: inline-flex; flex-direction: row; align-items: center; gap: 3px; font-weight: 500; font-size: 12px; margin: 0; padding: 3px 8px; border: 1px solid var(--line); border-radius: 99px; background: #fff; }
.schedule { background: var(--bg); border-radius: 8px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.schedule p { margin: 0; }
.warn { color: var(--amber); }
.ok-text.small { font-weight: 500; }
.pill.scheduled { background: #ede9fe; color: #6d28d9; } .pill.waiting { background: #fef3c7; color: var(--amber); }
.topbar #meBtn { color: #fff; border-color: rgba(255, 255, 255, .4); white-space: nowrap; }
.card.flat { border: 1px dashed var(--line); margin-top: 16px; }

/* Bandeja */
.conv-filters { padding: 12px; display: flex; flex-direction: column; gap: 6px; border-bottom: 1px solid var(--line); }
.conv-filters .row select { flex: 1; }
.conv-col > input { margin: 0; }
.conv-meta { display: flex; gap: 6px; align-items: center; margin-top: 4px; flex-wrap: wrap; }
.tag { background: #e7f3f1; color: var(--green-d); font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: 99px; }
.chat-head { flex-wrap: wrap; justify-content: space-between; }
.chat-title { display: flex; gap: 8px; align-items: center; }
.chat-tools { display: flex; gap: 6px; align-items: center; }
.chat-tools input, .chat-tools select { padding: 4px 8px; font-size: 13px; max-width: 170px; }
.tag-line { font-size: 10px; font-weight: 700; color: var(--green-d); text-transform: uppercase; }
.msg-img { max-width: 260px; max-height: 260px; border-radius: 6px; display: block; margin-bottom: 4px; }
.msg audio { max-width: 260px; }
.doc { display: inline-block; background: rgba(0, 0, 0, .05); padding: 6px 10px; border-radius: 6px; text-decoration: none; margin-bottom: 4px; font-weight: 600; }
.icon-btn { padding: 6px 10px; font-size: 16px; line-height: 1; }
.chat { position: relative; }
.popover { position: absolute; bottom: 110px; left: 10px; width: 340px; max-height: 360px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, .15); z-index: 20; display: flex; flex-direction: column; }
.popover > input { margin: 10px; }
.qr-list { overflow-y: auto; flex: 1; }
.qr-item { padding: 8px 12px; cursor: pointer; border-top: 1px solid var(--line); }
.qr-item:hover { background: #f1f7f6; }
.qr-foot { border-top: 1px solid var(--line); padding: 6px; text-align: right; }
.attach-bar { padding: 6px 12px; background: #fffbea; border-top: 1px solid var(--line); font-size: 13px; }

/* Plantillas */
.modal-box.wide { width: min(1080px, 100%); }
.tpl-editor { display: grid; grid-template-columns: 1.4fr 1fr; gap: 24px; }
.tpl-side { position: sticky; top: 0; align-self: start; }
.grid3 { display: grid; grid-template-columns: 1.3fr 1fr 1.2fr; gap: 12px; }
.btn-row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; flex-wrap: wrap; }
.btn-row input { flex: 1; min-width: 140px; }
.examples { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; background: var(--bg); padding: 8px; border-radius: 8px; margin: -4px 0 12px; }
.examples input { width: 140px; }
.tpl-snippet { max-width: 360px; }
@media (max-width: 900px) { .tpl-editor, .grid3 { grid-template-columns: 1fr; } }

/* Automatización */
.opt-card { border: 1px solid var(--line); border-radius: 8px; padding: 8px; margin-bottom: 8px; display: flex; flex-direction: column; gap: 6px; }
.opt-card .row input[data-f="title"] { flex: 2; } .opt-card .row input[data-f="tag"] { flex: 1; }
.switch { position: relative; display: inline-block; width: 38px; height: 22px; margin: 0 6px 0 0; vertical-align: middle; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #cfd6dc; border-radius: 99px; transition: .2s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::before { transform: translateX(16px); }
h2 .switch { flex-direction: row; }
.user-form { margin-top: 12px; }
.user-form input { flex: 1; min-width: 150px; }

/* ===== v3: asistente IA ===== */
.view-head.sub { margin-top: 8px; }
.view-head.sub h2 { margin: 0; }
.warn-box { background: #fffbea; border-color: #fde68a; margin: 0 0 14px; }
.ai-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 24px; align-items: start; }
.ai-grid .row select { flex: 1; }
.ai-test { position: sticky; top: 70px; }
.ai-chat { height: 420px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.ai-test form input { flex: 1; }
@media (max-width: 1000px) { .ai-grid { grid-template-columns: 1fr; } .ai-test { position: static; } }
.toolbar.bulk { background: var(--bg); padding: 8px 10px; border-radius: 8px; }
th.chk, td.chk { width: 32px; }

/* ===== v4: indicadores y recordatorios ===== */
.viz-root { --series-1: #2a78d6; --series-2: #eb6834; --grid: #e6e8ea; --axis-ink: #6b7785; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.seg button { border: 0; border-radius: 0; padding: 6px 14px; font-weight: 600; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.active { background: var(--green); color: #fff; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; }
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 26px; font-weight: 700; letter-spacing: -.01em; }
.kpi-sub { font-size: 12px; color: var(--muted); }
.small-kpis { grid-template-columns: repeat(2, 1fr); margin: 0; }
.small-kpis .kpi { background: var(--bg); border: 0; }
.delta { display: block; font-weight: 600; } .delta.up { color: #15803d; } .delta.down { color: var(--amber); }
.chart { position: relative; }
.chart svg .grid { stroke: var(--grid); stroke-width: 1; } .chart svg .base { stroke: #cfd6dc; stroke-width: 1; }
.chart svg .axis { font-size: 11px; fill: var(--axis-ink); }
.chart svg .hit.on { fill: rgba(0, 0, 0, .04); }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--text); }
.lg i, .tip i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.tip { position: absolute; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 6px 20px rgba(0, 0, 0, .12); pointer-events: none; white-space: nowrap; }
.tip b:first-child { display: block; margin-bottom: 4px; }
.tip b:first-child::first-letter { text-transform: uppercase; }
.hbar { display: grid; grid-template-columns: 150px 1fr 60px; gap: 10px; align-items: center; padding: 5px 0; font-size: 13px; }
.hbar.mini { grid-template-columns: 1fr 44px; padding: 0; }
.hbar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { height: 12px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.hbar-fill { display: block; height: 100%; background: #2a78d6; border-radius: 0 4px 4px 0; }
.hbar-val { text-align: right; font-weight: 600; }
details summary { cursor: pointer; color: var(--muted); margin-top: 8px; }
.rule-checks { display: flex; flex-direction: column; gap: 4px; margin: 6px 0 12px; }
.send-line { margin-bottom: 4px; }
.reply { color: var(--green-d); font-weight: 600; }
tr.dim td { opacity: .55; }

/* Barra superior con más pestañas */
.topbar { gap: 14px; padding: 0 16px; }
.brand { white-space: nowrap; flex-shrink: 0; }
nav { overflow-x: auto; scrollbar-width: none; min-width: 0; }
nav::-webkit-scrollbar { display: none; }
nav button { white-space: nowrap; padding: 8px 10px; font-size: 13.5px; flex-shrink: 0; }
.topbar #meBtn, .topbar #logoutBtn { flex-shrink: 0; }
@media (max-width: 1250px) { .brand { font-size: 0; gap: 0; } .brand .logo { font-size: 16px; } }
.kpis { grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); }

/* ===== v5: identidad corporativa ===== */
:root { --brand-soft: rgba(18, 140, 126, .10); }
.topbar { background: #fff; color: var(--text); height: 64px; border-bottom: 3px solid var(--green); box-shadow: 0 2px 10px rgba(16, 24, 40, .06); }
.topbar nav button { color: var(--muted); }
.topbar nav button:hover { background: var(--brand-soft); color: var(--green-d); }
.topbar nav button.active { background: var(--brand-soft); color: var(--green-d); box-shadow: inset 0 -2px 0 var(--green); border-radius: 8px 8px 2px 2px; }
.topbar .ghost, .topbar #meBtn { color: var(--text); border-color: var(--line); }
.topbar .ghost:hover { background: var(--brand-soft); }
.brand { gap: 12px; font-size: 14px; }
.brand-logo { height: 42px; max-width: 170px; object-fit: contain; display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text b { font-size: 14.5px; color: var(--green-d); }
.brand-text small { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.has-logo .topbar .brand-text { border-left: 1px solid var(--line); padding-left: 12px; }
.has-logo .topbar .brand-text small { display: none; }
.logo { background: var(--green); }
@media (max-width: 1540px) { .brand-text { display: none; } }
@media (max-width: 1250px) { .brand { font-size: 14px; gap: 10px; } .brand-logo { height: 36px; max-width: 120px; } }

.login-page { background: linear-gradient(165deg, var(--green-d) 0, var(--green) 36%, var(--bg) 36.1%); }
.login-wrap { display: flex; flex-direction: column; align-items: center; gap: 14px; width: min(400px, 92vw); }
.login-card { width: 100%; padding: 32px 30px 22px; box-shadow: 0 18px 50px rgba(16, 24, 40, .16); border: 0; }
.login-brand { text-align: center; margin-bottom: 18px; }
.login-logo { max-height: 90px; max-width: 250px; object-fit: contain; margin: 0 auto 14px; display: block; }
.login-brand h1 { font-size: 19px; color: var(--green-d); }
.login-brand p { margin: 2px 0 0; }
.has-logo .login-brand p { display: none; }
.logo.big { width: 58px; height: 58px; font-size: 26px; margin: 0 auto 12px; }
.login-card button.primary { padding: 11px; margin-top: 4px; }
.login-foot { color: var(--muted); font-size: 12px; margin: 0; }

.brand-grid { display: grid; grid-template-columns: 260px 1fr; gap: 24px; align-items: start; }
.brand-preview { border: 1px dashed var(--line); border-radius: var(--radius); min-height: 150px; display: grid; place-items: center; padding: 16px; background: repeating-conic-gradient(#f6f7f9 0 25%, #fff 0 50%) 0 0 / 16px 16px; }
.brand-preview img { max-width: 100%; max-height: 120px; object-fit: contain; }
.color-row { display: flex; gap: 8px; align-items: center; }
.color-row input[type="color"] { width: 46px; height: 38px; padding: 2px; }
.color-row input[type="text"] { width: 110px; font-family: ui-monospace, monospace; }
.swatches { display: flex; gap: 6px; margin-top: 6px; }
.swatches span { width: 28px; height: 18px; border-radius: 4px; border: 1px solid rgba(0, 0, 0, .1); }
@media (max-width: 900px) { .brand-grid { grid-template-columns: 1fr; } }
