/* ---------- theme: کیا کافی گستر پارسا ----------
   سبز برند #8DC63F و خاکستری برند #808285 (طبق راهنمای لوگوی کیا گستر).
   --accent برای سطوح پُررنگ (دکمه، چیپ فعال) و --accent-text برای متنِ سبز روی زمینهٔ روشن
   (سبز اصلی روی سفید کنتراست کافی ندارد، پس برای متن از سایهٔ تیره‌تر همان سبز استفاده می‌شود). */
:root {
  --bg: #f4f5f1; --surface: #ffffff; --surface-2: #f8f9f5; --ink: #2d2e30; --ink-2: #58595b; --ink-3: #6b6d70;
  --line: #e1e4da; --accent: #8dc63f; --accent-ink: #1d2a08; --accent-text: #4a7510; --accent-soft: #ecf5db;
  --ok: #1f7a46; --ok-soft: #e1f3e8; --warn: #9a6200; --warn-soft: #fff0d1; --bad: #b3261e; --bad-soft: #fde8e6; --info: #004a7c; --info-soft: #e1edf6;
  --shadow: 0 1px 2px rgba(40,50,25,.06), 0 6px 18px rgba(40,50,25,.07);
  --radius: 14px; --radius-sm: 10px;
  --font: "IRANSansX", "Vazirmatn", "Vazir", "Segoe UI", Tahoma, "Noto Sans Arabic", "Noto Naskh Arabic", system-ui, -apple-system, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1f2021; --surface: #2a2b2d; --surface-2: #323335; --ink: #f1f2ee; --ink-2: #c9cbc4; --ink-3: #9d9f99;
    --line: #424345; --accent: #8dc63f; --accent-ink: #14200a; --accent-text: #a8d964; --accent-soft: #2f3a20;
    --ok: #5fcf8e; --ok-soft: #173424; --warn: #f0b84f; --warn-soft: #3a2c10; --bad: #ff8a80; --bad-soft: #3d1b19; --info: #7db7f5; --info-soft: #172a40;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.35); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #1f2021; --surface: #2a2b2d; --surface-2: #323335; --ink: #f1f2ee; --ink-2: #c9cbc4; --ink-3: #9d9f99;
    --line: #424345; --accent: #8dc63f; --accent-ink: #14200a; --accent-text: #a8d964; --accent-soft: #2f3a20;
    --ok: #5fcf8e; --ok-soft: #173424; --warn: #f0b84f; --warn-soft: #3a2c10; --bad: #ff8a80; --bad-soft: #3d1b19; --info: #7db7f5; --info-soft: #172a40;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.35); color-scheme: dark;
  }
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.7; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }
.noscript { padding: 2rem; text-align: center; }
.ltr { direction: ltr; unicode-bidi: plaintext; text-align: left; }
.muted { color: var(--ink-3); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- buttons & inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 42px; padding: 0 1rem; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface); font-weight: 600; transition: background .15s, transform .05s; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { min-height: 34px; padding: 0 .7rem; font-size: .88rem; }
.btn.icon { width: 42px; padding: 0; }
.btn svg, .chip svg { width: 18px; height: 18px; flex: none; }
.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .85rem; }
.field > label, .lbl { font-size: .85rem; color: var(--ink-2); font-weight: 600; }
.input, select.input, textarea.input { width: 100%; min-height: 44px; padding: .55rem .8rem; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface); }
textarea.input { min-height: 90px; resize: vertical; }
.input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.row { display: flex; gap: .6rem; }
.row > * { flex: 1; min-width: 0; }
.err { color: var(--bad); background: var(--bad-soft); border-radius: var(--radius-sm); padding: .55rem .8rem; margin: 0 0 .8rem; font-size: .9rem; }
.hint { font-size: .82rem; color: var(--ink-3); margin-top: .15rem; }

