/* SiempreChat — identidad visual: #059669 · #102C35 · #FFFFFF · #F8FAFC */
:root {
  --brand: #059669; --brand-strong: #047857; --brand-soft: #d1fae5;
  --navy: #102C35; --navy-2: #173b47;
  --bg: #F8FAFC; --surface: #FFFFFF; --surface-2: #F1F5F9; --border: #E2E8F0;
  --text: #0f172a; --muted: #64748b; --chat-bg: #eef3f1; --bubble-out: #dcfce7; --bubble-in: #ffffff;
  --danger: #dc2626; --warning: #b45309; --ok: #047857; --info: #0369a1;
  --radius: 12px; --shadow: 0 1px 2px rgba(16,44,53,.06), 0 4px 16px rgba(16,44,53,.06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0b1d23; --surface: #102C35; --surface-2: #173b47; --border: #24505e;
  --text: #e8f1f3; --muted: #94adb5; --chat-bg: #0d242b; --bubble-out: #065f46; --bubble-in: #173b47;
  --brand-soft: #064e3b; --shadow: 0 1px 2px rgba(0,0,0,.3);
  --danger: #f87171; --warning: #fbbf24; --ok: #34d399; --info: #7dd3fc;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* Layout */
.layout { display: grid; grid-template-columns: 260px 1fr; height: 100vh; height: 100dvh; }
.sidebar { background: var(--navy); color: #e2f1ef; display: flex; flex-direction: column; padding: 16px 12px; gap: 12px; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 8px; }
.brand img { width: 38px; height: 38px; }
.brand strong { font-size: 18px; color: #fff; display: block; }
.brand small { color: #8fd8bf; font-size: 11.5px; letter-spacing: .02em; }
.company-select { width: 100%; background: var(--navy-2); color: #fff; border: 1px solid #2c5866; border-radius: 10px; padding: 9px 10px; }
.mode-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; }
.mode-TEST { background: #fef3c7; color: #92400e; }
.mode-REAL { background: #fee2e2; color: #991b1b; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; color: #cfe5e1; text-decoration: none; padding: 9px 12px; border-radius: 10px; font-weight: 500; }
.nav a:hover { background: var(--navy-2); color: #fff; }
.nav a.active { background: var(--brand); color: #fff; }
.nav .ico { width: 20px; text-align: center; }
.nav .badge { margin-left: auto; background: #fff; color: var(--brand-strong); border-radius: 999px; font-size: 11px; padding: 0 7px; font-weight: 700; }
.nav-sep { color: #7ea6ae; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; padding: 10px 12px 2px; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: #9fc3c9; padding: 8px; border-top: 1px solid #24505e; }
.sidebar-foot button { background: transparent; border: 1px solid #2c5866; color: #e2f1ef; border-radius: 8px; padding: 6px 10px; cursor: pointer; text-align: left; }
.main { overflow-y: auto; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: none; }
.page { padding: 24px 28px 48px; max-width: 1200px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { font-size: 22px; margin: 0; color: var(--text); }
.page-head p { margin: 4px 0 0; color: var(--muted); }

/* Componentes */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card h2 { font-size: 16px; margin: 0 0 12px; }
.card h3 { font-size: 14px; margin: 14px 0 8px; }
.grid { display: grid; gap: 14px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 28px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid transparent; background: var(--brand); color: #fff; padding: 9px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; text-decoration: none; }
.btn:hover { background: var(--brand-strong); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.link { background: none; color: var(--brand); padding: 4px; white-space: nowrap; }
.btn.link:hover { background: var(--surface-2); }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field label { font-size: 13px; font-weight: 600; }
.field .hint { font-size: 12px; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], input[type=tel], select, textarea {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px; width: 100%; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(5,150,105,.18); }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
textarea { resize: vertical; min-height: 80px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; word-break: break-all; }
.copy { display: flex; gap: 6px; align-items: center; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; }
.copy .mono { flex: 1; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .03em; }
.table-wrap { overflow-x: auto; }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--text); white-space: nowrap; }
.tag.ok { background: #d1fae5; color: #065f46; }
.tag.warn { background: #fef3c7; color: #92400e; }
.tag.err { background: #fee2e2; color: #991b1b; }
.tag.info { background: #e0f2fe; color: #075985; }
.alert { border-radius: 10px; padding: 12px 14px; margin-bottom: 14px; border: 1px solid; }
.alert.warn { background: #fffbeb; border-color: #fcd34d; color: #78350f; }
.alert.info { background: #ecfdf5; border-color: #6ee7b7; color: #064e3b; }
.alert.err { background: #fef2f2; border-color: #fca5a5; color: #7f1d1d; }
[data-theme="dark"] .alert.warn { background: #3b2f0b; color: #fde68a; border-color: #92400e; }
[data-theme="dark"] .alert.info { background: #06302a; color: #a7f3d0; border-color: #065f46; }
[data-theme="dark"] .alert.err { background: #3b1111; color: #fecaca; border-color: #991b1b; }
.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { padding: 7px 0; display: flex; gap: 10px; align-items: center; border-bottom: 1px dashed var(--border); }
.checklist li:last-child { border: 0; }
.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #cbd5e1; border-radius: 999px; cursor: pointer; transition: .15s; }
.switch span::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::before { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, var(--navy) 0%, #0d3b3a 55%, var(--brand) 140%); }
.login-card { background: var(--surface); width: 100%; max-width: 400px; border-radius: 18px; padding: 30px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.login-card .brand { justify-content: center; flex-direction: column; text-align: center; padding-bottom: 18px; }
.login-card .brand img { width: 58px; height: 58px; }
.login-card .brand strong { color: var(--text); font-size: 24px; }
.login-card .brand small { color: var(--brand); font-size: 13px; }

/* Bandeja de entrada (estilo WhatsApp Web) */
.inbox { display: grid; grid-template-columns: 340px 1fr 280px; height: 100vh; height: 100dvh; background: var(--surface); }
.inbox.no-info { grid-template-columns: 340px 1fr; }
.conv-list { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.conv-list .head { padding: 14px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--surface); padding: 3px 10px; border-radius: 999px; font-size: 13px; cursor: pointer; }
.chip.active { background: var(--brand-soft); border-color: var(--brand); color: var(--text); font-weight: 600; }
.conv-items { overflow-y: auto; flex: 1; }
.conv { display: flex; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--border); cursor: pointer; width: 100%; text-align: left; background: none; border-left: 0; border-right: 0; border-top: 0; }
.conv:hover { background: var(--surface-2); }
.conv.active { background: var(--brand-soft); }
.avatar { width: 42px; height: 42px; border-radius: 50%; background: var(--navy); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }
.conv .body { flex: 1; min-width: 0; }
.conv .top { display: flex; justify-content: space-between; gap: 8px; }
.conv .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .time { font-size: 12px; color: var(--muted); flex: none; }
.conv .preview { color: var(--muted); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; justify-content: space-between; gap: 6px; }
.unread { background: var(--brand); color: #fff; border-radius: 999px; font-size: 11.5px; min-width: 20px; height: 20px; display: inline-grid; place-items: center; padding: 0 6px; font-weight: 700; flex: none; }
.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--chat-bg); }
.chat-head { background: var(--surface); padding: 10px 14px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.chat-head .who { flex: 1; min-width: 0; }
.chat-head .who strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.messages { flex: 1; overflow-y: auto; padding: 18px 6%; display: flex; flex-direction: column; gap: 4px; }
.day-sep { align-self: center; background: var(--surface); color: var(--muted); font-size: 12px; padding: 3px 10px; border-radius: 8px; margin: 10px 0; box-shadow: var(--shadow); }
.bubble { max-width: min(72%, 560px); padding: 7px 10px 5px; border-radius: 10px; box-shadow: 0 1px 1px rgba(0,0,0,.08); white-space: pre-wrap; word-wrap: break-word; position: relative; }
.bubble.in { background: var(--bubble-in); align-self: flex-start; border-top-left-radius: 2px; }
.bubble.out { background: var(--bubble-out); align-self: flex-end; border-top-right-radius: 2px; }
.bubble .meta { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
[data-theme="dark"] .bubble .meta { color: #a8c5cb; }
.bubble .tpl { font-size: 11px; font-weight: 700; color: var(--brand-strong); margin-bottom: 2px; }
[data-theme="dark"] .bubble .tpl { color: #6ee7b7; }
.bubble .err { color: var(--danger); font-size: 12px; }
.ticks.read { color: #0ea5e9; }
.composer { background: var(--surface); border-top: 1px solid var(--border); padding: 10px 12px; position: relative; }
.composer form { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 42px; max-height: 160px; resize: none; border-radius: 20px; padding: 10px 14px; }
.composer .btn { border-radius: 50%; width: 44px; height: 44px; justify-content: center; padding: 0; flex: none; }
.qr-pop { position: absolute; bottom: 100%; left: 12px; right: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); max-height: 240px; overflow-y: auto; }
.qr-pop button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 12px; cursor: pointer; border-bottom: 1px solid var(--border); }
.qr-pop button:hover, .qr-pop button.sel { background: var(--brand-soft); }
.window-note { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.info-panel { border-left: 1px solid var(--border); padding: 16px; overflow-y: auto; }
.info-panel h3 { font-size: 13px; text-transform: uppercase; color: var(--muted); letter-spacing: .05em; margin: 16px 0 8px; }
.order-card { border: 1px solid var(--border); border-radius: 10px; padding: 10px; margin-bottom: 8px; font-size: 13.5px; }
.chat-empty { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 20px; }
.back-btn { display: none; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(2,12,16,.55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border-radius: 16px; width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal h2 { margin: 0 0 14px; font-size: 18px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.preview-bubble { background: var(--bubble-out); padding: 10px 12px; border-radius: 10px; white-space: pre-wrap; font-size: 14px; }
.var-row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.var-row span { width: 44px; font-weight: 700; color: var(--muted); }

/* Toasts */
#toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--navy); color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 380px; font-size: 14px; }
.toast.err { background: #991b1b; }
.toast.ok { background: var(--brand-strong); }

/* Gráfico de barras */
.chart { display: flex; align-items: flex-end; gap: 2px; height: 180px; padding: 8px 0 0; border-bottom: 1px solid var(--border); position: relative; }
.chart .bar { flex: 1; background: var(--brand); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; }
.chart .bar:hover { background: var(--brand-strong); }
.chart .bar .tip { display: none; position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; font-size: 12px; padding: 5px 8px; border-radius: 6px; white-space: nowrap; z-index: 5; pointer-events: none; }
.chart .bar:hover .tip, .chart .bar:focus .tip { display: block; }
.chart-axis { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--muted); margin-top: 4px; }

/* Responsive */
@media (max-width: 1100px) {
  .inbox { grid-template-columns: 300px 1fr; }
  .info-panel { display: none; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 82%; max-width: 300px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .layout.menu-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.45); }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--navy); color: #fff; position: sticky; top: 0; z-index: 30; }
  .topbar button { background: none; border: 0; color: #fff; font-size: 22px; cursor: pointer; }
  .topbar img { width: 28px; height: 28px; }
  .page { padding: 16px 14px 40px; }
  .grid-2 { grid-template-columns: 1fr; }
  .inbox, .inbox.no-info { grid-template-columns: 1fr; height: calc(100dvh - 52px); }
  .inbox.show-chat .conv-list { display: none; }
  .inbox:not(.show-chat) .chat { display: none; }
  .back-btn { display: inline-flex; }
  .messages { padding: 12px 10px; }
  .bubble { max-width: 86%; }
}
@media (max-width: 480px) { .grid-4 { grid-template-columns: 1fr 1fr; } .kpi .value { font-size: 22px; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
[data-theme="dark"] .avatar { background: var(--brand-strong); }
.chart .bar.zero { background: transparent; }
