/* ============================================
   Sellora - Wholesale Sales Management System
   Modern RTL Arabic-friendly Stylesheet
   ============================================ */

/* CSS Variables */
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --secondary: #64748b;
    --success: #10b981;
    --success-light: #d1fae5;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --info: #06b6d4;
    --info-light: #cffafe;
    --dark: #1e293b;
    --dark-light: #334155;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    --white: #ffffff;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius-sm: 0.375rem;
    --radius: 0.5rem;
    --radius-md: 0.75rem;
    --radius-lg: 1rem;
    --transition: all 0.2s ease;
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Segoe UI', 'Cairo', 'Tajawal', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.6;
    direction: rtl;
    text-align: right;
    overflow-x: hidden;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: var(--transition);
}

a:hover {
    color: var(--primary-dark);
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    color: var(--gray-900);
    line-height: 1.3;
}

h1 { font-size: 1.875rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.125rem; }

/* Layout */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

.page-wrapper {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--dark);
    color: var(--white);
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    overflow: hidden;
    z-index: 1000;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
}

.sidebar-auth-pending .sidebar-menu,
.sidebar-auth-pending .sidebar-footer {
    visibility: hidden;
}

.sidebar-brand {
    padding: 1.5rem;
    border-bottom: 1px solid var(--dark-light);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar-brand-icon {
    width: 40px;
    height: 40px;
    background: var(--primary);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: bold;
}

.sidebar-brand-text {
    font-size: 1.25rem;
    font-weight: 700;
}

.sidebar-brand img {
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    object-fit: contain;
}

.sidebar-menu {
    list-style: none;
    padding: 1rem 0;
    margin: 0;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    scrollbar-gutter: stable;
}

.sidebar-menu-item {
    margin: 0.25rem 1rem;
}

.sidebar-menu-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: var(--gray-300);
    border-radius: var(--radius);
    transition: var(--transition);
    font-size: 0.95rem;
}

.sidebar-menu-link:hover,
.sidebar-menu-link.active {
    background: var(--primary);
    color: var(--white);
}

.sidebar-menu-icon {
    font-size: 1.1rem;
    width: 24px;
    text-align: center;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--dark-light);
    margin-top: auto;
    position: static;
    flex: 0 0 auto;
    background: var(--dark);
}

.sidebar-footer .company-switcher {
    padding: 0 0 0.75rem;
    border-top: 0;
}

.sidebar-logout {
    color: #fca5a5;
}

.sidebar-logout:hover {
    color: var(--white);
}

/* Main Content */
.main-content {
    flex: 1;
    min-width: 0;
    margin-right: 260px;
    min-height: 100vh;
}

.system-copyright {
    padding: 1.25rem 2rem 1.75rem;
    text-align: center;
    color: var(--gray-500);
    font-size: 0.82rem;
}

.system-copyright a,
.login-footer a {
    color: var(--primary);
}

/* Header */
.header {
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    padding: 1rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-title {
    font-size: 1.25rem;
    font-weight: 600;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--gray-800);
}

.mobile-menu-toggle {
    display: none;
}

.header-user:hover {
    color: var(--primary);
}

.header-avatar {
    width: 36px;
    height: 36px;
    background: var(--primary);
    color: var(--white);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
}

.header-user-name {
    font-weight: 500;
    font-size: 0.9rem;
}

.header-user-role {
    font-size: 0.75rem;
    color: var(--gray-500);
}

.btn-logout {
    background: var(--danger-light);
    color: var(--danger);
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.875rem;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-logout:hover {
    background: var(--danger);
    color: var(--white);
}

/* Page Content */
.page-content {
    padding: 2rem;
}

/* Cards */
.card {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    border: 1px solid var(--gray-200);
    overflow: hidden;
    transition: var(--transition);
    min-width: 0;
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
}

.card-title {
    font-size: 1.125rem;
    font-weight: 600;
}

.card-body {
    padding: 1.5rem;
}

.card-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--gray-200);
    background: var(--gray-50);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    gap: 1.25rem;
    transition: var(--transition);
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.stat-card.is-clickable {
    cursor: pointer;
}

