:root {
  --bg: #0e110c;
  --panel: #161a13;
  --panel2: #1d2219;
  --line: #2a3125;
  --text: #e9eee2;
  --muted: #95a08b;
  --accent: #d6f25c;
  --ink: #172000;
  --ok: #7ad67a;
  --warn: #f2c35c;
  --bad: #f27a6a;
  --radius: 12px;
  font-family: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-size: 14px; }
a { color: inherit; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 18px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
code, .mono { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 12.5px; }
code { background: var(--panel2); padding: 2px 6px; border-radius: 6px; margin-left: 6px; word-break: break-all; }

.btn { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 9px; padding: 8px 14px; font: inherit; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { border-color: #46513d; }
.btn:disabled { opacity: .5; cursor: wait; }
.btn.primary { background: var(--accent); color: var(--ink); border-color: var(--accent); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 5px 10px; font-size: 12.5px; }

input, select, textarea { width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; font: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 0; border-color: transparent; }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
textarea { resize: vertical; line-height: 1.45; }

.shell { display: grid; grid-template-columns: 230px 1fr; height: 100vh; }
.nav { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 18px 12px; gap: 18px; }
.brand { display: flex; gap: 10px; align-items: center; padding: 0 6px; }
.brand small { display: block; color: var(--muted); font-size: 12px; }
.logo { background: var(--accent); color: var(--ink); font-weight: 800; border-radius: 10px; width: 36px; height: 36px; display: grid; place-items: center; }
.nav nav { display: flex; flex-direction: column; gap: 2px; }
.nav nav a { padding: 9px 12px; border-radius: 9px; text-decoration: none; color: var(--muted); display: flex; justify-content: space-between; align-items: center; }
.nav nav a:hover { background: var(--panel2); color: var(--text); }
.nav nav a.active { background: var(--panel2); color: var(--accent); font-weight: 600; }
.nav-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; color: var(--muted); font-size: 12px; padding: 0 6px; word-break: break-all; }

.view { overflow: auto; padding: 22px 26px; }
.head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.actions input { width: auto; min-width: 140px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 0 0 14px; line-height: 1.45; }
.muted { color: var(--muted); }
.loading, .empty { color: var(--muted); padding: 30px; text-align: center; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.card.error { color: var(--bad); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid2.wide-left { grid-template-columns: 1.3fr 1fr; align-items: start; }
.grid3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 16px; }
.form .field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field > span { font-size: 12.5px; color: var(--muted); }
.field .hint { margin: 0; }
.checks { display: flex; flex-direction: column; gap: 10px; margin: 6px 0 14px; }
.checks label { display: flex; gap: 8px; align-items: center; }
.copy { display: flex; gap: 8px; align-items: center; }
.copy code { margin: 0; flex: 1; padding: 9px 10px; }
.result { background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 12px; white-space: pre-wrap; margin: 12px 0 0; font-size: 12.5px; }

.pills { display: flex; gap: 8px; }
.pill { font-size: 12px; padding: 4px 10px; border-radius: 99px; background: var(--panel2); border: 1px solid var(--line); white-space: nowrap; }
.pill.ok { color: var(--ok); }
.pill.warn, .pill.pend { color: var(--warn); }
.pill.bad { color: var(--bad); }
.badge { background: var(--accent); color: var(--ink); border-radius: 99px; font-size: 11px; font-weight: 700; padding: 1px 7px; min-width: 20px; text-align: center; }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 6px; background: var(--panel2); border: 1px solid var(--line); }
.tag.warn { color: var(--warn); border-color: #5b4a1f; }

.setup { border-color: #4f5a1f; }
.checklist { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.checklist li.done { color: var(--muted); text-decoration: line-through; }
.checklist li.done::marker { content: '✓  '; color: var(--ok); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; text-decoration: none; display: flex; flex-direction: column; gap: 4px; }
.tile b { font-size: 26px; }
.tile span { color: var(--muted); font-size: 12.5px; }
.tile.warn b { color: var(--warn); }
.tile.bad b { color: var(--bad); }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 170px; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.bar i { display: block; width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.bar small, .bar .n { color: var(--muted); font-size: 11px; }
.funnel { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.funnel li { display: flex; justify-content: space-between; padding: 8px 10px; background: var(--panel2); border-radius: 8px; }
.funnel a { text-decoration: none; }

/* Conversaciones */
.view:has(.chat-layout) { padding: 0; overflow: hidden; }
.chat-layout { display: grid; grid-template-columns: 320px 1fr 290px; height: 100vh; }
.chat-col { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.chat-tools { padding: 12px; display: flex; flex-direction: column; gap: 8px; border-bottom: 1px solid var(--line); }
.chips { display: flex; gap: 6px; }
.chip { background: transparent; color: var(--muted); border: 1px solid var(--line); border-radius: 99px; padding: 4px 12px; cursor: pointer; font: inherit; font-size: 12.5px; }
.chip.on { color: var(--ink); background: var(--accent); border-color: var(--accent); }
.chat-list { overflow: auto; flex: 1; }
.chat-item { display: flex; flex-direction: column; gap: 4px; padding: 11px 14px; border-bottom: 1px solid var(--line); text-decoration: none; }
.chat-item:hover { background: var(--panel); }
.chat-item.active { background: var(--panel2); box-shadow: inset 3px 0 0 var(--accent); }
.row { display: flex; gap: 6px; align-items: center; justify-content: space-between; }
.row small { color: var(--muted); font-size: 11.5px; }
.preview { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.stage { font-size: 11px; padding: 1px 8px; border-radius: 6px; background: var(--panel2); }
.s-interesado { color: #8fd3ff; } .s-pago_por_verificar { color: var(--warn); } .s-cliente { color: var(--ok); }
.s-renovacion { color: #c9a2ff; } .s-soporte { color: #ffb08a; } .s-perdido { color: var(--muted); }

.chat-pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.pane-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--line); gap: 10px; flex-wrap: wrap; }
.pane-head small { display: block; color: var(--muted); }
.pane-head .who-head { flex: 1; }
.back { display: none; }
@media (max-width: 760px) { .back { display: inline-flex; } }
.thread { flex: 1; overflow: auto; padding: 18px; display: flex; flex-direction: column; gap: 8px; background: radial-gradient(circle at 20% 0, #151a12, var(--bg)); }
.msg { max-width: 72%; padding: 8px 12px; border-radius: 12px; background: var(--panel2); align-self: flex-start; display: flex; flex-direction: column; gap: 3px; }
.msg.out { align-self: flex-end; background: #2b3a12; }
.msg.out.agente { background: #12303a; }
.msg.out.sistema { background: #3a2f12; }
.msg .body { white-space: pre-wrap; word-wrap: break-word; line-height: 1.4; }
.msg .who { color: var(--accent); font-size: 11px; font-weight: 600; }
.msg.agente .who { color: #8fd3ff; }
.msg .meta { color: var(--muted); font-size: 10.5px; align-self: flex-end; }
.msg .err { color: var(--bad); font-size: 11.5px; }
.msg img { max-width: 260px; max-height: 320px; border-radius: 8px; display: block; }
.msg audio { width: 240px; }
.ticks.read { color: #5cc8f2; }
.ticks.failed { color: var(--bad); }
.composer { display: flex; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); align-items: flex-end; flex-wrap: wrap; }
.composer textarea { flex: 1; }
.composer > .hint { width: 100%; margin: 0; }
.composer.template { flex-direction: column; align-items: stretch; flex-wrap: nowrap; }
.composer .params { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 6px; }
.tpl-preview { white-space: pre-wrap; color: var(--muted); font-size: 12.5px; }
.chat-side { border-left: 1px solid var(--line); padding: 14px 16px; overflow: auto; }
.chat-side h3:first-child { margin-top: 0; }
.chat-side .field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.panel-box { display: grid; gap: 8px; margin-bottom: 14px; }
.sub { background: var(--panel2); border-radius: 9px; padding: 10px; display: grid; gap: 4px; }
.err { color: var(--bad); }

/* CRM */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(230px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: start; }
.col { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; min-height: 300px; display: flex; flex-direction: column; gap: 8px; }
.col.over { border-color: var(--accent); }
.col-head { display: flex; justify-content: space-between; padding: 2px 4px 6px; }
.col-head small { color: var(--muted); }
.card-item { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; text-decoration: none; display: flex; flex-direction: column; gap: 4px; cursor: grab; }
.card-item small { color: var(--muted); }

/* Tablas */
.table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { color: var(--muted); font-weight: 500; font-size: 12px; }
.table tr.off { opacity: .5; }
.table .right { text-align: right; }
.nowrap { white-space: nowrap; }
.lvl-error td { color: var(--bad); }
.lvl-warn td { color: var(--warn); }

.sim { height: 380px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 0; }
.card .composer { padding: 10px 0 0; border: 0; }
.card .composer input { flex: 1; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--accent); color: var(--ink); padding: 10px 18px; border-radius: 10px; font-weight: 600; z-index: 10; max-width: 90vw; box-shadow: 0 6px 30px #0008; }
.toast.bad { background: var(--bad); color: #2a0600; }

/* Login */
.login-page { display: grid; place-items: center; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; width: min(380px, 92vw); display: flex; flex-direction: column; gap: 14px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 12.5px; }
.login-card .brand { margin-bottom: 8px; padding: 0; }
.error { color: var(--bad); margin: 0; }

@media (max-width: 1100px) {
  .chat-layout { grid-template-columns: 280px 1fr; }
  .chat-side { display: none; }
  .grid2.wide-left { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .nav { flex-direction: row; overflow-x: auto; padding: 8px; gap: 8px; }
  .nav .brand, .nav-foot { display: none; }
  .nav nav { flex-direction: row; }
  .shell { grid-template-rows: auto 1fr; height: 100vh; }
  .chat-layout { grid-template-columns: 1fr; height: calc(100vh - 56px); }
  .chat-layout:not(.open) .chat-pane, .chat-layout.open .chat-col { display: none; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .view { padding: 14px; }
}