/* ---------- login ---------- */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 1.2rem; background: linear-gradient(180deg, var(--accent-soft) 0%, var(--bg) 60%); }
.login-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 1.8rem 1.5rem; box-shadow: var(--shadow); }
.login-card .logo { width: 64px; height: 64px; border-radius: 18px; display: block; margin: 0 auto 1rem; }
.login-card h1 { font-size: 1.25rem; text-align: center; margin: 0 0 .2rem; }
.login-card p.sub { text-align: center; color: var(--ink-3); margin: 0 0 1.4rem; font-size: .9rem; }

/* ---------- top bar ---------- */
.topbar { padding: .6rem max(.9rem, env(safe-area-inset-right)) .1rem max(.9rem, env(safe-area-inset-left)); }
.sticky { position: sticky; top: 0; z-index: 20; border-top: 4px solid var(--accent); background: color-mix(in srgb, var(--bg) 94%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); padding: .45rem max(.9rem, env(safe-area-inset-right)) .4rem max(.9rem, env(safe-area-inset-left)); }
.topbar-in { max-width: 1280px; margin: 0 auto; }
.bar1 { display: flex; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 800; font-size: 1rem; flex: 1; min-width: 0; }
.brand img { width: 30px; height: 30px; border-radius: 9px; }
.brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip { display: inline-flex; align-items: center; gap: .35rem; min-height: 34px; padding: 0 .75rem; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: .85rem; font-weight: 600; white-space: nowrap; }
button.chip:hover { background: var(--surface-2); }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.searchrow { display: flex; gap: .5rem; align-items: center; }
.search { position: relative; flex: 1; }
.search input { padding-inline-start: 2.6rem; padding-inline-end: 2.4rem; min-height: 48px; border-radius: 14px; font-size: 1rem; }
.search .ico { position: absolute; inset-inline-start: .85rem; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }
.search .ico svg { width: 20px; height: 20px; }
.search .clear { position: absolute; inset-inline-end: .35rem; top: 50%; transform: translateY(-50%); width: 36px; height: 36px; border: 0; background: transparent; color: var(--ink-3); border-radius: 50%; }
.chips { display: flex; gap: .45rem; overflow-x: auto; padding: .55rem 0 .15rem; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.chips::-webkit-scrollbar { display: none; }
.chips .chip { flex: none; }
.chip .n { font-weight: 500; opacity: .75; font-size: .78rem; }

/* ---------- toolbar ---------- */
.main { max-width: 1280px; margin: 0 auto; padding: .8rem max(.9rem, env(safe-area-inset-right)) 6rem max(.9rem, env(safe-area-inset-left)); }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-bottom: .8rem; }
.toolbar .count { font-weight: 700; margin-inline-end: auto; }
.toolbar select { min-height: 38px; padding: 0 .6rem; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; min-height: 36px; padding: 0 .7rem; font-size: .85rem; font-weight: 600; color: var(--ink-2); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.banner { background: var(--warn-soft); color: var(--warn); border-radius: var(--radius-sm); padding: .55rem .8rem; margin-bottom: .8rem; font-size: .88rem; display: flex; gap: .6rem; align-items: center; justify-content: space-between; }

/* ---------- product cards ---------- */
.grid { display: grid; grid-template-columns: 1fr; gap: .65rem; }
@media (min-width: 760px) { .grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1100px) { .grid { grid-template-columns: repeat(3, 1fr); } }
.card { display: grid; grid-template-columns: 84px 1fr; gap: .8rem; padding: .75rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-align: start; width: 100%; box-shadow: 0 1px 0 rgba(0,0,0,.02); content-visibility: auto; contain-intrinsic-size: 0 130px; }
.card:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.thumb { width: 84px; height: 84px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); display: grid; place-items: center; overflow: hidden; color: var(--ink-3); }
.thumb img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.thumb svg { width: 30px; height: 30px; opacity: .6; }
.card .t { font-weight: 700; line-height: 1.55; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word; }
.card .meta { color: var(--ink-3); font-size: .8rem; margin-top: .1rem; display: flex; flex-wrap: wrap; gap: .1rem .6rem; }
.card .pr { margin-top: .35rem; display: flex; align-items: baseline; flex-wrap: wrap; gap: .1rem .6rem; }
.price { font-weight: 800; font-size: 1.05rem; color: var(--accent-text); }
.price .u { font-weight: 600; font-size: .78rem; color: var(--ink-3); margin-inline-start: .25rem; }
.price.none { color: var(--ink-3); font-weight: 600; font-size: .9rem; }
.sub { font-size: .8rem; color: var(--ink-3); }
.badge { display: inline-flex; align-items: center; padding: 0 .5rem; border-radius: 999px; font-size: .74rem; font-weight: 700; line-height: 1.7; }
.badge.ok { background: var(--ok-soft); color: var(--ok); } .badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); } .badge.info { background: var(--info-soft); color: var(--info); }
.card .foot { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; margin-top: .3rem; }
.empty { text-align: center; padding: 3rem 1rem; color: var(--ink-3); }
.empty h3 { color: var(--ink-2); margin: .5rem 0; }
.more { display: block; margin: 1rem auto 0; }