.stat-card.is-clickable:focus-visible {
    outline: 3px solid var(--primary-light);
    outline-offset: 3px;
}

.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.stat-icon.primary { background: var(--primary-light); color: var(--primary); }
.stat-icon.success { background: var(--success-light); color: var(--success); }
.stat-icon.warning { background: var(--warning-light); color: var(--warning); }
.stat-icon.danger { background: var(--danger-light); color: var(--danger); }
.stat-icon.info { background: var(--info-light); color: var(--info); }

.stat-info {
    flex: 1;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--gray-500);
    margin-bottom: 0.25rem;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--gray-900);
    line-height: 1.2;
}

.stat-change {
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

.stat-change.positive { color: var(--success); }
.stat-change.negative { color: var(--danger); }

/* Tables */
.table-container {
    overflow-x: auto;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    border: 1px solid var(--gray-200);
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--white);
}

thead {
    background: var(--gray-50);
    border-bottom: 2px solid var(--gray-200);
}

th {
    padding: 0.875rem 1.25rem;
    text-align: right;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--gray-600);
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

td {
    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid var(--gray-200);
    font-size: 0.9rem;
    vertical-align: middle;
}

tr:hover td {
    background: var(--gray-50);
}

tr:last-child td {
    border-bottom: none;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.8rem;
    font-weight: 500;
}

.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-info { background: var(--info-light); color: var(--info); }
.badge-secondary { background: var(--gray-200); color: var(--gray-600); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: var(--primary);
    color: var(--white);
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-success {
    background: var(--success);
    color: var(--white);
}

.btn-danger {
    background: var(--danger);
    color: var(--white);
}

.btn-warning {
    background: var(--warning);
    color: var(--white);
}

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
}

.btn-secondary:hover {
    background: var(--gray-300);
}

.btn-sm {
    padding: 0.375rem 0.875rem;
    font-size: 0.85rem;
}

.btn-lg {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: var(--radius);
    justify-content: center;
}

.btn-group {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}

/* Forms */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: var(--gray-700);
}

.form-label .required {
    color: var(--danger);
}

