@font-face { font-family: 'Quicksand'; src: url('fonts/quicksand-latin.woff2') format('woff2'); font-weight: 300 700; font-style: normal; font-display: swap; }
button, input, select, textarea { font-family: inherit; }
:root {
  --bg: #F3F1FC;
  --surface: #FFFFFF;
  --surface-2: #ECE8FB;
  --surface-3: #E2DCF7;
  --border: #DCD5F1;
  --text: #221C36;
  --text-muted: #6E6690;
  --accent: #6C4FE0;
  --accent-strong: #5638D1;
  --accent-soft: #EDE8FC;
  --on-accent: #FFFFFF;
  --bubble-in-bg: #FFFFFF;
  --bubble-in-text: #221C36;
  --bubble-out-bg: #6C4FE0;
  --bubble-out-text: #FFFFFF;
  --success: #1F9D6E;
  --danger: #D0475C;
  --shadow: 0 1px 2px rgba(34, 28, 54, 0.06), 0 8px 24px -12px rgba(34, 28, 54, 0.22);
  --radius-s: 8px;
  --radius-m: 14px;
  --radius-l: 20px;
  --font-display: 'Quicksand', ui-sans-serif, system-ui, sans-serif;
  --font-body: 'Quicksand', ui-sans-serif, system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151027; --surface: #1C1733; --surface-2: #251F42; --surface-3: #2E2650;
    --border: #362D57; --text: #EFEBFA; --text-muted: #A79FC7;
    --accent: #9A85F5; --accent-strong: #B29EFF; --accent-soft: #2C2450; --on-accent: #181233;
    --bubble-in-bg: #251F42; --bubble-in-text: #EFEBFA; --bubble-out-bg: #6C4FE0; --bubble-out-text: #FFFFFF;
    --success: #3FD08C; --danger: #FF6B81;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 12px 28px -14px rgba(0,0,0,.6);
  }
}
:root[data-theme="dark"] {
  --bg: #151027; --surface: #1C1733; --surface-2: #251F42; --surface-3: #2E2650;
  --border: #362D57; --text: #EFEBFA; --text-muted: #A79FC7;
  --accent: #9A85F5; --accent-strong: #B29EFF; --accent-soft: #2C2450; --on-accent: #181233;
  --bubble-in-bg: #251F42; --bubble-in-text: #EFEBFA; --bubble-out-bg: #6C4FE0; --bubble-out-text: #FFFFFF;
  --success: #3FD08C; --danger: #FF6B81;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 12px 28px -14px rgba(0,0,0,.6);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text); font-family: var(--font-body); overflow: hidden;
}
h1, h2, h3 { font-family: var(--font-display); margin: 0; }
button { font-family: var(--font-display); }

.app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 22px; background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px;
  background: linear-gradient(155deg, var(--accent), var(--accent-strong));
  display: flex; align-items: center; justify-content: center; font-size: 19px; flex-shrink: 0; overflow: hidden;
}
.brand-mark img { width: 100%; height: 100%; object-fit: cover; display: block; }
.brand h1 { font-size: 17px; font-weight: 800; }
.brand .tagline { margin: 2px 0 0; font-size: 12px; color: var(--text-muted); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.switch { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-muted); cursor: pointer; user-select: none; }
.switch input {
  appearance: none; width: 34px; height: 20px; border-radius: 999px; background: var(--surface-3);
  border: 1px solid var(--border); position: relative; cursor: pointer; flex-shrink: 0; transition: background .15s;
}
.switch input::after {
  content: ''; position: absolute; top: 1px; left: 1px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--surface); box-shadow: var(--shadow); transition: transform .15s;
}
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(14px); background: var(--on-accent); }

.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 700; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; transition: background .12s, border-color .12s, transform .06s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn.accent { background: var(--accent-soft); border-color: transparent; color: var(--accent-strong); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 11px; font-size: 12px; }
.btn.full { width: 100%; justify-content: center; }
.btn.danger { color: var(--danger); border-color: transparent; }
.btn.icon { padding: 7px; border-radius: 8px; }
.btn.armed { background: var(--danger); border-color: var(--danger); color: #fff; }

.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 260px minmax(360px, 1fr) 320px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 10px; flex-shrink: 0; }
.panel-head h2 { font-size: 12.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); font-weight: 800; }

