*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue: #1e40af;
  --blue-light: #3b82f6;
  --blue-dark: #1e3a8a;
  --green: #16a34a;
  --red: #dc2626;
  --yellow: #d97706;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;
  --sidebar-w: 220px;
  --panel-w: 420px;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-lg: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
}

body { font-family: 'Inter', system-ui, sans-serif; background: var(--gray-50); color: var(--gray-800); height: 100vh; overflow: hidden; }

/* LOGIN */
.login-screen { display: flex; align-items: center; justify-content: center; height: 100vh; background: linear-gradient(135deg, var(--gray-900) 0%, var(--blue-dark) 100%); }
.login-box { background: white; border-radius: 16px; padding: 40px; width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 24px; font-size: 20px; font-weight: 700; color: var(--gray-900); }
.login-box h2 { font-size: 22px; font-weight: 600; color: var(--gray-700); margin-bottom: 20px; }
.login-box input { width: 100%; padding: 12px 14px; border: 1.5px solid var(--gray-200); border-radius: var(--radius); font-size: 14px; margin-bottom: 12px; outline: none; transition: border .15s; }
.login-box input:focus { border-color: var(--blue-light); }
.login-box button { width: 100%; padding: 13px; background: var(--blue); color: white; border: none; border-radius: var(--radius); font-size: 15px; font-weight: 600; cursor: pointer; transition: background .15s; }
.login-box button:hover { background: var(--blue-dark); }
.error-msg { background: #fee2e2; color: var(--red); padding: 10px 14px; border-radius: var(--radius); font-size: 13px; margin-bottom: 12px; }

/* APP LAYOUT */
#app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; height: 100vh; }

/* SIDEBAR */
.sidebar { background: var(--gray-900); color: white; display: flex; flex-direction: column; height: 100vh; overflow-y: auto; }
.sidebar-logo { display: flex; align-items: center; gap: 10px; padding: 20px 16px; font-size: 15px; font-weight: 700; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar-nav { padding: 12px 8px; flex: 1; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--radius); color: var(--gray-400); text-decoration: none; font-size: 14px; font-weight: 500; cursor: pointer; transition: all .15s; margin-bottom: 2px; }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: rgba(255,255,255,.06); color: white; }
.nav-item.active { background: var(--blue); color: white; }
.badge { background: var(--red); color: white; border-radius: 10px; padding: 2px 6px; font-size: 11px; font-weight: 700; margin-left: auto; }
.sidebar-bottom { padding: 12px 8px; border-top: 1px solid rgba(255,255,255,.08); display: flex; align-items: center; gap: 8px; }
.user-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--blue); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }
.user-name { font-size: 13px; font-weight: 600; color: white; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 130px; }
.user-role { font-size: 11px; color: var(--gray-500); }
.logout-btn { background: none; border: none; color: var(--gray-500); cursor: pointer; padding: 6px; border-radius: 6px; transition: all .15s; margin-left: auto; flex-shrink: 0; }
.logout-btn:hover { background: rgba(255,255,255,.08); color: white; }
.logout-btn svg { width: 16px; height: 16px; }

/* MAIN */
.main { display: flex; flex-direction: column; overflow: hidden; height: 100vh; }
.view { display: none; flex-direction: column; height: 100%; overflow: hidden; }
.view.active { display: flex; }
.view-header { padding: 20px 24px 16px; border-bottom: 1px solid var(--gray-200); background: white; }
.view-header h1 { font-size: 22px; font-weight: 700; color: var(--gray-900); margin-bottom: 12px; }
.header-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.search-input { flex: 1; min-width: 200px; padding: 8px 12px; border: 1.5px solid var(--gray-200); border-radius: var(--radius); font-size: 13px; outline: none; }
.search-input:focus { border-color: var(--blue-light); }
.filter-select { padding: 8px 10px; border: 1.5px solid var(--gray-200); border-radius: var(--radius); font-size: 13px; background: white; cursor: pointer; outline: none; }

