:root {
  color-scheme: dark;
  --app-font-family: Inter, Segoe UI, Arial, sans-serif;
  --app-font-size: 16px;
  --app-font-scale: 1;
  --bg: #090b0d;
  --surface: #15191e;
  --surface-2: #1d232a;
  --ink: #f7f9fb;
  --muted: #b5c2cf;
  --control-ink: #fbfdff;
  --control-muted: #d9e4ef;
  --control-subtle: #c1cedb;
  --line: rgba(148, 163, 184, 0.22);
  --line-strong: rgba(148, 163, 184, 0.34);
  --accent: #4b93ff;
  --accent-2: #35c98d;
  --orange: #ff4500;
  --waste: #c88a2e;
  --remainder: #2dbb82;
  --kerf: #7a8491;
  --radius: 18px;
  --tap: 56px;
  --on-accent: #ffffff;
  --body-bg: linear-gradient(180deg, #11161a 0%, #0b0e11 48%, #07090b 100%);
  --panel-bg:
    linear-gradient(180deg, rgba(26, 31, 37, 0.92), rgba(17, 21, 25, 0.94));
  --panel-strong-bg:
    linear-gradient(180deg, rgba(23, 28, 34, 0.98), rgba(15, 19, 23, 0.98));
  --panel-shadow:
    0 22px 58px rgba(0, 0, 0, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.045);
  --lift-shadow:
    0 24px 64px rgba(0, 0, 0, 0.36),
    0 0 0 1px rgba(75, 147, 255, 0.12);
  --soft-row-bg: rgba(255, 255, 255, 0.032);
  --soft-row-hover-bg: rgba(255, 255, 255, 0.055);
  --control-bg:
    linear-gradient(180deg, rgba(34, 41, 49, 0.92), rgba(24, 30, 36, 0.94));
  --control-hover-bg:
    linear-gradient(180deg, rgba(41, 49, 58, 0.94), rgba(28, 35, 42, 0.96));
  --top-control-bg: rgba(16, 20, 24, 0.72);
  --top-control-border: rgba(255, 255, 255, 0.13);
  --janpol-bg:
    linear-gradient(135deg, rgba(75, 147, 255, 0.13), rgba(53, 201, 141, 0.08)),
    rgba(19, 23, 28, 0.94);
  --janpol-shine-hot: rgba(255, 116, 68, 0.28);
  --janpol-shine-cool: rgba(75, 147, 255, 0.2);
  --janpol-ink: #ffffff;
  --janpol-shadow: 0 0 18px rgba(75, 147, 255, 0.38), 0 0 26px rgba(53, 201, 141, 0.16);
  --active-border: rgba(137, 169, 199, 0.42);
  --active-gradient: linear-gradient(180deg, #45647e 0%, #263f55 100%);
  --active-gradient-hover:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 42%),
    linear-gradient(180deg, #4b6d89 0%, #2b4861 100%);
  --active-shadow:
    0 8px 18px rgba(0, 0, 0, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.14);
  --split-line: rgba(255, 255, 255, 0.14);
  --drag-float-bg: rgba(25, 31, 37, 0.98);
  --map-dot: rgba(75, 147, 255, 0.2);
  --map-bg: rgba(255, 255, 255, 0.018);
  --bar-track-bg: #0b0f13;
  --popover-bg:
    linear-gradient(180deg, rgba(28, 34, 41, 0.98), rgba(15, 19, 23, 0.98));
  --popover-shadow: 0 24px 80px rgba(0, 0, 0, 0.46), 0 0 0 1px rgba(255, 255, 255, 0.045) inset;
  --modal-backdrop: rgba(5, 8, 12, 0.72);
  --modal-panel-bg:
    linear-gradient(180deg, rgba(28, 34, 41, 0.98), rgba(15, 19, 23, 0.98));
  --modal-panel-shadow: 0 30px 90px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.04) inset;
  --link-card-bg: rgba(255, 255, 255, 0.04);
  --nav-bg: rgba(12, 15, 18, 0.9);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eef3f8;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --ink: #142033;
  --muted: #4a5b70;
  --control-ink: #102033;
  --control-muted: #24364d;
  --control-subtle: #53667c;
  --line: rgba(95, 112, 132, 0.22);
  --line-strong: rgba(95, 112, 132, 0.36);
  --accent: #2477dc;
  --accent-2: #18835f;
  --orange: #e8561e;
  --waste: #b97821;
  --remainder: #1e9b68;
  --kerf: #8794a3;
  --body-bg: linear-gradient(180deg, #ffffff 0%, #eef3f8 54%, #e7edf4 100%);
  --panel-bg:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(247, 250, 253, 0.96));
  --panel-strong-bg:
    linear-gradient(180deg, rgba(255, 255, 255, 0.99), rgba(249, 252, 255, 0.98));
  --panel-shadow:
    0 18px 48px rgba(37, 57, 82, 0.13),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
  --lift-shadow:
    0 22px 54px rgba(37, 57, 82, 0.17),
    0 0 0 1px rgba(36, 119, 220, 0.1);
  --soft-row-bg: rgba(24, 47, 75, 0.035);
  --soft-row-hover-bg: rgba(24, 47, 75, 0.06);
  --control-bg:
    linear-gradient(180deg, #f8fbff, #edf3f9);
  --control-hover-bg:
    linear-gradient(180deg, #ffffff, #eef5fb);
  --top-control-bg: rgba(255, 255, 255, 0.78);
  --top-control-border: rgba(31, 49, 72, 0.14);
  --janpol-bg:
    linear-gradient(135deg, rgba(47, 135, 255, 0.18), rgba(49, 209, 139, 0.12)),
    rgba(255, 255, 255, 0.95);
  --janpol-shine-hot: rgba(232, 86, 30, 0.34);
  --janpol-shine-cool: rgba(47, 135, 255, 0.22);
  --janpol-ink: #17365c;
  --janpol-shadow: 0 1px 0 rgba(255, 255, 255, 0.9), 0 10px 22px rgba(47, 135, 255, 0.18);
  --active-border: rgba(48, 92, 126, 0.3);
  --active-gradient: linear-gradient(180deg, #5f83a2, #3d6686);
  --active-gradient-hover:
    linear-gradient(180deg, rgba(255, 255, 255, 0.26), transparent 44%),
    linear-gradient(180deg, #668dac, #426d8f);
  --active-shadow:
    0 8px 18px rgba(38, 69, 100, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.42);
  --split-line: rgba(30, 45, 63, 0.12);
  --drag-float-bg: rgba(255, 255, 255, 0.98);
  --map-dot: rgba(47, 135, 255, 0.18);
  --map-bg: rgba(31, 117, 216, 0.03);
  --bar-track-bg: #e7eef6;
  --popover-bg:
    linear-gradient(180deg, rgba(255, 255, 255, 0.99), rgba(247, 251, 255, 0.98));
  --popover-shadow: 0 24px 80px rgba(37, 57, 82, 0.2), 0 0 0 1px rgba(255, 255, 255, 0.72) inset;
  --modal-backdrop: rgba(11, 24, 38, 0.42);
  --modal-panel-bg:
    linear-gradient(180deg, rgba(255, 255, 255, 0.99), rgba(247, 251, 255, 0.98));
  --modal-panel-shadow: 0 30px 90px rgba(37, 57, 82, 0.22), 0 0 0 1px rgba(255, 255, 255, 0.72) inset;
  --link-card-bg: rgba(24, 47, 75, 0.04);
  --nav-bg: rgba(255, 255, 255, 0.9);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  background: var(--body-bg);
  color: var(--ink);
  font-family: var(--app-font-family);
  font-size: var(--app-font-size);
  line-height: 1.45;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
}

button {
  color: var(--control-ink);
}

button span,
button b {
  color: inherit;
}

button,
select {
  cursor: pointer;
}

.svg-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.ui-icon {
  display: inline-block;
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.primary,
.ghost,
.topbar-info-button,
.segmented button,
.top-tabs button,
.drag-handle,
.remove-cut,
.info-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.primary,
.ghost,
.topbar-info-button,
.segmented button,
.top-tabs button {
  gap: 8px;
}

.drag-handle .ui-icon,
.remove-cut .ui-icon {
  width: 20px;
  height: 20px;
}

.app {
  width: min(1168px, 100%);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: 8px 14px max(10px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.topbar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  align-items: stretch;
  margin-bottom: 6px;
  transition:
    margin-bottom 220ms ease,
    row-gap 220ms ease;
}

.topbar-hero,
.sheet,
.result-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-bg);
  box-shadow: var(--panel-shadow);
  backdrop-filter: blur(18px);
}

.topbar-hero {
  /* Три равные зоны держат баннер Janpol точно по центру панели, а служебные элементы остаются по бокам. */
  position: relative;
  z-index: 14;
  display: grid;
  grid-template-areas: "brand mark actions";
  grid-template-columns: minmax(0, 1fr) minmax(440px, 0.92fr) minmax(0, 1fr);
  min-width: 0;
  max-height: 116px;
  min-height: 84px;
  overflow: hidden;
  gap: 12px;
  align-items: center;
  padding: 9px 12px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.045), transparent 20%, transparent 80%, rgba(255, 255, 255, 0.035)),
    var(--panel-bg);
  transition:
    max-height 240ms ease,
    min-height 240ms ease,
    padding 240ms ease,
    border-color 180ms ease,
    box-shadow 180ms ease,
    opacity 180ms ease,
    transform 240ms ease;
}

.topbar-hero::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background:
    linear-gradient(90deg, rgba(75, 147, 255, 0.06), transparent 28%),
    linear-gradient(270deg, rgba(53, 201, 141, 0.055), transparent 30%);
  pointer-events: none;
}

.brand {
  grid-area: brand;
  position: relative;
  z-index: 1;
  display: flex;
  min-width: 0;
  gap: 14px;
  align-items: center;
  overflow: hidden;
  padding: 2px 0;
}

.brand-copy {
  min-width: 0;
}

.brand img {
  width: 54px;
  height: 54px;
  border-radius: 15px;
  object-fit: cover;
  filter:
    drop-shadow(0 10px 18px rgba(0, 0, 0, 0.22))
    drop-shadow(0 0 10px rgba(75, 147, 255, 0.12));
}

.brand strong {
  display: block;
  font-size: clamp(calc(21px * var(--app-font-scale)), calc(2.3vw * var(--app-font-scale)), calc(31px * var(--app-font-scale)));
  line-height: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand span {
  display: block;
  margin-top: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--control-muted);
  font-size: calc(14px * var(--app-font-scale));
}

.topbar-actions {
  grid-area: actions;
  position: relative;
  z-index: 1;
  display: flex;
  min-width: 0;
  justify-content: flex-end;
  align-items: center;
}

.janpol-mark {
  --shine-x: 15%;
  grid-area: mark;
  position: relative;
  z-index: 1;
  display: grid;
  isolation: isolate;
  justify-self: center;
  width: min(100%, 620px);
  max-height: 72px;
  min-height: 62px;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: 15px;
  background: var(--janpol-bg);
  color: var(--janpol-ink);
  font-size: clamp(calc(34px * var(--app-font-scale)), calc(4.2vw * var(--app-font-scale)), calc(50px * var(--app-font-scale)));
  font-weight: 950;
  text-shadow: var(--janpol-shadow);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 18px 38px rgba(0, 0, 0, 0.18),
    0 0 0 1px rgba(75, 147, 255, 0.08);
  transition:
    max-height 240ms ease,
    min-height 240ms ease,
    border-color 180ms ease,
    box-shadow 180ms ease,
    opacity 180ms ease,
    transform 240ms ease;
}

.topbar.is-scrolled {
  row-gap: 0;
  margin-bottom: 8px;
}

.topbar.is-scrolled .top-tabs {
  margin-top: 0;
}

.topbar.is-scrolled .topbar-hero {
  max-height: 0;
  min-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  border-width: 0;
  border-color: transparent;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-16px);
  box-shadow: none;
}

.janpol-mark>span {
  position: relative;
  z-index: 2;
  pointer-events: none;
}

.janpol-mark::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(circle at var(--shine-x) 46%, var(--janpol-shine-hot), transparent 30%),
    radial-gradient(circle at calc(var(--shine-x) + 12%) 54%, var(--janpol-shine-cool), transparent 24%);
  opacity: 0.18;
  transition: opacity 160ms ease;
  pointer-events: none;
}

