:root {
    --bg-base: #f1f5f9;
    --bg-surface: rgba(255, 255, 255, 0.85);
    --bg-surface-hover: rgba(255, 255, 255, 1);
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border: rgba(0, 0, 0, 0.08);
    
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #0ea5e9;

    --font-main: 'Outfit', sans-serif;
}

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

body {
    font-family: var(--font-main);
    background: var(--bg-base);
    background-image: 
        radial-gradient(at 0% 0%, rgba(37, 99, 235, 0.1) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(16, 185, 129, 0.08) 0px, transparent 50%);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
}

.hidden { display: none !important; }

/* Views */
.view {
    min-height: 100vh;
    width: 100vw;
    display: flex;
    animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Glassmorphism */
.glass-panel {
    background: var(--bg-surface);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.03);
}

/* Auth Container */
#auth-view {
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.auth-container {
    width: 100%;
    max-width: 420px;
    padding: 40px;
}

.auth-header {
    text-align: center;
    margin-bottom: 30px;
}

.logo-circle {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--primary), var(--info));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    color: white;
}

.auth-header h1 {
    font-size: 24px;
    font-weight: 600;
}

.auth-header p {
    color: var(--text-muted);
    font-size: 14px;
}

/* Forms */
.input-group {
    margin-bottom: 20px;
}

.input-group label {
    display: block;
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.input-wrapper {
    position: relative;
}

.input-wrapper i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    width: 18px;
    height: 18px;
}

input, select, textarea {
    width: 100%;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-main);
    font-family: var(--font-main);
    font-size: 14px;
    transition: all 0.2s;
}

.input-wrapper input, .input-wrapper select, .input-wrapper textarea {
    padding-left: 38px;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

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

/* Buttons */
.btn-primary {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--bg-surface);
    color: var(--text-main);
    border: 1px solid var(--border);
    padding: 10px 16px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: var(--bg-surface-hover);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: none;
    padding: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    border-radius: 8px;
    transition: all 0.2s;
}

.btn-ghost:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-main);
}

/* Dashboard Layout */
#dashboard-view {
    display: flex;
}

.sidebar {
    width: 260px;
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 24px 16px;
    overflow-y: auto;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 24px;
}

.brand-icon {
    color: var(--primary);
}

.sidebar-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 32px;
    padding: 12px;
    background: rgba(0, 0, 0, 0.04);
    border-radius: 12px;
}

.avatar {
    width: 40px;
    height: 40px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.user-info {
    display: flex;
    flex-direction: column;
}

#user-name {
    font-size: 14px;
    font-weight: 500;
}

.badge {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--primary);
    font-weight: 600;
}

#nav-menu {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.2s;
    cursor: pointer;
}

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

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 32px;
}

.top-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
}

.header-actions {
    display: flex;
    gap: 12px;
}

/* Grid & Cards */
.grid {
    display: grid;
    gap: 20px;
}

.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }

.stat-card {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stat-card h3 {
    font-size: 14px;
    color: var(--text-muted);
    font-weight: 500;
}

.stat-card .value {
    font-size: 28px;
    font-weight: 600;
}

/* Modals */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 16px;
}

.modal {
    width: 100%;
    max-width: 500px;
    padding: 24px;
    animation: fadeIn 0.2s ease-out;
    max-height: 100%;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.close-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
}

/* Tables */
.table-container {
    overflow-x: auto;
    background: var(--bg-surface);
    border-radius: 12px;
    border: 1px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    font-size: 12px;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
}

td {
    font-size: 14px;
}

.status-badge {
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    text-transform: capitalize;
}

.status-enq { background: rgba(59, 130, 246, 0.2); color: var(--primary); }
.status-int { background: rgba(245, 158, 11, 0.2); color: var(--warning); }
.status-hot { background: rgba(239, 68, 68, 0.2); color: var(--danger); }
.status-closed { background: rgba(16, 185, 129, 0.2); color: var(--success); }
.status-cancelled { background: rgba(148, 163, 184, 0.2); color: var(--text-muted); }

