/* ============================================================
   CRM System - Custom Styles (Fully Responsive)
   ============================================================ */

:root {
    --sidebar-bg: #1a1a2e;
    --sidebar-hover: #16213e;
    --sidebar-active: #0f3460;
    --sidebar-text: #a8b2c8;
    --sidebar-text-active: #ffffff;
    --sidebar-width: 260px;
    --topbar-height: 56px;
    --primary: #0f3460;
    --accent: #e94560;
    --success: #198754;
    --warning: #ffc107;
    --danger: #dc3545;
    --info: #0dcaf0;
}

/* ---- Base ---- */
*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f0f2f5;
    font-size: 14px;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
}

img, svg { max-width: 100%; }

/* ============================================================
   LAYOUT WRAPPER
   ============================================================ */
.wrapper {
    display: flex;
    min-height: 100vh;
    position: relative;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--sidebar-bg);
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 1050;
    box-shadow: 2px 0 10px rgba(0,0,0,0.2);
    transition: transform 0.3s ease, width 0.3s ease;
    flex-shrink: 0;
}

/* Sidebar scrollbar */
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: var(--sidebar-bg); }
.sidebar::-webkit-scrollbar-thumb { background: #444; border-radius: 2px; }

/* Brand / Header */
.sidebar-header {
    position: sticky;
    top: 0;
    background: var(--sidebar-bg);
    z-index: 10;
}
.brand-text { font-size: 16px; white-space: nowrap; }

/* Avatar */
.avatar-circle {
    width: 32px;
    height: 32px;
    background: var(--sidebar-active);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 14px;
    flex-shrink: 0;
}

/* Nav items */
.sidebar-nav { padding: 4px 0; }
.sidebar-menu-title {
    border-bottom: 1px solid rgba(255,255,255,0.08);
    padding-left: 16px;
}
.sidebar-section-title {
    padding-left: 16px;
}
.sidebar-item { position: relative; }

.sidebar-link {
    display: flex;
    align-items: center;
    padding: 11px 16px;
    color: var(--sidebar-text);
    text-decoration: none;
    transition: all 0.2s;
    gap: 10px;
    white-space: nowrap;
    border-radius: 0 24px 24px 0;
}
.sidebar-link:hover,
.sidebar-item.active > .sidebar-link {
    background: var(--sidebar-active);
    color: var(--sidebar-text-active);
    text-decoration: none;
}
.sidebar-link i { font-size: 15px; width: 18px; flex-shrink: 0; }
.sidebar-link .arrow {
    margin-left: auto !important;
    font-size: 11px;
    transition: transform 0.2s;
}
.sidebar-link[aria-expanded="true"] .arrow { transform: rotate(180deg); }

/* Sub-menu */
.sub-menu {
    background: rgba(0,0,0,0.2);
    padding: 4px 0;
}
.sub-menu li a {
    display: block;
    padding: 8px 16px 8px 44px;
    color: var(--sidebar-text);
    text-decoration: none;
    transition: all 0.2s;
    white-space: nowrap;
    font-size: 13px;
}
.sub-menu li a:hover,
.sub-menu li.active a {
    color: #fff;
    background: rgba(255,255,255,0.06);
}

.sidebar-divider {
    border-top: 1px solid rgba(255,255,255,0.08);
}

/* Sidebar overlay (mobile) */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1040;
}
.sidebar-overlay.show { display: block; }

/* ============================================================
   MAIN CONTENT
   ============================================================ */
#content {
    margin-left: var(--sidebar-width);
    transition: margin-left 0.3s ease;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0; /* prevent flex overflow */
}

/* Top Navbar */
.top-navbar {
    height: var(--topbar-height);
    position: sticky;
    top: 0;
    z-index: 999;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.top-navbar .navbar-date {
    font-size: 13px;
    color: #6c757d;
}

/* Page Content */
.page-content {
    flex: 1;
    padding: 24px;
}

/* ============================================================
   PAGE HEADER
   ============================================================ */
.page-header {
    margin-bottom: 20px;
}
.page-header h1 {
    font-size: 20px;
    font-weight: 700;
    color: #1a1a2e;
    margin-bottom: 4px;
}
.page-header .breadcrumb {
    margin-bottom: 0;
    font-size: 12px;
    flex-wrap: wrap;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
    border: none;
    border-radius: 10px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.07);
}
.card-header {
    background: #fff;
    border-bottom: 1px solid #eee;
    font-weight: 600;
    border-radius: 10px 10px 0 0 !important;
    padding: 14px 20px;
    flex-wrap: wrap;
    gap: 8px;
}

