/* ============================================================
   برآورد هزینه تعمیر خودرو — صفحه کاربر
   پالت: گرافیتی کارگاهی + سبز (مثل نمونه) + کاغذ پیش‌فاکتور
   ============================================================ */
:root {
    --ink: #1d2733;          /* متن اصلی، گرافیتی */
    --ink-2: #5b6776;        /* متن ثانویه */
    --line: #e3e7ec;         /* خطوط */
    --bg: #f3f5f7;           /* پس‌زمینه */
    --paper: #ffffff;
    --receipt: #fffdf7;      /* کاغذ پیش‌فاکتور */
    --green: #15924a;        /* رنگ اصلی */
    --green-dark: #0f6f38;
    --green-soft: #e7f5ec;
    --danger: #c0392b;
    --radius-lg: 18px;
    --radius: 12px;
    --radius-sm: 8px;
    --font: "Vazirmatn", Tahoma, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.7;
    color: var(--ink);
    background: var(--bg);
}
body.modal-open { overflow: hidden; }
img { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--ink-2); }

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px; }

/* ---------- نوار بالا و هدر ---------- */
.topbar { background: var(--paper); border-bottom: 1px solid var(--line); }
.topbar-inner { height: 60px; display: flex; align-items: center; }
.logo { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 700; }

