:root {
    --crm-primary: #102A43;
    --crm-blue: #2563EB;
    --crm-gold: #F59E0B;
    --crm-bg: #F5F7FB;
    --crm-border: #E2E8F0;
}

body {
    background:
        radial-gradient(circle at top right, rgba(37, 99, 235, 0.10), transparent 28%),
        radial-gradient(circle at bottom left, rgba(245, 158, 11, 0.10), transparent 32%),
        var(--crm-bg);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: #0F172A;
}

.crm-navbar {
    background: linear-gradient(135deg, #0F172A, #1D4ED8 55%, #F59E0B);
}

.nav-link {
    font-weight: 700;
    border-radius: 12px;
    padding: 8px 12px !important;
}

.nav-link:hover {
    background: rgba(255,255,255,0.12);
}

.crm-card {
    background: rgba(255,255,255,0.94);
    border: 1px solid rgba(226,232,240,0.85);
    border-radius: 22px;
    box-shadow: 0 18px 45px rgba(15, 23, 42, 0.07);
}

.crm-card-header {
    background: linear-gradient(135deg, #102A43, #2563EB);
    color: #fff;
    border-radius: 22px 22px 0 0 !important;
    border: 0;
    padding: 16px 20px;
}

.crm-soft-panel {
    background: rgba(255,255,255,0.78);
    border: 1px solid var(--crm-border);
    border-radius: 18px;
    padding: 14px;
}

.btn {
    border-radius: 12px;
    font-weight: 700;
}

.form-control,
.form-select {
    border-radius: 14px;
    border-color: #CBD5E1;
    padding: 10px 12px;
}

.table thead th {
    background: #F1F5F9;
    color: #0F172A;
    font-weight: 800;
}

.badge {
    border-radius: 999px;
    padding: 7px 10px;
}

.modal-content {
    border: 0;
    border-radius: 22px;
    box-shadow: 0 30px 90px rgba(15, 23, 42, 0.22);
}

.login-page {
    min-height: 100vh;
    background:
        radial-gradient(circle at 15% 20%, rgba(245,158,11,0.25), transparent 26%),
        radial-gradient(circle at 85% 0%, rgba(59,130,246,0.32), transparent 28%),
        linear-gradient(135deg, #0F172A, #1E3A8A);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 430px;
    border-radius: 28px;
    background: rgba(255,255,255,0.96);
    box-shadow: 0 35px 90px rgba(0,0,0,0.28);
}

.login-icon {
    width: 72px;
    height: 72px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 22px;
    background: linear-gradient(135deg, #1D4ED8, #F59E0B);
    color: #fff;
}

.stat-card {
    border-radius: 18px;
    background: #fff;
    border: 1px solid #E2E8F0;
    padding: 16px;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.05);
}

.stat-card .num {
    font-size: 26px;
    font-weight: 900;
    color: #1D4ED8;
}

.mobile-actions .btn {
    margin: 2px;
}

@media (max-width: 768px) {
    .container-fluid {
        padding-left: 12px !important;
        padding-right: 12px !important;
    }

    .table {
        font-size: 13px;
    }

    .btn-sm {
        font-size: 12px;
        padding: 6px 8px;
    }
}

/* ==============================
   Mobile Responsive Dashboard
   ============================== */
.phone-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
}

@media (max-width: 768px) {
    html,
    body {
        overflow-x: hidden;
    }

    body {
        font-size: 14px;
    }

    .container,
    .container-fluid {
        padding-left: 10px !important;
        padding-right: 10px !important;
    }

    .navbar-brand {
        font-size: 16px;
    }

    .navbar-nav {
        gap: 6px;
        padding-top: 10px;
    }

    .navbar-nav .nav-link {
        display: block;
        width: 100%;
        text-align: center;
    }

    .stat-card {
        text-align: center;
        padding: 14px 12px;
        border-radius: 16px;
    }

    .stat-card .num {
        font-size: 28px;
        line-height: 1.2;
    }

    .crm-card {
        border-radius: 16px;
        overflow: hidden;
    }

    .crm-card-header {
        flex-direction: column;
        align-items: stretch !important;
        gap: 10px !important;
        padding: 14px 12px;
        border-radius: 16px 16px 0 0 !important;
    }

    .crm-card-header h5 {
        width: 100%;
        font-size: 18px;
        text-align: center;
    }

    .crm-card-header > div {
        width: 100%;
    }

    .crm-card-header .btn {
        width: 100%;
        min-height: 42px;
    }

    .card-body {
        padding: 12px !important;
    }

    .crm-soft-panel {
        padding: 12px !important;
        border-radius: 14px;
    }

    .crm-soft-panel .form-control,
    .crm-soft-panel .form-select,
    .crm-soft-panel .btn {
        width: 100%;
        min-height: 44px;
        font-size: 14px;
    }

    #bulkBar {
        flex-direction: column;
        align-items: stretch;
    }

    #bulkBar .btn {
        width: 100%;
        min-height: 40px;
    }

    .dataTables_wrapper .row {
        gap: 8px;
    }

    .dataTables_length,
    .dataTables_filter,
    .dataTables_info,
    .dataTables_paginate {
        width: 100%;
        text-align: center !important;
    }

    .dataTables_length label,
    .dataTables_filter label {
        width: 100%;
    }

    .dataTables_filter input {
        width: 100% !important;
        margin: 8px 0 0 0 !important;
        min-height: 42px;
    }

    .dataTables_length select {
        min-height: 38px;
    }

    .dataTables_paginate .pagination {
        justify-content: center;
        flex-wrap: wrap;
        gap: 4px;
    }

    .table-responsive {
        overflow-x: visible !important;
    }

    #mainTable {
        width: 100% !important;
        border: 0 !important;
    }

    #mainTable thead {
        display: none;
    }

    #mainTable tbody,
    #mainTable tr,
    #mainTable td {
        display: block;
        width: 100% !important;
    }

    #mainTable tbody tr {
        background: #fff;
        border: 1px solid #e9ecef;
        border-radius: 18px;
        margin-bottom: 14px;
        padding: 12px;
        box-shadow: 0 8px 22px rgba(0, 0, 0, 0.06);
    }

    #mainTable tbody td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 12px;
        text-align: right !important;
        border: 0 !important;
        border-bottom: 1px solid #f1f3f5 !important;
        padding: 10px 2px !important;
        white-space: normal !important;
        word-break: break-word;
    }

    #mainTable tbody td:last-child {
        border-bottom: 0 !important;
    }

    #mainTable tbody td::before {
        content: attr(data-label);
        font-weight: 700;
        color: #495057;
        min-width: 110px;
        max-width: 120px;
        flex-shrink: 0;
        text-align: right;
    }

    #mainTable tbody td:first-child {
        justify-content: center;
    }

    #mainTable tbody td:first-child::before {
        content: "اختيار";
        min-width: auto;
    }

    #mainTable tbody td:nth-child(2) {
        display: none;
    }

    #mainTable tbody td:nth-child(3) {
        background: #f8f9fa;
        border-radius: 12px;
        margin-bottom: 4px;
        font-size: 15px;
    }

    .phone-actions {
        justify-content: flex-end;
    }

    .phone-actions .btn {
        min-height: 36px;
        padding: 6px 8px;
        font-size: 13px;
    }

    #mainTable .badge {
        white-space: normal;
        line-height: 1.6;
    }

    #mainTable td.mobile-actions {
        display: flex !important;
        flex-wrap: wrap;
        justify-content: center;
        align-items: stretch;
        gap: 6px;
    }

    #mainTable td.mobile-actions::before {
        content: "إجراءات";
        width: 100%;
        max-width: 100%;
        min-width: 100%;
        text-align: center;
        margin-bottom: 4px;
    }

    #mainTable td.mobile-actions .btn,
    #mainTable td.mobile-actions form {
        flex: 1 1 44px;
    }

    #mainTable td.mobile-actions .btn {
        width: 100%;
        min-height: 38px;
    }

    .modal-dialog {
        margin: 8px;
    }

    .modal-content {
        border-radius: 18px;
        overflow: hidden;
    }

    .modal-body {
        max-height: 75vh;
        overflow-y: auto;
    }

    .modal-body .row > [class*="col-"] {
        margin-bottom: 8px;
    }

    .modal-footer .btn {
        min-height: 44px;
    }
}


