/*
  ظاهر بازاریاب داخل پوستهٔ سکو. همه‌چیز زیر کلاس ‎.torob‎ است تا رنگ‌ها و قاعده‌های سراسریِ بازاریاب
  (پیش‌تر روی body و :root) به نوار ناوبری، کشوی منو و صفحه‌های ماژول‌های دیگر نشت نکند.
  فونت همان فونت سکو (Vazirmatn) است.
*/

.torob {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --border: #e3e8ee;
    --text: #1f2933;
    --muted: #6b7785;
    --brand: #e8384f;
    --brand-dark: #c72c40;
    --ok: #0f9d58;
    --warn: #f4b400;
    --danger: #d93025;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);

    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.8;
    min-height: 100%;
    -webkit-tap-highlight-color: transparent;
}

[data-bale-theme="dark"] .torob {
    --bg: #111b21;
    --surface: #1f2c33;
    --border: #2a3942;
    --text: #e9edef;
    --muted: #8696a0;
    --shadow: none;
}

.torob *, .torob *::before, .torob *::after { box-sizing: border-box; }

.torob img { max-width: 100%; }

.torob a { color: inherit; text-decoration: none; }
.torob a:hover { color: var(--brand); }

.t-container { max-width: 1180px; margin: 0 auto; padding: 0 16px; }

/* ---------- سربرگ ---------- */

.t-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}

.t-header-inner {
    display: flex;
    align-items: center;
    gap: 16px;
    min-height: 64px;
    flex-wrap: wrap;
}

.t-brand { display: flex; align-items: baseline; gap: 6px; font-weight: 700; }
.t-brand-mark { color: var(--brand); font-size: 22px; }
.t-brand-sub { color: var(--muted); font-size: 12px; }

.t-search { display: flex; flex: 1 1 320px; gap: 8px; }

.t-search input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font: inherit;
    background: var(--bg);
}

.t-search input:focus { outline: 2px solid var(--brand); background: var(--surface); }

.t-search button {
    padding: 10px 18px;
    border: 0;
    border-radius: var(--radius);
    background: var(--brand);
    color: #fff;
    font: inherit;
    cursor: pointer;
}

.t-search button:hover { background: var(--brand-dark); }

.t-nav { display: flex; align-items: center; gap: 14px; font-size: 13px; }

/* ---------- اجزای عمومی ---------- */

.t-main { padding: 24px 16px 48px; min-height: 60vh; }

.t-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
    margin-bottom: 18px;
}

.t-card h2, .t-card h3 { margin-top: 0; }

.t-btn {
    display: inline-block;
    padding: 9px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    cursor: pointer;
    text-align: center;
}

.t-btn:hover { border-color: var(--brand); color: var(--brand); }
.t-btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.t-btn-primary:hover { background: var(--brand-dark); color: #fff; }
.t-btn-sm { padding: 6px 12px; font-size: 13px; }
.t-btn-danger { border-color: var(--danger); color: var(--danger); }

.t-alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    border: 1px solid transparent;
}

