:root {
  --red: #e30613;
  --red-dark: #c10510;
  --red-soft: #ffe8ea;
  --ink: #1a1a1a;
  --muted: #6b6b6b;
  --line: #e3e3e3;
  --line-strong: #d0d0d0;
  --bg: #f5f5f5;
  --surface: #ffffff;
  --blue: #2f6fed;
  --blue-soft: #e8f0ff;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.04);
  font-family: "Manrope", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 400px at 10% -10%, #ffe5e7 0%, transparent 55%),
    radial-gradient(900px 360px at 100% 0%, #f0f0f0 0%, transparent 50%),
    var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

.app {
  max-width: 1440px;
  margin: 0 auto;
  padding: 16px 20px 32px;
}

/* —— Top bar —— */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  margin-bottom: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 36px;
  height: 44px;
  flex-shrink: 0;
}

.brand-mark svg,
.brand-mark.large svg {
  width: 100%;
  height: 100%;
  display: block;
}

.brand-mark.large {
  width: 52px;
  height: 64px;
  margin: 0 auto 8px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.brand-text strong {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.brand-text span {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--red);
}

.topbar-title {
  text-align: center;
}

.topbar-title h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
}

.topbar-title p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.topbar-badge {
  justify-self: end;
  max-width: 280px;
  padding: 8px 12px;
  border-radius: 6px;
  background: #fff4e5;
  border: 1px solid #f0d7a8;
  color: #7a5200;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.35;
  text-align: right;
}

/* —— Global bar —— */
.global-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.field > span {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field select,
.field input,
.hw-row input {
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field select:focus,
.field input:focus,
.hw-row input:focus,
.measure-input:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(227, 6, 19, 0.12);
}

.global-bar .field {
  width: 200px;
}

.field-inline {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.field-inline > span {
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
  color: var(--ink);
  font-weight: 500;
}

.field-inline select {
  width: 88px;
}

/* —— Buttons —— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 16px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--red);
  color: #fff;
}

.btn-primary:hover {
  background: var(--red-dark);
}

.btn-secondary {
  background: #fff;
  border-color: var(--line-strong);
  color: var(--ink);
}

.btn-secondary:hover {
  background: #f7f7f7;
}

.btn-ghost {
  background: transparent;
  border-color: var(--line-strong);
  color: var(--ink);
  font-weight: 600;
}

.btn-ghost:hover {
  background: #fafafa;
}

.btn-sm {
  height: 32px;
  padding: 0 12px;
  font-size: 12px;
}

.btn-calc {
  height: 42px;
  padding: 0 28px;
  font-size: 15px;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  font-size: 24px;
  line-height: 1;
  color: var(--muted);
  border-radius: 6px;
}

.icon-btn:hover {
  background: #f0f0f0;
  color: var(--ink);
}

/* —— Workspace (таблица на всю ширину) —— */
.workspace {
  display: block;
}

.main-col {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* —— Table —— */
.table-wrap {
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.openings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  min-width: 980px;
}

.openings-table th,
.openings-table td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 8px 8px;
  text-align: center;
  vertical-align: middle;
}

.openings-table th:last-child,
.openings-table td:last-child {
  border-right: none;
}

.openings-table thead th {
  background: #fafafa;
  font-size: 11px;
  font-weight: 700;
  color: #444;
  line-height: 1.25;
}

.openings-table thead tr:first-child th {
  border-bottom-color: var(--line-strong);
}

.openings-table tbody tr {
  background: #fff;
  transition: background 0.12s;
}

.openings-table tbody tr:hover {
  background: #fcfcfc;
}

.openings-table tbody tr.is-selected {
  background: #fff7f7;
  outline: 2px solid var(--red);
  outline-offset: -2px;
}

.openings-table tbody tr.is-group-a {
  box-shadow: inset 4px 0 0 var(--blue);
}

.openings-table tbody tr.cut-group-header td {
  padding: 0;
  border-bottom: none;
  background: transparent;
}

.cut-group-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  margin: 8px 4px 0;
  padding: 10px 14px;
  background: #e8f0ff;
  border: 2px solid #2f6fed;
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  font-size: 13px;
  font-weight: 600;
  color: #1e4bb8;
}

.cut-group-banner strong {
  font-weight: 800;
}

.cut-group-qty {
  margin-left: auto;
  padding: 2px 8px;
  background: #2f6fed;
  color: #fff;
  border-radius: 4px;
  font-size: 12px;
}

.openings-table tbody tr.is-cut-A {
  background: #eef4ff;
  box-shadow: inset 4px 0 0 #2f6fed;
}

.openings-table tbody tr.is-cut-A + tr.is-cut-A {
  box-shadow: inset 4px 0 0 #2f6fed, inset 0 1px 0 #c9dbff;
}

.openings-table tbody tr.is-cut-header-follow {
  border-top: none;
}

.openings-table tbody tr.is-cut-B {
  background: #f3f0ff;
  box-shadow: inset 4px 0 0 #6b5ce7;
}

.openings-table tbody tr.is-cut-C {
  background: #eefaf3;
  box-shadow: inset 4px 0 0 #1a9b5c;
}

.openings-table tbody tr.is-cut-D {
  background: #fff6eb;
  box-shadow: inset 4px 0 0 #d97706;
}

.openings-table tbody tr.is-cut-A.is-selected,
.openings-table tbody tr.is-cut-B.is-selected,
.openings-table tbody tr.is-cut-C.is-selected,
.openings-table tbody tr.is-cut-D.is-selected {
  outline-color: var(--blue);
}

.group-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  flex-shrink: 0;
}

.group-badge-lg {
  width: 22px;
  height: 22px;
  font-size: 12px;
}

.ext-pair {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.ext-pair-text {
  flex: 1;
  min-width: 0;
}

.col-ext-need {
  width: 72px;
}

.col-ext-cut {
  width: 168px;
}

.col-ext-qty {
  width: 100px;
}

.col-ext-group {
  background: #eef4ff !important;
}

.ext-need-cell,
.ext-qty-cell {
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
}

.ext-cut-cell {
  font-size: 11px;
  font-weight: 600;
  line-height: 1.35;
  text-align: left;
  color: #1e4bb8;
}

.group-note {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--blue-soft);
  border: 1px solid #c9dbff;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  color: #1e4bb8;
}

.group-note-B {
  background: #f3f0ff;
  border-color: #d4ccff;
  color: #4c3db8;
}

.group-note-C {
  background: #eefaf3;
  border-color: #b8e6cd;
  color: #146b40;
}

.group-note-D {
  background: #fff6eb;
  border-color: #f5d0a0;
  color: #9a5b0a;
}

.col-num {
  width: 44px;
}

.col-room {
  width: 110px;
}

.col-door {
  width: 170px;
}

.col-frame,
.col-trim,
.col-ext-qty {
  width: 72px;
}

.col-hw {
  width: 110px;
}

.col-group {
  background: #f3f3f3 !important;
}

.num-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-weight: 700;
}

