/* پنل مدیریت محصولات — بدون وابستگی خارجی */
@font-face {
  font-family: "Vazirmatn";
  src: url("/static/fonts/Vazirmatn-Variable.woff2") format("woff2-variations"),
       url("/static/fonts/Vazirmatn-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #f4f6f9; --surface: #ffffff; --surface-2: #f2f4f8; --surface-3: #e6eaf0; --border: #e2e6ed;
  --text: #18202e; --muted: #64708a;
  --primary: #2f5bea; --primary-ink: #ffffff; --primary-soft: #e9efff;
  --ok: #138a59; --ok-soft: #e3f5ec; --warn: #a96500; --warn-soft: #fff2d9; --err: #c62f3a; --err-soft: #fde7e9;
  --info: #0a6fa6; --info-soft: #e0f1fb; --violet: #7c3aed; --violet-soft: #f1e9ff; --neutral-soft: #eceef2;
  --radius: 12px; --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .07);
  --shadow-lg: 0 8px 28px rgba(16, 24, 40, .14);
  --font: "Vazirmatn", Tahoma, "Segoe UI", sans-serif;
  --sidebar: 232px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11141a; --surface: #191d25; --surface-2: #20252f; --surface-3: #2b313d; --border: #2c3240;
    --text: #e6e9ef; --muted: #98a1b3; --primary: #6d8dff; --primary-ink: #0d1020; --primary-soft: #222b48;
    --ok: #4cc38a; --ok-soft: #173326; --warn: #f0b04a; --warn-soft: #3a2c12; --err: #ff6b72; --err-soft: #3d1c20;
    --info: #5cbcf0; --info-soft: #14303f; --violet: #c4a5ff; --violet-soft: #2e2147; --neutral-soft: #2a303c;
    --shadow: none; --shadow-lg: 0 8px 28px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.7 var(--font); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
small { color: var(--muted); }
h1, h2, h3 { line-height: 1.4; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.ltr { direction: ltr; unicode-bidi: embed; }
.muted { color: var(--muted); }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 16px; }
.stack-sm > * + * { margin-top: 8px; }
.stack-sm:empty { display: none; }

/* ------------------------------------------------------------ app shell */
.shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: 4px;
  background: var(--surface); border-inline-end: 1px solid var(--border); padding: 16px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 16px; }
.brand b { display: block; font-size: 15px; }
.brand small { display: block; font-size: 12px; line-height: 1.4; }
.sidebar .brand small { direction: ltr; text-align: right; }
.brand-mark { flex: none; width: 36px; height: 36px; border-radius: 10px; background: var(--primary); color: var(--primary-ink);
  display: grid; place-items: center; font-weight: 800; font-size: 18px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; border: 0; border-radius: 10px;
  background: transparent; color: var(--muted); font: inherit; text-align: start; cursor: pointer; white-space: nowrap;
}
.nav-item svg { width: 19px; height: 19px; flex: none; }
.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.nav-item .count { margin-inline-start: auto; min-width: 22px; padding: 0 7px; border-radius: 99px; font-size: 12px;
  font-weight: 700; text-align: center; background: var(--warn-soft); color: var(--warn); }