.janpol-mark:hover::before {
  opacity: 1;
}

.janpol-mark::after {
  content: "";
  position: absolute;
  inset: auto 18px 12px;
  z-index: 1;
  height: 2px;
  border-radius: 99px;
  background: linear-gradient(90deg, transparent, var(--orange), var(--accent), transparent);
}

.topbar-info-button {
  flex: 0 0 auto;
  margin-left: auto;
  min-height: 36px;
  padding: 0 11px;
  border: 1px solid var(--top-control-border);
  border-radius: 12px;
  background: var(--top-control-bg);
  color: var(--control-ink);
  font-size: 13px;
  font-weight: 900;
  line-height: 1;
  text-shadow: none;
  backdrop-filter: blur(10px);
}

.topbar-info-button:focus-visible {
  outline: 0;
  box-shadow: 0 0 0 3px rgba(75, 147, 255, 0.22);
}

main {
  position: relative;
  z-index: 10;
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 0;
  overflow: auto;
  padding: 0 2px 10px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

main::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

.screen {
  display: none;
  gap: 10px;
}

.scroll-sentinel {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  pointer-events: none;
}

.screen.active {
  display: grid;
  animation: screen-in 220ms ease both;
}

@keyframes screen-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.sheet {
  padding: 16px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
  margin-bottom: 14px;
}

.section-head span {
  display: block;
  color: var(--accent);
  font-size: calc(12px * var(--app-font-scale));
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(calc(28px * var(--app-font-scale)), calc(5.4vw * var(--app-font-scale)), calc(38px * var(--app-font-scale)));
  line-height: 1.08;
}

h2 {
  font-size: clamp(calc(22px * var(--app-font-scale)), calc(4.4vw * var(--app-font-scale)), calc(30px * var(--app-font-scale)));
  line-height: 1.1;
}

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

.field {
  display: grid;
  gap: 6px;
}

.field>span {
  min-height: 28px;
  display: flex;
  gap: 8px;
  align-items: end;
  color: var(--muted);
  font-weight: 850;
}

.info-btn {
  width: 26px;
  min-width: 26px;
  height: 26px;
  min-height: 26px;
  border: 1px solid rgba(75, 147, 255, 0.36);
  border-radius: 999px;
  background: rgba(75, 147, 255, 0.1);
  color: var(--control-ink);
  font-size: 14px;
  font-weight: 950;
  line-height: 1;
  box-shadow: 0 0 0 0 rgba(75, 147, 255, 0.2);
}

.info-btn .ui-icon {
  width: 14px;
  height: 14px;
}

.info-btn:focus-visible {
  outline: 0;
  box-shadow: 0 0 0 3px rgba(75, 147, 255, 0.18);
}

input,
select {
  width: 100%;
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--control-bg);
  color: var(--control-ink);
  padding: 0 16px;
  outline: none;
  font-size: calc(17px * var(--app-font-scale));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.035);
  transition:
    background 160ms ease,
    border-color 160ms ease,
    box-shadow 160ms ease;
}