.form-control {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.9rem;
    transition: var(--transition);
    background: var(--white);
    color: var(--gray-800);
    font-family: inherit;
    min-width: 0;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-control:disabled {
    background: var(--gray-100);
    cursor: not-allowed;
}

select.form-control {
    cursor: pointer;
}

textarea.form-control {
    resize: vertical;
    min-height: 80px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.25rem;
}

.form-row > *,
.grid-2 > *,
.grid-3 > *,
.grid-4 > * {
    min-width: 0;
}

.order-item {
    display: grid;
    grid-template-columns: minmax(180px, 2fr) minmax(90px, 1fr) minmax(110px, 1fr) auto;
    gap: 1rem;
    align-items: end;
    margin-bottom: 1rem;
    padding: 1rem;
    background: var(--gray-50);
    border-radius: var(--radius);
}

.order-calculation {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 1px;
    margin: .5rem 0 1rem;
    overflow: hidden;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    background: var(--gray-200);
}

.order-calculation > div {
    display: flex;
    flex-direction: column;
    gap: .25rem;
    padding: .85rem;
    background: white;
}

.order-calculation span {
    color: var(--gray-500);
    font-size: .8rem;
}

.order-calculation strong {
    color: var(--gray-900);
    font-size: .95rem;
}

.order-calculation .order-calculation-total {
    background: var(--primary-light);
}

.payment-summary {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .75rem;
    margin-bottom: 1rem;
    padding: .9rem;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    background: var(--gray-50);
}

.payment-summary div {
    display: flex;
    flex-direction: column;
    gap: .25rem;
}

.payment-summary span { color: var(--gray-500); font-size: .8rem; }
.payment-summary strong { color: var(--gray-900); }

.finance-money-link { padding: 0; border: 0; border-bottom: 1px dashed var(--primary); background: transparent; color: var(--primary); cursor: pointer; font: inherit; }
.finance-money-link:hover { color: var(--primary-dark); }
.finance-review-modal, .payments-review-modal { max-width: 720px; }
.payment-history-summary { display: flex; justify-content: space-between; gap: 1rem; padding: 1rem; margin-bottom: 1rem; border-radius: var(--radius); background: var(--gray-50); }
.payment-history-list { display: grid; gap: 0.5rem; }
.payment-detail-row { display: grid; grid-template-columns: 1.1fr 1fr 1fr 1fr; gap: 0.75rem; align-items: center; padding: 0.875rem; border: 1px solid var(--gray-200); border-radius: var(--radius); }
.payment-detail-row strong { color: var(--success); }
.finance-filter-card { margin-bottom: 1.5rem; }
.finance-filter-action .btn { width: 100%; }
.finance-stats { margin-bottom: 1.5rem; }

@media (max-width: 600px) {
    .payment-history-summary { align-items: flex-start; flex-direction: column; }
    .payment-detail-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
    .order-calculation { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.order-item > * {
    min-width: 0;
}

.form-hint {
    font-size: 0.8rem;
    color: var(--gray-500);
    margin-top: 0.25rem;
}

.form-alert {
    margin-bottom: 1rem;
}

.form-alert .alert {
    margin-bottom: 0;
    align-items: flex-start;
}

/* User account */
.account-layout {
    max-width: 980px;
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 1.5rem;
    align-items: start;
}

#company-settings-card {
    grid-column: 2;
}

.account-summary {
    padding: 2rem 1.5rem;
    text-align: center;
}

.account-avatar {
    width: 84px;
    height: 84px;
    margin: 0 auto 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--primary);
    color: var(--white);
    font-size: 2rem;
    font-weight: 700;
}

.account-summary h2 {
    margin-bottom: 0.25rem;
    font-size: 1.2rem;
}

.account-summary p {
    margin-bottom: 0.25rem;
    color: var(--gray-500);
}

.account-email {
    display: block;
    margin-bottom: 1rem;
    color: var(--gray-600);
    font-size: 0.9rem;
    overflow-wrap: anywhere;
}

.account-email:not([href]) {
    color: var(--gray-400);
    cursor: default;
}

@media (max-width: 800px) {
    .account-layout {
        grid-template-columns: 1fr;
    }

    #company-settings-card {
        grid-column: auto;
    }
}

/* Modals */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 2rem;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    transform: scale(0.95);
    transition: var(--transition);
}

.modal-overlay.active .modal {
    transform: scale(1);
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title {
    font-size: 1.125rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--gray-500);
    line-height: 1;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    transition: var(--transition);
}

.modal-close:hover {
    background: var(--gray-100);
    color: var(--gray-700);
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--gray-200);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* Alerts */
.alert {
    padding: 0.875rem 1.25rem;
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.9rem;
}

.alert-success {
    background: var(--success-light);
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.alert-danger {
    background: var(--danger-light);
    color: #991b1b;
    border: 1px solid #fecaca;
}

.alert-warning {
    background: var(--warning-light);
    color: #92400e;
    border: 1px solid #fde68a;
}

.alert-info {
    background: var(--info-light);
    color: #155e75;
    border: 1px solid #a5f3fc;
}

.alert-close {
    margin-right: auto;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    color: inherit;
    opacity: 0.7;
}

.alert-close:hover {
    opacity: 1;
}

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1.5rem;
}

.pagination-btn {
    min-width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--gray-300);
    background: var(--white);
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.875rem;
    padding: 0 0.75rem;
}

.pagination-btn:hover {
    background: var(--gray-100);
}

.pagination-btn.active {
    background: var(--primary);
    color: var(--white);
    border-color: var(--primary);
}

.pagination-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Login Page */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--dark) 100%);
    padding: 1rem;
}

.login-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 420px;
    padding: 2.5rem;
}

.login-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.login-logo-icon {
    width: 64px;
    height: 64px;
    background: var(--primary);
    color: var(--white);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: bold;
    margin: 0 auto 1rem;
}

.login-logo img {
    width: 80px;
    height: 80px;
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
    display: block;
    margin-left: auto;
    margin-right: auto;
}

