* { box-sizing: border-box; font-family: -apple-system, Segoe UI, Roboto, sans-serif; }
body { margin: 0; background: #f5f6f8; color: #1a1d21; }
header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 24px; background: #005bff; color: white;
}
header h1 { font-size: 18px; margin: 0; }
main { padding: 20px; max-width: 900px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }
section { background: white; border-radius: 8px; padding: 18px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
h2 { margin-top: 0; font-size: 16px; }
label { display: block; margin-top: 10px; font-size: 13px; color: #555; }
input, select { width: 100%; padding: 8px; margin-top: 4px; border: 1px solid #ccc; border-radius: 4px; }
button {
  cursor: pointer; background: #005bff; color: white; border: none;
  border-radius: 4px; padding: 8px 14px; margin-top: 10px; font-size: 14px;
}
button:hover { background: #0047cc; }
button.secondary { background: #e6ebf0; color: #1a1d21; }
table { width: 100%; border-collapse: collapse; margin-top: 10px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid #eee; font-size: 13px; }
pre { background: #f0f2f5; padding: 10px; border-radius: 4px; font-size: 12px; overflow-x: auto; white-space: pre-wrap; }
.item-row { display: flex; gap: 8px; margin-top: 6px; }
.item-row input { width: auto; flex: 1; }
dialog { border: none; border-radius: 8px; padding: 20px; width: 320px; }
.dialog-actions { display: flex; gap: 8px; }
.status-badge {
  display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px;
}
.status-SUCCESS { background: #dbf5e3; color: #147a3d; }
.status-IN_PROGRESS { background: #fff4d6; color: #8a6a00; }
.status-FAILED, .status-EXPIRED { background: #fde2e2; color: #b3261e; }
.status-NOT_STARTED { background: #eee; color: #666; }

.version { font-size: 12px; font-weight: normal; opacity: 0.8; margin-left: 6px; }
.header-actions { display: flex; gap: 8px; }
.header-actions button { margin-top: 0; background: rgba(255,255,255,0.18); }
.header-actions button:hover { background: rgba(255,255,255,0.3); }
#updateDialog { width: 420px; }
#updLastError { background: #fde2e2; color: #b3261e; max-height: 200px; overflow: auto; }

.header-actions { align-items: center; }
.batch-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%;
  margin: 6px 0 0; padding: 10px 12px; text-align: left; background: #f4f6f9; color: #1a1a1a;
  border: 1px solid #e3e6ea; border-radius: 8px; font-weight: 600; cursor: pointer; }
.batch-head:hover { background: #eaeef3; }
.batch-head.open { background: #e6efff; border-color: #b8cdf5; border-radius: 8px 8px 0 0; }
.batch-head .batch-sum { font-weight: 400; font-size: 13px; color: #555; white-space: nowrap; }
.supply-group { border: 1px solid #b8cdf5; border-top: none; border-radius: 0 0 8px 8px; padding: 4px 12px 8px; }
#batchDetail { border: 1px solid #b8cdf5; border-top: none; border-radius: 0 0 8px 8px; padding: 4px 12px 12px; }
.header-actions button.update-available { background: #ffd54a; color: #1a1a1a; font-weight: 600; }
.header-actions button.update-available:hover { background: #ffe07a; }
.upd-cloud { border: 1px solid #e3e6ea; border-radius: 8px; padding: 10px 12px; margin: 8px 0 14px; }
.upd-cloud details { margin-top: 6px; font-size: 13px; }
.upd-cloud summary { cursor: pointer; color: #555; }
.account-label { margin: 0; color: white; font-size: 13px; opacity: 0.9; }
#accountSelect {
  width: auto; min-width: 160px; max-width: 260px; margin: 0;
  padding: 6px 8px; border: none; border-radius: 4px; font-size: 14px;
}
.hint { font-size: 13px; color: #555; margin: 4px 0 8px; }
#accountDialog { width: 380px; }

.conn { font-size: 18px; line-height: 1; cursor: help; }
.conn-ok { color: #4ade80; }
.conn-err { color: #ff8a8a; }
.conn-wait { color: rgba(255,255,255,0.5); }
.msg-ok { color: #147a3d; }
.msg-err { color: #b3261e; white-space: pre-wrap; }
#clusterId { margin-top: 6px; }

.search-results { max-height: 240px; overflow-y: auto; margin-top: 4px; }
.search-results:empty { display: none; }
.search-results { border: 1px solid #e0e3e8; border-radius: 4px; }
.search-item { padding: 8px 10px; cursor: pointer; border-bottom: 1px solid #f0f2f5; font-size: 13px; }
.search-item:last-child { border-bottom: none; }
.search-item:hover { background: #eef3ff; }
.search-item .addr { color: #666; font-size: 12px; }
.search-note { padding: 8px 10px; font-size: 13px; color: #666; }
.selected-point {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  margin-top: 4px; padding: 8px 10px; border: 1px solid #b7d0ff; background: #f3f7ff; border-radius: 4px;
  font-size: 13px;
}
.selected-point button { margin-top: 0; }
.hint a { color: #005bff; }

.item-row { align-items: flex-start; }
.product-picker { flex: 1; min-width: 0; }
.product-picker .product-search { width: 100%; margin-top: 0; }
.item-row .qty-input { flex: 0 0 110px; margin-top: 0; }
.item-row .remove-item { margin-top: 0; }
.product-item { display: flex; gap: 10px; align-items: center; }
.product-item img, .product-selected img {
  width: 36px; height: 36px; object-fit: contain; border-radius: 4px; background: #f0f2f5; flex-shrink: 0;
}
.product-item .meta, .product-selected .meta { color: #666; font-size: 12px; }
.product-selected {
  display: flex; gap: 10px; align-items: center; padding: 6px 8px;
  border: 1px solid #b7d0ff; background: #f3f7ff; border-radius: 4px; font-size: 13px; min-height: 38px;
}
.product-selected .info { flex: 1; min-width: 0; }
.product-selected .info div:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.product-selected button { margin-top: 0; padding: 4px 10px; }

.notice { padding: 10px 12px; border-radius: 6px; font-size: 13px; margin: 8px 0; white-space: pre-wrap; }
.notice-warn { background: #fff4d6; color: #6b5200; }
.notice-err { background: #fde2e2; color: #b3261e; }
.cluster-title { font-weight: 600; margin: 10px 0 4px; font-size: 14px; }
.wh-option {
  display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; margin: 4px 0;
  border: 1px solid #e0e3e8; border-radius: 6px; cursor: pointer; color: #1a1d21;
}
.wh-option:hover { background: #f7f9fc; }
.wh-option input { width: auto; margin-top: 3px; }
.wh-option .meta { color: #666; font-size: 12px; }
.wh-state { font-size: 12px; margin-top: 2px; }
.wh-state.bad { color: #b3261e; }
.wh-state.good { color: #147a3d; }
details summary { cursor: pointer; font-size: 13px; color: #555; margin-top: 12px; }

.slot-btn.slot-selected { background: #005bff; color: white; }
.notice-ok { background: #dbf5e3; color: #147a3d; }

.item-row-wrap { margin-top: 6px; }
.item-row-wrap .item-row { margin-top: 0; }
.plan-line { font-size: 12px; margin: 3px 0 0 2px; }
.plan-line:empty { display: none; }
.plan-ok { color: #147a3d; }
.plan-warn { color: #8a6a00; }

#boxRuleDialog { width: 520px; }
.box-type-row { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.box-type-row input { margin-top: 0; }
.box-type-row .box-name { flex: 1; }
.box-type-row .box-cap { flex: 0 0 110px; }
.box-type-row span { font-size: 13px; color: #555; }
.box-type-row button { margin-top: 0; }
button.danger { background: #d93025; }
button.danger:hover { background: #b3261e; }
#boxRulesTable td { vertical-align: middle; }
#boxRulesTable .meta { color: #666; font-size: 12px; }
#boxRulesTable button { margin-top: 0; }

.order-card { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13px;
  background: #f7f9fc; border: 1px solid #e0e3e8; border-radius: 6px; padding: 12px 14px; }
.order-card .k { color: #666; }
.order-card .v { font-weight: 500; }
#cargoPlan table { margin-top: 6px; }
#cargoPlan .meta { color: #666; font-size: 12px; }
#cargoPlan .total { font-weight: 600; margin-top: 6px; font-size: 13px; }
#labelsStatus a { font-weight: 600; }

.autopilot { border: 1px solid #b7d0ff; background: #f3f7ff; border-radius: 8px; padding: 12px 14px; margin: 8px 0 12px; }
.ap-title { font-weight: 600; font-size: 15px; margin-bottom: 8px; }
.ap-steps { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.ap-step { font-size: 12px; padding: 3px 9px; border-radius: 12px; background: #eee; color: #666; }
.ap-step.step-done { background: #dbf5e3; color: #147a3d; }
.ap-step.step-now { background: #fff4d6; color: #8a6a00; font-weight: 600; }
.ap-step.step-fail { background: #fde2e2; color: #b3261e; font-weight: 600; }
.ap-logs { font-size: 12px; font-family: Consolas, monospace; background: white; border-radius: 4px;
  padding: 6px 8px; max-height: 200px; overflow-y: auto; }
.ap-log { padding: 1px 0; white-space: pre-wrap; }
.ap-warn { color: #8a6a00; }
.ap-error { color: #b3261e; font-weight: 600; }
/* Пока работает автопилот, ручные действия скрыты, чтобы не мешать ему */
.autopilot-busy #warehousesBlock, .autopilot-busy #timeslotBlock, .autopilot-busy #confirmBlock,
.autopilot-busy #sendCargoesBtn, .autopilot-busy #labelsBtn { display: none !important; }
#manualDraftBtn { margin-left: 8px; }

label.check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: #444; margin-top: 6px; }
label.check input { width: auto; margin: 0; }

.recs-controls { display: flex; gap: 12px; flex-wrap: wrap; }
.recs-controls > div { flex: 1; min-width: 220px; }
.recs-statuses { display: flex; gap: 16px; flex-wrap: wrap; margin: 6px 0; }
#recsTable td { vertical-align: middle; }
#recsTable input[type=checkbox] { width: auto; margin: 0; }
#recsTable .meta { color: #666; font-size: 12px; }
.rec-badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; white-space: nowrap; }
.rec-urgent { background: #fde2e2; color: #b3261e; }
.rec-soon { background: #fff4d6; color: #8a6a00; }
.rec-ok { background: #dbf5e3; color: #147a3d; }
.rec-no { background: #eee; color: #666; }
.plan-rec { color: #005bff; }

.src-tabs { display: flex; gap: 0; border-bottom: 2px solid #e6ebf0; margin-bottom: 12px; }
.src-tab { background: none; color: #555; border-radius: 0; border-bottom: 2px solid transparent;
  margin: 0 0 -2px 0; padding: 8px 14px; }
.src-tab:hover { background: #f3f7ff; }
.src-tab.active { color: #005bff; border-bottom-color: #005bff; font-weight: 600; }
.fc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 10px; }
.fc-card { border: 1px solid #e0e3e8; border-radius: 8px; padding: 10px 12px; }
.fc-title { font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.fc-inline { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.fc-inline input { margin-top: 0; }
.fc-inline input[type=number] { width: 80px; }
button.small { font-size: 12px; padding: 5px 10px; }
#fcClusterBlock { margin-top: 10px; }
#fcClusterTable input { width: 90px; margin: 0; padding: 4px 6px; }
#fcClusterTable td, #fcClusterTable th { padding: 4px 8px; }
#recsTable .sub { color: #666; font-size: 11px; }

.own-stock { margin: 12px 0; }
.own-stock .fc-inline { margin-top: 6px; flex-wrap: wrap; }
.own-stock #osUrl { flex: 1; min-width: 260px; }
#recsTable tr.no-stock td { color: #999; }
.os-warn { color: #b3261e; }

.plan-block { border: 1px solid #b7d0ff; background: #f7faff; border-radius: 8px; padding: 12px 14px; margin: 12px 0; }
.plan-block h3 { margin-top: 0; }
.plan-block table { background: white; }
.plan-block td input[type=checkbox] { width: auto; margin: 0; }
.plan-total { font-weight: 600; font-size: 14px; }
#planProducts tr.off td, #planClusters tr.off td, #planOut tr.off td { color: #999; }
.plan-out, .os-short { margin: 8px 0; }
.plan-out > summary, .os-short > summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.os-short-text { margin-top: 6px; white-space: pre-line; }
.cl-chips { font-size: 11px; color: #666; }
#batchTable td { vertical-align: middle; }
#batchTable .err { color: #b3261e; font-size: 12px; }
#batchTable button { margin-top: 0; }

#driversDialog { width: 560px; }
#driversTable td { vertical-align: middle; font-size: 13px; }
#driversTable button { margin-top: 0; padding: 4px 8px; font-size: 12px; }
#driversTable .meta { color: #666; font-size: 12px; }
#driverInfo { font-size: 13px; margin-bottom: 6px; }
#goodsWrap table td, #goodsWrap table th { font-size: 12px; }
#goodsWrap .meta { color: #666; font-size: 11px; }
