/* ══════════════════════════════════════════════════════════
   SignalMatrix AI CRM — Custom Theme
   ══════════════════════════════════════════════════════════ */

/* ── CSS Variables ── */
:root {
    --crm-primary: #2563eb;
    --crm-primary-hover: #1d4ed8;
    --crm-sidebar-width: 260px;
    --crm-sidebar-collapsed: 64px;
    --crm-header-height: 56px;
    --crm-body-bg: #f1f5f9;
    --crm-card-bg: #ffffff;
    --crm-text: #1e293b;
    --crm-text-muted: #64748b;
    --crm-border: #e2e8f0;
    --crm-success: #10b981;
    --crm-warning: #f59e0b;
    --crm-danger: #ef4444;
    --crm-info: #06b6d4;
    --crm-radius: 0.75rem;
    --crm-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --crm-shadow-lg: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
    --crm-transition: 0.2s ease;
}

/* ── Base ── */
body {
    background: var(--crm-body-bg);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: var(--crm-text);
}

/* ── Sidebar ── */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--crm-sidebar-width);
    height: 100vh;
    background: linear-gradient(180deg, #1e293b, #0f172a);
    padding: 0;
    z-index: 1040;
    overflow-y: auto;
    overflow-x: hidden;
    transition: width var(--crm-transition);
    display: flex;
    flex-direction: column;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }

.sidebar-brand {
    color: white;
    font-size: 1.15rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.25rem 1rem;
    text-decoration: none;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    flex-shrink: 0;
}

.sidebar-brand:hover { color: white; }
.sidebar-brand i { color: var(--crm-primary); font-size: 1.4rem; }

/* Sidebar nav groups */
.sidebar-nav { padding: 0.5rem 0.75rem; flex: 1; }

.sidebar-group { margin-bottom: 0.25rem; }

.sidebar-group-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #64748b;
    cursor: pointer;
    user-select: none;
    border-radius: 0.375rem;
    transition: color var(--crm-transition);
}

.sidebar-group-label:hover { color: #94a3b8; }

.sidebar-group-label .chevron {
    font-size: 0.6rem;
    transition: transform var(--crm-transition);
}

.sidebar-group.collapsed .chevron { transform: rotate(-90deg); }
.sidebar-group.collapsed .sidebar-group-items { display: none; }

.sidebar-group-items { list-style: none; padding: 0; margin: 0; }

.sidebar .nav-link {
    color: #94a3b8;
    padding: 0.55rem 0.75rem;
    border-radius: 0.5rem;
    margin-bottom: 1px;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    font-size: 0.85rem;
    transition: all var(--crm-transition);
    white-space: nowrap;
}

.sidebar .nav-link:hover { color: #e2e8f0; background: rgba(255,255,255,0.06); }
.sidebar .nav-link.active { color: white; background: rgba(37,99,235,0.2); }
.sidebar .nav-link.active i { color: var(--crm-primary); }
.sidebar .nav-link i { font-size: 1rem; width: 1.25rem; text-align: center; flex-shrink: 0; }

/* Sidebar footer */
.sidebar-footer {
    padding: 0.75rem 1rem;
    border-top: 1px solid rgba(255,255,255,0.06);
    flex-shrink: 0;
}

/* ── Main Content ── */
.main-content {
    margin-left: var(--crm-sidebar-width);
    padding: 1.5rem;
    min-height: 100vh;
    transition: margin-left var(--crm-transition);
}

/* ── Top Header Bar ── */
.crm-header {
    position: sticky;
    top: 0;
    z-index: 1030;
    background: var(--crm-card-bg);
    border-bottom: 1px solid var(--crm-border);
    padding: 0.5rem 1.5rem;
    margin: -1.5rem -1.5rem 1.5rem -1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--crm-header-height);
    box-shadow: var(--crm-shadow);
}

.crm-breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--crm-text-muted);
}

.crm-breadcrumb a { color: var(--crm-text-muted); text-decoration: none; }
.crm-breadcrumb a:hover { color: var(--crm-primary); }
.crm-breadcrumb .current { color: var(--crm-text); font-weight: 600; }

.crm-header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.crm-search {
    position: relative;
    width: 240px;
}

.crm-search input {
    background: var(--crm-body-bg);
    border: 1px solid var(--crm-border);
    border-radius: 2rem;
    padding: 0.4rem 0.75rem 0.4rem 2.25rem;
    font-size: 0.825rem;
    width: 100%;
    transition: border-color var(--crm-transition), box-shadow var(--crm-transition);
}