/* ==============================
   Card + Dropdown CRM Layout
   ============================== */
.customers-toolbar,
.users-toolbar {
    background: #F8FAFC;
    border: 1px solid var(--crm-border);
    border-radius: 16px;
    padding: 10px 12px;
}

.select-all-card {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 800;
    color: #0F172A;
    cursor: pointer;
}

.customers-card-list,
.users-card-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
}

.customer-card,
.user-card {
    background: #fff;
    border: 1px solid #E2E8F0;
    border-radius: 20px;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.06);
    overflow: hidden;
}

.customer-card-main,
.user-card-main {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
}

.customer-select input {
    width: 18px;
    height: 18px;
}

.customer-summary,
.user-summary {
    flex: 1;
    min-width: 0;
}

.customer-name,
.user-name {
    color: #0F172A;
    font-weight: 900;
    font-size: 17px;
}

.customer-phone,
.user-meta {
    display: flex;
    align-items: center;
    gap: 7px;
    color: #475569;
    font-weight: 700;
    word-break: break-word;
}

.customer-primary-actions,
.user-primary-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
}

.customer-details-collapse,
.user-details-collapse {
    border-top: 1px solid #E2E8F0;
    background: #F8FAFC;
}

.customer-details-grid,
.user-details-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    padding: 14px;
}

