.calculator-brand {
  display: block;
  margin-bottom: 9px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.calculator-brand img {
  display: block;
  width: min(180px, 52vw);
  height: auto;
  object-fit: contain;
}

.calculator-brand:focus-visible {
  border-radius: 8px;
  outline: 2px solid var(--brand-red);
  outline-offset: 4px;
}

.calculators-view .calculators-hero {
  padding-top: 14px;
  padding-bottom: 22px;
}

.calculator-module-list {
  display: grid;
  gap: 12px;
  max-width: 620px;
}

.calculator-module-card {
  min-height: 100px;
  padding: 20px;
}

.calculator-alert-stack {
  position: sticky;
  top: 8px;
  z-index: 5;
  display: grid;
  gap: 8px;
  pointer-events: none;
}

.calculator-alert-stack > :not(.hidden) {
  margin-top: 10px;
  pointer-events: auto;
  box-shadow: 0 10px 28px rgba(26, 45, 67, .12);
}

.calculator-alert-stack .calculator-error {
  border-color: #e2a2a5;
  background: #fdeced;
  color: #7d2024;
}

.calculator-form { gap: 12px; }

.calculator-option-section {
  min-width: 0;
  overflow: clip;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--page);
}

.calculator-option-section > summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 16px;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 12px 14px;
  color: var(--text);
  cursor: pointer;
  list-style: none;
  font-size: 13px;
  font-weight: 800;
}

.calculator-option-section > summary::-webkit-details-marker { display: none; }
.calculator-option-section > summary small { color: var(--secondary); font-size: 10px; font-weight: 650; text-align: right; }
.calculator-option-section > summary::after {
  content: '';
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--secondary);
  border-bottom: 2px solid var(--secondary);
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform .15s ease;
}
.calculator-option-section[open] > summary::after { transform: rotate(225deg) translate(-2px, -2px); }
.calculator-option-section[open] > summary { border-bottom: 1px solid var(--line); }
.calculator-option-section > summary:focus-visible { outline: 2px solid var(--brand-red); outline-offset: -3px; }

.calculator-option-section-body {
  display: grid;
  gap: 14px;
  padding: 14px;
}

.calculator-adjustments {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.calculator-adjustments label {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 6px;
  color: var(--secondary);
  font-size: 11px;
  font-weight: 700;
}

.calculator-adjustments input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fafb;
  color: var(--text);
  padding: 10px 12px;
  font-size: 16px;
  font-weight: 700;
  outline: 0;
}

.calculator-adjustments input:focus {
  border-color: var(--brand-red-border);
  box-shadow: 0 0 0 3px rgba(211, 47, 47, .075);
}

.calculator-adjustments input[aria-invalid="true"] { border-color: var(--brand-red); }
.calculator-adjustments-hint { margin: 9px 0 0; color: var(--secondary); font-size: 10px; line-height: 1.4; }
.calculator-keyboard-actions { display: none; justify-content: flex-end; margin-top: 10px; }
.calculator-keyboard-done {
  min-width: 96px;
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  background: var(--brand-red);
  color: #fff;
  padding: 10px 18px;
  font: inherit;
  font-weight: 800;
}
.calculator-keyboard-done:focus-visible { outline: 3px solid rgba(211, 47, 47, .25); outline-offset: 2px; }

@media (max-width: 719px), (hover: none) and (pointer: coarse) {
  .calculator-numeric-fieldset:focus-within .calculator-keyboard-actions { display: flex; }
}