.crm-search input:focus {
    border-color: var(--crm-primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
    outline: none;
}

.crm-search i {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--crm-text-muted);
    font-size: 0.85rem;
}

.header-icon-btn {
    position: relative;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--crm-text-muted);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all var(--crm-transition);
}

.header-icon-btn:hover { background: var(--crm-body-bg); color: var(--crm-text); }

.header-icon-btn .badge {
    position: absolute;
    top: 2px;
    right: 2px;
    font-size: 0.6rem;
    padding: 2px 5px;
}

/* ── Cards ── */
.card {
    border: none;
    border-radius: var(--crm-radius);
    box-shadow: var(--crm-shadow);
    transition: box-shadow var(--crm-transition);
}

.card:hover { box-shadow: var(--crm-shadow-lg); }

.stat-card {
    background: var(--crm-card-bg);
    border-radius: var(--crm-radius);
    padding: 1.5rem;
    box-shadow: var(--crm-shadow);
    transition: transform var(--crm-transition), box-shadow var(--crm-transition);
}

.stat-card:hover { transform: translateY(-2px); box-shadow: var(--crm-shadow-lg); }
.stat-value { font-size: 1.75rem; font-weight: 700; color: var(--crm-text); }
.stat-label { color: var(--crm-text-muted); font-size: 0.875rem; }

/* ── Badges ── */
.badge-email { background: var(--crm-success); }
.badge-website { background: var(--crm-primary); }
.badge-phone { background: var(--crm-warning); }

/* ── User Avatar ── */
.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
    flex-shrink: 0;
}

/* ── Login ── */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
    position: relative;
    overflow: hidden;
}
.login-wrapper::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(ellipse at 30% 20%, rgba(56,189,248,0.08) 0%, transparent 50%),
                radial-gradient(ellipse at 70% 80%, rgba(14,165,233,0.06) 0%, transparent 50%);
    pointer-events: none;
}

.login-container {
    display: flex;
    width: 100%;
    max-width: 880px;
    min-height: 520px;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 25px 80px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.05);
    position: relative;
    z-index: 1;
}

.login-brand {
    flex: 1;
    background: linear-gradient(160deg, #0ea5e9, #0284c7, #0369a1);
    padding: 48px 40px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    color: #fff;
    position: relative;
    overflow: hidden;
}
.login-brand::before {
    content: '';
    position: absolute;
    top: -80px;
    right: -80px;
    width: 250px;
    height: 250px;
    border-radius: 50%;
    background: rgba(255,255,255,0.08);
}
.login-brand::after {
    content: '';
    position: absolute;
    bottom: -60px;
    left: -60px;
    width: 200px;
    height: 200px;
    border-radius: 50%;
    background: rgba(255,255,255,0.05);
}
.login-brand-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 32px;
    position: relative;
    z-index: 1;
}
.login-brand-logo img {
    width: 40px;
    height: 40px;
    filter: brightness(0) invert(1);
}
.login-brand-logo span {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.3px;
}
.login-brand h2 {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 16px;
    position: relative;
    z-index: 1;
}
.login-brand p {
    font-size: 0.95rem;
    opacity: 0.85;
    line-height: 1.6;
    position: relative;
    z-index: 1;
}
.login-brand-features {
    margin-top: 32px;
    position: relative;
    z-index: 1;
}
.login-brand-features li {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
    font-size: 0.9rem;
    opacity: 0.9;
}
.login-brand-features li i {
    font-size: 1rem;
    opacity: 0.8;
}

.login-card {
    background: #fff;
    padding: 48px 40px;
    width: 100%;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.login-card .login-heading {
    margin-bottom: 28px;
}
.login-card .login-heading h4 {
    font-size: 1.4rem;
    font-weight: 700;
    color: #0f172a;
    margin-bottom: 4px;
}
.login-card .login-heading p {
    color: #64748b;
    font-size: 0.9rem;
    margin: 0;
}
.login-card .form-label {
    font-weight: 600;
    font-size: 0.85rem;
    color: #334155;
    margin-bottom: 6px;
}
.login-card .form-control {
    padding: 12px 14px;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    font-size: 0.95rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: #f8fafc;
}
.login-card .form-control:focus {
    border-color: #0ea5e9;
    box-shadow: 0 0 0 3px rgba(14,165,233,0.1);
    background: #fff;
}
.login-card .btn-login {
    background: linear-gradient(135deg, #0ea5e9, #0284c7);
    border: none;
    padding: 12px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.95rem;
    color: #fff;
    width: 100%;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    margin-top: 8px;
}
.login-card .btn-login:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(14,165,233,0.3);
}
.login-card .login-footer {
    margin-top: 24px;
    text-align: center;
    font-size: 0.8rem;
    color: #94a3b8;
}

@media (max-width: 768px) {
    .login-container {
        flex-direction: column;
        max-width: 420px;
        min-height: auto;
    }
    .login-brand {
        padding: 32px 28px;
    }
    .login-brand h2 { font-size: 1.35rem; }
    .login-brand-features { display: none; }
    .login-card { padding: 32px 28px; max-width: 100%; }
}

/* ── Bootstrap Overrides ── */
.btn-primary {
    background: var(--crm-primary);
    border-color: var(--crm-primary);
}

.btn-primary:hover {
    background: var(--crm-primary-hover);
    border-color: var(--crm-primary-hover);
}

.table { border-color: var(--crm-border); }
.table thead th {
    background: var(--crm-body-bg);
    border-bottom-width: 1px;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--crm-text-muted);
    font-weight: 600;
}

