:root {
  --ink: #17202a;
  --muted: #667085;
  --line: #e4e7ec;
  --surface: #ffffff;
  --soft: #f6f7fb;
  --brand: #5b35d5;
  --brand-dark: #4323aa;
  --success: #067647;
  --success-bg: #ecfdf3;
  --error: #b42318;
  --shadow: 0 12px 32px rgba(24, 30, 42, .07);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--soft);
  font: 15px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
a { color: inherit; }
button, input { font: inherit; }

.topbar {
  min-height: 66px;
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #19152b;
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; font-weight: 730; }
.brand-mark {
  width: 36px; height: 36px; display: grid; place-items: center;
  border-radius: 10px; background: #fff; color: var(--brand); font-weight: 850;
}
.user-menu { display: flex; align-items: center; gap: 18px; color: #d6d1e8; font-size: 14px; }
.user-menu form { margin: 0; }
.link-button { border: 0; padding: 0; background: transparent; color: #fff; cursor: pointer; }

.nav-shell {
  display: flex; gap: 24px; padding: 0 28px; background: #fff; border-bottom: 1px solid var(--line); overflow-x: auto; white-space: nowrap;
}
.nav-shell a { padding: 15px 2px 12px; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; }
.nav-shell a[aria-current="page"] { color: var(--brand); border-color: var(--brand); font-weight: 700; }
.page-shell { max-width: 1180px; margin: 0 auto; padding: 34px 28px 64px; }
.page-heading { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 26px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(28px, 4vw, 40px); line-height: 1.1; letter-spacing: -.035em; }
h2 { margin-bottom: 3px; font-size: 20px; }
.eyebrow { margin-bottom: 7px; color: var(--brand); font-size: 12px; font-weight: 800; letter-spacing: .11em; text-transform: uppercase; }
.muted { margin-bottom: 0; color: var(--muted); }

.button { display: inline-flex; min-height: 44px; align-items: center; justify-content: center; padding: 10px 18px; border: 1px solid transparent; border-radius: 10px; text-decoration: none; font-weight: 720; cursor: pointer; }
.button.primary { background: var(--brand); color: #fff; box-shadow: 0 5px 15px rgba(91,53,213,.22); }
.button.primary:hover { background: var(--brand-dark); }
.button.secondary { border-color: #cfc7f3; background: #f6f3ff; color: var(--brand-dark); }
.button.secondary:hover { background: #eee9ff; }
.access-check-form { margin: -4px 0 18px; }
.access-check-form .button { width: 100%; }

.metric-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin-bottom: 24px; }
.metric-card, .panel, .integration-card, .auth-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.metric-card { min-height: 150px; padding: 22px; display: flex; flex-direction: column; }
.metric-card span { color: var(--muted); }
.metric-card strong { margin: auto 0 4px; font-size: 28px; letter-spacing: -.025em; }
.metric-card small { color: var(--muted); }
.metric-card.placeholder strong { font-size: 20px; color: #344054; }
.panel { padding: 24px; }
.panel-heading { margin-bottom: 18px; }

.launch-list { margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; list-style: none; }
.launch-list li { display: flex; gap: 10px; padding: 14px; border-radius: 12px; background: var(--soft); color: var(--muted); }
.launch-list li > span { width: 27px; height: 27px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 50%; background: #e9e7f2; font-weight: 800; }
.launch-list strong, .launch-list small { display: block; }
.launch-list small { margin-top: 3px; }
.launch-list .active { background: #f0edff; color: var(--ink); }
.launch-list .active > span { background: var(--brand); color: #fff; }
.launch-list .done { background: var(--success-bg); color: var(--ink); }
.launch-list .done > span { background: var(--success); color: #fff; }

.integration-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.integration-card { padding: 24px; }
.integration-head { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; margin-bottom: 22px; }
.integration-head h2, .integration-head p { margin: 0; }
.integration-head p { color: var(--muted); font-size: 13px; }
.market-logo { width: 46px; height: 46px; display: grid; place-items: center; border-radius: 13px; color: #fff; font-weight: 850; }
.market-logo.wb { background: linear-gradient(135deg, #cb11ab, #6611c9); }
.market-logo.ozon { background: #1469ff; }
.status { padding: 5px 9px; border-radius: 999px; background: #f2f4f7; color: var(--muted); font-size: 12px; font-weight: 760; }
.status.success { background: var(--success-bg); color: var(--success); }
.connection-summary { display: flex; justify-content: space-between; gap: 10px; margin: -8px 0 18px; padding: 10px 12px; border-radius: 9px; background: var(--success-bg); color: var(--success); font-size: 13px; }
.stack-form { display: grid; gap: 9px; }
.stack-form label { margin-top: 4px; font-weight: 680; }
.stack-form input { width: 100%; min-height: 44px; padding: 9px 12px; border: 1px solid #cfd4dc; border-radius: 9px; background: #fff; }
.stack-form input:focus { outline: 3px solid rgba(91,53,213,.13); border-color: var(--brand); }
.stack-form .button { margin-top: 7px; }
.field-help, .notice { margin: 0; color: var(--muted); font-size: 13px; }
.errorlist { margin: 0; padding: 8px 11px; border-radius: 8px; background: #fef3f2; color: var(--error); list-style: none; }
.security-note { margin-top: 20px; padding: 16px 18px; border: 1px solid #d9d5ef; border-radius: 12px; background: #f6f3ff; color: #41377a; }

.messages { margin-bottom: 18px; }
.message { padding: 12px 14px; border-radius: 10px; background: #eef1f5; }
.message.success { background: var(--success-bg); color: var(--success); }
.message.error { background: #fef3f2; color: var(--error); }
.message.warning { background: #fff4e8; color: #9a4c00; }
.auth-card { max-width: 430px; margin: 8vh auto 0; padding: 30px; }

@media (max-width: 800px) {
  .metric-grid, .integration-grid, .settings-grid { grid-template-columns: 1fr; }
  .launch-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page-heading { align-items: start; flex-direction: column; }
  .finance-load-form { width: 100%; min-width: 0; }
  .finance-load-form > small { text-align: left; }
}
@media (max-width: 520px) {
  .topbar { padding: 0 16px; }
  .brand > span:last-child { display: none; }
  .user-menu > span { display: none; }
  .nav-shell { padding: 0 16px; }
  .page-shell { padding: 24px 16px 48px; }
  .launch-list { grid-template-columns: 1fr; }
  .integration-head { grid-template-columns: auto 1fr; }
  .integration-head .status { grid-column: 1 / -1; justify-self: start; }
  .connection-summary { flex-direction: column; }
  .finance-load-actions { align-items: stretch; flex-direction: column; }
  .finance-load-actions input,
  .finance-load-actions select { width: 100%; }
}


.finance-heading { align-items: center; }
.finance-load-form {
  min-width: 470px;
  display: grid;
  gap: 6px;
}
.finance-load-form > label { font-weight: 700; }
.finance-load-form > small { color: var(--muted); text-align: right; }
.finance-load-actions { display: flex; gap: 10px; }
.finance-load-actions input,
.finance-load-actions select {
  min-width: 260px;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid #cfd4dc;
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}
.finance-load-actions input:focus,
.finance-load-actions select:focus {
  outline: 3px solid rgba(91,53,213,.13);
  border-color: var(--brand);
}
.finance-load-actions option.loaded-week-option {
  color: #8b93a1;
  background: #eef1f5;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, .85fr);
  gap: 20px;
  align-items: start;
}
.account-list {
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
  list-style: none;
}
.account-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px;
  border-radius: 11px;
  background: var(--soft);
}
.account-list strong, .account-list small { display: block; }
.account-list small { margin-top: 2px; color: var(--muted); }

.report-toolbar { margin-bottom: 20px; display: flex; justify-content: space-between; align-items: end; gap: 20px; }
.period-form { display: grid; gap: 8px; min-width: 680px; }
.period-form-title { font-weight: 700; }
.period-range-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(190px, 1fr)) auto;
  align-items: end;
  gap: 10px;
}
.period-range-field { display: grid; gap: 5px; }
.period-range-field > span { color: var(--muted); font-size: 12px; font-weight: 600; }
.period-form select {
  width: 100%; min-height: 44px; padding: 8px 36px 8px 12px;
  border: 1px solid #cfd4dc; border-radius: 9px;
  background: #fff; color: var(--ink); font: inherit;
}
.period-range-fields .button { min-height: 44px; white-space: nowrap; }
.compare-control { display: grid; gap: 4px; justify-items: end; }
.compare-control small { color: var(--muted); }
.comparison-open-form, .comparison-load-form { margin: 0; }
.comparison-panel { margin-bottom: 20px; }
.comparison-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 20px;
}
.comparison-heading .eyebrow { margin-bottom: 5px; }
.comparison-table-scroll { overflow-x: auto; }
.comparison-table {
  width: 100%;
  min-width: 1080px;
  border-collapse: collapse;
}
.comparison-table th,
.comparison-table td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  vertical-align: top;
}
.comparison-table th:first-child,
.comparison-table td:first-child { text-align: left; }
.comparison-table thead th {
  color: var(--muted);
  background: var(--soft);
  font-size: 12px;
}
.comparison-table thead th:first-child { border-radius: 10px 0 0 10px; }
.comparison-table thead th:last-child { border-radius: 0 10px 10px 0; }
.comparison-table tbody tr:last-child th,
.comparison-table tbody tr:last-child td { border-bottom: 0; }
.comparison-table td strong,
.comparison-table td small,
.comparison-table thead small { display: block; }
.comparison-table td small,
.comparison-table thead small {
  margin-top: 3px;
  color: var(--muted);
  font-weight: 500;
}
.comparison-confirmation-backdrop {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(23, 20, 43, .55);
  backdrop-filter: blur(3px);
}
.comparison-confirmation {
  width: min(720px, 100%);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding: 28px;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(23, 20, 43, .25);
}
.comparison-dialog-messages { margin: 16px 0; }
.comparison-dialog-error {
  display: grid;
  gap: 4px;
  padding: 13px 15px;
  border: 1px solid #ffc7bf;
  border-radius: 11px;
  background: var(--error-bg);
  color: var(--error);
  font-size: 13px;
  line-height: 1.45;
}
.comparison-dialog-error strong { font-size: 14px; }
.comparison-missing-ranges {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 20px 0;
}
.comparison-missing-ranges > div {
  padding: 14px;
  border-radius: 12px;
  background: var(--soft);
}
.comparison-missing-ranges > .comparison-range-loaded {
  border: 1px solid var(--line);
  background: #f3f4f6;
}
.comparison-range-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.comparison-range-status {
  flex: 0 0 auto;
  margin: 0 !important;
  padding: 4px 7px;
  border-radius: 999px;
  font-size: 10px !important;
  font-weight: 750;
  line-height: 1.2;
  white-space: nowrap;
}
.comparison-range-status.loaded { background: #e5e7eb; color: #4b5563; }
.comparison-range-status.missing { background: #fff0dd; color: #9a4c00; }
.comparison-missing-ranges strong,
.comparison-missing-ranges span { display: block; }
.comparison-missing-ranges span { margin-top: 2px; color: var(--muted); font-size: 13px; }
.comparison-missing-ranges ul {
  margin: 10px 0 0;
  padding-left: 18px;
  color: #344054;
  font-size: 13px;
}
.comparison-confirmation-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
}
.button:disabled { opacity: .52; cursor: not-allowed; box-shadow: none; }

.finance-metric-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px; margin-bottom: 20px;
}
.finance-metric {
  min-height: 128px; padding: 18px; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow);
}
.finance-metric span, .finance-metric small { color: var(--muted); }
.finance-metric strong { margin: auto 0 2px; font-size: 22px; line-height: 1.2; letter-spacing: -.025em; }
.finance-metric.primary-metric { grid-column: span 2; background: #231a45; color: #fff; border-color: #231a45; }
.finance-metric.primary-metric span, .finance-metric.primary-metric small { color: #d9d2f6; }
.finance-metric.primary-metric strong { font-size: 32px; }
.finance-metric.ozon-primary-metric { background: #0755d9; border-color: #0755d9; }
.finance-metric.ozon-primary-metric span,
.finance-metric.ozon-primary-metric small { color: #dbe8ff; }

.reconciliation-panel {
  margin-bottom: 20px; display: flex; justify-content: space-between; align-items: center; gap: 24px;
}
.reconciliation-panel h2 { margin-bottom: 5px; }
.reconciliation-ok, .reconciliation-warning {
  min-width: 220px; padding: 14px 16px; border-radius: 11px; display: grid;
}
.reconciliation-ok { background: var(--success-bg); color: var(--success); }
.reconciliation-warning { background: #fff4e8; color: #9a4c00; }
.reconciliation-ok span, .reconciliation-warning span { font-size: 12px; }
.reconciliation-ok strong, .reconciliation-warning strong { font-size: 20px; }
.reconciliation-ok small, .reconciliation-warning small { margin-top: 2px; font-size: 11px; }
.reconciliation-equation {
  margin: 10px 0 0;
  color: #41377a;
  font-size: 13px;
  font-weight: 750;
}

.breakdown-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px;
}
.breakdown-grid > div { padding: 14px; border-radius: 10px; background: var(--soft); display: grid; gap: 4px; }
.breakdown-grid span { color: var(--muted); font-size: 12px; }
.breakdown-grid strong { font-size: 16px; }
.ozon-breakdown-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.ozon-operation-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.operation-breakdown-card {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--soft);
}
.operation-breakdown-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.operation-breakdown-heading h3 { margin: 0 0 3px; font-size: 16px; }
.operation-breakdown-heading p { margin: 0; color: var(--muted); font-size: 12px; }
.operation-breakdown-heading > strong { flex: 0 0 auto; font-size: 18px; white-space: nowrap; }
.operation-breakdown-list { display: grid; }
.operation-breakdown-list > div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}
.operation-breakdown-list > div:last-child { border-bottom: 0; padding-bottom: 0; }
.operation-breakdown-list span { min-width: 0; font-size: 13px; font-weight: 650; }
.operation-breakdown-list span small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
}
.operation-breakdown-list strong { white-space: nowrap; }
.amount-expense { color: #b54708; }
.amount-income { color: var(--success); }

.product-finance-panel {
  width: min(1560px, calc(100vw - 56px));
  margin-top: 20px;
  margin-left: 50%;
  padding-left: 0;
  padding-right: 0;
  overflow: visible;
  transform: translateX(-50%);
}
.product-finance-panel .panel-heading { padding: 0 28px; }
.table-scroll { overflow: visible; }
.finance-table { width: 100%; min-width: 0; table-layout: fixed; border-collapse: collapse; }
.finance-table th:nth-child(1) { width: 24%; }
.finance-table th:nth-child(2) { width: 13%; }
.finance-table th:nth-child(3),
.finance-table th:nth-child(4),
.finance-table th:nth-child(5),
.finance-table th:nth-child(6) { width: 9%; }
.finance-table th:nth-child(7) { width: 12%; }
.finance-table th:nth-child(8) { width: 6%; }
.finance-table th:nth-child(9) { width: 9%; }
.finance-table th, .finance-table td {
  padding: 14px;
  border-top: 1px solid var(--line);
  text-align: right;
  vertical-align: middle;
}
.finance-table th {
  position: sticky;
  top: 0;
  z-index: 4;
  color: var(--muted);
  background: #fbfbfd;
  font-size: 12px;
  font-weight: 750;
  line-height: 1.25;
  white-space: normal;
  box-shadow: 0 1px 0 var(--line);
}
.finance-table th:first-child, .finance-table td:first-child {
  padding-left: 28px;
  text-align: left;
}
.finance-table th:last-child, .finance-table td:last-child { padding-right: 28px; }
.finance-table td { overflow: hidden; }
.finance-table td.logistics-cell { overflow: hidden; }
.finance-table td strong, .finance-table td small { display: block; }
.finance-table td:not(:first-child) strong { white-space: nowrap; }
.finance-table td small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
  white-space: normal;
  overflow-wrap: anywhere;
}
.product-cell {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}
.product-cell > div {
  min-width: 0;
  flex: 1 1 auto;
}
.product-cell img, .product-placeholder {
  width: 48px;
  height: 62px;
  flex: 0 0 auto;
  border-radius: 8px;
  object-fit: cover;
  background: #eeeafc;
}
.product-placeholder { display: grid; place-items: center; color: var(--brand); font-size: 11px; font-weight: 800; }
.product-placeholder.ozon-placeholder { background: #eaf2ff; color: #0755d9; font-size: 9px; }
.product-cell strong {
  max-width: 100%;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.product-cell small {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.logistics-popover { display: inline-block; }
.logistics-amount {
  padding: 2px 0;
  border: 0;
  border-bottom: 1px dashed #8c82b7;
  color: var(--text);
  background: transparent;
  font: inherit;
  white-space: nowrap;
  cursor: help;
}
.logistics-amount:hover,
.logistics-amount:focus-visible {
  color: var(--brand);
  border-bottom-color: var(--brand);
  outline: none;
}
.logistics-floating-card {
  position: fixed;
  z-index: 1000;
  width: min(480px, calc(100vw - 24px));
  padding: 14px;
  border: 1px solid #ddd8f0;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 18px 48px rgba(35, 24, 75, 0.2);
  color: var(--ink);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  text-align: left;
  transition: opacity 100ms ease;
}
.logistics-floating-card.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}
.logistics-popover-heading {
  display: grid;
  gap: 2px;
  margin-bottom: 10px;
}
.logistics-popover-heading strong { font-size: 15px; }
.logistics-popover-heading small {
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.logistics-popover-scroll {
  display: block;
  max-height: 270px;
  overflow-y: auto;
}
.logistics-floating-card table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.logistics-floating-card th,
.logistics-floating-card td {
  padding: 8px 7px;
  border-top: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}
.logistics-floating-card th:first-child,
.logistics-floating-card td:first-child { padding-left: 4px; text-align: left; }
.logistics-floating-card th:last-child,
.logistics-floating-card td:last-child { padding-right: 4px; }
.logistics-floating-card thead th {
  position: static;
  color: var(--muted);
  background: #fff;
  box-shadow: none;
  font-size: 11px;
}
.logistics-floating-card tfoot th {
  color: var(--text);
  background: var(--soft);
  font-weight: 800;
}
.logistics-result {
  display: inline-block;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}
.logistics-result.is-buyout { background: var(--success-bg); color: var(--success); }
.logistics-result.is-return { background: #fff0f0; color: #bf2d25; }
.empty-state { padding: 34px; text-align: center; }

@media (max-width: 1050px) {
  .product-finance-panel {
    width: calc(100vw - 32px);
    overflow: hidden;
  }
  .table-scroll { overflow-x: auto; }
  .finance-table { min-width: 1280px; }
}

@media (max-width: 900px) {
  .finance-metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .breakdown-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ozon-operation-columns { grid-template-columns: 1fr; }
}
@media (max-width: 650px) {
  .report-toolbar, .reconciliation-panel { align-items: stretch; flex-direction: column; }
  .period-form { min-width: 0; }
  .period-range-fields { grid-template-columns: 1fr; }
  .compare-control { justify-items: stretch; }
  .comparison-heading, .comparison-confirmation-actions { align-items: stretch; flex-direction: column; }
  .comparison-missing-ranges { grid-template-columns: 1fr; }
  .comparison-confirmation-actions .button { width: 100%; }
  .finance-metric-grid { grid-template-columns: 1fr; }
  .finance-metric.primary-metric { grid-column: auto; }
}

.password-field { position: relative; width: 100%; }
.password-field input { padding-right: 56px; }
.password-toggle { position: absolute; top: 50%; right: 3px; transform: translateY(-50%); display: grid; place-items: center; width: 42px; height: 40px; padding: 0; border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; }
.password-toggle[hidden] { display: none; }
.password-toggle:hover { background: var(--soft); color: var(--brand); }
.password-toggle:focus-visible { outline: 3px solid rgba(91,53,213,.3); outline-offset: -2px; }
.password-toggle-slash { display: none; }
.password-toggle[aria-pressed="true"] .password-toggle-slash { display: block; }