.t-alert-success { background: #e6f4ea; border-color: #b7dfc2; color: #0b6b33; }
.t-alert-error { background: #fce8e6; border-color: #f3b4ae; color: #9c221a; }
.t-alert-info { background: #e8f0fe; border-color: #b6cdf7; color: #174ea6; }

.t-muted { color: var(--muted); }
.t-small { font-size: 12px; }

/* ---------- فرم ---------- */

.t-field { margin-bottom: 14px; }
.t-field label { display: block; margin-bottom: 6px; font-size: 13px; color: var(--muted); }

.t-field input,
.t-field select,
.t-field textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font: inherit;
    background: var(--surface);
}

.t-field input:focus,
.t-field select:focus,
.t-field textarea:focus { outline: 2px solid var(--brand); }

.t-grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }

/* ---------- کارت محصول ---------- */

.t-products {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 14px;
}

.t-product {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.t-product:hover { border-color: var(--brand); }

.t-product-image {
    aspect-ratio: 1;
    background: var(--bg);
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.t-product-image img { width: 100%; height: 100%; object-fit: contain; }

.t-product-title {
    font-size: 13px;
    line-height: 1.7;
    min-height: 3.4em;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.t-price { font-weight: 700; font-size: 16px; }
.t-price small { font-weight: 400; font-size: 11px; color: var(--muted); }
.t-price-old { text-decoration: line-through; color: var(--muted); font-size: 12px; font-weight: 400; }

.t-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    border: 1px solid var(--border);
}

.t-badge-ok { background: #e6f4ea; border-color: #b7dfc2; color: #0b6b33; }
.t-badge-warn { background: #fef7e0; border-color: #f6dd8f; color: #7a5b00; }
.t-badge-danger { background: #fce8e6; border-color: #f3b4ae; color: #9c221a; }
.t-badge-muted { background: var(--bg); color: var(--muted); }

.t-out-of-stock { color: var(--danger); font-size: 12px; }

/* ---------- جدول ---------- */

.t-table-wrap { overflow-x: auto; }

.t-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.t-table th, .t-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: right; }
.t-table th { background: var(--bg); font-weight: 600; color: var(--muted); white-space: nowrap; }
.t-table tbody tr:hover { background: #fafbfc; }

/* ---------- آمار ---------- */

.t-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }

.t-stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
}

.t-stat-label { font-size: 12px; color: var(--muted); }
.t-stat-value { font-size: 22px; font-weight: 700; margin-top: 4px; }

/* نمودار ستونی ساده؛ ارتفاع هر ستون با متغیر --h از سمت سرور می‌آید. */
.t-chart { display: flex; align-items: flex-end; gap: 6px; height: 140px; margin-top: 12px; }
.t-chart-bar { flex: 1; background: var(--bg); border-radius: 4px 4px 0 0; position: relative; display: flex; align-items: flex-end; }
.t-chart-fill { width: 100%; background: var(--brand); border-radius: 4px 4px 0 0; height: var(--h, 0%); min-height: 2px; }
.t-chart-labels { display: flex; gap: 6px; font-size: 10px; color: var(--muted); margin-top: 6px; }
.t-chart-labels span { flex: 1; text-align: center; }

/* ---------- پنل ---------- */

/* minmax(0, …): ستونِ «1fr» حداقلِ پیش‌فرضش اندازهٔ محتواست و جدولِ پهن (اجراهای روبات)
   کل صفحه را افقی اسکرول‌دار می‌کرد به‌جای اینکه داخل .t-table-wrap اسکرول بخورد. */
.t-panel { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 18px; align-items: start; }

.t-panel-nav {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px;
    position: sticky;
    top: 80px;
}

.t-panel-nav a { display: block; padding: 9px 12px; border-radius: 8px; font-size: 13px; }
.t-panel-nav a:hover { background: var(--bg); }
.t-panel-nav a.active { background: var(--brand); color: #fff; }

/* ---------- تبلیغات ---------- */

.t-ads { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); gap: 12px; margin-bottom: 18px; }

.t-ad {
    position: relative;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface);
    display: block;
}

.t-ad img { width: 100%; display: block; }
.t-ad-body { padding: 10px 12px; }
.t-ad-tag { position: absolute; top: 8px; left: 8px; background: rgba(0,0,0,.6); color: #fff; font-size: 10px; padding: 2px 8px; border-radius: 999px; }

.torob .hidden { display: none !important; }

/* ---------- صفحه‌بندی ---------- */

.t-pager { display: flex; gap: 6px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }
.t-pager a, .t-pager span { padding: 6px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.t-pager .current { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ---------- پابرگ ---------- */

.t-footer { background: var(--surface); border-top: 1px solid var(--border); padding: 28px 0; margin-top: 40px; }
.t-footer-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; }
.t-footer h4 { margin: 0 0 8px; font-size: 14px; }
.t-footer a { display: block; font-size: 13px; color: var(--muted); }

/* ---------- کد ---------- */

.t-code {
    background: #1f2933;
    color: #e3e8ee;
    padding: 14px;
    border-radius: var(--radius);
    font-family: Consolas, monospace;
    font-size: 12px;
    direction: ltr;
    text-align: left;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

/* ---------- صفحهٔ جزئیات کالا ---------- */

.t-pdp { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 18px; align-items: start; }

.t-pdp-hero { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 18px; }

.t-pdp-title { font-size: 20px; line-height: 1.7; margin: 0 0 10px; overflow-wrap: anywhere; }
.t-pdp-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-bottom: 10px; }
.t-pdp-price { font-size: 24px; }
.t-pdp-offers-title { font-size: 17px; }
/* نمودار تاریخچهٔ قیمت؛ محور زمان همیشه چپ‌به‌راست است حتی در صفحهٔ راست‌به‌چپ. */
.t-price-history svg { display: block; width: 100%; height: auto; direction: ltr; overflow: visible; }
.t-price-history-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 8px; }
.t-pdp-store-title { font-size: 15px; margin-bottom: 8px; }

.t-offers tr.is-current { background: #fff7e6; }
.t-offers tbody tr.is-current:hover { background: #fff1d6; }
.t-offer-title a { overflow-wrap: anywhere; }
.t-offer-current { display: none; }

/* نوار خرید پایین صفحه فقط روی موبایل؛ روی دسکتاپ دکمهٔ کنار تصویر همیشه دیده می‌شود. */
.t-buybar { display: none; }

/* ---------- فیلتر جست‌وجو ---------- */

.t-filters > summary { display: none; }

/* ---------- موبایل ---------- */

@media (max-width: 820px) {
    .t-panel { grid-template-columns: minmax(0, 1fr); }
    .t-panel-nav {
        position: static;
        display: flex;
        gap: 4px;
        overflow-x: auto;
        scrollbar-width: none;
    }
    .t-panel-nav::-webkit-scrollbar { display: none; }
    .t-panel-nav a { white-space: nowrap; flex: none; }
    .t-header-inner { min-height: auto; padding: 10px 0; }

    .t-pdp { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 640px) {
    .t-container { padding: 0 12px; }
    .t-main { padding: 14px 12px 32px; }
    .t-card { padding: 14px; margin-bottom: 12px; }

    .torob h1 { font-size: 20px; }
    .torob h2 { font-size: 17px; }

    /* سربرگ: نشان و منو در یک خط، جست‌وجو تمام‌عرض در خط دوم. */
    .t-header-inner { gap: 8px 12px; padding: 8px 0 10px; }
    .t-brand { order: 1; }
    .t-brand-mark { font-size: 20px; }
    .t-nav {
        order: 2;
        margin-inline-start: auto;
        gap: 12px;
        font-size: 12px;
        overflow-x: auto;
        white-space: nowrap;
        scrollbar-width: none;
    }
    .t-nav::-webkit-scrollbar { display: none; }
    .t-search { order: 3; flex: 1 1 100%; }
    .t-search button { padding: 10px 14px; }

    /* زیر ۱۶px، سافاری iOS با فوکوس روی ورودی صفحه را زوم می‌کند. */
    .t-search input,
    .t-field input,
    .t-field select,
    .t-field textarea { font-size: 16px; }

    .t-btn { min-height: 42px; display: inline-flex; align-items: center; justify-content: center; }
    .t-btn-sm { min-height: 36px; }

    /* دو ستون کارت کالا، مثل اپ‌های فروشگاهی. */
    .t-products { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
    .t-product { padding: 8px; gap: 6px; }
    .t-product-title { font-size: 12px; }
    .t-price { font-size: 14px; }

    .t-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
    .t-stat-value { font-size: 18px; }

    .t-footer { padding: 20px 0; margin-top: 24px; }

    /* فیلترها روی موبایل جمع می‌شوند تا نتایج بالای صفحه بیایند. */
    .t-filters > summary {
        display: flex;
        align-items: center;
        justify-content: space-between;
        cursor: pointer;
        font-weight: 700;
        list-style: none;
    }
    .t-filters > summary::-webkit-details-marker { display: none; }
    .t-filters > summary::after { content: "▾"; color: var(--muted); transition: transform .2s; }
    .t-filters[open] > summary { margin-bottom: 12px; }
    .t-filters[open] > summary::after { transform: rotate(180deg); }
    .t-filters .t-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 10px; }

    /* ----- جزئیات کالا ----- */

    .t-pdp { gap: 0; }
    .t-pdp-hero { grid-template-columns: minmax(0, 1fr); gap: 14px; }
    .t-pdp-hero .t-product-image { width: min(100%, 300px); margin: 0 auto; }
    .t-pdp-title { font-size: 17px; }
    .t-pdp-price { font-size: 22px; }
    .t-pdp-cta { width: 100%; }
    .t-pdp-offers-title { font-size: 15px; }

    /* جدول فروشگاه‌ها روی موبایل به فهرست کارت تبدیل می‌شود؛ پنج ستون در ۳۶۰px جا نمی‌شود. */
    .t-offers thead { display: none; }
    .t-offers, .t-offers tbody { display: block; }
    .t-offers tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas:
            "store price"
            "title title"
            "status go";
        align-items: center;
        gap: 6px 10px;
        padding: 12px 0;
        border-bottom: 1px solid var(--border);
    }
    .t-offers tr:last-child { border-bottom: 0; }
    .t-offers tr.is-current { padding: 12px 10px; border-radius: 8px; border-bottom-color: transparent; }
    .t-table-wrap:has(.t-offers) { overflow: visible; }
    .t-offers td { padding: 0; border: 0; }
    .t-offer-store { grid-area: store; font-weight: 700; }
    .t-offer-price { grid-area: price; white-space: nowrap; }
    .t-offer-price strong { font-size: 15px; }
    .t-offer-title { grid-area: title; font-size: 12px; color: var(--muted); }
    .t-offer-status { grid-area: status; }
    .t-offer-go { grid-area: go; }
    .t-offer-current { display: inline-block; }

    .t-buybar {
        position: fixed;
        inset-inline: 0;
        bottom: 0;
        z-index: 30;
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
        background: var(--surface);
        border-top: 1px solid var(--border);
        box-shadow: 0 -4px 16px rgba(16, 24, 40, .08);
        transition: transform .2s ease;
    }
    .t-buybar.is-hidden { transform: translateY(110%); }
    .t-buybar-price { flex: none; line-height: 1.4; }
    .t-buybar-price .t-price { font-size: 17px; }
    .t-buybar .t-btn { flex: 1; }

    /* جای نوار خرید تا پابرگ زیرش نماند. */
    .torob:has(.t-buybar) .t-footer { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
}
/* ---------- داخل پنل مدیر سکو ---------- */

.torob.t-admin { background: transparent; padding: 4px 0 24px; }

/* ---------- داخل پوستهٔ سکو ---------- */

/* ‎.bale-main‎ ستون flex است؛ بدون این، محتوای بلند فشرده می‌شد و پابرگ رویش می‌افتاد. */
main.torob > * { flex-shrink: 0; }
main.torob > .t-main { flex-grow: 1; width: 100%; }