.contacts { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.contact-list { list-style: none; margin: 0; padding: 4px 8px 12px; overflow-y: auto; }
.contact-item { display: flex; align-items: center; gap: 10px; padding: 9px 8px; border-radius: var(--radius-m); cursor: pointer; border: 1px solid transparent; }
.contact-item:hover { background: var(--surface-2); }
.contact-item.active { background: var(--accent-soft); border-color: var(--accent); }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0; background: var(--accent);
  display: flex; align-items: center; justify-content: center; font-family: var(--font-display); font-weight: 800; font-size: 13px; color: #fff;
}
.contact-meta { min-width: 0; flex: 1; }
.contact-name { font-size: 13.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-preview { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.contact-time { font-size: 10.5px; color: var(--text-muted); flex-shrink: 0; align-self: flex-start; margin-top: 2px; }
.attach-chip { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 20px; background: var(--accent-soft); border-top: 1px solid var(--border); font-size: 12.5px; flex-shrink: 0; }
.doc-chip { display: inline-block; padding: 8px 12px; margin-bottom: 6px; border-radius: 10px; background: rgba(255,255,255,.18); color: inherit; text-decoration: none; font-size: 13px; font-weight: 600; word-break: break-all; }
.bubble-row.in .doc-chip { background: var(--surface-2); }
.doc-preview { padding: 12px; border-radius: var(--radius-s); background: var(--surface-2); font-size: 13px; word-break: break-all; }
.bubble audio { max-width: 240px; height: 38px; display: block; margin-bottom: 6px; }
.contact-search { padding: 0 12px 8px; }
.contact-search input { width: 100%; padding: 8px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 12.5px; }
.contact-hint { margin: 0; padding: 0 16px 8px; font-size: 11.5px; color: var(--text-muted); line-height: 1.4; }
.template-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 20px; background: var(--surface); border-top: 1px solid var(--border); font-size: 12.5px; color: var(--text-muted); }
.template-bar select { flex: 1; min-width: 160px; padding: 7px 10px; border-radius: var(--radius-s); border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 12.5px; }
.empty-side { padding: 20px 16px; color: var(--text-muted); font-size: 12.5px; text-align: center; }

.chat { display: flex; flex-direction: column; min-height: 0; background: radial-gradient(ellipse at top left, var(--surface-2) 0%, transparent 55%), var(--bg); }
.chat-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.chat-contact { display: flex; align-items: center; gap: 10px; min-width: 0; }
.chat-contact .avatar { width: 34px; height: 34px; font-size: 12px; }
.chat-contact-name { font-size: 14px; font-weight: 700; }
.chat-contact-sub { font-size: 11.5px; color: var(--text-muted); }

.ficha { padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0; display: flex; flex-direction: column; gap: 8px; }
.ficha-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 12.5px; }
.ficha-text { color: var(--text-muted); }
.ficha-alert { margin: 0; padding: 8px 10px; border-radius: var(--radius-s); background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); font-size: 12.5px; font-weight: 600; }
.ficha-summary { margin: 0; font-size: 12.5px; line-height: 1.45; color: var(--text-muted); padding: 7px 10px; border-radius: var(--radius-s); background: var(--surface-2); }
.ficha-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ficha-cost { font-size: 11px; color: var(--text-muted); margin-left: auto; }
.stage-chip { font-family: var(--font-display); font-size: 11px; font-weight: 800; padding: 3px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-strong); }
.stage-chip.ordered, .stage-chip.closed { background: color-mix(in srgb, var(--success) 18%, transparent); color: var(--success); }
.stage-chip.lost { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.contact-flag { display: inline-block; margin-left: 6px; font-size: 10px; font-weight: 800; padding: 1px 7px; border-radius: 999px; background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.bubble-source { opacity: .8; margin-right: auto; }

.chat-scroll { flex: 1; overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 10px; }
.empty-chat { margin: auto; text-align: center; color: var(--text-muted); font-size: 13px; max-width: 260px; }

.bubble-row { display: flex; max-width: 78%; }
.bubble-row.in { align-self: flex-start; }
.bubble-row.out { align-self: flex-end; }
.bubble { padding: 9px 12px; border-radius: var(--radius-m); box-shadow: var(--shadow); font-size: 13.5px; line-height: 1.42; }
.bubble-row.in .bubble { background: var(--bubble-in-bg); color: var(--bubble-in-text); border-bottom-left-radius: 4px; }
.bubble-row.out .bubble { background: var(--bubble-out-bg); color: var(--bubble-out-text); border-bottom-right-radius: 4px; }
.bubble p { margin: 0; white-space: pre-wrap; }
.bubble .media-wrap { margin-bottom: 6px; border-radius: 10px; overflow: hidden; max-width: 260px; }
/* Foto y video con su forma original (vertical u horizontal), sin recortar. */
.bubble .media-wrap img, .bubble .media-wrap video { display: block; width: auto; height: auto; max-width: 100%; max-height: 360px; object-fit: contain; background: #000; }
.bubble-meta { display: flex; align-items: center; gap: 4px; justify-content: flex-end; margin-top: 4px; font-size: 10.5px; opacity: .75; }
.bubble-row.in .bubble-meta { color: var(--text-muted); }

.composer { display: flex; gap: 10px; padding: 14px 20px; background: var(--surface); border-top: 1px solid var(--border); flex-shrink: 0; }
.composer input { flex: 1; padding: 11px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 13.5px; }
.composer-hint { padding: 0 20px 10px; font-size: 11px; color: var(--text-muted); flex-shrink: 0; margin-top: -6px; }

.quickpanel { background: var(--surface); border-left: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.qp-search { padding: 0 16px 10px; }
.qp-search input { width: 100%; padding: 8px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 12.5px; }
.qp-categories { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 12px; }
.pill { border: 1px solid var(--border); background: var(--surface-2); color: var(--text-muted); font-size: 11.5px; font-weight: 700; padding: 5px 11px; border-radius: 999px; cursor: pointer; font-family: var(--font-display); }
.pill.active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

.qp-list { flex: 1; overflow-y: auto; padding: 0 12px 12px; display: flex; flex-direction: column; gap: 8px; }
.qp-empty { color: var(--text-muted); font-size: 12.5px; text-align: center; padding: 24px 10px; }
.qp-card { border: 1px solid var(--border); border-radius: var(--radius-m); padding: 10px 10px 8px; background: var(--surface); display: flex; gap: 9px; }
.qp-thumb { width: 44px; height: 44px; border-radius: 8px; flex-shrink: 0; overflow: hidden; background: var(--surface-2); display: flex; align-items: center; justify-content: center; font-size: 16px; color: var(--text-muted); }
.qp-thumb img, .qp-thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.qp-body { min-width: 0; flex: 1; }
.qp-title { font-size: 12.5px; font-weight: 700; display: flex; align-items: center; gap: 6px; }
.qp-cat-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex-shrink: 0; }
.qp-text { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.qp-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.qp-tag { font-size: 10px; background: var(--surface-2); color: var(--text-muted); padding: 2px 7px; border-radius: 999px; }
.qp-actions { display: flex; flex-direction: column; gap: 5px; flex-shrink: 0; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(10,6,25,.5); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.modal { background: var(--surface); border-radius: var(--radius-l); padding: 22px; width: 100%; max-width: 420px; max-height: 88vh; overflow-y: auto; box-shadow: var(--shadow); border: 1px solid var(--border); }
.modal h3 { font-size: 16px; margin-bottom: 14px; }
.modal form { display: flex; flex-direction: column; gap: 12px; }
.modal label { font-size: 12px; font-weight: 700; color: var(--text-muted); display: flex; flex-direction: column; gap: 5px; }
.modal input[type="text"], .modal input[type="search"], .modal textarea, .modal select, .modal input[type="file"] {
  font-size: 13.5px; font-weight: 400; color: var(--text); padding: 9px 11px; border-radius: var(--radius-s);
  border: 1px solid var(--border); background: var(--surface-2); font-family: var(--font-body);
}
.modal textarea { resize: vertical; min-height: 70px; }
.field-error { font-size: 11.5px; color: var(--danger); font-weight: 600; }
.media-preview { position: relative; border-radius: var(--radius-s); overflow: hidden; max-width: 200px; }
.media-preview img, .media-preview video { width: 100%; display: block; max-height: 160px; object-fit: cover; }
.media-preview button { position: absolute; top: 6px; right: 6px; }
.ficha-labels { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
.ficha-labels:empty { display: none; }
.label-chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; color: #fff; }
.label-chip button { background: transparent; border: 0; color: inherit; cursor: pointer; font-size: 13px; line-height: 1; padding: 0 4px; opacity: .85; }
.ficha-labels select { font-size: 11.5px; padding: 3px 6px; border-radius: 999px; border: 1px dashed var(--border); background: var(--surface-2); color: var(--text-muted); max-width: 150px; }
.bubble .media-wrap img.zoomable { cursor: zoom-in; }
.lightbox { position: fixed; inset: 0; z-index: 100; background: rgba(8,5,20,.92); display: flex; align-items: center; justify-content: center; padding: 56px 16px 16px; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; box-shadow: 0 10px 40px rgba(0,0,0,.5); background: #000; }
.lightbox-bar { position: absolute; top: 12px; right: 16px; display: flex; gap: 8px; }
.modal.modal-wide { max-width: 540px; }
.modal input[type="number"] { width: 76px; font-size: 13.5px; font-weight: 400; color: var(--text); padding: 7px 9px; border-radius: var(--radius-s); border: 1px solid var(--border); background: var(--surface-2); font-family: var(--font-body); }
.steps-intro { display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.steps-intro small { color: var(--text-muted); font-size: 12px; }
#stepsList { display: flex; flex-direction: column; gap: 10px; }
.step-card { border: 1px solid var(--border); border-radius: var(--radius-m); padding: 10px; background: var(--surface-2); display: flex; flex-direction: column; gap: 8px; }
.step-head { display: flex; align-items: center; gap: 8px; }
.step-num { font-size: 12px; font-weight: 800; color: var(--text-muted); white-space: nowrap; }
.step-head select { flex: 1; min-width: 0; }
.step-tools { display: flex; gap: 4px; }
.modal select.step-vars { align-self: flex-start; max-width: 100%; padding: 6px 9px; font-size: 12px; border-radius: 999px; color: var(--text-muted); }
.step-file { display: flex; flex-direction: column; gap: 6px; }
.step-file small { color: var(--text-muted); font-size: 11.5px; }
.step-preview { max-width: 100%; max-height: 150px; border-radius: var(--radius-s); object-fit: cover; }
.modal label.step-delay { flex-direction: row; align-items: center; gap: 8px; font-weight: 600; flex-wrap: wrap; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; flex-wrap: wrap; }

.cat-manage-list { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.cat-manage-row { display: flex; align-items: center; gap: 6px; }
.cat-manage-row input { flex: 1; padding: 7px 10px; border-radius: var(--radius-s); border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 12.5px; }
.new-cat-form { display: flex; gap: 8px; margin-bottom: 6px; }
.new-cat-form input { flex: 1; padding: 8px 11px; border-radius: var(--radius-s); border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 12.5px; }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 12.5px; box-shadow: var(--shadow); z-index: 80; }

@media (max-width: 900px) {
  .app { height: auto; min-height: 100vh; overflow: visible; }
  body { overflow: auto; }
  .layout { grid-template-columns: 1fr; grid-auto-rows: min-content; }
  .contacts, .chat, .quickpanel { border: none; border-bottom: 1px solid var(--border); }
  .contacts { max-height: 220px; }
  .chat { min-height: 420px; }
  .quickpanel { max-height: 480px; }
}

/* Herramientas antiguas (respuestas rápidas y mensajes masivos del panel): ocultas por omisión, ahora viven en la extensión. */
.no-legacy .quickpanel, .no-legacy .legacy-only { display: none !important; }
.no-legacy .layout { grid-template-columns: 260px minmax(360px, 1fr); }
@media (max-width: 900px) { .no-legacy .layout { grid-template-columns: 1fr; } }