.detail-item {
    background: #fff;
    border: 1px solid #E2E8F0;
    border-radius: 14px;
    padding: 10px;
    min-height: 68px;
}

.detail-item span {
    display: block;
    color: #64748B;
    font-size: 12px;
    font-weight: 800;
    margin-bottom: 4px;
}

.detail-item strong {
    color: #0F172A;
    font-size: 14px;
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-word;
}

.detail-wide {
    grid-column: 1 / -1;
}

.customer-card-actions,
.user-card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 14px 14px;
}

.customer-card-actions .btn,
.customer-card-actions form,
.user-card-actions .btn,
.user-card-actions form {
    flex: 1 1 120px;
}

.customer-card-actions .btn,
.user-card-actions .btn {
    width: 100%;
}

.empty-customers {
    grid-column: 1 / -1;
    background: #fff;
    border: 1px dashed #CBD5E1;
    border-radius: 20px;
}


@media (min-width: 769px) {
    .customer-card,
    .user-card {
        width: 100%;
    }

    .customer-card-main,
    .user-card-main {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        min-height: 92px;
        padding: 16px 18px;
    }

    .customer-summary,
    .user-summary {
        flex: 1 1 auto;
    }

    .customer-primary-actions,
    .user-primary-actions {
        flex: 0 0 auto;
        min-width: 520px;
    }

    .customer-primary-actions .btn,
    .user-primary-actions .btn {
        min-width: 110px;
    }

    .customer-details-grid,
    .user-details-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

@media (max-width: 768px) {
    .customers-card-list,
    .users-card-list {
        grid-template-columns: 1fr;
    }

    .customer-card-main,
    .user-card-main {
        align-items: flex-start;
        flex-direction: column;
    }

    .customer-select {
        align-self: flex-start;
    }

    .customer-primary-actions,
    .user-primary-actions {
        width: 100%;
        justify-content: stretch;
    }

    .customer-primary-actions .btn,
    .user-primary-actions .btn {
        flex: 1 1 100%;
        min-height: 40px;
    }

    .customer-details-grid,
    .user-details-grid {
        grid-template-columns: 1fr;
        padding: 12px;
    }

    .customer-card-actions,
    .user-card-actions {
        flex-direction: column;
        padding: 0 12px 12px;
    }
}

/* ==============================
   Desktop Layout Enhancements
   Keeps current mobile design unchanged
   ============================== */
@media (min-width: 992px) {
    body {
        min-height: 100vh;
    }

    .navbar.crm-navbar {
        border-bottom: 1px solid rgba(255, 255, 255, 0.16);
    }

    .navbar.crm-navbar .container-fluid,
    body > .container-fluid {
        max-width: 1440px;
        margin-left: auto;
        margin-right: auto;
    }

    body > .container-fluid {
        padding-left: 28px !important;
        padding-right: 28px !important;
    }

    .navbar-brand {
        font-size: 20px;
        letter-spacing: -0.2px;
    }

    .navbar-nav {
        gap: 6px;
    }

    .navbar-nav .nav-link {
        min-height: 40px;
        display: inline-flex;
        align-items: center;
        gap: 6px;
    }

    .stat-card {
        min-height: 118px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        padding: 22px 24px;
        border-radius: 22px;
        transition: transform 0.18s ease, box-shadow 0.18s ease;
    }

    .stat-card:hover {
        transform: translateY(-2px);
        box-shadow: 0 18px 38px rgba(15, 23, 42, 0.08);
    }

    .stat-card .num {
        font-size: 34px;
        line-height: 1.15;
    }

    .crm-card {
        border-radius: 26px;
        overflow: hidden;
    }

    .crm-card-header {
        padding: 18px 24px;
        min-height: 76px;
    }

    .crm-card-header h5 {
        font-size: 22px;
        font-weight: 900;
    }

    .crm-card-header .btn {
        min-width: 138px;
        min-height: 38px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
    }

    .card-body {
        padding: 24px !important;
    }

    .crm-soft-panel {
        align-items: center;
        padding: 18px;
        border-radius: 22px;
        box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
    }

    .crm-soft-panel .form-control,
    .crm-soft-panel .form-select,
    .crm-soft-panel .btn {
        min-height: 46px;
    }

    #bulkBar {
        align-items: center;
        border-radius: 18px !important;
        padding: 12px !important;
    }

    #bulkBar .btn {
        min-width: 130px;
    }

    .customers-toolbar,
    .users-toolbar {
        padding: 13px 16px;
        border-radius: 18px;
    }

    .customers-card-list,
    .users-card-list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 18px;
        align-items: start;
    }

    .customer-card,
    .user-card {
        border-radius: 24px;
        transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
    }

    .customer-card:hover,
    .user-card:hover {
        transform: translateY(-2px);
        border-color: rgba(37, 99, 235, 0.35);
        box-shadow: 0 18px 42px rgba(15, 23, 42, 0.09);
    }

    .customer-card-main,
    .user-card-main {
        min-height: 120px;
        padding: 18px;
        align-items: center;
    }

    .customer-select,
    .user-select {
        align-self: stretch;
        display: flex;
        align-items: center;
    }

    .customer-select input,
    .select-all-card input {
        accent-color: var(--crm-blue);
    }

    .customer-summary,
    .user-summary {
        display: flex;
        flex-direction: column;
        justify-content: center;
        gap: 6px;
    }

    .customer-name,
    .user-name {
        font-size: 18px;
    }

    .customer-phone,
    .user-meta {
        font-size: 15px;
    }

    .customer-primary-actions,
    .user-primary-actions {
        flex: 0 0 210px;
        justify-content: flex-end;
        align-content: center;
    }

    .customer-primary-actions .btn,
    .user-primary-actions .btn {
        min-height: 34px;
        min-width: 96px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 5px;
    }

    .customer-details-grid,
    .user-details-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 12px;
        padding: 18px;
    }

    .detail-item {
        border-radius: 16px;
        padding: 12px;
        min-height: 76px;
    }

    .detail-item span {
        font-size: 12.5px;
    }

    .detail-item strong {
        font-size: 14.5px;
    }

    .customer-card-actions,
    .user-card-actions {
        padding: 0 18px 18px;
        justify-content: flex-end;
    }

    .customer-card-actions .btn,
    .user-card-actions .btn {
        min-height: 36px;
    }

    .modal-dialog {
        max-width: 760px;
    }

    .modal-dialog.modal-lg,
    .modal-dialog.modal-xl {
        max-width: 980px;
    }

    .modal-body .row > [class*="col-"] {
        margin-bottom: 10px;
    }
}

