/* ORION CRM · estilos base (sin frameworks) */
:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8ef;
  --text: #17202e;
  --muted: #64748b;
  --brand: #f97316;          /* naranja ORION */
  --brand-dark: #ea580c;
  --brand-soft: #fff1e6;
  --side: #0f172a;
  --side-text: #cbd5e1;
  --side-active: #1e293b;
  --ok: #16a34a;
  --ok-soft: #e8f7ee;
  --warn: #d97706;
  --warn-soft: #fff7e6;
  --error: #dc2626;
  --error-soft: #fdecec;
  --info: #2563eb;
  --info-soft: #e8f0fe;
  --wa-in: #ffffff;
  --wa-out: #dcf8c6;
  --chat-bg: #efeae2;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); font-size: 14px; line-height: 1.45; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--info); }
.oculto { display: none !important; }

/* ---------- Botones y formularios ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-weight: 600; white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primario { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primario:hover:not(:disabled) { background: var(--brand-dark); }
.btn-fb { background: #1877f2; border-color: #1877f2; color: #fff; }
.btn-fb:hover:not(:disabled) { background: #166fe5; }
.btn-texto { border: 0; background: none; color: var(--muted); padding: 6px 8px; }
.campo { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.campo label { font-size: 12px; font-weight: 600; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
}
.input:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
textarea.input { resize: vertical; min-height: 80px; }
.fila { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 16px; background: linear-gradient(135deg, #0f172a, #1e293b); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border-radius: 14px; padding: 32px 28px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-card h1 { margin: 12px 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 22px; color: var(--muted); }
.login-card .btn { width: 100%; padding: 11px; margin-top: 6px; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: .08em; font-size: 18px; }
.logo-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 16px; }
.alerta { padding: 10px 12px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; }
.alerta-error { background: var(--error-soft); color: var(--error); }
.alerta-ok { background: var(--ok-soft); color: var(--ok); }
.alerta-warn { background: var(--warn-soft); color: #92400e; }

/* ---------- Layout de la app ---------- */
.app { display: grid; grid-template-columns: 232px 1fr; height: 100%; }
.sidebar { background: var(--side); color: var(--side-text); display: flex; flex-direction: column; padding: 18px 12px; }
.sidebar .logo { color: #fff; padding: 0 8px 20px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
  color: var(--side-text); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--side-active); color: #fff; }