/* Stat cards */
.stat-card {
    border-radius: 12px;
    border: none;
    box-shadow: 0 4px 15px rgba(0,0,0,0.08);
    transition: transform 0.2s, box-shadow 0.2s;
    overflow: hidden;
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.12);
}
.stat-card .stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}
.stat-card .stat-value {
    font-size: 26px;
    font-weight: 700;
    line-height: 1;
}
.stat-card .stat-label {
    font-size: 12px;
    color: #6c757d;
    margin-top: 4px;
}

/* Quick link cards */
.quick-link-card {
    border: none;
    border-radius: 10px;
    text-align: center;
    padding: 16px 8px;
    text-decoration: none;
    transition: all 0.2s;
    display: block;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    background: #fff;
    height: 100%;
}
.quick-link-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.12);
    text-decoration: none;
}
.quick-link-card .ql-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    margin: 0 auto 8px;
}
.quick-link-card .ql-label {
    font-size: 12px;
    font-weight: 600;
    color: #333;
    line-height: 1.3;
}

/* ============================================================
   STATUS BADGES
   ============================================================ */
.badge-unassigned         { background-color: #dc3545; color: #fff; }
.badge-assigned           { background-color: #198754; color: #fff; }
.badge-company_unassigned { background-color: #fd7e14; color: #fff; }
.badge-sales_lead         { background-color: #0d6efd; color: #fff; }
.badge-purchase_lead      { background-color: #6f42c1; color: #fff; }
.badge-sales_order        { background-color: #20c997; color: #fff; }
.badge-pending            { background-color: #ffc107; color: #000; }
.badge-in_progress        { background-color: #0dcaf0; color: #000; }
.badge-completed          { background-color: #198754; color: #fff; }
.badge-reviewed           { background-color: #6c757d; color: #fff; }
.badge-active             { background-color: #198754; color: #fff; }
.badge-inactive           { background-color: #6c757d; color: #fff; }

.status-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: capitalize;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

/* ============================================================
   TABLES
   ============================================================ */
.table-responsive {
    border-radius: 8px;
    -webkit-overflow-scrolling: touch;
}
.table thead th {
    background: #f8f9fa;
    border-color: #e9ecef;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #495057;
    white-space: nowrap;
    padding: 10px 12px;
    position: sticky;
    top: 0;
    z-index: 1;
}
.table tbody td {
    vertical-align: middle;
    font-size: 13px;
    padding: 8px 12px;
    color: #333;
    border-color: #f0f0f0;
}
.table tbody tr:hover { background: #f8f9ff; }

/* Leads wide table */
.leads-table-wrapper {
    overflow-x: auto;
    border-radius: 8px;
    -webkit-overflow-scrolling: touch;
}
.leads-table { min-width: 2200px; }

/* Scrollbar for table */
.table-scroll::-webkit-scrollbar { height: 6px; }
.table-scroll::-webkit-scrollbar-track { background: #f1f1f1; border-radius: 3px; }
.table-scroll::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }
.table-scroll::-webkit-scrollbar-thumb:hover { background: #aaa; }

/* ============================================================
   FORMS
   ============================================================ */
.form-label {
    font-weight: 600;
    font-size: 13px;
    color: #555;
    margin-bottom: 4px;
}
.form-control, .form-select {
    border-radius: 8px;
    border: 1px solid #dee2e6;
    font-size: 13px;
    padding: 8px 12px;
    transition: border-color 0.2s, box-shadow 0.2s;
    max-width: 100%;
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(15,52,96,0.12);
}
.form-section-title {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #888;
    padding-bottom: 8px;
    border-bottom: 2px solid #eee;
    margin-bottom: 16px;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    border-radius: 8px;
    font-size: 13px;
    padding: 7px 14px;
    font-weight: 500;
    white-space: nowrap;
}
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: #0d2d56; border-color: #0d2d56; }
.btn-sm  { padding: 4px 10px; font-size: 12px; }
.btn-xs  { padding: 2px 7px;  font-size: 11px; border-radius: 6px; }

/* ============================================================
   TABS
   ============================================================ */
.nav-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    border-bottom: 1px solid #dee2e6;
}
.nav-tabs::-webkit-scrollbar { display: none; }
.nav-tabs .nav-item { flex-shrink: 0; }
.nav-tabs .nav-link {
    border-radius: 8px 8px 0 0;
    font-size: 13px;
    font-weight: 500;
    color: #6c757d;
    padding: 8px 14px;
    white-space: nowrap;
}
.nav-tabs .nav-link.active {
    color: var(--primary);
    font-weight: 700;
    background: #fff;
    border-color: #dee2e6 #dee2e6 #fff;
}
.tab-content {
    background: #fff;
    border: 1px solid #dee2e6;
    border-top: none;
    border-radius: 0 0 10px 10px;
    padding: 16px;
}

/* ============================================================
   FILTER BAR
   ============================================================ */
.filter-bar {
    background: #fff;
    border-radius: 10px;
    padding: 14px 16px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

/* ============================================================
   PAGINATION
   ============================================================ */
.pagination {
    flex-wrap: wrap;
    gap: 2px;
}
.pagination .page-link {
    border-radius: 6px !important;
    margin: 0 2px;
    font-size: 13px;
    color: var(--primary);
    border-color: #dee2e6;
}
.pagination .page-item.active .page-link {
    background: var(--primary);
    border-color: var(--primary);
}

/* ============================================================
   ALERTS
   ============================================================ */
.alert { border-radius: 8px; font-size: 13px; }

/* ============================================================
   MODALS
   ============================================================ */
.modal-content {
    border-radius: 12px;
    border: none;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
}
.modal-header { border-radius: 12px 12px 0 0; }

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-wrapper {
    min-height: 100vh;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.login-card {
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    width: 100%;
    max-width: 420px;
    padding: 36px 32px;
}
.login-logo {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, #0f3460, #e94560);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    font-size: 28px;
    color: white;
}

/* ============================================================
   LEAD DETAIL VIEW
   ============================================================ */
.detail-field  { margin-bottom: 12px; }
.detail-label  { font-size: 11px; font-weight: 700; text-transform: uppercase; color: #999; letter-spacing: 0.5px; }
.detail-value  { font-size: 14px; color: #333; margin-top: 2px; word-break: break-word; }

/* ============================================================
   ANALYTICS
   ============================================================ */
.progress { border-radius: 10px; height: 8px; }
.progress-bar { border-radius: 10px; }

/* ============================================================
   UTILITIES
   ============================================================ */
.text-truncate-custom {
    max-width: 120px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cursor-pointer { cursor: pointer; }
.bg-light-primary { background: rgba(15,52,96,0.08); }
.border-left-primary { border-left: 4px solid var(--primary) !important; }
.border-left-success { border-left: 4px solid #198754 !important; }
.border-left-warning { border-left: 4px solid #ffc107 !important; }
.border-left-danger  { border-left: 4px solid #dc3545 !important; }
.border-left-info    { border-left: 4px solid #0dcaf0 !important; }
.border-left-purple  { border-left: 4px solid #6f42c1 !important; }

/* ============================================================
   ██████╗ ███████╗███████╗██████╗  ██████╗ ███╗   ██╗███████╗
   ██╔══██╗██╔════╝██╔════╝██╔══██╗██╔═══██╗████╗  ██║██╔════╝
   ██████╔╝█████╗  ███████╗██████╔╝██║   ██║██╔██╗ ██║███████╗
   ██╔══██╗██╔══╝  ╚════██║██╔═══╝ ██║   ██║██║╚██╗██║╚════██║
   ██║  ██║███████╗███████║██║     ╚██████╔╝██║ ╚████║███████║
   ╚═╝  ╚═╝╚══════╝╚══════╝╚═╝      ╚═════╝ ╚═╝  ╚═══╝╚══════╝
   ============================================================ */

/* ---- Large tablets (992px – 1199px) ---- */
@media (max-width: 1199px) {
    :root { --sidebar-width: 240px; }

    .stat-card .stat-value { font-size: 22px; }
    .stat-card .stat-icon  { width: 44px; height: 44px; font-size: 18px; }
}

/* ---- Tablets (768px – 991px) ---- */
@media (max-width: 991px) {
    :root { --sidebar-width: 220px; }

    .page-content { padding: 16px; }

    /* Sidebar hides off-canvas by default on tablets */
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.mobile-open {
        transform: translateX(0);
    }
    #content {
        margin-left: 0 !important;
    }

    /* Stats: 2-column grid on tablets */
    .stats-row .col-xl-3 { flex: 0 0 50%; max-width: 50%; }

    /* Quick links: 4 per row on tablets */
    .quick-links-row .col-xl-3 { flex: 0 0 25%; max-width: 25%; }

    /* Filter bar: wrap gracefully */
    .filter-bar .row { row-gap: 8px; }

    /* Navbar: hide date on tablet */
    .top-navbar .navbar-date { display: none; }

    /* Nav tabs: make scrollable */
    .nav-tabs { flex-wrap: nowrap; overflow-x: auto; }

    /* Tab content padding */
    .tab-content { padding: 12px; }
}

/* ---- Mobile (< 768px) ---- */
@media (max-width: 767px) {
    .page-content { padding: 12px; }

    /* ---- Sidebar: full off-canvas ---- */
    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width) !important;
    }
    .sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0,0,0,0.4);
    }
    #content { margin-left: 0 !important; }

    /* ---- Top Navbar ---- */
    .top-navbar { padding: 0 12px !important; }
    .top-navbar .navbar-date { display: none; }
    .top-navbar .dropdown-toggle { font-size: 12px; }

    /* ---- Page Header ---- */
    .page-header h1 { font-size: 17px; }
    .page-header .breadcrumb { font-size: 11px; }

    /* ---- Stat cards: 2 columns on mobile ---- */
    .stat-card .stat-value { font-size: 20px; }
    .stat-card .stat-icon  { width: 40px; height: 40px; font-size: 16px; }
    .stat-card .card-body  { padding: 10px !important; gap: 10px !important; }

    /* ---- Quick links: 2 per row ---- */
    .quick-link-card { padding: 12px 6px; }
    .quick-link-card .ql-icon  { width: 36px; height: 36px; font-size: 15px; }
    .quick-link-card .ql-label { font-size: 11px; }

    /* ---- Cards ---- */
    .card-header { padding: 12px 14px; font-size: 13px; }
    .card-body   { padding: 12px !important; }

    /* ---- Tables ---- */
    .table thead th { font-size: 11px; padding: 8px 8px; }
    .table tbody td { font-size: 12px; padding: 7px 8px; }
    .table-responsive { font-size: 12px; }

    /* ---- Leads wide table: keep scroll ---- */
    .leads-table-wrapper { overflow-x: auto; }
    .leads-table { min-width: 2200px; }

    /* ---- Filter bar ---- */
    .filter-bar { padding: 12px; }
    .filter-bar .row { gap: 6px 0; }
    .filter-bar [class*="col-md"] { flex: 0 0 100%; max-width: 100%; }

    /* ---- Forms ---- */
    .row.g-3 > [class*="col-md"],
    .row.g-3 > [class*="col-lg"] {
        flex: 0 0 100%;
        max-width: 100%;
    }
    .row.g-4 > [class*="col-md"],
    .row.g-4 > [class*="col-lg"] {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* ---- Page header action buttons ---- */
    .page-header { flex-direction: column; align-items: flex-start !important; }
    .page-header > a.btn, .page-header > .btn { align-self: flex-start; }

    /* ---- Tabs: scrollable ---- */
    .nav-tabs  { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 1px; }
    .nav-tabs .nav-link { padding: 7px 12px; font-size: 12px; }
    .tab-content { padding: 10px; }

    /* ---- Analytics report card stats ---- */
    .report-card-stats { flex-wrap: wrap; gap: 8px; }
    .report-card-stats .col { min-width: 60px; }

    /* ---- Modals ---- */
    .modal-dialog { margin: 8px; }
    .modal-body   { padding: 12px; }

    /* ---- Login ---- */
    .login-card { padding: 24px 18px; }

    /* ---- Pagination ---- */
    .pagination .page-link { padding: 4px 8px; font-size: 12px; }

    /* ---- Buttons in action columns ---- */
    .btn-xs { padding: 2px 5px; font-size: 10px; }

    /* ---- Enquiry / My Leads tabs ---- */
    .nav-tabs-scroll { overflow-x: auto; }
}

/* ---- Very small (< 400px) ---- */
@media (max-width: 400px) {
    :root { --sidebar-width: 240px; }

    .page-content { padding: 8px; }
    .page-header h1 { font-size: 15px; }

    .stat-card .card-body { flex-direction: column; text-align: center; }
    .stat-card .stat-icon  { margin: 0 auto; }
    .stat-card .stat-value { font-size: 18px; }

    .login-card { padding: 20px 14px; border-radius: 12px; }
    .login-logo  { width: 52px; height: 52px; font-size: 22px; }
}

.site-footer {
    background: #002675;
    color: #f5f7ff;
}
.site-footer .footer-heading {
    color: #ffffff;
    font-size: 1.05rem;
    font-weight: 700;
}
.footer-section { background: #f3f6fb; }
.footer-card { background: #0f5bb5; }
.footer-card-logo { width: 76px; height: 76px; }
.footer-card-img { width: 42px; height: 42px; }
.footer-heading { font-size: 1.03rem; font-weight: 700; color: #0f1d43; }
.footer-contact li,
.footer-links li { margin-bottom: .9rem; display: flex; align-items: center; gap: .65rem; }
.footer-contact li { color: #1f2b47; }
.footer-links li a { color: #0f5bb5; text-decoration: none; }
.footer-links li a:hover { color: #0b3a7d; }
.footer-heading, .footer-card .h5, .footer-card .footer-heading { color: #0f1d43; }
.footer-card { border-radius: 1.5rem; padding: 2rem; color: #ffffff; }
.footer-card p, .footer-card .footer-heading { color: rgba(255,255,255,.9); }
.footer-timing { background: #ffffff; border: 1px solid rgba(15,23,42,.08); color: #0f172a; }
.footer-contact .footer-icon, .footer-card-logo { font-size: 1rem; }
.footer-icon { font-size: 1rem; color: #0f5bb5; }
.footer-bottom { border-color: rgba(15,23,42,.12); color: #6b7280; }
@media (max-width: 991px) {
    .footer-card { padding: 1.6rem; }
}
@media (max-width: 767px) {
    .footer-contact li,
    .footer-links li { font-size: .95rem; gap: .5rem; }
    .footer-heading { font-size: 1rem; }
}
@media (max-width: 767px) {
    .site-footer .footer-contact li,
    .site-footer .footer-links li {
        gap: .5rem;
        font-size: .92rem;
    }
    .site-footer .footer-heading {
        font-size: 1rem;
    }
}

/* ============================================================
   SIDEBAR COLLAPSED (desktop toggle)
   ============================================================ */
@media (min-width: 992px) {
    .sidebar.collapsed {
        width: 60px;
        overflow: visible;
    }
    .sidebar.collapsed .brand-text,
    .sidebar.collapsed .sidebar-link span,
    .sidebar.collapsed .arrow,
    .sidebar.collapsed .sub-menu,
    .sidebar.collapsed .sidebar-header .d-flex > div:last-child {
        display: none !important;
    }
    .sidebar.collapsed .sidebar-link {
        justify-content: center;
        padding: 12px;
    }
    .sidebar.collapsed .sidebar-link i { width: auto; margin: 0; }
    .sidebar.collapsed .avatar-circle { margin-right: 0 !important; }
    #content.collapsed-content { margin-left: 60px; }
}