input[type="number"] {
  appearance: textfield;
  -moz-appearance: textfield;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  margin: 0;
  -webkit-appearance: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow:
    0 0 0 3px rgba(75, 147, 255, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.055);
}

input:disabled {
  cursor: not-allowed;
  opacity: 0.72;
}

.field.is-disabled>span {
  opacity: 0.78;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  min-height: var(--tap);
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--control-bg);
}

.segmented button,
.top-tabs button,
.primary,
.ghost {
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--control-ink);
  font-weight: 900;
  touch-action: manipulation;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    box-shadow 160ms ease,
    color 160ms ease,
    transform 160ms ease;
}

button.primary span,
button.ghost span,
.topbar-info-button span,
.segmented button span,
.top-tabs button span,
.custom-select-button span,
.custom-select-option span,
.bar-flip-button span {
  color: inherit;
}

.segmented button {
  border: 0;
  background: transparent;
}

.segmented button.active,
.primary,
.top-tabs button.active {
  border-color: var(--active-border);
  background: var(--active-gradient);
  color: var(--on-accent);
}

.segmented button.active:hover,
.segmented button.active:focus-visible {
  border-color: var(--active-border);
  background: var(--active-gradient-hover);
  color: var(--on-accent);
}

.primary {
  box-shadow: var(--active-shadow);
}

.ghost {
  background: var(--control-bg);
}

.primary:hover,
.primary:focus-visible,
.ghost:hover,
.ghost:focus-visible,
.segmented button:hover {
  border-color: var(--line-strong);
  background: var(--control-hover-bg);
  color: var(--control-ink);
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.14);
}

.primary:hover,
.primary:focus-visible {
  border-color: var(--active-border);
  background: var(--active-gradient-hover);
  color: var(--on-accent);
}

.small {
  min-height: 48px;
  padding: 0 14px;
}

.full {
  width: 100%;
  margin-top: 12px;
}

.toggle {
  display: flex;
  min-height: var(--tap);
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--control-bg);
  color: var(--control-ink);
  padding: 0 14px;
  font-weight: 900;
}

.toggle .ui-icon {
  color: var(--accent);
}

.toggle input {
  width: 28px;
  min-height: 28px;
  accent-color: var(--accent);
}

.setting-toggle {
  align-items: center;
  min-height: 56px;
}

.setting-toggle b {
  line-height: 1.15;
}

.cut-list,
.stock-list,
.history-list {
  display: grid;
  gap: 10px;
}

.cut-item,
.stock-row,
.history-item {
  display: grid;
  grid-template-columns: 54px minmax(150px, 1fr) minmax(104px, 0.38fr) 54px;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--soft-row-bg);
}

.cut-item {
  grid-template-columns: 54px minmax(150px, 1fr) minmax(164px, 0.42fr) 54px;
}

.cut-item:hover,
.stock-row:hover,
.history-item:hover {
  border-color: var(--line-strong);
  background: var(--soft-row-hover-bg);
}

.cut-field {
  position: relative;
  display: block;
  min-width: 0;
}

.cut-field span {
  position: absolute;
  top: 7px;
  left: 14px;
  z-index: 1;
  color: var(--muted);
  font-size: calc(11px * var(--app-font-scale));
  font-weight: 950;
  line-height: 1;
  text-transform: uppercase;
}

.cut-field input {
  min-height: 56px;
  padding-top: 18px;
  font-size: calc(19px * var(--app-font-scale));
  font-weight: 850;
}

.cut-length-field input {
  padding-right: 84px;
}

.cut-field .cut-map-color {
  position: absolute;
  top: 7px;
  left: auto;
  right: 7px;
  bottom: 7px;
  display: block;
  width: min(62px, 22%);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 11px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.18), transparent 36%),
    linear-gradient(180deg, var(--piece-start), var(--piece-end));
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.08),
    0 10px 18px rgba(0, 0, 0, 0.15);
  text-transform: none;
  pointer-events: none;
}

.cut-map-color::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.18), transparent 28%, transparent 72%, rgba(0, 0, 0, 0.1));
}

.cut-map-color i {
  display: none;
}

.cut-qty-field input {
  padding-right: 114px;
}

.qty-stepper {
  position: absolute;
  top: 6px;
  right: 6px;
  bottom: 6px;
  display: grid;
  grid-template-columns: repeat(2, 48px);
  gap: 6px;
}

.qty-step {
  display: grid;
  min-width: 48px;
  min-height: 44px;
  place-items: center;
  border: 1px solid rgba(75, 147, 255, 0.32);
  border-radius: 12px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 44%),
    var(--control-bg);
  color: var(--control-ink);
  font-size: calc(24px * var(--app-font-scale));
  font-weight: 950;
  line-height: 1;
  touch-action: manipulation;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 8px 18px rgba(0, 0, 0, 0.12);
}

.qty-step:active {
  border-color: rgba(75, 147, 255, 0.68);
  background: var(--active-gradient);
  color: var(--on-accent);
  transform: translateY(1px);
}

