:root {
  --primary: #7c3aed;
  --primary-dark: #5b21b6;
  --secondary: #06b6d4;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #16213e;
  --border: rgba(255,255,255,.1);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --radius: 10px;
  --sidebar-w: 240px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }

/* ── Loading ── */
.loading-overlay { position: fixed; inset: 0; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem; z-index: 9999; }
.spinner-ring { width: 40px; height: 40px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Login ── */
.login-bg { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: radial-gradient(ellipse at 60% 40%, #3b0764 0%, #0f0f1a 70%); padding: 1rem; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 2.5rem 2rem; width: 100%; max-width: 400px; }
.login-logo { text-align: center; margin-bottom: 1.75rem; }
.logo-icon { font-size: 2.5rem; margin-bottom: .5rem; }
.login-logo h1 { font-size: 1.3rem; font-weight: 700; color: var(--text); }
.login-logo p { font-size: .82rem; color: var(--muted); margin-top: .3rem; }

/* ── App Shell ── */
#appShell { display: flex; min-height: 100vh; }

/* ── Sidebar ── */
.sidebar { width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; position: fixed; top: 0; left: 0; height: 100vh; overflow-y: auto; z-index: 100; }
.sidebar-brand { padding: 1.25rem 1rem; display: flex; align-items: center; gap: .75rem; border-bottom: 1px solid var(--border); }
.brand-icon { font-size: 1.8rem; }
.brand-name { font-size: 1rem; font-weight: 700; color: var(--text); }
.brand-sub { font-size: .7rem; color: var(--muted); }
.sidebar-nav { padding: .75rem .5rem; flex: 1; }
.nav-item { display: flex; align-items: center; padding: .6rem .85rem; border-radius: var(--radius); margin-bottom: 2px; cursor: pointer; color: var(--muted); font-size: .88rem; transition: all .2s; text-decoration: none; }
.nav-item:hover { background: rgba(124,58,237,.15); color: var(--text); }
.nav-item.active { background: rgba(124,58,237,.25); color: #a78bfa; font-weight: 600; }
.sidebar-footer { padding: .75rem; border-top: 1px solid var(--border); }
.user-pill { display: flex; align-items: center; gap: .6rem; }
.user-avatar { width: 32px; height: 32px; border-radius: 50%; background: linear-gradient(135deg, var(--primary), var(--secondary)); display: flex; align-items: center; justify-content: center; font-size: .8rem; font-weight: 700; color: #fff; flex-shrink: 0; }

/* ── Main ── */
.main-wrap { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }
.topbar { height: 52px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 1rem; padding: 0 1.25rem; position: sticky; top: 0; z-index: 50; }
.topbar-title { font-size: 1rem; font-weight: 600; }
.page-content { padding: 1.5rem; flex: 1; }

/* ── Cards ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; gap: .5rem; }
.card-title { font-size: 1rem; font-weight: 600; }

/* ── Stats Grid ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem; }
.stat-value { font-size: 1.9rem; font-weight: 700; line-height: 1.2; }
.stat-label { font-size: .75rem; color: var(--muted); margin-top: .25rem; }
.stat-icon { font-size: 1.4rem; margin-bottom: .4rem; }

/* ── Grid ── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
@media (max-width: 768px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } .main-wrap { margin-left: 0; } }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; gap: .4rem; padding: .5rem 1rem; border-radius: 6px; font-size: .875rem; font-weight: 500; cursor: pointer; border: none; transition: all .2s; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(.9); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.9); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: rgba(255,255,255,.07); color: var(--text); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: rgba(255,255,255,.07); }
.btn-sm { padding: .3rem .65rem; font-size: .8rem; }
.btn-icon { padding: .35rem .45rem; }
.w-full { width: 100%; justify-content: center; }

/* ── Forms ── */
.form-group { margin-bottom: .9rem; }
.form-label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: .35rem; font-weight: 500; }
.form-control { width: 100%; padding: .55rem .75rem; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: .875rem; transition: border .2s; }
.form-control:focus { outline: none; border-color: var(--primary); }
.form-row { display: grid; gap: .75rem; }
.form-row.cols-2 { grid-template-columns: 1fr 1fr; }
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 600px) { .form-row.cols-2, .form-row.cols-3 { grid-template-columns: 1fr; } }
textarea.form-control { resize: vertical; }
select.form-control option { background: var(--surface); }

/* ── Badges ── */
.badge { display: inline-flex; align-items: center; padding: .2rem .55rem; border-radius: 99px; font-size: .72rem; font-weight: 600; }
.badge-hot     { background: rgba(239,68,68,.2);  color: #fca5a5; }
.badge-warm    { background: rgba(245,158,11,.2); color: #fcd34d; }
.badge-cold    { background: rgba(148,163,184,.15); color: var(--muted); }
.badge-new     { background: rgba(124,58,237,.2); color: #c4b5fd; }
.badge-converted { background: rgba(16,185,129,.2); color: #6ee7b7; }
.badge-lost    { background: rgba(239,68,68,.15); color: #fca5a5; }
.badge-primary { background: rgba(124,58,237,.2); color: #c4b5fd; }
.badge-success { background: rgba(16,185,129,.2); color: #6ee7b7; }
.badge-warning { background: rgba(245,158,11,.2); color: #fcd34d; }
.badge-secondary { background: rgba(148,163,184,.15); color: var(--muted); }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
thead th { text-align: left; padding: .6rem .75rem; font-size: .75rem; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody td { padding: .65rem .75rem; border-bottom: 1px solid rgba(255,255,255,.04); vertical-align: top; }
tbody tr:hover td { background: rgba(255,255,255,.03); }
tbody tr:last-child td { border-bottom: none; }

/* ── Modal ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.7); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 1rem; opacity: 0; pointer-events: none; transition: opacity .2s; }
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; width: 100%; max-width: 540px; max-height: 90vh; overflow-y: auto; }
.modal-lg { max-width: 720px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-title { font-size: 1rem; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--muted); font-size: 1.1rem; cursor: pointer; padding: .2rem .4rem; border-radius: 4px; }
.modal-close:hover { background: rgba(255,255,255,.1); color: var(--text); }
.modal-body { padding: 1.25rem; }
.modal-footer { padding: .9rem 1.25rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: .5rem; }

/* ── Toast ── */
.toast-container { position: fixed; bottom: 1.25rem; right: 1.25rem; display: flex; flex-direction: column; gap: .5rem; z-index: 9000; }
.toast { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: .7rem 1rem; font-size: .85rem; min-width: 220px; max-width: 340px; animation: slideIn .25s ease; display: flex; align-items: center; gap: .6rem; }
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.warning { border-left: 3px solid var(--warning); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── Alerts ── */
.alert { padding: .75rem 1rem; border-radius: 8px; font-size: .875rem; }
.alert-danger  { background: rgba(239,68,68,.15); border: 1px solid rgba(239,68,68,.3); color: #fca5a5; }
.alert-success { background: rgba(16,185,129,.15); border: 1px solid rgba(16,185,129,.3); color: #6ee7b7; }
.alert-warning { background: rgba(245,158,11,.15); border: 1px solid rgba(245,158,11,.3); color: #fcd34d; }
.mt-1 { margin-top: .5rem; }

/* ── Empty State ── */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty-icon { font-size: 2.5rem; margin-bottom: .75rem; }

/* ── Lead Card (Kanban style) ── */
.leads-board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
@media (max-width: 900px) { .leads-board { grid-template-columns: 1fr; } }
.board-col { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem; min-height: 300px; }
.board-col-header { font-size: .8rem; font-weight: 700; margin-bottom: .75rem; display: flex; align-items: center; gap: .5rem; }
.lead-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .75rem; margin-bottom: .5rem; cursor: pointer; transition: border-color .2s, transform .15s; }
.lead-card:hover { border-color: var(--primary); transform: translateY(-1px); }
.lead-card-name { font-weight: 600; font-size: .9rem; }
.lead-card-meta { font-size: .75rem; color: var(--muted); margin-top: .2rem; }

/* ── Progress ── */
.progress { height: 6px; background: rgba(255,255,255,.08); border-radius: 99px; overflow: hidden; }
.progress-bar { height: 100%; background: linear-gradient(90deg, var(--primary), var(--secondary)); border-radius: 99px; transition: width .4s; }

/* ── Conversations ── */
.conversation-wrap { max-height: 320px; overflow-y: auto; padding: .5rem; display: flex; flex-direction: column; gap: .5rem; }
.msg { max-width: 75%; padding: .55rem .8rem; border-radius: 10px; font-size: .85rem; line-height: 1.5; }
.msg.outbound { background: rgba(124,58,237,.25); border-bottom-right-radius: 3px; align-self: flex-end; }
.msg.inbound  { background: var(--surface2); border-bottom-left-radius: 3px; align-self: flex-start; }
.msg-meta { font-size: .68rem; color: var(--muted); margin-top: .2rem; }

/* ── Content Calendar ── */
.calendar-week { display: grid; grid-template-columns: repeat(7, 1fr); gap: .4rem; }
.cal-day-col { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; min-height: 120px; }
.cal-day-head { padding: .4rem .6rem; font-size: .72rem; font-weight: 700; color: var(--muted); border-bottom: 1px solid var(--border); }
.cal-content-item { padding: .3rem .5rem; margin: .3rem; border-radius: 4px; font-size: .7rem; cursor: pointer; }
.content-educativo      { background: rgba(6,182,212,.2); color: #67e8f9; }
.content-autoridad      { background: rgba(124,58,237,.2); color: #c4b5fd; }
.content-venta_indirecta { background: rgba(245,158,11,.2); color: #fcd34d; }
.content-testimonio     { background: rgba(16,185,129,.2); color: #6ee7b7; }

/* ── Script Card ── */
.script-card { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 1rem; margin-bottom: .75rem; }
.script-category { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; margin-bottom: .4rem; }
.script-title { font-size: .95rem; font-weight: 600; margin-bottom: .6rem; }
.script-content { font-size: .82rem; color: var(--muted); white-space: pre-wrap; line-height: 1.55; }

/* ── Misc ── */
.text-muted { color: var(--muted); }
.text-small { font-size: .8rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.gap-1 { gap: .5rem; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; }

/* ── Pipeline funnel ── */
.funnel-row { display: flex; gap: .5rem; margin-bottom: .5rem; align-items: center; font-size: .82rem; }
.funnel-bar { height: 22px; border-radius: 4px; min-width: 4px; background: linear-gradient(90deg, var(--primary), var(--secondary)); transition: width .5s; }
.funnel-label { white-space: nowrap; min-width: 120px; color: var(--muted); }
.funnel-count { min-width: 32px; text-align: right; font-weight: 600; }
