*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0a1020;
    --surface: #0f172a;
    --surface-2: #1a2540;
    --border: #1e2d48;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --primary: #3b82f6;
    --green: #22c55e;
    --amber: #f59e0b;
    --red: #ef4444;
    --violet: #8b5cf6;
    --cyan: #06b6d4;
    --radius: .75rem;
    --header-h: 56px;
}

html, body {
    font-family: 'Cairo', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #0a1020;
    color: #f1f5f9;
    min-height: 100vh;
    direction: rtl;
    overflow-x: hidden;
}

.ma-header {
    position: sticky;
    top: 0;
    z-index: 40;
    height: 56px;
    background: rgba(15,23,42,.92);
    border-bottom: 1px solid #1e2d48;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
    gap: .75rem;
}

.ma-header__brand {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-weight: 900;
    font-size: 1rem;
    color: #f1f5f9;
    text-decoration: none;
}

.ma-header__end {
    display: flex;
    align-items: center;
    gap: .75rem;
}

.ma-btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: .75rem;
    border: 1px solid #1e2d48;
    background: #1a2540;
    color: #f1f5f9;
    cursor: pointer;
}

.ma-btn-icon svg { width: 18px; height: 18px; }

#ma-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.6);
    z-index: 50;
}

#ma-overlay.open { display: block; }

#ai-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.6);
    z-index: 65;
}

#ai-overlay.open { display: block; }

.ma-sidebar {
    position: fixed;
    top: 0;
    right: -320px;
    width: 280px;
    height: 100vh;
    height: 100dvh;
    background: #0f172a;
    border-left: 1px solid #1e2d48;
    z-index: 60;
    display: flex;
    flex-direction: column;
    transition: right .25s cubic-bezier(.4,0,.2,1);
    overflow-y: auto;
}

.ma-sidebar.open { right: 0; }

/* AI Sidebar Styles */
.ai-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    max-width: 400px;
    height: 100vh;
    height: 100dvh;
    background: #0f172a;
    border-right: 1px solid #1e2d48;
    z-index: 70;
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform .25s cubic-bezier(.4,0,.2,1);
}

.ai-sidebar.open { transform: translateX(0); }

.ai-sidebar__header {
    padding: 1rem;
    border-bottom: 1px solid #1e2d48;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #1a2540;
}

.ai-sidebar__title {
    font-weight: 700;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #f1f5f9;
}

.ai-sidebar__body {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.ai-sidebar__footer {
    padding: 1rem;
    border-top: 1px solid #1e2d48;
    background: #1a2540;
}

.ai-chat-messages {
    height: calc(100% - 60px);
    overflow-y: auto;
    margin-bottom: 1rem;
    padding: 0.5rem;
}

.ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.ai-chat-messages::-webkit-scrollbar-track {
    background: #1a2540;
    border-radius: 3px;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: #1e2d48;
    border-radius: 3px;
}

.ai-message {
    padding: 8px 12px;
    border-radius: 8px;
    margin: 4px 0;
    max-width: 90%;
    font-size: 0.8rem;
    line-height: 1.4;
    word-wrap: break-word;
}

.ai-message.user {
    background: linear-gradient(135deg, #3b82f6, #3b82f6);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.ai-message.assistant {
    background: #1a2540;
    color: #f1f5f9;
    margin-right: auto;
    border-bottom-left-radius: 4px;
    border: 1px solid #1e2d48;
}

.ai-message pre {
    background: #0a1020;
    padding: 10px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
    font-size: 0.85rem;
    border: 1px solid #1e2d48;
}

.ai-message code {
    background: #0a1020;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85rem;
    border: 1px solid #1e2d48;
}

.ai-message ul, .ai-message ol {
    margin: 8px 0;
    padding-left: 20px;
}

.ai-message li {
    margin: 4px 0;
}

.ai-message strong {
    font-weight: 700;
}

.ai-message table {
    margin: 8px 0;
    border-collapse: collapse;
    width: 100%;
}

.ai-message table th {
    background: #1a2540;
    padding: 8px;
    border: 1px solid #1e2d48;
    font-weight: 600;
    font-size: 0.75rem;
}

.ai-message table td {
    padding: 8px;
    border: 1px solid #1e2d48;
    font-size: 0.8rem;
}

.ai-message a {
    color: #3b82f6;
    text-decoration: none;
}

.ai-message a:hover {
    text-decoration: underline;
}

.ma-sidebar__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #1e2d48;
}

.ma-sidebar__title { font-weight: 900; font-size: .95rem; }

.ma-nav {
    padding: .75rem .5rem;
    list-style: none;
}

.ma-nav__section {
    padding: .5rem .75rem .2rem;
    font-size: .65rem;
    font-weight: 800;
    letter-spacing: .08em;
    color: #94a3b8;
    text-transform: uppercase;
}

.ma-nav a {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .55rem .75rem;
    border-radius: .5rem;
    font-size: .85rem;
    font-weight: 600;
    color: #94a3b8;
    text-decoration: none;
    transition: background .12s, color .12s;
}

.ma-nav a svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.ma-nav a:hover,
.ma-nav a.active {
    background: rgba(59,130,246,.15);
    color: #3b82f6;
}

.ma-main {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    padding: .75rem 1.25rem 1.25rem;
}

.ma-container {
    display: flex;
    min-height: 100vh;
}

.ma-content {
    flex: 1;
    min-width: 0;
}

.ma-stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: .75rem;
    margin-bottom: 1.25rem;
}

