:root {
    --primary-bg: #1a1a1a;
    --secondary-bg: #222222;
    --hover-bg: #2a2a2a;
    --border-color: #333333;
    --text-color: #f5f5f5;
    --text-muted: #aaaaaa;
    --gold-color: #D4AF37;
    --gold-light: #e5c76b;
    --gold-dark: #a88a29;
    --primary-color: var(--gold-color);
    --success-color: #2ecc71;
    --warning-color: #f39c12;
    --danger-color: #e74c3c;
    --info-color: var(--gold-color);
    --card-bg: #2c2c2c;
    --card-border: #444;
    --card-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Stats Container */
.leads-stats-container {
    padding: 0.75rem;
    background-color: var(--primary-bg);
    border-bottom: 1px solid var(--border-color);
}

/* Stat Cards */
.stat-card {
    background-color: var(--card-bg);
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    height: 100%;
    transition: transform 0.2s, box-shadow 0.2s;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.stat-card-body {
    display: flex;
    align-items: center;
    padding: 0.75rem;
}

/* Color coding for stat cards */
.stat-card.total-leads {
    border-left-color: var(--gold-color);
}

.stat-card.contacted {
    border-left-color: var(--success-color);
}

.stat-card.pending {
    border-left-color: var(--warning-color);
}

.stat-card.conversion {
    border-left-color: var(--gold-color);
}

.stat-card-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 0.75rem;
    flex-shrink: 0;
}

.stat-card-icon i {
    font-size: 1.25rem;
    color: white;
}

.bg-primary {
    background-color: var(--primary-color);
}

.bg-success {
    background-color: var(--success-color);
}

.bg-warning {
    background-color: var(--warning-color);
}

.bg-info {
    background-color: var(--info-color);
}

.stat-card-info {
    flex-grow: 1;
}

.stat-card-value {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--text-color);
}

