@font-face {
  font-display: swap;
  font-family: "Vazirmatn";
  font-style: normal;
  font-weight: 400;
  src: url("/static/fonts/vazirmatn-400.woff2") format("woff2");
}
@font-face {
  font-display: swap;
  font-family: "Vazirmatn";
  font-style: normal;
  font-weight: 700;
  src: url("/static/fonts/vazirmatn-700.woff2") format("woff2");
}

:root {
  --ink: #16242e;
  --deep: #0f3d5c;
  --deep-hover: #164e73;
  --teal: #1b8a8f;
  --saffron: #c97b24;
  --paper: #f2f5f7;
  --card: #ffffff;
  --line: #d9e2e8;
  --muted: #5e7280;
  --success: #2e7d5b;
  --danger: #b3453a;
  --shadow: 0 12px 34px rgba(15, 61, 92, 0.08);
  --shadow-hover: 0 18px 42px rgba(15, 61, 92, 0.12);
  --topbar-height: 72px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(circle at 85% 0, rgba(27, 138, 143, .08), transparent 28rem), var(--paper);
  color: var(--ink);
  font-family: "Vazirmatn", Tahoma, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.65;
}
button, input, select { color: inherit; font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
:focus-visible { outline: 3px solid rgba(27, 138, 143, .35); outline-offset: 2px; }
.hidden { display: none !important; }

.topbar {
  align-items: center;
  background: linear-gradient(110deg, #0b344f, var(--deep) 55%, #145b69);
  box-shadow: 0 6px 22px rgba(7, 36, 55, .18);
  color: #fff;
  display: flex;
  gap: 20px;
  justify-content: space-between;
  padding: 14px 22px;
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar h1 { font-size: 18px; margin: 0; }
.topbar span { color: #d3e2ea; display: block; font-size: 12px; margin-top: 1px; }
.brand-lockup { align-items: center; display: flex; gap: 11px; }
.brand-symbol { align-items: center; background: rgba(255, 255, 255, .14); border: 1px solid rgba(255, 255, 255, .22); border-radius: 11px; color: #fff !important; display: inline-flex !important; flex: 0 0 42px; font-size: 20px !important; font-weight: 700; height: 42px; justify-content: center; margin: 0 !important; }
.top-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.button { align-items: center; border: 0; border-radius: 9px; display: inline-flex; font-weight: 700; justify-content: center; min-height: 38px; padding: 8px 16px; text-decoration: none; transition: background .16s ease, box-shadow .16s ease, transform .16s ease; }
.button:not(:disabled):active { transform: translateY(1px); }
.button.primary { background: var(--deep); color: #fff; }
.button.primary:hover { background: var(--deep-hover); box-shadow: 0 8px 20px rgba(15, 61, 92, .18); }
.button.outline { background: #fff; border: 1px solid #c7d8df; color: var(--deep); font-size: 11px; min-height: 34px; }
.button.outline:hover { background: #edf5f6; border-color: #9fbdc8; }
.button.subtle { background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.24); color: #fff; }
.button.subtle:hover { background: rgba(255,255,255,.2); }
.button.danger-subtle { background: transparent; border: 1px solid rgba(255,255,255,.24); color: #ffd9d5; }
.button.full { width: 100%; }

.page-shell { align-items: start; display: grid; gap: 20px; grid-template-columns: 296px minmax(0, 1fr); margin: 0 auto; max-width: 1680px; padding: 20px; }
.filters { background: rgba(255, 255, 255, .96); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); max-height: calc(100vh - var(--topbar-height) - 30px); overflow: auto; position: sticky; top: calc(var(--topbar-height) + 16px); }
.panel-heading, .section-title { align-items: center; border-bottom: 1px solid var(--line); display: flex; gap: 10px; justify-content: space-between; padding: 11px 14px; }
.panel-heading { background: #f8fafb; border-radius: 14px 14px 0 0; position: sticky; top: 0; z-index: 2; }
.panel-heading strong { font-size: 15px; }
.link-button { background: none; border: 0; color: var(--teal); font-size: 12px; padding: 2px 4px; }
fieldset { border: 0; margin: 0; padding: 0; }
.filter-group { border-bottom: 1px solid var(--line); padding: 12px 14px; }
.filter-group:last-child { border-bottom: 0; }
.filter-group > label:first-child { color: var(--muted); display: block; font-size: 12px; margin-bottom: 7px; }
.filter-group input[type="text"], .filter-group input:not([type]), .filter-group select, .date-input, .search-input, select {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px;
  min-height: 36px;
  padding: 6px 9px;
  width: 100%;
}
.two-columns { display: grid; gap: 8px; grid-template-columns: 1fr 1fr; }
.date-input { direction: ltr; text-align: center; }
.filter-group small { color: var(--muted); display: block; font-size: 10px; margin-top: 5px; }
.checkbox-line { align-items: center; display: flex; gap: 7px; margin-top: 9px; }
.checkbox-line input, .check-list input { accent-color: var(--deep); }
.search-input { margin-bottom: 6px; }
.check-list { background: #fbfcfd; border: 1px solid var(--line); border-radius: 7px; max-height: 178px; overflow: auto; padding: 4px 6px; }
.check-list label { align-items: center; border-radius: 5px; display: flex; gap: 7px; padding: 3px 2px; }
.check-list label:hover { background: #edf3f6; }
.check-list .count { color: var(--muted); direction: ltr; font-size: 10px; margin-right: auto; }
.list-actions { display: flex; gap: 6px; margin-top: 6px; }
.list-actions button { background: #eef3f6; border: 1px solid var(--line); border-radius: 5px; color: var(--muted); flex: 1; font-size: 11px; padding: 3px; }

.dashboard-main, .dashboard, .tab-panel { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.tab-panel[hidden] { display: none; }
.dashboard-toolbar { display: flex; flex-direction: column; align-items: center; gap: 9px; position: sticky; top: calc(var(--topbar-height) + 10px); z-index: 20; }
.dashboard-tabs { align-items: center; background: rgba(255, 255, 255, .94); border: 1px solid var(--line); border-radius: 13px; box-shadow: var(--shadow); display: grid; gap: 5px; grid-template-columns: repeat(4, minmax(120px, 1fr)); padding: 5px; width: min(760px, 100%); }
.dashboard-tab { align-items: center; background: transparent; border: 0; border-radius: 9px; color: var(--muted); display: flex; font-size: 12px; font-weight: 700; gap: 7px; justify-content: center; min-height: 42px; padding: 7px 12px; transition: background .16s ease, color .16s ease, box-shadow .16s ease; }
.dashboard-tab span { font-size: 17px; line-height: 1; }
.dashboard-tab:hover { background: #edf4f6; color: var(--deep); }
.dashboard-tab.active { background: var(--deep); box-shadow: 0 6px 16px rgba(15, 61, 92, .2); color: #fff; }
.active-filters { align-items: center; background: rgba(255, 255, 255, .96); border: 1px solid var(--line); border-radius: 11px; box-shadow: var(--shadow); display: flex; flex-wrap: wrap; gap: 7px; padding: 8px 12px; width: 100%; }
.filter-chip-title { color: var(--muted); font-size: 11px; font-weight: 700; }
.filter-chip { align-items: center; background: #eaf2f4; border: 1px solid #cfe0e5; border-radius: 99px; color: var(--deep); display: inline-flex; font-size: 11px; gap: 4px; padding: 3px 5px 3px 10px; }
.filter-chip-remove { background: rgba(15, 61, 92, .09); border: 0; border-radius: 50%; color: var(--deep); font-size: 13px; height: 17px; line-height: 1; padding: 0; width: 17px; }
.filter-chip-remove:hover { background: var(--danger); color: #fff; }
.filter-chip-clear { background: none; border: 0; color: var(--teal); font-size: 11px; font-weight: 700; margin-right: auto; padding: 2px 6px; text-decoration: underline; }
.section-intro { align-items: end; background: linear-gradient(120deg, rgba(15, 61, 92, .06), rgba(27, 138, 143, .08)); border: 1px solid rgba(15, 61, 92, .09); border-radius: 13px; display: flex; gap: 20px; justify-content: space-between; padding: 18px 20px; }
.section-intro h2 { font-size: 19px; margin: 1px 0 0; }
.section-intro p { color: var(--muted); margin: 0; max-width: 480px; }
.eyebrow { color: var(--teal); display: block; font-size: 10px; font-weight: 700; letter-spacing: .03em; }
.upload-card, .section-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.upload-card { border-style: dashed; padding: 28px; text-align: center; transition: .15s ease; }
.upload-card.dragging { background: #eff7f7; border-color: var(--teal); }
.upload-card h2 { font-size: 16px; margin: 5px 0; }
.upload-card p { color: var(--muted); margin: 0 auto 14px; max-width: 680px; }
.upload-icon { align-items: center; background: #e7f2f3; border-radius: 50%; color: var(--teal); display: inline-flex; font-size: 23px; height: 44px; justify-content: center; width: 44px; }
.upload-card.has-dataset { align-items: center; border-style: solid; display: grid; gap: 14px; grid-template-columns: auto minmax(0, 1fr) auto; padding: 14px 18px; text-align: right; }
.upload-card.has-dataset .upload-copy h2 { margin: 0; }
.upload-card.has-dataset .upload-copy p { margin: 1px 0 0; }
.upload-card.has-dataset .status { grid-column: 2 / -1; min-height: 0; padding: 0; }
.upload-card.has-dataset .progress { grid-column: 1 / -1; margin-top: 0; width: 100%; }
.status { color: var(--muted); min-height: 24px; padding-top: 8px; }
.progress { background: #e3ebf0; border-radius: 99px; height: 5px; margin-top: 14px; overflow: hidden; }
.progress i { animation: slide 1.1s infinite ease-in-out; background: var(--teal); display: block; height: 100%; width: 30%; }
@keyframes slide { from { margin-right: -30%; } to { margin-right: 100%; } }
.error-box, .form-error { background: #fdf2f1; border: 1px solid #e9c3be; border-radius: 8px; color: #8c332a; padding: 10px 14px; }

.section-title h2 { font-size: 14px; margin: 0; }
.pill { background: #e9f1f4; border: 1px solid #d9e5e9; border-radius: 99px; color: var(--muted); font-size: 11px; padding: 3px 10px; white-space: nowrap; }
.management-overview { background: linear-gradient(135deg, #f9fbfc, #eaf2f4); border: 1px solid #d5e2e7; border-radius: 15px; box-shadow: var(--shadow); padding: 18px; }
.overview-heading { align-items: center; display: flex; gap: 14px; justify-content: space-between; margin-bottom: 13px; }
.overview-heading h2 { font-size: 17px; margin: 0; }
.overview-heading p { color: var(--muted); font-size: 11px; margin: 1px 0 0; }
.kpi-grid { display: grid; gap: 11px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 15px; }
.kpi-head { align-items: center; display: flex; gap: 7px; }
.kpi-dot { background: var(--muted); border-radius: 50%; flex: 0 0 8px; height: 8px; width: 8px; }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { color: var(--ink); direction: ltr; font-size: 26px; font-weight: 700; line-height: 1.25; margin: 7px 0 2px; text-align: right; }
.kpi .detail { color: var(--muted); font-size: 11px; }
.kpi.buyers-kpi .kpi-dot { background: #2a78d6; }
.kpi.average-kpi .kpi-dot { background: #4a3aa7; }
.kpi.delivery-kpi .kpi-dot { background: #0ca30c; }
.kpi.cancellation-kpi .kpi-dot { background: #d03b3b; }
/* Exactly one hero figure per view - the number the dashboard leads with. */
.kpi.is-hero { background: linear-gradient(115deg, #0b344f, var(--deep) 60%, #145b69); border-color: transparent; grid-column: 1 / -1; padding: 20px 22px; }
.kpi.is-hero .kpi-dot { background: rgba(255, 255, 255, .55); }
.kpi.is-hero .label { color: #d3e2ea; font-size: 13px; }
.kpi.is-hero .value { color: #fff; font-size: 48px; margin: 4px 0 3px; }
.kpi.is-hero .detail { color: #cbdce6; font-size: 12px; }
.mini-kpis { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.section-card > .mini-kpis { padding: 12px; }
.mini-kpi { background: var(--card); border: 1px solid var(--line); border-radius: 9px; min-height: 80px; padding: 12px 13px; }
.data-input-tools { align-items: center; display: flex; flex-wrap: wrap; gap: 8px; }
.quality-badge { align-items: baseline; border-radius: 99px; display: inline-flex; font-size: 11px; gap: 5px; padding: 3px 11px; }
.quality-badge strong { direction: ltr; font-size: 13px; }
.quality-badge.is-clean { background: #eaf6ef; color: var(--success); }
.quality-badge.needs-review { background: #fff4e7; color: #9c5b12; }
.quality-details { display: grid; gap: 12px; padding: 14px 16px 16px; }
.quality-actions { display: flex; }
.quality-summary { align-items: center; display: flex; gap: 14px; }
.quality-copy strong { font-size: 14px; }
.quality-copy p { color: var(--muted); font-size: 11px; margin: 2px 0 0; }
.quality-grid { display: grid; gap: 8px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.quality-item { align-items: center; background: #f8fafb; border: 1px solid var(--line); border-radius: 8px; display: grid; gap: 7px; grid-template-columns: auto minmax(0, 1fr) auto; min-height: 43px; padding: 7px 10px; }
.quality-item strong { direction: ltr; }
.quality-dot { background: var(--success); border-radius: 50%; height: 7px; width: 7px; }
.quality-item.has-warning { background: #fff9f1; border-color: #eed8b9; }
.quality-item.has-warning .quality-dot { background: var(--saffron); }
.quality-label { color: var(--muted); font-size: 10px; }
.mini-kpi .value { direction: ltr; font-size: 17px; font-weight: 700; text-align: right; }
.mini-kpi .label { color: var(--muted); font-size: 11px; }
.chart-grid { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.chart-tools { display: flex; gap: 6px; margin-right: auto; }
.chart-tools select { font-size: 11px; min-height: 30px; padding: 3px 7px; width: auto; }
.chart-box { height: 340px; padding: 16px; position: relative; }
.chart-box.tall { height: 365px; }
.chart-empty { color: var(--muted); left: 20px; margin: 0; position: absolute; right: 20px; text-align: center; top: 46%; }
.chart-total { align-items: center; background: #f7f9fa; border-top: 1px solid var(--line); display: flex; justify-content: space-between; padding: 10px 14px; }
.chart-total span { color: var(--muted); font-size: 12px; }
.chart-total strong { direction: ltr; font-size: 20px; }
.table-scroll { overflow: auto; }
table { border-collapse: collapse; min-width: 700px; width: 100%; }
th, td { border-bottom: 1px solid var(--line); padding: 9px 12px; text-align: right; }
th { background: #f3f7f8; color: var(--muted); font-size: 11px; position: sticky; top: 0; vertical-align: middle; }
td.numeric { direction: ltr; font-variant-numeric: tabular-nums; text-align: left; }
th.numeric { direction: rtl; text-align: left; unicode-bidi: plaintext; }
tbody tr:nth-child(even) { background: #fbfcfd; }
tbody tr:hover { background: #eef5f6; }
.comparison-body { padding: 14px; }
.comparison-controls { align-items: end; display: grid; gap: 10px; grid-template-columns: repeat(7, minmax(0, 1fr)); margin-bottom: 14px; }
.comparison-controls label { color: var(--muted); font-size: 11px; }
.comparison-controls label span { display: block; margin-bottom: 3px; }
.comparison-controls .button { min-height: 36px; }
.empty-state { color: var(--muted); margin: 8px; text-align: center; }
.sr-only { clip: rect(0, 0, 0, 0); clip-path: inset(50%); height: 1px; overflow: hidden; position: absolute; white-space: nowrap; width: 1px; }
.ltr { direction: ltr; text-align: left; }
.customer-search-body { padding: 16px; }
.section-description { color: var(--muted); margin: 0 0 12px; }
.customer-search-form { display: grid; gap: 9px; grid-template-columns: minmax(220px, 1fr) auto; max-width: 760px; }
.customer-search-form input { border: 1px solid var(--line); border-radius: 8px; min-height: 40px; padding: 7px 11px; width: 100%; }
.customer-search-status { color: var(--muted); min-height: 28px; padding-top: 7px; }
.customer-results-list { display: flex; gap: 8px; margin: 5px 0 14px; overflow-x: auto; padding-bottom: 4px; }
.customer-result { background: #f7f9fa; border: 1px solid var(--line); border-radius: 9px; display: grid; flex: 0 0 190px; gap: 1px; padding: 9px 11px; text-align: right; }
.customer-result:hover { background: #eef4f6; border-color: #aec6d3; }
.customer-result.selected { background: #e7f2f3; border-color: var(--teal); box-shadow: inset 0 0 0 1px var(--teal); }
.customer-result span, .customer-result small { color: var(--muted); font-size: 11px; }
.customer-summary { display: grid; gap: 8px; grid-template-columns: repeat(6, minmax(0, 1fr)); margin: 0 0 14px; }
.customer-summary .mini-kpi { border-radius: 8px; min-width: 0; }
.customer-orders-wrap { border: 1px solid var(--line); border-radius: 9px; max-height: 520px; }
.customer-orders-wrap table { min-width: 1120px; }
.customer-orders-wrap .order-items { min-width: 280px; white-space: normal; }
.result-note { background: #f7f9fa; border-radius: 7px; color: var(--muted); font-size: 11px; margin: 7px 0; padding: 7px 10px; }
.positive { color: var(--success); }
.negative { color: var(--danger); }
footer { color: var(--muted); font-size: 11px; padding: 4px 18px 18px; text-align: center; }

.login-page { align-items: center; background: linear-gradient(145deg, #e9f0f4, #f7f5f0); display: flex; justify-content: center; padding: 20px; }
.login-card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 22px 65px rgba(15,61,92,.16); max-width: 420px; padding: 34px; width: 100%; }
.login-card h1 { font-size: 20px; margin: 12px 0 4px; }
.login-card p { color: var(--muted); margin: 0 0 22px; }
.login-card label { display: block; font-size: 12px; margin-bottom: 6px; }
.login-card input { border: 1px solid var(--line); border-radius: 8px; direction: ltr; margin-bottom: 14px; min-height: 44px; padding: 8px 11px; width: 100%; }
.login-card .form-error { margin-top: 12px; }
.brand-mark { align-items: center; background: var(--deep); border-radius: 12px; color: #fff; display: flex; font-size: 21px; font-weight: 700; height: 46px; justify-content: center; width: 46px; }

@media (max-width: 1100px) {
  .page-shell { grid-template-columns: 1fr; }
  .filters { max-height: none; position: static; }
  .customer-summary { grid-template-columns: repeat(3, 1fr); }
  .quality-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 720px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .page-shell { padding: 10px; }
  .dashboard-toolbar { position: static; }
  .dashboard-tabs { grid-template-columns: repeat(2, 1fr); }
  .section-intro { align-items: flex-start; flex-direction: column; }
  .chart-grid { grid-template-columns: 1fr; }
  .comparison-controls { grid-template-columns: repeat(2, 1fr); }
  .customer-search-form { grid-template-columns: 1fr; }
  .customer-summary { grid-template-columns: repeat(2, 1fr); }
  .quality-summary { align-items: stretch; flex-direction: column; }
  .quality-grid { grid-template-columns: repeat(2, 1fr); }
  .upload-card.has-dataset { grid-template-columns: auto minmax(0, 1fr); }
  .upload-card.has-dataset .button { grid-column: 1 / -1; }
  .upload-card.has-dataset .status { grid-column: 1 / -1; }
}
@page { size: A4 landscape; margin: 8mm; }
@media print {
  .filters, .upload-card, .top-actions, footer, .chart-tools, .dashboard-tabs, .section-intro, #qualityDownload, #qualityToggle, .filter-chip-remove, .filter-chip-clear { display: none !important; }
  .dashboard-toolbar { display: block; position: static; }
  .active-filters { border: 0; box-shadow: none; padding: 0 0 4px; }
  #qualityDetails.hidden { display: grid !important; }
  html, body { background: #fff; font-size: 10px; }
  .page-shell { display: block; padding: 0; }
  .dashboard-main, .dashboard { gap: 8px; }
  .tab-panel[hidden] { display: flex !important; }
  .topbar { print-color-adjust: exact; }
  .section-card, .kpi { break-inside: avoid; box-shadow: none; }
  .kpi.is-hero { print-color-adjust: exact; }
  .chart-grid { display: block; }
  .chart-card {
    break-before: page;
    break-after: page;
    break-inside: avoid;
    display: flex;
    flex-direction: column;
    height: 188mm;
    justify-content: center;
    margin-left: auto;
    margin-right: auto;
    max-width: 265mm;
    overflow: hidden;
    page-break-before: always;
    page-break-after: always;
    page-break-inside: avoid;
    width: 100%;
  }
  .chart-card .section-title { flex: 0 0 auto; width: 100%; }
  .chart-card .chart-box {
    flex: 0 0 145mm;
    height: 145mm;
    margin-left: auto;
    margin-right: auto;
    max-width: 100%;
    overflow: hidden;
    width: 100%;
  }
  .chart-card canvas { display: block; max-width: 100% !important; }
  .comparison-section, .customer-search-section { break-inside: auto; }
  .comparison-section {
    margin-left: auto;
    margin-right: auto;
    max-width: 265mm;
    overflow: hidden;
    width: 100%;
  }
  .comparison-controls, .customer-search-form, .customer-search-status, .customer-results-list, .result-note { display: none !important; }
  .comparison-body, .customer-search-body { padding: 8px; }
  .comparison-section .chart-box {
    break-inside: avoid;
    height: 105mm;
    max-width: 100%;
    overflow: hidden;
    page-break-inside: avoid;
    width: 100%;
  }
  .comparison-section canvas { display: block; max-width: 100% !important; }
  .table-scroll, .customer-orders-wrap { max-height: none !important; overflow: visible !important; }
  table, .customer-orders-wrap table { min-width: 0 !important; table-layout: fixed; width: 100%; }
  thead { display: table-header-group; }
  tr { break-inside: avoid; page-break-inside: avoid; }
  th { position: static; }
  th, td { font-size: 8px; overflow-wrap: anywhere; padding: 4px 5px; }
  .customer-summary { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .customer-orders-wrap { border: 0; }
  .customer-orders-wrap .order-items { min-width: 0; white-space: normal; }
  #customerOrders th:nth-child(1), #customerOrders td:nth-child(1) { width: 11%; }
  #customerOrders th:nth-child(2), #customerOrders td:nth-child(2) { width: 10%; }
  #customerOrders th:nth-child(3), #customerOrders td:nth-child(3) { width: 28%; }
  #customerOrders th:nth-child(4), #customerOrders td:nth-child(4) { width: 14%; }
  #customerOrders th:nth-child(5), #customerOrders td:nth-child(5) { width: 17%; }
  #customerOrders th:nth-child(6), #customerOrders td:nth-child(6) { width: 8%; }
  #customerOrders th:nth-child(7), #customerOrders td:nth-child(7) { width: 12%; }
}
@media (prefers-reduced-motion: reduce) {
  .progress i { animation: none; width: 100%; }
}