.room-cell {
  min-width: 120px;
  text-align: left;
}

.room-input {
  width: 100%;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 6px;
  background: #fff;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
}

.room-input:hover,
.room-input:focus {
  border-color: var(--line-strong);
}

.room-custom {
  width: 100%;
  height: 28px;
  margin-top: 4px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 0 6px;
  font-size: 12px;
}

.door-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
  cursor: pointer;
  padding: 2px;
  border-radius: 6px;
}

.door-cell:hover {
  background: var(--red-soft);
}

.door-thumb {
  width: 28px;
  height: 48px;
  flex-shrink: 0;
}

.door-thumb svg {
  width: 100%;
  height: 100%;
  display: block;
}

.door-meta {
  display: flex;
  flex-direction: column;
  gap: 1px;
  line-height: 1.2;
  min-width: 0;
}

.door-meta strong {
  font-size: 12px;
  font-weight: 700;
}

.door-meta span {
  font-size: 11px;
  color: var(--muted);
}

.measure-input {
  width: 64px;
  height: 30px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
}

.measure-input::placeholder,
.room-input::placeholder {
  color: #bbb;
  font-weight: 500;
}

.leaf-cell {
  font-weight: 700;
  white-space: nowrap;
}

.hw-btn {
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink);
}

.hw-btn:hover,
.hw-btn.is-active {
  border-color: var(--blue);
  background: var(--blue-soft);
  color: var(--blue);
}