.login-brand-image {
    width: min(280px, 100%) !important;
    height: auto !important;
    max-height: 220px;
    object-fit: contain;
}

.login-logo-text {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--gray-900);
}

.login-logo-subtitle {
    color: var(--gray-500);
    font-size: 0.9rem;
    margin-top: 0.25rem;
}

.login-form .form-group {
    margin-bottom: 1.25rem;
}

.login-form .form-control {
    padding: 0.75rem 1rem;
    font-size: 1rem;
}

.login-form .btn {
    width: 100%;
    padding: 0.875rem;
    font-size: 1rem;
    margin-top: 0.5rem;
}

.login-footer {
    text-align: center;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--gray-200);
    font-size: 0.875rem;
    color: var(--gray-500);
}

.login-error {
    background: var(--danger-light);
    color: #991b1b;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1.25rem;
    font-size: 0.9rem;
}

/* Loading Spinner */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--gray-500);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 0.5rem;
}

/* Grid Layouts */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
}

.grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
}

@media (max-width: 1024px) {
    .grid-3, .grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .grid-2, .grid-3, .grid-4 {
        grid-template-columns: 1fr;
    }

    .sidebar {
        transform: translateX(100%);
        box-shadow: var(--shadow-lg);
        width: min(280px, 86vw);
        transition: transform 0.25s ease;
        display: flex;
        flex-direction: column;
        overscroll-behavior: contain;
    }

    .sidebar-brand {
        padding: 1.125rem 1rem;
    }

    .sidebar-menu-item {
        margin-inline: 0.75rem;
    }

    .sidebar-menu-link {
        min-height: 46px;
    }

    .sidebar-menu {
        flex: 1;
        overflow-y: auto;
    }

    .sidebar-footer {
        position: static;
        margin-top: auto;
        flex: 0 0 auto;
    }

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

    .sidebar-overlay {
        position: fixed;
        inset: 0;
        z-index: 900;
        background: rgb(15 23 42 / 0.48);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.25s ease, visibility 0.25s ease;
    }

    .sidebar-overlay.active {
        opacity: 1;
        visibility: visible;
    }

    body.menu-open {
        overflow: hidden;
    }

    .mobile-menu-toggle {
        width: 40px;
        height: 40px;
        padding: 8px;
        display: inline-flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        flex: 0 0 auto;
        border: 1px solid var(--gray-200);
        border-radius: var(--radius);
        background: var(--white);
        cursor: pointer;
    }

    .mobile-menu-toggle span {
        width: 19px;
        height: 2px;
        border-radius: 2px;
        background: var(--gray-700);
    }

    .main-content {
        margin-right: 0;
    }

    .header {
        padding: 1rem;
        gap: 0.75rem;
        min-height: 64px;
    }

    .header-title {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 1.05rem;
        flex: 1;
    }

    .header-actions {
        min-width: 0;
        gap: 0.5rem;
        flex: 0 0 auto;
    }

    .header-user > div:last-child {
        display: none;
    }

    .header-avatar {
        width: 34px;
        height: 34px;
    }

    .btn-logout {
        padding: 0.5rem;
        width: 40px;
        height: 40px;
        justify-content: center;
    }

    .btn-logout span:last-child {
        display: none;
    }

    .page-content {
        padding: 1rem;
        width: 100%;
    }

    .system-copyright {
        padding: 1rem;
    }

    .stats-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .stat-card {
        padding: 1.125rem;
    }

    .stat-value {
        font-size: 1.5rem;
        overflow-wrap: anywhere;
    }

    .card-header {
        align-items: flex-start;
        flex-direction: column;
        gap: 0.75rem;
    }

    .card-header .btn,
    .card-header .btn-group {
        width: 100%;
    }

    .card-header .btn-group {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
    }

    .card-header .search-box,
    .card-header .form-control {
        width: 100%;
    }

    .card-header .btn {
        justify-content: center;
    }

    .table-container {
        margin-inline: -0.25rem;
        border-radius: 0;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-inline: contain;
        box-shadow: none;
    }

    table {
        width: max-content;
        min-width: 100%;
    }

    th,
    td {
        padding: 0.75rem 0.875rem;
        white-space: nowrap;
    }

    .inline-actions {
        min-width: max-content;
    }

    .modal-overlay {
        align-items: flex-start;
        padding: 0;
        overflow-y: auto;
    }

    .modal {
        margin: 0;
        min-height: 100dvh;
        max-width: none !important;
        max-height: none;
        border-radius: 0;
        display: flex;
        flex-direction: column;
    }

    .modal-header {
        position: sticky;
        top: 0;
        z-index: 2;
        padding: 1rem;
        background: var(--white);
    }

    .modal-body {
        padding: 1rem;
        flex: 1;
    }

    .modal-footer {
        padding: 1rem;
        flex-wrap: wrap;
        position: sticky;
        bottom: 0;
        z-index: 2;
        background: var(--white);
    }

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

    .order-item {
        grid-template-columns: minmax(0, 1fr) minmax(90px, 0.45fr);
        gap: 0.75rem;
    }

    .order-item > :first-child {
        grid-column: 1 / -1;
    }

    .order-item > .btn {
        width: 44px;
        height: 42px;
        padding: 0;
    }
}