/* STATS */
.stats-bar { display: flex; gap: 0; background: white; border-bottom: 1px solid var(--gray-200); padding: 0 24px; overflow-x: auto; }
.stat-item { display: flex; flex-direction: column; align-items: center; padding: 12px 20px; border-right: 1px solid var(--gray-100); cursor: pointer; transition: background .15s; white-space: nowrap; }
.stat-item:hover { background: var(--gray-50); }
.stat-num { font-size: 22px; font-weight: 700; color: var(--gray-900); }
.stat-label { font-size: 11px; color: var(--gray-500); text-transform: uppercase; letter-spacing: .05em; margin-top: 2px; }

/* LEADS TABLE */
.leads-table-wrap { flex: 1; overflow-y: auto; }
.leads-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.leads-table thead th { position: sticky; top: 0; background: white; padding: 10px 16px; text-align: left; font-size: 11px; font-weight: 600; color: var(--gray-500); text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--gray-200); white-space: nowrap; }
.leads-table tbody tr { border-bottom: 1px solid var(--gray-100); cursor: pointer; transition: background .1s; }
.leads-table tbody tr:hover { background: var(--gray-50); }
.leads-table td { padding: 11px 16px; vertical-align: middle; }
.loading-row { text-align: center; color: var(--gray-400); padding: 40px !important; }
.lead-name { font-weight: 600; color: var(--gray-900); }
.lead-phone { color: var(--gray-600); }
.unread-dot { display: inline-block; width: 8px; height: 8px; background: var(--blue-light); border-radius: 50%; margin-left: 6px; vertical-align: middle; }

