/**
 * CRM Dashboard Styles
 * Dubai Realty CRM Panel
 */

/* ===== Layout ===== */
.crm-wrapper {
    display: flex;
    min-height: 100vh;
    background: var(--gray-50);
}

/* Hide main site navbar on CRM pages */
body:has(.crm-wrapper) .topbar,
body:has(.crm-wrapper) .main-navbar,
body:has(.crm-wrapper) .navbar-placeholder {
    display: none !important;
}

/* Full height fix when navbar is hidden */
body:has(.crm-wrapper) main {
    padding-top: 0 !important;
}

/* ===== Sidebar ===== */
.crm-sidebar {
    width: 260px;
    background: linear-gradient(180deg, var(--graphite) 0%, #151920 100%);
    color: white;
    position: fixed;
    top: 0;
    inset-inline-start: 0;
    height: 100vh;
    z-index: 1050;
    overflow-y: auto;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header h4 {
    margin: 0;
    font-weight: 700;
    color: var(--primary);
}

.sidebar-nav {
    padding: 1rem 0;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1.5rem;
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    transition: all 0.2s ease;
    border-inline-start: 3px solid transparent;
}

.sidebar-link:hover {
    color: white;
    background: rgba(255,255,255,0.05);
}

.sidebar-link.active {
    color: white;
    background: rgba(37, 183, 176, 0.15);
    border-left-color: var(--primary);
}

.sidebar-link i {
    width: 20px;
    text-align: center;
    font-size: 1rem;
}

.sidebar-divider {
    margin: 0.75rem 1.5rem;
    border-color: rgba(255,255,255,0.1);
}

/* ===== Main Content ===== */
.crm-main {
    flex: 1;
    margin-inline-start: 260px;
    min-height: 100vh;
    position: relative;
    overflow-x: hidden;
}

.crm-header {
    background: white;
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--gray-200);
    position: sticky;
    top: 0;
    z-index: 100;
    /* Prevent overlapping sidebar when sticky */
    margin-inline-start: 0;
    width: 100%;
}

.crm-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
    color: var(--graphite);
}

.crm-subtitle {
    font-size: 0.875rem;
}

.crm-content {
    padding: 2rem;
}

/* ===== Stat Cards ===== */
.stat-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: white;
    border-radius: var(--radius-xl);
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.stat-icon.primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
}

.stat-icon.success {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
}

.stat-icon.warning {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: white;
}

.stat-icon.gold {
    background: linear-gradient(135deg, var(--gold) 0%, var(--caramel) 100%);
    color: white;
}

.stat-icon.danger {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
}

.stat-info h3 {
    font-size: 1.75rem;
    font-weight: 700;
    margin: 0;
    color: var(--graphite);
}

.stat-info p {
    font-size: 0.875rem;
    color: var(--gray-500);
    margin: 0;
}

/* ===== Cards ===== */
.crm-card {
    background: white;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.crm-card-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.crm-card-header h5 {
    margin: 0;
    font-weight: 600;
    color: var(--graphite);
}

.crm-card-body {
    padding: 1.5rem;
}

/* ===== Charts ===== */
.chart-container {
    position: relative;
    height: 300px;
}

/* ===== Tables ===== */
.crm-table {
    width: 100%;
    border-collapse: collapse;
}

.crm-table th {
    background: var(--gray-50);
    padding: 0.875rem 1rem;
    text-align: start;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--gray-600);
    border-bottom: 1px solid var(--gray-200);
}

.crm-table td {
    padding: 1rem;
    border-bottom: 1px solid var(--gray-100);
    vertical-align: middle;
}

.crm-table tr:hover {
    background: var(--gray-50);
}

.crm-table tr:last-child td {
    border-bottom: none;
}