@media (max-width: 480px) {
    .page-content {
        padding: 0.75rem;
    }

    .header {
        min-height: 64px;
        padding: 0.75rem;
        gap: 0.5rem;
    }

    .header-title {
        font-size: 0.95rem;
    }

    .header-actions .header-user {
        display: none;
    }

    .card-body,
    .card-header {
        padding: 1rem;
    }

    .card {
        border-radius: var(--radius);
    }

    .card-header {
        gap: 0.625rem;
    }

    .card-title {
        font-size: 1rem;
    }

    .stats-grid {
        margin-bottom: 1rem;
    }

    .stat-card {
        gap: 0.875rem;
    }

    .stat-icon {
        width: 46px;
        height: 46px;
        font-size: 1.25rem;
    }

    .login-card {
        padding: 1.5rem 1rem;
    }

    .login-page {
        align-items: flex-start;
        padding-top: 1.5rem;
    }

    .form-row {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .form-control {
        min-height: 44px;
        font-size: 16px;
    }

    textarea.form-control {
        min-height: 88px;
    }

    .btn-group:not(.card-header .btn-group) {
        display: grid;
        grid-template-columns: 1fr;
        width: 100%;
    }

    .btn-group:not(.card-header .btn-group) .btn {
        width: 100%;
    }

    .order-item {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        padding: 0.875rem;
    }

    .order-item > .btn {
        grid-column: 1 / -1;
        width: 100%;
    }

    .alert {
        padding: 0.75rem;
        align-items: flex-start;
    }

    .btn-lg,
    .login-form .btn {
        width: 100%;
    }
}

/* Utility Classes */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-left { text-align: left; }

.text-primary { color: var(--primary); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }
.text-muted { color: var(--gray-500); }

.font-bold { font-weight: 700; }
.font-medium { font-weight: 500; }

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mb-4 { margin-bottom: 2rem; }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }

.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.flex-1 { flex: 1; }

.hidden { display: none !important; }
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--gray-100);
}

::-webkit-scrollbar-thumb {
    background: var(--gray-400);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--gray-500);
}

/* Chart Container */
.chart-container {
    position: relative;
    height: 300px;
    width: 100%;
}

/* Search Input */
.search-box {
    position: relative;
}

.search-box .form-control {
    padding-left: 2.5rem;
    padding-right: 1rem;
}

.search-box-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-400);
    pointer-events: none;
}

/* Inline Actions */
.inline-actions {
    display: flex;
    gap: 0.25rem;
}

/* Tooltip */
.tooltip {
    position: relative;
    display: inline-block;
}

.tooltip-text {
    visibility: hidden;
    background: var(--gray-900);
    color: var(--white);
    text-align: center;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    white-space: nowrap;
    position: absolute;
    z-index: 1;
    bottom: 125%;
    right: 50%;
    transform: translateX(50%);
    opacity: 0;
    transition: opacity 0.3s;
}