@media (min-width: 1400px) {
    .customers-card-list,
    .users-card-list {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .customer-primary-actions,
    .user-primary-actions {
        flex-basis: 230px;
    }
}

/* ==============================
   Customer Status Color System
   ============================== */
.customer-status-badge {
    background: #0DCAF0;
    color: #0F172A;
    font-weight: 900;
    border: 1px solid rgba(15, 23, 42, 0.08);
}

.status-color-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    padding: 7px 12px;
    border-radius: 999px;
    color: #fff;
    font-weight: 900;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.12);
}

/* ==============================
   Duplicate Mobile Filter + Cleaner Desktop Cards
   ============================== */
.duplicate-filter-toggle {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 10px;
    background: #FFFFFF;
    border: 1px solid #D7E3F4;
    border-radius: 16px;
    padding: 10px 12px;
    color: #0F172A;
    font-weight: 900;
    cursor: pointer;
}

.duplicate-filter-toggle input {
    width: 18px;
    height: 18px;
    accent-color: var(--crm-blue);
}

.duplicate-filter-toggle span {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.duplicate-filter-toggle small {
    color: #64748B;
    font-weight: 800;
}

.duplicate-filter-note {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 11px 14px;
    border-radius: 16px;
    background: #EFF6FF;
    border: 1px solid #BFDBFE;
    color: #1D4ED8;
    font-weight: 800;
}

@media (min-width: 992px) {
    .customers-card-list {
        grid-template-columns: 1fr !important;
        gap: 16px;
    }

    .customer-card-main {
        display: grid;
        grid-template-columns: 34px minmax(260px, 1fr) minmax(520px, auto);
        gap: 16px;
        align-items: center;
        min-height: 104px;
        padding: 18px 20px;
    }

    .customer-select {
        align-self: center;
        justify-content: center;
    }

    .customer-summary {
        min-width: 0;
    }

    .customer-primary-actions {
        display: grid;
        grid-template-columns: repeat(4, minmax(118px, 1fr));
        gap: 8px;
        min-width: 520px;
        flex: initial !important;
        justify-content: stretch;
    }

    .customer-primary-actions .btn {
        width: 100%;
        min-height: 39px;
        min-width: 0 !important;
        padding-inline: 10px;
        white-space: nowrap;
        border-radius: 13px;
    }

    .customer-card-actions {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(150px, max-content));
        justify-content: end;
        align-items: center;
        gap: 8px;
        padding: 0 20px 18px;
    }

    .customer-card-actions form,
    .customer-card-actions .btn {
        flex: initial !important;
        width: auto;
    }
}