body.telegram-dark .calculator-option-section { background: #222d37; }
body.telegram-dark .calculator-alert-stack .calculator-error { border-color: #8b4b52; background: #45252a; color: #ffd2d4; }
body.telegram-dark .calculator-adjustments input { background: #222d37; color: var(--text); }

.calculator-scheme {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 16px;
  align-items: center;
}

.calculator-scheme .calculator-gate {
  position: static;
  width: 160px;
  height: auto;
  max-width: 100%;
  aspect-ratio: auto;
  margin: 0;
  overflow: visible;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.calculator-scheme-outline { fill: none; stroke: var(--line); stroke-width: 1; }
.calculator-scheme-slat { stroke: #9a9a9a; }
.calculator-scheme-stiffener { fill: #4a4a4a; }
.calculator-scheme-profile { fill: var(--brand-red); }
.calculator-scheme-text { display: grid; gap: 4px; font-size: 14px; }
.calculator-legend { display: inline-flex; align-items: center; gap: 6px; }
.calculator-swatch { display: inline-block; width: 14px; height: 4px; border-radius: 2px; }
.calculator-swatch-profile { background: var(--brand-red); }
.calculator-swatch-stiffener { background: #4a4a4a; }

body.telegram-dark .calculator-scheme-slat { stroke: #7a7a7a; }
body.telegram-dark .calculator-scheme-stiffener { fill: #d0d0d0; }
body.telegram-dark .calculator-swatch-stiffener { background: #d0d0d0; }

.calculator-profile-fieldset {
  display: grid;
  gap: 10px;
}

.calculator-profile-drawings {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.calculator-profile-figure {
  display: grid;
  grid-template-rows: 160px auto;
  gap: 8px;
  min-width: 0;
  margin: 0;
  padding: 12px 8px 10px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--page);
}

.calculator-profile-figure svg {
  display: block;
  width: 100%;
  height: 160px;
  overflow: visible;
}

.calculator-profile-figure figcaption {
  display: grid;
  align-content: start;
  gap: 3px;
  min-width: 0;
  text-align: center;
  font-size: 12px;
  line-height: 1.25;
}

.calculator-profile-figure figcaption strong { color: var(--text); font-size: 13px; }
.calculator-profile-figure figcaption span { color: var(--secondary); }
.calculator-profile-line { fill: none; stroke: var(--text); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.calculator-profile-hem { stroke: var(--text); stroke-width: 4; stroke-linecap: round; }
.calculator-profile-corner,
.calculator-profile-dimension { fill: none; stroke: var(--secondary); stroke-width: 0.9; stroke-linecap: round; stroke-linejoin: round; }
.calculator-profile-text,
.calculator-profile-muted-text { fill: var(--text); font: 600 7px ui-monospace, SFMono-Regular, Consolas, monospace; }
.calculator-profile-muted-text { fill: var(--secondary); }

.calculator-profile-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--secondary);
  font-size: 12px;
}

.calculator-profile-chips > span {
  padding: 5px 8px;
  border-radius: 999px;
  background: var(--page);
}

.calculator-profile-chips b { color: var(--text); }

body.telegram-dark .calculator-profile-figure,
body.telegram-dark .calculator-profile-chips > span { background: var(--panel); }

@media (max-width: 420px) {
  .calculator-scheme { grid-template-columns: minmax(0, 1fr); }
  .calculator-scheme .calculator-gate { width: 140px; }
  .calculator-profile-drawings { grid-template-columns: minmax(0, 1fr); }
  .calculator-option-section > summary { grid-template-columns: minmax(0, 1fr) 16px; }
  .calculator-option-section > summary small { grid-column: 1; grid-row: 2; text-align: left; }
  .calculator-option-section > summary::after { grid-column: 2; grid-row: 1 / span 2; }
}

/* Keep the calculator as one continuous scroll surface. */
.calculator-header {
  position: static;
  top: auto;
  z-index: auto;
  margin: 0;
  padding: 10px 0 17px;
  background: transparent;
  backdrop-filter: none;
}

.calculator-result-panel {
  position: static;
  top: auto;
}

body.telegram-dark .calculator-header {
  background: transparent;
}

@media (min-width: 720px) {
  .calculator-screen { overflow-x: hidden; }
  .calculator-header {
    width: 100%;
    align-items: center;
    margin-inline: 0;
    padding: 12px 0 17px;
  }
  .calculator-header-actions {
    flex: 0 0 auto;
    justify-content: flex-end;
    margin-left: auto;
  }
  .calculator-header h1,
  .calculator-header p {
    white-space: nowrap;
  }
  .calculator-header h1 {
    overflow: visible;
    padding-bottom: 2px;
  }
  .calculator-header p {
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

@media (min-width: 1024px) {
  .calculator-header-copy {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas:
      "brand title"
      "brand subtitle";
    align-items: center;
    column-gap: 20px;
  }
  .calculator-brand {
    grid-area: brand;
    margin: 0;
  }
  .calculator-brand img {
    width: 170px;
    max-width: 170px;
  }
  .calculator-header h1 { grid-area: title; }
  .calculator-header p {
    grid-area: subtitle;
    margin-top: 4px;
  }
}