.tooltip:hover .tooltip-text {
    visibility: visible;
    opacity: 1;
}

/* Select2 Alternative */
.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: left 0.75rem center;
    background-repeat: no-repeat;
    background-size: 1.5em 1.5em;
    padding-left: 2.5rem;
}

/* Order Summary */
.order-summary {
    background: var(--gray-50);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    margin-top: 1rem;
}

.order-summary-row {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--gray-200);
    font-size: 0.9rem;
}

.order-summary-row:last-child {
    border-bottom: none;
    font-weight: 600;
    font-size: 1.1rem;
    padding-top: 0.75rem;
    color: var(--primary);
}

/* Print Styles */
@media print {
    .sidebar, .header, .btn, .no-print {
        display: none !important;
    }

    .main-content {
        margin-right: 0;
    }

    body {
        background: white;
    }

    .card {
        box-shadow: none;
        border: 1px solid #ddd;
        break-inside: avoid;
    }
}

/* Dashboard Analytics */
.dashboard-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

@media (max-width: 1024px) {
    .dashboard-row {
        grid-template-columns: 1fr;
    }
}

.chart-container {
    position: relative;
    height: 280px;
    padding: 0.5rem;
}

.progress-cell {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 120px;
}

.progress-bar {
    flex: 1;
    height: 8px;
    background: var(--gray-200);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s ease;
}

.progress-fill.success { background: var(--success); }
.progress-fill.warning { background: var(--warning); }
.progress-fill.danger { background: var(--danger); }

.progress-text {
    font-size: 0.8rem;
    font-weight: 600;
    min-width: 35px;
    text-align: left;
}

.progress-text.success { color: var(--success); }
.progress-text.warning { color: var(--warning); }
.progress-text.danger { color: var(--danger); }

.table-sm th,
.table-sm td {
    padding: 0.6rem 0.75rem;
    font-size: 0.875rem;
}

.stat-icon.purple {
    background: #ede9fe;
    color: #7c3aed;
}

/* Notifications bell + dropdown */
.notification-bell-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
}
.notification-bell {
    position: relative;
    background: transparent;
    border: none;
    font-size: 1.35rem;
    cursor: pointer;
    padding: 0.35rem;
    border-radius: 0.5rem;
    line-height: 1;
}
.notification-bell:hover { background: rgba(0,0,0,0.05); }
.notification-badge {
    position: absolute;
    top: -2px;
    left: -2px;
    background: var(--danger, #ef4444);
    color: #fff;
    border-radius: 999px;
    min-width: 18px;
    height: 18px;
    font-size: 0.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}
.notification-dropdown {
    position: absolute;
    top: 110%;
    left: 0;
    width: 320px;
    max-width: 90vw;
    background: #fff;
    border: 1px solid var(--gray-200, #e5e7eb);
    border-radius: 0.75rem;
    box-shadow: 0 12px 30px rgba(0,0,0,0.15);
    z-index: 1200;
    display: none;
    overflow: hidden;
}
.notification-dropdown.open { display: block; }
.notification-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--gray-200, #e5e7eb);
    font-weight: 600;
}
.notification-list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 340px;
    overflow-y: auto;
}
.notification-item {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--gray-100, #f1f5f9);
    cursor: pointer;
}
.notification-item.unread { background: #eff6ff; }
.notification-title { font-weight: 600; font-size: 0.9rem; }
.notification-message { font-size: 0.85rem; color: var(--gray-600, #475569); margin-top: 2px; }
.notification-time { font-size: 0.75rem; color: var(--gray-400, #94a3b8); margin-top: 4px; }
.notification-empty { padding: 1.5rem; text-align: center; color: var(--gray-400, #94a3b8); }

/* Company switcher (super admin) */
.company-switcher {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--gray-200, #e5e7eb);
}
.company-switcher-label {
    display: block;
    font-size: 0.75rem;
    color: var(--gray-500, #64748b);
    margin-bottom: 0.35rem;
}
.company-switcher .form-input { width: 100%; }
