:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --secondary: #10b981;
    --bg-base: #f8fafc;
    --bg-surface: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --sidebar-bg: #1e293b;
    --sidebar-text: #f8fafc;
    --danger: #ef4444;
    --warning: #f59e0b;
    --radius: 12px;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

a[href^="tel"] {
    text-decoration: none !important;
}

[data-theme='dark'] {
    --primary: #818cf8;
    --primary-hover: #6366f1;
    --bg-base: #0f172a;
    --bg-surface: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border: #334155;
    --sidebar-bg: #0f172a;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.5);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.5);
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-base);
    color: var(--text-primary);
    transition: var(--transition);
    height: 100vh;
    overflow: hidden;
    display: flex;
}

/* Layout */
#app {
    display: flex;
    width: 100%;
    height: 100%;
}

.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    transition: var(--transition);
    z-index: 20;
    box-shadow: var(--shadow);
}

.sidebar-header {
    padding: 24px;
    font-size: 1.25rem;
    font-weight: 700;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 0;
    overflow-y: auto;
}

.nav-item {
    padding: 12px 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    transition: var(--transition);
    cursor: pointer;
    font-weight: 500;
}

.nav-item:hover, .nav-item.active {
    color: #fff;
    background-color: rgba(255, 255, 255, 0.1);
    border-left: 4px solid var(--primary);
}

.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.header {
    height: 70px;
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 10;
}

.theme-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: var(--transition);
}

.theme-toggle:hover {
    background-color: rgba(0,0,0,0.05);
    color: var(--primary);
}
[data-theme='dark'] .theme-toggle:hover {
    background-color: rgba(255,255,255,0.05);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 500;
}

.main-content {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
}

/* Components */
.card {
    background-color: var(--bg-surface);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    margin-bottom: 24px;
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.btn {
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.btn-primary {
    background-color: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

/* Tables */
.table-container {
    width: 100%;
    overflow-x: auto;
}

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

th, td {
    padding: 10px 8px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}

th {
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}

tr:hover td {
    background-color: rgba(0, 0, 0, 0.02);
}
[data-theme='dark'] tr:hover td {
    background-color: rgba(255, 255, 255, 0.02);
}

/* Auth View */
.auth-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    width: 100vw;
    background: linear-gradient(135deg, var(--bg-base) 0%, var(--border) 100%);
}
[data-theme='dark'] .auth-wrapper {
    background: linear-gradient(135deg, var(--bg-base) 0%, #1e293b 100%);
}

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

.form-group {
    margin-bottom: 20px;
    text-align: left;
}

.form-label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.detail-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    font-weight: 600;
}

.detail-value {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
}

.form-control {
    width: 100%;
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background-color: var(--bg-base);
    color: var(--text-primary);
    font-family: inherit;
    transition: var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

/* Hide number input spinners */
input[type=number]::-webkit-inner-spin-button, 
input[type=number]::-webkit-outer-spin-button { 
    -webkit-appearance: none; 
    margin: 0; 
}
input[type=number] {
    -moz-appearance: textfield;
}

/* Kanban Board */
.kanban-board {
    display: flex;
    gap: 24px;
    height: calc(100vh - 200px);
    overflow-x: auto;
    padding-bottom: 20px;
}

.kanban-col {
    min-width: 300px;
    background-color: var(--bg-base);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
}

.kanban-header {
    font-weight: 600;
    margin-bottom: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.kanban-cards {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.kanban-card {
    background-color: var(--bg-surface);
    padding: 16px;
    border-radius: 8px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: var(--transition);
}

.kanban-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
}

/* Badges */
.badge {
    padding: 4px 8px;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-pending { background: rgba(245, 158, 11, 0.1); color: var(--warning); }
.badge-danger { background: rgba(239, 68, 68, 0.1); color: var(--danger); }
.badge-done { background: rgba(16, 185, 129, 0.1); color: var(--secondary); }
.badge-primary { background: rgba(99, 102, 241, 0.1); color: var(--primary); }

/* Stage Switcher */
.stage-switcher {
    display: flex;
    background: rgba(0, 0, 0, 0.05);
    padding: 4px;
    border-radius: 9999px;
    border: 1px solid var(--border);
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE 10+ */
    max-width: 100%;
}
.stage-switcher::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
}
[data-theme='dark'] .stage-switcher {
    background: rgba(255, 255, 255, 0.05);
}

.stage-btn {
    padding: 8px 16px;
    border-radius: 9999px;
    border: none;
    background: none;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.8rem;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
    white-space: nowrap;
}

.stage-btn.active {
    background: var(--bg-surface);
    color: var(--primary);
    box-shadow: var(--shadow);
}

.hidden { display: none !important; }

/* Role group should be visible in editing mode too */
#user-modal.editing #user-role-group {
    display: block;
}

/* Role-based UI Hiding */
body[data-role="sales"] #pipeline-controls-container,
body[data-role="sales"] #btn-new-lead {
    display: none !important;
}

/* Mobile Responsiveness */
.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: var(--transition);
}

.mobile-menu-btn:hover {
    background-color: rgba(0,0,0,0.05);
    color: var(--primary);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0,0,0,0.5);
    z-index: 15;
}

