@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --bg-color: #0f172a;
    --surface-color: rgba(30, 41, 59, 0.7);
    --surface-border: rgba(255, 255, 255, 0.1);
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --success: #10b981;
    --success-hover: #059669;
    --whatsapp: #25D366;
    --whatsapp-hover: #128C7E;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --danger: #ef4444;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
}

body {
    background: var(--bg-color);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* =============================================
   GLASS PANEL
   ============================================= */
.glass-panel {
    background: var(--surface-color);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--surface-border);
    border-radius: 12px;
}

/* =============================================
   MOBILE TOP BAR (hidden on desktop)
   ============================================= */
.mobile-topbar {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--surface-color);
    border-bottom: 1px solid var(--surface-border);
    position: sticky;
    top: 0;
    z-index: 200;
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
}

.mobile-logo {
    font-size: 1rem;
    font-weight: 700;
    background: linear-gradient(135deg, #60a5fa, #a78bfa);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Hamburger button */
.hamburger {
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 4px;
}

.hamburger span {
    display: block;
    width: 24px;
    height: 2px;
    background: var(--text-main);
    border-radius: 2px;
    transition: all 0.3s;
}

.hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* Sidebar Overlay (mobile) */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 150;
    opacity: 0;
    transition: opacity 0.3s;
}
.sidebar-overlay.active {
    opacity: 1;
}

/* =============================================
   SIDEBAR
   ============================================= */
.sidebar {
    width: 260px;
    height: 100vh;
    border-right: 1px solid var(--surface-border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    flex-shrink: 0;
    border-radius: 0;
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid var(--surface-border);
}

.sidebar-header h2 {
    font-size: 1.1rem;
    background: linear-gradient(135deg, #60a5fa, #a78bfa);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sidebar-nav {
    padding: 16px 12px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
}

.nav-item {
    padding: 12px 16px;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
    font-size: 0.95rem;
}

.nav-item:hover, .nav-item.active {
    background: rgba(59, 130, 246, 0.12);
    color: var(--primary);
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--surface-border);
}

/* =============================================
   MAIN CONTENT
   ============================================= */
.main-content {
    flex: 1;
    padding: 32px;
    overflow-y: auto;
    min-height: 100vh;
}

/* =============================================
   AUTH / LOGIN
   ============================================= */
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

.auth-box {
    width: 100%;
    max-width: 420px;
    padding: 40px;
    text-align: center;
}

.auth-logo {
    font-size: 3rem;
    margin-bottom: 12px;
}

.auth-box h2 {
    font-size: 1.5rem;
    background: linear-gradient(135deg, #60a5fa, #a78bfa);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 8px;
}

.auth-box p {
    color: var(--text-muted);
    margin-bottom: 24px;
    font-size: 0.9rem;
}

/* Auth tabs */
.auth-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--surface-border);
    padding-bottom: 0;
}

.auth-tab {
    flex: 1;
    padding: 10px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
    margin-bottom: -1px;
}

.auth-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* =============================================
   FORM ELEMENTS
   ============================================= */
.form-group {
    margin-bottom: 16px;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--surface-border);
    border-radius: 6px;
    color: var(--text-main);
    transition: 0.2s;
    font-size: 1rem;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

textarea.form-control {
    resize: vertical;
    min-height: 80px;
}

select.form-control option {
    background: #1e293b;
}

/* =============================================
   BUTTONS
   ============================================= */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-weight: 500;
    cursor: pointer;
    transition: 0.2s;
    font-size: 0.95rem;
    text-decoration: none;
    color: var(--text-main);
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); }

.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: var(--success-hover); }

.btn-whatsapp { background: var(--whatsapp); color: white; }
.btn-whatsapp:hover { background: var(--whatsapp-hover); }

.logout-btn { background: rgba(239,68,68,0.1); color: #ef4444; border: 1px solid rgba(239,68,68,0.2); }
.logout-btn:hover { background: rgba(239,68,68,0.2); }

/* =============================================
   TABS
   ============================================= */
.tab-content { display: none; animation: fadeIn 0.3s ease; }
.tab-content.active { display: block; }

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 28px;
    gap: 12px;
}