.qty-step:focus-visible {
  outline: 0;
  box-shadow:
    0 0 0 3px rgba(75, 147, 255, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.cut-item {
  will-change: transform;
  transition:
    transform 220ms cubic-bezier(.2, .8, .2, 1),
    border-color 160ms ease,
    background 160ms ease,
    box-shadow 160ms ease,
    opacity 160ms ease;
}

.cut-item.dragging {
  z-index: 3;
  border-color: rgba(75, 147, 255, 0.64);
  background: rgba(75, 147, 255, 0.14);
  box-shadow: 0 18px 38px rgba(75, 147, 255, 0.16);
  opacity: 0.74;
  transform: scale(1.015);
}

.drag-placeholder {
  border-color: rgba(75, 147, 255, 0.7);
  background:
    linear-gradient(135deg, rgba(75, 147, 255, 0.14), rgba(53, 201, 141, 0.06)),
    rgba(75, 147, 255, 0.07);
  box-shadow: inset 0 0 0 1px rgba(75, 147, 255, 0.14);
}

.drag-placeholder>* {
  opacity: 0;
}

.drag-float {
  position: fixed;
  z-index: 999;
  margin: 0;
  pointer-events: none;
  touch-action: none;
  transform: rotate(-1deg) scale(1.025);
  border-color: rgba(75, 147, 255, 0.82);
  background: var(--drag-float-bg);
  box-shadow:
    0 28px 70px rgba(0, 0, 0, 0.42),
    0 0 0 1px rgba(75, 147, 255, 0.18);
}

.drag-handle {
  min-height: 48px;
  border: 1px solid rgba(75, 147, 255, 0.32);
  border-radius: 13px;
  background: rgba(75, 147, 255, 0.1);
  color: var(--control-ink);
  font-weight: 950;
  cursor: grab;
  touch-action: none;
}

.result-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: stretch;
}

.result-grid[data-count="0"] {
  display: none;
}

.summary-rail {
  display: contents;
}

.result-grid .result-card {
  flex: 1 1 100%;
  min-width: 0;
}

/* JS ставит data-columns, а flex растягивает неполную последнюю строку. */
.result-grid[data-columns="2"] .result-card {
  flex-basis: calc((100% - 12px) / 2);
}

.result-grid[data-columns="3"] .result-card {
  flex-basis: calc((100% - 24px) / 3);
}

.result-grid[data-columns="4"] .result-card {
  flex-basis: calc((100% - 36px) / 4);
}

.result-card {
  position: relative;
  z-index: 0;
  isolation: isolate;
  min-height: 98px;
  overflow: hidden;
  padding: 16px 17px;
  transition:
    border-color 180ms ease,
    box-shadow 180ms ease,
    transform 180ms ease;
}

.result-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 1px;
  background: linear-gradient(90deg, rgba(75, 147, 255, 0.6), rgba(53, 201, 141, 0.28), transparent);
  opacity: 0.62;
  pointer-events: none;
}

.result-card:hover {
  z-index: 5;
  border-color: var(--line-strong);
  box-shadow:
    0 0 0 1px var(--line-strong),
    var(--lift-shadow);
  transform: none;
}

.result-card:hover::before {
  height: 2px;
  opacity: 1;
}

.optimize-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border-color: rgba(49, 209, 139, 0.5);
  background:
    linear-gradient(135deg, rgba(53, 201, 141, 0.12), transparent 46%),
    var(--panel-bg);
}

.optimize-card>div {
  position: relative;
  min-width: 0;
  padding-left: 34px;
}

.optimize-card>div::before {
  content: "!";
  position: absolute;
  left: 0;
  top: 4px;
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--remainder), #1f8d61);
  color: #06110c;
  font-size: 15px;
  font-weight: 950;
}

.optimize-card strong {
  font-size: clamp(calc(18px * var(--app-font-scale)), calc(4vw * var(--app-font-scale)), calc(24px * var(--app-font-scale)));
}

.result-card span {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: calc(12px * var(--app-font-scale));
  font-weight: 850;
  letter-spacing: 0;
}

.result-card span .ui-icon {
  width: 16px;
  height: 16px;
  color: var(--accent);
}

.result-card strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(calc(22px * var(--app-font-scale)), calc(5vw * var(--app-font-scale)), calc(32px * var(--app-font-scale)));
  line-height: 1.05;
}

.pause-row {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr 150px;
  gap: 10px;
  margin-bottom: 12px;
}

/* Этот служебный блок оставлен в DOM для JS, но скрыт из интерфейса, чтобы карта раскроя начиналась сразу. */
.map-sheet>.section-head,
.map-sheet>.pause-row {
  display: none;
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -2px 0 12px;
}

.map-sheet>.map-legend {
  margin-top: 0;
}

.map-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 14px;
}

#manualMapResetBtn {
  margin-left: auto;
}

.manual-map-active .map-toolbar {
  padding: 8px;
  border: 1px solid rgba(75, 147, 255, 0.22);
  border-radius: 14px;
  background: rgba(75, 147, 255, 0.045);
}

.map-sheet.is-calculating .bars {
  opacity: 0.45;
}

.calc-busy {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 18px;
  background: radial-gradient(circle at center, rgba(75, 147, 255, 0.12), rgba(4, 7, 10, 0.38) 62%, rgba(4, 7, 10, 0.58));
  pointer-events: none;
}

.calc-busy-panel {
  display: flex;
  width: min(380px, 100%);
  align-items: center;
  gap: 15px;
  padding: 15px 17px;
  border: 1px solid rgba(75, 147, 255, 0.34);
  border-radius: 16px;
  background: var(--popover-bg);
  box-shadow: var(--popover-shadow);
}

.calc-busy-copy {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.calc-busy-copy b {
  color: var(--ink);
  font-size: 16px;
  font-weight: 950;
  line-height: 1.12;
}

.calc-busy-copy small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
}

.hourglass-loader {
  position: relative;
  flex: 0 0 auto;
  width: 42px;
  height: 52px;
  border-top: 5px solid var(--accent);
  border-bottom: 5px solid var(--accent-2);
  border-radius: 10px;
  filter: drop-shadow(0 0 14px rgba(75, 147, 255, 0.28));
  animation: hourglass-turn 1.35s ease-in-out infinite;
}

.hourglass-loader::before,
.hourglass-loader::after {
  content: "";
  position: absolute;
  left: 8px;
  width: 0;
  height: 0;
  border-left: 13px solid transparent;
  border-right: 13px solid transparent;
}

.hourglass-loader::before {
  top: 8px;
  border-top: 15px solid var(--accent);
}

.hourglass-loader::after {
  bottom: 8px;
  border-bottom: 15px solid var(--waste);
}

.hourglass-loader i {
  position: absolute;
  top: 22px;
  left: 19px;
  width: 4px;
  height: 10px;
  border-radius: 999px;
  background: var(--ink);
  opacity: 0.9;
  animation: sand-flow 1.35s ease-in-out infinite;
}

@keyframes hourglass-turn {
  0%,
  42% {
    transform: rotate(0deg);
  }

  58%,
  100% {
    transform: rotate(180deg);
  }
}

@keyframes sand-flow {
  0%,
  42% {
    transform: scaleY(1);
    opacity: 0.95;
  }

  58%,
  100% {
    transform: scaleY(0.35);
    opacity: 0.45;
  }
}

.map-legend span {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--control-bg);
  color: var(--muted);
  font-size: calc(12px * var(--app-font-scale));
  font-weight: 850;
}

.map-legend i {
  width: 16px;
  height: 9px;
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14);
}

.piece-key {
  background: linear-gradient(180deg, #4b93ff, #256ed4);
}

.kerf-key {
  background: linear-gradient(180deg, #8d98a7, #586372);
}

.done-key {
  background: linear-gradient(180deg, #35c98d, #208960);
}

.remainder-key {
  background: linear-gradient(180deg, var(--remainder), #1f8d61);
}

.all-remainder-as-waste .remainder-legend-item {
  display: none;
}

.waste-key {
  background: linear-gradient(180deg, var(--waste), #9f6d1d);
}

.bars {
  display: grid;
  gap: 12px;
  margin-top: 14px;
  contain: layout paint;
}

.bar-row {
  position: relative;
  contain: layout paint style;
  content-visibility: auto;
  contain-intrinsic-size: auto 190px;
  overflow: hidden;
  padding: 14px;
  border: 1px solid rgba(75, 147, 255, 0.2);
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(75, 147, 255, 0.035), transparent 38%),
    var(--soft-row-bg);
  transition:
    border-color 180ms ease,
    background 180ms ease,
    box-shadow 180ms ease;
}

.bar-row::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  opacity: 0.8;
}

.bar-row:hover,
.bar-row:focus {
  border-color: rgba(75, 147, 255, 0.58);
  background: var(--soft-row-hover-bg);
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.16);
  outline: 0;
}

.bar-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  color: var(--muted);
  font-weight: 850;
}

.bar-actions {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.bar-flip-button {
  min-height: 42px;
  padding: 0 12px;
  border-color: rgba(75, 147, 255, 0.24);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.055), transparent 42%),
    rgba(75, 147, 255, 0.055);
  color: var(--control-ink);
  font-size: calc(12px * var(--app-font-scale));
  letter-spacing: 0;
  white-space: nowrap;
}

