/* =========================================================================
   Ayoub Trading Company — Core Design System
   Mobile-first. Light/Dark themes via CSS variables. Full RTL/LTR support
   using logical properties (margin-inline, padding-inline, etc.) so the
   layout mirrors automatically when <html dir="rtl">.
   ========================================================================= */

:root {
    /* Brand */
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-primary-light: #eff6ff;
    --color-accent: #0ea5e9;
    --color-success: #16a34a;
    --color-success-light: #dcfce7;
    --color-warning: #d97706;
    --color-warning-light: #fef3c7;
    --color-danger: #dc2626;
    --color-danger-light: #fee2e2;

    /* Surfaces (light theme default) */
    --bg-body: #f5f7fa;
    --bg-surface: #ffffff;
    --bg-surface-alt: #f8fafc;
    --bg-sidebar: #111827;
    --border-color: #e5e7eb;
    --border-color-strong: #d1d5db;

    /* Text */
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --text-on-primary: #ffffff;
    --text-on-sidebar: #d1d5db;
    --text-on-sidebar-active: #ffffff;

    /* Shape / motion */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
    --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.08);
    --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.12);
    --transition: 150ms ease;

    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, Helvetica, Arial, sans-serif;
    --font-arabic: "Segoe UI", "Tahoma", "Cairo", sans-serif;

    --sidebar-width: 260px;
    --topbar-height: 64px;
}

[data-theme="dark"] {
    --bg-body: #0b0f19;
    --bg-surface: #131826;
    --bg-surface-alt: #1a2133;
    --bg-sidebar: #0b0f19;
    --border-color: #232b3d;
    --border-color-strong: #2e374b;

    --text-primary: #f3f4f6;
    --text-secondary: #a1a8b8;
    --text-muted: #6b7280;
    --text-on-sidebar: #9aa4bb;

    --color-primary-light: #14213d;
    --color-success-light: #0f2a1a;
    --color-warning-light: #2c2108;
    --color-danger-light: #2c1414;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.55);
}

/* ---------------------------------------------------------------- Reset --- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    background: var(--bg-body);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    transition: background var(--transition), color var(--transition);
}
html[dir="rtl"] body { font-family: var(--font-arabic); }

img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
ul { list-style: none; margin: 0; padding: 0; }
button { font-family: inherit; }
h1, h2, h3, h4, h5, h6 { margin: 0 0 .5em; font-weight: 700; letter-spacing: -0.01em; }
p { margin: 0 0 1em; color: var(--text-secondary); }

.container { width: 100%; max-width: 1280px; margin-inline: auto; padding-inline: 16px; }

/* --------------------------------------------------------------- Layout --- */
.skip-link {
    position: absolute; inset-inline-start: -999px; top: 0;
    background: var(--color-primary); color: #fff; padding: 8px 16px; z-index: 999;
}
.skip-link:focus { inset-inline-start: 8px; top: 8px; }

/* --------------------------------------------------------------- Topbar --- */
.topbar {
    position: sticky; top: 0; z-index: 40;
    display: flex; align-items: center; justify-content: space-between;
    height: var(--topbar-height);
    padding-inline: 16px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    gap: 12px;
}
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; }
.topbar .brand img { height: 32px; width: auto; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; border-radius: var(--radius-md);
    border: 1px solid var(--border-color); background: var(--bg-surface);
    color: var(--text-secondary); cursor: pointer; transition: all var(--transition);
    position: relative;
}
.icon-btn:hover { background: var(--bg-surface-alt); color: var(--text-primary); }
.icon-btn .dot {
    position: absolute; top: -3px; inset-inline-end: -3px;
    width: 9px; height: 9px; border-radius: 50%;
    background: var(--color-danger); border: 2px solid var(--bg-surface);
}

