:root {
  /* Paleta premium Sumeria — dorado más saturado/profundo (Four Seasons-like) */
  --bg: #0d1117;
  --bg-elev: #161b22;
  --bg-card: #1c232d;
  --border: #2d3540;
  --text: #e6eaef;
  --text-muted: #8896a6;
  --primary: #c8963e;
  --primary-hover: #d9a84e;
  --accent: #a07840;
  --ok: #5cb85c;
  --warn: #f0ad4e;
  --danger: #d9534f;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 8px 28px rgba(0, 0, 0, 0.35);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
          'Helvetica Neue', Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}

.muted { color: var(--text-muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 28px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}
.logo {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), #a17630);
  color: #1a1a1a;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: 0.5px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.2);
}
.brand h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.brand p {
  font-size: 13px;
  margin: 2px 0 0;
}

.status { display: flex; gap: 6px; }
.badge {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.badge-ok    { background: rgba(92,184,92,0.12); color: var(--ok); border: 1px solid rgba(92,184,92,0.3); }
.badge-warn  { background: rgba(240,173,78,0.12); color: var(--warn); border: 1px solid rgba(240,173,78,0.3); }
.badge-muted { background: rgba(136,150,166,0.12); color: var(--text-muted); border: 1px solid rgba(136,150,166,0.2); }
.status-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  display: inline-block;
  cursor: help;
}
.status-dot-ok   { background: var(--ok); box-shadow: 0 0 8px rgba(92,184,92,0.6); }
.status-dot-warn { background: var(--warn); }

main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 28px 40px;
}

.query-zone { margin-bottom: 24px; }

.query-bar {
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 14px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.query-bar:focus-within {
  border-color: var(--primary);
  box-shadow: var(--shadow-lg);
}
.icon-search {
  display: inline-flex;
  align-items: center;
  margin-right: 10px;
  color: var(--text-muted);
}
.icon-search svg { display: block; }

#q {
  flex: 1;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--text);
  font-size: 16px;
  padding: 8px 4px;
  font-family: var(--font);
}
#q::placeholder { color: var(--text-muted); }

.btn-primary, .btn-secondary, .btn-link {
  font-family: var(--font);
  font-weight: 600;
  border: 0;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.15s, transform 0.05s, color 0.15s, border-color 0.15s;
}
.btn-primary {
  background: var(--primary);
  color: #1a1a1a;
  padding: 10px 20px;
  font-size: 14px;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:focus-visible {
  outline: 2px solid var(--primary-hover);
  outline-offset: 2px;
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 12px;
  font-size: 13px;
}
.btn-secondary:hover { border-color: var(--primary); color: var(--text); }

.btn-link {
  background: transparent;
  color: var(--primary);
  text-decoration: none;
  padding: 6px 0;
  font-size: 13px;
}
.btn-link:hover { color: var(--primary-hover); }
.btn-link:focus-visible { outline: 1px solid var(--primary); outline-offset: 2px; border-radius: 4px; }

.examples {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  font-size: 13px;
}
.chip-link {
  background: rgba(200, 150, 62, 0.08);
  border: 1px dashed rgba(200, 150, 62, 0.35);
  color: var(--primary);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font);
}
.chip-link:hover { background: rgba(200, 150, 62, 0.16); }

.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 24px;
  align-items: flex-start;
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .filters-panel { position: static; }
}
@media (max-width: 680px) {
  .results { grid-template-columns: 1fr !important; }  /* P2-3 */
}
@media (max-width: 640px) {
  main { padding: 16px 14px 24px; }
  .topbar { padding: 12px 16px; }
  .selection-bar { flex-direction: column; gap: 8px; padding: 10px 16px; }
  .selection-actions { width: 100%; display: flex; }
  .selection-actions .btn-primary { flex: 1; }
}

.filters-panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  position: sticky;
  top: 16px;
}
.filters-panel h2 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin: 0 0 12px;
  color: var(--text-muted);
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(200, 150, 62, 0.12);
  color: var(--primary);
  border: 1px solid rgba(200, 150, 62, 0.35);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
}
.chip button {
  background: transparent;
  border: 0;
  color: var(--primary);
  cursor: pointer;
  padding: 0;
  font-size: 14px;
  line-height: 1;
}

#clear-filters { margin-top: 14px; width: 100%; }

.status-line {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
  min-height: 18px;
}

.results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 16px;
}