.bar-flip-button .ui-icon {
  width: 17px;
  height: 17px;
  color: var(--accent);
}

.bar-flip-button:active {
  transform: translateY(1px);
}

.bar-identity {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
}

.bar-index {
  display: grid;
  flex: 0 0 52px;
  min-height: 42px;
  place-items: center;
  border: 1px solid rgba(75, 147, 255, 0.38);
  border-radius: 13px;
  background:
    linear-gradient(180deg, rgba(75, 147, 255, 0.18), rgba(75, 147, 255, 0.07)),
    rgba(75, 147, 255, 0.08);
  color: var(--ink);
  font-size: calc(13px * var(--app-font-scale));
  font-weight: 950;
}

.bar-title {
  min-width: 0;
}

.bar-title strong,
.bar-title span {
  display: block;
}

.bar-title strong {
  color: var(--ink);
  font-size: calc(17px * var(--app-font-scale));
  line-height: 1.1;
}

.bar-title span {
  margin-top: 5px;
  font-size: calc(13px * var(--app-font-scale));
}

.bar-count {
  display: grid;
  flex: 0 0 auto;
  min-width: 74px;
  min-height: 50px;
  place-items: center;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--control-bg);
  color: var(--ink);
}

.bar-count strong {
  font-size: calc(24px * var(--app-font-scale));
  line-height: 0.95;
}

.bar-count span {
  color: var(--muted);
  font-size: calc(11px * var(--app-font-scale));
  font-weight: 950;
  line-height: 1;
  text-transform: uppercase;
}

.bar-groups {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 12px;
}

.length-chip {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  gap: 8px;
  padding: 0 10px 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--control-bg);
  color: var(--ink);
  font-size: calc(12px * var(--app-font-scale));
  line-height: 1;
  white-space: nowrap;
}

.length-chip i {
  width: 18px;
  height: 10px;
  border-radius: 999px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.22), transparent 40%),
    linear-gradient(180deg, var(--piece-start), var(--piece-end));
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.13) inset;
}

.length-chip b {
  font-weight: 950;
}

.length-chip em {
  color: var(--muted);
  font-style: normal;
  font-weight: 900;
}

.bar-track-shell {
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 4px;
  contain: paint;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.bar-track-shell::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

.bar-track {
  position: relative;
  display: flex;
  min-width: 760px;
  min-height: 56px;
  contain: layout paint;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bar-track-bg);
  isolation: isolate;
  transition:
    border-color 180ms ease,
    box-shadow 180ms ease;
}

.track-slot {
  position: relative;
  display: grid;
  flex: 0 1 auto;
  min-height: 56px;
  place-items: stretch;
}

.piece-slot {
  min-width: 56px;
}

.kerf-slot {
  min-width: 2px;
  max-width: 5px;
}

.tail-slot {
  min-width: 50px;
}

.track-slot:first-child>span {
  border-top-left-radius: 13px;
  border-bottom-left-radius: 13px;
  transform-origin: left center;
}

.track-slot:last-child>span {
  border-top-right-radius: 13px;
  border-bottom-right-radius: 13px;
  transform-origin: right center;
}

.bar-row:hover .bar-track,
.bar-row:focus .bar-track,
.bar-row:focus-within .bar-track {
  border-color: rgba(75, 147, 255, 0.56);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.piece,
.kerf-piece,
.remainder-piece,
.waste-piece {
  position: relative;
  z-index: 1;
  display: grid;
  width: 100%;
  min-width: 0;
  height: 100%;
  place-items: center;
  color: var(--piece-ink, #fff);
  font-size: calc(12px * var(--app-font-scale));
  font-weight: 900;
  border-right: 1px solid rgba(255, 255, 255, 0.14);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.22);
  transform: translate3d(0, 0, 0);
  transition:
    transform 260ms cubic-bezier(.2, .8, .2, 1),
    opacity 180ms ease,
    box-shadow 180ms ease,
    filter 180ms ease;
  white-space: nowrap;
}

.piece-label,
.tail-label {
  display: grid;
  gap: 1px;
  place-items: center;
  line-height: 1;
  min-width: 34px;
  padding: 0 2px;
}

.piece-label b,
.tail-label b {
  font-size: calc(13px * var(--app-font-scale));
  line-height: 1;
}

.piece-label small,
.tail-label small {
  font-size: calc(9px * var(--app-font-scale));
  font-weight: 950;
  line-height: 1;
  opacity: 0.82;
  text-transform: uppercase;
}

.bar-row:hover .piece,
.bar-row:focus .piece,
.bar-row:focus-within .piece,
.bar-row:hover .remainder-piece,
.bar-row:focus .remainder-piece,
.bar-row:focus-within .remainder-piece,
.bar-row:hover .waste-piece,
.bar-row:focus .waste-piece,
.bar-row:focus-within .waste-piece {
  filter: saturate(1.08);
  transform: none;
}

.bar-row:hover .kerf-piece,
.bar-row:focus .kerf-piece,
.bar-row:focus-within .kerf-piece {
  opacity: 1;
  filter: brightness(1.08);
  transform: none;
}

.piece {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.16), transparent 36%),
    linear-gradient(180deg, var(--piece-start), var(--piece-end));
}

.manual-piece-slot {
  position: relative;
  cursor: grab;
  touch-action: none;
}

.manual-piece-slot:active {
  cursor: grabbing;
}

.manual-piece {
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.14),
    inset 0 -10px 18px rgba(0, 0, 0, 0.08);
}

.manual-piece::after {
  content: "";
  position: absolute;
  inset: 8px auto 8px 7px;
  width: 3px;
  border-radius: 99px;
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.82) 1px, transparent 1.5px) 0 0 / 3px 7px;
  opacity: 0.72;
  pointer-events: none;
}

.manual-piece-slot.map-insert-before,
.manual-piece-slot.map-insert-after {
  z-index: 8;
}

.manual-piece-slot.map-insert-before::before,
.manual-piece-slot.map-insert-after::before {
  content: "";
  position: absolute;
  top: 6px;
  bottom: 6px;
  z-index: 9;
  width: 4px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffffff, var(--accent), #35c98d);
  box-shadow:
    0 0 0 3px rgba(75, 147, 255, 0.18),
    0 0 18px rgba(75, 147, 255, 0.52);
  pointer-events: none;
}

.manual-piece-slot.map-insert-before::before {
  left: 3px;
}

.manual-piece-slot.map-insert-after::before {
  right: 3px;
}

.manual-piece-slot.map-insert-before .manual-piece {
  transform: translateX(10px) scale(0.985);
  filter: brightness(1.12) saturate(1.12);
}

