:root {
  --bg-page: #eef1f5;
  --surface: #ffffff;
  --surface2: #f8fafc;
  --line: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --brand: #0ea5e9;
  --brand2: #0284c7;
  --accent: #14b8a6;
  --accent2: #0d9488;
  --gold: #f59e0b;
  --danger: #ef4444;
  --success: #10b981;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
  --radius: 16px;
  --hero-height: 104px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font: 15px/1.5 "Manrope", "Segoe UI", sans-serif;
  background: var(--bg-page);
}

.hero {
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 12px 20px;
  background: linear-gradient(135deg, #0b3d3a 0%, #0f766e 55%, #115e59 100%);
  color: #fff;
  box-shadow: 0 4px 20px rgba(15, 23, 42, 0.15);
}

.hero-inner {
  max-width: 1560px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(200px, 1fr) minmax(300px, 420px) minmax(200px, 1fr);
  align-items: center;
  gap: 16px 20px;
}

.hero-fx {
  justify-self: center;
  width: 100%;
  max-width: 420px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 14px;
  padding: 10px 14px 8px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(6px);
  color: #fff;
}

.fx-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  line-height: 1.25;
}

.fx-table th,
.fx-table td {
  padding: 3px 6px;
  text-align: right;
  font-weight: 700;
}

.fx-th-title {
  text-align: left !important;
  color: rgba(255, 255, 255, 0.72);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.fx-th-date {
  color: rgba(255, 255, 255, 0.72);
  font-size: 12px;
  font-weight: 800;
  min-width: 88px;
}

.fx-cell-label {
  text-align: left !important;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  color: #fff;
  white-space: nowrap;
}

.fx-cell-val {
  font-variant-numeric: tabular-nums;
  color: #fff;
  font-weight: 800;
}

.fx-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  flex-shrink: 0;
}

.fx-icon-cny { background: #ef4444; }
.fx-icon-usd { background: #22c55e; }
.fx-icon-eur { background: #3b82f6; }

.fx-fallback {
  margin-top: 4px;
  font-size: 10px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.62);
  text-align: center;
}

@media (max-width: 1100px) {
  .hero-inner {
    grid-template-columns: 1fr;
    justify-items: stretch;
  }
  .hero-fx { max-width: none; }
  .hero-actions { justify-content: flex-start; flex-wrap: wrap; }
  .brand { text-align: left; }
}

.brand { font-size: 26px; font-weight: 800; letter-spacing: -0.03em; justify-self: start; }
.brand small {
  display: block;
  font-size: 10px;
  font-weight: 700;
  opacity: 0.85;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.hero-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-self: end;
  justify-content: flex-end;
}

.btn {
  border: 0;
  border-radius: 12px;
  padding: 10px 16px;
  font-weight: 800;
  font-size: 13px;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease;
  text-decoration: none;
  display: inline-block;
  line-height: 1.2;
}

.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-glass {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.35);
}

.btn-sync {
  background: #38bdf8;
  color: #0c4a6e;
  box-shadow: 0 4px 14px rgba(56, 189, 248, 0.35);
}

.btn-primary {
  background: linear-gradient(135deg, var(--brand), var(--accent));
  color: #fff;
  box-shadow: 0 8px 20px rgba(14, 165, 233, 0.28);
}

.btn-outline {
  background: #fff;
  color: var(--brand2);
  border: 1px solid var(--line);
}

.app-shell {
  max-width: 1560px;
  margin: 16px auto 24px;
  padding: 0 16px;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 220px;
  gap: 14px;
  align-items: stretch;
  min-height: calc(100vh - var(--hero-height) - 40px);
}

.sidebar-left.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-right { position: sticky; top: calc(var(--hero-height) + 12px); align-self: start; }

.main-center {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  min-height: 0;
}

#center-dashboard {
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
  min-height: 0;
}

#center-dashboard > .panel:last-child {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#center-dashboard > .panel:last-child .block {
  flex: 1;
  min-height: 0;
}

.hidden { display: none !important; }

.dashboard-top { padding: 14px 16px 16px; }

