:root {
    --sidebar-width: 264px;
    --topbar-height: 68px;

    --primary: #7a0f6b;
    --primary-dark: #5c0b51;
    --primary-rgb: 122, 15, 107;
    --primary-soft: #f5e6f4;

    --accent-gold: #2ebbc9;
    --accent-gold-dark: #1f9da8;
    --accent-gold-soft: #dcf6f9;

    --ink: #20141f;
    --ink-soft: #352435;
    --bg-soft: #f7f5f7;
    --surface: #ffffff;
    --border-soft: #e9e5e9;
    --text-muted: #6e6671;

    --radius: 14px;
    --radius-sm: 10px;

    --shadow-xs: 0 1px 2px rgba(16, 32, 28, 0.04);
    --shadow-sm: 0 1px 3px rgba(16, 32, 28, 0.06), 0 1px 2px rgba(16, 32, 28, 0.04);
    --shadow-md: 0 8px 24px rgba(16, 32, 28, 0.09);
}

* { box-sizing: border-box; }

body {
    background: var(--bg-soft);
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--ink);
    margin: 0;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 { font-weight: 650; letter-spacing: -0.01em; color: var(--ink); }

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

.app-shell {
    display: flex;
    min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, #241623 0%, #150b14 100%);
    color: #fff;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1050;
    transform: translateX(-100%);
    transition: transform 0.25s ease, width 0.2s ease;
    overflow-y: auto;
    border-right: 1px solid rgba(255,255,255,0.04);
}

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

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 1.35rem 1.4rem;
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: -0.01em;
    border-bottom: 1px solid rgba(255,255,255,0.07);
    color: #fff;
}

.sidebar-brand i {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #4bd7e3, #0ba2b8);
    color: #05343a;
    border-radius: 9px;
    font-size: 1.05rem;
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

.sidebar-nav { padding: 1rem 0.75rem; display: flex; flex-direction: column; gap: 2px; }

.sidebar-nav .nav-link {
    color: #bf9f9a;
    padding: 0.65rem 0.85rem;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.92rem;
    font-weight: 500;
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: background 0.15s ease, color 0.15s ease;
}

.sidebar-nav .nav-link i { font-size: 1.05rem; width: 20px; text-align: center; }

.sidebar-nav .nav-link:hover { background: rgba(255,255,255,0.06); color: #fff; }

.sidebar-nav .nav-link.active {
    background: rgba(201, 150, 46, 0.14);
    color: #fff;
    border-left-color: var(--accent-gold);
}

.sidebar-section-label {
    color: #94706b;
    font-size: 0.72rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 0.9rem 0.85rem 0.15rem;
}

.sidebar-nav .nav-link.nav-link-sub {
    padding-left: 1.5rem;
}

html[dir="rtl"] .sidebar-nav .nav-link.nav-link-sub {
    padding-left: 0.85rem;
    padding-right: 1.5rem;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(10, 15, 30, 0.55);
    z-index: 1040;
    backdrop-filter: blur(1px);
}

.sidebar-overlay.show { display: block; }

/* ---------- Main area ---------- */
.main-area {
    flex: 1;
    min-width: 0;
    width: 100%;
    transition: margin-left 0.2s ease, margin-right 0.2s ease;
}

.topbar {
    height: var(--topbar-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border-soft);
    box-shadow: var(--shadow-xs);
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1.25rem;
    position: sticky;
    top: 0;
    z-index: 1020;
}

.topbar-title {
    font-size: 1.15rem;
    font-weight: 650;
    margin: 0;
    flex: 1;
    letter-spacing: -0.01em;
}

.topbar-user { display: flex; align-items: center; gap: 0.75rem; }

.user-name { font-weight: 550; color: var(--ink-soft); }

.btn-icon {
    border: none;
    background: transparent;
    font-size: 1.4rem;
    line-height: 1;
    padding: 0.25rem 0.5rem;
    color: var(--ink-soft);
}

.content {
    padding: 1.5rem;
    max-width: 1400px;
    margin: 0 auto;
}

/* ---------- Cards ---------- */
.kpi-card {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border-soft);
    box-shadow: var(--shadow-sm);
    padding: 1.25rem 1.35rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    height: 100%;
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}

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

.kpi-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    flex-shrink: 0;
    box-shadow: inset 0 0 0 1px rgba(16, 32, 28, 0.05);
}