.manual-piece-slot.map-insert-after .manual-piece {
  transform: translateX(-10px) scale(0.985);
  filter: brightness(1.12) saturate(1.12);
}

.manual-bar-track.map-drop-target {
  border-color: rgba(75, 147, 255, 0.88);
  box-shadow:
    0 0 0 3px rgba(75, 147, 255, 0.16),
    inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.manual-bar-track.map-drop-rebalance {
  border-color: rgba(200, 138, 46, 0.92);
  box-shadow:
    0 0 0 3px rgba(200, 138, 46, 0.18),
    inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.manual-bar-track.map-drop-denied {
  border-color: rgba(255, 90, 70, 0.9);
  box-shadow:
    0 0 0 3px rgba(255, 90, 70, 0.16),
    inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.map-piece-source {
  opacity: 0.42;
}

.map-piece-float {
  position: fixed;
  z-index: 1200;
  display: grid;
  min-width: 56px;
  min-height: 56px;
  pointer-events: none;
  opacity: 0.94;
  filter: drop-shadow(0 20px 28px rgba(0, 0, 0, 0.34));
}

.piece.done {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.15), transparent 36%),
    linear-gradient(180deg, #35c98d, #208960);
}

.kerf-piece {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.14), transparent 40%),
    linear-gradient(180deg, #8d98a7, #586372);
}

.remainder-piece {
  background: linear-gradient(180deg, var(--remainder), #1f8d61);
}

.waste-piece {
  background: linear-gradient(180deg, var(--waste), #9f6d1d);
}

.bar-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  color: var(--muted);
  font-size: calc(12px * var(--app-font-scale));
  font-weight: 850;
}

.bar-footer span {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  gap: 5px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.025);
}

.bar-footer b {
  color: var(--ink);
}

.stock-row {
  grid-template-columns: minmax(0, 1fr) 140px;
}

.stock-row>span,
.history-item strong {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
}

.stock-row .ui-icon,
.history-item .ui-icon {
  width: 18px;
  height: 18px;
  color: var(--accent);
}

.history-item {
  grid-template-columns: minmax(0, 1fr) auto;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px 10px;
  align-items: start;
}

.settings-grid .hint {
  margin-top: 0;
}

.theme-field {
  grid-column: span 2;
}

.theme-switch {
  width: min(360px, 100%);
}

.manual-map-field {
  grid-column: span 1;
}

.typography-font-field,
.typography-size-field {
  grid-column: span 1;
}

.typography-size-field>span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

#settingsFontSizeValue {
  color: var(--accent);
  font-size: calc(12px * var(--app-font-scale));
  font-weight: 950;
  line-height: 1;
}

#settingsFontSize {
  padding: 0;
  accent-color: var(--accent);
}

.native-select-hidden {
  position: absolute;
  width: 1px;
  min-height: 1px;
  opacity: 0;
  pointer-events: none;
}

.custom-select {
  position: relative;
  z-index: 20;
}

.custom-select-button {
  display: flex;
  width: 100%;
  min-height: var(--tap);
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--control-bg);
  color: var(--control-ink);
  padding: 0 14px 0 16px;
  font-weight: 850;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.035);
  transition:
    background 160ms ease,
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.custom-select-button:hover,
.custom-select-button:focus-visible,
.custom-select-button[aria-expanded="true"] {
  border-color: rgba(75, 147, 255, 0.58);
  background: var(--control-hover-bg);
  outline: 0;
  box-shadow:
    0 0 0 3px rgba(75, 147, 255, 0.16),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.custom-select-button .ui-icon {
  width: 18px;
  height: 18px;
  color: var(--accent);
  transition: transform 160ms ease;
}

.custom-select-button[aria-expanded="true"] .ui-icon {
  transform: rotate(180deg);
}

.custom-select-menu {
  position: absolute;
  top: calc(100% + 7px);
  left: 0;
  right: 0;
  z-index: 80;
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px solid rgba(75, 147, 255, 0.32);
  border-radius: 16px;
  background: var(--popover-bg);
  box-shadow: var(--popover-shadow);
}

.custom-select-option {
  display: flex;
  width: 100%;
  min-height: 48px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--control-ink);
  padding: 0 12px;
  text-align: left;
  font-weight: 900;
}

.custom-select-option small {
  color: var(--control-subtle);
  font-size: calc(11px * var(--app-font-scale));
  font-weight: 850;
}

.custom-select-option:hover,
.custom-select-option:focus-visible {
  border-color: var(--line-strong);
  background: var(--control-hover-bg);
  outline: 0;
}

.custom-select-option.active {
  border-color: var(--active-border);
  background: var(--active-gradient);
  color: var(--on-accent);
  box-shadow: var(--active-shadow);
}

.custom-select-option.active small {
  color: rgba(255, 255, 255, 0.9);
}

.summary-field {
  grid-column: 1 / -1;
}

.settings-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  margin-top: 2px;
}

.reset-settings-button {
  min-width: min(100%, 520px);
}

.summary-visibility-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 7px;
}

.summary-toggle {
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--control-bg);
  color: var(--control-ink);
  font-size: calc(13px * var(--app-font-scale));
  font-weight: 900;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    transform 160ms ease;
}

.summary-toggle:hover {
  border-color: var(--line-strong);
  background: var(--control-hover-bg);
  transform: translateY(-1px);
}

.summary-toggle input {
  width: 22px;
  min-height: 22px;
  accent-color: var(--accent);
}

.summary-toggle .ui-icon {
  width: 17px;
  height: 17px;
  color: var(--accent);
}

.hint {
  margin-top: 4px;
  padding: 12px 14px;
  border: 1px solid rgba(75, 147, 255, 0.24);
  border-radius: 16px;
  background: rgba(75, 147, 255, 0.065);
  color: var(--muted);
}

.hint b {
  margin-top: 6px;
  display: block;
  color: var(--ink);
  margin-bottom: 4px;
}

.info-popover {
  position: fixed;
  z-index: 40;
  width: min(430px, calc(100vw - 24px));
  padding: 18px 48px 18px 18px;
  border: 1px solid rgba(75, 147, 255, 0.34);
  border-radius: 18px;
  background: var(--popover-bg);
  color: var(--ink);
  box-shadow: var(--popover-shadow);
  backdrop-filter: blur(16px);
}

.info-popover[hidden] {
  display: none;
}

.info-popover p {
  color: var(--muted);
  font-size: 14px;
  font-weight: 750;
  line-height: 1.5;
  white-space: pre-line;
}

.info-close {
  position: absolute;
  top: 10px;
  right: 10px;
  display: grid;
  width: 34px;
  min-height: 34px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--control-bg);
  color: var(--control-ink);
  font-size: 18px;
  font-weight: 950;
}

.about-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--modal-backdrop);
  backdrop-filter: blur(14px);
}

.about-modal[hidden] {
  display: none;
}

.about-panel {
  position: relative;
  width: min(620px, 100%);
  max-height: min(86vh, 760px);
  overflow: auto;
  padding: 24px;
  border: 1px solid rgba(75, 147, 255, 0.32);
  border-radius: 20px;
  background: var(--modal-panel-bg);
  box-shadow: var(--modal-panel-shadow);
}

.about-kicker {
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 950;
  text-transform: uppercase;
}

.about-panel h2 {
  max-width: calc(100% - 46px);
  margin-top: 6px;
}