.ma-stat-card {
    background: #0f172a;
    border: 1px solid #1e2d48;
    border-radius: .75rem;
    padding: 1rem;
}

.ma-stat-card__label {
    font-size: .75rem;
    color: #94a3b8;
    margin-bottom: .5rem;
}

.ma-stat-card__value {
    font-size: 1.25rem;
    font-weight: 700;
    color: #f1f5f9;
}

.ma-card {
    background: #0f172a;
    border: 1px solid #1e2d48;
    border-radius: .75rem;
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.ma-card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.ma-card__title {
    font-size: 1rem;
    font-weight: 700;
    color: #f1f5f9;
}

.ma-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    padding: .5rem 1rem;
    border-radius: .5rem;
    border: none;
    font-family: inherit;
    font-size: .875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
}

.ma-btn--primary {
    background: #3b82f6;
    color: white;
}

.ma-btn--primary:hover {
    background: #2563eb;
}

.ma-table {
    width: 100%;
    border-collapse: collapse;
}

.ma-table th,
.ma-table td {
    padding: .75rem;
    text-align: right;
    border-bottom: 1px solid #1e2d48;
}

.ma-table th {
    font-size: .75rem;
    font-weight: 600;
    color: #94a3b8;
    text-transform: uppercase;
}

.ma-table td {
    font-size: .875rem;
    color: #f1f5f9;
}

.ma-badge {
    display: inline-flex;
    align-items: center;
    padding: .25rem .5rem;
    border-radius: .25rem;
    font-size: .75rem;
    font-weight: 600;
}

.ma-badge--success {
    background: rgba(34,197,94,.15);
    color: #22c55e;
}

.ma-badge--warning {
    background: rgba(245,158,11,.15);
    color: #f59e0b;
}

.ma-badge--danger {
    background: rgba(239,68,68,.15);
    color: #ef4444;
}

@media (min-width: 1024px) {
    .ma-sidebar {
        position: relative;
        top: auto;
        right: auto;
        height: 100%;
        width: 280px;
        flex-shrink: 0;
        border-left: none;
        border-right: 1px solid #1e2d48;
        transition: none;
    }

    .ma-sidebar__header {
        display: none !important;
    }

    .ma-container {
        margin-left: 0;
    }

    .ma-btn-icon#ma-menu-btn {
        display: none;
    }

    #ma-overlay {
        display: none !important;
    }

    .ma-stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .ai-sidebar {
        position: fixed;
        left: -400px;
        max-width: 400px;
    }

    .ai-sidebar.open {
        left: 0;
    }
}