.row-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  justify-content: center;
}

.row-actions.always {
  display: flex;
}

.row-actions button {
  height: 22px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
}

.row-actions button:hover {
  color: var(--ink);
  border-color: var(--line-strong);
}

.col-type { width: 88px; }
.col-sum { width: 88px; }
.col-act { width: 52px; }

.type-cell { font-size: 11px; font-weight: 600; color: #444; }
.sum-cell { font-weight: 700; font-size: 12px; white-space: nowrap; }

.warn-dot {
  display: inline-flex;
  margin-left: 4px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #e6a100;
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
}

.group-notes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.money-input {
  width: 96px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
}

.svc-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 8px 12px;
  background: #fafafa;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.svc-check {
  font-weight: 700;
  font-size: 14px;
  min-height: 36px;
  padding-right: 8px;
}

.svc-check input {
  width: 18px;
  height: 18px;
}

.svc-hint {
  font-size: 11px;
  color: var(--muted);
}

.money-input:disabled,
select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.side-check {
  margin: 4px 0;
  font-size: 13px;
}

.issues-bar {
  padding: 12px 16px;
  background: #fff8e8;
  border: 1px solid #f0d7a8;
  border-radius: var(--radius);
}

.issues-bar strong {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
}

.issues-bar ul {
  margin: 0;
  padding-left: 18px;
  font-size: 12px;
  line-height: 1.45;
}

.issue-error { color: #a40000; }
.issue-needs_clarification { color: #7a5200; }
.issue-warning { color: #6b4e00; }

.panel-hint {
  margin: 0 0 10px;
  font-size: 11px;
  color: var(--muted);
}

.spec-body { font-size: 12px; overflow: auto; max-height: 280px; }

.spec-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.spec-table th,
.spec-table td {
  border-bottom: 1px solid var(--line);
  padding: 4px 6px;
  text-align: left;
  vertical-align: top;
}

.spec-table th {
  font-size: 10px;
  color: var(--muted);
}

.muted { color: var(--muted); font-size: 11px; }

.test-out {
  margin-top: 8px;
  width: 100%;
  max-height: 120px;
  overflow: auto;
  font-size: 10px;
  text-align: left;
  background: #f7f7f7;
  padding: 8px;
  border-radius: 6px;
}

/* —— Table footer actions —— */
.table-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
}

/* —— Service / install / totals —— */
.service-bar,
.install-bar,
.totals-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.service-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--red-soft);
  color: var(--red);
  display: grid;
  place-items: center;
}

.service-icon svg {
  width: 20px;
  height: 20px;
}

.service-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 180px;
}

.service-text strong {
  font-size: 13px;
}

.service-text span {
  font-size: 12px;
  color: var(--muted);
}

.install-title {
  font-size: 13px;
  margin-right: 4px;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.check input {
  width: 16px;
  height: 16px;
  accent-color: var(--red);
}

.totals-bar {
  gap: 8px 18px;
}

.total-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 110px;
}

.total-item span {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
}

.total-item strong {
  font-size: 16px;
  font-weight: 800;
}

.total-final {
  padding-left: 14px;
  border-left: 1px solid var(--line);
  margin-left: 4px;
}

.total-final strong {
  color: var(--red);
  font-size: 20px;
}

.totals-bar .btn-calc {
  margin-left: auto;
}

