:root {
    --navy: #0a1f44;
    --navy-light: #142d5c;
    --gold: #c9a227;
    --gold-light: #e8c547;
    --white: #ffffff;
    --gray-bg: #f4f6f9;
    --text-muted: #6c757d;
    --sidebar-width: 260px;
    --font-family: 'Cairo', sans-serif;
    --bs-body-font-family: var(--font-family);
    --bs-font-sans-serif: var(--font-family);
}

@font-face {
    font-family: 'Cairo';
    src: url('/fonts/Cairo.ttf') format('truetype');
    font-weight: 200 900;
    font-style: normal;
    font-display: swap;
}

* { box-sizing: border-box; }

html, body {
    overflow-x: hidden;
    max-width: 100%;
}

body {
    font-family: var(--font-family);
    background: var(--gray-bg);
    color: #333;
    margin: 0;
}

body.rtl { font-family: var(--font-family); }

button, input, select, textarea, .btn, .form-control, .form-select, .dropdown-menu, .table, .nav-link, .card, .badge, .page-title, .sidebar, .tom-select, .ts-control, .ts-dropdown {
    font-family: var(--font-family);
}

.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: linear-gradient(180deg, var(--navy) 0%, var(--navy-light) 100%);
    color: var(--white);
    position: fixed;
    top: 0;
    z-index: 1000;
    transition: transform 0.3s ease;
}

body.ltr .sidebar { left: 0; }
body.rtl .sidebar { right: 0; }

.sidebar-brand {
    padding: 1.5rem 1.25rem;
    font-weight: 700;
    font-size: 0.95rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--gold-light);
}

.sidebar-brand i { font-size: 1.5rem; }

.sidebar-nav { padding: 1rem 0; }

.sidebar-nav .nav-link {
    color: rgba(255,255,255,0.85);
    padding: 0.75rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    transition: all 0.2s;
    border-inline-start: 3px solid transparent;
}

.sidebar-nav .nav-link:hover,
.sidebar-nav .nav-link.active {
    background: rgba(201, 162, 39, 0.15);
    color: var(--gold-light);
    border-inline-start-color: var(--gold);
}

.main-wrapper {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    width: calc(100% - var(--sidebar-width));
    min-width: 0;
    max-width: calc(100% - var(--sidebar-width));
}

body.ltr .main-wrapper { margin-left: var(--sidebar-width); margin-right: 0; }
body.rtl .main-wrapper { margin-right: var(--sidebar-width); margin-left: 0; }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(10, 31, 68, 0.45);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.show {
    display: block;
    opacity: 1;
}

.top-navbar {
    background: var(--white);
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: 0 2px 8px rgba(10,31,68,0.08);
    position: sticky;
    top: 0;
    z-index: 100;
    width: 100%;
    max-width: 100%;
}

.page-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--navy);
}

.content-area {
    padding: 1.25rem 1.5rem;
    flex: 1;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
}

.page-content {
    width: 100%;
    max-width: 1320px;
    margin: 0 auto;
}

.app-footer {
    padding: 1rem 1.5rem;
    background: var(--white);
    border-top: 1px solid #e9ecef;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.stat-card {
    background: var(--white);
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: 0 4px 12px rgba(10,31,68,0.06);
    border-inline-start: 4px solid var(--gold);
    transition: transform 0.2s;
    height: 100%;
}

.stat-card:hover { transform: translateY(-2px); }

.stat-card .stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    background: rgba(201, 162, 39, 0.15);
    color: var(--gold);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--navy);
    line-height: 1.2;
}

.stat-card .stat-label { color: var(--text-muted); font-size: 0.9rem; }