.page-header h1 {
    font-size: 1.6rem;
    font-weight: 700;
}

/* =============================================
   DASHBOARD METRICS
   ============================================= */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 28px;
}

.metric-card {
    padding: 24px;
    text-align: left;
    border-left: 4px solid var(--primary);
}

.metric-title {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    font-weight: 500;
}

.metric-value {
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--text-main);
}

.dashboard-widgets {
    display: flex;
    gap: 20px;
}

.widget { padding: 24px; }

/* =============================================
   FILTERS BAR
   ============================================= */
.filters-bar {
    width: 100%;
    padding: 12px 16px;
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.filters-bar input { flex: 1; min-width: 180px; }
.filters-bar select { width: auto; min-width: 150px; }

/* =============================================
   REMINDERS LIST
   ============================================= */
.reminders-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.rem-item {
    padding: 14px 16px;
    background: rgba(15, 23, 42, 0.4);
    border-radius: 8px;
    border-left: 4px solid #f59e0b;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.rem-item.completed {
    opacity: 0.6;
    border-left-color: var(--success);
    text-decoration: line-through;
}

/* =============================================
   LEADS TABLE
   ============================================= */
.crm-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.crm-table th {
    padding: 14px 16px;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    border-bottom: 1px solid var(--surface-border);
    white-space: nowrap;
}

.crm-table td {
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    font-size: 0.9rem;
}

.crm-table tbody tr { transition: background 0.2s; cursor: pointer; }
.crm-table tbody tr:hover { background: rgba(255, 255, 255, 0.03); }

/* =============================================
   MOBILE LEAD CARDS (shown only on mobile)
   ============================================= */
.lead-cards { display: none; flex-direction: column; gap: 12px; }

.lead-card {
    background: var(--surface-color);
    border: 1px solid var(--surface-border);
    border-radius: 12px;
    padding: 16px;
    cursor: pointer;
    transition: all 0.2s;
    border-left: 4px solid var(--primary);
}

.lead-card:hover { background: rgba(30, 41, 59, 0.9); transform: translateY(-1px); }
.lead-card-name { font-size: 1.05rem; font-weight: 700; color: white; }
.lead-card-phone { font-size: 0.85rem; color: var(--text-muted); margin-top: 4px; }
.lead-card-meta { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; align-items: center; }
.lead-card-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* =============================================
   BADGES
   ============================================= */
.badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 500;
    white-space: nowrap;
}