.hero {
    background: var(--ink);
    color: #fff;
    position: relative;
    overflow: hidden;
}
/* الگوی آچار و پیچ: خطوط مورب ملایم، یادآور کف کارگاه */
.hero::before {
    content: "";
    position: absolute; inset: 0;
    background:
        repeating-linear-gradient(135deg, rgba(255,255,255,.035) 0 2px, transparent 2px 22px);
    pointer-events: none;
}
.hero-inner { position: relative; padding: 36px 20px 64px; }
.hero h1 { margin: 0 0 8px; font-size: clamp(22px, 3.2vw, 32px); font-weight: 800; line-height: 1.4; max-width: 22ch; }
.hero p { margin: 0; color: #c9d2dc; max-width: 60ch; }

/* ---------- تب دسته‌های اصلی ---------- */
.tabs {
    display: flex; gap: 6px; flex-wrap: wrap;
    margin-top: -26px; position: relative;
    margin-bottom: 20px;
}
.tabs button {
    display: flex; align-items: center; gap: 8px;
    border: 1px solid var(--line); background: var(--paper);
    padding: 10px 18px; border-radius: var(--radius);
    font-weight: 600; color: var(--ink-2);
}
.tabs button img { width: 22px; height: 22px; }
.tabs button.active { color: var(--green-dark); border-color: var(--green); box-shadow: inset 0 -3px 0 var(--green); }

/* ---------- چیدمان اصلی ---------- */
.layout { display: flex; gap: 24px; align-items: flex-start; padding-bottom: 48px; }
.parts { flex: 1; min-width: 0; }
.parts-head h2 { margin: 0 0 12px; font-size: 18px; }

/* ---------- لیست زیردسته‌ها ---------- */
.cat-list { display: flex; flex-direction: column; gap: 10px; }
.cat {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
}
.cat-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.cat-icon { width: 34px; height: 34px; flex-shrink: 0; object-fit: contain; }
.cat-name { font-weight: 600; flex: 1; }
.cat-empty { font-size: 13px; color: var(--ink-2); }
.badge {
    font-size: 12px; font-weight: 600;
    background: var(--green-soft); color: var(--green-dark);
    padding: 2px 10px; border-radius: 99px;
}
.cat.has-items { border-color: #bfe3cc; }
.cat.has-items .cat-row { background: var(--green-soft); }

.add-btn {
    width: 36px; height: 36px; border-radius: 50%;
    border: 0; background: var(--green); color: #fff;
    display: grid; place-items: center; flex-shrink: 0;
    transition: background .15s;
}
.add-btn:hover { background: var(--green-dark); }
.add-btn:disabled { background: #c5ccd4; cursor: not-allowed; }

.cart-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 14px; border-top: 1px solid var(--line);
}
.cart-item img { width: 52px; height: 52px; object-fit: contain; border-radius: var(--radius-sm); background: var(--bg); flex-shrink: 0; }
.cart-item .info { flex: 1; min-width: 0; }
.cart-item .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cart-item .meta { font-size: 13px; color: var(--ink-2); }
.cart-item .actions { display: flex; gap: 4px; }

.icon-btn {
    width: 36px; height: 36px; border-radius: var(--radius-sm);
    border: 0; background: transparent; color: var(--ink-2);
    display: grid; place-items: center;
}
.icon-btn:hover { background: var(--bg); color: var(--ink); }
.icon-btn.danger:hover { color: var(--danger); background: #fbeceb; }

.skeleton { height: 60px; border-radius: var(--radius); background: linear-gradient(90deg, #e9edf1, #f5f7f9, #e9edf1); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.empty-state { background: var(--paper); border: 1px dashed var(--line); border-radius: var(--radius); padding: 28px; text-align: center; color: var(--ink-2); }

/* ---------- پیش‌فاکتور (عنصر شاخص صفحه) ---------- */
.receipt {
    width: 300px; flex-shrink: 0;
    position: sticky; top: 16px;
    background: var(--receipt);
    border: 1px solid #ece6d6;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 18px 18px 26px;
    /* لبه پایین دندانه‌ای مثل کاغذ پاره‌شده رسید */
    -webkit-mask: radial-gradient(circle 7px at 10px 100%, transparent 98%, #000) -10px 0 / 20px 100% repeat-x;
            mask: radial-gradient(circle 7px at 10px 100%, transparent 98%, #000) -10px 0 / 20px 100% repeat-x;
}
.receipt-head { display: flex; align-items: baseline; justify-content: space-between; border-bottom: 2px dashed #e4dcc6; padding-bottom: 10px; }
.receipt-head h2 { margin: 0; font-size: 17px; }
.receipt-count { font-size: 13px; color: var(--ink-2); }
.receipt-lines { list-style: none; margin: 10px 0; padding: 0; max-height: 280px; overflow-y: auto; font-size: 13px; }
.receipt-lines li { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; border-bottom: 1px dotted #e8e1cf; }
.receipt-lines li span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.receipt-lines li span:last-child { white-space: nowrap; font-variant-numeric: tabular-nums; }
.receipt-lines .empty { color: var(--ink-2); border: 0; justify-content: center; padding: 14px 0; }
.receipt-total { display: flex; justify-content: space-between; align-items: baseline; padding: 12px 0; border-top: 2px solid var(--ink); margin-top: 6px; }
.receipt-total strong { font-size: 22px; font-weight: 800; }
.receipt-total small { font-size: 13px; font-weight: 500; color: var(--ink-2); }
.receipt-actions { display: flex; flex-direction: column; gap: 8px; }
.receipt-note { font-size: 12px; color: var(--ink-2); margin: 12px 0 0; }
.clear-btn { align-self: center; color: var(--ink-2); margin-top: 2px; }
.clear-btn:disabled { visibility: hidden; }

/* ---------- ثبت سفارش ---------- */
.modal-sm { max-width: 460px; }
.order-form { padding: 16px; overflow-y: auto; }
.order-summary {
    display: flex; justify-content: space-between; align-items: baseline;
    background: var(--receipt); border: 1px dashed #e4dcc6; border-radius: var(--radius-sm);
    padding: 10px 14px; margin-bottom: 14px; font-size: 14px;
}
.order-summary strong { font-size: 18px; }
.o-field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.o-field > span { font-weight: 600; font-size: 14px; }
.o-field small { font-weight: 400; color: var(--ink-2); }
.o-field input, .o-field textarea {
    border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 9px 12px; background: var(--paper); resize: vertical;
}
.o-field input:focus, .o-field textarea:focus { border-color: var(--green); outline: none; }
.o-field input[dir="ltr"] { text-align: right; }
.o-field.invalid input { border-color: var(--danger); }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.o-error { background: #fbeceb; color: var(--danger); border-radius: var(--radius-sm); padding: 8px 12px; font-size: 14px; margin-bottom: 10px; }
.o-hint { font-size: 12px; color: var(--ink-2); margin: 0 0 14px; }
.o-actions { display: flex; gap: 8px; }
.o-actions .btn-primary { flex: 1; }
.order-done { padding: 28px 20px; text-align: center; }
.order-done h3 { margin: 10px 0 6px; font-size: 19px; }
.order-done p { margin: 0 0 6px; }
.tracking {
    font-size: 28px; font-weight: 800; letter-spacing: 3px; margin: 4px auto 14px;
    background: var(--receipt); border: 2px dashed #e4dcc6; border-radius: var(--radius); padding: 8px 18px; display: inline-block;
    font-variant-numeric: tabular-nums;
}
.order-done .btn-primary { margin-top: 14px; min-width: 140px; }

/* ---------- دکمه‌ها ---------- */
.btn-primary {
    border: 0; background: var(--green); color: #fff;
    padding: 10px 18px; border-radius: var(--radius-sm); font-weight: 600;
    text-decoration: none; display: inline-flex; justify-content: center; align-items: center; gap: 6px;
}
.btn-primary:hover { background: var(--green-dark); }
.btn-primary:disabled { background: #b8c2cc; cursor: not-allowed; }
.btn-ghost {
    border: 1px solid var(--line); background: var(--paper); color: var(--ink);
    padding: 9px 16px; border-radius: var(--radius-sm); font-weight: 500;
}
.btn-ghost:hover { border-color: #c5ccd4; }
.btn-ghost:disabled { color: #aab3bd; cursor: not-allowed; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.link-btn { border: 0; background: none; color: var(--green-dark); font-size: 13px; padding: 0; }

/* ---------- مودال ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-top { z-index: 60; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(20, 28, 38, .55); }
.modal-dialog {
    position: relative; background: var(--paper);
    border-radius: var(--radius-lg);
    width: 100%; max-width: 640px; max-height: calc(100vh - 32px);
    display: flex; flex-direction: column;
    box-shadow: 0 24px 60px rgba(20, 28, 38, .25);
    animation: pop .16s ease-out;
}
.modal-lg { max-width: 1000px; height: calc(100vh - 32px); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 17px; flex: 1; }
.modal-head .muted { flex: 1; }
.modal-foot { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); }
.modal-foot .btn-primary { margin-inline-start: auto; min-width: 120px; }

/* ---------- انتخاب کالا ---------- */
.picker { display: flex; flex: 1; min-height: 0; }
.picker-filters { width: 240px; flex-shrink: 0; border-inline-end: 1px solid var(--line); overflow-y: auto; padding: 14px; }
.filters-head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.filters-head strong { flex: 1; }
.mobile-only { display: none !important; }
.filter-group { border-bottom: 1px solid var(--line); }
.filter-group summary { padding: 10px 0; font-weight: 600; cursor: pointer; list-style: none; display: flex; justify-content: space-between; }
.filter-group summary::-webkit-details-marker { display: none; }
.filter-group summary::after { content: "‹"; transform: rotate(-90deg); transition: transform .15s; color: var(--ink-2); }
.filter-group[open] summary::after { transform: rotate(90deg); }
.filter-options { padding-bottom: 10px; max-height: 220px; overflow-y: auto; }
.filter-options label { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 14px; cursor: pointer; }
.filter-options input { accent-color: var(--green); width: 16px; height: 16px; }
.filter-options .count { margin-inline-start: auto; font-size: 12px; color: var(--ink-2); }
.filter-options label.zero { color: #a5aeb8; }

.picker-main { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 14px 16px 0; }
.picker-tools { display: flex; gap: 8px; }
.search {
    flex: 1; display: flex; align-items: center; gap: 8px;
    border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0 12px; color: var(--ink-2);
}
.search:focus-within { border-color: var(--green); }
.search input { border: 0; outline: 0; flex: 1; padding: 9px 0; background: none; color: var(--ink); }
.filters-toggle { display: none; }

.sortbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 0; font-size: 14px; }
.sort-options { display: flex; gap: 2px; flex-wrap: wrap; }
.sort-options button { border: 0; background: none; padding: 4px 10px; border-radius: 99px; color: var(--ink-2); }
.sort-options button.active { background: var(--green-soft); color: var(--green-dark); font-weight: 600; }
.page-size { margin-inline-start: auto; display: flex; align-items: center; gap: 6px; color: var(--ink-2); }
.page-size select { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 3px 6px; background: var(--paper); }

.product-list { flex: 1; overflow-y: auto; border-top: 1px solid var(--line); }
.product-row { display: flex; align-items: center; gap: 14px; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.product-row img { width: 72px; height: 72px; object-fit: contain; border-radius: var(--radius-sm); background: var(--bg); flex-shrink: 0; }
.product-row .info { flex: 1; min-width: 0; }
.product-row .name { font-weight: 500; }
.product-row .picked { font-size: 12px; color: var(--green-dark); font-weight: 600; }
.product-row .price { text-align: left; white-space: nowrap; font-weight: 700; }
.product-row .price small { font-weight: 400; color: var(--ink-2); }
.product-row .row-actions { display: flex; gap: 6px; margin-top: 6px; justify-content: flex-end; }
.list-message { padding: 40px 10px; text-align: center; color: var(--ink-2); }

.pager { display: flex; justify-content: center; gap: 4px; padding: 10px 0; }
.pager button { min-width: 34px; height: 34px; border: 1px solid var(--line); background: var(--paper); border-radius: var(--radius-sm); }
.pager button.active { background: var(--green); border-color: var(--green); color: #fff; }
.pager button:disabled { opacity: .45; cursor: default; }

/* ---------- جزئیات کالا ---------- */
.detail { padding: 18px; overflow-y: auto; }
.detail-top { display: flex; gap: 18px; }
.detail-top img { width: 200px; height: 200px; object-fit: contain; background: var(--bg); border-radius: var(--radius); flex-shrink: 0; }
.detail-top h4 { margin: 0 0 8px; font-size: 18px; line-height: 1.5; }
.detail-price { font-size: 22px; font-weight: 800; margin: 8px 0; }
.detail-price small { font-size: 14px; font-weight: 500; color: var(--ink-2); }
.detail-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 18px 0 12px; }
.detail-tabs button { border: 0; background: none; padding: 8px 14px; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.detail-tabs button.active { color: var(--green-dark); border-bottom-color: var(--green); font-weight: 600; }
.specs { width: 100%; border-collapse: collapse; font-size: 14px; }
.specs th, .specs td { text-align: right; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.specs th { width: 38%; color: var(--ink-2); font-weight: 500; background: #fafbfc; }
.desc { white-space: pre-line; font-size: 14px; }

.qty { display: flex; align-items: center; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.qty button { width: 34px; height: 36px; border: 0; background: var(--bg); font-size: 18px; }
.qty input { width: 46px; height: 36px; border: 0; text-align: center; -moz-appearance: textfield; }
.qty input::-webkit-outer-spin-button, .qty input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* وقتی کالا عکس ندارد، آیکون زیردسته کوچک‌تر و کم‌رنگ‌تر نمایش داده می‌شود */
img.fallback { padding: 12px; opacity: .55; }
.detail-top img.fallback { padding: 50px; }

/* ---------- اعلان ---------- */
.toast {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
    background: var(--ink); color: #fff; padding: 10px 18px; border-radius: var(--radius);
    z-index: 100; font-size: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.2);
}

.error-page { max-width: 560px; margin: 80px auto; padding: 0 20px; text-align: center; }

/* ---------- موبایل ---------- */
@media (max-width: 860px) {
    .layout { flex-direction: column-reverse; align-items: stretch; padding-bottom: 150px; }
    .receipt {
        position: fixed; bottom: 0; right: 0; left: 0; top: auto; width: auto; z-index: 40;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        -webkit-mask: none; mask: none;
        padding: 12px 16px; box-shadow: 0 -8px 30px rgba(20,28,38,.12);
    }
    .receipt-head, .receipt-lines, .receipt-note { display: none; }
    .receipt-total { border-top: 0; margin: 0; padding: 0 0 8px; }
    .receipt-actions { flex-direction: row; }
    .receipt-actions > * { flex: 1; }
    .receipt-actions .clear-btn { display: none; }

    .toast { bottom: 130px; }
    .modal { padding: 0; align-items: flex-end; }
    .modal-dialog, .modal-lg { max-width: none; max-height: 100vh; height: auto; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
    .modal-lg { height: 100vh; height: 100dvh; border-radius: 0; }
    .picker { flex-direction: column; position: relative; }
    .picker-filters {
        display: none; position: absolute; inset: 0; z-index: 2; width: auto;
        background: var(--paper); border: 0; padding: 0;
        flex-direction: column; overflow: hidden;
    }
    .picker-filters.open { display: flex; }
    .picker-filters .filters-head { padding: 10px 12px; margin: 0; border-bottom: 1px solid var(--line); }
    .filter-list { flex: 1; overflow-y: auto; padding: 4px 16px 12px; }
    .filters-foot { padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
    .filters-foot .btn-primary { width: 100%; padding: 12px; }
    .mobile-only { display: flex !important; }
    .filters-foot.mobile-only { display: block !important; }
    .filters-toggle { display: inline-block; white-space: nowrap; }
    .filters-toggle.active { border-color: var(--green); color: var(--green-dark); font-weight: 600; }
    .detail-top { flex-direction: column; }
    .detail-top img { width: 100%; height: 180px; }
    .product-row img { width: 56px; height: 56px; }
    .modal-foot { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- چاپ پیش‌فاکتور ---------- */
.print-area { display: none; }
@media print {
    body { background: #fff; }
    body > *:not(.print-area) { display: none !important; }
    .print-area { display: block !important; font-size: 12pt; color: #000; }
    .print-area h1 { font-size: 16pt; margin: 0 0 4pt; }
    .print-area .print-meta { display: flex; justify-content: space-between; margin-bottom: 10pt; }
    .print-area table { width: 100%; border-collapse: collapse; }
    .print-area th, .print-area td { border: 1px solid #555; padding: 4pt 6pt; text-align: right; }
    .print-area th { background: #eee; }
    .print-area td.num { text-align: left; white-space: nowrap; }
    .print-area .group-row td { background: #f5f5f5; font-weight: 700; }
    .print-area tfoot td { font-weight: 800; }
    .print-area .print-note { margin-top: 10pt; font-size: 10pt; }
}
