:root {
  --ink: #151a16;
  --lime: #a8df2d;
  --lime-soft: #eef8d6;
  --bg: #f4f5f2;
  --panel: #ffffff;
  --line: #e3e6df;
  --muted: #6b726c;
  --out: #e9f6c9;
  --in: #ffffff;
  --danger: #c0392b;
  --warn-bg: #fff6dc;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
code { background: var(--lime-soft); padding: 1px 6px; border-radius: 6px; font-size: .85em; word-break: break-all; }
h2, h3 { margin: 0; }
.muted { color: var(--muted); font-size: .9em; }
.error { color: var(--danger); font-size: .9em; min-height: 1em; margin: 0; }
.warning { background: var(--warn-bg); border: 1px solid #f0d58a; padding: 10px 12px; border-radius: 10px; font-size: .9em; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.row.end { justify-content: flex-end; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }

.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 9px 14px; cursor: pointer; font-weight: 600; }
.btn:hover { border-color: #c9cec4; }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.primary:hover { background: #2a322b; }
.btn.small { padding: 6px 10px; font-size: .85em; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }

input, select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--lime); outline-offset: -1px; border-color: transparent; }
.form { display: grid; gap: 12px; padding: 20px; }
.form label { display: grid; gap: 4px; font-size: .9em; font-weight: 600; }
.form label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.form label.check input { width: auto; }
.center { text-align: center; justify-items: center; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); display: grid; gap: 14px; padding: 28px; }
.login-logo { height: 40px; justify-self: start; }
.login-card label { display: grid; gap: 4px; font-size: .9em; font-weight: 600; }

