:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #1b2330;
  --muted: #667085;
  --blue: #1f4fa3;
  --blue-soft: #e6eefb;
  --red: #c8202f;
  --red-soft: #fbe9eb;
  --green: #1d7a4a;
  --green-soft: #e3f4ea;
  --amber: #a15c00;
  --amber-soft: #fdf1dc;
  --violet: #6a3fb5;
  --violet-soft: #efe8fa;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161d; --surface: #1a2029; --surface-2: #222a35; --border: #2e3744;
    --text: #e6e9ee; --muted: #98a2b3;
    --blue: #7aa7ff; --blue-soft: #1d2c47; --red: #ff6b78; --red-soft: #3a1d22;
    --green: #5fd197; --green-soft: #173327; --amber: #f2b45a; --amber-soft: #3a2b14;
    --violet: #b79bff; --violet-soft: #2a2140;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); font-size: 14px; line-height: 1.45; }
a { color: var(--blue); }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Encabezado */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 24px; padding: 0 20px; height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand .dot { width: 12px; height: 12px; border-radius: 50%; background: linear-gradient(135deg, var(--red) 50%, var(--blue) 50%); }
#tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
#tabs a { text-decoration: none; color: var(--muted); padding: 8px 12px; border-radius: 8px; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
#tabs a.active { background: var(--blue-soft); color: var(--blue); font-weight: 600; }
.badge { background: var(--red); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 7px; font-weight: 700; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status-dot.ok { background: var(--green); } .status-dot.warn { background: var(--amber); }

main { padding: 16px 20px 40px; max-width: 1500px; margin: 0 auto; }
.view { display: none; } .view.active { display: block; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.toolbar input[type=search] { flex: 1; min-width: 200px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; }
textarea { width: 100%; resize: vertical; }
.check { display: inline-flex; gap: 6px; align-items: center; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 5px 12px; cursor: pointer; font: inherit; color: var(--text); }
.chip.on { background: var(--text); color: var(--surface); border-color: var(--text); }

.btn { font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px; padding: 7px 14px; cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--red); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }

.stats { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 10px; color: var(--muted); }
.stats b { color: var(--text); }

/* Tabla */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow); }
table.list { width: 100%; border-collapse: collapse; }
.list th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--border); }
.list td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.list tr:last-child td { border-bottom: 0; }
.list tbody tr { cursor: pointer; } .list tbody tr:hover { background: var(--surface-2); }
.list .who b { display: block; } .list .who span { color: var(--muted); font-size: 12px; }
.list .sum { max-width: 420px; color: var(--muted); }
.chat-log { display: flex; flex-direction: column; gap: 10px; margin: 12px 0; }
.chat-log:empty { display: none; }
.bubble { padding: 10px 12px; border-radius: 12px; max-width: 760px; }
.bubble.user { align-self: flex-end; background: var(--blue); color: #fff; }
.bubble.bot { align-self: flex-start; background: var(--surface-2); }
.bubble.bot .filters { margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; }
.chat-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.chat-cards .card { cursor: pointer; margin: 0; }
.chat-cards .card .frag { margin-top: 6px; font-size: 12px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.chat-form { display: flex; gap: 8px; margin-top: 10px; }
.chat-form input { flex: 1; }
mark { background: var(--amber-soft); color: inherit; padding: 0 2px; border-radius: 3px; }
.list .frag { max-width: 460px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 30px; }

.tag { display: inline-block; border-radius: 6px; padding: 2px 8px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.tag.busqueda { background: var(--blue-soft); color: var(--blue); }
.tag.venta { background: var(--red-soft); color: var(--red); }
.tag.alquiler { background: var(--violet-soft); color: var(--violet); }
.tag.temporal { background: var(--green-soft); color: var(--green); }
.tag.otro, .tag.none { background: var(--surface-2); color: var(--muted); }
.tag.stage { background: var(--surface-2); color: var(--text); font-weight: 500; }
.tag.warn { background: var(--amber-soft); color: var(--amber); }
.tag.ok { background: var(--green-soft); color: var(--green); }
.ch { font-size: 11px; color: var(--muted); }

/* Tablero */
.board { display: grid; grid-template-columns: repeat(6, minmax(220px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.col { background: var(--surface-2); border-radius: var(--radius); padding: 10px; min-height: 300px; }
.col h3 { margin: 0 0 10px; font-size: 13px; display: flex; justify-content: space-between; }
.col.over { outline: 2px dashed var(--blue); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin-bottom: 8px; cursor: grab; box-shadow: var(--shadow); }
.card b { display: block; margin-bottom: 4px; }
.card p { margin: 6px 0 0; font-size: 12px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* Tarjetas genéricas */
.cards { display: grid; gap: 10px; }
.item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.item-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.item-head .spacer, .actions .spacer { flex: 1; }
.item pre { white-space: pre-wrap; font: inherit; margin: 0; }
.actions { display: flex; gap: 8px; align-items: center; margin-top: 10px; flex-wrap: wrap; }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 14px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.panel h3 { margin: 0 0 6px; }
.panel img.qr { display: block; margin: 12px 0; background: #fff; padding: 8px; border-radius: 8px; }
.notice { background: var(--amber-soft); color: var(--amber); border-radius: 8px; padding: 10px 12px; margin: 10px 0; font-size: 13px; }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; }
.switch input { width: 40px; height: 22px; appearance: none; background: var(--border); border-radius: 999px; position: relative; cursor: pointer; border: 0; padding: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .15s; }
.switch input:checked { background: var(--green); } .switch input:checked::after { left: 21px; }

/* Ficha */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(620px, 100vw); background: var(--surface); z-index: 20; display: flex; flex-direction: column; box-shadow: -8px 0 30px rgba(0,0,0,.15); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { margin: 0; font-size: 18px; }
.drawer-body { overflow-y: auto; padding: 16px 18px 30px; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.25); z-index: 15; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.fields label, .form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.fields input, .fields select { color: var(--text); }
.sumbox { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; margin: 10px 0; }
.sumbox dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 8px 0 0; font-size: 13px; }
.sumbox dt { color: var(--muted); }
.thread { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.msg { max-width: 85%; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); white-space: pre-wrap; word-wrap: break-word; }
.msg.out { align-self: flex-end; background: var(--blue-soft); }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 4px; }
.pair-code { font: 600 32px/1.2 ui-monospace, Consolas, monospace; letter-spacing: .12em; margin: 8px 0 12px; }
.msg .subj { font-weight: 600; font-size: 12px; }
.msg .media { display: block; max-width: 100%; border-radius: 8px; margin-bottom: 4px; }
.msg img.media { max-height: 320px; width: auto; background: var(--surface); }
.msg img.media.sticker { max-height: 140px; background: none; }
.msg audio.media { width: 280px; max-width: 100%; }
.msg video.media { max-height: 360px; }
.msg .media-doc { display: inline-block; margin-bottom: 4px; }
.msg .media-err { display: block; font-size: 12px; color: var(--muted); font-style: italic; }
h4 { margin: 18px 0 6px; }

dialog { border: 0; border-radius: 14px; padding: 0; width: min(640px, 94vw); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.35); }
.form { padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.form h3 { margin: 0; }
.form .row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.form .row > label { flex: 1; min-width: 140px; }
.form label.check { flex-direction: row; color: var(--text); font-size: 14px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 8px; z-index: 50; }

/* Ingreso */
body.login { display: grid; place-items: center; min-height: 100vh; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; width: min(360px, 92vw); display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow); }
.login-card label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 13px; }
.login-card p { margin: 0; }
.error { color: var(--red); }

@media (max-width: 700px) {
  .top { gap: 10px; padding: 0 12px; } .brand { display: none; }
  main { padding: 12px; }
  .fields { grid-template-columns: 1fr; }
  .list .sum, .list th:nth-child(4), .list td:nth-child(4) { display: none; }
}