/* STATUS BADGES */
.status-badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; text-transform: capitalize; }
.status-nuevo { background: #dbeafe; color: #1d4ed8; }
.status-contactado { background: #fef3c7; color: #92400e; }
.status-propuesta { background: #e0e7ff; color: #3730a3; }
.status-negociacion { background: #fce7f3; color: #9d174d; }
.status-matriculado { background: #dcfce7; color: #15803d; }
.status-perdido { background: var(--gray-100); color: var(--gray-500); }

.pagination { padding: 12px 24px; background: white; border-top: 1px solid var(--gray-200); display: flex; gap: 6px; align-items: center; justify-content: flex-end; font-size: 13px; }
.page-btn { padding: 5px 10px; border: 1.5px solid var(--gray-200); border-radius: 6px; background: white; cursor: pointer; font-size: 13px; }
.page-btn:disabled { opacity: .4; cursor: default; }
.page-btn.active { background: var(--blue); color: white; border-color: var(--blue); }

/* LEAD PANEL */
.lead-panel { position: fixed; right: 0; top: 0; bottom: 0; width: var(--panel-w); background: white; border-left: 1px solid var(--gray-200); z-index: 100; display: flex; flex-direction: column; box-shadow: -4px 0 20px rgba(0,0,0,.08); overflow: hidden; }
.lead-panel-header { padding: 20px; border-bottom: 1px solid var(--gray-200); display: flex; align-items: flex-start; justify-content: space-between; background: white; flex-shrink: 0; }
.lead-panel-header h2 { font-size: 18px; font-weight: 700; color: var(--gray-900); }
.lp-phone { font-size: 14px; color: var(--blue-light); font-weight: 500; }
.close-panel { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--gray-400); padding: 4px; border-radius: 4px; line-height: 1; }
.close-panel:hover { background: var(--gray-100); }
.lead-panel-body { flex: 1; overflow-y: auto; padding-bottom: 20px; }
.lp-section { padding: 16px 20px; border-bottom: 1px solid var(--gray-100); }
.lp-section h4 { font-size: 12px; font-weight: 600; color: var(--gray-500); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 12px; }
.lp-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.lp-field { display: flex; flex-direction: column; gap: 4px; }
.lp-field label { font-size: 11px; font-weight: 600; color: var(--gray-500); text-transform: uppercase; letter-spacing: .03em; }
.lp-field input, .lp-field select { padding: 7px 10px; border: 1.5px solid var(--gray-200); border-radius: 6px; font-size: 13px; outline: none; }
.lp-field input:focus, .lp-field select:focus { border-color: var(--blue-light); }
.btn-save { margin-top: 12px; padding: 8px 16px; background: var(--blue); color: white; border: none; border-radius: var(--radius); font-size: 13px; font-weight: 600; cursor: pointer; }
.btn-save:hover { background: var(--blue-dark); }
textarea#lp-notes { width: 100%; padding: 10px; border: 1.5px solid var(--gray-200); border-radius: var(--radius); font-size: 13px; resize: vertical; min-height: 80px; outline: none; font-family: inherit; }
textarea#lp-notes:focus { border-color: var(--blue-light); }

/* CHAT */
.lp-chat { height: 200px; overflow-y: auto; background: var(--gray-50); border-radius: var(--radius); padding: 10px; margin-bottom: 10px; display: flex; flex-direction: column; gap: 6px; }
.chat-msg { max-width: 80%; padding: 8px 12px; border-radius: 12px; font-size: 13px; line-height: 1.4; }
.chat-msg.in { background: white; border: 1px solid var(--gray-200); align-self: flex-start; }
.chat-msg.out { background: var(--blue); color: white; align-self: flex-end; }
.chat-msg .msg-time { font-size: 10px; opacity: .6; margin-top: 3px; }
.chat-empty { text-align: center; color: var(--gray-400); font-size: 12px; margin: auto; }
.lp-chat-input { display: flex; gap: 8px; }
.lp-chat-input input { flex: 1; padding: 8px 12px; border: 1.5px solid var(--gray-200); border-radius: var(--radius); font-size: 13px; outline: none; }
.lp-chat-input input:focus { border-color: var(--blue-light); }
.lp-chat-input button { padding: 8px 14px; background: var(--blue); color: white; border: none; border-radius: var(--radius); cursor: pointer; }
.wa-session-selector { margin-top: 6px; font-size: 12px; color: var(--gray-500); }
.wa-session-selector select { border: 1px solid var(--gray-200); border-radius: 4px; padding: 2px 6px; font-size: 12px; }

/* ACTIVITY */
.activity-list { display: flex; flex-direction: column; gap: 8px; }
.activity-item { display: flex; gap: 10px; align-items: flex-start; }
.activity-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--blue-light); flex-shrink: 0; margin-top: 5px; }
.activity-dot.nota { background: var(--yellow); }
.activity-dot.estado { background: var(--green); }
.activity-content { font-size: 12px; color: var(--gray-600); }
.activity-time { font-size: 11px; color: var(--gray-400); margin-top: 2px; }

/* BUTTONS */
.btn-primary { padding: 8px 16px; background: var(--blue); color: white; border: none; border-radius: var(--radius); font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-primary:disabled { opacity: .5; cursor: default; }
.btn-secondary { padding: 8px 14px; background: white; color: var(--gray-700); border: 1.5px solid var(--gray-200); border-radius: var(--radius); font-size: 13px; font-weight: 500; cursor: pointer; }
.btn-secondary:hover { border-color: var(--gray-400); }
.btn-ghost { padding: 8px 14px; background: transparent; color: var(--gray-600); border: none; font-size: 13px; cursor: pointer; border-radius: var(--radius); }
.btn-ghost:hover { background: var(--gray-100); }
.btn-assign { padding: 4px 10px; background: white; color: var(--blue); border: 1.5px solid var(--blue); border-radius: 6px; font-size: 12px; cursor: pointer; }
.btn-assign:hover { background: var(--blue); color: white; }

/* KANBAN */
.kanban { display: flex; gap: 16px; padding: 20px 24px; overflow-x: auto; height: 100%; align-items: flex-start; }
.kanban-col { background: var(--gray-100); border-radius: 12px; padding: 12px; min-width: 220px; width: 220px; flex-shrink: 0; }
.kanban-col-header { font-size: 12px; font-weight: 700; color: var(--gray-600); text-transform: uppercase; letter-spacing: .04em; padding-bottom: 10px; display: flex; justify-content: space-between; align-items: center; }
.kanban-col-header .col-count { background: white; border-radius: 10px; padding: 2px 7px; font-size: 11px; color: var(--gray-500); }
.kanban-cards { display: flex; flex-direction: column; gap: 8px; }
.kanban-card { background: white; border-radius: 8px; padding: 12px; box-shadow: var(--shadow); cursor: pointer; transition: box-shadow .15s; }
.kanban-card:hover { box-shadow: var(--shadow-lg); }
.kanban-card-name { font-weight: 600; font-size: 13px; color: var(--gray-900); }
.kanban-card-phone { font-size: 12px; color: var(--gray-500); margin-top: 3px; }
.kanban-card-meta { display: flex; justify-content: space-between; margin-top: 8px; font-size: 11px; color: var(--gray-400); }

/* WHATSAPP VIEW */
.wa-container { padding: 24px; display: flex; gap: 24px; flex-wrap: wrap; }
.wa-sessions { background: white; border-radius: 12px; padding: 20px; border: 1px solid var(--gray-200); min-width: 280px; }
.wa-sessions h3 { font-size: 15px; font-weight: 700; margin-bottom: 16px; color: var(--gray-900); }
.wa-sessions button { display: block; width: 100%; margin-bottom: 8px; }
.wa-session-item { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 8px; background: var(--gray-50); margin-bottom: 8px; font-size: 13px; }
.wa-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.wa-dot.ready { background: var(--green); }
.wa-dot.loading, .wa-dot.qr { background: var(--yellow); }
.wa-dot.disconnected, .wa-dot.error { background: var(--gray-300); }
.wa-qr-area { background: white; border-radius: 12px; padding: 24px; border: 1px solid var(--gray-200); text-align: center; }
.wa-qr-area h3 { font-size: 15px; font-weight: 700; margin-bottom: 8px; }
.wa-qr-area p { font-size: 13px; color: var(--gray-500); margin-bottom: 16px; }
#wa-qr-img img { border: 8px solid white; box-shadow: var(--shadow-lg); border-radius: 8px; }

/* IMPORT */
.import-container { padding: 24px; display: flex; justify-content: center; }
.import-box { background: white; border-radius: 12px; padding: 32px; border: 1px solid var(--gray-200); max-width: 500px; width: 100%; text-align: center; }
.import-icon { font-size: 48px; margin-bottom: 12px; }
.import-box h3 { font-size: 18px; font-weight: 700; margin-bottom: 8px; color: var(--gray-900); }
.import-box p { font-size: 13px; color: var(--gray-600); margin-bottom: 8px; }
.hint { font-size: 12px; color: var(--gray-400); }
.import-assign { display: flex; align-items: center; gap: 10px; margin: 16px 0 8px; font-size: 13px; color: var(--gray-600); }
.import-assign select { flex: 1; padding: 8px; border: 1.5px solid var(--gray-200); border-radius: 6px; font-size: 13px; }
.file-drop { display: flex; flex-direction: column; align-items: center; gap: 10px; border: 2px dashed var(--gray-300); border-radius: 12px; padding: 32px 20px; cursor: pointer; transition: border-color .15s; margin: 16px 0; color: var(--gray-500); font-size: 13px; }
.file-drop:hover, .file-drop.drag-over { border-color: var(--blue-light); }
.file-drop input { display: none; }
.import-result { padding: 14px; border-radius: var(--radius); font-size: 13px; font-weight: 500; margin-top: 12px; }
.import-result.success { background: #dcfce7; color: #15803d; }
.import-result.error { background: #fee2e2; color: var(--red); }

/* MODAL */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 200; }
.modal { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: white; border-radius: 12px; padding: 28px; width: 440px; z-index: 201; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.modal h3 { font-size: 18px; font-weight: 700; margin-bottom: 20px; color: var(--gray-900); }
.modal-fields { display: flex; flex-direction: column; gap: 10px; }
.modal-fields input, .modal-fields select { padding: 10px 12px; border: 1.5px solid var(--gray-200); border-radius: var(--radius); font-size: 13px; outline: none; width: 100%; }
.modal-fields input:focus, .modal-fields select:focus { border-color: var(--blue-light); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* RESPONSIVE */
@media (max-width: 900px) {
  :root { --sidebar-w: 60px; --panel-w: 100vw; }
  .sidebar-logo span, .nav-item span, .user-name, .user-role { display: none; }
  .nav-item { justify-content: center; }
  .sidebar-bottom { justify-content: center; }
  .logout-btn { margin-left: 0; }
}

/* SCROLLBAR */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }
