/* ============================================================
   AI Sales Bot — Admin Panel
   Premium design system: clean, spacious, modern
   ============================================================ */

/* --- Tokens --- */
:root {
    --bg: #F6F8FB;
    --surface: #FFFFFF;
    --surface-hover: #F9FAFB;
    --border: #E8ECF1;
    --border-light: #F1F4F8;
    --text: #111827;
    --text-secondary: #6B7280;
    --text-muted: #9CA3AF;
    --primary: #4F46E5;
    --primary-hover: #4338CA;
    --primary-light: #EEF2FF;
    --danger: #EF4444;
    --danger-hover: #DC2626;
    --success: #10B981;
    --warning: #F59E0B;
    --sidebar-bg: #0F172A;
    --sidebar-hover: #1E293B;
    --sidebar-active: linear-gradient(135deg, #4F46E5 0%, #7C3AED 100%);
    --sidebar-text: #94A3B8;
    --sidebar-text-active: #FFFFFF;
    --radius: 10px;
    --radius-lg: 14px;
    --radius-sm: 6px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04), 0 1px 3px rgba(0,0,0,0.06);
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 4px 12px rgba(0,0,0,0.04);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.08), 0 12px 40px rgba(0,0,0,0.04);
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Reset --- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body { font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); line-height: 1.6; font-size: 14px; }
a { color: var(--primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary-hover); }
img { max-width: 100%; }
hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* --- Typography --- */
h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.5px; color: var(--text); }
h2 { font-size: 20px; font-weight: 700; letter-spacing: -0.3px; }
h3 { font-size: 16px; font-weight: 600; letter-spacing: -0.2px; }
h4 { font-size: 14px; font-weight: 600; }

/* --- Layout --- */
.layout { display: flex; min-height: 100vh; }

/* --- Sidebar --- */
.sidebar {
    width: 260px; background: var(--sidebar-bg); color: var(--sidebar-text);
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 100;
    display: flex; flex-direction: column; overflow-y: auto;
    border-right: 1px solid rgba(255,255,255,0.06);
}
.sidebar-header {
    padding: 24px 20px 20px; display: flex; align-items: center; gap: 12px;
}
.sidebar-logo {
    width: 38px; height: 38px; border-radius: 10px;
    background: var(--sidebar-active); display: flex; align-items: center;
    justify-content: center; font-size: 18px; color: #fff; flex-shrink: 0;
}
.sidebar-brand h2 { font-size: 16px; font-weight: 700; color: #fff; letter-spacing: -0.3px; }
.sidebar-brand small { font-size: 11px; color: var(--sidebar-text); font-weight: 400; }

.sidebar-nav { flex: 1; padding: 8px 10px; }
.sidebar-nav a {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 14px; border-radius: 8px; font-size: 14px;
    color: var(--sidebar-text); transition: all var(--transition);
    margin-bottom: 2px; font-weight: 500;
}
.sidebar-nav a:hover { background: var(--sidebar-hover); color: #E2E8F0; text-decoration: none; }
.sidebar-nav a.active {
    background: var(--sidebar-active); color: var(--sidebar-text-active);
    box-shadow: 0 2px 8px rgba(79,70,229,0.35);
}
.sidebar-nav a .nav-icon {
    width: 20px; height: 20px; display: flex; align-items: center; justify-content: center;
    font-size: 16px; opacity: 0.7;
}
.sidebar-nav a.active .nav-icon { opacity: 1; }

.sidebar-footer {
    padding: 16px 20px; border-top: 1px solid rgba(255,255,255,0.06);
}
.sidebar-footer a {
    display: flex; align-items: center; gap: 8px;
    color: var(--sidebar-text); font-size: 13px; font-weight: 500;
    padding: 8px 4px; border-radius: 6px; transition: all var(--transition);
}
.sidebar-footer a:hover { color: #E2E8F0; text-decoration: none; }

/* --- Content --- */
.content { margin-left: 260px; flex: 1; padding: 32px 40px; max-width: 1400px; }

/* --- Page Header --- */
.page-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 28px;
}
.page-header h1 { margin: 0; }
.page-subtitle { color: var(--text-secondary); font-size: 14px; margin-top: 4px; }

/* --- Cards --- */
.card {
    background: var(--surface); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm); border: 1px solid var(--border-light);
    padding: 24px; transition: box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow); }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.card-header h3 { margin: 0; }

/* --- Stats --- */
.stats-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px; margin-bottom: 28px;
}
.stat-card {
    background: var(--surface); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm); border: 1px solid var(--border-light);
    padding: 20px 24px; transition: all var(--transition);
    position: relative; overflow: hidden;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-card .stat-icon {
    width: 42px; height: 42px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; margin-bottom: 14px;
}
.stat-card .stat-icon.blue { background: #EEF2FF; }
.stat-card .stat-icon.green { background: #ECFDF5; }
.stat-card .stat-icon.amber { background: #FFFBEB; }
.stat-card .stat-icon.rose { background: #FFF1F2; }
.stat-card .stat-icon.violet { background: #F5F3FF; }
.stat-card .stat-label { font-size: 13px; color: var(--text-secondary); font-weight: 500; margin-bottom: 6px; }
.stat-card .stat-value { font-size: 30px; font-weight: 800; color: var(--text); letter-spacing: -1px; line-height: 1; }
.stat-card .stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 6px; font-weight: 500; }
.stat-card .stat-sub.positive { color: var(--success); }

/* --- Badges --- */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 10px; border-radius: 20px; font-size: 12px;
    font-weight: 600; letter-spacing: 0.2px; white-space: nowrap;
}
.badge-dot {
    width: 6px; height: 6px; border-radius: 50%; display: inline-block;
}
.badge-greeting { background: #DBEAFE; color: #1E40AF; }
.badge-qualifying { background: #E0E7FF; color: #3730A3; }
.badge-presenting { background: #FEF3C7; color: #92400E; }
.badge-objection_handling { background: #FFE4E6; color: #9F1239; }
.badge-closing { background: #D1FAE5; color: #065F46; }
.badge-payment_sent { background: #CFFAFE; color: #155E75; }
.badge-completed { background: #D1FAE5; color: #065F46; }
.badge-lost { background: #FEE2E2; color: #B91C1C; }
.badge-escalated { background: #FFEDD5; color: #9A3412; }
.badge-instagram { background: linear-gradient(135deg, #fce4ec 0%, #e8eaf6 100%); color: #C2185B; }
.badge-whatsapp { background: #DCFCE7; color: #166534; }
.badge-active { background: #DCFCE7; color: #166534; }
.badge-inactive { background: #FEE2E2; color: #B91C1C; }
.badge-paused { background: #FEF9C3; color: #854D0E; }

/* --- Buttons --- */
button, .btn {
    cursor: pointer; border: none; border-radius: var(--radius-sm);
    padding: 9px 18px; font-size: 14px; font-weight: 600;
    font-family: inherit; display: inline-flex; align-items: center;
    gap: 6px; transition: all var(--transition); line-height: 1.4;
}
.btn-primary {
    background: var(--primary); color: #fff;
    box-shadow: 0 1px 2px rgba(79,70,229,0.3);
}
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(79,70,229,0.3); }
.btn-secondary { background: var(--surface); color: var(--text-secondary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--surface-hover); border-color: #D1D5DB; color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-ghost { background: transparent; color: var(--text-secondary); padding: 6px 10px; }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-sm { padding: 5px 12px; font-size: 13px; border-radius: 6px; }
.btn-icon { width: 36px; height: 36px; padding: 0; display: flex; align-items: center; justify-content: center; border-radius: 8px; }

/* --- Forms --- */
input, select, textarea {
    font-family: inherit; font-size: 14px; padding: 10px 14px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    width: 100%; background: var(--surface); color: var(--text);
    transition: all var(--transition); line-height: 1.5;
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.12);
}
input::placeholder, textarea::placeholder { color: var(--text-muted); }
textarea { resize: vertical; min-height: 80px; }
select { cursor: pointer; }
input[type="checkbox"] { width: auto; margin-right: 8px; accent-color: var(--primary); }

.form-group { margin-bottom: 18px; }
.form-group label {
    display: block; font-size: 13px; font-weight: 600;
    color: var(--text-secondary); margin-bottom: 6px;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* --- Tables --- */
table { width: 100%; border-collapse: separate; border-spacing: 0; }
th {
    padding: 12px 16px; text-align: left; font-size: 12px;
    font-weight: 600; color: var(--text-muted); text-transform: uppercase;
    letter-spacing: 0.6px; border-bottom: 1px solid var(--border);
    background: var(--surface-hover);
}
th:first-child { border-radius: var(--radius-sm) 0 0 0; }
th:last-child { border-radius: 0 var(--radius-sm) 0 0; }
td {
    padding: 14px 16px; border-bottom: 1px solid var(--border-light);
    font-size: 14px; vertical-align: middle;
}
tbody tr { transition: background var(--transition); cursor: default; }
tbody tr:hover { background: var(--surface-hover); }
tbody tr:last-child td { border-bottom: none; }
.table-clickable tr { cursor: pointer; }

/* --- Chat --- */
.chat-container {
    max-height: 640px; overflow-y: auto; padding: 20px;
    display: flex; flex-direction: column; gap: 10px;
    background: #FAFBFC; border-radius: var(--radius); border: 1px solid var(--border-light);
}
.chat-msg {
    max-width: 75%; padding: 12px 16px; font-size: 14px;
    line-height: 1.6; word-wrap: break-word; position: relative;
    animation: msgIn 0.2s ease-out;
}
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.chat-msg.user {
    align-self: flex-start; background: var(--surface); color: var(--text);
    border-radius: 4px 16px 16px 16px;
    border: 1px solid var(--border-light); box-shadow: var(--shadow-sm);
}
.chat-msg.bot {
    align-self: flex-end;
    background: linear-gradient(135deg, #4F46E5 0%, #6366F1 100%);
    color: #fff; border-radius: 16px 4px 16px 16px;
    box-shadow: 0 2px 8px rgba(79,70,229,0.25);
}
.chat-msg.system {
    align-self: center; background: #FEF9C3; color: #854D0E;
    font-size: 12px; border-radius: 20px; padding: 6px 16px;
    border: 1px solid #FDE68A;
}
.chat-meta { font-size: 11px; color: var(--text-muted); margin-top: 6px; }
.chat-msg.bot .chat-meta { color: rgba(255,255,255,0.65); }
.chat-msg.user .chat-label { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; font-weight: 600; }
.chat-msg.bot .chat-label { font-size: 11px; color: rgba(255,255,255,0.7); margin-bottom: 4px; font-weight: 600; }

.chat-input {
    display: flex; gap: 10px; margin-top: 16px; padding-top: 16px;
    border-top: 1px solid var(--border-light);
}
.chat-input input { flex: 1; border-radius: 20px; padding: 10px 18px; }
.chat-input button { border-radius: 20px; padding: 10px 20px; }

/* --- Detail Layout --- */
.detail-layout { display: grid; grid-template-columns: 360px 1fr; gap: 24px; align-items: start; }
.info-card { position: sticky; top: 32px; }
.info-card .field { margin-bottom: 16px; }
.info-card .field-label {
    font-size: 11px; font-weight: 600; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px;
}
.info-card .field-value { font-size: 14px; font-weight: 500; color: var(--text); }
.info-card .divider { height: 1px; background: var(--border); margin: 20px 0; }

/* --- Filters --- */
.filters {
    display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
}
.filters input, .filters select { width: auto; min-width: 180px; }

/* --- Grid --- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }

/* --- Knowledge Cards --- */
.knowledge-card {
    background: var(--surface); border-radius: var(--radius);
    box-shadow: var(--shadow-sm); border: 1px solid var(--border-light);
    padding: 20px; transition: all var(--transition);
}
.knowledge-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.knowledge-card h4 { font-size: 14px; color: var(--text); margin-bottom: 8px; line-height: 1.4; }
.knowledge-card p { font-size: 13px; color: var(--text-secondary); line-height: 1.6; }
.knowledge-card .card-footer {
    margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border-light);
    display: flex; justify-content: space-between; align-items: center;
}

/* --- Settings --- */
.settings-section { margin-bottom: 28px; }
.settings-section > .card { padding: 28px; }
.settings-section h3 {
    font-size: 17px; font-weight: 700; margin-bottom: 20px;
    padding-bottom: 12px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 10px;
}
.settings-section h3 .section-icon { font-size: 20px; }

/* --- Modal --- */
.modal-overlay {
    display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15,23,42,0.6); backdrop-filter: blur(4px);
    z-index: 1000; justify-content: center; align-items: center;
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--surface); border-radius: var(--radius-lg);
    padding: 28px; max-width: 520px; width: 92%;
    max-height: 85vh; overflow-y: auto;
    box-shadow: var(--shadow-lg); animation: modalIn 0.2s ease-out;
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.95) translateY(10px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.modal h3 { margin-bottom: 20px; font-size: 18px; }

/* --- Login --- */
.login-container {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #0F172A 0%, #1E1B4B 50%, #0F172A 100%);
}
.login-box {
    background: var(--surface); border-radius: 16px;
    padding: 44px 40px; width: 400px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.3);
}
.login-box .login-logo {
    width: 50px; height: 50px; border-radius: 12px;
    background: var(--sidebar-active); display: flex;
    align-items: center; justify-content: center;
    font-size: 24px; color: #fff; margin-bottom: 24px;
}
.login-box h1 { font-size: 26px; margin-bottom: 6px; letter-spacing: -0.5px; }
.login-box p { color: var(--text-secondary); margin-bottom: 28px; font-size: 15px; }
.login-box .error {
    background: #FEF2F2; color: #DC2626; font-size: 13px;
    padding: 10px 14px; border-radius: var(--radius-sm);
    margin-bottom: 16px; border: 1px solid #FECACA;
}
.login-box .btn-primary { width: 100%; padding: 12px; font-size: 15px; border-radius: 8px; justify-content: center; }

/* --- Alerts --- */
.alert {
    padding: 14px 18px; border-radius: var(--radius-sm);
    margin-bottom: 20px; font-size: 14px; font-weight: 500;
    display: flex; align-items: center; gap: 10px;
}
.alert-success { background: #ECFDF5; color: #065F46; border: 1px solid #A7F3D0; }
.alert-error { background: #FEF2F2; color: #B91C1C; border: 1px solid #FECACA; }

/* --- Empty State --- */
.empty-state {
    text-align: center; padding: 60px 24px; color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.5; }
.empty-state p { font-size: 15px; }

/* --- Funnel bar --- */
.funnel-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 0; border-bottom: 1px solid var(--border-light);
}
.funnel-item:last-child { border-bottom: none; }
.funnel-bar {
    flex: 1; height: 8px; background: var(--border-light);
    border-radius: 4px; overflow: hidden;
}
.funnel-bar-fill {
    height: 100%; border-radius: 4px;
    background: linear-gradient(90deg, #4F46E5, #7C3AED);
    transition: width 0.6s ease;
}
.funnel-count { font-weight: 700; font-size: 15px; min-width: 30px; text-align: right; }

/* --- Activity feed --- */
.activity-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 0; border-bottom: 1px solid var(--border-light);
    font-size: 13px;
}
.activity-item:last-child { border-bottom: none; }
.activity-dot {
    width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.activity-dot.comment { background: #F59E0B; }
.activity-dot.dm { background: #4F46E5; }
.activity-dot.stage { background: #10B981; }
.activity-dot.payment { background: #06B6D4; }
.activity-dot.escalation { background: #EF4444; }
.activity-dot.salesman { background: #8B5CF6; }
.activity-dot.default { background: #9CA3AF; }
.activity-text { flex: 1; color: var(--text-secondary); }
.activity-time { color: var(--text-muted); font-size: 12px; white-space: nowrap; }

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #D1D5DB; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #9CA3AF; }

/* --- Responsive --- */
@media (max-width: 1024px) {
    .sidebar { width: 220px; }
    .content { margin-left: 220px; padding: 24px; }
    .detail-layout { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
}
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); transition: transform 0.3s ease; position: fixed; width: 260px; }
    .sidebar.open { transform: translateX(0); }
    .content { margin-left: 0; padding: 16px; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .grid-2 { grid-template-columns: 1fr; }
    .mobile-toggle { display: block !important; }
}
.mobile-toggle { display: none; }