.badge.high { background: rgba(239, 68, 68, 0.2); color: #ef4444; }
.badge.medium { background: rgba(245, 158, 11, 0.2); color: #f59e0b; }
.badge.low { background: rgba(16, 185, 129, 0.2); color: #10b981; }

.status-badge {
    background: rgba(59, 130, 246, 0.12);
    color: #60a5fa;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.78rem;
    white-space: nowrap;
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 32px 20px;
    font-size: 0.9rem;
}

/* =============================================
   FORM SECTIONS (Modals)
   ============================================= */
.form-section {
    padding: 24px;
    border-bottom: 1px solid var(--surface-border);
}

.form-section h3 {
    margin-bottom: 16px;
    font-size: 1rem;
    color: #60a5fa;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.checkbox-grid label {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-main);
    font-weight: normal;
    cursor: pointer;
    font-size: 0.9rem;
}

.checkbox-grid input { width: 15px; height: 15px; flex-shrink: 0; }

/* =============================================
   MODALS
   ============================================= */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: 0.3s;
    z-index: 500;
    padding: 16px;
}

.modal-overlay.active { opacity: 1; pointer-events: all; }

.modal-content {
    background: #1e293b;
    width: 100%;
    border-radius: 12px;
    border: 1px solid var(--surface-border);
    display: flex;
    flex-direction: column;
    transform: translateY(20px);
    transition: 0.3s;
    max-height: 95vh;
    overflow: hidden;
}

.modal-overlay.active .modal-content { transform: translateY(0); }

.modal-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--surface-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.modal-title { font-size: 1.15rem; font-weight: 600; }

.close-modal {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    padding: 4px;
}

.modal-body { overflow-y: auto; flex: 1; }

/* Lead Profile Modal — two panels side by side */
.lead-profile-modal {
    max-width: 1000px;
    max-height: 95vh;
    flex-direction: row;
}

.lead-profile-left {
    flex: 1;
    border-right: 1px solid var(--surface-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.lead-profile-right {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: rgba(15, 23, 42, 0.2);
    overflow: hidden;
    min-width: 0;
}

/* =============================================
   TIMELINE
   ============================================= */
.timeline {
    display: flex;
    flex-direction: column;
    gap: 14px;
    position: relative;
    padding-left: 20px;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 4px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--surface-border);
}

.t-item {
    position: relative;
    background: rgba(15, 23, 42, 0.4);
    padding: 14px;
    border-radius: 8px;
    border: 1px solid var(--surface-border);
}

.t-item::before {
    content: '';
    position: absolute;
    left: -20px;
    top: 18px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--primary);
    box-shadow: 0 0 0 4px #1e293b;
}

.t-type { font-size: 0.7rem; color: #a78bfa; font-weight: 600; text-transform: uppercase; margin-bottom: 4px; }
.t-date { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 6px; }
.t-text { font-size: 0.9rem; line-height: 1.5; }

/* =============================================
   ADMIN PANEL
   ============================================= */
.user-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    background: rgba(15, 23, 42, 0.4);
    border-radius: 8px;
    margin-bottom: 8px;
    flex-wrap: wrap;
    gap: 10px;
}

.user-info { display: flex; flex-direction: column; gap: 4px; }
.user-name { font-weight: 600; color: white; }
.user-meta { font-size: 0.8rem; color: var(--text-muted); }
.role-badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 0.75rem; font-weight: 500; }
.role-badge.admin { background: rgba(168,85,247,0.2); color: #a855f7; }
.role-badge.user { background: rgba(59,130,246,0.2); color: #60a5fa; }

/* =============================================
   TOAST NOTIFICATION
   ============================================= */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--success);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
    transform: translateY(120px);
    opacity: 0;
    transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 9999;
    font-weight: 500;
    max-width: calc(100vw - 48px);
}

.toast.error { background: var(--danger); }

/* =============================================
   ALERT BANNERS
   ============================================= */
.alert {
    padding: 12px 16px;
    border-radius: 6px;
    font-size: 0.875rem;
    display: none;
}

.alert.error { background: rgba(239,68,68,0.1); color: #f87171; display: block; }

/* =============================================
   ANIMATIONS
   ============================================= */
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* =============================================
   RESPONSIVE - TABLET (768px)
   ============================================= */
@media (max-width: 1024px) {
    .metrics-grid { grid-template-columns: repeat(2, 1fr); }
    .dashboard-widgets { flex-direction: column; }
}

/* =============================================
   RESPONSIVE - MOBILE (768px and below)
   ============================================= */
@media (max-width: 768px) {
    /* Show mobile top bar */
    .mobile-topbar { display: flex; }

    /* Sidebar becomes floating drawer */
    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        height: 100vh;
        z-index: 160;
        transition: left 0.3s ease;
        width: 270px;
        border-radius: 0 12px 12px 0;
    }

    .sidebar.open { left: 0; }

    .sidebar-overlay { display: block; }

    /* App layout stacks vertically */
    #appView {
        flex-direction: column !important;
    }

    .main-content {
        padding: 16px;
        min-height: calc(100vh - 56px);
    }

    /* Page header */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        margin-bottom: 20px;
    }

    .page-header h1 { font-size: 1.3rem; }

    /* Metrics */
    .metrics-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
    .metric-value { font-size: 1.8rem; }
    .metric-card { padding: 16px; }

    /* Dashboard widgets stacked */
    .dashboard-widgets { flex-direction: column; gap: 14px; }
    .widget { padding: 16px; }

    /* Filters bar */
    .filters-bar { flex-direction: column; gap: 10px; padding: 12px; }
    .filters-bar input, .filters-bar select { width: 100%; min-width: unset; }

    /* Hide table, show cards */
    #leadsTableContainer { display: none !important; }
    #leadsCardContainer { display: flex !important; }
    #trashTableContainer { display: none !important; }
    #trashCardContainer { display: flex !important; }

    /* Lead profile modal — full screen, stacked */
    .lead-profile-modal {
        flex-direction: column;
        max-height: calc(100vh - 32px);
        border-radius: 12px;
    }

    .lead-profile-left, .lead-profile-right {
        flex: unset;
    }

    .lead-profile-left {
        border-right: none;
        border-bottom: 1px solid var(--surface-border);
        max-height: 50vh;
        overflow-y: auto;
    }

    .lead-profile-right {
        max-height: 50vh;
        overflow-y: auto;
    }

    /* Form grids → single column */
    .form-grid { grid-template-columns: 1fr; gap: 12px; }
    .checkbox-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }

    /* Auth box */
    .auth-box { padding: 28px 20px; }

    /* Modal padding */
    .modal-overlay { padding: 8px; align-items: flex-end; }

    .modal-content {
        border-radius: 16px 16px 8px 8px;
        max-height: 94vh;
    }

    .form-section { padding: 16px; }

    /* Toast position */
    .toast { bottom: 16px; right: 16px; left: 16px; text-align: center; }
}

