:root {
  --bg: #eef1f0;
  --panel: #ffffff;
  --border: #e3e6e5;
  --text: #1b1f1e;
  --text-dim: #667066;
  --primary: #1d7a53;
  --primary-dark: #0f4a33;
  --out-bubble: #d9fdd3;
  --in-bubble: #ffffff;
  --accent: #b5892b;
  --danger: #b3311c;
  --unread: #1d7a53;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13.5px;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: 13.5px; }

/* ===== Login ===== */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-shell { width: 100%; max-width: 360px; padding: 16px; }
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 32px 24px; box-shadow: 0 2px 10px rgba(0,0,0,.06);
}
.login-brand { text-align: center; margin-bottom: 24px; }
.login-brand strong { display: block; font-size: 20px; color: var(--primary-dark); }
.login-brand span { display: block; font-size: 12px; color: var(--text-dim); letter-spacing: .04em; text-transform: uppercase; margin-top: 2px; }
.field-label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 14px; }
.field-label input, .field-label select { width: 100%; margin-top: 6px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px; }
button.primary { background: var(--primary); color: #fff; border: none; padding: 10px 16px; border-radius: 6px; font-weight: 600; }
button.primary:hover { background: var(--primary-dark); }
button.wide { width: 100%; }
.form-error { color: var(--danger); font-size: 12.5px; margin-top: 10px; }

/* ===== App shell ===== */
.app { height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 8px 16px;
  background: var(--primary-dark); color: #fff; flex: 0 0 auto;
}
.brand-copy strong { display: block; font-size: 14px; line-height: 1.2; }
.brand-copy span { display: block; font-size: 10px; opacity: .75; text-transform: uppercase; letter-spacing: .05em; }
.tabs { display: flex; gap: 4px; margin-left: 16px; flex: 1; }
.tab { background: transparent; border: none; color: rgba(255,255,255,.75); padding: 7px 12px; border-radius: 6px; font-size: 12.5px; }
.tab.active { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.send-status-badge { font-size: 10.5px; background: rgba(179,49,28,.2); color: #ffd7cf; padding: 3px 8px; border-radius: 999px; }
.icon-button, .top-icon { background: transparent; border: 1px solid rgba(255,255,255,.25); color: #fff; border-radius: 6px; padding: 5px 9px; font-size: 12.5px; }

.workspace { flex: 1; min-height: 0; position: relative; }
.view { display: none; height: 100%; }
.view.active-view { display: block; }
#view-inbox.active-view { display: grid; grid-template-columns: 300px 1fr 280px; height: 100%; }
#view-properties.active-view, #view-copilot.active-view { display: flex; flex-direction: column; padding: 20px 24px; overflow-y: auto; }

/* ===== Inbox: columna 1 (densidad tipo WhatsApp) ===== */
.conversation-pane { border-right: 1px solid var(--border); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.pane-title-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 6px; }
.pane-title-row h2 { font-size: 14.5px; margin: 0; }
.search-box { display: flex; align-items: center; gap: 6px; margin: 0 14px 8px; padding: 6px 10px; background: var(--bg); border-radius: 8px; }
.search-box input { border: none; outline: none; flex: 1; background: transparent; font-size: 13px; }
.filters { display: flex; flex-wrap: wrap; gap: 5px; padding: 0 14px 8px; }
.filters button { background: var(--bg); border: none; border-radius: 999px; padding: 4px 9px; font-size: 11px; color: var(--text-dim); }
.filters button.active { background: var(--primary); color: #fff; }
.test-data-toggle { display: flex; align-items: center; gap: 6px; padding: 0 14px 8px; font-size: 11px; color: var(--text-dim); cursor: pointer; }
.test-data-toggle input { margin: 0; }
.chat-list { flex: 1; overflow-y: auto; }

.chat-item { display: flex; gap: 10px; padding: 9px 14px; border-bottom: 1px solid var(--border); cursor: pointer; align-items: flex-start; }
.chat-item:hover { background: var(--bg); }
.chat-item.selected { background: #e3f3ea; }
.chat-item-avatar {
  width: 42px; height: 42px; border-radius: 50%; background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 15px; flex: 0 0 auto;
}
.chat-item-body { min-width: 0; flex: 1; }
.chat-item-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.chat-item-name { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item-time { font-size: 10.5px; color: var(--text-dim); flex: 0 0 auto; }
.chat-item-sub { font-size: 11.5px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.chat-item-bottom { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 2px; }
.chat-item-preview { font-size: 12px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.unread-count {
  flex: 0 0 auto; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--unread); color: #fff;
  font-size: 10.5px; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.badge.review { background: #fbe6d4; color: #8a4b12; border: 1px solid #f0c496; padding: 1px 6px; border-radius: 999px; font-size: 9.5px; }

/* ===== Inbox: chat ===== */
.chat-pane { display: flex; flex-direction: column; min-height: 0; background: #e9edea; }
.chat-header { display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--border); }
.contact-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; flex: 0 0 auto; font-size: 13px; }
.contact-main { min-width: 0; flex: 1; }
.contact-line { display: flex; align-items: center; gap: 8px; }
.contact-line h1 { font-size: 14px; margin: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-sub { font-size: 11.5px; color: var(--text-dim); margin-top: 1px; }
.status-pill { font-size: 10px; padding: 2px 8px; border-radius: 999px; background: var(--bg); color: var(--text-dim); border: 1px solid var(--border); flex: 0 0 auto; }

.schema-warning { background: #fdecea; color: var(--danger); font-size: 12px; padding: 6px 14px; border-bottom: 1px solid #f4c7c0; }

.messages { flex: 1; overflow-y: auto; padding: 14px 18px; display: flex; flex-direction: column; gap: 4px; }
.empty-chat { margin: auto; text-align: center; color: var(--text-dim); }
.msg-row { display: flex; margin: 2px 0; }
.msg-row.in { justify-content: flex-start; }
.msg-row.out { justify-content: flex-end; }
.msg-row.system { justify-content: center; }
.msg-bubble { max-width: 65%; padding: 6px 9px 5px; border-radius: 8px; font-size: 13px; line-height: 1.35; box-shadow: 0 1px 1px rgba(0,0,0,.06); }
.msg-row.in .msg-bubble { background: var(--in-bubble); border-bottom-left-radius: 2px; }
.msg-row.out .msg-bubble { background: var(--out-bubble); border-bottom-right-radius: 2px; }
.msg-row.system .msg-bubble { background: #fff3cd; color: #6b5300; font-size: 11.5px; max-width: 80%; text-align: center; }
.msg-content { white-space: pre-wrap; word-break: break-word; }
.msg-meta { display: block; text-align: right; font-size: 10px; margin-top: 2px; color: var(--text-dim); }

.composer-zone { background: var(--panel); border-top: 1px solid var(--border); padding: 8px 14px; }
.composer-row { display: flex; gap: 8px; }
.composer-row textarea { flex: 1; resize: none; height: 38px; border: 1px solid var(--border); border-radius: 20px; padding: 8px 14px; background: var(--bg); font-size: 13px; }
.send-button { background: var(--border); color: var(--text-dim); border: none; border-radius: 20px; padding: 0 18px; font-weight: 600; }
.composer-hint { font-size: 10.5px; color: var(--danger); margin-top: 4px; text-align: center; }

/* ===== Inbox: panel lead (Sección 6: LEAD / OPORTUNIDAD / CONVERSIÓN / TÉCNICO) ===== */
.right-pane { border-left: 1px solid var(--border); background: var(--panel); overflow-y: auto; }
.right-scroll { padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.side-section { border-bottom: 1px solid var(--border); padding-bottom: 12px; }
.side-section:last-child { border-bottom: none; }
.side-title { font-size: 10.5px; font-weight: 700; letter-spacing: .05em; color: var(--text-dim); margin-bottom: 8px; text-transform: uppercase; }
.lead-panel dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 5px 10px; font-size: 12px; }
.lead-panel dt { color: var(--text-dim); }
.lead-panel dd { margin: 0; font-weight: 600; text-align: right; word-break: break-word; }
.identity-missing-notice { margin-top: 8px; color: var(--danger); font-size: 11px; }
.empty-note { color: var(--text-dim); font-size: 12px; margin: 0; }
.files-toggle { width: 100%; background: transparent; border: none; display: flex; justify-content: space-between; align-items: center; font-size: 10.5px; font-weight: 700; color: var(--text-dim); text-transform: uppercase; letter-spacing: .05em; padding: 0; }
.tech-panel { margin-top: 8px; font-size: 11px; color: var(--text-dim); }
.tech-panel dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 8px; }
.tech-panel dt { opacity: .8; }
.tech-panel dd { margin: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10.5px; word-break: break-all; }

.inbox-error { margin: 16px; padding: 14px; border: 1px solid #f0c4bc; background: #fdf1ee; border-radius: var(--radius); }
.inbox-error strong { display: block; color: var(--danger); font-size: 13px; margin-bottom: 4px; }
.inbox-error p { margin: 0 0 10px; font-size: 12px; color: var(--text-dim); word-break: break-word; }
.inbox-error button { background: var(--danger); color: #fff; border: none; border-radius: 6px; padding: 6px 14px; font-size: 12.5px; }

/* ===== Botones secundarios (reintentar, volver, usar respuesta) ===== */
button.secondary { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 6px 14px; font-size: 12.5px; }
button.secondary:hover { background: var(--bg); }
button.secondary:disabled { opacity: .5; cursor: not-allowed; }
button.primary:disabled { opacity: .6; cursor: not-allowed; }

/* ===== Propiedades ===== */
.properties-body { margin-top: 12px; }
.property-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.property-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; background: var(--panel); cursor: pointer; }
.property-card:hover { border-color: var(--primary); }
.property-card h3 { margin: 0 0 6px; font-size: 14px; }
.property-card dl { margin: 0; font-size: 12px; color: var(--text-dim); display: grid; grid-template-columns: auto 1fr; gap: 3px 8px; }
.property-card dd { margin: 0; text-align: right; color: var(--text); }

.property-detail { margin-top: 12px; display: flex; flex-direction: column; gap: 12px; max-width: 640px; }
.property-detail-section { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; background: var(--panel); }
.property-detail-section dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; font-size: 12.5px; }
.property-detail-section dt { color: var(--text-dim); }
.property-detail-section dd { margin: 0; text-align: right; font-weight: 600; word-break: break-word; }
.property-field-pending { color: var(--accent); font-style: italic; font-weight: 500; }
.property-field-not-applicable { color: var(--text-dim); font-style: italic; font-weight: 500; }
.property-field-confirmed { color: var(--text); }

/* ===== Selector de propiedad asociada (Sección 3, panel LEAD) ===== */
.property-picker { margin-top: 10px; }
.property-picker-label { display: block; font-size: 10.5px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }
.property-picker select { width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 12.5px; background: var(--panel); }

/* ===== Copiloto ===== */
.copilot-body { margin-top: 12px; }
.copilot-placeholder { text-align: center; color: var(--text-dim); padding: 60px 20px; border: 1px dashed var(--border); border-radius: var(--radius); }
.copilot-placeholder .ai-spark { font-size: 26px; color: var(--accent); display: block; margin-bottom: 8px; }
.copilot-context.side-section { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; background: var(--panel); margin-bottom: 12px; }
.copilot-context dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; font-size: 13px; }
.copilot-context dd { margin: 0; font-weight: 600; text-align: right; }
.copilot-field { margin-bottom: 12px; }
.copilot-field:last-child { margin-bottom: 0; }
.copilot-field-label { font-size: 10.5px; font-weight: 700; letter-spacing: .05em; color: var(--text-dim); text-transform: uppercase; margin-bottom: 4px; }
.copilot-field-value { font-size: 13px; white-space: pre-wrap; }
.copilot-alerts ul { margin: 0; padding-left: 18px; }
.copilot-alerts li { font-size: 12px; color: var(--danger); margin-bottom: 4px; }

/* ===== Responsive (Sección 11: WhatsApp-like — nunca 3 columnas comprimidas) ===== */
.mobile-back, .mobile-info, .mobile-close-info { display: none; }

@media (max-width: 980px) {
  #view-inbox.active-view { grid-template-columns: 1fr; position: relative; }
  /* Por defecto (mobile, ninguna conversacion abierta): solo la lista. */
  .chat-pane { display: none; }
  .right-pane { display: none; }
  /* Con una conversacion abierta (JS agrega .mobile-chat-active a #view-inbox): solo el chat. */
  #view-inbox.mobile-chat-active .conversation-pane { display: none; }
  #view-inbox.mobile-chat-active .chat-pane { display: flex; }
  .mobile-back, .mobile-info { display: inline-flex; align-items: center; justify-content: center; background: transparent; border: none; font-size: 20px; color: var(--text); width: 32px; height: 32px; flex: 0 0 auto; }
  #view-inbox.mobile-chat-active .mobile-back,
  #view-inbox.mobile-chat-active .mobile-info { display: inline-flex; }
  /* Panel de informacion comercial como drawer superpuesto (JS agrega .mobile-open al abrirlo). */
  .right-pane.mobile-open { display: flex; flex-direction: column; position: fixed; inset: 48px 0 0 0; z-index: 20; }
  .mobile-close-info { display: block; width: 100%; text-align: right; background: transparent; border: none; color: var(--text-dim); font-size: 13px; padding: 4px 0 12px; }
  .tabs { margin-left: 8px; }
  .tab { padding: 6px 9px; font-size: 11.5px; }
}
