* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font-family: Arial, sans-serif; background: #f6f7f9; color: #1b1f24; }
a { color: #075aa8; text-decoration: none; }
.topbar { height: 56px; display: flex; align-items: center; gap: 24px; padding: 0 24px; background: #fff; border-bottom: 1px solid #e1e5ea; position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; color: #111; }
nav { display: flex; gap: 16px; flex: 1; }
button, .button { border: 0; border-radius: 6px; background: #0b72c9; color: #fff; padding: 9px 14px; font-weight: 600; cursor: pointer; display: inline-block; }
.secondary { background: #45515e; }
.ghost { background: #eef2f6; color: #20252b; }
.danger { background: #c83232; }
.page { padding: 24px; }
.heading-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; margin-bottom: 18px; }
h1 { font-size: 26px; margin: 0 0 6px; }
h2 { font-size: 18px; margin: 0 0 14px; }
p { margin: 0; color: #68717d; }
.actions, .inline-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.table-wrap, .panel, .form-card, .order-row { background: #fff; border: 1px solid #e1e5ea; border-radius: 8px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid #edf0f3; vertical-align: top; }
th { background: #fafbfc; color: #4d5863; font-size: 12px; text-transform: uppercase; }
input, textarea { width: 100%; border: 1px solid #cfd6dd; border-radius: 6px; padding: 9px 10px; font: inherit; }
select { border: 1px solid #cfd6dd; border-radius: 6px; padding: 9px 10px; font: inherit; background: #fff; }
.search { display: flex; gap: 10px; min-width: 360px; }
.wide-search { min-width: min(720px, 100%); }
.pagination { display: flex; gap: 16px; margin-top: 16px; align-items: center; }
.filters { display: grid; gap: 12px; }
.tabs { display: flex; flex-wrap: wrap; gap: 8px; }
.tabs a { padding: 8px 12px; border-radius: 6px; background: #eef2f6; color: #20252b; }
.tabs a.active { background: #0b72c9; color: #fff; }
.supplier-tabs { align-items: center; }
.supplier-tabs a { border: 1px solid #dfe6ee; }
.supplier-tabs a:not(.active) { background: #fff; }
.period-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.period-form label { display: grid; gap: 4px; color: #4d5863; font-size: 13px; }
.period-form .order-search { min-width: 340px; flex: 1; }
.workflow-badge { display: inline-block; padding: 9px 12px; border-radius: 6px; font-weight: 700; text-align: center; }
.workflow-badge.issued { color: #176b38; background: #dcf5e5; }
.workflow-issued { background: #198754; }
.login-panel { max-width: 380px; margin: 10vh auto; }
.login-panel h1 { text-align: center; margin-bottom: 20px; }
.form-card, .panel { padding: 18px; }
.form-card label, .stack label { display: grid; gap: 6px; margin-bottom: 12px; color: #4d5863; }
.flash-list { display: grid; gap: 8px; margin-bottom: 16px; }
.flash { padding: 10px 12px; border-radius: 6px; background: #eef4ff; border: 1px solid #c9ddff; }
.flash.error { background: #fff0f0; border-color: #ffc9c9; }
.flash.success { background: #edf9f0; border-color: #bfe8c8; }
.grid-2 { display: grid; grid-template-columns: minmax(280px, 420px) 1fr; gap: 18px; }
.checkbox { display: flex !important; grid-template-columns: none !important; align-items: center; gap: 8px !important; }
.checkbox input { width: auto; }
.shop-list { display: grid; gap: 10px; }
.shop-row, .order-main { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.shop-row span { display: block; color: #68717d; margin-top: 4px; }
.shop-edit { display: grid; gap: 10px; padding: 12px; border: 1px solid #edf0f3; border-radius: 6px; background: #fafbfc; }
.shop-edit .stack label { margin-bottom: 8px; }
.orders-list { display: grid; gap: 12px; }
.order-row { padding: 14px; }
.summary-grid { display: grid; grid-template-columns: repeat(6, minmax(120px, 1fr)); gap: 10px; margin-bottom: 12px; }
.summary-grid div { display: grid; gap: 4px; padding: 10px; border: 1px solid #edf0f3; border-radius: 6px; background: #fafbfc; }
.summary-grid strong { font-size: 18px; }
.summary-grid span { color: #68717d; font-size: 12px; }
.items { margin-top: 10px; display: grid; gap: 6px; color: #4d5863; font-size: 14px; }
.item-line { display: grid; grid-template-columns: minmax(260px, 1fr) minmax(220px, 320px) 150px 100px auto; gap: 8px; align-items: center; }
.upload-row { display: grid; grid-template-columns: minmax(220px, 1fr) 180px 120px auto; gap: 10px; align-items: center; }
.compact { margin-bottom: 18px; }
.settings-extra { margin-top: 18px; }
.card-matching-panel { border-top: 4px solid #7b3fc6; }
.matching-status { display: grid; gap: 6px; margin-top: 16px; padding: 12px; border-radius: 7px; background: #f7f2fc; color: #4d5863; }
button:disabled { opacity: .55; cursor: not-allowed; }
.muted { color: #68717d; display: grid; gap: 6px; margin-bottom: 12px; }
.danger-text { color: #c83232; }
.warehouse-summary { grid-template-columns: repeat(6, minmax(130px, 1fr)); }
.warehouse-metrics { display: grid; gap: 14px; }
.summary-period-form { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; }
.summary-tabs button { background: #eef2f6; color: #20252b; }
.summary-tabs button.active, .custom-period button.active { background: #0b72c9; color: #fff; }
.custom-period { display: flex; align-items: center; gap: 7px; }
.custom-period input { width: auto; }
.warehouse-summary .period-metric { background: #edf6ff; border-color: #c9dff3; }
.warehouse-tools, .warehouse-list { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.warehouse-list form { display: inline-flex; }
.warehouse-list .danger { padding: 5px 8px; font-size: 11px; }
.warehouse-actions > .panel { min-width: 0; }
.warehouse-actions .grid-2 { grid-template-columns: 1fr 1fr; gap: 10px; }
.mini-form { display: grid; grid-template-columns: minmax(75px, 1fr); gap: 5px; min-width: 110px; }
.mini-form input, .mini-form button { padding: 6px 7px; font-size: 12px; }
.muted-inline { color: #68717d; font-size: 12px; }
.margin-positive { color: #237045; font-weight: 700; }
.margin-negative { color: #c83232; font-weight: 700; }
.local-stock-form { display: grid; grid-template-columns: auto minmax(260px, 1fr) auto; gap: 8px; align-items: center; padding: 8px; background: #f4f8fc; border-radius: 6px; }
.local-stock-used { padding: 8px; background: #e8f6ed; color: #237045; border-radius: 6px; font-weight: 700; }
.warehouse-history { margin-top: 18px; grid-template-columns: 1fr 1fr; }
.product-picker { position: relative; }
.product-search-results { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); max-height: 330px; overflow-y: auto; padding: 5px; background: #fff; border: 1px solid #cfd6dd; border-radius: 7px; box-shadow: 0 10px 26px rgba(31, 42, 55, .16); }
.product-search-results button { width: 100%; display: grid; gap: 3px; text-align: left; padding: 9px 10px; color: #1b1f24; background: #fff; border-radius: 5px; }
.product-search-results button:hover, .product-search-results button:focus { background: #eef4fb; }
.product-search-results button span, .product-selected span { color: #68717d; font-size: 12px; font-weight: 400; }
.product-not-found { padding: 12px; color: #a84222; }
.product-selected { margin-top: 7px; padding: 9px 10px; display: grid; gap: 4px; border-radius: 6px; background: #e8f6ed; color: #237045; }
.bulk-toolbar { position: sticky; top: 56px; z-index: 4; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 14px; background: #fff; border: 1px solid #e1e5ea; border-radius: 8px 8px 0 0; }
dialog { width: min(620px, calc(100vw - 28px)); max-height: 90vh; overflow: auto; border: 0; border-radius: 10px; padding: 20px; box-shadow: 0 20px 70px rgba(0,0,0,.28); }
dialog::backdrop { background: rgba(18,27,38,.55); }
.wide-modal { width: min(900px, calc(100vw - 28px)); }
.orders-modal { width: min(1180px, calc(100vw - 28px)); }
.orders-workspace { display: grid; grid-template-columns: 330px minmax(0,1fr); gap: 18px; min-height: 440px; }
.orders-period-form { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; padding-bottom: 14px; border-bottom: 1px solid #e1e5ea; }
.sale-order-list { display: grid; align-content: start; gap: 8px; max-height: 70vh; overflow: auto; padding-right: 4px; }
.sale-order-card { display: grid; gap: 5px; text-align: left; background: #f4f7fa; color: #1b1f24; border: 1px solid #dfe6ee; }
.sale-order-card:hover { background: #e8f1fa; border-color: #9ec3e6; }
.sale-order-card.returned { background: #f3f4f5; color: #68717d; }
.sale-order-card span { color: #68717d; font-size: 12px; }
.sale-order-editor { min-width: 0; }
.order-empty-state { display: grid; place-items: center; min-height: 360px; color: #68717d; border: 1px dashed #cfd6dd; border-radius: 8px; }
.sale-edit-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.sale-edit-head h2 { margin-top: 12px; }
.sale-edit-head > strong { font-size: 22px; }
.return-order { margin-top: 14px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-head h2 { margin: 0; }.modal-head [data-close] { background: #eef2f6; color: #20252b; font-size: 20px; padding: 5px 11px; }
.sale-line { display: grid; grid-template-columns: minmax(280px,1fr) 100px 140px auto; gap: 8px; align-items: start; padding: 10px; border: 1px solid #e1e5ea; border-radius: 7px; margin-bottom: 8px; }
.inventory-picker { position: relative; }.picker-results { position: absolute; z-index: 30; top: calc(100% + 3px); left: 0; right: 0; max-height: 260px; overflow: auto; background: #fff; border: 1px solid #cfd6dd; box-shadow: 0 10px 25px rgba(0,0,0,.15); padding: 5px; border-radius: 6px; }
.picker-results button { width: 100%; display: grid; text-align: left; background: #fff; color: #1b1f24; }.picker-results button:hover { background: #eef4fb; }.picker-results span { color: #68717d; font-size: 12px; }
.local-match-options { display: grid; gap: 5px; }.local-match { display: flex; gap: 7px; align-items: center; padding: 7px; background: #fff; border: 1px solid #dfe6ee; border-radius: 6px; }.local-match input { width: auto; }
.original-article-cell { min-width: 190px; font-size: 15px; color: #17365d; }
.kaspi-cell { min-width: 360px; }
.kaspi-cards { display: grid; gap: 8px; }
.kaspi-card { display: grid; gap: 6px; padding: 9px; border: 1px solid #dfe6ee; border-radius: 6px; background: #fbfcfd; min-width: 320px; max-width: 520px; }
.kaspi-card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.kaspi-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.kaspi-sku { font-weight: 700; color: #075aa8; }
.kaspi-open { display: inline-flex; align-items: center; min-height: 22px; padding: 3px 8px; border-radius: 6px; background: #0b72c9; color: #fff; font-size: 12px; font-weight: 700; }
.kaspi-title { color: #1b1f24; line-height: 1.3; }
.kaspi-meta, .kaspi-numbers { display: flex; flex-wrap: wrap; gap: 6px; color: #68717d; font-size: 12px; }
.kaspi-meta span, .kaspi-numbers span, .badge { display: inline-flex; align-items: center; min-height: 22px; padding: 3px 7px; border-radius: 999px; background: #eef2f6; color: #4d5863; white-space: nowrap; }
.badge.ok { background: #e8f6ed; color: #237045; }
.kaspi-warning { color: #a84222; font-size: 12px; line-height: 1.3; }
@media (max-width: 800px) {
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .heading-row, .grid-2, .shop-row, .order-main, .item-line, .upload-row, .local-stock-form, .warehouse-history { display: grid; grid-template-columns: 1fr; }
  .search { min-width: 0; width: 100%; }
  .page { padding: 14px; }
  .kaspi-cell, .kaspi-card { min-width: 280px; }
  .sale-line { grid-template-columns: 1fr; }
  .summary-period-form, .custom-period { align-items: stretch; }
  .custom-period { flex-wrap: wrap; }
  .orders-workspace { grid-template-columns: 1fr; }
  .orders-modal.editing .sale-order-list { display: none; }
}