.stat-card-title {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* Pipeline Chart */
.pipeline-container {
    background-color: var(--card-bg);
    border-radius: 8px;
    padding: 0.75rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    margin-bottom: 0.5rem;
}

.pipeline-title {
    color: var(--gold-color);
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

.pipeline-chart {
    display: flex;
    align-items: flex-end;
    justify-content: space-around;
    height: 80px;
    margin-top: 0.75rem;
}

.pipeline-stage {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.pipeline-bar {
    width: 100%;
    background-color: var(--primary-color);
    border-radius: 4px 4px 0 0;
    transition: height 0.5s;
    position: relative;
}

.pipeline-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.pipeline-count {
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--secondary-bg);
    color: var(--text-color);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
}

/* Main Container */
.leads-main-container {
    display: flex;
    height: calc(100vh - 60px - 180px);
    background-color: var(--secondary-bg);
    position: relative;
    overflow: hidden;
    max-width: 100%;
}

.leads-list-panel {
    width: 30%;
    min-width: 300px;
    max-width: 400px;
    height: 100%;
    background-color: var(--primary-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
}

.leads-list-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--card-bg);
}

.leads-list-header h2 {
    font-size: 1.25rem;
    margin: 0;
}

.leads-list-search {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.leads-list-search .form-control {
    background-color: var(--primary-bg);
    border-color: var(--border-color);
    color: var(--text-color);
}

.leads-list-body {
    flex-grow: 1;
    overflow-y: auto;
}

.lead-item {
    padding: 12px 15px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background-color 0.2s;
}

.lead-item:hover {
    background-color: var(--hover-bg);
}

.lead-item.active {
    background-color: var(--active-bg);
    border-left: 3px solid var(--primary-color);
}

.leads-list-item.active::before,
.leads-list-item:hover::before {
    background-color: var(--gold-color);
}

.leads-list-item.status-new::before {
    background-color: var(--primary-color);
}

.leads-list-item.status-contacted::before {
    background-color: var(--success-color);
}

.leads-list-item.status-pending::before {
    background-color: var(--warning-color);
}

.leads-list-item.status-qualified::before {
    background-color: var(--gold-light);
}

.leads-list-item.status-lost::before {
    background-color: var(--danger-color);
}

.lead-name {
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: var(--text-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.lead-info {
    font-size: 0.8125rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.lead-status {
    padding: 0.2em 0.6em;
    border-radius: 4px;
    text-transform: uppercase;
}

.lead-detail-panel {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--secondary-bg);
    box-shadow: -2px 0 5px rgba(0, 0, 0, 0.1);
    position: relative;
    z-index: 1;
    border-left: 1px solid var(--border-color);
    position: relative;
    transition: all 0.3s ease;
    overflow-x: hidden;
    width: 70%;
}

.lead-detail-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--card-bg);
    border-radius: 8px 8px 0 0;
    margin-bottom: 1rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.lead-detail-body {
    padding: 1rem;
    flex-grow: 1;
    overflow-y: auto;
    background-color: var(--secondary-bg);
}

/* Lead Status Badge */
.lead-status-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.5rem 1rem;
    border-radius: 50px;
    background-color: var(--primary-bg);
    font-weight: 600;
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 8px;
    background-color: var(--gold-color);
}

/* Lead Summary Card */
.lead-summary-card {
    background-color: var(--card-bg);
    border-radius: 8px;
    padding: 1rem;
    box-shadow: var(--card-shadow);
    border-left: 3px solid var(--gold-color);
}

.lead-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background-color: var(--primary-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
}

.lead-avatar i {
    font-size: 3rem;
    color: var(--text-muted);
}

.lead-info-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.lead-info-item {
    display: flex;
    flex-direction: column;
}

.info-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.info-value {
    font-size: 1rem;
    color: var(--text-color);
    word-break: break-word;
}

/* CRM Tabs */
.crm-tabs {
    border-bottom-color: var(--border-color);
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Firefox */
    margin-bottom: 0;
}

.crm-tabs::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Edge */
}

.crm-tabs .nav-item {
    flex: 0 0 auto;
}

.crm-tabs .nav-link {
    color: var(--text-muted);
    border: none;
    padding: 0.5rem 1rem;
    background-color: transparent;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    font-size: 0.9rem;
    font-weight: 500;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.crm-tabs .nav-link i {
    font-size: 0.9rem;
}

.crm-tabs .nav-link:hover {
    color: var(--text-color);
    background-color: rgba(255, 255, 255, 0.05);
    border-bottom: 2px solid var(--text-muted);
}

.crm-tabs .nav-link.active {
    color: var(--gold-color);
    background-color: transparent;
    border-bottom: 2px solid var(--gold-color);
    font-weight: 600;
}

.crm-tab-content {
    background-color: var(--card-bg);
    border-radius: 0 0 8px 8px;
    min-height: 300px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    padding: 1rem !important;
}

/* Tasks List */
.tasks-list {
    max-height: 400px;
    overflow-y: auto;
    padding-right: 0.5rem;
    -webkit-overflow-scrolling: touch;
}

.tasks-list::-webkit-scrollbar {
    width: 6px;
}

.tasks-list::-webkit-scrollbar-track {
    background: var(--primary-bg);
    border-radius: 10px;
}

.tasks-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

/* Improved touch targets for mobile */
@media (max-width: 768px) {
    .tasks-list {
        max-height: 350px;
    }
    
    .task-checkbox {
        width: 20px;
        height: 20px;
    }
    
    .form-check-label {
        font-size: 0.95rem;
        padding: 0.25rem 0;
    }
}

.task-item {
    background-color: var(--primary-bg);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.task-item:hover {
    background-color: var(--hover-bg);
    transform: translateX(2px);
    border-left: 3px solid var(--primary-color);
}

.task-item.completed {
    border-left: 3px solid var(--success-color);
    opacity: 0.7;
}

.task-item.completed label {
    text-decoration: line-through;
    color: var(--text-muted);
}

.form-check {
    display: flex;
    align-items: center;
    flex-grow: 1;
}

.task-checkbox {
    margin-right: 0.75rem;
    cursor: pointer;
    width: 18px;
    height: 18px;
}

.task-delete-btn {
    opacity: 0.6;
    transition: all 0.2s ease;
    padding: 0.25rem 0.5rem;
    line-height: 1;
}

.task-delete-btn:hover {
    opacity: 1;
    background-color: var(--danger-color);
    color: white;
}

/* Activity Log */
.activity-log {
    max-height: 400px;
    overflow-y: auto;
    padding-right: 0.5rem;
    -webkit-overflow-scrolling: touch;
}

.activity-log::-webkit-scrollbar {
    width: 6px;
}

.activity-log::-webkit-scrollbar-track {
    background: var(--primary-bg);
    border-radius: 10px;
}

.activity-log::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

.activity-item {
    background-color: var(--primary-bg);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 0.75rem;
    border-left: 3px solid var(--primary-color);
    transition: all 0.2s ease;
}

.activity-item:hover {
    transform: translateX(2px);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
}

/* Improved touch targets for mobile */
@media (max-width: 768px) {
    .activity-item {
        padding: 0.75rem;
    }
    
    .activity-header {
        padding-bottom: 0.35rem;
        margin-bottom: 0.5rem;
    }
    
    .activity-body {
        font-size: 0.9rem;
    }
}

/* Style activity items based on type */
.activity-item.type-call {
    border-left-color: var(--primary-color);
}

.activity-item.type-email {
    border-left-color: var(--info-color);
}

.activity-item.type-meeting {
    border-left-color: var(--success-color);
}

.activity-item.type-note {
    border-left-color: var(--warning-color);
}

.activity-header {
    display: flex;
    align-items: center;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.activity-body {
    color: var(--text-color);
    font-size: 0.95rem;
    line-height: 1.5;
    padding: 0.25rem 0;
}

/* Notes List */
.notes-list {
    max-height: 400px;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.notes-list::-webkit-scrollbar {
    width: 6px;
}

.notes-list::-webkit-scrollbar-track {
    background: var(--primary-bg);
    border-radius: 10px;
}

.notes-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

.note-item {
    background-color: var(--primary-bg);
    border-radius: 8px;
    padding: 1.25rem;
    margin-bottom: 1rem;
    border-left: 3px solid var(--gold-color);
    transition: all 0.2s ease;
    position: relative;
}

.note-item:hover {
    transform: translateX(2px);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
}

.note-title {
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text-color);
    font-size: 1.1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.note-content {
    color: var(--text-color);
    font-size: 0.95rem;
    line-height: 1.6;
    white-space: pre-line;
}

.note-date {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 1rem;
    text-align: right;
    font-style: italic;
}

.lead-detail-placeholder {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
}

.lead-detail-placeholder i {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.detail-section {
    margin-bottom: 0.75rem !important;
}

.detail-section h5 {
    color: var(--gold-color);
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.notes-history {
    margin-top: 1rem;
}

.note-item {
    background: var(--secondary-bg);
    padding: 0.75rem;
    border-radius: 4px;
    margin-bottom: 0.5rem;
}

/* Responsive Design */
@media (max-width: 992px) {
    .lead-info-grid {
        grid-template-columns: 1fr;
    }
    
    .lead-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .lead-actions .btn {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.25rem;
        transition: all 0.2s ease;
    }
    
    .lead-actions .btn:hover {
        transform: translateY(-2px);
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    }
    
    .lead-detail-body {
        padding: 1rem;
    }
    
    .crm-tab-content {
        padding: 1rem !important;
    }
}

@media (max-width: 767.98px) {
    .leads-main-container {
        height: auto;
        min-height: 500px;
    }

    .leads-list-panel {
        width: 100%;
        position: absolute;
        top: 0;
        left: 0;
        height: 100%;
        z-index: 10;
        transform: translateX(0);
        box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
    }

    .lead-detail-panel.hidden-mobile {
        display: none;
    }

    .lead-detail-panel {
        width: 100%;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        height: 100dvh; /* dynamic viewport height for mobile browsers */
        min-height: 100vh; /* fallback */
        z-index: 5000; /* ensure above footer and other elements */
        background-color: var(--primary-bg);
        overflow-y: auto;
        transition: transform 0.3s ease, opacity 0.3s ease;
        transform: translateX(100%);
        opacity: 0;
        box-shadow: -5px 0 15px rgba(0, 0, 0, 0.3);
    }

    .lead-detail-panel.active {
        transform: translateX(0);
        opacity: 1;
    }

    /* Improve mobile scrolling experience */
    .leads-list-body {
        -webkit-overflow-scrolling: touch;
    }

    /* Make back button more prominent on mobile */
    .back-to-list {
        display: inline-flex !important;
        align-items: center;
        gap: 0.25rem;
        padding: 0.375rem 0.75rem;
        border-radius: 4px;
        background-color: var(--primary-bg);
        color: var(--text-color);
        border: 1px solid var(--border-color);
        cursor: pointer;
        transition: all 0.2s ease;
    }
    
    .back-to-list:hover {
        background-color: var(--hover-bg);
    }
    
    .stat-card-body {
        padding: 1rem;
    }
    
    .stat-card-icon {
        width: 40px;
        height: 40px;
    }
    
    .stat-card-value {
        font-size: 1.5rem;
    }
    
    .pipeline-chart {
        height: 100px;
    }
    
    .pipeline-label {
        font-size: 0.7rem;
    }
    
    .lead-avatar {
        width: 60px;
        height: 60px;
        margin-bottom: 1rem;
    }
    
    .lead-avatar i {
        font-size: 2rem;
    }
    
    .crm-tabs .nav-link {
        padding: 0.5rem 0.75rem;
        font-size: 0.9rem;
    }
    
    .lead-summary-card {
        margin-bottom: 1rem;
    }

    /* Lead actions: icon-only in a single row */
    .lead-actions {
        display: flex !important;
        flex-wrap: nowrap;
        gap: 0.5rem;
        justify-content: flex-end;
        width: 100%;
    }
    .lead-actions .btn {
        width: 40px;
        height: 40px;
        padding: 0;
        font-size: 0; /* hide any text nodes */
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    .lead-actions .btn i {
        font-size: 1.1rem;
        margin: 0; /* no spacing for icon-only */
    }
    .lead-actions .btn span,
    .lead-actions .btn .label {
        display: none !important; /* ensure no text shows */
    }
    /* Improve task and activity items on mobile */
    .task-item, .activity-item, .note-item {
        padding: 0.75rem;
    }
}

/* Ghost button: subtle, low-emphasis */
.btn-ghost {
    background-color: transparent;
    border: 1px solid transparent;
    color: var(--muted-text, #6c757d);
}
.btn-ghost:hover,
.btn-ghost:focus {
    background-color: rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.06);
    color: var(--text, #333);
    box-shadow: none;
}
.btn-ghost:active {
    background-color: rgba(0, 0, 0, 0.06);
}

/* Back-to-list specific tweaks */
.lead-detail-header .back-to-list.btn-ghost {
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
}

@media (max-width: 576px) {
    .leads-stats-container {
        padding: 1rem;
    }
    
    .stat-card-body {
        flex-direction: column;
        text-align: center;
    }
    
    .stat-card-icon {
        margin-right: 0;
        margin-bottom: 0.5rem;
    }
    
    .pipeline-chart {
        overflow-x: auto;
        padding-bottom: 1rem;
    }
    
    .lead-detail-header {
        flex-direction: column;
        gap: 1rem;
    }
    
    .lead-actions {
        width: 100%;
        display: flex !important;
        flex-wrap: nowrap;
        justify-content: space-between;
        gap: 0.5rem;
    }
    
    .lead-actions .btn {
        width: 40px;
        height: 40px;
        padding: 0;
        font-size: 0; /* hide text */
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    
    .lead-actions .btn i {
        margin: 0;
        font-size: 1.1rem;
    }
    
    .crm-tabs {
        gap: 0.25rem;
    }
    
    .crm-tabs .nav-link {
        padding: 0.5rem;
        margin-right: 0.25rem;
    }
    
    .crm-tab-content {
        padding: 0.75rem !important;
    }
    
    /* Improve form layouts on small mobile */
    .form-label {
        font-size: 0.9rem;
        margin-bottom: 0.25rem;
    }
    
    .form-control, .form-select {
        font-size: 0.9rem;
        padding: 0.375rem 0.5rem;
    }
    
    .btn {
        font-size: 0.9rem;
        padding: 0.375rem 0.75rem;
    }
    
    /* Improve task and activity items on mobile */
    .task-item, .activity-item, .note-item {
        padding: 0.75rem;
    }
    
    /* Improve lead detail view on small screens */
    .lead-detail-body {
        padding: 0.75rem;
    }
    
    .lead-summary-card {
        padding: 1rem;
    }
    
    /* Make back button more visible */
    #backToListBtn {
        padding: 0.5rem 0.75rem;
        font-size: 0.9rem;
        background-color: transparent; /* ghost */
        color: var(--text-muted); /* grey */
        border: 1px solid var(--border-color); /* subtle outline */
        margin-bottom: 0.5rem;
        width: 100%;
        text-align: center;
        display: flex !important;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
    }
}

/* Ensure the Edit Lead modal stacks above high z-index panels on this page */
/* The mobile lead detail panel uses z-index: 5000; Bootstrap modals default to ~1055. */
/* Raise the specific lead modal and its backdrop only on this page. */
#leadModal {
    z-index: 6000 !important; /* above .lead-detail-panel (5000) */
}

.modal-backdrop {
    z-index: 5998 !important; /* just below the modal itself */
}
