@font-face { font-family: Vazirmatn; src: url(/static/fonts/Vazirmatn-Regular.ttf) format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: Vazirmatn; src: url(/static/fonts/Vazirmatn-Medium.ttf) format("truetype"); font-weight: 500; font-display: swap; }
@font-face { font-family: Vazirmatn; src: url(/static/fonts/Vazirmatn-Bold.ttf) format("truetype"); font-weight: 700; font-display: swap; }

/* light, spreadsheet-style: Excel's green, grey chrome, thin gridlines */
:root {
  --xl-green: #217346;
  --xl-green-dark: #185c37;
  --xl-green-soft: #e3f1e8;
  --xl-select: #c6e0ce;
  --chrome: #f3f3f3;
  --chrome-2: #e9e9e9;
  --grid-line: #e1e1e1;
  --head-line: #c8c8c8;
  --text: #1f1f1f;
  --muted: #6b6b6b;
  --surface: #ffffff;
  --old: #8a8a8a;
  --manual: #d97706;
  --rule: #185c37;
  --up: #b42318; --down: #217346;
  --st-approved: #11632f; --st-approved-bg: #d7efe0;
  --st-confident: #217346; --st-confident-bg: #e6f4ea;
  --st-review: #8a5a00;   --st-review-bg: #fdf0d2;
  --st-notfound: #a3332c; --st-notfound-bg: #fbe3e1;
  --st-nosource: #5f6368; --st-nosource-bg: #eeeeee;
  --row-h: 26px;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--surface); color: var(--text); font: 13px/1.5 Vazirmatn, Tahoma, sans-serif;
  display: grid; grid-template-rows: auto auto auto auto 1fr auto auto; height: 100vh; overflow: hidden;
}
h2 { font-size: 15px; margin: 0; }
code { font-family: Consolas, monospace; background: var(--chrome); padding: 0 4px; border-radius: 3px; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
.num { font-variant-numeric: tabular-nums; }
.error { color: var(--st-notfound); margin: 0; }

/* title bar */
.titlebar { display: flex; align-items: center; gap: 10px; height: 34px; padding: 0 12px; background: var(--xl-green); color: #fff; }
.app-icon { width: 22px; height: 22px; border-radius: 3px; background: #fff; color: var(--xl-green); display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.doc-title { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.titlebar-side { margin-inline-start: auto; display: flex; align-items: center; gap: 10px; font-size: 12px; opacity: .95; }
.tb-btn { font: inherit; font-size: 12px; color: #fff; background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.35); border-radius: 3px; padding: 2px 10px; cursor: pointer; }
.tb-btn:hover { background: rgba(255,255,255,.22); }

/* ribbon */
.ribbon-tabs { display: flex; gap: 2px; padding: 0 8px; background: var(--surface); border-bottom: 1px solid var(--head-line); }
.rtab { font: inherit; font-size: 13px; background: none; border: 0; border-bottom: 3px solid transparent; padding: 6px 14px 4px; cursor: pointer; color: var(--text); }
.rtab:hover { background: var(--chrome); }
.rtab[aria-selected="true"] { color: var(--xl-green); border-bottom-color: var(--xl-green); font-weight: 500; }
.ribbon { display: flex; gap: 0; padding: 6px 6px 0; background: var(--chrome); border-bottom: 1px solid var(--head-line); overflow-x: auto; min-height: 92px; }
.rgroup { display: flex; flex-direction: column; padding: 0 10px; border-inline-end: 1px solid #d6d6d6; flex-shrink: 0; }
.rgroup:last-child { border-inline-end: 0; }
.rgroup.wide-text { flex-shrink: 1; min-width: 260px; max-width: 520px; }
.rgroup-body { display: flex; align-items: center; gap: 8px; flex: 1; }
.rgroup-label { font-size: 11px; color: var(--muted); text-align: center; padding: 2px 0 4px; }
.r-stack { display: flex; flex-direction: column; gap: 3px; }
.r-search { width: 220px; }
.r-note { margin: 0; font-size: 11.5px; color: var(--muted); line-height: 1.6; }
.rbtn, .xbtn { font: inherit; font-size: 12.5px; background: transparent; border: 1px solid transparent; color: var(--text); padding: 3px 8px; border-radius: 3px; cursor: pointer; white-space: nowrap; text-align: start; }
.rbtn:hover, .xbtn:hover { background: #dcdcdc; border-color: #c4c4c4; }
.rbtn.big { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 10px; text-align: center; max-width: 120px; white-space: normal; line-height: 1.3; }
.rbtn .ico { font-size: 20px; color: var(--xl-green); line-height: 1.1; }
.xbtn { border-color: #c4c4c4; background: var(--surface); padding: 4px 12px; }
.xbtn.primary { background: var(--xl-green); border-color: var(--xl-green); color: #fff; }
.xbtn.primary:hover { background: var(--xl-green-dark); }
.xbtn.danger { color: var(--st-notfound); }
.rbtn:disabled, .xbtn:disabled { opacity: .5; cursor: progress; }
.r-check { display: flex; align-items: center; gap: 5px; font-size: 12.5px; cursor: pointer; white-space: nowrap; }
select, input[type="search"], input[type="text"], input[type="number"], .field input, #key-input, .formula-input, textarea {
  font: inherit; font-size: 12.5px; color: var(--text); background: var(--surface); border: 1px solid #c4c4c4; border-radius: 2px; padding: 3px 6px; min-width: 0;
}
select:focus, input:focus, textarea:focus { outline: 1px solid var(--xl-green); border-color: var(--xl-green); }

/* formula bar */
.formula-bar { display: flex; align-items: stretch; gap: 0; border-bottom: 1px solid var(--head-line); background: var(--surface); height: 28px; }
.name-box { width: 90px; border-inline-end: 1px solid var(--head-line); display: grid; place-items: center; font-size: 12px; direction: ltr; }
.fx { width: 34px; display: grid; place-items: center; color: var(--muted); font-style: italic; border-inline-end: 1px solid var(--head-line); }
.formula-input { flex: 1; border: 0; border-radius: 0; padding: 0 8px; }
.formula-input:focus { outline: 0; }

/* sheets */
.sheets { min-height: 0; position: relative; }
.sheet { position: absolute; inset: 0; }
.sheet-split { display: grid; grid-template-columns: 1fr 340px; height: 100%; min-height: 0; }
.rules-split { grid-template-columns: 1fr 400px; }
.plain-wrap { overflow: auto; height: 100%; padding: 0 0 20px; }
.sheet-toolbar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--chrome); border-bottom: 1px solid var(--head-line); position: sticky; top: 0; z-index: 3; }

/* the virtual grid */
.grid { position: relative; overflow: auto; height: 100%; outline: none; background: var(--surface); }
.grid-head { position: sticky; top: 0; z-index: 4; width: max-content; min-width: 100%; }
.g-row { display: grid; grid-template-columns: var(--cols); height: var(--row-h); width: max-content; min-width: 100%; }
.g-letters .g-cell, .g-titles .g-cell, .g-rowhead {
  background: var(--chrome); color: #444; border-inline-end: 1px solid var(--head-line); border-bottom: 1px solid var(--head-line);
  text-align: center; justify-content: center; font-size: 12px; font-weight: 400;
}
.g-titles .g-cell { background: #fafafa; font-weight: 600; color: var(--text); }
.g-letters .g-cell.hl, .g-rowhead.hl { background: var(--xl-select); color: var(--xl-green-dark); border-bottom: 2px solid var(--xl-green); }
.g-rowhead.hl { border-bottom-width: 1px; border-inline-start: 2px solid var(--xl-green); }
.g-cell { display: flex; align-items: center; padding: 0 6px; border-inline-end: 1px solid var(--grid-line); border-bottom: 1px solid var(--grid-line);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12.5px; position: relative; cursor: cell; }
.g-rowhead { position: sticky; inset-inline-start: 0; z-index: 2; display: flex; align-items: center; cursor: default; }
.g-head-corner { position: sticky; inset-inline-start: 0; z-index: 5; }
.grid-canvas { position: relative; width: max-content; min-width: 100%; }
.grid-rows { position: absolute; inset-inline: 0; top: 0; }
.g-cell.n { justify-content: flex-end; direction: ltr; font-variant-numeric: tabular-nums; }
.g-cell.code { direction: ltr; justify-content: flex-end; font-variant-numeric: tabular-nums; }
.g-cell.price { font-weight: 600; }
.g-cell.old { color: var(--old); font-weight: 400; }
.g-cell.ruled { color: var(--rule); }
.g-cell.manual::after { content: ""; position: absolute; top: 0; inset-inline-start: 0; border-style: solid; border-width: 0 7px 7px 0;
  border-color: transparent var(--manual) transparent transparent; }
[dir="rtl"] .g-cell.manual::after { border-width: 7px 7px 0 0; border-color: var(--manual) transparent transparent transparent; }
.g-cell.sel { background: var(--xl-green-soft); }
.g-cell.active { outline: 2px solid var(--xl-green); outline-offset: -2px; background: var(--surface); z-index: 1; }
.g-cell .delta { font-size: 11px; margin-inline-start: 6px; }
.delta.up { color: var(--up); } .delta.down { color: var(--down); }
.badge { display: inline-block; font-size: 11.5px; padding: 0 7px; border-radius: 2px; color: var(--fg); background: var(--bgc); line-height: 18px; }
.cell-editor { position: absolute; z-index: 6; border: 2px solid var(--xl-green); font: inherit; font-size: 12.5px; font-weight: 600; padding: 0 5px; direction: ltr; text-align: right; background: #fff; outline: none; }
.grid-empty { padding: 30px; text-align: center; color: var(--muted); }

/* task pane */
.pane { border-inline-start: 1px solid var(--head-line); background: #fbfbfb; overflow: auto; padding: 12px; min-width: 0; }
.pane-empty { color: var(--muted); padding: 20px 4px; }
.pane h3 { margin: 0 0 2px; font-size: 14px; }
.pane .sub { color: var(--muted); font-size: 12px; margin-bottom: 10px; direction: ltr; text-align: right; }
.pane section { border-top: 1px solid var(--grid-line); padding: 10px 0; }
.pane section > b { display: block; font-size: 12.5px; margin-bottom: 6px; color: var(--xl-green-dark); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 12.5px; }
.kv span:nth-child(odd) { color: var(--muted); }
.steps { margin: 0; padding: 0; list-style: none; font-size: 12.5px; }
.steps li { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; border-bottom: 1px dashed var(--grid-line); }
.steps li.final { font-weight: 700; border-bottom: 0; }
.inline-form { display: flex; gap: 6px; margin-top: 6px; }
.inline-form input { flex: 1; direction: ltr; text-align: right; }
.reasons { margin: 4px 0 0; padding-inline-start: 18px; font-size: 12.5px; }
.cand { border: 1px solid var(--grid-line); background: #fff; padding: 6px 8px; margin-top: 6px; font-size: 12.5px; display: grid; gap: 4px; }
.cand.current { border-color: var(--xl-green); }
.cand .meta { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12px; align-items: center; }

/* plain sheets: rules, log, lists */
.xl-table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
.xl-table th { position: sticky; top: 41px; background: #fafafa; font-weight: 600; border: 1px solid var(--head-line); padding: 4px 8px; text-align: right; z-index: 2; white-space: nowrap; }
.xl-table td { border: 1px solid var(--grid-line); padding: 3px 8px; vertical-align: middle; }
.xl-table td.n { text-align: left; direction: ltr; font-variant-numeric: tabular-nums; }
.xl-table tr:hover td { background: #f7fbf8; }
.xl-table tr.editing td { background: var(--xl-green-soft); }
.xl-table .empty { text-align: center; color: var(--muted); padding: 24px; }
.table-scroll { max-height: 280px; overflow: auto; border: 1px solid var(--grid-line); }
.table-scroll .xl-table th { top: 0; }

.rule-pane h3 { margin: 0 0 8px; font-size: 14px; }
.rf { display: grid; gap: 4px; margin-bottom: 10px; }
.rf > span { font-size: 12px; color: var(--muted); }
.rf-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.rf-row > * { flex: 1; min-width: 0; }
.rf-row .r-check { flex: 0 0 auto; }
.seg { display: flex; border: 1px solid #c4c4c4; border-radius: 2px; overflow: hidden; }
.seg button { font: inherit; font-size: 12.5px; flex: 1; border: 0; background: #fff; padding: 4px 6px; cursor: pointer; }
.seg button + button { border-inline-start: 1px solid #c4c4c4; }
.seg button[aria-pressed="true"] { background: var(--xl-green); color: #fff; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; }
.tag { font-size: 12px; background: var(--xl-green-soft); border: 1px solid #b9dcc5; padding: 0 6px; border-radius: 2px; display: inline-flex; gap: 4px; align-items: center; }
.tag button { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0; font-size: 13px; line-height: 1; }
.impact { background: #fff; border: 1px solid var(--grid-line); padding: 8px; margin: 8px 0; font-size: 12.5px; }
.impact b { color: var(--xl-green-dark); }
.rule-actions { display: flex; gap: 6px; justify-content: flex-start; margin-top: 8px; flex-wrap: wrap; }
/* the rule's impact and its save button stay in view while the form scrolls */
.rule-footer { position: sticky; bottom: -12px; margin: 0 -12px -12px; padding: 4px 12px 12px; background: #fbfbfb; border-top: 1px solid var(--grid-line); }
.rule-footer .impact { max-height: 260px; overflow: auto; }

.lists-wrap { display: grid; grid-template-columns: 1fr 1fr; gap: 0; align-content: start; }
.lists-col { min-width: 0; border-inline-end: 1px solid var(--grid-line); }
.lists { display: grid; gap: 8px; padding: 10px 12px; }
.list-card { border: 1px solid var(--grid-line); padding: 10px; background: #fff; }
.list-card .t { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.list-card .meta { color: var(--muted); font-size: 12px; margin: 2px 0 8px; overflow-wrap: anywhere; }
.bar { display: flex; height: 8px; overflow: hidden; background: var(--grid-line); }
.bar span { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 8px; height: 8px; margin-inline-end: 4px; }
.upload { display: grid; gap: 8px; padding: 10px 12px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.field { display: grid; gap: 3px; font-size: 12px; color: var(--muted); }
.drop { display: grid; place-items: center; text-align: center; border: 1.5px dashed #b5b5b5; padding: 16px 10px; cursor: pointer; background: #fafafa; color: var(--muted); }
.drop:hover, .drop.over { border-color: var(--xl-green); color: var(--text); }
.drop.has-file { border-style: solid; border-color: var(--xl-green); color: var(--text); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.hint { margin: 0; font-size: 12px; color: var(--muted); }
.job { padding: 8px 10px; font-size: 12.5px; background: var(--xl-green-soft); border: 1px solid #b9dcc5; }
.job.failed { background: var(--st-notfound-bg); color: var(--st-notfound); border-color: #f1c3bf; }
.job.done { color: var(--xl-green-dark); }
#uploads { padding: 6px 12px; }
#uploads table { width: 100%; border-collapse: collapse; font-size: 12px; table-layout: fixed; }
#uploads td { padding: 4px; border-bottom: 1px solid var(--grid-line); overflow-wrap: anywhere; }
#uploads td:nth-child(1) { width: 26%; } #uploads td:nth-child(2) { width: 20%; } #uploads td:nth-child(3) { width: 16%; }
.spinner { display: inline-block; width: 11px; height: 11px; border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -1px; margin-inline-end: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* sheet tabs and status bar */
.sheet-tabs { display: flex; gap: 0; background: var(--chrome); border-top: 1px solid var(--head-line); padding: 0 8px; overflow-x: auto; }
.stab { font: inherit; font-size: 12.5px; border: 0; border-inline-end: 1px solid #d6d6d6; background: transparent; padding: 4px 16px; cursor: pointer; color: var(--text); white-space: nowrap; }
.stab:hover { background: #e2e2e2; }
.stab[aria-selected="true"] { background: #fff; color: var(--xl-green); font-weight: 600; box-shadow: inset 0 -3px 0 var(--xl-green); }
.statusbar { display: flex; align-items: center; gap: 14px; padding: 0 12px; height: 24px; font-size: 12px; background: var(--chrome); border-top: 1px solid #d6d6d6; color: #444; white-space: nowrap; overflow: hidden; }
.status-counts { display: flex; gap: 10px; overflow: hidden; }
.status-counts button { font: inherit; font-size: 12px; background: none; border: 0; padding: 0 2px; cursor: pointer; color: #444; }
.status-counts button:hover, .status-counts button[aria-pressed="true"] { color: var(--xl-green); text-decoration: underline; }

/* dialogs */
dialog { border: 1px solid var(--head-line); border-radius: 4px; padding: 16px; background: #fff; color: var(--text); width: min(420px, 94vw); box-shadow: 0 8px 30px rgba(0,0,0,.18); }
dialog::backdrop { background: rgba(0,0,0,.25); }
dialog.wide { width: min(980px, 96vw); max-height: 92vh; overflow: auto; }
#login-form, #map-form, #brand-form { display: grid; gap: 10px; }
#login-dialog { width: min(380px, 94vw); }
#who { font-weight: 500; }
#users-table td:last-child { width: 1%; white-space: nowrap; }
.dialog-actions { display: flex; justify-content: flex-start; gap: 8px; }
.map-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.map-cols { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 6px; }
.map-col { border: 1px solid var(--grid-line); padding: 6px 8px; background: #fafafa; display: grid; gap: 5px; min-width: 0; }
.map-col.req { border-color: var(--xl-green); }
.map-col .lbl { font-weight: 600; font-size: 12.5px; overflow-wrap: anywhere; }
.map-col .lbl.empty { color: var(--muted); font-weight: 400; }
.map-col ul { margin: 0; padding: 0; list-style: none; font-size: 12px; color: var(--muted); }
.map-col li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.map-row { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; }
.map-brands { display: grid; gap: 6px; border-top: 1px solid var(--grid-line); padding-top: 8px; }
.brand-add { display: flex; gap: 6px; }
.brand-add input { flex: 1; font: inherit; border: 1px solid #c4c4c4; padding: 3px 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font: inherit; font-size: 12px; border: 1px solid #c4c4c4; background: #fff; padding: 2px 8px; cursor: pointer; border-radius: 2px; }
.chip[aria-pressed="true"] { background: var(--xl-green); border-color: var(--xl-green); color: #fff; }
.chip .n, .tag .n { opacity: .8; font-size: 11px; margin-inline-start: 6px; }
.brand-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; width: 100%; }
#brand-chips { flex-direction: column; align-items: stretch; gap: 6px; }
.tag.chosen { background: var(--xl-green); color: #fff; border-color: var(--xl-green); font-size: 12.5px; padding: 2px 8px; }
.tag.chosen button { color: #fff; font-size: 15px; }
.no-brand { background: var(--st-review-bg); border: 1px solid #f0d9a4; padding: 8px 10px; font-size: 12.5px; margin: 4px 0 8px; line-height: 1.9; }
.map-status { font-size: 12.5px; }
.map-status.err { color: var(--st-notfound); }

.toast { position: fixed; bottom: 40px; inset-inline-start: 50%; transform: translateX(50%) translateY(16px); opacity: 0; background: #323232; color: #fff;
  padding: 8px 14px; border-radius: 3px; font-size: 12.5px; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 20; max-width: 90vw; }
.toast.show { opacity: 1; transform: translateX(50%) translateY(0); }

@media (max-width: 900px) {
  .sheet-split, .rules-split { grid-template-columns: 1fr; grid-template-rows: 1fr 40%; }
  .pane { border-inline-start: 0; border-top: 1px solid var(--head-line); }
  .lists-wrap { grid-template-columns: 1fr; }
  .rgroup.wide-text { display: none; }
}
@media (max-width: 600px) {
  .r-search { width: 150px; }
  .titlebar-side #updated { display: none; }
  .field-row { grid-template-columns: 1fr; }
  .status-counts { display: none; }
}