.kpi-body { min-width: 0; flex: 1; }

.kpi-value {
    font-size: clamp(0.95rem, 3.6vw, 1.55rem);
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: -0.02em;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    overflow: hidden;
    text-overflow: ellipsis;
}
.kpi-label { color: var(--text-muted); font-size: 0.84rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.card-panel {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border-soft);
    box-shadow: var(--shadow-sm);
    padding: 1.4rem;
}

.card-panel h2, .card-panel h3 { letter-spacing: -0.01em; }

/* ---------- Responsive tables -> cards on mobile ---------- */
.table-responsive-cards thead { display: table-header-group; }

.table-responsive-cards table { margin: 0; }

.table-responsive-cards thead th {
    background: #fdfafa;
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border-soft);
    padding-top: 0.85rem;
    padding-bottom: 0.85rem;
}

.table-responsive-cards tbody tr {
    transition: background 0.12s ease;
}

.table-responsive-cards tbody tr:hover {
    background: #fdf9f8;
}

.table-responsive-cards tbody td {
    border-color: var(--border-soft);
}

@media (max-width: 767.98px) {
    .table-responsive-cards table,
    .table-responsive-cards thead,
    .table-responsive-cards tbody,
    .table-responsive-cards tr,
    .table-responsive-cards td { display: block; width: 100%; }

    .table-responsive-cards thead { display: none; }

    .table-responsive-cards tr {
        background: var(--surface);
        border: 1px solid var(--border-soft);
        border-radius: var(--radius-sm);
        margin-bottom: 0.75rem;
        padding: 0.75rem 1rem;
    }

    .table-responsive-cards tr:hover { background: var(--surface); }

    .table-responsive-cards td {
        border: none;
        padding: 0.35rem 0;
        display: flex;
        justify-content: space-between;
        gap: 0.5rem 1rem;
        text-align: right;
        min-width: 0;
    }

    .table-responsive-cards td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-muted);
        text-align: left;
        white-space: nowrap;
        flex-shrink: 0;
    }

    .table-responsive-cards td .cell-value {
        display: inline-block;
        max-width: 100%;
        min-width: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        font-variant-numeric: tabular-nums;
    }

    .table-responsive-cards td:not(:has(.cell-value)) {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .table-responsive-cards td.no-label::before { content: none; }
}

/* Like .table-responsive-cards, but stacked into cards unconditionally instead of only
   below the mobile breakpoint — for tables living in a narrow sidebar column, where the
   available width stays too small for a data table even on desktop. */
.table-cards-always table,
.table-cards-always thead,
.table-cards-always tbody,
.table-cards-always tr,
.table-cards-always td { display: block; width: 100%; }

.table-cards-always thead { display: none; }

.table-cards-always tr {
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm);
    margin-bottom: 0.75rem;
    padding: 0.75rem 1rem;
}

.table-cards-always tr:hover { background: var(--surface); }

.table-cards-always td {
    border: none;
    padding: 0.35rem 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.5rem 1rem;
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.table-cards-always td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-muted);
    text-align: left;
    white-space: nowrap;
}

.table-cards-always td.no-label::before { content: none; }

/* ---------- Forms ---------- */
.form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

@media (min-width: 768px) {
    .form-grid.cols-2 { grid-template-columns: 1fr 1fr; }
}

.form-label { font-weight: 550; font-size: 0.88rem; color: var(--ink-soft); }

.form-control, .form-select {
    border-color: var(--border-soft);
    border-radius: var(--radius-sm);
    padding: 0.55rem 0.85rem;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.15);
}