.form-control:focus, .form-select:focus {
    border-color: var(--crm-primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

/* ── Mobile Hamburger ── */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 1050;
    width: 40px;
    height: 40px;
    border-radius: 0.5rem;
    background: #1e293b;
    color: white;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

/* ── Sidebar Overlay (mobile) ── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1035;
}

/* ── Mobile Responsive ── */
@media (max-width: 991.98px) {
    .sidebar-toggle { display: flex; }

    .sidebar {
        transform: translateX(-100%);
        width: var(--crm-sidebar-width);
    }

    .sidebar.show { transform: translateX(0); }
    .sidebar.show ~ .sidebar-overlay { display: block; }

    .main-content {
        margin-left: 0;
        padding-top: 4rem;
    }

    .crm-header { margin-top: 0; }
    .crm-search { width: 160px; }
}

@media (max-width: 575.98px) {
    .main-content { padding: 0.75rem; padding-top: 4rem; }
    .crm-header { padding: 0.5rem 0.75rem; margin: -0.75rem -0.75rem 1rem; }
    .crm-search { display: none; }
}

/* ══════════════════════════════════════════════════════════
   CONTENT AREA — Light Theme Overrides
   Forces all bg-dark cards/tables in pages to light theme
   ══════════════════════════════════════════════════════════ */

/* ── Force all cards to white ── */
.main-content .card.bg-dark,
.main-content .card[class*="bg-dark"] {
    background: var(--crm-card-bg) !important;
    color: var(--crm-text) !important;
    border: 1px solid var(--crm-border) !important;
}

.main-content .card.bg-dark .card-header,
.main-content .card[class*="bg-dark"] .card-header {
    background: var(--crm-body-bg) !important;
    color: var(--crm-text) !important;
    border-bottom: 1px solid var(--crm-border) !important;
}

.main-content .card.bg-dark .card-body,
.main-content .card[class*="bg-dark"] .card-body {
    color: var(--crm-text) !important;
}

/* ── Text color fixes inside forced-light cards ── */
.main-content .card.bg-dark .text-light,
.main-content .card.bg-dark .text-white,
.main-content .card[class*="bg-dark"] .text-light,
.main-content .card[class*="bg-dark"] .text-white {
    color: var(--crm-text) !important;
}

.main-content .card.bg-dark .text-muted,
.main-content .card[class*="bg-dark"] .text-muted {
    color: var(--crm-text-muted) !important;
}

/* ── Tables: light theme ── */
.main-content .table-dark {
    --bs-table-bg: var(--crm-card-bg);
    --bs-table-color: var(--crm-text);
    --bs-table-border-color: var(--crm-border);
    --bs-table-striped-bg: #f8fafc;
    --bs-table-hover-bg: #f1f5f9;
    --bs-table-hover-color: var(--crm-text);
}

.main-content .table-dark thead th {
    background: var(--crm-body-bg) !important;
    color: var(--crm-text-muted) !important;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
    border-bottom: 1px solid var(--crm-border) !important;
}

.main-content .table-dark tbody td {
    border-color: var(--crm-border) !important;
}

.main-content .table-dark tbody tr:hover {
    background: #f1f5f9 !important;
}

/* ── Outline buttons: fix for light bg ── */
.main-content .btn-outline-light {
    color: var(--crm-text-muted) !important;
    border-color: var(--crm-border) !important;
}
.main-content .btn-outline-light:hover {
    color: var(--crm-text) !important;
    background: var(--crm-body-bg) !important;
    border-color: var(--crm-border) !important;
}

/* ── border-secondary → crm border ── */
.main-content .border-secondary {
    border-color: var(--crm-border) !important;
}

/* ── Progress bars on light bg ── */
.main-content .progress {
    background: #e2e8f0;
}

/* ══════════════════════════════════════════════════════════
   STAT CARDS — Modern Design with Icons + Color Accents
   ══════════════════════════════════════════════════════════ */

.main-content .card.bg-dark .card-body .fs-2,
.main-content .card.bg-dark .card-body .fs-1 {
    font-weight: 800;
    letter-spacing: -0.5px;
}

/* ── Agent Status Cards (dashboard.php) ── */
.agent-card {
    background: var(--crm-card-bg) !important;
    border-radius: var(--crm-radius) !important;
    box-shadow: var(--crm-shadow) !important;
    border-left: 4px solid !important;
}
.agent-card:hover {
    box-shadow: var(--crm-shadow-lg) !important;
    transform: translateY(-2px);
}
.agent-name { color: var(--crm-text) !important; }
.agent-metric-label { color: var(--crm-text-muted) !important; }
.agent-metric-value { color: var(--crm-text) !important; }

/* ── Card header improvements ── */
.main-content .card-header {
    font-weight: 600;
    padding: 0.875rem 1.25rem;
}

.main-content .card-header h6,
.main-content .card-header .h6 {
    font-weight: 700;
    font-size: 0.9rem;
    margin: 0;
}

/* ── Better rounded card look ── */
.main-content .card {
    border-radius: var(--crm-radius);
    overflow: hidden;
}

/* ── Alert banner ── */
.main-content .alert {
    border-radius: var(--crm-radius);
    border: none;
    box-shadow: var(--crm-shadow);
}

/* ── Form elements inside cards ── */
.main-content .form-control,
.main-content .form-select {
    border-radius: 0.5rem;
    border: 1px solid var(--crm-border);
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    transition: border-color var(--crm-transition), box-shadow var(--crm-transition);
}

/* ── Dropdown menus ── */
.dropdown-menu {
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-radius);
    box-shadow: var(--crm-shadow-lg);
    padding: 0.5rem;
}
.dropdown-item {
    border-radius: 0.375rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
}
.dropdown-item:hover {
    background: var(--crm-body-bg);
}

/* ── Pagination ── */
.page-link {
    color: var(--crm-primary);
    border-color: var(--crm-border);
    border-radius: 0.375rem !important;
    margin: 0 2px;
    font-size: 0.85rem;
}
.page-item.active .page-link {
    background: var(--crm-primary);
    border-color: var(--crm-primary);
}

/* ── Modal improvements ── */
.modal-content {
    border: none;
    border-radius: var(--crm-radius);
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.modal-header {
    border-bottom: 1px solid var(--crm-border);
    padding: 1rem 1.5rem;
}
.modal-footer {
    border-top: 1px solid var(--crm-border);
    padding: 1rem 1.5rem;
}

/* ── Badge improvements ── */
.badge {
    font-weight: 600;
    letter-spacing: 0.3px;
    padding: 0.35em 0.65em;
}

/* ── Empty state ── */
.main-content .text-center.text-muted.py-4,
.main-content .text-center.text-muted.py-3 {
    font-size: 0.9rem;
    padding: 2rem !important;
}

/* ── Scrollbar in main content ── */
.main-content ::-webkit-scrollbar { width: 6px; height: 6px; }
.main-content ::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
.main-content ::-webkit-scrollbar-track { background: transparent; }

/* ── Page titles ── */
.main-content h1, .main-content .h1,
.main-content h2, .main-content .h2,
.main-content h3, .main-content .h3 {
    color: var(--crm-text);
    font-weight: 700;
}

/* ── Nav tabs / pills inside pages ── */
.main-content .nav-tabs .nav-link {
    color: var(--crm-text-muted);
    border-radius: 0.5rem 0.5rem 0 0;
    font-size: 0.875rem;
    font-weight: 500;
}
.main-content .nav-tabs .nav-link.active {
    color: var(--crm-primary);
    font-weight: 600;
    border-color: var(--crm-border) var(--crm-border) #fff;
}

.main-content .nav-pills .nav-link {
    color: var(--crm-text-muted);
    border-radius: 0.5rem;
    font-size: 0.85rem;
    padding: 0.4rem 1rem;
}
.main-content .nav-pills .nav-link.active {
    background: var(--crm-primary);
    color: white;
}

/* ── Kanban board columns ── */
.main-content .card.bg-dark .card-body .badge {
    font-size: 0.75rem;
}

/* ── Tooltip style ── */
.tooltip-inner {
    background: #1e293b;
    border-radius: 0.5rem;
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
}

/* ── Animations ── */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.main-content > *:first-child { animation: fadeIn 0.25s ease; }