/* Mobile-specific improvements */
@media (max-width: 1023px) {
    .ma-btn-icon {
        width: 32px;
        height: 32px;
    }

    .ma-btn-icon svg {
        width: 16px;
        height: 16px;
    }

    .ma-sidebar {
        width: 280px;
        max-width: 85vw;
    }

    .ma-nav a {
        font-size: 0.8rem;
        padding: 0.5rem 0.6rem;
    }

    .ma-nav a svg {
        width: 14px;
        height: 14px;
    }

    .ma-nav__section {
        font-size: 0.6rem;
        padding: 0.4rem 0.6rem 0.1rem;
    }

    .ai-sidebar {
        width: 100%;
        max-width: 100%;
    }

    .ai-message {
        max-width: 95%;
        font-size: 0.85rem;
    }

    .ai-message table {
        font-size: 0.75rem;
    }

    .ai-message table th,
    .ai-message table td {
        padding: 6px;
    }

    .ma-stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .ma-stat-card {
        padding: 0.75rem;
    }

    .ma-stat-card__value {
        font-size: 1.1rem;
    }

    .ma-card {
        padding: 1rem;
    }

    .ma-table th,
    .ma-table td {
        padding: 0.5rem;
        font-size: 0.8rem;
    }

    .ma-btn {
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
    }

    /* General content improvements */
    .stat-card {
        padding: 0.75rem;
    }

    .stat-icon {
        width: 36px;
        height: 36px;
        font-size: 1.2rem;
    }

    .stat-value {
        font-size: 1.25rem;
    }

    .stat-label {
        font-size: 0.7rem;
    }

    /* Tables - make scrollable horizontally */
    table {
        font-size: 0.8rem;
    }

    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Forms */
    .form-control,
    .form-select {
        font-size: 0.9rem;
        padding: 0.5rem 0.75rem;
    }

    .form-label {
        font-size: 0.85rem;
        margin-bottom: 0.25rem;
    }

    .btn {
        font-size: 0.85rem;
        padding: 0.4rem 0.8rem;
    }

    /* Cards */
    .card {
        margin-bottom: 0.75rem;
    }

    .card-body {
        padding: 0.75rem;
    }

    .card-header {
        padding: 0.6rem 0.75rem;
        font-size: 0.9rem;
    }

    /* Grid layouts */
    .row {
        margin-left: -0.25rem;
        margin-right: -0.25rem;
    }

    .col,
    .col-1,
    .col-2,
    .col-3,
    .col-4,
    .col-5,
    .col-6,
    .col-7,
    .col-8,
    .col-9,
    .col-10,
    .col-11,
    .col-12 {
        padding-left: 0.25rem;
        padding-right: 0.25rem;
    }

    /* Pagination */
    .pagination {
        font-size: 0.85rem;
    }

    .page-link {
        padding: 0.3rem 0.6rem;
    }

    /* Badges */
    .badge {
        font-size: 0.7rem;
        padding: 0.25rem 0.4rem;
    }

    /* Alerts */
    .alert {
        font-size: 0.85rem;
        padding: 0.6rem 0.75rem;
    }

    /* Modal */
    .modal-content {
        margin: 0.5rem;
    }

    .modal-body {
        padding: 0.75rem;
    }

    .modal-header,
    .modal-footer {
        padding: 0.6rem 0.75rem;
    }

    /* Dropdowns */
    .dropdown-menu {
        font-size: 0.85rem;
        min-width: 150px;
    }

    .dropdown-item {
        padding: 0.4rem 0.75rem;
    }

    /* Tabs */
    .nav-tabs .nav-link {
        font-size: 0.85rem;
        padding: 0.4rem 0.6rem;
    }

    /* Progress bars */
    .progress {
        height: 0.5rem;
    }

    /* Input groups */
    .input-group-text {
        font-size: 0.85rem;
        padding: 0.4rem 0.6rem;
    }

    /* Checkboxes and radios */
    .form-check-input {
        width: 1rem;
        height: 1rem;
    }

    .form-check-label {
        font-size: 0.85rem;
    }

    /* Spacing utilities */
    .mt-3 { margin-top: 0.75rem !important; }
    .mb-3 { margin-bottom: 0.75rem !important; }
    .my-3 { margin-top: 0.75rem !important; margin-bottom: 0.75rem !important; }
    .p-3 { padding: 0.75rem !important; }
    .gap-3 { gap: 0.75rem !important; }

    /* Orders page specific */
    .or-stats {
        gap: 0.5rem;
        padding-bottom: 0.5rem;
    }

    .or-stat {
        padding: 0.6rem 0.7rem;
        flex: 1 0 100px;
    }

    .or-stat__val {
        font-size: 1.1rem;
    }

    .or-stat__lbl {
        font-size: 0.65rem;
    }

    .or-filters {
        grid-template-columns: 1fr !important;
        gap: 0.5rem;
    }

    .or-filter-extra {
        display: block !important;
    }

    .or-field label {
        font-size: 0.7rem;
    }

    .or-filter-actions {
        margin-top: 0.5rem;
    }

    .or-card {
        padding: 0.6rem;
        gap: 0.5rem;
    }

    .or-card__top {
        font-size: 0.85rem;
    }

    .or-card__invoice {
        font-size: 0.85rem;
    }

    .or-card__grid {
        grid-template-columns: 1fr;
        gap: 0.4rem;
        font-size: 0.75rem;
    }

    .or-card__foot {
        font-size: 0.75rem;
    }

    .or-details-grid {
        grid-template-columns: 1fr !important;
        gap: 0.5rem;
    }

    .or-details-item {
        font-size: 0.8rem;
    }

    .or-provider-response__label {
        font-size: 0.7rem;
    }

    .or-provider-response__msg {
        font-size: 0.75rem;
    }

    .or-provider-response__json {
        font-size: 0.65rem;
        padding: 0.5rem;
        max-height: 150px;
    }

    .or-table-meta {
        font-size: 0.7rem;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.3rem;
    }

    .or-mobile-list {
        gap: 0.5rem;
    }

    /* Mobile table improvements */
    .ma-table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .ma-table {
        min-width: 600px;
    }
}