.about-panel p {
  margin-top: 14px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.58;
}

.about-panel strong {
  color: var(--ink);
}

.about-details {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.about-details a {
  display: flex;
  min-width: 0;
  min-height: 48px;
  align-items: center;
  padding: 0 14px;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--link-card-bg);
  color: var(--ink);
  font-size: 14px;
  font-weight: 850;
  text-decoration: none;
}

.about-legal {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid rgba(49, 209, 139, 0.3);
  border-radius: 16px;
  background: rgba(49, 209, 139, 0.07);
}

.about-legal h3 {
  margin: 0;
  font-size: 17px;
}

.about-legal p {
  margin-top: 8px;
}

.about-close {
  position: absolute;
  top: 14px;
  right: 14px;
  display: grid;
  width: 38px;
  min-height: 38px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--control-bg);
  color: var(--control-ink);
  font-size: 20px;
  font-weight: 950;
}

.legend {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.legend div {
  display: flex;
  gap: 8px;
  align-items: center;
  min-height: 58px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--soft-row-bg);
}

.legend i {
  width: 46px;
  height: 34px;
  border-radius: 10px;
}

.legend .made {
  background: linear-gradient(180deg, #4b93ff, #256ed4);
}

.legend .kerf {
  background: linear-gradient(180deg, #8d98a7, #586372);
}

.legend .remainder {
  background: linear-gradient(180deg, var(--remainder), #1f8d61);
}

.legend .waste {
  background: linear-gradient(180deg, var(--waste), #9f6d1d);
}

/* Верхняя навигация сделана как отдельная стеклянная панель, чтобы она не спорила с карточками ниже. */
.top-tabs {
  grid-column: 1 / -1;
  position: relative;
  z-index: 12;
  isolation: isolate;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: stretch;
  gap: 6px;
  min-width: 0;
  overflow-x: auto;
  margin-top: 0;
  padding: 7px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 22px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.018)),
    var(--nav-bg);
  box-shadow:
    0 18px 42px rgba(0, 0, 0, 0.24),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(16px);
  scrollbar-width: none;
  transition:
    margin-top 220ms ease,
    border-color 180ms ease,
    box-shadow 180ms ease;
}

.top-tabs::-webkit-scrollbar {
  display: none;
}

.top-tabs button {
  --tab-accent: var(--accent);
  position: relative;
  flex-direction: row;
  min-width: 0;
  min-height: 56px;
  overflow: hidden;
  padding: 0 12px;
  border-color: var(--top-control-border);
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.038), rgba(255, 255, 255, 0.01)),
    var(--top-control-bg);
  color: var(--control-muted);
  font-size: 13px;
  letter-spacing: 0;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 8px 18px rgba(0, 0, 0, 0.1);
  transition:
    background 200ms ease,
    border-color 200ms ease,
    box-shadow 200ms ease,
    color 200ms ease,
    transform 200ms cubic-bezier(.2, .8, .2, 1);
}

.top-tabs button:nth-child(2) {
  --tab-accent: #35c98d;
}

.top-tabs button:nth-child(3) {
  --tab-accent: #7aa7ff;
}

.top-tabs button:nth-child(4) {
  --tab-accent: #ff8a3d;
}

.top-tabs button::before {
  content: "";
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 8px;
  height: 2px;
  border-radius: 999px;
  background: var(--tab-accent);
  opacity: 0;
  transform: scaleX(0.3);
  transition:
    opacity 200ms ease,
    transform 220ms ease;
}

.top-tabs button .ui-icon {
  width: 19px;
  height: 19px;
}

.top-tabs button span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-tabs button:hover,
.top-tabs button:focus-visible {
  z-index: 3;
  border-color: rgba(148, 163, 184, 0.34);
  color: var(--control-ink);
  transform: none;
  box-shadow:
    0 0 0 1px rgba(148, 163, 184, 0.28),
    0 10px 20px rgba(0, 0, 0, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.09);
}

.top-tabs button:focus-visible {
  outline: 0;
  box-shadow:
    0 0 0 3px rgba(75, 147, 255, 0.18),
    0 12px 24px rgba(75, 147, 255, 0.1);
}

.top-tabs button.active {
  z-index: 2;
  border-color: var(--active-border);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.062), rgba(255, 255, 255, 0.014)),
    var(--control-bg);
  color: var(--control-ink);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.11),
    inset 0 -1px 0 rgba(137, 169, 199, 0.16);
  transform: none;
}

.top-tabs button.active::before {
  background: rgba(137, 169, 199, 0.92);
  opacity: 1;
  transform: scaleX(1);
  box-shadow: none;
}

.top-tabs button.active:hover,
.top-tabs button.active:focus-visible {
  z-index: 4;
  border-color: var(--active-border);
  box-shadow:
    0 0 0 1px rgba(137, 169, 199, 0.34),
    0 12px 24px rgba(0, 0, 0, 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 0.13),
    inset 0 -1px 0 rgba(137, 169, 199, 0.18);
}

@media (prefers-reduced-motion: reduce) {
  .topbar,
  .topbar-hero,
  .brand,
  .janpol-mark,
  .screen.active,
  .top-tabs button.active::before {
    animation: none;
    transition: none;
  }

  .top-tabs button {
    transition: none;
  }

  .bar-track,
  .track-slot,
  .track-slot>span {
    transition: none;
  }

  .bar-row:hover .bar-track,
  .bar-row:focus .bar-track,
  .bar-row:focus-within .bar-track,
  .bar-row:hover .piece,
  .bar-row:focus .piece,
  .bar-row:focus-within .piece,
  .bar-row:hover .kerf-piece,
  .bar-row:focus .kerf-piece,
  .bar-row:focus-within .kerf-piece,
  .bar-row:hover .remainder-piece,
  .bar-row:focus .remainder-piece,
  .bar-row:focus-within .remainder-piece,
  .bar-row:hover .waste-piece,
  .bar-row:focus .waste-piece,
  .bar-row:focus-within .waste-piece {
    transform: none;
  }
}

@media (hover: none), (pointer: coarse), (max-width: 980px) {
  .topbar-hero,
  .sheet,
  .result-card,
  .top-tabs,
  .topbar-info-button,
  .info-popover,
  .about-modal {
    backdrop-filter: none;
  }

  .sheet,
  .result-card,
  .top-tabs,
  .bar-row {
    box-shadow: none;
  }

  .topbar,
  .topbar-hero,
  .janpol-mark,
  .screen.active,
  .top-tabs,
  .top-tabs button,
  .segmented button,
  .primary,
  .ghost,
  input,
  select,
  .cut-item,
  .result-card,
  .bar-row,
  .bar-track,
  .piece,
  .kerf-piece,
  .remainder-piece,
  .waste-piece {
    transition: none;
  }

  .topbar.is-scrolled .topbar-hero,
  .piece,
  .kerf-piece,
  .remainder-piece,
  .waste-piece {
    transform: none;
  }

  .bar-row:hover,
  .bar-row:focus,
  .bar-row:hover .bar-track,
  .bar-row:focus .bar-track,
  .bar-row:focus-within .bar-track {
    box-shadow: none;
  }

  .bar-row:hover .piece,
  .bar-row:focus .piece,
  .bar-row:focus-within .piece,
  .bar-row:hover .kerf-piece,
  .bar-row:focus .kerf-piece,
  .bar-row:focus-within .kerf-piece,
  .bar-row:hover .remainder-piece,
  .bar-row:focus .remainder-piece,
  .bar-row:focus-within .remainder-piece,
  .bar-row:hover .waste-piece,
  .bar-row:focus .waste-piece,
  .bar-row:focus-within .waste-piece {
    filter: none;
  }

  .brand img,
  .map-piece-float {
    filter: none;
  }

  .cut-item {
    will-change: auto;
  }

  .janpol-mark::before {
    opacity: 0.32;
  }
}