/* ─── Skeleton shimmer (P1-4 — estándar premium) ────── */
.card-skeleton {
  background: linear-gradient(90deg, #1c232d 25%, #2a323e 50%, #1c232d 75%);
  background-size: 800px 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  height: 360px;
  position: relative;
  overflow: hidden;
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
}
.card-skeleton::before {
  content: "";
  position: absolute; top: 0; left: 0; right: 0;
  height: 200px;
  background: linear-gradient(90deg, #14181f 25%, #1f2530 50%, #14181f 75%);
  background-size: 800px 100%;
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
}
@keyframes skeleton-shimmer {
  0% { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}

/* ─── Cards ────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.card:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
  box-shadow: var(--shadow-lg);
}

.card-photo {
  position: relative;
  height: 200px;
  background: #0a0d12;
}
.card-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.card-photo .no-photo-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #14181f 0%, #1c232d 100%);
  color: var(--text-muted);
  font-size: 12px;
  gap: 6px;
}
.card-photo .no-photo-placeholder svg { opacity: 0.4; }

.photo-count {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 600;
  backdrop-filter: blur(4px);
}

.card-body {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.card-title {
  font-size: 15px;
  margin: 0;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.005em;
}
.card-ref {
  font-size: 11px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0;
}
.card-meta {
  font-size: 13px;
  margin: 0;
  color: var(--text-muted);
}
.card-meta strong {
  color: var(--primary);
  font-weight: 700;
}
.card-why {
  margin: 4px 0 0;
  font-style: italic;
}
.card-actions {
  display: flex;
  gap: 14px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  align-items: center;
  flex-wrap: wrap;
}
.card-whatsapp { color: #25d366 !important; }
.card-whatsapp:hover { color: #4ade80 !important; }

.empty, .error-state {
  background: var(--bg-elev);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 30px;
  text-align: center;
  color: var(--text-muted);
}
.empty ul {
  margin: 12px auto 12px;
  padding: 0;
  list-style: none;
  text-align: left;
  max-width: 480px;
}
.empty ul li { padding: 6px 0; }
.empty .btn-secondary { margin-top: 4px; }

.loading {
  position: relative;
  padding-right: 28px;
}
.loading::after {
  content: "";
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--primary);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-left: 8px;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Panel LLM "Resumen del cliente" ─────────────────────────────── */
.llm-panel {
  background: linear-gradient(135deg, rgba(200, 150, 62, 0.10), rgba(160, 120, 64, 0.06));
  border: 1px solid rgba(200, 150, 62, 0.30);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 18px;
  position: relative;
}
.llm-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.llm-badge {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--primary);
}
.llm-perfil {
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  margin: 0 0 10px;
  padding: 8px 10px;
  background: rgba(0,0,0,0.15);
  border-radius: 6px;
  border: 1px dashed rgba(200, 150, 62, 0.25); /* siempre visible (P1-5) */
  cursor: text;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.llm-perfil:hover { border-color: rgba(200, 150, 62, 0.45); }
.llm-perfil:focus {
  border-color: var(--primary);
  background: rgba(0,0,0,0.25);
}
.llm-edit-hint {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-muted);
  margin-left: auto;
  margin-right: 12px;
  opacity: 0.7;
}
.llm-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
}
.llm-meta strong { color: var(--text); margin-right: 4px; }

/* Grid de campos estructurados extraídos por LLM */
.llm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 6px 14px;
  margin: 12px 0;
  font-size: 12px;
}
.llm-field {
  display: flex;
  flex-direction: column;
  padding: 6px 10px;
  background: rgba(0,0,0,0.18);
  border-radius: 6px;
  border-left: 2px solid rgba(200, 150, 62, 0.4);
}
.llm-key {
  color: var(--text-muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.llm-val {
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
  word-break: break-word;
}
.llm-tags {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}
.llm-tag-row strong { color: var(--text); margin-right: 4px; }
.llm-actions {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
}
#llm-enrich-deal {
  font-size: 12px;
}

/* ─── Card seleccionable ────────────────────────────────────────────── */
.card { position: relative; }
.card-select {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 3;
  width: 28px; height: 28px;
  background: rgba(0,0,0,0.65);
  border: 2px solid rgba(255,255,255,0.5);
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: all 0.15s;
}
.card-select input { display: none; }
.card-select-tick {
  color: white;
  font-size: 16px;
  font-weight: 800;
  opacity: 0;
  transition: opacity 0.15s;
  /* Borde visible siempre (P1-3) para que se distinga sobre fotos claras */
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  display: grid;
  place-items: center;
  line-height: 1;
}
.card-select:hover {
  border-color: var(--primary);
  background: rgba(200, 150, 62, 0.3);
}
.card-select input:checked + .card-select-tick {
  opacity: 1;
  border-color: white;
  background: transparent;
}
.card.is-selected .card-select {
  background: var(--primary);
  border-color: var(--primary);
}
.card.is-selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(200, 150, 62, 0.5);
}
.card.is-selected .card-select-tick {
  opacity: 1;
  background: white;
  color: var(--primary);
  border-color: white;
}

/* ─── Barra inferior flotante de selección ─────────────────────────── */
.selection-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  box-shadow: 0 -6px 24px rgba(0,0,0,0.4);
  padding: 14px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  z-index: 100;
  animation: slideUp 0.2s ease-out;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.selection-info {
  font-weight: 600;
  font-size: 14px;
}
.selection-info span#selection-count {
  color: var(--primary);
  font-size: 18px;
  font-weight: 800;
  margin-right: 4px;
}
.selection-actions {
  display: flex;
  gap: 10px;
}
#selection-clear {
  color: var(--text);
  border: 1px solid var(--border);
  background: transparent;
}
#selection-clear:hover {
  border-color: var(--danger);
  color: var(--danger);
}

/* ─── Toast (P2-1: posición arriba de la barra de selección) ─────── */
.toast {
  position: fixed;
  bottom: 140px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--primary);
  border-left: 4px solid var(--primary);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  z-index: 200;
  animation: toastIn 0.25s ease-out;
  max-width: 600px;
}
.toast.is-error {
  border-color: var(--danger);
  border-left: 4px solid var(--danger);
}
.toast.is-success {
  border-color: var(--ok);
  border-left: 4px solid var(--ok);
}
@keyframes toastIn {
  from { transform: translate(-50%, 20px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

/* ─── Compact mode dentro de placement (iframe Bitrix tab del deal) ─── */
body[data-placement="true"] .brand h1 { font-size: 14px; }
body[data-placement="true"] .brand p { font-size: 12px; }
body[data-placement="true"] .topbar { padding: 10px 16px; }
body[data-placement="true"] main { padding: 16px 18px 24px; }
body[data-placement="true"] .examples { display: none; }
