:root{
  --bg:#f4f6f8;--card:#fff;--text:#1d2733;--muted:#687586;--line:#dfe5ec;
  --blue:#1b6ef3;--ok:#147d3f;--red:#b42318;--green:#137333;--soft-red:#fff1f0;--soft-green:#f0fdf4;--soft-yellow:#fff7e6;
}
*{box-sizing:border-box}
body{margin:0;background:var(--bg);font-family:Arial,Helvetica,sans-serif;color:var(--text)}
a{color:var(--blue);text-decoration:none} a:hover{text-decoration:underline}
.topbar{height:54px;background:#111827;color:#fff;display:flex;align-items:center;justify-content:flex-start;padding:0 22px;position:sticky;top:0;z-index:20}
.brand a{font-weight:700;color:#fff;font-size:20px}.ver{opacity:.75;margin-left:auto}.wrap{max-width:1500px;margin:22px auto;padding:0 18px}
.nav{display:flex;gap:14px;margin-left:24px;flex:1}.nav a{color:#dbeafe;font-weight:600}
h1{margin:0 0 10px;font-size:30px} h2{margin:0 0 8px;font-size:20px}.muted{color:var(--muted)}.ok{color:var(--ok);font-weight:700}.err{color:#b91c1c;font-weight:700}
.page-head,.section-head{display:flex;align-items:flex-start;justify-content:space-between;gap:16px}.page-head{margin-bottom:10px}
.card{background:var(--card);border:1px solid var(--line);border-radius:14px;padding:18px;margin:16px 0;box-shadow:0 2px 8px rgba(20,30,45,.04)}.wide{overflow:auto}
.grid-form{display:grid;grid-template-columns:160px minmax(260px,480px);gap:10px 12px;align-items:center}.grid-form input,.grid-form select{height:38px;border:1px solid var(--line);border-radius:8px;padding:0 10px;background:#fff}
.grid-form button,button{height:38px;border:0;border-radius:8px;background:var(--blue);color:#fff;font-weight:700;padding:0 14px;cursor:pointer}.grid-form button:disabled{background:#9aa6b2;cursor:not-allowed}
button.light,.light{background:#fff;color:#1f2937;border:1px solid var(--line)}button.light:hover,.light:hover{background:#f8fafc;text-decoration:none}.light.active{background:#e8f0ff;border-color:#9bbcff;color:#0b52c1}
.btnlink{display:inline-flex;align-items:center;height:38px;border-radius:8px;background:var(--blue);color:#fff;font-weight:700;padding:0 14px}.btnlink:hover{text-decoration:none}.secondary{background:#64748b;color:#fff;border:0}
.cards-row{display:grid;grid-template-columns:repeat(6,minmax(150px,1fr));gap:12px;margin:16px 0}.metrics-main{grid-template-columns:repeat(6,minmax(170px,1fr))}
.metric{background:#fff;border:1px solid var(--line);border-radius:12px;padding:14px;min-height:72px}.metric span{display:block;color:var(--muted);font-size:13px;margin-bottom:6px}.metric b{font-size:20px}.metric.big b{font-size:24px}.pos{color:var(--green)}.neg{color:var(--red)}
.toolbar-card{padding:12px 14px}.report-tools{display:flex;align-items:end;gap:16px;flex-wrap:wrap}.report-tools label{display:flex;flex-direction:column;gap:6px;color:var(--muted);font-size:13px}.report-tools input{height:38px;min-width:310px;border:1px solid var(--line);border-radius:8px;padding:0 12px;background:#fff}.quick-filters{display:flex;gap:8px;flex-wrap:wrap}.visible-summary{margin-left:auto;color:var(--muted);padding-bottom:8px}.visible-summary b{color:var(--text)}
table{border-collapse:collapse;width:100%;margin-top:12px;background:#fff} th,td{border-bottom:1px solid var(--line);padding:9px 10px;text-align:left;vertical-align:top} th{font-size:13px;color:#445064;background:#f8fafc;position:sticky;top:54px;z-index:5}td{font-size:14px}.compact td,.compact th{font-size:13px;padding:7px 8px}.name{min-width:300px}.json{max-width:420px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;color:#526173}.num{text-align:right;white-space:nowrap}.id-cell{font-weight:700;min-width:135px}.sku-cell{white-space:normal;max-width:160px}.total-cell{font-size:14px}.row-neg{background:var(--soft-red)}.row-pos:hover,.row-neg:hover,tr:hover{background:#f8fafc}.row-neg:hover{background:#ffe7e5}
.report-table th,.report-table td{white-space:nowrap}.report-table .name{white-space:normal}.extra-col{color:#334155}
.pill{display:inline-block;border-radius:999px;padding:3px 8px;font-size:12px;font-weight:700;background:#e5e7eb;color:#374151;white-space:nowrap}.pill-sales{background:#dcfce7;color:#166534}.pill-returns{background:#fee2e2;color:#991b1b}.pill-commission{background:#e0f2fe;color:#075985}.pill-logistics{background:#fef3c7;color:#92400e}.pill-partner{background:#ede9fe;color:#5b21b6}.pill-ads{background:#fce7f3;color:#9d174d}.pill-penalty{background:#fee2e2;color:#991b1b}.pill-storage{background:#f3f4f6;color:#374151}.pill-acquiring{background:#e0e7ff;color:#3730a3}.pill-unknown{background:#fff7ed;color:#9a3412}
.badge{display:inline-block;border-radius:999px;padding:3px 8px;font-size:12px;font-weight:700}.okb{background:#dcfce7;color:#166534}.offb{background:#e5e7eb;color:#374151}.small{font-size:12px;margin-top:3px}.warn-row{background:#fff7e6}code{font-family:Consolas,monospace;font-size:12px}.mini-form{display:flex;gap:6px;align-items:center}.mini-form select{max-width:140px}.mini-form input[type="text"]{max-width:180px}.actions{display:flex;gap:8px;align-items:flex-start}.actions form{margin:0}
@media(max-width:1100px){.cards-row,.metrics-main{grid-template-columns:repeat(2,1fr)}.report-tools input{min-width:220px}.visible-summary{margin-left:0}.extra-col{display:none}}
@media(max-width:900px){.grid-form{grid-template-columns:1fr}.wrap{padding:0 10px}h1{font-size:24px}.page-head{display:block}.report-tools{display:block}.quick-filters{margin:12px 0}.report-tools label{margin-bottom:10px}}

/* v006: integrations / multi-marketplace foundation */
.nav a.disabled{opacity:.45;cursor:not-allowed}.nav a.disabled:hover{text-decoration:none}
.info-grid{display:grid;grid-template-columns:minmax(280px,1fr) minmax(320px,1.3fr);gap:20px;align-items:start}.roadmap-box{background:#f8fafc;border:1px solid var(--line);border-radius:12px;padding:14px}.roadmap-box ol{margin:10px 0 0 20px;padding:0}.roadmap-box li{margin:4px 0;color:#4b5563}
.integration-tabs{display:flex;gap:10px;flex-wrap:wrap;padding:12px}.integration-tabs .tab{display:inline-flex;align-items:center;gap:8px;border:1px solid var(--line);border-radius:999px;padding:9px 13px;background:#fff;font-weight:700;color:#1f2937}.integration-tabs .tab span{font-weight:500;color:var(--muted);font-size:12px}.integration-tabs .tab.active{border-color:#9bbcff;background:#e8f0ff;color:#0b52c1}.integration-tabs .tab.disabled{opacity:.65;cursor:not-allowed}.integration-tabs .tab:hover{text-decoration:none}.integration-form{margin-top:10px}.integrations-card{overflow:auto}
.integrations-table{min-width:1080px;table-layout:auto}.integrations-table th{position:static;top:auto;white-space:nowrap}.integrations-table td{vertical-align:middle;white-space:normal}.integrations-table .w-id{width:56px}.integrations-table .w-market{width:120px}.integrations-table .w-status{width:110px}.integrations-table .w-actions{width:220px}.integrations-table code{white-space:nowrap}.market-badge{display:inline-block;border-radius:999px;padding:4px 9px;font-size:12px;font-weight:800;letter-spacing:.04em}.market-ozon{background:#e8f0ff;color:#0b52c1}.market-wb{background:#f3e8ff;color:#6b21a8}.market-ym{background:#fef3c7;color:#92400e}.market-ms{background:#dcfce7;color:#166534}.check-cell{min-width:220px}.check-message{max-width:360px;white-space:normal;line-height:1.25}.actions{display:flex;gap:8px;align-items:center;flex-wrap:wrap}.actions form{margin:0}.coming-grid{display:grid;grid-template-columns:repeat(3,minmax(220px,1fr));gap:14px;margin-top:14px}.coming h3{margin:0 0 8px}.report-load-form select:disabled{color:#334155;background:#f8fafc}
@media(max-width:1000px){.info-grid,.coming-grid{grid-template-columns:1fr}.integrations-table{min-width:920px}}

/* v008: product catalog / SKU mapping */
.warnb{background:#fef3c7;color:#92400e}.badb{background:#fee2e2;color:#991b1b}
.product-filter-form{display:flex;gap:10px;align-items:center;flex-wrap:wrap}.product-filter-form select,.product-filter-form input{height:38px;border:1px solid var(--line);border-radius:8px;padding:0 10px;background:#fff}
.sync-form{display:flex;align-items:center;gap:12px;flex-wrap:wrap;margin-top:14px;border-top:1px solid var(--line);padding-top:14px}.sync-form button{min-width:230px}
.product-metrics{grid-template-columns:repeat(5,minmax(160px,1fr))}.products-table th{position:sticky}.products-table .name{min-width:280px}.products-table code{white-space:nowrap}
@media(max-width:1100px){.product-metrics{grid-template-columns:repeat(2,1fr)}}

.badge.neutrb{background:#eef2f7;color:#475569}

/* v011: readable report rows + client-side pagination */
.report-card{overflow:auto}
.report-table{min-width:1280px;table-layout:fixed}
.report-table th,.report-table td{white-space:normal;overflow-wrap:anywhere;word-break:normal}
.report-table .num,.report-table .id-cell,.report-table .w-date{white-space:nowrap;overflow-wrap:normal}
.report-table .w-id{width:150px}.report-table .w-date{width:105px}.report-table .w-sku{width:150px}.report-table .w-offer{width:120px}.report-table .w-name{width:380px}.report-table .w-qty{width:75px}.report-table .w-money{width:115px}.report-table .w-small{width:70px}
.report-table .list-cell{line-height:1.35}.mini-item{margin:0 0 3px}.mini-item:last-child{margin-bottom:0}.mini-item code{white-space:normal;overflow-wrap:anywhere}
.product-line{margin:0 0 5px;line-height:1.28}.product-line:last-child{margin-bottom:0}.product-line + .product-line{padding-top:5px;border-top:1px dashed #d7dee8}
.table-pagination{display:flex;align-items:center;justify-content:space-between;gap:14px;flex-wrap:wrap;margin-top:14px;padding-top:14px;border-top:1px solid var(--line)}
.page-size-box,.pager-buttons{display:flex;align-items:center;gap:8px;color:var(--muted)}
.page-size-box select{height:34px;border:1px solid var(--line);border-radius:8px;padding:0 8px;background:#fff;color:var(--text)}
.pager-buttons button{min-width:42px;height:34px;padding:0 12px}.pager-buttons button:disabled{opacity:.45;cursor:not-allowed;background:#f8fafc}
@media(max-width:900px){.report-table{min-width:1080px}.report-table .w-name{width:300px}.table-pagination{align-items:flex-start}}

/* v012: product drill-down + cleaner accrual detail */
.product-link{display:block;color:var(--text);padding:6px 8px;border:1px solid transparent;border-radius:10px;background:#fff}
.product-link:hover{border-color:#bcd3ff;background:#f8fbff;text-decoration:none}
.product-title{display:block;font-weight:700;line-height:1.25}.product-meta{display:block;margin-top:3px;color:var(--muted);font-size:12px}
.product-chip-list{display:grid;grid-template-columns:repeat(auto-fill,minmax(280px,1fr));gap:10px;margin-top:12px}
.product-chip{display:block;border:1px solid var(--line);border-radius:12px;background:#fff;padding:11px;color:var(--text)}
.product-chip:hover{border-color:#9bbcff;background:#f8fbff;text-decoration:none}.product-chip b{display:block;margin-bottom:4px}.product-chip span{display:block;line-height:1.25}.product-chip small{display:block;color:var(--muted);margin-top:5px}
.product-hero{display:flex;justify-content:space-between;gap:22px;align-items:flex-start}.product-hero h2{font-size:30px;margin:2px 0 8px}.product-hero-name{font-size:18px;line-height:1.35;margin:0}.product-hero-meta{display:grid;grid-template-columns:repeat(3,minmax(160px,1fr));gap:10px;min-width:520px}.product-hero-meta div{border:1px solid var(--line);background:#f8fafc;border-radius:10px;padding:10px}.product-hero-meta span{display:block;color:var(--muted);font-size:12px;margin-bottom:4px}.product-hero-meta b{font-size:15px;overflow-wrap:anywhere}
.product-orders-table{min-width:1100px}.product-orders-table th{position:sticky}.product-orders-table .id-cell{min-width:150px}
.detail-card{overflow:auto}.clean-detail-table{min-width:1220px;table-layout:fixed}.clean-detail-table th,.clean-detail-table td{white-space:normal}.clean-detail-table .w-date{width:105px}.clean-detail-table .w-group{width:150px}.clean-detail-table .w-operation{width:250px}.clean-detail-table .w-detail{width:420px}.clean-detail-table .w-money{width:110px;white-space:nowrap}.op-name{font-weight:700;line-height:1.25;margin-bottom:3px}.detail-subtitle{font-size:11px;font-weight:800;letter-spacing:.04em;text-transform:uppercase;color:#64748b;margin-bottom:5px}.detail-subtitle.with-gap{margin-top:10px}.inline-product-link{display:block;color:#1d4ed8;font-weight:700;line-height:1.25;margin-bottom:5px}.inline-product-link:hover{text-decoration:underline}.service-list{display:grid;gap:4px}.service-row{display:flex;align-items:flex-start;justify-content:space-between;gap:12px;border-bottom:1px dashed #d7dee8;padding-bottom:4px}.service-row:last-child{border-bottom:0;padding-bottom:0}.service-row span{line-height:1.25}.service-row b{white-space:nowrap;font-variant-numeric:tabular-nums}
@media(max-width:1000px){.product-hero{display:block}.product-hero-meta{min-width:0;grid-template-columns:1fr;margin-top:14px}.clean-detail-table{min-width:1040px}}


/* v015: MoySklad costs */
.integrations-forms{display:grid;grid-template-columns:1fr 1fr;gap:14px;margin-bottom:14px}.button-like{display:inline-block;border:0;background:var(--blue);color:#fff;border-radius:8px;padding:8px 12px;font-weight:700}.button-like.light{background:#e8f0ff;color:#0b52c1}.button-like:hover{text-decoration:none;filter:brightness(.98)}
.cost-metrics{grid-template-columns:repeat(5,minmax(160px,1fr))}.costs-card{overflow:auto}.costs-table{min-width:1180px}.costs-table th{position:sticky}.costs-table .name{min-width:260px}.components-cell{min-width:320px}.component-line{border-bottom:1px dashed #d7dee8;padding:2px 0;line-height:1.25}.component-line:last-child{border-bottom:0}.status-ok{background:#dcfce7;color:#166534}.status-not_found,.status-error{background:#fee2e2;color:#991b1b}.status-zero_cost,.status-multiple,.status-not_loaded{background:#fef3c7;color:#92400e}
@media(max-width:1000px){.integrations-forms{grid-template-columns:1fr}.cost-metrics{grid-template-columns:repeat(2,1fr)}}

/* v016: progress for long MoySklad cost sync */
.sync-progress {
  margin-top: 16px;
  padding: 14px 16px;
  border: 1px solid #dbe4f0;
  border-radius: 14px;
  background: #f8fbff;
}
.sync-progress-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}
.sync-progress-bar {
  height: 12px;
  border-radius: 999px;
  background: #e5edf7;
  overflow: hidden;
  margin-bottom: 10px;
}
.sync-progress-bar span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #2563eb, #16a34a);
  transition: width .25s ease;
}
.sync-progress-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  margin-bottom: 8px;
  font-size: 14px;
}
.sync-progress.sync-done {
  background: #f0fdf4;
  border-color: #bbf7d0;
}
.sync-progress.sync-error {
  background: #fff1f2;
  border-color: #fecdd3;
}

/* v017: себестоимость и прибыль в отчёте */
.profit-metrics{grid-template-columns:repeat(5,minmax(160px,1fr))}
.notice{border:1px solid var(--line);border-radius:14px;padding:12px 16px;margin:14px 0;background:#fff}
.notice.warn{background:#fff7ed;border-color:#fed7aa;color:#9a3412;font-weight:700}
.notice.muted-note{background:#f8fafc;color:#64748b}
.profit-report-table{min-width:1540px}
.profit-report-table .w-id{width:150px}.profit-report-table .w-date{width:100px}.profit-report-table .w-sku{width:135px}.profit-report-table .w-offer{width:120px}.profit-report-table .w-name{width:360px}.profit-report-table .w-qty{width:70px}.profit-report-table .w-money{width:115px}.profit-report-table .w-margin{width:85px}.profit-report-table .w-cost-status{width:150px}.profit-report-table .w-small{width:65px}
.row-neg-soft{background:#fff7ed}.cost-ok,.cost-item-ok{background:#dcfce7;color:#166534}.cost-warning,.cost-item-multiple,.cost-item-zero_cost{background:#fef3c7;color:#92400e}.cost-incomplete,.cost-no_items,.cost-item-not_found,.cost-item-error,.cost-item-not_loaded,.cost-item-no_offer{background:#fee2e2;color:#991b1b}.cost-item-ok,.cost-item-multiple,.cost-item-zero_cost,.cost-item-not_found,.cost-item-error,.cost-item-not_loaded,.cost-item-no_offer{white-space:nowrap}
.accrual-products-card{overflow:auto}.accrual-products-table{min-width:1050px}.accrual-products-table th{position:sticky}.accrual-products-table td{vertical-align:top}.product-profit-table{min-width:1180px}.product-profit-table th{position:sticky}.product-profit-table .id-cell{min-width:150px}
@media(max-width:1100px){.profit-metrics{grid-template-columns:repeat(2,1fr)}.profit-report-table{min-width:1400px}}