@media (min-width: 1540px) and (orientation: landscape) {
  .app {
    width: min(1780px, calc(100% - 32px));
  }

  .topbar {
    width: 100%;
    justify-self: stretch;
  }

  .topbar-hero {
    grid-template-columns: minmax(0, 1fr) minmax(620px, 0.82fr) minmax(0, 1fr);
  }

  /* В широком режиме шапка и вкладки занимают ту же ширину, что и рабочая сетка ниже. */
  .top-tabs {
    grid-column: 1 / -1;
  }

  main {
    overflow-x: hidden;
    padding-inline: 0;
  }

  .screen:not(#screen-calc).active {
    width: min(1168px, 100%);
    justify-self: center;
  }

  /* На широком экране раскладываем калькулятор в три колонки:
     рабочие формы остаются в центре, а быстрые итоги занимают боковые поля. */
  #screen-calc.active {
    grid-template-columns: minmax(250px, 318px) minmax(760px, 1fr) minmax(250px, 318px);
    align-items: start;
  }

  #screen-calc>.main-sheet,
  #screen-calc>.sheet:not(.main-sheet):not(.map-sheet),
  #screen-calc>.map-sheet {
    grid-column: 2;
    min-width: 0;
  }

  #screen-calc>.main-sheet {
    grid-row: 1;
  }

  #screen-calc>.sheet:not(.main-sheet):not(.map-sheet) {
    grid-row: 2;
  }

  #screen-calc>.map-sheet {
    grid-row: 3;
  }

  #screen-calc>.result-grid {
    grid-column: 1 / -1;
    grid-row: 1 / 4;
    display: grid;
    grid-template-columns: minmax(250px, 318px) minmax(760px, 1fr) minmax(250px, 318px);
    align-items: start;
    gap: 14px;
    pointer-events: none;
  }

  #screen-calc>.result-grid[data-count="0"] {
    display: none;
  }

  #screen-calc>.result-grid .summary-rail {
    display: grid;
    gap: 14px;
    align-content: start;
    pointer-events: auto;
  }

  #screen-calc>.result-grid .summary-rail-left {
    grid-column: 1;
  }

  #screen-calc>.result-grid .summary-rail-right {
    grid-column: 3;
  }

  #screen-calc>.result-grid .result-card {
    min-width: 0;
    min-height: 108px;
    flex: none;
  }

  #screen-calc>.result-grid .optimize-card {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 980px) {
  .topbar-hero {
    grid-template-areas:
      "brand actions"
      "mark mark";
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px 10px;
    max-height: 180px;
    padding: 9px;
  }

  .janpol-mark {
    width: 100%;
    min-height: 70px;
  }
}

@media (max-width: 760px) {
  .app {
    padding: 10px 10px max(8px, env(safe-area-inset-bottom));
  }

  .topbar {
    grid-template-columns: 1fr;
  }

  .form-grid,
  .result-grid,
  .pause-row,
  .settings-grid,
  .about-details,
  .legend {
    grid-template-columns: 1fr;
  }

  .theme-switch {
    width: 100%;
  }

  .theme-field,
  .manual-map-field {
    grid-column: 1 / -1;
  }

  .summary-visibility-grid {
    grid-template-columns: 1fr;
  }

  .result-grid[data-columns] .result-card {
    flex-basis: 100%;
  }

  .optimize-card {
    grid-template-columns: 1fr;
  }

  .cut-item {
    grid-template-columns: 42px minmax(0, 1fr) 46px;
    gap: 8px;
  }

  .cut-item>.drag-handle {
    grid-row: 1 / 3;
  }

  .cut-item>.cut-field:not(.cut-qty-field) {
    grid-column: 2;
    grid-row: 1;
  }

  .cut-item>.cut-qty-field {
    grid-column: 2 / 4;
    grid-row: 2;
  }

  .cut-item>.remove-cut {
    grid-column: 3;
    grid-row: 1;
  }

  .cut-length-field input {
    padding-right: 82px;
  }

  .cut-field .cut-map-color {
    width: 62px;
  }

  .bar-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
  }

  .bar-actions {
    align-items: stretch;
  }

  .bar-flip-button {
    min-width: 48px;
    padding: 0 11px;
  }

  .bar-flip-button span {
    display: none;
  }

  .bar-row {
    padding: 12px;
  }

  .bar-track {
    min-width: 100%;
    min-height: 48px;
  }

  .track-slot {
    min-height: 48px;
  }

  .piece-slot {
    min-width: 28px;
  }

  .tail-slot {
    min-width: 58px;
    z-index: 4;
    overflow: visible;
  }

  .piece-label b,
  .tail-label b {
    font-size: 11px;
  }

  .piece-label small {
    display: none;
  }

  .tail-label small {
    display: block;
    font-size: 8px;
  }

  .waste-piece .tail-label {
    display: grid;
    position: absolute;
    top: 50%;
    left: 50%;
    min-width: 38px;
    padding: 2px 3px;
    border-radius: 7px;
    background: rgba(0, 0, 0, 0.28);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12);
    color: #fff;
    transform: translate(-50%, -50%);
    z-index: 5;
  }

  .bar-footer {
    gap: 6px;
  }

  .top-tabs {
    gap: 5px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    overflow: visible;
    padding: 6px;
    border-radius: 18px;
  }

  .top-tabs button {
    min-height: 52px;
    padding: 0 10px;
    border-radius: 13px;
    font-size: 12px;
  }

  .top-tabs button::before {
    left: 14px;
    right: 14px;
    bottom: 7px;
  }

  .info-popover {
    left: 12px !important;
    right: 12px;
    top: auto !important;
    bottom: calc(14px + env(safe-area-inset-bottom));
    width: auto;
    max-height: min(46vh, 320px);
    overflow: auto;
  }
}

@media (max-width: 430px) {
  .top-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .brand {
    gap: 10px;
  }

  .brand img {
    width: 48px;
    height: 48px;
    border-radius: 14px;
  }

  .brand strong {
    font-size: 21px;
  }

  .brand span {
    font-size: 12px;
  }

  .topbar-info-button {
    min-height: 34px;
    padding: 0 9px;
    font-size: 12px;
  }

  input,
  select {
    font-size: 20px;
  }

  .cut-length-field input {
    padding-right: 72px;
  }

  .cut-field .cut-map-color {
    width: 54px;
  }

  .sheet {
    padding: 14px;
  }

  .about-panel {
    padding: 20px;
  }

  .top-tabs button {
    font-size: 12px;
  }
}

@media (max-width: 360px) {
  .app {
    padding-inline: 8px;
  }

  .top-tabs button {
    min-height: 48px;
    padding: 0 8px;
  }

  .top-tabs button .ui-icon {
    width: 17px;
    height: 17px;
  }
}