/* ---------- table view ---------- */
.tablewrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.t th { position: sticky; top: 0; background: var(--surface-2); text-align: start; padding: .55rem .7rem; font-size: .8rem; color: var(--ink-2); border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t td { padding: .45rem .7rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr { cursor: pointer; }
table.t tbody tr:hover { background: var(--surface-2); }
table.t .thumb { width: 44px; height: 44px; }
table.t .nm { max-width: 340px; font-weight: 600; }
table.t .num { white-space: nowrap; }
@media (max-width: 759px) { .only-wide { display: none !important; } }

/* ---------- FAB ---------- */
.fab { position: fixed; inset-block-end: max(1rem, env(safe-area-inset-bottom)); inset-inline-start: 1rem; z-index: 15; min-height: 54px; padding: 0 1.2rem; border-radius: 999px; box-shadow: 0 8px 24px rgba(90,140,25,.35); }

/* ---------- dialogs ---------- */
dialog { border: 0; padding: 0; background: var(--surface); color: var(--ink); border-radius: 20px; width: min(640px, calc(100% - 1.2rem)); max-height: min(92dvh, 900px); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(20,22,16,.55); backdrop-filter: blur(2px); }
.dlg { display: flex; flex-direction: column; max-height: inherit; }
.dlg-h { display: flex; align-items: center; gap: .5rem; padding: .9rem 1.1rem; border-bottom: 1px solid var(--line); }
.dlg-h h2 { margin: 0; font-size: 1.05rem; flex: 1; }
.dlg-b { padding: 1.1rem; overflow-y: auto; }
.dlg-f { display: flex; gap: .6rem; padding: .8rem 1.1rem; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 20px 20px; flex-wrap: wrap; }
.dlg-f .spacer { flex: 1; }
@media (max-width: 640px) { dialog { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 22px 22px 0 0; max-height: 94dvh; } .dlg-f { border-radius: 0; padding-bottom: max(.8rem, env(safe-area-inset-bottom)); } }
.kv { display: grid; grid-template-columns: 7.5rem 1fr; gap: .35rem .8rem; margin: 0; }
.kv dt { color: var(--ink-3); font-size: .85rem; } .kv dd { margin: 0; word-break: break-word; }
.hero { display: grid; grid-template-columns: 120px 1fr; gap: 1rem; margin-bottom: 1rem; }
.hero .thumb { width: 120px; height: 120px; }
.hero h3 { margin: 0 0 .3rem; font-size: 1.1rem; line-height: 1.6; }
.pricebox { background: var(--accent-soft); border-radius: var(--radius-sm); padding: .8rem 1rem; margin: .2rem 0 1rem; }
.pricebox .price { font-size: 1.5rem; }
.pricebox .line { display: flex; justify-content: space-between; gap: 1rem; align-items: baseline; flex-wrap: wrap; }
.hist { list-style: none; padding: 0; margin: .4rem 0 0; }
.hist li { display: flex; justify-content: space-between; gap: .8rem; padding: .45rem 0; border-bottom: 1px dashed var(--line); font-size: .86rem; flex-wrap: wrap; }
.sec-t { font-weight: 800; margin: 1.1rem 0 .3rem; font-size: .95rem; }
.tabs { display: flex; gap: .3rem; margin-bottom: .9rem; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; background: transparent; padding: .55rem .9rem; font-weight: 700; color: var(--ink-3); border-bottom: 3px solid transparent; }
.tabs button.on { color: var(--accent-text); border-bottom-color: var(--accent); }
.ulist { list-style: none; margin: 0; padding: 0; }
.ulist li { display: grid; grid-template-columns: 1fr auto; gap: .5rem; align-items: center; padding: .6rem 0; border-bottom: 1px solid var(--line); }
.feed li { grid-template-columns: 1fr; gap: 0; }
.feed .when { font-size: .78rem; color: var(--ink-3); }
.pill-row { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }

/* ---------- toasts ---------- */
#toasts { position: fixed; inset-inline: 0; inset-block-end: max(5.2rem, env(safe-area-inset-bottom)); z-index: 100; display: flex; flex-direction: column; align-items: center; gap: .5rem; pointer-events: none; padding: 0 1rem; }
.toast { pointer-events: auto; background: #414042; color: #fff; padding: .65rem 1rem; border-radius: 12px; box-shadow: var(--shadow); max-width: 520px; font-size: .92rem; animation: pop .18s ease-out; }
.toast.ok { background: #4a7510; } .toast.bad { background: #a32019; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.spinner { width: 18px; height: 18px; border: 3px solid currentColor; border-inline-end-color: transparent; border-radius: 50%; display: inline-block; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: grid; place-items: center; min-height: 60dvh; gap: 1rem; color: var(--ink-3); }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media print { .topbar, .fab, #toasts, .toolbar { display: none !important; } .card { break-inside: avoid; } }

/* ---------- additions ---------- */
svg[aria-hidden="true"] { width: 1.2em; height: 1.2em; flex: none; }
input[type="search"]::-webkit-search-cancel-button { display: none; }
.dlg-f:empty { display: none; }
.cbody { min-width: 0; }
.pre { white-space: pre-wrap; }
.center { justify-content: center; }
.login-card .btn { width: 100%; }
.login-card .field { margin-bottom: 1rem; }
.lbl-wide { display: none; }
@media (min-width: 560px) { .lbl-wide { display: inline; } }
@media (min-width: 900px) { .chips { flex-wrap: wrap; overflow: visible; } }
.input-sm { min-height: 36px; padding: 0 .6rem; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); max-width: 9.5rem; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .5rem; align-items: center; margin-bottom: .8rem; padding: .7rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.filters select { min-height: 40px; padding: 0 .6rem; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); }
.check { display: flex; align-items: center; gap: .5rem; font-size: .9rem; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.warnbox { background: var(--warn-soft); color: var(--warn); padding: .6rem .8rem; border-radius: var(--radius-sm); margin-bottom: .8rem; }
.hint.bad { color: var(--bad); }
.more-host { text-align: center; min-height: 1px; }
.actions { margin: .9rem 0 .2rem; }
.menu { display: grid; gap: .45rem; margin-bottom: 1rem; }
.menu-item { justify-content: flex-start; width: 100%; }
.photo { display: grid; grid-template-columns: 84px 1fr; gap: .8rem; align-items: center; margin-top: .4rem; padding-top: .9rem; border-top: 1px dashed var(--line); }
.bulk-out { margin-top: .6rem; }
.empty > svg { width: 44px; height: 44px; opacity: .5; }
.hero .pill-row { margin-top: .4rem; }
.pricebox .lbl { color: var(--ink-2); font-size: .88rem; }
.pricebox .line + .line { margin-top: .25rem; }
table.t td .foot { margin: 0; }

.toolbar .count { flex: 1; min-width: 6rem; }
.toolbar .tools { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; width: 100%; }
@media (min-width: 760px) { .toolbar .tools { width: auto; } }
.banner .btn { white-space: nowrap; }
.kv { grid-template-columns: 6rem 1fr; }
.kv dt { padding-top: .1rem; }
