:root {
  --ink: #202124;
  --muted: #5f6368;
  --line: #c0c4c8;
  --head: #f8f9fa;
  --yellow: #fff59d;
  --top: #1d4ed8;
  --bg: #e8edf3;
  --uk-scale: 1;
  --rh: 36px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-height: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: .55rem 1.25rem;
  background: #fff;
  border-bottom: 1px solid #d1d5db;
  flex-shrink: 0;
}
.brand { display: flex; gap: .65rem; align-items: center; }
.mark {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--top); color: #fff;
  display: grid; place-items: center; font-weight: 800;
}
.brand strong { display: block; font-size: .98rem; letter-spacing: -.02em; }
.brand span { display: block; font-size: .75rem; color: var(--muted); }
.top-actions { display: flex; gap: .55rem; align-items: center; flex-wrap: wrap; }
.toggle { font-size: .82rem; color: var(--muted); display: flex; gap: .35rem; align-items: center; }
button, .ghost {
  border: 1px solid #d1d5db;
  background: #fff;
  border-radius: 8px;
  padding: .35rem .7rem;
  font: inherit;
  font-size: .82rem;
  cursor: pointer;
}
a.ghost {
  text-decoration: none;
  color: inherit;
  display: inline-flex;
  align-items: center;
}
button:hover, .ghost:hover { background: #f3f4f6; }

.page {
  flex: 1;
  padding: 1rem 1.25rem 2.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.hint {
  margin: 0;
  padding: 0;
  font-size: .82rem;
  color: #4b5563;
  max-width: 52rem;
  line-height: 1.45;
}

.block-head {
  padding: .65rem .85rem .45rem;
  display: flex;
  flex-wrap: wrap;
  gap: .35rem 1rem;
  align-items: center;
  border-bottom: 1px solid #e5e7eb;
  flex-shrink: 0;
}
.block-head h2 {
  margin: 0;
  font-size: .98rem;
  letter-spacing: -.02em;
  flex: 1 1 auto;
  min-width: 8rem;
}
.block-head .block-desc {
  margin: 0;
  font-size: .78rem;
  color: var(--muted);
  flex: 1 1 100%;
}
.block-head p {
  margin: 0;
  font-size: .78rem;
  color: var(--muted);
}
.sheet-block {
  background: #fff;
  border: 1px solid #c5d4e3;
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, .06);
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: min(62vh, 720px);
}
.sheet-block.opi {
  border-color: #86efac;
  max-height: min(70vh, 780px);
}
.sheet-block.opi .block-head {
  background: #f0fdf4;
  border-bottom-color: #bbf7d0;
}
.sheet-block.opi .block-head h2 { color: #166534; }
.sheet-block.fact {
  border-color: #fdba74;
  max-height: min(70vh, 780px);
}
.sheet-block.fact .block-head {
  background: #fff7ed;
  border-bottom-color: #fed7aa;
}
.sheet-block.fact .block-head h2 { color: #9a3412; }
.sheet-block.cmp-block {
  max-height: none;
  border-color: #93c5fd;
}
.sheet-block.cmp-block .block-head {
  background: #eff6ff;
  border-bottom-color: #bfdbfe;
}
.sheet-block.cmp-block .block-head h2 { color: #1e3a8a; }
.block-head .section-toggle {
  align-self: center;
  flex-shrink: 0;
}
.block-head .desc-toggle {
  align-self: center;
  flex-shrink: 0;
  margin-left: auto;
  font-size: .75rem;
  padding: .2rem .55rem;
  color: #4b5563;
}
.block-head .desc-toggle.is-on {
  background: #e8eefc;
  border-color: #93b4f5;
  color: #1e3a8a;
}
.sheet-block.opi .desc-toggle.is-on {
  background: #dcfce7;
  border-color: #86efac;
  color: #166534;
}
.sheet-block.fact .desc-toggle.is-on {
  background: #ffedd5;
  border-color: #fdba74;
  color: #9a3412;
}
.sheet-block.ym {
  border-color: #facc15;
  max-height: min(70vh, 780px);
}
.sheet-block.ym .block-head {
  background: #fefce8;
  border-bottom-color: #fde047;
}
.sheet-block.ym .block-head h2 { color: #854d0e; }
.sheet-block.ym .desc-toggle.is-on {
  background: #fef9c3;
  border-color: #facc15;
  color: #854d0e;
}
.sheet-block.is-folded .block-head { border-bottom: none; }
.sheet-block.is-folded .cmp-body,
.sheet-block.is-folded .sheet-toolbar,
.sheet-block.is-folded .grid-wrap,
.sheet-block.is-folded .opi-legend,
.sheet-block.is-folded .block-desc,
.sheet-block.is-folded .desc-toggle { display: none; }
.sheet-block.is-folded { max-height: none; }
.sheet-block.desc-hidden .block-desc,
.sheet-block.desc-hidden .opi-legend,
.sheet-block.desc-hidden .cmp-note { display: none; }
.sheet-block.cmp-block.is-folded { max-height: none; }
.cmp-sku-name {
  font-size: .8rem;
  color: #4b5563;
  min-width: 0;
  flex: 1;
}
.cmp-wrap {
  padding: .65rem .75rem 1rem;
  overflow: auto;
}
.cmp-table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: .84rem;
}
.cmp-table col.metric { width: 28%; }
.cmp-table col.g,
.cmp-table col.opi,
.cmp-table col.fact { width: 24%; }
.cmp-table th,
.cmp-table td {
  border: 1px solid #e5e7eb;
  padding: .4rem .55rem;
  vertical-align: middle;
}
.cmp-table thead th {
  font-size: .78rem;
  font-weight: 700;
  text-align: center;
}
.cmp-table thead th.metric { text-align: left; background: #f8fafc; }
.cmp-table thead th.g { background: #f1f5f9; color: #334155; }
.cmp-table thead th.opi { background: #dcfce7; color: #166534; }
.cmp-table thead th.fact { background: #ffedd5; color: #9a3412; }
.cmp-table td.metric {
  text-align: left;
  color: #334155;
  background: #f8fafc;
}
.cmp-table td.metric .sub {
  display: block;
  font-size: .72rem;
  color: #6b7280;
  font-weight: 400;
  margin-top: .1rem;
}
.cmp-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}
.cmp-table td.g { background: #fff; }
.cmp-table td.opi { background: #f0fdf4; }
.cmp-table td.fact { background: #fff7ed; }
.cmp-table tr.grp td {
  background: #e2e8f0;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: #475569;
  padding: .28rem .55rem;
}
.cmp-table td.empty { color: #9ca3af; }
.cmp-table td.neg { color: #b91c1c; }
.cmp-note {
  margin: .55rem 0 0;
  font-size: .76rem;
  color: #6b7280;
  line-height: 1.4;
}
#cmp-article,
#cmp-gtype {
  min-width: 12rem;
  max-width: 28rem;
}
.ozon-status {
  font-size: .78rem;
  color: #6b7280;
}
.ozon-status.ok { color: #166534; }
.ozon-status.bad { color: #b91c1c; }
.opi-legend {
  margin: 0;
  padding: .4rem .85rem .55rem 1.6rem;
  font-size: .76rem;
  color: #4b5563;
  line-height: 1.4;
  flex-shrink: 0;
}
.opi-legend li { margin: 0 0 .12rem; }
.sheet-block.ym .opi-legend {
  border-top: 1px solid #e5e7eb;
  padding-top: .65rem;
  padding-bottom: .75rem;
}
.sheet-block.ym .opi-legend li { margin: 0 0 .35rem; }
.sheet-toolbar {
  display: flex;
  align-items: center;
  gap: .65rem;
  flex-wrap: wrap;
  padding: .5rem .75rem;
  border-bottom: 1px solid #e5e7eb;
  flex-shrink: 0;
}
.sheet-opt {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .8rem;
  color: #4b5563;
}
.sheet-opt select {
  font: inherit;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  padding: .28rem .4rem;
}
.col-menu-wrap { position: relative; }
.col-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 30;
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(15, 23, 42, .12);
  padding: .45rem;
  max-height: 320px;
  overflow: auto;
  min-width: 260px;
}
.col-menu label {
  display: flex;
  gap: .45rem;
  align-items: flex-start;
  font-size: .8rem;
  padding: .22rem .3rem;
  border-radius: 6px;
}
.col-menu label:hover { background: #f3f4f6; }
.col-menu .letter {
  font-weight: 700;
  color: #1d4ed8;
  min-width: 1.4rem;
}
.hidden-chips {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
  font-size: .75rem;
  color: #4b5563;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  background: #eef2f7;
  border-radius: 999px;
  padding: .12rem .45rem .12rem .55rem;
}
.chip button {
  border: 0;
  background: transparent;
  padding: 0;
  font-size: .85rem;
  line-height: 1;
  color: #6b7280;
}

.grid-wrap {
  overflow: auto;
  flex: 1;
  min-height: 220px;
  background: #fff;
  border-radius: 0 0 10px 10px;
}
.loading { padding: 2rem; color: var(--muted); }

table.sheet {
  border-collapse: separate;
  border-spacing: 0;
  font-size: calc(12px * var(--uk-scale));
  table-layout: fixed;
  width: max-content;
}
.sheet col {
  min-width: 0;
}
.sheet th, .sheet td {
  box-sizing: border-box;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: calc(2px * var(--uk-scale)) calc(5px * var(--uk-scale));
  white-space: normal;
  word-break: normal;
  overflow-wrap: break-word;
  hyphens: none;
  vertical-align: middle;
  line-height: 1.2;
  background: #fff;
  overflow: hidden;
}
.sheet .cell-clip {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  overflow-wrap: break-word;
  word-break: normal;
}
.sheet thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--head);
  font-weight: 650;
  text-align: center;
  line-height: 1.15;
  padding: 4px 10px 4px 4px;
}
.sheet thead tr.letters th {
  top: 0;
  z-index: 6;
  font-size: calc(10px * var(--uk-scale));
  color: var(--muted);
  font-weight: 600;
  padding: 2px 14px 2px 4px;
  height: calc(18px * var(--uk-scale));
  white-space: nowrap;
  overflow: hidden;
}
.sheet thead tr.titles th {
  top: calc(18px * var(--uk-scale));
  z-index: 5;
  height: calc(32px * var(--uk-scale));
  max-height: calc(32px * var(--uk-scale));
  overflow: hidden;
  vertical-align: top;
}
.sheet thead tr.groups th {
  top: 0;
  z-index: 6;
  font-size: calc(10px * var(--uk-scale));
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #374151;
  height: calc(22px * var(--uk-scale));
  white-space: nowrap;
  overflow: hidden;
}
.sheet thead tr.groups + .titles th {
  top: calc(22px * var(--uk-scale));
}
.g-sku { background: #eef2f7 !important; }
.g-inputs { background: #f8fafc !important; }
.g-price { background: #dbeafe !important; }
.g-mp { background: #ffedd5 !important; }
.g-gross { background: #dcfce7 !important; }
.g-tax { background: #fef9c3 !important; }
.g-net { background: #bbf7d0 !important; }
.g-cmp { background: #f3e8ff !important; }
td.g-gross-val { background: #f0fdf4; font-weight: 650; }
td.g-net-val { background: #ecfdf5; font-weight: 700; }
.sheet thead tr.titles .th-label {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  line-height: 1.15;
  max-height: 2.3em;
  word-break: normal;
  overflow-wrap: break-word;
  hyphens: none;
}
.sheet .rh {
  position: sticky;
  left: 0;
  z-index: 4;
  background: var(--head);
  text-align: center;
  color: var(--muted);
  font-size: calc(10px * var(--uk-scale));
  width: var(--rh);
  min-width: var(--rh);
  max-width: var(--rh);
  overflow: hidden;
}
.sheet thead .rh { z-index: 8; }
.sheet td.sticky, .sheet th.sticky { position: sticky; z-index: 3; }
.sheet td.sticky { background: #fff; box-shadow: 1px 0 0 var(--line); }
.sheet td.sticky.input { background: var(--yellow); }
.sheet tr.group td.sticky { background: #dbe4f0; }
.sheet tr.section td.sticky { background: #e8eaed; }
.sheet thead th.sticky { z-index: 7; }
.sheet td.input {
  background: var(--yellow);
  cursor: text;
}
.sheet td.input:focus, .sheet td.input.editing {
  outline: 2px solid #1d4ed8;
  outline-offset: -2px;
}
.sheet tr.group td {
  background: #dbe4f0;
  font-weight: 700;
}
.sheet tr.section td {
  background: #e8eaed;
  font-weight: 700;
}
.sheet tr.hidden-row { display: none; }
body.show-hidden tr.hidden-row { display: table-row; }
body.show-hidden tr.hidden-row.user-collapsed { display: none; }
.sheet tr.hidden-row td { opacity: .82; }
.sheet tr.user-collapsed { display: none !important; }
.sheet td.num { text-align: right; font-variant-numeric: tabular-nums; }
.sheet input.cell-edit {
  width: 100%;
  border: 0;
  padding: 0;
  font: inherit;
  background: transparent;
  outline: none;
}
.neg { color: #b91c1c; }

.col-resizer {
  position: absolute;
  top: 0;
  right: -2px;
  width: 10px;
  height: 100%;
  cursor: col-resize;
  z-index: 9;
}
.col-resizer:hover,
.col-resizer.is-active {
  background: linear-gradient(to right, transparent 3px, #2563eb 3px, #2563eb 7px, transparent 7px);
}
.sheet thead th { position: sticky; }
body.is-resizing { cursor: col-resize; user-select: none; }
body.is-resizing * { cursor: col-resize !important; }
.col-hide {
  position: absolute;
  top: 1px;
  right: 8px;
  border: 0;
  background: transparent;
  padding: 0 2px;
  font-size: 11px;
  line-height: 1;
  color: #9ca3af;
  display: none;
}
.sheet thead tr.letters th:hover .col-hide,
.sheet.opi-sheet thead tr.titles th:hover .col-hide { display: inline; }
.sheet thead th { position: sticky; }

.group-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-right: 4px;
  border: 1px solid #9aa7b8;
  border-radius: 4px;
  background: #fff;
  font-size: 12px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  vertical-align: middle;
}
.section-toggle {
  width: 20px;
  height: 20px;
  font-weight: 700;
  border-color: #1d4ed8;
  color: #1d4ed8;
}
.section-btns { display: inline-flex; gap: .35rem; flex-wrap: wrap; }
.section-btns .ghost.is-on {
  background: #e8eefc;
  border-color: #93b4f5;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: #eef2f7;
}
.login-card {
  width: min(380px, calc(100% - 2rem));
  background: #fff;
  border-radius: 16px;
  padding: 1.4rem 1.3rem 1.2rem;
  box-shadow: 0 10px 30px rgba(21,32,54,.08);
  display: grid;
  gap: .7rem;
}
.login-card h1 { margin: 0; letter-spacing: -.03em; }
.login-card .eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: .06em;
  font-size: .72rem;
  color: var(--top);
  font-weight: 700;
}
.login-card .lead { margin: 0; color: var(--muted); font-size: .92rem; }
.login-card label { display: grid; gap: .3rem; font-size: .85rem; }
.login-card input {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .55rem .7rem;
  font: inherit;
}
.login-card button {
  background: var(--top);
  color: #fff;
  border: 0;
  min-height: 40px;
  font-weight: 650;
}
.login-card .error { margin: 0; color: #b91c1c; font-size: .85rem; }

.top-actions a.ghost.is-here {
  background: #dbeafe;
  border-color: #93c5fd;
  color: #1e3a8a;
}
.draft-badge {
  font-size: .78rem;
  color: #1e3a8a;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  padding: .22rem .65rem;
  max-width: 28rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.admin-form, .admin-users { padding: .85rem 1rem 1.1rem; display: grid; gap: .85rem; }
.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: .65rem .85rem;
  align-items: end;
}
.admin-grid label, .period-title-field {
  display: grid;
  gap: .28rem;
  font-size: .82rem;
  color: #334155;
}
.admin-grid input, .period-title-field input, .period-choice select, .period-choice input[type="date"] {
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: .42rem .55rem;
  font: inherit;
}
.admin-flags {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
}
.admin-flag-title {
  margin: 0 0 .35rem;
  font-size: .78rem;
  font-weight: 700;
  color: #1e3a8a;
}
.admin-check {
  display: flex;
  gap: .4rem;
  align-items: flex-start;
  font-size: .84rem;
  margin: .18rem 0;
}
.admin-card {
  border: 1px solid #dbeafe;
  border-radius: 12px;
  padding: .75rem .85rem;
  background: #fff;
  display: grid;
  gap: .7rem;
}
.admin-card-head { display: flex; flex-wrap: wrap; gap: .35rem .75rem; align-items: baseline; }
.admin-login { color: #64748b; font-size: .85rem; }
.admin-role {
  font-size: .75rem;
  color: #166534;
  background: #dcfce7;
  border-radius: 999px;
  padding: .1rem .5rem;
}
.admin-card-actions { display: flex; gap: .5rem; }
.admin-card-actions .danger { color: #991b1b; border-color: #fecaca; background: #fef2f2; }
.admin-page .admin-form button[type="submit"],
.admin-card-actions button[data-save] {
  background: #1d4ed8;
  color: #fff;
  border-color: #1d4ed8;
}
.plan-toast.is-bad { background: #991b1b; }

@media (max-width: 720px) {
  .admin-flags { grid-template-columns: 1fr; }
}

.sku-orders-link {
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  color: #1d4ed8;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  font: inherit;
  text-align: left;
  max-width: 100%;
}
.sku-orders-link:hover { color: #1e40af; }

.ym-orders-dialog {
  width: min(960px, calc(100vw - 2rem));
  max-height: min(82vh, 760px);
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 0;
  box-shadow: 0 20px 50px rgba(15, 23, 42, .18);
}
.ym-orders-dialog::backdrop { background: rgba(15, 23, 42, .45); }
.ym-orders-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: .9rem 1rem;
  border-bottom: 1px solid #fde047;
  background: #fefce8;
}
.ym-orders-head h3 { margin: 0; font-size: 1.05rem; color: #854d0e; }
.ym-orders-sub { margin: .28rem 0 0; color: #64748b; font-size: .85rem; }
.ym-orders-body { overflow: auto; padding: .6rem .8rem 1rem; }
.ym-orders-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.ym-orders-table th,
.ym-orders-table td {
  border-bottom: 1px solid #e5e7eb;
  padding: .42rem .45rem;
  text-align: left;
  vertical-align: top;
}
.ym-orders-table th.num,
.ym-orders-table td.num { text-align: right; white-space: nowrap; }
.ym-orders-table .need {
  display: inline-block;
  margin: 0 .25rem .2rem 0;
  padding: .12rem .42rem;
  border-radius: 999px;
  background: #fef3c7;
  font-size: .75rem;
}
.ym-orders-table .need.ok { background: #dcfce7; color: #166534; }
.ym-orders-table .need.warn { background: #fee2e2; color: #991b1b; }
.ym-orders-table tr.out td { color: #64748b; }
.ym-orders-table tfoot td { font-weight: 600; background: #f8fafc; }

@media (max-width: 720px) {
  .page { padding: .75rem .7rem 1.5rem; }
  .sheet-block { max-height: 78vh; }
  .sheet-block.is-folded,
  .sheet-block.cmp-block { max-height: none; }
  #cmp-article, #cmp-gtype { min-width: 0; max-width: 100%; }
}