@media (max-width: 768px) {
    body {
        overflow-y: auto;
        height: auto;
    }

    #app {
        height: auto;
        min-height: 100vh;
    }

    .sidebar {
        position: fixed;
        left: -260px;
        top: 0;
        bottom: 0;
        height: 100vh;
        width: 260px;
    }

    .sidebar.active {
        left: 0;
    }

    .sidebar-overlay.active {
        display: block;
    }

    .mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .header {
        padding: 0 16px;
    }

    .main-content {
        padding: 16px;
    }

    .card {
        padding: 16px;
    }

    /* Show grid elements in two columns even on mobile */
    .grid-responsive {
        grid-template-columns: 1fr 1fr !important;
        gap: 12px !important;
    }

    /* Kanban Board responsiveness */
    .kanban-board {
        flex-direction: column;
        gap: 24px;
        height: auto;
        overflow-x: hidden;
    }
    
    .kanban-col {
        min-width: 100%;
        height: auto;
    }

    /* Modal adjustments */
    .modal-content {
        width: 95%;
        margin: 10px;
        max-height: 95vh;
    }
    
    .modal-body {
        padding: 16px;
    }
    
    /* User profile on mobile */
    .user-profile span {
        display: none;
    }

    /* Dashboard stats */
    #tpl-admin-dashboard > .card > div {
        grid-template-columns: 1fr !important;
    }

    /* Better table support for mobile */
    .table-container {
        border-radius: 8px;
        border: 1px solid var(--border);
    }
    
    table, thead, tbody, th, td, tr { 
        display: block; 
    }
    
    thead tr { 
        position: absolute;
        top: -9999px;
        left: -9999px;
    }
    
    tr { border: 1px solid var(--border); margin-bottom: 8px; border-radius: 8px; background: var(--bg-surface); }
    
    td { 
        border: none;
        border-bottom: 1px solid var(--border); 
        position: relative;
        padding-left: 50%; 
        min-height: 45px;
        display: flex;
        align-items: center;
        justify-content: flex-end;
        text-align: right;
    }
    
    td:last-child { border-bottom: none; }
    
    td:before { 
        position: absolute;
        left: 12px;
        width: 45%; 
        padding-right: 10px; 
        white-space: nowrap;
        content: attr(data-label);
        font-weight: 600;
        text-align: left;
        color: var(--text-secondary);
        font-size: 0.75rem;
        text-transform: uppercase;
    }
}
.nowrap {
    white-space: nowrap !important;
}

@keyframes blink-row {
    0% { background-color: inherit; }
    50% { background-color: rgba(34, 197, 94, 0.2); } /* Tailwind green-500 light */
    100% { background-color: inherit; }
}
.blink-highlight td {
    animation: blink-row 2s infinite !important;
}
.blink-highlight {
    animation: blink-row 2s infinite !important;
}