/* Layout */
.app { display: flex; height: 100vh; height: 100dvh; }
.rail { width: 76px; background: var(--ink); display: flex; flex-direction: column; align-items: center; padding: 14px 0; gap: 6px; }
.rail-logo { width: 34px; margin-bottom: 14px; }
.rail-btn[hidden] { display: none; }
.rail-btn { width: 62px; border: 0; background: transparent; color: #c5cbc4; border-radius: 10px; padding: 8px 0; cursor: pointer; display: grid; gap: 2px; font-size: 1.2em; }
.rail-btn span { font-size: .55em; }
.rail-btn:hover { background: #242b25; }
.rail-btn.active { background: var(--lime); color: var(--ink); }
.rail-spacer { flex: 1; }
.view { flex: 1; min-width: 0; }

/* Inbox */
.inbox { display: flex; height: 100%; }
.conv-col { width: 340px; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.conv-head { padding: 16px; display: grid; gap: 10px; border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 6px; align-items: center; }
.tab { border: 0; background: transparent; padding: 6px 10px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--muted); }
.tab.active { background: var(--lime-soft); color: var(--ink); }
.mine { margin-left: auto; font-size: .85em; display: flex; gap: 4px; align-items: center; }
.mine input { width: auto; }
.conv-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.conv { padding: 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer; display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; align-items: center; }
.conv:hover { background: #fafbf8; }
.conv.active { background: var(--lime-soft); }
.avatar { width: 40px; height: 40px; border-radius: 12px; background: var(--ink); color: var(--lime); display: grid; place-items: center; font-weight: 700; }
.avatar.has-img { background: #eef0eb; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.chat-avatar { width: 36px; height: 36px; border-radius: 10px; font-size: .85em; flex: none; }
.avatar.small { width: 24px; height: 24px; border-radius: 7px; font-size: .6em; flex: none; }
.k-who { display: flex; align-items: center; gap: 6px; min-width: 0; }
.conv-main { min-width: 0; }
.conv-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-prev { color: var(--muted); font-size: .88em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-meta { display: grid; justify-items: end; gap: 4px; font-size: .75em; color: var(--muted); }
.badge { background: var(--lime); color: var(--ink); border-radius: 999px; padding: 1px 7px; font-weight: 700; }
.tag { font-size: .72em; background: #eef0eb; border-radius: 6px; padding: 1px 6px; color: var(--muted); }
.list-empty { padding: 30px 16px; text-align: center; color: var(--muted); }

.chat { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }
.chat-empty { margin: auto; text-align: center; color: var(--muted); }
.chat-empty img { width: 56px; opacity: .25; }
.chat-inner { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-head { background: var(--panel); border-bottom: 1px solid var(--line); padding: 10px 16px; display: flex; align-items: center; gap: 10px; }
.chat-title { flex: 1; min-width: 0; display: grid; }
.chat-title strong { cursor: pointer; }
.chat-head select { width: auto; max-width: 170px; }
.back { display: none; }
.messages { flex: 1; overflow-y: auto; padding: 18px 6%; display: flex; flex-direction: column; gap: 6px; }
.day { align-self: center; font-size: .75em; color: var(--muted); background: #e8ebe4; padding: 3px 10px; border-radius: 999px; margin: 8px 0; }
.msg { max-width: min(560px, 80%); padding: 8px 11px 6px; border-radius: 12px; background: var(--in); border: 1px solid var(--line); white-space: pre-wrap; word-wrap: break-word; }
.msg.out { align-self: flex-end; background: var(--out); border-color: #d6ebab; }
.msg-meta { font-size: .7em; color: var(--muted); text-align: right; margin-top: 3px; }
.msg-media { font-style: italic; color: var(--muted); }
.msg.sticker { background: transparent; border: 0; padding: 0; }
.msg-img { display: block; max-width: 100%; max-height: 320px; border-radius: 8px; cursor: zoom-in; margin-bottom: 4px; background: #eef0eb; min-width: 120px; min-height: 80px; object-fit: cover; }
.msg.sticker .msg-img { width: 140px; height: 140px; min-width: 0; object-fit: contain; background: transparent; cursor: default; }
.msg-video { display: block; max-width: 100%; max-height: 320px; border-radius: 8px; margin-bottom: 4px; }
.msg-audio { display: block; width: 260px; max-width: 100%; margin-bottom: 2px; }
.msg-doc { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: rgba(0,0,0,.04); border-radius: 8px; color: inherit; text-decoration: none; margin-bottom: 4px; font-weight: 600; word-break: break-all; }
.msg-err { font-size: .85em; color: var(--muted); font-style: italic; }
.attach { font-size: 1.2em; padding: 8px 10px; cursor: pointer; }
.attach.busy { opacity: .4; pointer-events: none; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: grid; place-items: center; z-index: 50; cursor: zoom-out; }
.lightbox img { max-width: 94vw; max-height: 94vh; }
.import-status { font-size: .85em; color: var(--muted); }
.composer { display: flex; gap: 8px; padding: 12px 16px; background: var(--panel); border-top: 1px solid var(--line); align-items: flex-end; }
.composer textarea { resize: none; max-height: 160px; }

/* Pages */
.page { padding: 28px; overflow-y: auto; display: grid; gap: 16px; align-content: start; max-width: 860px; }
.lines { display: grid; gap: 12px; }
.line { padding: 16px; display: grid; gap: 10px; }
.line-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { font-size: .75em; font-weight: 700; border-radius: 999px; padding: 2px 9px; }
.pill.open { background: var(--lime); }
.pill.connecting { background: #ffe9a8; }
.pill.close { background: #f3d6d2; color: #8a2a1f; }
.users { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.users li { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; display: flex; justify-content: space-between; }

dialog { border: 0; border-radius: 16px; padding: 0; width: min(440px, calc(100% - 32px)); }
dialog::backdrop { background: rgba(21, 26, 22, .45); }
.qr { width: 260px; height: 260px; background: #fff; }

/* Departamentos, etiquetas, ficha */
.filters { display: flex; gap: 6px; }
.filters select { font-size: .85em; padding: 6px 8px; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: .72em; font-weight: 600; border-radius: 999px; padding: 2px 8px; color: #fff; white-space: nowrap; }
.chip.soft { background: #eef0eb; color: var(--ink); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.conv-chips { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.chat-tags { display: flex; gap: 6px; flex-wrap: wrap; padding: 6px 16px; background: var(--panel); border-bottom: 1px solid var(--line); min-height: 0; }
.chat-tags:empty { display: none; }
.panel { width: 300px; background: var(--panel); border-left: 1px solid var(--line); padding: 16px; overflow-y: auto; display: grid; gap: 12px; align-content: start; }
.panel label { display: grid; gap: 4px; font-size: .85em; font-weight: 600; }
.panel-label { font-size: .85em; font-weight: 600; margin-bottom: 6px; }
.p-fields { display: grid; gap: 10px; }
.tag-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-opt { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 3px 10px; font-size: .78em; cursor: pointer; display: inline-flex; align-items: center; gap: 5px; }
.tag-opt.on { color: #fff; border-color: transparent; }
.small-note { font-size: .75em; min-height: 1em; margin: 0; }

/* Respuestas rápidas */
.qr-popup { margin: 0 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.08); max-height: 240px; overflow-y: auto; }
.qr-item { padding: 8px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.qr-item:last-child { border-bottom: 0; }
.qr-item.sel, .qr-item:hover { background: var(--lime-soft); }
.qr-item strong { font-size: .85em; }
.qr-item div { font-size: .8em; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Kanban */
.kanban-view { display: flex; flex-direction: column; min-height: 0; height: 100%; }
.kanban-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; flex-wrap: wrap; }
.kanban-head select { width: auto; }
.kanban { flex: 1; display: flex; gap: 12px; overflow-x: auto; padding: 0 20px 20px; min-height: 0; }
.k-col { flex: 0 0 270px; background: #eceee9; border-radius: 12px; display: flex; flex-direction: column; min-height: 0; }
.k-col.over { outline: 2px dashed var(--lime); }
.k-col-head { padding: 10px 12px; font-weight: 700; display: flex; align-items: center; gap: 8px; font-size: .9em; }
.k-col-head .count { margin-left: auto; color: var(--muted); font-weight: 600; }
.k-cards { flex: 1; overflow-y: auto; padding: 0 8px 8px; display: grid; gap: 8px; align-content: start; }
.k-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px; cursor: grab; display: grid; gap: 4px; }
.k-card:active { cursor: grabbing; }
.k-card .conv-prev { font-size: .82em; }
.k-card.dragging { opacity: .4; }

/* Configuración */
.settings { max-width: 980px; }
.templates { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.tpl { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: #fff; cursor: pointer; text-align: left; display: grid; gap: 4px; }
.tpl:hover { border-color: var(--ink); }
.tpl.current { border-color: var(--lime); box-shadow: 0 0 0 2px var(--lime) inset; }
.tpl .ico { font-size: 1.6em; }
.tpl p { margin: 0; font-size: .8em; color: var(--muted); }
.editor { margin-top: 16px; }
.editor table { width: 100%; border-collapse: collapse; font-size: .9em; }
.editor th { text-align: left; font-size: .78em; color: var(--muted); font-weight: 600; padding: 4px 6px; }
.editor td { padding: 4px 6px; vertical-align: top; }
.editor td input, .editor td select, .editor td textarea { padding: 6px 8px; }
.editor td input[type=color] { width: 44px; height: 34px; padding: 2px; }
.editor td.act { width: 1%; white-space: nowrap; }
.editor .hint { font-size: .8em; color: var(--muted); margin: 4px 0 8px; }

/* Productos del ERP */
.product-popup { max-height: 360px; display: flex; flex-direction: column; }
.product-search { display: flex; gap: 6px; padding: 8px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
#product-results { overflow-y: auto; }
.prod { display: grid; grid-template-columns: 44px 1fr auto; gap: 10px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.prod:hover { background: var(--lime-soft); }
.prod img, .prod .noimg { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: #eef0eb; display: grid; place-items: center; }
.prod-name { font-weight: 600; font-size: .88em; }
.prod-meta { font-size: .76em; color: var(--muted); }
.prod-price { text-align: right; font-weight: 700; font-size: .9em; }
.prod-price .out { color: var(--danger); font-size: .75em; font-weight: 600; display: block; }
.integration { display: grid; gap: 10px; border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.integration .row { flex-wrap: wrap; }

/* Horario y asistente */
.schedule { display: grid; gap: 6px; }
.sched-row { display: grid; grid-template-columns: 110px auto auto auto; gap: 8px; align-items: center; font-size: .9em; }
.sched-row input[type=time] { width: auto; padding: 5px 8px; }
.sched-row label { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.sched-row label input { width: auto; }
#suggest-btn.busy { animation: pulse 1s infinite; pointer-events: none; }
@keyframes pulse { 50% { opacity: .35; } }
.composer textarea.ai-draft { outline: 2px solid #c9b6f2; }

/* Canales Meta */
.window-warn { margin: 0 16px 6px; padding: 8px 12px; font-size: .82em; background: var(--warn-bg); border: 1px solid #f0d58a; border-radius: 10px; }
.meta-admin { display: grid; gap: 6px; font-size: .9em; }

/* Equipo y asignación */
.users li.user-row { display: grid; gap: 8px; }
.users li.inactive { opacity: .55; }
.user-assign { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; font-size: .85em; }
.user-assign label.check { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.user-assign input { width: auto; }

/* Bot */
.bot-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 16px; font-size: .85em; border-bottom: 1px solid var(--line); background: #f1ecfb; }
.bot-bar.human { background: #fff1e8; }
.bot-bar.paused { background: #eef0eb; }
.bot-bar .grow { flex: 1; min-width: 180px; }
.chip.human { background: #f08a3c; }
.bot-settings { border-top: 1px solid var(--line); padding-top: 12px; display: grid; gap: 10px; }
.bot-settings h4 { margin: 0; }

/* Administración */
.admin-table-wrap { overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; font-size: .9em; }
.admin-table th { text-align: left; font-size: .78em; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.admin-table td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.admin-table select { width: auto; padding: 5px 8px; font-size: .9em; }
.admin-table .ws-name { font-weight: 700; }
.admin-table tr.suspended td { opacity: .55; }
.admin-table tr.home .ws-name::after { content: ' (tú)'; color: var(--muted); font-weight: 400; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.created { background: var(--lime-soft); border: 1px solid #cfe9a0; border-radius: 10px; padding: 12px; font-size: .9em; }
.created code { background: #fff; }
.acting-banner { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 40; background: var(--ink); color: #fff; border-radius: 999px; padding: 6px 8px 6px 16px; display: flex; gap: 12px; align-items: center; box-shadow: 0 6px 20px rgba(0,0,0,.2); font-size: .9em; }
.acting-banner .btn { background: var(--lime); border-color: var(--lime); color: var(--ink); }

/* Móvil */
@media (max-width: 760px) {
  .app { flex-direction: column-reverse; }
  .rail { width: 100%; flex-direction: row; justify-content: space-around; padding: 6px 4px; }
  .rail-logo, .rail-spacer { display: none; }
  .rail-btn { width: auto; flex: 1; }
  .view { min-height: 0; }
  .conv-col { width: 100%; border-right: 0; }
  .chat { display: none; }
  .inbox.chat-open .conv-col { display: none; }
  .inbox.chat-open .chat { display: flex; }
  .back { display: inline-block; }
  .chat-head { padding: 8px; gap: 6px; }
  .chat-head select { max-width: 110px; }
  .messages { padding: 12px; }
  .page { padding: 16px; }
  .panel { position: fixed; inset: 0 0 56px 0; width: auto; z-index: 20; border-left: 0; }
  .kanban { padding: 0 12px 12px; }
  .k-col { flex-basis: 82vw; }
  .editor table, .editor tbody, .editor tr, .editor td { display: block; width: 100%; }
  .editor thead { display: none; }
  .editor tr { border-bottom: 1px solid var(--line); padding: 8px 0; }
}
