:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1b2430;
  --muted: #5f6b7a;
  --line: #dde2e8;
  --brand: #0f5d63;
  --brand-ink: #ffffff;
  --accent: #b3541e;
  --ok: #1f7a44;
  --warn: #8a5a00;
  --bad: #a32b2b;
  --radius: 10px;
  --gap: 16px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.45;
}

a { color: var(--brand); }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.2; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
p { margin: 0 0 8px; }

.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }

.sidebar { background: #10222b; color: #cfe0e3; padding: 18px 14px; }
.sidebar .brand { font-weight: 700; font-size: 18px; letter-spacing: .08em; color: #fff; margin-bottom: 4px; }
.sidebar .brand small { display: block; font-weight: 400; font-size: 11px; letter-spacing: .02em; color: #8fb0b6; }
.sidebar nav { margin-top: 18px; display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a { color: #cfe0e3; text-decoration: none; padding: 8px 10px; border-radius: 8px; font-size: 13px; }
.sidebar nav a:hover { background: #1b3641; }
.sidebar nav a.active { background: #1f4a56; color: #fff; }
.sidebar .foot { margin-top: 24px; font-size: 11px; color: #7f9aa1; }

.main { min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 22px; background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar .who { font-size: 12px; color: var(--muted); }
.content { padding: 20px 22px 40px; max-width: 1280px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: var(--gap); }
.card > h2 { margin-bottom: 10px; }
.grid { display: grid; gap: var(--gap); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; margin-top: 6px; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
}

.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi .n { font-size: 22px; font-weight: 700; }
.kpi .l { font-size: 12px; color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--line); padding: 8px 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
td { padding: 8px; border-bottom: 1px solid #eef1f4; vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

form .row { display: grid; gap: 12px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
form .row.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; color: var(--ink); background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #9ec6c9; border-color: var(--brand); }
textarea { min-height: 70px; resize: vertical; }
.field { margin-bottom: 10px; }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

button, .btn {
  display: inline-block; border: 1px solid var(--brand); background: var(--brand); color: var(--brand-ink);
  padding: 8px 14px; border-radius: 8px; font: inherit; cursor: pointer; text-decoration: none;
}
button:hover, .btn:hover { filter: brightness(1.08); }
.btn.secondary, button.secondary { background: #fff; color: var(--brand); }
.btn.ghost, button.ghost { background: transparent; border-color: var(--line); color: var(--muted); }
button.link { background: none; border: 0; color: var(--brand); padding: 0; cursor: pointer; text-decoration: underline; }
button[disabled] { opacity: .5; cursor: not-allowed; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; border: 1px solid; background: #fff; white-space: nowrap; }
.badge.ok { color: var(--ok); border-color: #b6dcc4; background: #eef8f1; }
.badge.warn { color: var(--warn); border-color: #ecd7a8; background: #fdf7e8; }
.badge.bad { color: var(--bad); border-color: #e8bcbc; background: #fbeeee; }
.badge.neutral { color: var(--muted); border-color: var(--line); background: #f7f8fa; }

.flash { border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; border: 1px solid; }
.flash.ok { background: #eef8f1; border-color: #b6dcc4; color: #14532d; }
.flash.bad { background: #fbeeee; border-color: #e8bcbc; color: #7f1d1d; }
.errors { background: #fbeeee; border: 1px solid #e8bcbc; color: #7f1d1d; border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; }
.errors ul { margin: 0; padding-left: 18px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12px; }
.nowrap { white-space: nowrap; }
.stack > * + * { margin-top: 10px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 8px 12px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; font-size: 13px; }
.tabs a.active { color: var(--ink); border-bottom-color: var(--brand); font-weight: 600; }
.day { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; background: #fcfcfd; }
.day h3 { text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--ink); }
.item { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px dashed var(--line); }
.item:first-of-type { border-top: 0; }
.msg { max-width: 78%; padding: 8px 12px; border-radius: 12px; margin-bottom: 8px; white-space: pre-wrap; }
.msg.in { background: #eef1f4; }
.msg.out { background: #e2f2f3; margin-left: auto; }
.msg .meta { font-size: 10px; color: var(--muted); margin-top: 4px; }
.chat { max-height: 520px; overflow-y: auto; padding: 6px 2px; }
.trace { font-size: 12px; }
.trace td { padding: 6px 8px; }
.notice { border-left: 3px solid var(--brand); background: #f2f8f8; padding: 10px 12px; border-radius: 0 8px 8px 0; }
.notice.warn { border-color: var(--warn); background: #fdf7e8; }
.notice.bad { border-color: var(--bad); background: #fbeeee; }

/* ---------- Bandeja y chat ---------- */
.inbox-shell { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .inbox-shell { grid-template-columns: 1fr; } }

.chat-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; display: flex; flex-direction: column; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); background: #fbfcfd; }
.avatar { width: 42px; height: 42px; border-radius: 50%; background: #dcecee; color: var(--brand); display: grid; place-items: center; font-weight: 700; font-size: 15px; flex: 0 0 auto; }
.chat-head .who { min-width: 0; }
.chat-head .name { font-weight: 700; font-size: 15px; }
.chat-head .sub { font-size: 12px; color: var(--muted); }
.chat-head .spacer { flex: 1; }

.chat-body { padding: 16px; background: #f7f9fa; min-height: 420px; max-height: 58vh; overflow-y: auto; }
.chat-day { text-align: center; font-size: 11px; color: var(--muted); margin: 14px 0 10px; }
.chat-day span { background: #e9eef1; border-radius: 999px; padding: 3px 10px; }

.bubble { position: relative; max-width: 76%; padding: 9px 12px 20px; border-radius: 14px; margin-bottom: 10px; font-size: 14px; line-height: 1.45; box-shadow: 0 1px 1px rgba(16,34,43,.05); white-space: pre-wrap; word-wrap: break-word; }
.bubble.in { background: #fff; border: 1px solid var(--line); border-top-left-radius: 4px; }
.bubble.out { background: #dcf3ef; border: 1px solid #bfe6df; margin-left: auto; border-top-right-radius: 4px; }
.bubble .meta { position: absolute; right: 10px; bottom: 5px; font-size: 10px; color: #6b7a86; display: flex; gap: 5px; align-items: center; }
.bubble .author { font-size: 10px; font-weight: 700; color: var(--brand); margin-bottom: 3px; text-transform: uppercase; letter-spacing: .04em; }
.bubble.failed { border-color: #e0a8a8; background: #fdeeee; }
.tick { font-size: 11px; }
.tick.read { color: #1f7a44; }
.tick.failed { color: var(--bad); }

.composer { border-top: 1px solid var(--line); padding: 12px 14px; background: #fff; }
.composer textarea { min-height: 64px; resize: vertical; }
.composer .tools { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.chip { border: 1px dashed var(--line); background: #fbfcfd; border-radius: 999px; padding: 4px 10px; font-size: 12px; cursor: pointer; color: var(--muted); }
.chip:hover { border-color: var(--brand); color: var(--brand); }

.inbox-filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.inbox-filters a { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 12px; font-size: 12px; text-decoration: none; color: var(--muted); }
.inbox-filters a.active { border-color: var(--brand); color: var(--brand); font-weight: 600; }
.conv-row { display: flex; gap: 10px; padding: 10px 8px; border-bottom: 1px solid #eef1f4; text-decoration: none; color: inherit; }
.conv-row:hover { background: #f7fafb; }
.conv-row .body { min-width: 0; flex: 1; }
.conv-row .prev { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-row .when { font-size: 11px; color: var(--muted); white-space: nowrap; }
.unread { background: var(--brand); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; }
.side-block { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 14px; }
.side-block h3 { margin-bottom: 8px; }
.kv { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; padding: 3px 0; }
.kv .k { color: var(--muted); }
.trace-list { font-size: 11px; color: var(--muted); max-height: 220px; overflow-y: auto; }
.trace-list li { margin-bottom: 4px; }
@media (max-width: 640px) {
  .bubble { max-width: 88%; }
  .chat-body { max-height: 50vh; }
}

.bubble { text-align: left; }
.bubble.out { text-align: left; }


/* pre-line conserva los saltos del mensaje pero no la indentación de la plantilla */
.bubble { white-space: pre-line; }


/* ---------- Bandeja comercial ---------- */
.kpi-strip { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 10px; margin-bottom: 12px; }
.kpi-strip .k { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; display: flex; align-items: center; gap: 10px; }
.kpi-strip .k strong { font-size: 20px; }
.kpi-strip .k span { font-size: 12px; color: var(--muted); }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.tabs a { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 6px 12px; font-size: 13px; color: var(--muted); text-decoration: none; }
.tabs a.active { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.tabs a .n { font-size: 11px; opacity: .8; margin-left: 4px; }
.label-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.label-row a { font-size: 11px; border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px; text-decoration: none; color: var(--muted); background: #fff; text-transform: uppercase; letter-spacing: .03em; }
.label-row a.active { background: #eef6f7; border-color: var(--brand); color: var(--brand); }
.list-row { display: flex; gap: 10px; padding: 10px 12px; border-bottom: 1px solid #eef1f4; text-decoration: none; color: inherit; align-items: flex-start; }
.list-row:hover { background: #f7fafb; }
.list-row.unread { background: #f2f9f8; }
.list-row .main { flex: 1; min-width: 0; }
.list-row .top { display: flex; justify-content: space-between; gap: 8px; }
.list-row .name { font-weight: 700; font-size: 14px; }
.list-row .when { font-size: 11px; color: var(--muted); white-space: nowrap; }
.list-row .prev { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 5px; }
.tag { font-size: 10px; border-radius: 4px; padding: 1px 6px; background: #eef1f4; color: #4b5a66; text-transform: uppercase; letter-spacing: .03em; }
.tag.brand { background: #e2f1f0; color: var(--brand); }
.tag.warn { background: #fdf3e2; color: #8a5a00; }
.tag.bad { background: #fdecec; color: #a03030; }
.msg-quote { border-left: 3px solid #b9d9d4; padding: 4px 8px; margin-bottom: 5px; font-size: 12px; color: #4b5a66; background: #f6fbfa; border-radius: 0 6px 6px 0; }
.window-chip { font-size: 11px; border-radius: 999px; padding: 3px 9px; background: #eef6f7; color: var(--brand); }
.window-chip.closed { background: #fdecec; color: #a03030; }
.stage-form select { padding: 5px 8px; font-size: 12px; }
.note { border-left: 3px solid #d6e3e8; padding: 6px 10px; margin-bottom: 8px; background: #fafcfd; border-radius: 0 6px 6px 0; }
.note .who { font-size: 11px; color: var(--muted); }
@media (max-width: 900px) { .kpi-strip { grid-template-columns: repeat(2, minmax(0,1fr)); } }

/* ---------- WhatsApp Web: lista | chat | ficha ---------- */
.wa-shell { display: grid; grid-template-columns: 330px minmax(0, 1fr) 320px; gap: 12px; align-items: stretch; }
.wa-shell.two { grid-template-columns: 330px minmax(0, 1fr); }
.wa-col { background: #fff; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.wa-list { overflow-y: auto; max-height: calc(100vh - 210px); }
.wa-chat { display: flex; flex-direction: column; min-height: 0; }
.wa-chat .chat-body { flex: 1; max-height: none; overflow-y: auto; }
.wa-panel { overflow-y: auto; max-height: calc(100vh - 210px); padding: 12px; }
.wa-head { padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fbfcfd; }
.wa-head .t { font-weight: 700; font-size: 14px; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }
.wa-head input { font-size: 12px; padding: 7px 10px; }
.wa-tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 8px; }
.wa-tabs a { font-size: 11px; border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px; text-decoration: none; color: var(--muted); background: #fff; }
.wa-tabs a.active { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.wa-row { display: flex; gap: 9px; padding: 9px 12px; border-bottom: 1px solid #f0f3f5; text-decoration: none; color: inherit; }
.wa-row:hover { background: #f7fafb; }
.wa-row.active { background: #eaf4f3; border-left: 3px solid var(--brand); }
.wa-row .av { width: 38px; height: 38px; border-radius: 50%; background: #dcecee; color: var(--brand); display: grid; place-items: center; font-weight: 700; font-size: 12px; flex: 0 0 auto; }
.wa-row .c { flex: 1; min-width: 0; }
.wa-row .n { display: flex; justify-content: space-between; gap: 6px; font-size: 13px; font-weight: 600; }
.wa-row .p { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wa-row .m { font-size: 10px; color: var(--muted); margin-top: 3px; display: flex; gap: 5px; flex-wrap: wrap; align-items: center; }
.wa-empty { display: grid; place-items: center; text-align: center; color: var(--muted); padding: 40px; }
.wa-empty h2 { color: var(--ink); margin-bottom: 6px; }
@media (max-width: 1200px) { .wa-shell { grid-template-columns: 300px minmax(0, 1fr); } .wa-panel { display: none; } }
@media (max-width: 760px) { .wa-shell, .wa-shell.two { grid-template-columns: 1fr; } .wa-list { max-height: 40vh; } }

/* ---------- Pantalla completa tipo WhatsApp Web ---------- */
.wa-page { height: calc(100vh - 96px); display: flex; flex-direction: column; min-height: 0; }
.wa-page .wa-shell { flex: 1; min-height: 0; align-items: stretch; }
.wa-page .wa-col { height: 100%; min-height: 0; }
.wa-page .wa-list { flex: 1; min-height: 0; max-height: none; }
.wa-page .wa-chat { display: flex; flex-direction: column; min-height: 0; height: 100%; }
.wa-page .chat-body { flex: 1; min-height: 0; max-height: none; overflow-y: auto; }
.wa-page .composer { flex: 0 0 auto; }
.wa-page .wa-panel { height: 100%; max-height: none; overflow-y: auto; }
.wa-page .wa-empty { height: 100%; }
.wa-page { overflow: hidden; }

/* La bandeja usa todo el ancho disponible */
.wa-wide .content { max-width: none; }