.sidebar-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }
.main { min-width: 0; padding: 24px 28px 72px; }
.page { max-width: 1200px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px 20px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { font-size: 21px; margin: 0; }
.page-head p { margin: 2px 0 0; color: var(--muted); max-width: 720px; }
.page > * + * { margin-top: 16px; }
.page > .page-head + * { margin-top: 0; }

/* running job banner */
.banner {
  max-width: 1200px; margin: 0 auto 18px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 14px; border-radius: var(--radius); background: var(--warn-soft); color: var(--warn);
}
.banner b { color: inherit; }
.banner .progress { flex: 1; min-width: 120px; max-width: 280px; background: rgba(255, 255, 255, .55); }
.banner .progress > div { background: var(--warn); }

/* ------------------------------------------------------------ cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card h2 { font-size: 15.5px; margin: 0; }
.card h3 { font-size: 14px; margin: 0 0 6px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.card-head p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.subhead { margin: 18px 0 2px !important; font-size: 13px !important; color: var(--muted); }
.grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); align-items: start; }
.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.stat { padding: 14px 16px; }
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-size: 23px; font-weight: 800; margin-top: 2px; }
.stat .hint { font-size: 12px; color: var(--muted); }
.c-ok { color: var(--ok); } .c-err { color: var(--err); } .c-warn { color: var(--warn); }

/* automation facts */
.facts { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.fact { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; min-width: 0; }
.fact .k { font-size: 12px; color: var(--muted); }
.fact .v { font-weight: 700; font-size: 15px; }
.fact .s { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
#ovAlerts { margin-top: 12px; }

/* status pill */
.pill { display: inline-flex; align-items: center; gap: 7px; padding: 2px 11px; border-radius: 99px; font-size: 12.5px; font-weight: 700; white-space: nowrap; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill-ok { background: var(--ok-soft); color: var(--ok); }
.pill-info { background: var(--info-soft); color: var(--info); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-err { background: var(--err-soft); color: var(--err); }
.pill-off { background: var(--neutral-soft); color: var(--muted); }

/* to-do list */
.todo { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.todo:first-child { padding-top: 0; }
.todo:last-child { border-bottom: 0; padding-bottom: 0; }
.todo .n { flex: none; min-width: 46px; height: 46px; padding: 0 6px; border-radius: 12px; display: grid; place-items: center; font-weight: 800; font-size: 16px; }
.todo .t { flex: 1; min-width: 0; }
.todo .t b { display: block; }
.todo .t small { display: block; line-height: 1.5; }
.n-create { background: var(--info-soft); color: var(--info); }
.n-rename { background: var(--violet-soft); color: var(--violet); }
.n-price { background: var(--primary-soft); color: var(--primary); }
.n-cart { background: var(--warn-soft); color: var(--warn); }
.all-good { display: flex; align-items: center; gap: 10px; color: var(--ok); font-weight: 600; }

/* recent jobs list */
.jobline { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.jobline:first-child { padding-top: 0; }
.jobline:last-child { border-bottom: 0; padding-bottom: 0; }
.jobline:hover .jl-title { color: var(--primary); }
.jl-title { font-weight: 600; }
.mini { display: inline-block; font-size: 11.5px; padding: 0 7px; border-radius: 6px; background: var(--surface-2); color: var(--muted); margin-inline-end: 4px; white-space: nowrap; }
.mini-err { background: var(--err-soft); color: var(--err); }

/* ------------------------------------------------------------ buttons & inputs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); padding: 7px 14px; border-radius: 9px; font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover:not(:disabled) { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 700; }
.btn-primary:hover:not(:disabled) { background: var(--primary); filter: brightness(1.08); }
.btn-danger { color: var(--err); border-color: var(--err); }
.btn-sm { padding: 3px 11px; font-size: 12.5px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-link { border: 0; background: none; color: var(--primary); padding: 0 2px; cursor: pointer; font: inherit; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 7px 10px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { width: 100%; min-height: 80px; direction: ltr; }
.input-wide { width: 100%; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.field input, .field select { color: var(--text); }
.fields { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }

/* toggle switch */
input.toggle { appearance: none; -webkit-appearance: none; position: relative; flex: none; width: 40px; height: 23px; padding: 0; margin: 0;
  border: 0; border-radius: 99px; background: var(--surface-3); cursor: pointer; transition: background .15s; }
input.toggle::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 17px; height: 17px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: inset-inline-start .15s; }
input.toggle:checked { background: var(--primary); }
input.toggle:checked::after { inset-inline-start: 20px; }
input.toggle:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* settings rows */
.setting { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 12px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.setting:last-child { border-bottom: 0; padding-bottom: 0; }
.setting > span { flex: 1; min-width: 0; }
.setting > span b { display: block; font-weight: 600; }
.setting > span small { display: block; line-height: 1.6; }
.setting input[type=number], .setting select { width: 110px; flex: none; }
.setting.disabled { opacity: .5; }
.savebar { position: sticky; bottom: 16px; z-index: 15; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--primary); border-radius: var(--radius); padding: 10px 14px; box-shadow: var(--shadow-lg); }

/* segmented control */
.segmented { display: inline-flex; gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface-3); flex-wrap: wrap; }
.segmented button { border: 0; background: transparent; color: var(--muted); padding: 6px 14px; border-radius: 9px; font: inherit; cursor: pointer; }
.segmented button:hover { color: var(--text); }
.segmented button.active { background: var(--surface); color: var(--text); font-weight: 700; box-shadow: var(--shadow); }

/* dropzone */
.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 28px 16px; text-align: center; cursor: pointer; transition: .15s; }
.dropzone:hover, .dropzone.drag { border-color: var(--primary); background: var(--primary-soft); }
.dropzone svg { width: 34px; height: 34px; color: var(--primary); }
.dropzone b { display: block; font-size: 15px; }
.opts { margin-top: 6px; }

/* collapsible */
details.details { border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; margin-top: 14px; }
details.details summary { cursor: pointer; font-weight: 600; }
details.details[open] summary { margin-bottom: 8px; }

/* ------------------------------------------------------------ chips, badges, filters */
.badge { display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-create { background: var(--info-soft); color: var(--info); }
.b-rename { background: var(--violet-soft); color: var(--violet); }
.b-restock, .b-success, .b-finished, .b-auto { background: var(--ok-soft); color: var(--ok); }
.b-update_price { background: var(--primary-soft); color: var(--primary); }
.b-make_oos, .b-error, .b-failed { background: var(--err-soft); color: var(--err); }
.b-skip, .b-skipped, .b-cancelled, .b-queued, .b-neutral { background: var(--neutral-soft); color: var(--muted); }
.b-running, .b-warn { background: var(--warn-soft); color: var(--warn); }
.rename-box { margin-top: 6px; padding: 6px 8px; border-inline-start: 3px solid var(--violet); background: var(--surface-2); border-radius: 6px; }
.old-title { text-decoration: line-through; color: var(--muted); font-size: 12.5px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 99px; padding: 0 8px; font-size: 12px; margin: 2px; }
.chip button { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0; font-size: 14px; line-height: 1; }
.chip button:hover { color: var(--err); }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filter { border: 1px solid var(--border); background: var(--surface); border-radius: 99px; padding: 3px 12px; font: inherit; font-size: 13px; cursor: pointer; color: var(--muted); }
.filter:hover { color: var(--text); }
.filter.active { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); font-weight: 700; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin: 12px 0; }
.toolbar input { min-width: 240px; }

/* ------------------------------------------------------------ table */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
.table-wrap.tall { max-height: 620px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 9px 10px; text-align: right; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--surface-2); font-weight: 700; color: var(--muted); position: sticky; top: 0; z-index: 1; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
tr.is-auto td { opacity: .65; }
td.title { min-width: 260px; max-width: 480px; }
td .sub { color: var(--muted); font-size: 12px; }
td.empty { text-align: center; color: var(--muted); padding: 28px; }
.thumb { width: 42px; height: 42px; border-radius: 7px; object-fit: cover; background: var(--surface-2); border: 1px solid var(--border); flex: none; }
.price-from { color: var(--muted); font-size: 12px; }
td.price { white-space: nowrap; }
.pager { display: flex; gap: 6px; align-items: center; justify-content: center; margin-top: 12px; }
.pager:empty { display: none; }

/* sticky action bar (preview) */
.actionbar { position: sticky; bottom: 16px; z-index: 15; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; box-shadow: var(--shadow-lg); }

/* progress */
.progress { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--primary); width: 0; transition: width .3s; }

/* alerts & toast */
.alert { border-radius: 9px; padding: 9px 12px; font-size: 13px; }
.alert-error { background: var(--err-soft); color: var(--err); }
.alert-warn { background: var(--warn-soft); color: var(--warn); }
.alert-info { background: var(--info-soft); color: var(--info); }
.alert-ok { background: var(--ok-soft); color: var(--ok); }
.toast { position: fixed; bottom: 18px; inset-inline-start: 18px; z-index: 60; max-width: 420px; box-shadow: var(--shadow-lg); }
.empty-state { text-align: center; color: var(--muted); padding: 26px 10px; }

/* rules editor */
.rule-row { display: grid; grid-template-columns: 1fr 1.5fr auto; gap: 8px; margin-bottom: 6px; }

/* login */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; padding: 24px; }

/* ------------------------------------------------------------ responsive */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 30; height: auto; flex-direction: row; align-items: center; gap: 6px;
    padding: 8px 10px; border-inline-end: 0; border-bottom: 1px solid var(--border); overflow-x: auto; overflow-y: hidden; }
  .sidebar .brand { padding: 0 4px 0 8px; }
  .sidebar .brand div { display: none; }
  .nav { flex-direction: row; gap: 2px; }
  .nav-item { width: auto; padding: 7px 10px; }
  .nav-item .count { margin-inline-start: 4px; }
  .sidebar-foot { margin: 0; padding: 0; border: 0; margin-inline-start: auto; }
  .sidebar-foot .label { display: none; }
  .main { padding: 16px 14px 64px; }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .rule-row { grid-template-columns: 1fr; }
  td.title { min-width: 200px; }
  .toolbar input { min-width: 0; width: 100%; }
  .setting { align-items: flex-start; }
}