/* ===== Badges ===== */
.badge-status {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-priority {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-priority.low { background: var(--gray-100); color: var(--gray-600); }
.badge-priority.medium { background: #dbeafe; color: #1d4ed8; }
.badge-priority.high { background: #fef3c7; color: #b45309; }
.badge-priority.urgent { background: #fee2e2; color: #dc2626; }

.badge-type {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.625rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-type.sell { background: #dcfce7; color: #15803d; }
.badge-type.buy { background: #dbeafe; color: #1d4ed8; }
.badge-type.rent { background: #fef3c7; color: #b45309; }
.badge-type.consultation { background: #f3e8ff; color: #7c3aed; }

/* ===== Lead Row ===== */
.lead-name {
    font-weight: 600;
    color: var(--graphite);
}

.lead-contact {
    font-size: 0.875rem;
    color: var(--gray-500);
}

.lead-date {
    font-size: 0.875rem;
    color: var(--gray-500);
}

/* ===== Task Item ===== */
.task-item {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1rem;
    border-radius: var(--radius-lg);
    background: var(--gray-50);
    margin-bottom: 0.75rem;
    transition: var(--transition);
}

.task-item:hover {
    background: var(--gray-100);
}

.task-item.overdue {
    background: #fef2f2;
    border-inline-start: 3px solid #ef4444;
}

.task-item.completed {
    opacity: 0.6;
}

.task-item.completed .task-title {
    text-decoration: line-through;
}

.task-checkbox {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: var(--primary);
}

.task-content {
    flex: 1;
}

.task-title {
    font-weight: 500;
    color: var(--graphite);
    margin-bottom: 0.25rem;
}

.task-meta {
    font-size: 0.8rem;
    color: var(--gray-500);
}

.task-due {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    background: var(--gray-100);
    color: var(--gray-600);
}

.task-due.overdue {
    background: #fee2e2;
    color: #dc2626;
}

/* ===== Activity Timeline ===== */
.activity-timeline {
    position: relative;
    padding-inline-start: 2rem;
}

.activity-timeline::before {
    content: '';
    position: absolute;
    inset-inline-start: 7px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--gray-200);
}

.activity-item {
    position: relative;
    padding-bottom: 1.5rem;
}

.activity-item:last-child {
    padding-bottom: 0;
}

.activity-dot {
    position: absolute;
    inset-inline-start: -2rem;
    top: 4px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    border: 3px solid white;
    box-shadow: var(--shadow-sm);
}

.activity-dot.status_changed { background: #3b82f6; }
.activity-dot.note_added { background: #8b5cf6; }
.activity-dot.call { background: #10b981; }
.activity-dot.meeting { background: #f59e0b; }
.activity-dot.showing { background: var(--gold); }
.activity-dot.created { background: var(--primary); }

.activity-content {
    background: var(--gray-50);
    padding: 0.875rem 1rem;
    border-radius: var(--radius-lg);
}

.activity-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
}

.activity-type {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--graphite);
}

.activity-time {
    font-size: 0.75rem;
    color: var(--gray-500);
}

.activity-description {
    font-size: 0.875rem;
    color: var(--gray-600);
    margin: 0;
}

.activity-user {
    font-size: 0.75rem;
    color: var(--gray-500);
    margin-top: 0.5rem;
}

/* ===== Notes ===== */
.note-item {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 1rem;
    margin-bottom: 1rem;
}

.note-item.pinned {
    border-color: var(--gold);
    background: #fffbeb;
}

.note-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.note-author {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--graphite);
}

.note-date {
    font-size: 0.75rem;
    color: var(--gray-500);
}

.note-content {
    font-size: 0.9375rem;
    color: var(--gray-700);
    line-height: 1.6;
}

/* ===== Lead Detail ===== */
.lead-detail-header {
    background: white;
    border-radius: var(--radius-xl);
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-sm);
}

.lead-detail-title {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.lead-detail-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
}

.lead-info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
}

.lead-info-item {
    padding: 1rem;
    background: var(--gray-50);
    border-radius: var(--radius-lg);
}

.lead-info-item label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--gray-500);
    display: block;
    margin-bottom: 0.25rem;
}

.lead-info-item span {
    font-weight: 500;
    color: var(--graphite);
}

/* ===== Filters ===== */
.filter-bar {
    background: white;
    border-radius: var(--radius-xl);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end;
}

.filter-group {
    flex: 1;
    min-width: 150px;
}

.filter-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--gray-500);
    margin-bottom: 0.375rem;
}

/* ===== Buttons ===== */
.btn-crm {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    border-radius: var(--radius-lg);
    font-weight: 500;
    font-size: 0.875rem;
    transition: var(--transition);
    border: none;
    cursor: pointer;
    text-decoration: none;
}

.btn-crm-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
}

.btn-crm-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    color: white;
}

.btn-crm-outline {
    background: white;
    border: 1px solid var(--gray-300);
    color: var(--gray-700);
}

.btn-crm-outline:hover {
    background: var(--gray-50);
    border-color: var(--gray-400);
    color: var(--gray-700);
}

.btn-crm-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8rem;
}

/* ===== Pagination ===== */
.crm-pagination {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 2rem;
}

.crm-pagination .page-link {
    padding: 0.5rem 0.875rem;
    border-radius: var(--radius-md);
    background: white;
    color: var(--gray-600);
    border: 1px solid var(--gray-200);
    text-decoration: none;
    transition: var(--transition);
}

.crm-pagination .page-link:hover {
    background: var(--gray-50);
    border-color: var(--primary);
    color: var(--primary);
}

.crm-pagination .page-link.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* ===== Status Selector ===== */
.status-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.status-btn {
    padding: 0.5rem 1rem;
    border-radius: var(--radius-full);
    font-size: 0.8rem;
    font-weight: 500;
    border: 2px solid;
    cursor: pointer;
    transition: var(--transition);
    background: white;
}

.status-btn:hover {
    transform: scale(1.05);
}

.status-btn.active {
    color: white;
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--gray-500);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state h4 {
    color: var(--gray-600);
    margin-bottom: 0.5rem;
}

/* ===== Mobile Navigation ===== */
.crm-mobile-header {
    background: linear-gradient(180deg, var(--graphite) 0%, #151920 100%);
    color: white;
    position: fixed;
    top: 0;
    inset-inline-start: 0;
    inset-inline-end: 0;
    z-index: 1060;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

.crm-mobile-logo {
    color: var(--primary);
    font-weight: 700;
    font-size: 1.1rem;
    text-decoration: none;
}

.crm-mobile-logo:hover {
    color: var(--primary);
}

.crm-mobile-nav {
    position: fixed;
    bottom: 0;
    inset-inline-start: 0;
    inset-inline-end: 0;
    background: white;
    display: flex;
    justify-content: space-around;
    padding: 0.5rem 0;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    z-index: 1060;
    border-top: 1px solid var(--gray-200);
}

.crm-mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.5rem 0.75rem;
    color: var(--gray-600);
    text-decoration: none;
    font-size: 0.7rem;
    transition: color 0.2s;
}

.crm-mobile-nav-item i {
    font-size: 1.1rem;
}

.crm-mobile-nav-item.active,
.crm-mobile-nav-item:hover {
    color: var(--primary);
}

.crm-mobile-nav-item.active {
    font-weight: 600;
}

/* ===== Responsive ===== */
@media (max-width: 992px) {
    .crm-sidebar {
        width: 70px;
    }

    .sidebar-header h4,
    .sidebar-link span {
        display: none;
    }

    .sidebar-link {
        justify-content: center;
        padding: 1rem;
    }

    .sidebar-link i {
        font-size: 1.25rem;
    }

    .crm-main {
        margin-inline-start: 70px;
    }

    .crm-content {
        padding: 1rem;
    }
}

@media (max-width: 768px) {
    .crm-sidebar {
        display: none;
    }

    .crm-main {
        margin-inline-start: 0;
        padding-top: 50px; /* Space for mobile header */
        padding-bottom: 70px; /* Space for mobile navigation */
    }

    .stat-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .stat-card {
        padding: 1rem;
    }

    .stat-card .number {
        font-size: 1.5rem;
    }

    .filter-row {
        flex-direction: column;
        gap: 0.75rem;
    }

    .filter-group {
        width: 100%;
    }

    /* CRM Header improvements */
    .crm-header {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }

    .crm-header h1 {
        font-size: 1.5rem;
    }

    /* Table improvements */
    .crm-table {
        font-size: 0.85rem;
    }

    .crm-table th,
    .crm-table td {
        padding: 0.625rem 0.5rem;
    }

    /* Hide less important columns on mobile */
    .crm-table .hide-mobile {
        display: none;
    }

    /* Data cards stack */
    .data-card {
        padding: 1rem;
    }

    /* Modal adjustments */
    .crm-modal .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
}

/* Small phones */
@media (max-width: 576px) {
    .stat-cards {
        grid-template-columns: 1fr;
    }

    .stat-card {
        flex-direction: row;
        align-items: center;
        gap: 1rem;
    }

    .stat-card .icon {
        margin-bottom: 0;
    }

    .stat-card .info {
        text-align: start;
    }

    .crm-content {
        padding: 0.75rem;
    }

    .crm-header h1 {
        font-size: 1.25rem;
    }

    /* Action buttons */
    .action-buttons {
        flex-direction: column;
        gap: 0.5rem;
    }

    .action-buttons .btn {
        width: 100%;
    }

    /* Kanban adjustments */
    .kanban-column {
        min-width: 280px;
    }

    /* Lead cards */
    .lead-card {
        padding: 0.75rem;
    }

    .lead-card .lead-name {
        font-size: 0.9rem;
    }
}

/* Extra small phones */
@media (max-width: 480px) {
    .crm-header {
        padding: 0.75rem;
    }

    .filter-group .form-control,
    .filter-group .form-select {
        font-size: 0.85rem;
        padding: 0.5rem 0.75rem;
    }

    .btn-sm {
        padding: 0.375rem 0.625rem;
        font-size: 0.8rem;
    }
}