.dashboard-top-bar {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.period-bar {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  width: 100%;
}

.period-switch {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
  padding: 3px;
  border-radius: 12px;
  background: var(--surface2);
  border: 1px solid var(--line);
}

.period-custom {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface2);
  border: 1px solid var(--line);
}

.period-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.period-field input[type="date"] {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  background: #fff;
}

.period-range-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
}

.btn-sm {
  padding: 7px 12px;
  font-size: 12px;
}

.period-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  padding: 7px 12px;
  border-radius: 9px;
  cursor: pointer;
}

.period-btn.active {
  background: #fff;
  color: var(--brand2);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}

.stats-cards.stats-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.stat-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
  text-align: left;
}

.stat-card:hover { transform: translateY(-1px); box-shadow: var(--shadow); }

.stat-card.active {
  border-color: var(--brand);
  box-shadow: 0 8px 20px rgba(14, 165, 233, 0.12);
  background: #fff;
}

.stat-card .lbl {
  flex: 1;
  min-width: 0;
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1.35;
}

.stat-card .val {
  flex-shrink: 0;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: #0b1f3a;
  line-height: 1;
  text-align: right;
}

.stat-card[data-stat="arrived"] .val { color: #0369a1; }
.stat-card[data-stat="processed"] .val { color: #047857; }
.stat-card[data-stat="pushed_bitrix"] .val { color: #4338ca; }
.stat-card[data-stat="missing_data"] .val { color: #b45309; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  font-weight: 800;
  font-size: 14px;
  color: #0b1f3a;
}

.search { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.search input, .search select, .wh-select, .logic-input {
  width: 100%;
  margin-top: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  background: #fff;
}

.search input:first-child, .search select:first-child { margin-top: 0; }
.search select { margin-top: 8px; }

.card-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.card-item {
  padding: 12px 14px;
  border-bottom: 1px solid #eef2f7;
  cursor: pointer;
  transition: background .15s ease;
}

.card-item:hover, .card-item.active { background: #f0f9ff; }
.card-item.active { box-shadow: inset 3px 0 0 var(--brand); }

.card-product { font-weight: 800; font-size: 13px; color: #0b1f3a; }
.card-client { font-size: 12px; color: var(--muted); margin-top: 3px; }

.badge {
  display: inline-block;
  margin-top: 8px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
}

.st-new { background: #dbeafe; color: #1d4ed8; }
.st-missing_data { background: #fef3c7; color: #92400e; }
.st-calculated, .st-kp_ready { background: #d1fae5; color: #065f46; }
.st-pushed_bitrix { background: #e0e7ff; color: #3730a3; }

.center-workspace { min-height: calc(100vh - 140px); }

.workspace-head {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface2);
}

.btn-back {
  border: 0;
  background: transparent;
  color: var(--brand2);
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  padding: 6px 4px;
}

.btn-back:hover { color: var(--brand); }

.block {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.block:last-child { border-bottom: 0; }

.block-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.block-title h2 {
  margin: 0;
  font-size: 14px;
  line-height: 1.35;
  letter-spacing: -0.02em;
  color: #0b1f3a;
}

.block-tender { background: linear-gradient(180deg, #fff, #f8fbff); }
.block-logist {
  background: linear-gradient(180deg, #f0fdf9, #ecfeff);
  border-top: 3px solid var(--accent);
}

.flow-arrow {
  text-align: center;
  padding: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  background: #f1f5f9;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
}

.tag-bitrix { background: #dbeafe; color: #1e40af; }
.tag-output { background: #ccfbf1; color: #0f766e; }
.tag-timing { background: #ede9fe; color: #5b21b6; }
.tag-assumed { background: #fef3c7; color: #92400e; }

.block-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }

.field {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 13px;
  min-height: 68px;
}

.field-output {
  border-color: #99f6e4;
  background: linear-gradient(180deg, #fff, #f0fdfa);
}

.field label {
  display: block;
  font-size: 10px;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 5px;
}

.field .value {
  font-size: 17px;
  font-weight: 800;
  color: #0b1f3a;
  letter-spacing: -0.02em;
}

.field .value.small { font-size: 14px; font-weight: 700; }

.variants { display: grid; gap: 10px; }

.variant {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  cursor: pointer;
  background: #fff;
  transition: all .18s ease;
}

.variant:hover {
  border-color: var(--brand);
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(14, 165, 233, 0.1);
}

.variant.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.15);
  background: linear-gradient(180deg, #fff, #f0fdfa);
}

.variant-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-weight: 800;
  color: #0b1f3a;
  font-size: 13px;
}

.variant-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.metric {
  background: #f8fafc;
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 11px;
  color: var(--muted);
}

.metric b { color: #0f172a; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }

.kpi { padding: 14px 16px; }

.kpi-card {
  background: var(--surface2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 10px;
}

.kpi-card:last-child { margin-bottom: 0; }

.kpi-card .lbl {
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
  line-height: 1.35;
  margin-bottom: 8px;
}

.kpi-card .val {
  font-size: 22px;
  font-weight: 900;
  letter-spacing: -0.04em;
  color: #0f766e;
  line-height: 1.15;
}

.kpi-card:last-child .val {
  color: #0b1f3a;
  font-size: 20px;
}

.ship-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }

.ship-stat {
  border-radius: 12px;
  padding: 12px;
  text-align: center;
  background: var(--surface2);
  border: 1px solid var(--line);
}

.ship-stat .n { font-size: 24px; font-weight: 900; }
.ship-stat .t { font-size: 10px; color: var(--muted); margin-top: 3px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }
.ship-stat.ok .n { color: var(--success); }
.ship-stat.warn .n { color: var(--gold); }
.ship-stat.bad .n { color: var(--danger); }

.recent { font-size: 12px; }
.recent div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid #eef2f7;
}

.wh-select { margin-bottom: 12px; }

.wh-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.wh-grid div {
  background: var(--surface2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  font-size: 12px;
  line-height: 1.4;
}

.wh-grid b { font-size: 18px; color: #0b1f3a; }

.empty { padding: 32px 20px; text-align: center; color: var(--muted); font-size: 13px; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 30;
  padding: 20px;
}

.modal.open { display: flex; }

.modal-box {
  background: #fff;
  border-radius: 20px;
  width: min(980px, 100%);
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.2);
}

.modal-head { padding: 20px 22px 0; }
.modal-head h2 { margin: 0 0 6px; font-size: 20px; color: #0b1f3a; }
.modal-head p { margin: 0; color: var(--muted); font-size: 13px; }

.tabs {
  display: flex;
  gap: 8px;
  padding: 14px 22px 0;
  flex-wrap: wrap;
}

.tab {
  border: 1px solid var(--line);
  background: #f8fafc;
  color: #334155;
  border-radius: 999px;
  padding: 7px 13px;
  font-weight: 800;
  font-size: 12px;
  cursor: pointer;
}

.tab.active {
  background: linear-gradient(135deg, var(--brand), var(--accent));
  color: #fff;
  border-color: transparent;
}

.tab-panel { display: none; padding: 16px 22px 22px; }
.tab-panel.active { display: block; }

.logic-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.logic-table th, .logic-table td {
  border-bottom: 1px solid var(--line);
  padding: 9px 8px;
  text-align: left;
}

.logic-table th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.hint {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 12px;
}

.field-hint {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.35;
}

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar-right { position: static; }
  .card-list { max-height: 320px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .stats-cards.stats-layout { grid-template-columns: 1fr; }
  .ship-stats { grid-template-columns: 1fr; }
  .stat-card .val { font-size: 24px; }
}

/* Warehouse matrix page */
.warehouses-page { background: var(--bg-page); }

.wh-shell {
  max-width: none;
  width: 100%;
  margin: 16px 0 24px;
  padding: 0 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 14px;
  align-items: start;
}

.wh-shell-single {
  grid-template-columns: minmax(0, 1fr);
  max-width: 100%;
}

.wh-panel { min-width: 0; }

.wh-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.wh-title { font-size: 18px; font-weight: 800; }
.wh-subtitle { font-size: 12px; color: var(--muted); margin-top: 4px; max-width: 720px; }
.wh-legend { font-size: 14px; font-weight: 700; white-space: nowrap; }

.wh-table-wrap {
  overflow-x: auto;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.wh-matrix {
  width: 100%;
  min-width: 920px;
  border-collapse: collapse;
  font-size: 13px;
}

.wh-matrix th,
.wh-matrix td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 10px 12px;
  text-align: right;
  white-space: nowrap;
}

.wh-matrix th:last-child,
.wh-matrix td:last-child { border-right: 0; }

.wh-sticky-col {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface2);
  text-align: left !important;
  min-width: 240px;
  max-width: 360px;
  white-space: normal !important;
  font-weight: 700;
}

.wh-matrix thead th {
  background: #ecfdf5;
  color: #0f766e;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  position: sticky;
  top: var(--hero-height);
  z-index: 1;
}

.wh-matrix thead .wh-sticky-col { z-index: 3; background: #d1fae5; }

.wh-chevron {
  display: inline-block;
  width: 1.1em;
  margin-right: 6px;
  color: #0f766e;
  font-size: 11px;
}

.wh-section-row.expanded .wh-row-label { background: #ecfdf5; }

.wh-material-row .wh-material-label {
  padding-left: 28px;
  font-weight: 600;
  font-size: 12px;
  color: #334155;
  background: #fff;
}

.wh-material-row td { background: #fafbfc; font-size: 12px; }

.wh-row-label,
.wh-cell {
  cursor: pointer;
  transition: background .12s ease;
}

.wh-editing .wh-row-label { cursor: default; }

.wh-row-label:hover,
.wh-cell:hover { background: #f0fdfa; }

.wh-editing .wh-row-label:hover { background: #ecfdf5; }

.wh-editable { padding: 4px 6px !important; }

.wh-editing .wh-section-cell.wh-readonly {
  background: #f8fafc;
  color: #475569;
  cursor: default;
}

.wh-editing .wh-section-cell.wh-readonly:hover { background: #f8fafc; }

.wh-edit-input {
  width: 100%;
  min-width: 56px;
  border: 1px solid #99f6e4;
  border-radius: 8px;
  padding: 6px 8px;
  font: inherit;
  font-weight: 700;
  text-align: right;
  background: #fff;
  color: #0b1f3a;
}

.wh-edit-input:focus {
  outline: none;
  border-color: #14b8a6;
  box-shadow: 0 0 0 2px rgba(20, 184, 166, 0.2);
}

.wh-total-col {
  font-weight: 800;
  background: #f8fafc;
}

.wh-totals-row th,
.wh-totals-row td {
  background: #ecfdf5;
  font-weight: 800;
  border-top: 2px solid #99f6e4;
}

.wh-grand { color: #0f766e; }

.wh-detail-panel {
  position: sticky;
  top: calc(var(--hero-height) + 12px);
  max-height: calc(100vh - var(--hero-height) - 24px);
  overflow: auto;
}

.wh-detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.wh-detail-body { padding: 0 16px 16px; }

.wh-detail-block + .wh-detail-block { margin-top: 14px; }

.wh-detail-wh {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-weight: 800;
  font-size: 13px;
  margin-bottom: 8px;
  color: #0f766e;
}

.wh-detail-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.wh-detail-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}

.wh-detail-list li:last-child { border-bottom: 0; }
.wh-detail-list li span { flex: 1; min-width: 0; }
.wh-detail-list li b { white-space: nowrap; }
.wh-empty { color: var(--muted); justify-content: center !important; }
.wh-error { text-align: center; color: var(--danger); padding: 24px !important; }

.btn-sm { padding: 7px 12px; font-size: 12px; }

.wh-nav-active {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.55);
}

.wh-back-bar {
  margin-bottom: 8px;
}

@media (max-width: 1100px) {
  .wh-shell { grid-template-columns: 1fr; }
  .wh-detail-panel { position: static; max-height: none; }
}