@media (min-width: 1400px) {
    .customers-card-list {
        grid-template-columns: 1fr !important;
    }
}

@media (min-width: 992px) and (max-width: 1199.98px) {
    .customer-card-main {
        grid-template-columns: 34px minmax(220px, 1fr) minmax(420px, auto);
    }

    .customer-primary-actions {
        grid-template-columns: repeat(2, minmax(150px, 1fr));
        min-width: 420px;
    }
}

/* Duplicate alert + pagination polish */
.duplicate-mobile-alert {
    border-radius: 14px;
    font-weight: 800;
}

.customers-pagination .page-link {
    border-radius: 12px;
    font-weight: 800;
    color: var(--crm-primary);
}

.customers-pagination .page-item.active .page-link {
    background: var(--crm-blue);
    border-color: var(--crm-blue);
    color: #fff;
}


/* ==============================
   Today Offers Modal
   ============================== */
.today-offers-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 14px;
}

.today-offer-card {
    background: #fff;
    border: 1px solid #E2E8F0;
    border-radius: 18px;
    padding: 14px;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.06);
}

.today-offer-card h5 {
    font-weight: 900;
    margin-top: 10px;
}

.today-offer-card p {
    white-space: pre-wrap;
    color: #334155;
}

.today-offer-media {
    width: 100%;
    max-height: 260px;
    object-fit: cover;
    border-radius: 14px;
    border: 1px solid #E2E8F0;
    background: #F8FAFC;
}

.offer-edit-form {
    background: #F8FAFC;
    border: 1px dashed #CBD5E1;
    border-radius: 14px;
    padding: 10px;
}


/* ==========================================================
   UTF-8 Arabic + Mobile Layout Hotfix
   ========================================================== */
* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    direction: rtl;
    unicode-bidi: plaintext;
}

img,
video,
iframe,
table {
    max-width: 100%;
}

.form-control,
.form-select,
textarea,
input {
    unicode-bidi: plaintext;
}

.modal {
    padding-left: 0 !important;
    padding-right: 0 !important;
}

.modal-dialog {
    max-width: min(96vw, 1140px);
}

.today-offers-dialog .modal-content {
    overflow: hidden;
}

.today-offers-dialog .modal-body {
    overflow-x: hidden;
}

.today-offers-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr));
}

.today-offer-card,
.today-offer-card * {
    max-width: 100%;
}

.today-offer-card p,
.today-offer-card h5 {
    overflow-wrap: anywhere;
    word-break: break-word;
    line-height: 1.8;
    direction: rtl;
    text-align: right;
}

.today-offer-media {
    display: block;
    width: 100%;
    height: auto;
    max-height: 62vh;
    object-fit: contain;
}

@media (max-width: 576px) {
    body {
        font-size: 14px;
    }

    .container-fluid {
        padding-left: 8px !important;
        padding-right: 8px !important;
    }

    .crm-card,
    .crm-soft-panel,
    .customer-card,
    .user-card {
        border-radius: 14px;
    }

    .modal-dialog,
    .modal-dialog.modal-lg,
    .modal-dialog.modal-xl {
        width: 100vw;
        max-width: 100vw;
        height: 100vh;
        margin: 0;
    }

    .modal-content {
        min-height: 100vh;
        border-radius: 0 !important;
    }

    .modal-header,
    .modal-footer {
        padding: 10px 12px;
    }

    .modal-body {
        max-height: calc(100vh - 112px) !important;
        padding: 12px;
        overflow-x: hidden;
        overflow-y: auto;
    }

    .today-offers-grid {
        display: block;
    }

    .today-offer-card {
        margin-bottom: 12px;
        padding: 10px;
        border-radius: 14px;
    }

    .today-offer-media {
        max-height: 46vh;
        object-fit: contain;
    }

    .btn,
    .form-control,
    .form-select {
        min-height: 42px;
    }
}