.error-msg {
    color: var(--danger);
    font-size: 14px;
    margin-top: 12px;
    text-align: center;
}

/* Toolbar & Actions */
.toolbar {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
}

.action-icons {
    display: flex;
    gap: 8px;
}

.action-btn {
    background: rgba(0, 0, 0, 0.03);
    border: 1px solid var(--border);
    color: var(--text-main);
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.action-btn:hover { 
    background: var(--primary); 
    border-color: var(--primary);
    color: white;
}

.action-btn.whatsapp:hover { 
    background: #25D366; 
    border-color: #25D366;
    color: white;
}

.action-btn.call:hover { 
    background: #10b981; 
    border-color: #10b981;
    color: white;
}

/* Leaderboard Widgets */
.leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.leaderboard-item {
    display: flex;
    align-items: center;
    padding: 16px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    gap: 16px;
    transition: transform 0.2s;
}
.leaderboard-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}
.leaderboard-rank {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-weight: 700;
    font-size: 14px;
    color: white;
    background: var(--text-muted);
}
.rank-1 .leaderboard-rank {
    background: linear-gradient(135deg, #fbbf24, #d97706); /* Gold */
    box-shadow: 0 0 10px rgba(245, 158, 11, 0.5);
}
.rank-2 .leaderboard-rank {
    background: linear-gradient(135deg, #94a3b8, #475569); /* Silver */
}
.rank-3 .leaderboard-rank {
    background: linear-gradient(135deg, #d97706, #92400e); /* Bronze */
}
.leaderboard-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
}
.leaderboard-info {
    flex: 1;
}
.leaderboard-name {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 2px;
}
.leaderboard-metric {
    font-size: 13px;
    color: var(--text-muted);
}
.leaderboard-score {
    font-weight: 700;
    font-size: 20px;
    color: var(--primary);
}

/* Mobile Responsiveness */
.mobile-only {
    display: none !important;
}

@media (max-width: 768px) {
    .mobile-only {
        display: flex !important;
    }

    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        height: 100%;
        height: 100dvh;
        z-index: 50;
        transition: left 0.3s ease;
        box-shadow: 4px 0 24px rgba(0,0,0,0.5);
        background: #ffffff;
        padding-bottom: calc(24px + env(safe-area-inset-bottom));
    }

    .sidebar.open {
        left: 0;
    }

    .main-content {
        padding: 16px;
    }

    .grid-cols-4, .grid-cols-3 {
        display: flex;
        flex-wrap: nowrap;
        gap: 8px;
        overflow-x: auto;
        padding-bottom: 8px; /* For scrollbar */
    }

    .grid-cols-4 > *, .grid-cols-3 > * {
        flex: 1 0 auto;
        min-width: 80px; /* Ensure they don't squish too much */
    }

    .stat-card {
        padding: 12px 8px;
    }

    .stat-card h3 {
        font-size: 11px;
        white-space: nowrap;
    }

    .stat-card .value {
        font-size: 16px;
    }

    .header-actions {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
        gap: 8px;
    }

    .toolbar {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 6px;
    }

    .toolbar .btn-secondary {
        flex: 1 1 auto;
        padding: 6px 8px;
        font-size: 11px;
        justify-content: center;
    }

    .toolbar .input-wrapper {
        width: 100%;
        flex: 1 1 100%;
        margin-top: 4px;
    }

    .input-wrapper select, .input-wrapper input {
        width: 100%;
    }

    .modal {
        max-width: 100%;
        padding: 16px;
        max-height: 100%;
        overflow-y: auto;
    }

    .input-group {
        margin-bottom: 12px;
    }

    .input-group label {
        margin-bottom: 4px;
    }

    .table-container {
        border: 1px solid var(--border);
        background: var(--bg-surface);
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        display: table;
        min-width: 650px;
    }
    
    .top-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }
    
    .top-header > div:first-child {
        width: 100%;
        flex-wrap: wrap;
    }
    
    #days-remaining-badge {
        margin-left: auto !important;
    }
    
    .form-grid-2 {
        grid-template-columns: 1fr;
    }
}