/* —— Bottom panels —— */
.bottom-panels {
  display: grid;
  grid-template-columns: 1.4fr 0.8fr;
  gap: 12px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

.panel-hint {
  margin: 0 0 10px;
  font-size: 11px;
  color: var(--muted);
}

/* —— Bottom sheet: фурнитура —— */
.hw-sheet-root {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  pointer-events: none;
}

.hw-sheet-root[hidden] {
  display: none !important;
}

.hw-sheet-root:not([hidden]) {
  pointer-events: auto;
}

.hw-sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 20, 20, 0.35);
  opacity: 0;
  transition: opacity 0.22s ease;
}

.hw-sheet-root.is-open .hw-sheet-backdrop {
  opacity: 1;
}

.hw-sheet {
  position: relative;
  width: min(720px, 100%);
  max-height: min(78vh, 520px);
  overflow: auto;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.18);
  padding: 8px 20px 20px;
  transform: translateY(110%);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.hw-sheet-root.is-open .hw-sheet {
  transform: translateY(0);
}

.hw-sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 4px;
  background: #d5d5d5;
  margin: 4px auto 12px;
}

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

.hw-sheet-head h3 {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 750;
}

.hw-grid-sheet {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
  margin-bottom: 16px;
}

.hw-sheet-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.hw-sheet-actions .btn {
  min-width: 120px;
}

.hw-row {
  display: grid;
  grid-template-columns: 1fr 56px;
  gap: 6px;
}


.tip-panel ol {
  margin: 0;
  padding-left: 18px;
  font-size: 12.5px;
  line-height: 1.55;
  color: #333;
}

.tip-panel li + li {
  margin-top: 8px;
}

.brand-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.brand-panel strong {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.brand-panel p {
  margin: 8px 0 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--muted);
  line-height: 1.4;
}

/* —— Door sheet (выезжающая модалка) —— */
.door-sheet-root {
  position: fixed;
  inset: 0;
  z-index: 85;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  pointer-events: none;
}

.door-sheet-root[hidden] {
  display: none !important;
}

.door-sheet-root:not([hidden]) {
  pointer-events: auto;
}

.door-sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 20, 20, 0.35);
  opacity: 0;
  transition: opacity 0.22s ease;
}

.door-sheet-root.is-open .door-sheet-backdrop {
  opacity: 1;
}

.door-sheet {
  position: relative;
  width: min(720px, 100%);
  max-height: min(88vh, 640px);
  overflow: auto;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.18);
  padding: 8px 20px 20px;
  transform: translateY(110%);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.door-sheet-root.is-open .door-sheet {
  transform: translateY(0);
}

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

.door-sheet-head h2 {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 750;
}

.door-sheet-body {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 16px;
  margin-bottom: 16px;
  align-items: start;
}

.door-preview {
  display: grid;
  place-items: center;
  padding: 12px;
  background: linear-gradient(180deg, #fafafa, #f0f0f0);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.door-svg {
  width: 96px;
  height: auto;
}

.door-sheet-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
}

.door-sheet-fields .field select {
  width: 100%;
}

.door-sheet-fields .side-check {
  grid-column: 1 / -1;
}

.door-sheet-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.door-sheet-actions .btn {
  min-width: 120px;
}

@media (max-width: 640px) {
  .door-sheet-body {
    grid-template-columns: 1fr;
  }

  .door-sheet-fields {
    grid-template-columns: 1fr;
  }
}

/* —— Toast —— */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  z-index: 50;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.cut-details {
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  background: #fafafa;
  border: 1px dashed var(--line-strong);
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.45;
  color: #444;
  display: none;
}

.cut-details.is-open {
  display: block;
}

@media (max-width: 1100px) {
  .bottom-panels {
    grid-template-columns: 1fr;
  }

  .hw-grid-sheet {
    grid-template-columns: 1fr;
  }

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

  .topbar-title {
    text-align: left;
  }

  .topbar-badge {
    justify-self: start;
    text-align: left;
  }
}