/* -------------------------------------------------------------- Buttons --- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 18px; border-radius: var(--radius-md); border: 1px solid transparent;
    font-size: 14px; font-weight: 600; cursor: pointer; transition: all var(--transition);
    white-space: nowrap; line-height: 1.2;
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-secondary { background: var(--bg-surface-alt); color: var(--text-primary); border-color: var(--border-color); }
.btn-secondary:hover { background: var(--border-color); }
.btn-success { background: var(--color-success); color: #fff; }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-outline { background: transparent; border-color: var(--border-color-strong); color: var(--text-primary); }
.btn-outline:hover { background: var(--bg-surface-alt); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 14px 24px; font-size: 16px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-icon { padding: 8px; width: 38px; height: 38px; }

/* ---------------------------------------------------------------- Cards --- */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.card-body { padding: 20px; }
.card-header {
    padding: 16px 20px; border-bottom: 1px solid var(--border-color);
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card-header h3 { margin: 0; font-size: 16px; }

.stat-card { padding: 20px; display: flex; flex-direction: column; gap: 6px; }
.stat-card .stat-label { font-size: 13px; color: var(--text-secondary); font-weight: 600; }
.stat-card .stat-value { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.stat-card .stat-delta { font-size: 12px; font-weight: 600; }
.stat-delta.up { color: var(--color-success); }
.stat-delta.down { color: var(--color-danger); }
.stat-card .stat-icon {
    width: 40px; height: 40px; border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center; font-size: 18px;
    background: var(--color-primary-light); color: var(--color-primary); margin-bottom: 4px;
}

/* --------------------------------------------------------------- Grid ----- */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(1, 1fr); }
.grid-3 { grid-template-columns: repeat(1, 1fr); }
.grid-4 { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 640px) {
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 860px) {
    .grid-2 { grid-template-columns: repeat(2, 1fr); }
    .grid-3 { grid-template-columns: repeat(3, 1fr); }
    .grid-4 { grid-template-columns: repeat(4, 1fr); }
}

/* --------------------------------------------------------------- Forms ---- */
.form-group { margin-bottom: 16px; }
.form-label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; color: var(--text-primary); }
.form-control, select.form-control, textarea.form-control {
    width: 100%; padding: 10px 12px; border-radius: var(--radius-md);
    border: 1px solid var(--border-color-strong); background: var(--bg-surface);
    color: var(--text-primary); font-size: 14px; transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus {
    outline: none; border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}
.form-row { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .form-row.cols-2 { grid-template-columns: 1fr 1fr; } .form-row.cols-3 { grid-template-columns: repeat(3, 1fr); } }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.form-error { font-size: 12px; color: var(--color-danger); margin-top: 4px; }
.input-group { display: flex; }
.input-group .form-control { border-radius: 0; }
.input-group .form-control:first-child { border-start-start-radius: var(--radius-md); border-end-start-radius: var(--radius-md); }
.input-group .form-control:last-child { border-start-end-radius: var(--radius-md); border-end-end-radius: var(--radius-md); }
.checkbox-row { display: flex; align-items: center; gap: 8px; }

/* --------------------------------------------------------------- Tables --- */
.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--border-color); }
table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 560px; }
thead th {
    text-align: start; padding: 12px 16px; background: var(--bg-surface-alt);
    color: var(--text-secondary); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
    border-bottom: 1px solid var(--border-color); white-space: nowrap;
}
tbody td { padding: 14px 16px; border-bottom: 1px solid var(--border-color); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { background: var(--bg-surface); transition: background var(--transition); }
tbody tr:hover { background: var(--bg-surface-alt); }

/* --------------------------------------------------------------- Badges --- */
.badge {
    display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px;
    border-radius: 999px; font-size: 12px; font-weight: 700;
}
.badge-success { background: var(--color-success-light); color: var(--color-success); }
.badge-warning { background: var(--color-warning-light); color: var(--color-warning); }
.badge-danger { background: var(--color-danger-light); color: var(--color-danger); }
.badge-neutral { background: var(--bg-surface-alt); color: var(--text-secondary); border: 1px solid var(--border-color); }
.badge-primary { background: var(--color-primary-light); color: var(--color-primary); }

/* ---------------------------------------------------------------- Misc ---- */
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-success { color: var(--color-success); }
.text-danger { color: var(--color-danger); }
.text-center { text-align: center; }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-1 { gap: 8px; } .gap-2 { gap: 16px; } .gap-3 { gap: 24px; }
.mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.hidden { display: none !important; }
.rounded-full { border-radius: 999px; }
.divider { height: 1px; background: var(--border-color); margin: 16px 0; }

.empty-state { padding: 60px 20px; text-align: center; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; }

.spinner {
    width: 18px; height: 18px; border-radius: 50%;
    border: 2px solid rgba(255,255,255,.35); border-top-color: #fff;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------- Toasts --- */
#toast-container {
    position: fixed; bottom: 20px; inset-inline-end: 20px; z-index: 999;
    display: flex; flex-direction: column; gap: 10px; max-width: 340px;
}
.toast {
    background: var(--bg-surface); border: 1px solid var(--border-color); box-shadow: var(--shadow-lg);
    border-radius: var(--radius-md); padding: 12px 16px; font-size: 14px;
    display: flex; align-items: center; gap: 10px;
    animation: toast-in .25s ease;
    border-inline-start: 4px solid var(--color-primary);
}
.toast.success { border-inline-start-color: var(--color-success); }
.toast.error { border-inline-start-color: var(--color-danger); }
.toast.warning { border-inline-start-color: var(--color-warning); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------------------------------------------------------------- Modal --- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(10,14,25,.55); z-index: 200;
    display: flex; align-items: flex-end; justify-content: center; padding: 0;
}
@media (min-width: 640px) { .modal-overlay { align-items: center; padding: 20px; } }
.modal {
    background: var(--bg-surface); width: 100%; max-width: 520px;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0; max-height: 90vh; overflow-y: auto;
    box-shadow: var(--shadow-lg);
}
@media (min-width: 640px) { .modal { border-radius: var(--radius-lg); } }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 20px; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--border-color); display: flex; justify-content: flex-end; gap: 8px; }

/* ------------------------------------------------------------- Pagination - */
.pagination { display: flex; gap: 6px; flex-wrap: wrap; }
.pagination a, .pagination span {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 34px; height: 34px; border-radius: var(--radius-sm); font-size: 13px;
    border: 1px solid var(--border-color); color: var(--text-secondary);
}
.pagination a:hover { background: var(--bg-surface-alt); }
.pagination .active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

/* ----------------------------------------------------------- Auth screens - */
.auth-shell {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    padding: 20px; background: linear-gradient(160deg, var(--bg-body), var(--bg-surface-alt));
}
.auth-card { width: 100%; max-width: 420px; padding: 32px 28px; }
.auth-logo { text-align: center; margin-bottom: 20px; font-size: 22px; font-weight: 800; }

/* Utility for language/theme toggle pill switches */
.toggle-group { display: inline-flex; border: 1px solid var(--border-color); border-radius: 999px; padding: 3px; background: var(--bg-surface-alt); }
.toggle-group button {
    border: none; background: transparent; padding: 6px 14px; border-radius: 999px;
    font-size: 13px; font-weight: 600; color: var(--text-secondary); cursor: pointer;
}
.toggle-group button.active { background: var(--bg-surface); color: var(--text-primary); box-shadow: var(--shadow-sm); }