/* Hide the native up/down spinner arrows on number inputs everywhere. */
input[type="number"] {
    -moz-appearance: textfield;
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.btn-touch {
    min-height: 44px;
    min-width: 44px;
}

.btn {
    font-weight: 550;
    border-radius: var(--radius-sm);
}

.btn-primary {
    --bs-btn-bg: var(--primary);
    --bs-btn-border-color: var(--primary);
    --bs-btn-hover-bg: var(--primary-dark);
    --bs-btn-hover-border-color: var(--primary-dark);
    --bs-btn-active-bg: var(--primary-dark);
    --bs-btn-active-border-color: var(--primary-dark);
    --bs-btn-focus-shadow-rgb: var(--primary-rgb);
    box-shadow: var(--shadow-xs);
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.btn-primary:hover {
    box-shadow: var(--shadow-sm);
}

.btn-outline-secondary {
    --bs-btn-color: var(--ink-soft);
    --bs-btn-border-color: var(--border-soft);
    --bs-btn-hover-bg: #f9f2f1;
    --bs-btn-hover-color: var(--ink);
    --bs-btn-hover-border-color: var(--border-soft);
}

/* ---------- Desktop layout ---------- */
@media (min-width: 992px) {
    .sidebar { transform: translateX(0); position: fixed; }
    .main-area { margin-left: var(--sidebar-width); }
    .sidebar-overlay { display: none !important; }
}

/* ---------- Sidebar collapse (icons-only) toggle, desktop only ---------- */
.sidebar-collapse-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    padding: 0;
    margin-left: auto;
    flex-shrink: 0;
    background: rgba(255,255,255,0.08);
    color: #e6cecb;
    border: 0;
    border-radius: 6px;
    font-size: 0.6rem;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.sidebar-collapse-toggle:hover { background: rgba(255,255,255,0.18); color: #fff; }

/* .sidebar-brand i is styled as the big 34px gold logo box — override all of that here
   since this button's icon sits inside .sidebar-brand too. */
.sidebar-collapse-toggle i {
    width: auto;
    height: auto;
    background: none;
    box-shadow: none;
    border-radius: 0;
    font-size: 0.6rem;
    color: inherit;
}

@media (min-width: 992px) {
    .sidebar-collapse-toggle { display: inline-flex; }

    html.sidebar-collapsed {
        --sidebar-width: 76px;
    }

    html.sidebar-collapsed .sidebar-brand { justify-content: center; padding-left: 0.5rem; padding-right: 0.5rem; }
    html.sidebar-collapsed .sidebar-brand span { display: none; }
    html.sidebar-collapsed .sidebar-collapse-toggle { margin-left: 0; }

    html.sidebar-collapsed .sidebar-section-label { display: none; }

    html.sidebar-collapsed .sidebar-nav .nav-link { justify-content: center; padding-left: 0.6rem; padding-right: 0.6rem; }
    html.sidebar-collapsed .sidebar-nav .nav-link.nav-link-sub { padding-left: 0.6rem; }
    html.sidebar-collapsed .sidebar-nav .nav-link span { display: none; }
    html.sidebar-collapsed .sidebar-nav .nav-link i { width: auto; }
}

html[dir="rtl"].sidebar-collapsed .sidebar-nav .nav-link.nav-link-sub { padding-right: 0.6rem; }

.badge {
    font-weight: 600;
    font-size: 0.76rem;
    padding: 0.4em 0.7em;
    border-radius: 999px;
}

.badge-soft-danger { background: #fde8e8; color: #c0362c; }
.badge-soft-warning { background: #fef3e0; color: #b0650f; }
.badge-soft-success { background: #e3f8ea; color: #1a7f4e; }
.badge-soft-primary { background: var(--primary-soft); color: var(--primary-dark); }
.badge-soft-info { background: #e3edfd; color: #1d5aa8; }

.stock-progress {
    height: 8px;
    width: 100%;
    flex: 1 1 100%;
    border-radius: 999px;
    background: var(--bg-soft);
    overflow: hidden;
    margin-top: 0.35rem;
}
.stock-progress-bar {
    height: 100%;
    border-radius: 999px;
    transition: width 0.2s ease;
}
.stock-progress-bar.is-success { background: #1a7f4e; }
.stock-progress-bar.is-danger { background: #d64545; }
.stock-progress-bar.is-primary { background: var(--primary-dark); }
.stock-progress-bar.is-warning { background: #d99a2b; }

.stat-list .stat-row {
    display: flex;
    justify-content: space-between;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--border-soft);
}

.stat-list .stat-row:last-child { border-bottom: none; }

/* ---------- Product images ---------- */
.product-thumb {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 8px;
    flex-shrink: 0;
    border: 1px solid var(--border-soft);
}

.product-thumb-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-soft);
    color: #c5adaa;
    font-size: 1.1rem;
    border: 1px solid var(--border-soft);
}

.product-image-large {
    width: 100%;
    max-width: 260px;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: var(--radius);
    display: block;
    margin-bottom: 1rem;
    border: 1px solid var(--border-soft);
}

.product-image-placeholder-large {
    width: 100%;
    max-width: 260px;
    aspect-ratio: 1 / 1;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-soft);
    color: #c5adaa;
    font-size: 2.5rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border-soft);
}

/* ---------- Searchable selects (Choices.js) ---------- */
.choices {
    font-size: 1rem;
    margin-bottom: 0;
}

.choices__inner {
    background: var(--surface);
    border: 1px solid var(--border-soft) !important;
    border-radius: var(--radius-sm) !important;
    padding: 0.45rem 0.85rem;
    min-height: calc(1.5em + 1.1rem + 2px);
    font-family: inherit;
}

.choices.is-focused .choices__inner,
.choices.is-open .choices__inner {
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.15);
}

.choices__list--dropdown, .choices__list[aria-expanded] {
    border-color: var(--border-soft) !important;
    border-radius: var(--radius-sm) !important;
    box-shadow: var(--shadow-md);
    overflow: hidden;
    font-family: inherit;
}

.choices__list--dropdown .choices__input {
    border-bottom-color: var(--border-soft) !important;
}

.choices__list--dropdown .choices__item--selectable.is-highlighted,
.choices__list[aria-expanded] .choices__item--selectable.is-highlighted {
    background: var(--primary-soft) !important;
    color: var(--primary-dark);
}

.choices[data-type*="select-one"] .choices__inner {
    padding-bottom: 0.45rem;
}

.choices[data-type*="select-one"]::after {
    border-color: var(--text-muted) transparent transparent;
}

.choices[data-type*="select-one"].is-open::after {
    border-color: transparent transparent var(--text-muted);
}

.choices__list--single .choices__placeholder,
.choices__input {
    color: var(--text-muted);
    opacity: 1;
}

/* ---------- RTL (Arabic) support ---------- */
html[dir="rtl"] body {
    font-family: "Cairo", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

html[dir="rtl"] .sidebar {
    left: auto;
    right: 0;
    border-right: none;
    border-left: 1px solid rgba(255,255,255,0.04);
    transform: translateX(100%);
}

html[dir="rtl"] .sidebar-nav .nav-link {
    border-left: none;
    border-right: 3px solid transparent;
}

html[dir="rtl"] .sidebar-nav .nav-link.active {
    border-right-color: var(--accent-gold);
}

@media (min-width: 992px) {
    html[dir="rtl"] .main-area {
        margin-left: 0;
        margin-right: var(--sidebar-width);
    }
}

html[dir="rtl"] .choices[data-type*="select-one"]::after {
    right: auto;
    left: 11.5px;
}

html[dir="rtl"] .choices[data-type*="select-one"] .choices__button {
    right: auto;
    left: 0;
    margin-left: 25px;
    margin-right: 0;
}