@media (max-width: 480px) {
    .metrics-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .metric-value { font-size: 1.6rem; }
    .checkbox-grid { grid-template-columns: 1fr 1fr; }
}

/* =============================================
   ACTION BUTTONS IN LEAD PROFILE
   ============================================= */
.action-btn-row {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.action-btn {
    flex: 1;
    min-width: 70px;
    padding: 9px 10px;
    font-size: 0.85rem;
    text-align: center;
    border-radius: 6px;
    text-decoration: none;
    font-weight: 600;
    color: white;
    cursor: pointer;
    border: none;
    white-space: nowrap;
}

.action-call  { background: #10b981; }
.action-call:hover { background: #059669; }
.action-wa    { background: #25D366; }
.action-wa:hover { background: #128C7E; }
.action-email { background: #6366f1; }
.action-email:hover { background: #4f46e5; }
.action-delete { background: rgba(239,68,68,0.15); color:#ef4444; border:1px solid rgba(239,68,68,0.3); }
.action-delete:hover { background: rgba(239,68,68,0.3); }

/* CRM delete button (small, table/card) */
.crm-del-btn {
    background: rgba(239,68,68,0.15);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: 0.2s;
    white-space: nowrap;
}

.crm-del-btn:hover { background: rgba(239,68,68,0.3); }

/* =============================================
   PERMISSION GRID (Admin panel — Add user form)
   ============================================= */
.perm-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.perm-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.88rem;
    color: var(--text-main);
    cursor: pointer;
    padding: 8px 10px;
    background: rgba(15,23,42,0.4);
    border-radius: 6px;
    border: 1px solid var(--surface-border);
    transition: border-color 0.2s;
    user-select: none;
    font-weight: 400;
}

.perm-item:hover { border-color: rgba(59, 130, 246, 0.5); }
.perm-item input { width: 15px; height: 15px; flex-shrink: 0; accent-color: var(--primary); }

/* Per-user permission edit grid */
.perm-edit-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 8px;
}

@media (max-width: 768px) {
    .perm-grid     { grid-template-columns: repeat(2, 1fr); }
    .perm-edit-grid { grid-template-columns: repeat(2, 1fr); }
    .action-btn-row { gap: 6px; }
    .action-btn { font-size: 0.8rem; padding: 8px 6px; }
}

/* =============================================
   DOCUMENT FOLDER TABS
   ============================================= */
.doc-folder-tab {
    background: rgba(30, 41, 59, 0.6);
    border: 1px solid var(--surface-border);
    color: var(--text-muted);
    padding: 8px 18px;
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 500;
    transition: all 0.2s;
    white-space: nowrap;
}

.doc-folder-tab:hover {
    background: rgba(59, 130, 246, 0.1);
    color: var(--primary);
    border-color: rgba(59, 130, 246, 0.3);
}

.doc-folder-tab.active {
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
    border-color: rgba(59, 130, 246, 0.5);
    font-weight: 600;
}