.nav a.activo { background: var(--side-active); color: #fff; box-shadow: inset 3px 0 0 var(--brand); }
.nav .ico { width: 20px; text-align: center; }
.nav .badge { margin-left: auto; }
.sidebar-pie { border-top: 1px solid #1e293b; padding: 14px 8px 0; font-size: 13px; }
.sidebar-pie .nombre { color: #fff; font-weight: 600; }
.sidebar-pie .sub { color: #94a3b8; font-size: 12px; margin-bottom: 8px; }
.sidebar-pie .btn-texto { color: #94a3b8; padding-left: 0; }

.main { display: flex; flex-direction: column; min-width: 0; height: 100%; overflow: hidden; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar h2 { margin: 0; font-size: 18px; flex: 1; }
.btn-menu { display: none; }
.contenido { flex: 1; overflow: auto; padding: 24px; }
.contenido.sin-padding { padding: 0; overflow: hidden; }

.badge { display: inline-block; min-width: 20px; padding: 1px 7px; border-radius: 999px; background: var(--brand); color: #fff; font-size: 11px; font-weight: 700; text-align: center; }
.chip { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); border: 1px solid var(--border); }
.etapa-nuevo { background: var(--info-soft); color: var(--info); border-color: transparent; }
.etapa-contactado { background: #f1ecfe; color: #6d28d9; border-color: transparent; }
.etapa-cotizado { background: var(--warn-soft); color: #b45309; border-color: transparent; }
.etapa-negociacion { background: var(--brand-soft); color: var(--brand-dark); border-color: transparent; }
.etapa-vendido { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.etapa-perdido { background: #f1f5f9; color: var(--muted); border-color: transparent; }

/* ---------- Tarjetas y panel ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card h3 { margin: 0 0 14px; font-size: 15px; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.kpi .etq { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi .valor { font-size: 30px; font-weight: 750; margin-top: 4px; }
.grid-2 { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; }
.embudo-fila { display: grid; grid-template-columns: 110px 1fr 40px; align-items: center; gap: 10px; margin-bottom: 10px; }
.embudo-barra { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.embudo-barra span { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.embudo-fila .num { text-align: right; font-weight: 700; }
.lista-simple { list-style: none; margin: 0; padding: 0; }
.lista-simple li { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.lista-simple li:last-child { border-bottom: 0; }
.vacio { color: var(--muted); text-align: center; padding: 28px 12px; }

.avatar { flex: none; width: 38px; height: 38px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-dark); display: grid; place-items: center; font-weight: 700; }
.elipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--muted); }
.peq { font-size: 12px; }

/* ---------- Bandeja ---------- */
.bandeja { display: grid; grid-template-columns: 320px 1fr 300px; height: 100%; }
.bandeja-lista { border-right: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; min-height: 0; }
.bandeja-lista .buscar { padding: 12px; border-bottom: 1px solid var(--border); }
.convs { flex: 1; overflow: auto; }
.conv { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.conv:hover { background: var(--surface-2); }
.conv.activa { background: var(--brand-soft); }
.conv .cuerpo { flex: 1; min-width: 0; }
.conv .arriba { display: flex; justify-content: space-between; gap: 8px; }
.conv .nombre { font-weight: 600; }
.conv.no-leida .nombre, .conv.no-leida .prev { font-weight: 700; color: var(--text); }

.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--chat-bg); }
.chat-cab { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.chat-cab .info { flex: 1; min-width: 0; }
.btn-volver { display: none; }
.mensajes { flex: 1; overflow: auto; padding: 18px 6%; display: flex; flex-direction: column; gap: 6px; }
.burbuja { max-width: 72%; padding: 7px 10px 5px; border-radius: 8px; box-shadow: 0 1px 1px rgba(0,0,0,.08); white-space: pre-wrap; word-wrap: break-word; }
.burbuja.entrante { align-self: flex-start; background: var(--wa-in); border-top-left-radius: 2px; }
.burbuja.saliente { align-self: flex-end; background: var(--wa-out); border-top-right-radius: 2px; }
.burbuja .meta { display: block; text-align: right; font-size: 11px; color: var(--muted); margin-top: 2px; }
.burbuja .meta.failed { color: var(--error); }
.dia { align-self: center; background: #e1f3fb; color: #3b5563; font-size: 12px; padding: 3px 10px; border-radius: 6px; margin: 8px 0; }
.composer { display: flex; gap: 8px; padding: 10px 14px; background: var(--surface-2); border-top: 1px solid var(--border); }
.composer textarea { flex: 1; min-height: 42px; max-height: 140px; resize: none; }
.aviso-ventana { padding: 8px 14px; font-size: 12px; background: var(--warn-soft); color: #92400e; }
.chat-vacio { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 24px; }

.ficha { border-left: 1px solid var(--border); background: var(--surface); overflow: auto; padding: 18px; }
.ficha h3 { margin: 0 0 4px; font-size: 16px; }

/* ---------- Clientes ---------- */
.barra-filtros { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.barra-filtros .input { max-width: 280px; }
.barra-filtros .espacio { flex: 1; }
.filtro { cursor: pointer; }
.filtro.activo { background: var(--text); color: #fff; border-color: var(--text); }
.tabla-wrap { overflow-x: auto; }
table.tabla { width: 100%; border-collapse: collapse; }
.tabla th, .tabla td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border); }
.tabla th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); }
.tabla tbody tr { cursor: pointer; }
.tabla tbody tr:hover { background: var(--surface-2); }

/* ---------- Embudo (kanban) ---------- */
.kanban { display: grid; grid-template-columns: repeat(6, minmax(220px, 1fr)); gap: 12px; overflow-x: auto; height: 100%; padding-bottom: 8px; }
.columna { background: #e9edf3; border-radius: var(--radius); display: flex; flex-direction: column; min-height: 200px; }
.columna.sobre { outline: 2px dashed var(--brand); }
.columna-cab { display: flex; justify-content: space-between; align-items: center; padding: 12px 12px 8px; font-weight: 700; }
.columna-cuerpo { flex: 1; padding: 0 8px 8px; display: flex; flex-direction: column; gap: 8px; overflow: auto; }
.tarjeta { background: var(--surface); border-radius: 8px; padding: 10px 12px; box-shadow: var(--shadow); cursor: grab; }
.tarjeta:active { cursor: grabbing; }
.tarjeta .t-nombre { font-weight: 600; }

/* ---------- WhatsApp ---------- */
.cuenta { display: flex; gap: 14px; align-items: center; padding: 14px 0; border-bottom: 1px solid var(--border); }
.cuenta:last-child { border-bottom: 0; }
.cuenta .wa-ico { width: 42px; height: 42px; border-radius: 50%; background: #25d366; color: #fff; display: grid; place-items: center; font-weight: 800; }
.pasos { color: var(--muted); padding-left: 20px; line-height: 1.8; }
.estado-msg { min-height: 1.4em; margin-top: 12px; color: var(--muted); }
.estado-msg.ok { color: var(--ok); }
.estado-msg.error { color: var(--error); }

/* ---------- Modal / panel lateral ---------- */
.capa { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; justify-content: flex-end; z-index: 50; }
.panel-lateral { width: 100%; max-width: 420px; height: 100%; background: var(--surface); padding: 22px; overflow: auto; box-shadow: -10px 0 30px rgba(0,0,0,.15); }
.panel-lateral .cab { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.panel-lateral h3 { margin: 0; }
.acciones { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 100; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.toast.error { background: var(--error); }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .bandeja { grid-template-columns: 300px 1fr; }
  .ficha { display: none; }
}
@media (max-width: 900px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 250px; z-index: 60; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.abierta { transform: none; }
  .btn-menu { display: inline-flex; }
  .topbar { padding: 12px 16px; }
  .contenido { padding: 16px; }
  .bandeja { grid-template-columns: 1fr; }
  .bandeja.con-chat .bandeja-lista { display: none; }
  .bandeja:not(.con-chat) .chat { display: none; }
  .btn-volver { display: inline-flex; }
  .mensajes { padding: 14px 10px; }
  .burbuja { max-width: 88%; }
  .fila { grid-template-columns: 1fr; }
  .kpi .valor { font-size: 24px; }
}

/* ---------- Instalador ---------- */
.login-card.ancho { max-width: 560px; }
.login-card h3 { margin: 22px 0 8px; font-size: 15px; }
.login-card .ayuda { font-size: 13px; margin: 0 0 12px; }
.login-card code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.requisitos { list-style: none; padding: 0; margin: 0 0 14px; font-size: 13px; }
.requisitos li { padding: 3px 0; }
.requisitos .ok { color: var(--ok); }
.requisitos .falla { color: var(--error); font-weight: 600; }
.fila-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pasos { padding-left: 20px; line-height: 1.7; }
.input.codigo { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; width: 100%; }
a.btn { display: inline-block; text-align: center; text-decoration: none; }
.copiable { display: flex; gap: 8px; }
.copiable .input { flex: 1; min-width: 0; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; margin: 4px 0 8px; }
@media (max-width: 640px) { .fila-2 { grid-template-columns: 1fr; } }