.stat-card-highlight { border-top: 4px solid var(--navy); }
.stat-card-success { border-top: 4px solid #198754; }
.stat-card-danger { border-top: 4px solid #dc3545; }
.stat-card .stat-value-sm { font-size: 1.35rem; }

.dashboard-header .dashboard-filter .form-select { border-color: rgba(10, 31, 68, 0.15); }

.dashboard-chart-wrap {
    position: relative;
    height: 280px;
}

.dashboard-chart-wrap-donut {
    height: 260px;
}

.dashboard-no-data {
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-panel {
    background: var(--white);
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(10,31,68,0.06);
    overflow: hidden;
}

.card-panel .card-header {
    background: var(--navy);
    color: var(--white);
    padding: 1rem 1.25rem;
    font-weight: 600;
}

.card-panel .card-body { padding: 1.25rem; }

.card-panel .table-responsive {
    -webkit-overflow-scrolling: touch;
}

.sidebar-toggle {
    color: var(--navy);
    padding: 0.25rem 0.5rem;
    flex-shrink: 0;
}

.btn-primary {
    background: var(--navy);
    border-color: var(--navy);
}

.btn-primary:hover {
    background: var(--navy-light);
    border-color: var(--navy-light);
}

.btn-gold {
    background: var(--gold);
    border-color: var(--gold);
    color: var(--navy);
    font-weight: 600;
}

.btn-gold:hover {
    background: var(--gold-light);
    border-color: var(--gold-light);
    color: var(--navy);
}

.btn-outline-gold {
    border-color: var(--gold);
    color: var(--navy);
}

.btn-outline-gold:hover {
    background: var(--gold);
    color: var(--navy);
}

.table thead {
    background: var(--navy);
    color: var(--white);
}

.table thead th { border: none; font-weight: 500; }

.form-control:focus, .form-select:focus {
    border-color: var(--gold);
    box-shadow: 0 0 0 0.2rem rgba(201, 162, 39, 0.25);
}

.quotation-item-row {
    background: #fafbfc;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 0.75rem;
    border: 1px solid #e9ecef;
}

.totals-box {
    background: linear-gradient(135deg, var(--navy) 0%, var(--navy-light) 100%);
    color: var(--white);
    border-radius: 12px;
    padding: 1.25rem;
}

.totals-box .grand-total {
    font-size: 1.5rem;
    color: var(--gold-light);
    font-weight: 700;
}

.badge-status { font-size: 0.8rem; padding: 0.4em 0.8em; }

.low-stock-badge { font-size: 0.7rem; vertical-align: middle; }
.low-stock-nav-badge { font-size: 0.65rem; min-width: 1.1rem; }
.low-stock-dropdown { min-width: 280px; max-height: 360px; overflow-y: auto; }
.low-stock-dropdown-item { white-space: normal; }
.low-stock-banner { border-right: 4px solid var(--gold); }
body.rtl .low-stock-banner { border-right: none; border-left: 4px solid var(--gold); }
.low-stock-panel { border: 1px solid rgba(255, 193, 7, 0.5) !important; }

/* Tom Select searchable dropdowns */
select.form-select.tomselected,
select.tomselected {
    display: none !important;
}

.ts-wrapper.form-select,
.ts-wrapper.single {
    padding: 0;
    border: none;
    background: transparent;
}

.ts-wrapper .ts-control {
    min-height: calc(1.5em + 0.75rem + 2px);
    padding: 0.375rem 2.25rem 0.375rem 0.75rem;
    border: 1px solid #ced4da;
    border-radius: 0.375rem;
    background-color: #fff;
    font-size: 1rem;
    line-height: 1.5;
}

body.rtl .ts-wrapper .ts-control {
    padding: 0.375rem 0.75rem 0.375rem 2.25rem;
    text-align: right;
    direction: rtl;
}

.ts-wrapper.focus .ts-control {
    border-color: var(--gold);
    box-shadow: 0 0 0 0.2rem rgba(201, 162, 39, 0.25);
}

.ts-wrapper.form-select-sm .ts-control,
.ts-wrapper.single.form-select-sm .ts-control {
    min-height: calc(1.5em + 0.5rem + 2px);
    padding-top: 0.25rem;
    padding-bottom: 0.25rem;
    font-size: 0.875rem;
}

.ts-dropdown {
    z-index: 1055;
    border-radius: 0.375rem;
    border-color: #ced4da;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.1);
}

body.rtl .ts-dropdown {
    direction: rtl;
    text-align: right;
}

.ts-dropdown .no-results {
    font-size: 0.875rem;
}

@media (max-width: 991.98px) {
    body {
        overflow-x: hidden;
    }

    body.ltr .sidebar { transform: translateX(-100%); left: 0; right: auto; }
    body.rtl .sidebar { transform: translateX(100%); right: 0; left: auto; }

    .sidebar.show {
        transform: translateX(0) !important;
    }

    body.ltr .main-wrapper,
    body.rtl .main-wrapper {
        margin: 0 !important;
        width: 100%;
        max-width: 100vw;
    }

    .top-navbar {
        padding: 0.75rem 1rem;
        gap: 0.5rem;
    }

    .page-title {
        font-size: 1rem;
        flex: 1;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .navbar-actions {
        flex-shrink: 0;
    }

    .navbar-actions .btn {
        padding: 0.375rem 0.625rem;
        font-size: 0.875rem;
    }

    .content-area {
        padding: 1rem;
    }

    .app-footer {
        padding: 0.75rem 1rem;
        font-size: 0.8rem;
        text-align: center;
    }

    .stat-card {
        padding: 1rem;
    }

    .stat-card .stat-value {
        font-size: 1.5rem;
    }

    .stat-card .stat-icon {
        width: 40px;
        height: 40px;
        font-size: 1.25rem;
        flex-shrink: 0;
    }

    .low-stock-banner {
        flex-direction: column;
        align-items: stretch !important;
    }

    .low-stock-dropdown {
        min-width: min(280px, calc(100vw - 2rem));
    }

    .card-panel .card-header {
        padding: 0.875rem 1rem;
        font-size: 0.95rem;
    }

    .card-panel .card-body.p-0 {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .table thead th,
    .table tbody td {
        white-space: nowrap;
        font-size: 0.875rem;
    }

    .btn-sm {
        padding: 0.25rem 0.5rem;
        font-size: 0.8rem;
    }
}

@media (max-width: 575.98px) {
    .stat-card .stat-value {
        font-size: 1.35rem;
    }

    .stat-card .stat-label {
        font-size: 0.8rem;
    }
}

.contract-preview-iframe {
    width: 100%;
    min-height: 720px;
    height: calc(100vh - 220px);
    border: 0;
    background: #f8f9fa;
}

.contract-preview-frame .card-body {
    min-height: 720px;
}

.share-qr-wrap {
    width: 200px;
    padding: 0.75rem;
    border: 1px dashed rgba(10, 31, 68, 0.2);
    border-radius: 12px;
    background: #fff;
}

.share-page-header {
    background: linear-gradient(90deg, var(--navy) 0%, var(--navy-light) 100%);
}

body.share-page {
    background: var(--gray-bg);
}

body.setup-page {
    background: linear-gradient(180deg, #eef3fb 0%, var(--gray-bg) 100%);
    min-height: 100vh;
}

.setup-shell {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem 1rem 3rem;
}

.setup-brand .bi {
    color: var(--navy);
}

.setup-content .card-panel {
    box-shadow: 0 12px 40px rgba(10, 31, 68, 0.08);
}

.pdf-template-preview {
    min-height: 280px;
    box-shadow: inset 0 0 0 1px rgba(10, 31, 68, 0.06);
}

.pdf-preview-logo {
    max-height: 56px;
    max-width: 72px;
    object-fit: contain;
}

.pdf-preview-stamp {
    max-height: 44px;
    max-width: 72px;
    object-fit: contain;
}

.pdf-preview-doc .table thead th {
    border: none;
    font-size: 0.85em;
}
