:root {
  color-scheme: light;
  --ink: #182136;
  --muted: #687188;
  --line: #dde2ec;
  --line-strong: #cbd2df;
  --surface: #ffffff;
  --surface-soft: #f5f7fb;
  --canvas: #edf1f6;
  --primary: #335cff;
  --primary-hover: #2449df;
  --primary-soft: #edf1ff;
  --good: #14805a;
  --good-soft: #eaf8f2;
  --warn: #a85f00;
  --warn-soft: #fff5e6;
  --danger: #c43849;
  --danger-soft: #fff0f2;
  --shadow: 0 12px 34px rgba(25, 35, 55, .08);
  --radius: 13px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--canvas); }
body { margin: 0; min-width: 320px; color: var(--ink); background: var(--canvas); }
button, input, select { font: inherit; }
button, summary { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 3px solid rgba(51, 92, 255, .24);
  outline-offset: 2px;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 5px; font-size: clamp(22px, 2vw, 28px); line-height: 1.14; letter-spacing: -.025em; }
h2 { margin-bottom: 5px; font-size: 19px; line-height: 1.2; letter-spacing: -.015em; }
h3 { margin-bottom: 4px; font-size: 15px; }

.app-shell { min-height: 100vh; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 62px;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 22px;
  color: #f8faff;
  background: #172033;
  box-shadow: 0 4px 18px rgba(15, 23, 38, .16);
}
.brand { display: inline-flex; align-items: center; gap: 10px; min-width: 220px; color: inherit; text-decoration: none; }
.brand__mark { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 9px; color: #172033; background: #fff; font-weight: 900; letter-spacing: -.04em; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; }
.brand small { margin-top: 1px; color: #aeb9ce; font-size: 11px; font-weight: 500; }
.save-status { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; color: #c4cede; font-size: 12px; }
.save-status__dot { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: var(--good); }
.save-status.is-working .save-status__dot { background: #7fa0ff; animation: pulse 1s infinite; }
.save-status.is-error .save-status__dot { background: #ff7d8b; }
@keyframes pulse { 50% { opacity: .25; } }
.topbar__actions { display: flex; gap: 8px; }

.button {
  min-height: 38px;
  padding: 8px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  font-weight: 700;
  line-height: 1.1;
}
.button:hover { background: var(--surface-soft); }
.button--primary { color: #fff; border-color: var(--primary); background: var(--primary); }
.button--primary:hover { background: var(--primary-hover); }
.button--quiet { color: var(--muted); border-color: transparent; background: transparent; }
.topbar .button--quiet { color: #c8d1e2; }
.topbar .button--quiet:hover { color: #fff; background: rgba(255,255,255,.08); }
.button--dashed { color: var(--muted); border-style: dashed; }
.icon-button { width: 34px; height: 34px; display: inline-grid; place-items: center; padding: 0; border: 1px solid var(--line); border-radius: 7px; color: var(--muted); background: #fff; font-size: 16px; }
.icon-button:hover { color: var(--ink); background: var(--surface-soft); }
.icon-button--danger:hover { color: var(--danger); border-color: #efb8c0; background: var(--danger-soft); }

.global-message { margin: 14px auto 0; width: min(1400px, calc(100% - 32px)); padding: 11px 13px; border: 1px solid #efb8c0; border-radius: 9px; color: var(--danger); background: var(--danger-soft); font-size: 13px; }
.workspace { width: min(1440px, 100%); margin: 0 auto; padding: 18px 20px 42px; }
.screen { display: none; }
.screen.is-active { display: block; }
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.panel-heading { padding: 16px 17px 12px; }
.panel-heading--inline { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.kicker { margin-bottom: 5px; color: var(--muted); font-size: 10px; font-weight: 850; letter-spacing: .09em; text-transform: uppercase; }
.muted { margin-bottom: 0; color: var(--muted); font-size: 12px; line-height: 1.45; }

.preset-panel { margin-bottom: 14px; }
.preset-list { display: flex; gap: 8px; padding: 0 16px 13px; overflow-x: auto; scrollbar-width: thin; }
.preset-button { flex: 0 0 auto; min-height: 39px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: #fff; font-weight: 760; white-space: nowrap; }
.preset-button:hover { border-color: #aeb9ce; background: var(--surface-soft); }
.preset-button.is-active { color: var(--primary); border-color: #9eafff; background: var(--primary-soft); }
.preset-button.is-local::after { content: "локальный"; margin-left: 7px; color: var(--muted); font-size: 9px; font-weight: 700; }
.sheet-facts { display: flex; flex-wrap: wrap; gap: 1px; border-top: 1px solid var(--line); background: var(--line); border-radius: 0 0 var(--radius) var(--radius); overflow: hidden; }
.sheet-fact { flex: 1 1 175px; min-width: 0; padding: 10px 13px; background: #fbfcfe; }
.sheet-fact span { display: block; color: var(--muted); font-size: 10px; }
.sheet-fact strong { display: block; margin-top: 3px; font-size: 13px; }

.order-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(290px, .55fr); gap: 14px; align-items: start; }
.products-panel { min-width: 0; }
.product-list { padding: 0 14px 14px; }
.product-row { position: relative; padding: 12px 0; border-top: 1px solid #edf0f5; }
.product-row:first-child { border-top: 0; }
.product-row.is-disabled { opacity: .58; }
.product-row.is-disabled::after { content: "Строка отключена"; position: absolute; right: 7px; top: 4px; padding: 2px 6px; border-radius: 999px; color: var(--muted); background: var(--surface-soft); font-size: 9px; font-weight: 800; }
.product-row__main { display: grid; grid-template-columns: minmax(145px, 1.45fr) repeat(2, minmax(72px, .62fr)) minmax(90px, .72fr) minmax(65px, .46fr) minmax(68px, .48fr) repeat(2, minmax(58px, .4fr)) auto; gap: 7px; align-items: start; }
.product-row__actions { display: flex; gap: 4px; padding-top: 17px; }
.field { display: grid; gap: 4px; min-width: 0; }
.field > span { color: var(--muted); font-size: 10px; font-weight: 720; line-height: 1.15; }
.field input, .field select { width: 100%; min-height: 36px; min-width: 0; padding: 7px 8px; border: 1px solid #ccd3df; border-radius: 7px; color: var(--ink); background: #fff; }
.field input:hover, .field select:hover { border-color: #aeb8c9; }
.field input:focus, .field select:focus { border-color: var(--primary); outline: 3px solid rgba(51,92,255,.16); }
.field.has-error input, .field.has-error select { border-color: var(--danger); background: var(--danger-soft); }
.field-error { min-height: 0; margin-top: 6px; color: var(--danger); font-size: 11px; line-height: 1.35; }
.field-error:empty { display: none; }
.product-row__details { margin-top: 8px; }
.product-row__details summary { width: fit-content; color: var(--muted); font-size: 11px; font-weight: 700; }
.product-row__details[open] summary { margin-bottom: 9px; color: var(--ink); }
.details-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; padding: 10px; border-radius: 9px; background: var(--surface-soft); }
.field--wide { grid-column: span 2; }

.calculation-message { margin: 0 14px 10px; padding: 10px 12px; border-radius: 8px; font-size: 12px; line-height: 1.4; }
.calculation-message--working { color: var(--primary); background: var(--primary-soft); }
.calculation-message--error { color: var(--danger); background: var(--danger-soft); }

.summary-panel { position: sticky; top: 78px; }
.summary-content { padding: 0 16px 16px; }
.summary-empty { padding: 15px; border: 1px dashed var(--line-strong); border-radius: 9px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.summary-hero { padding: 14px; border-radius: 10px; background: var(--primary-soft); }
.summary-hero__badges { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 7px; }
.badge { display: inline-flex; align-items: center; min-height: 21px; padding: 2px 7px; border-radius: 999px; color: var(--good); background: var(--good-soft); font-size: 9px; font-weight: 850; letter-spacing: .02em; }
.badge--primary { color: var(--primary); background: #dfe6ff; }
.badge--muted { color: var(--muted); background: #e9edf4; }
.badge--warn { color: var(--warn); background: var(--warn-soft); }
.summary-hero strong { display: block; margin-bottom: 2px; font-size: 28px; letter-spacing: -.025em; }
.summary-hero span:last-child { color: var(--muted); font-size: 11px; }
.metric-list { margin: 11px 0 0; padding: 0; list-style: none; }
.metric-list li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid #edf0f5; font-size: 12px; }
.metric-list li:last-child { border-bottom: 0; }
.metric-list strong { text-align: right; }
.summary-actions { display: grid; gap: 7px; margin-top: 12px; }

.quick-comparison { margin-top: 14px; overflow: hidden; }
.quick-metrics { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 1px; border-top: 1px solid var(--line); background: var(--line); }
.quick-metric { min-width: 0; padding: 12px 14px; background: #fff; }
.quick-metric span { display: block; color: var(--muted); font-size: 10px; }
.quick-metric strong { display: block; margin-top: 3px; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quick-metric em { display: block; min-height: 14px; margin-top: 2px; color: var(--good); font-size: 9px; font-style: normal; }

.screen-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin: 3px 0 15px; }
.screen-heading__actions { display: flex; gap: 8px; align-items: center; }
.scope-note { margin-bottom: 12px; padding: 10px 12px; border: 1px solid #efdbb6; border-radius: 8px; color: #7d5417; background: #fff9ed; font-size: 11px; line-height: 1.45; }
.alternatives-list { display: grid; gap: 9px; }
.alternative-card { display: grid; grid-template-columns: minmax(210px, 1.35fr) repeat(5, minmax(85px, .65fr)) auto; gap: 1px; align-items: stretch; border: 1px solid var(--line); border-radius: 10px; background: var(--line); overflow: hidden; box-shadow: var(--shadow); }
.alternative-card.is-selected { border-color: #9dafef; box-shadow: 0 0 0 2px rgba(51,92,255,.12), var(--shadow); }
.alternative-cell { min-width: 0; padding: 12px; background: #fff; }
.alternative-cell--title { display: grid; align-content: center; }
.alternative-cell span { display: block; color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .04em; }
.alternative-cell strong { display: block; margin-top: 4px; font-size: 14px; overflow: hidden; text-overflow: ellipsis; }
.alternative-cell--title strong { font-size: 14px; }
.alternative-card__badges { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 4px; }
.alternative-action { display: grid; place-items: center; min-width: 112px; padding: 8px; background: #fff; }

.segmented { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.segmented button { min-height: 31px; padding: 5px 9px; border: 0; border-radius: 6px; color: var(--muted); background: transparent; font-weight: 700; }
.segmented button.is-active { color: var(--primary); background: var(--primary-soft); }
.layout-workspace { display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 14px; align-items: start; }
.layout-canvas { min-height: 560px; display: grid; place-items: center; padding: clamp(16px, 3vw, 36px); background: #f7f9fc; overflow: auto; }
.layout-sheet { position: relative; width: min(100%, 950px); min-width: 520px; aspect-ratio: 650 / 313; display: grid; gap: 3px; padding: 18px 18px 32px; border: 1px solid #bcc5d3; background: #fff; box-shadow: 0 16px 35px rgba(35,45,63,.12); }
.layout-sheet::after { content: "зона захвата / нижнее поле"; position: absolute; left: 0; right: 0; bottom: 8px; color: var(--muted); font-size: 9px; text-align: center; }
.layout-cell { min-width: 0; display: grid; place-items: center; padding: 3px; border: 1px solid #8da2d7; color: #334160; background: #edf2ff; font-size: 9px; font-weight: 750; text-align: center; overflow: hidden; }
.layout-cell:nth-child(3n) { border-color: #70a38c; background: #eaf8f2; }
.layout-cell small { display: block; margin-top: 2px; font-size: 8px; font-weight: 600; }
.layout-details { position: sticky; top: 78px; padding: 16px; }
.layout-details .metric-list { margin-top: 8px; }
.layout-empty { color: var(--muted); font-size: 12px; line-height: 1.5; }

.mobile-nav { display: none; }
.dialog { width: min(620px, calc(100% - 26px)); max-height: calc(100vh - 30px); padding: 0; border: 0; border-radius: 14px; color: var(--ink); background: #fff; box-shadow: 0 24px 70px rgba(13, 20, 34, .28); }
.dialog::backdrop { background: rgba(12, 18, 30, .56); backdrop-filter: blur(2px); }
.dialog form { padding: 20px; }
.dialog-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 15px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; margin-top: 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.dialog-error { margin-top: 12px; padding: 9px 11px; border-radius: 8px; color: var(--danger); background: var(--danger-soft); font-size: 12px; }

@media (max-width: 1120px) {
  .workspace { padding-inline: 14px; }
  .order-grid { grid-template-columns: minmax(0, 1fr) 285px; }
  .product-row__main { grid-template-columns: minmax(150px, 1.35fr) repeat(2, minmax(66px, .52fr)) minmax(85px, .62fr) repeat(2, minmax(58px, .42fr)) auto; }
  .field--colors { display: none; }
  .alternative-card { grid-template-columns: minmax(190px, 1.2fr) repeat(4, minmax(78px, .6fr)) auto; }
  .alternative-cell[data-metric="passes"] { display: none; }
}

@media (max-width: 860px) {
  .topbar { height: 56px; padding: 0 12px; gap: 10px; }
  .brand { min-width: auto; }
  .brand small, .save-status { display: none; }
  .topbar__actions { margin-left: auto; }
  .topbar__actions .button--quiet { display: none; }
  .workspace { padding: 11px 10px 78px; }
  .panel-heading { padding: 13px 12px 10px; }
  .panel-heading--inline { gap: 10px; }
  .preset-list { padding-inline: 11px; }
  .sheet-facts { display: grid; grid-template-columns: 1fr 1fr; }
  .sheet-fact { min-width: 0; }
  .order-grid { display: block; }
  .summary-panel { position: static; margin-top: 10px; }
  .product-list { padding: 0 10px 10px; }
  .product-row__main { grid-template-columns: 1.25fr .75fr .75fr; gap: 7px; }
  .field--name { grid-column: span 2; }
  .field--colors { display: grid; }
  .product-row__actions { grid-column: 1 / -1; justify-content: flex-end; padding-top: 0; }
  .details-grid { grid-template-columns: 1fr 1fr; }
  .quick-metrics { grid-template-columns: repeat(2, 1fr); }
  .quick-metric:last-child { grid-column: 1 / -1; }
  .screen-heading { display: block; }
  .screen-heading > .button, .screen-heading__actions { margin-top: 10px; }
  .screen-heading__actions { justify-content: space-between; }
  .alternative-card { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; }
  .alternative-cell--title { grid-column: 1 / -1; }
  .alternative-cell[data-metric="passes"] { display: block; }
  .alternative-action { grid-column: 1 / -1; min-height: 48px; }
  .layout-workspace { display: block; }
  .layout-canvas { min-height: 370px; padding: 12px; }
  .layout-sheet { min-width: 620px; }
  .layout-details { position: static; margin-top: 10px; }
  .mobile-nav { position: fixed; z-index: 40; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(3, 1fr); padding-bottom: env(safe-area-inset-bottom); border-top: 1px solid var(--line); background: rgba(255,255,255,.97); box-shadow: 0 -5px 18px rgba(25,35,55,.08); backdrop-filter: blur(10px); }
  .mobile-nav button { min-height: 58px; display: grid; place-items: center; align-content: center; gap: 2px; border: 0; color: var(--muted); background: transparent; font-size: 10px; font-weight: 780; }
  .mobile-nav button span { width: 20px; height: 20px; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--line-strong); font-size: 9px; }
  .mobile-nav button.is-active { color: var(--primary); }
  .mobile-nav button.is-active span { color: #fff; border-color: var(--primary); background: var(--primary); }
}

@media (max-width: 520px) {
  h1 { font-size: 21px; }
  h2 { font-size: 17px; }
  .brand__mark { width: 31px; height: 31px; }
  .brand strong { font-size: 14px; }
  .topbar__actions .button--primary { min-height: 33px; padding: 6px 9px; font-size: 11px; }
  .panel { border-radius: 10px; box-shadow: none; }
  .panel-heading--inline { display: grid; }
  .panel-heading--inline .button { width: 100%; }
  .sheet-facts { grid-template-columns: 1fr; }
  .product-row__main { grid-template-columns: 1fr 1fr; }
  .field--name { grid-column: 1 / -1; }
  .product-row__actions { grid-column: 1 / -1; }
  .details-grid { grid-template-columns: 1fr; }
  .field--wide { grid-column: auto; }
  .quick-comparison { display: none; }
  .screen-heading__actions { display: grid; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; }
  .alternative-card { grid-template-columns: 1fr 1fr; }
  .alternative-cell { padding: 9px; }
  .alternative-cell strong { font-size: 13px; }
  .layout-canvas { min-height: 320px; align-items: start; overflow-x: auto; }
  .layout-sheet { width: 620px; min-width: 620px; }
  .form-grid { grid-template-columns: 1fr; }
  .field--wide { grid-column: 1; }
  .dialog form { padding: 16px; }
  .dialog-actions { display: grid; grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
