/* ===================== Reset & Base ===================== */
* { box-sizing: border-box; }
html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    font-family: Tahoma, 'Segoe UI', Arial, sans-serif;
    background: #f4f6f5;
    color: #1f2a24;
    direction: rtl;
}
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

:root {
    --primary: #1976d2;
    --primary-dark: #0d47a1;
    --danger: #c0392b;
    --border: #dfe5e2;
    --card-bg: #ffffff;
}

/* ===================== Buttons / Alerts / Forms (shared) ===================== */
.btn {
    display: inline-block;
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #fff;
    color: #1f2a24;
    font-size: 14px;
}
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: transparent; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-block { width: 100%; text-align: center; }
.btn-icon { background: transparent; border: none; font-size: 20px; padding: 4px 8px; }

.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; }
.alert-error { background: #fdecea; color: #a1281c; border: 1px solid #f3c6c1; }
.alert-success { background: #e8f6ef; color: #146c48; border: 1px solid #bfe8d4; }
.alert ul { margin: 0; padding-inline-start: 20px; }

.form-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    max-width: 640px;
    margin-bottom: 20px;
}
.form-card label {
    display: block;
    margin-bottom: 14px;
    font-size: 14px;
    color: #3c4a43;
}
.form-card input[type=text], .form-card input[type=password], .form-card input[type=number],
.form-card input[type=search], .form-card input[type=file], .form-card input[type=email], .form-card input[type=tel], .form-card select, .form-card textarea {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    background: #fff;
}
.form-card .checkbox-label { display: flex; align-items: center; gap: 8px; }
.form-card .checkbox-label input { width: auto; margin: 0; }
.form-actions { display: flex; gap: 10px; margin-top: 10px; }
.thumb-preview { max-width: 120px; border-radius: 8px; margin-bottom: 14px; border: 1px solid var(--border); }
.thumb-preview.thumb-round { border-radius: 50%; }

/* ===================== Install page ===================== */
.install-page { display: flex; justify-content: center; padding: 40px 16px; }
.install-wrap {
    background: #fff; border: 1px solid var(--border); border-radius: 14px;
    padding: 28px; max-width: 560px; width: 100%;
}
.install-wrap h1 { font-size: 20px; margin-top: 0; }
.install-wrap form label { display: block; margin-bottom: 14px; font-size: 14px; }
.install-wrap input { display: block; width: 100%; margin-top: 6px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; }
.req-list { list-style: none; padding: 0; }
.req-list li { padding: 6px 0; }
.req-list li.ok { color: #146c48; }
.req-list li.fail { color: #a1281c; }
.req-detail { color: #7a8a83; font-size: 12px; margin-inline-start: 8px; }

/* ===================== Login page ===================== */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-card {
    background: #fff; border: 1px solid var(--border); border-radius: 16px;
    padding: 32px; max-width: 380px; width: 100%; text-align: center;
}
.login-logo img { width: 72px; height: 72px; margin: 0 auto 12px; border-radius: 50%; }
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-subtitle { color: #7a8a83; margin-bottom: 20px; font-size: 14px; }
.login-card form { text-align: right; }
.login-card label { display: block; margin-bottom: 14px; font-size: 14px; }
.login-card input {
    display: block; width: 100%; margin-top: 6px; padding: 10px 12px;
    border: 1px solid var(--border); border-radius: 8px; font-size: 15px;
}

/* ===================== Catalog: top bar ===================== */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    background: #fff; border-bottom: 1px solid var(--border);
    padding: 10px 16px; position: sticky; top: 0; z-index: 20;
}
.topbar-title { display: flex; align-items: center; gap: 10px; font-weight: bold; font-size: 16px; }
.topbar-user {
    display: flex; align-items: center; gap: 10px;
    position: fixed; top: 10px; left: 16px;
    background: #fff; padding: 6px 10px; border-radius: 10px;
    border: 1px solid var(--border);
}
.user-avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }
.user-meta { font-size: 12px; text-align: right; line-height: 1.5; }
.user-name { font-weight: bold; font-size: 13px; }
.user-last-update { color: #7a8a83; }

@media (max-width: 640px) {
    .topbar-user { position: static; margin-top: 8px; flex-wrap: wrap; }
    .topbar { flex-wrap: wrap; }
}

/* ===================== Search / sort / brand filter ===================== */
.search-bar-wrap { display: flex; flex-wrap: wrap; gap: 10px; padding: 14px 16px 6px; }
.search-input {
    flex: 1; min-width: 160px; padding: 10px 14px; border: 1px solid var(--border); border-radius: 10px; font-size: 14px; background: #fff;
}
.sort-select { padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: #fff; font-size: 14px; }
.view-toggle { display: flex; gap: 4px; }
.view-toggle .btn { padding: 8px 10px; }
.view-toggle .btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.catalog-alert { margin: 8px 16px; }

.order-summary {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    margin: 8px 16px 14px; padding: 12px 14px; background: #e8f1fb;
    border: 1px solid #bfd6ef; border-radius: 10px; color: #173b64;
}
.order-summary > div { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.order-summary span { font-size: 13px; }

.image-lightbox {
    position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 100;
    display: flex; align-items: center; justify-content: center; padding: 24px;
}
.image-lightbox[hidden] { display: none; }
.image-lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 8px; object-fit: contain; }
.image-lightbox-close {
    position: absolute; top: 16px; left: 16px; width: 38px; height: 38px;
    border-radius: 50%; border: none; background: rgba(255,255,255,.9); color: #1f2a24;
    font-size: 18px;
}

.brand-filter-wrap {
    display: flex; gap: 10px; padding: 6px 16px 14px; overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.brand-btn {
    display: flex; align-items: center; gap: 6px; white-space: nowrap;
    padding: 6px 14px; border-radius: 999px; border: 1px solid var(--border);
    background: #fff; font-size: 13px;
}
.brand-btn img { height: 22px; width: auto; max-width: 64px; }
.brand-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ===================== Layout: sidebar + grid ===================== */
.catalog-layout { display: flex; gap: 16px; padding: 0 16px 24px; align-items: flex-start; }

.sidebar {
    width: 240px; flex-shrink: 0;
    background: #fff; border: 1px solid var(--border); border-radius: 12px;
    padding: 14px; position: sticky; top: 72px;
    max-height: calc(100vh - 90px); overflow-y: auto;
}
.sidebar h3 { margin: 0 0 10px; font-size: 15px; }

.cat-tree, .cat-children { list-style: none; margin: 0; padding: 0; }
.cat-children { display: block; }
.cat-node.collapsed > .cat-children { display: none; }
.cat-row { display: flex; align-items: center; gap: 4px; }
.cat-toggle { background: none; border: none; font-size: 12px; width: 18px; color: #7a8a83; }
.cat-toggle-spacer { display: inline-block; width: 18px; }
.cat-label {
    flex: 1; text-align: right; background: none; border: none; padding: 6px 4px;
    border-radius: 6px; font-size: 14px; color: #1f2a24;
}
.cat-label:hover { background: #f0f4f2; }
.cat-label.active { background: var(--primary); color: #fff; }

.product-area { flex: 1; min-width: 0; }
.empty-state { text-align: center; padding: 60px 20px; color: #7a8a83; font-size: 15px; }

.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 16px;
}

/* ===================== Product card ===================== */
.product-card {
    background: var(--card-bg); border: 1px solid var(--border); border-radius: 14px;
    overflow: hidden; position: relative; display: flex; flex-direction: column;
}
.card-image-wrap {
    position: relative; width: 100%; height: 150px; background: #fff;
    display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.card-image { width: auto; height: 100%; max-width: 100%; object-fit: contain; }
.card-brand-badge {
    position: absolute; top: 8px; right: 8px; height: 28px; width: auto; max-width: 40%;
    border-radius: 4px; padding: 3px 5px;
    background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.card-sku {
    position: absolute; bottom: 8px; right: 8px;
    background: rgba(0,0,0,.65); color: #fff; font-size: 11px;
    padding: 2px 8px; border-radius: 6px;
}
.card-body { padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card-title { font-size: 14px; margin: 0; font-weight: bold; line-height: 1.4; }
.card-desc {
    font-size: 12px; color: #6b7a73; margin: 0; line-height: 1.5;
    display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.card-desc.truncatable { cursor: pointer; }
.card-desc.expanded { -webkit-line-clamp: unset; display: block; overflow: visible; }

.card-attributes { display: flex; flex-direction: column; gap: 4px; }
.attr-line { font-size: 12px; display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.attr-line-title { color: #3c4a43; font-weight: bold; }
.attr-line-values { color: #6b7a73; }

.card-stock { font-size: 12px; color: #6b7a73; }

.card-variants { display: flex; flex-direction: column; gap: 4px; }
.variant-row {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    font-size: 12px; padding: 3px 0; border-top: 1px dashed var(--border);
}
.variant-row:first-child { border-top: none; }
.variant-label { color: #3c4a43; }
.variant-sku { color: #7a8a83; font-size: 11px; }
.variant-stock { color: #6b7a73; white-space: nowrap; }
.variant-row-extra { display: none; }
.card-variants.expanded .variant-row-extra { display: flex; }
.variant-toggle-btn {
    align-self: flex-start; background: none; border: none; padding: 4px 0 0;
    color: var(--primary); font-size: 11px; font-weight: bold; cursor: pointer;
}
.variant-toggle-btn:hover { text-decoration: underline; }

.card-units { display: flex; flex-direction: column; gap: 4px; margin-top: auto; padding-top: 6px; }
.unit-price-row {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    font-size: 13px; padding: 3px 0; border-top: 1px dashed var(--border);
}
.unit-price-row:first-child { border-top: none; }
.unit-price-label { color: #3c4a43; }
.unit-price-wrap { display: flex; flex-direction: column; align-items: flex-end; }
.unit-price-value { font-weight: bold; color: var(--primary-dark); white-space: nowrap; }
.unit-price-per-item { font-size: 10px; color: #9aa6a0; white-space: nowrap; }

.card-order-controls { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.card-order-title { font-size: 12px; font-weight: bold; color: #3c4a43; margin-bottom: 4px; }
.card-order-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 0; font-size: 11px; color: #526057; }
.card-order-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-order-row input { width: 82px; flex: 0 0 auto; padding: 5px 7px; border: 1px solid var(--border); border-radius: 6px; direction: ltr; text-align: center; }

.product-grid.list-view { display: flex; flex-direction: column; gap: 10px; }
.product-grid.list-view .product-card { min-height: 156px; display: grid; grid-template-columns: 170px minmax(0, 1fr); overflow: visible; }
.product-grid.list-view .card-image-wrap { height: 100%; min-height: 156px; border-radius: 13px 0 0 13px; }
.product-grid.list-view .card-body { justify-content: center; }
.product-grid.list-view .card-share-btn { left: 8px; }

.color-swatches { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.color-swatch {
    position: relative; width: 18px; height: 18px; border-radius: 50%;
    border: 1px solid rgba(0,0,0,.15); box-shadow: 0 0 0 1px rgba(255,255,255,.6) inset;
    flex-shrink: 0;
}
.color-tooltip {
    position: absolute; bottom: calc(100% + 6px); right: 50%; transform: translateX(50%);
    background: rgba(20,20,20,.9); color: #fff; font-size: 11px; white-space: nowrap;
    padding: 3px 8px; border-radius: 6px; opacity: 0; visibility: hidden; pointer-events: none;
    transition: opacity .15s ease; z-index: 5;
}
.color-swatch:hover .color-tooltip,
.color-swatch.tooltip-active .color-tooltip { opacity: 1; visibility: visible; }

.card-share-btn {
    position: absolute; top: 8px; left: 8px; width: 30px; height: 30px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%; border: none; background: rgba(255,255,255,.9); color: #1f2a24;
    box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.product-card.capturing .card-share-btn,
.product-card.capturing .card-stock,
.product-card.capturing .card-order-controls,
.product-card.capturing .card-sku { display: none; }

/* ===================== PDF export (off-screen, captured via html2canvas) ===================== */
.pdf-export-container {
    display: none; position: fixed; top: 0; left: -9999px;
    background: #fff; direction: rtl; width: 1150px;
}
.pdf-table { width: 1150px; border-collapse: collapse; font-family: Tahoma, Arial, sans-serif; background: #fff; }
.pdf-table th, .pdf-table td {
    height: 75px; max-height: 75px; padding: 0 10px; text-align: right;
    border-bottom: 1px solid #ddd; font-size: 13px; color: #1f2a24;
    overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.pdf-table th { background: #f4f6f5; font-weight: bold; font-size: 13px; }
.pdf-table td:first-child, .pdf-table th:first-child { width: 78px; padding: 0 8px; }
.pdf-table td img { width: 66px; height: 66px; object-fit: contain; border-radius: 4px; vertical-align: middle; }

.pdf-header-html { width: 1150px; background: #fff; direction: rtl; }

.pdf-footer-text { position: relative; width: 1150px; min-height: 34px; padding: 8px 10px 20px; background: #fff; }
.pdf-footer-vat { font-size: 12px; color: #555; text-align: center; }
.pdf-footer-date { position: absolute; left: 10px; bottom: 4px; font-size: 10px; color: #888; white-space: nowrap; }

/*
 * Breakpoints: mobile <=600px (1 card/row, off-canvas sidebar),
 * tablet 601-1023px (2 cards/row, static sidebar), desktop >=1024px (auto-fill, static sidebar).
 */

/* Tablet: 2 cards per row */
@media (max-width: 1023px) {
    .product-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Mobile: sidebar becomes off-canvas, 1 card per row */
@media (max-width: 600px) {
    .catalog-layout { flex-direction: column; }
    .sidebar {
        position: fixed; top: 0; bottom: 0; right: 0; z-index: 50;
        width: 85%; max-width: 300px; max-height: none; border-radius: 0;
        transform: translateX(100%); transition: transform .2s ease;
        box-shadow: -4px 0 12px rgba(0,0,0,.15);
    }
    .sidebar.open { transform: translateX(0); }
    .product-grid { grid-template-columns: 1fr; gap: 10px; }
    .product-card { width: 100%; }
    .catalog-layout { padding: 0 10px 20px; }
    .search-bar-wrap, .brand-filter-wrap { padding-left: 10px; padding-right: 10px; }
    .order-summary { margin-left: 10px; margin-right: 10px; align-items: stretch; flex-direction: column; }
    .order-summary .btn { width: 100%; }
    .product-grid.list-view .product-card { grid-template-columns: 110px minmax(0, 1fr); min-height: 130px; }
    .product-grid.list-view .card-image-wrap { min-height: 130px; }
}

.order-modal[hidden] { display: none; }
.order-modal { position: fixed; inset: 0; z-index: 120; display: flex; align-items: center; justify-content: center; padding: 16px; }
.order-modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.48); }
.order-modal-dialog { position: relative; width: min(100%, 820px); max-height: calc(100vh - 32px); overflow-y: auto; background: #fff; border-radius: 14px; padding: 22px; box-shadow: 0 12px 34px rgba(0,0,0,.26); }
.order-modal-dialog h2 { margin: 0 0 8px; font-size: 18px; }
.order-modal-hint { margin: 0 0 16px; color: #6b7a73; font-size: 13px; line-height: 1.7; }
.order-modal-close { position: absolute; top: 8px; left: 10px; background: transparent; border: none; font-size: 26px; color: #66736c; }
.order-form label { display: block; margin-bottom: 12px; font-size: 13px; color: #3c4a43; }
.order-form input, .order-form textarea, .order-form select { display: block; width: 100%; margin-top: 5px; padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px; background: #fff; font: inherit; }
.order-form-field { margin-bottom: 12px; }
.order-form-label { display: block; margin-bottom: 5px; font-size: 13px; color: #3c4a43; }
.customer-picker { position: relative; }
.customer-picker-trigger { display: flex; width: 100%; min-height: 42px; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px; background: #fff; color: #26342d; font: inherit; text-align: right; cursor: pointer; }
.customer-picker-trigger:hover, .customer-picker-trigger:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px rgba(25,118,210,.12); }
.customer-picker-trigger[aria-expanded="true"] { border-color: var(--primary); border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.customer-picker-chevron { color: #607069; font-size: 20px; line-height: 1; transition: transform .15s ease; }
.customer-picker-trigger[aria-expanded="true"] .customer-picker-chevron { transform: rotate(180deg); }
.customer-picker-options { position: absolute; z-index: 3; top: calc(100% - 1px); inset-inline: 0; max-height: 260px; overflow-y: auto; border: 1px solid var(--primary); border-radius: 0 0 9px 9px; background: #fff; box-shadow: 0 12px 26px rgba(0,0,0,.14); }
.customer-picker-search-row { position: sticky; top: 0; z-index: 1; padding: 9px; border-bottom: 1px solid #e7ece9; background: #f7faf8; }
.customer-picker-search { margin: 0 !important; padding-inline-start: 36px !important; background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%236b7a73' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-4-4'/%3E%3C/svg%3E") no-repeat 10px center !important; }
.customer-picker-option { display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border: 0; border-bottom: 1px solid #eef1ef; background: #fff; color: #1f2a24; text-align: right; font: inherit; }
.customer-picker-option:hover, .customer-picker-option:focus { background: #eaf3fd; outline: none; }
.customer-picker-option span { direction: ltr; color: #607069; font-size: 12px; }
.customer-picker-empty { padding: 14px; color: #7a8a83; text-align: center; font-size: 13px; }
.order-modal-items { margin: 14px 0; border: 1px solid var(--border); border-radius: 8px; max-height: 320px; overflow: auto; }
.order-preview-table { width: 100%; min-width: 620px; border-collapse: collapse; font-size: 12px; }
.order-preview-table th, .order-preview-table td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: right; vertical-align: middle; }
.order-preview-table th { position: sticky; top: 0; z-index: 1; background: #f4f7f5; color: #35443c; font-weight: bold; }
.order-preview-number { white-space: nowrap; font-variant-numeric: tabular-nums; }
.order-preview-gross { color: #146c48; font-weight: bold; }
.order-preview-total { position: sticky; bottom: 0; display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 11px 12px; background: #eaf4ee; color: #174b33; border-top: 1px solid #c5dfcf; }
.order-preview-total strong { white-space: nowrap; font-size: 14px; }

/* Sidebar toggle button is only meaningful when the sidebar is off-canvas (mobile). */
@media (min-width: 601px) {
    #sidebarToggle { display: none; }
}
