/* Eastline Panels Configurator — lightweight, form-first */
:root {
  --navy-950: #0a0f1a;
  --navy-900: #0f1729;
  --navy-800: #152038;
  --navy-700: #1e2d4a;
  --navy-600: #2a3f66;
  --steel-100: #e8ecf1;
  --steel-200: #c5ced9;
  --steel-300: #8b9bb0;
  --steel-400: #5c6f88;
  --accent: #3b82f6;
  --accent-light: #60a5fa;
  --verify: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --font: Inter, system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: var(--navy-950);
  color: var(--steel-100);
  line-height: 1.5;
}

a {
  color: var(--accent-light);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(15, 23, 41, 0.92);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--steel-100);
  font-weight: 600;
  text-decoration: none;
}
.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #1d4ed8);
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.brand span.sub {
  display: block;
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--steel-300);
}

.topbar-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.shell {
  max-width: 1120px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 4rem;
}

.hero-mini {
  margin-bottom: 1.25rem;
}
.hero-mini h1 {
  margin: 0 0 0.35rem;
  font-size: clamp(1.4rem, 2.5vw, 1.85rem);
  letter-spacing: -0.02em;
}
.hero-mini p {
  margin: 0;
  color: var(--steel-300);
  max-width: 52ch;
}

/* Steps */
.steps {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin: 1.25rem 0 1.5rem;
}
.step-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  font-size: 0.78rem;
  color: var(--steel-300);
  background: var(--navy-900);
  border: 1px solid transparent;
  cursor: pointer;
  font-family: inherit;
}
.step-pill .num {
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--navy-700);
  font-size: 0.7rem;
  font-weight: 600;
}
.step-pill.active {
  color: #fff;
  border-color: rgba(59, 130, 246, 0.45);
  background: rgba(59, 130, 246, 0.12);
}
.step-pill.active .num {
  background: var(--accent);
}
.step-pill.done {
  color: var(--verify);
}
.step-pill.done .num {
  background: rgba(34, 197, 94, 0.2);
  color: var(--verify);
}

.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}
@media (min-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.9fr);
    align-items: start;
  }
}

.card {
  background: var(--navy-900);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
}
.card h2 {
  margin: 0 0 0.25rem;
  font-size: 1.05rem;
}
.card .lede {
  margin: 0 0 1rem;
  color: var(--steel-300);
  font-size: 0.9rem;
}

.field {
  margin-bottom: 0.9rem;
}
.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--steel-200);
  margin-bottom: 0.35rem;
}
.field .hint {
  font-size: 0.75rem;
  color: var(--steel-400);
  margin-top: 0.3rem;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: var(--navy-950);
  color: var(--steel-100);
  font-family: inherit;
  font-size: 0.95rem;
}
input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(59, 130, 246, 0.45);
  outline-offset: 1px;
  border-color: var(--accent);
}
input[type="number"] {
  font-variant-numeric: tabular-nums;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}
.grid-4 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}
@media (min-width: 640px) {
  .grid-4 {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Enclosure groups */
.tier-group {
  margin-bottom: 1rem;
}
.tier-group h3 {
  margin: 0 0 0.5rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--steel-200);
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.tier-group h3 .rate {
  font-weight: 400;
  color: var(--steel-400);
  font-size: 0.75rem;
}
.option-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.5rem;
}
.option-card {
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: var(--navy-950);
  border-radius: 10px;
  padding: 0.7rem 0.65rem;
  cursor: pointer;
  text-align: left;
  color: inherit;
  font-family: inherit;
  transition: border-color 0.15s, background 0.15s;
}
.option-card:hover {
  border-color: rgba(59, 130, 246, 0.35);
}
.option-card.selected {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.1);
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.25);
}
.option-card .title {
  font-weight: 600;
  font-size: 0.9rem;
}
.option-card .meta {
  font-size: 0.72rem;
  color: var(--steel-400);
  margin-top: 0.2rem;
}
.option-card.disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.option-card.ab {
  border-style: dashed;
}

.radio-row {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.radio-row label {
  display: flex;
  gap: 0.55rem;
  align-items: flex-start;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: var(--navy-950);
  cursor: pointer;
  font-size: 0.9rem;
}
.radio-row label.selected {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.1);
}
.radio-row input {
  margin-top: 0.2rem;
  accent-color: var(--accent);
}
.radio-row .sku {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--steel-300);
}
.radio-row .price {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  color: var(--steel-200);
  font-size: 0.85rem;
  white-space: nowrap;
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.15rem;
}
.radio-row .price-sub {
  font-size: 0.65rem;
  font-weight: 400;
  color: var(--steel-400);
}
.radio-row label.partial-fit {
  border-style: dashed;
  opacity: 0.92;
}
.fit-badge {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 600;
  vertical-align: middle;
}
.fit-badge.ok {
  background: rgba(34, 197, 94, 0.15);
  color: #86efac;
}
.fit-badge.warn {
  background: rgba(245, 158, 11, 0.15);
  color: #fcd34d;
}
.stack-line {
  margin-top: 0.2rem;
  font-family: var(--mono);
  font-size: 0.72rem !important;
  color: var(--steel-300) !important;
}

.qty-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.55rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
.qty-row:last-child {
  border-bottom: 0;
}
.qty-row label {
  margin: 0;
  font-size: 0.9rem;
}
.qty-row input {
  width: 5.5rem;
  text-align: center;
}
.qty-row .brand-select {
  width: 100%;
  max-width: 11rem;
  font-size: 0.8rem;
  padding: 0.4rem 0.5rem;
}

.plant-brand-field {
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.plant-brand-select {
  width: 100%;
  max-width: 100%;
  font-size: 0.88rem;
  padding: 0.55rem 0.65rem;
  margin-top: 0.25rem;
}

/* Devices step — collapsible groups by device type (default closed) */
.device-groups {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0.25rem 0 0.5rem;
}
.device-group {
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(15, 23, 41, 0.55);
  overflow: hidden;
}
.device-group-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.65rem;
  position: relative;
  padding: 0.65rem 0.8rem 0.65rem 1.65rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.device-group-summary::-webkit-details-marker {
  display: none;
}
.device-group-summary::before {
  content: "▸";
  position: absolute;
  left: 0.7rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--accent-light, #7dd3fc);
  font-size: 0.8rem;
  transition: transform 0.12s ease;
}
.device-group[open] > .device-group-summary::before {
  transform: translateY(-50%) rotate(90deg);
}
.device-group-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--steel-50, #f8fafc);
  flex: 1 1 auto;
  min-width: 8rem;
}
.device-group-badge {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 0.18rem 0.5rem;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.15);
  color: #7dd3fc;
  border: 1px solid rgba(56, 189, 248, 0.28);
  white-space: nowrap;
  max-width: min(100%, 16rem);
  overflow: hidden;
  text-overflow: ellipsis;
}
.device-group-badge.muted {
  background: rgba(148, 163, 184, 0.1);
  color: var(--steel-400, #94a3b8);
  border-color: rgba(148, 163, 184, 0.2);
  font-weight: 500;
}
.device-group-sub {
  flex: 1 1 100%;
  font-size: 0.78rem;
  color: var(--steel-400, #94a3b8);
  line-height: 1.35;
}
.device-group-body {
  padding: 0.15rem 0.8rem 0.65rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.device-group-body .qty-row:last-child,
.device-group-body .pole-section:last-child {
  border-bottom: 0;
}
.device-group-lede {
  margin: 0.35rem 0 0.5rem;
  font-size: 0.8rem;
  color: var(--steel-300, #cbd5e1);
}

.pole-section {
  padding: 0.65rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
.pole-section-head label {
  margin: 0;
  font-size: 0.9rem;
  display: block;
}
.pole-section-head .hint {
  margin-top: 0.2rem;
}
.pole-matrix {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
  margin-top: 0.55rem;
}
.pole-matrix-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.pole-cell {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.25rem;
  padding: 0.45rem 0.5rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.pole-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--steel-200);
  letter-spacing: 0.04em;
}
.pole-cell input {
  width: 100%;
  text-align: center;
  font-size: 0.95rem;
}
.pole-sku {
  font-size: 0.65rem;
  color: var(--steel-400);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
@media (max-width: 520px) {
  .pole-matrix,
  .pole-matrix-3 {
    grid-template-columns: 1fr;
  }
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.65rem 1.1rem;
  border-radius: 9px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:active {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-light);
  color: #0a0f1a;
}
.btn-secondary {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.12);
  color: var(--steel-100);
}
.btn-secondary:hover:not(:disabled) {
  border-color: var(--steel-300);
}
.btn-ghost {
  background: transparent;
  color: var(--steel-300);
  border: 0;
  padding: 0.5rem 0.65rem;
}
.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.35);
}

.nav-row {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 1.25rem;
  flex-wrap: wrap;
}

/* Preview panel */
.preview-card {
  position: sticky;
  top: 4.5rem;
}
.view-toggle {
  display: inline-flex;
  gap: 0;
  margin: 0.5rem 0 0.35rem;
  padding: 3px;
  border-radius: 9px;
  background: var(--navy-950);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.view-toggle-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--steel-300);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.4rem 0.85rem;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.view-toggle-btn:hover {
  color: var(--steel-100);
}
.view-toggle-btn.active {
  background: rgba(59, 130, 246, 0.2);
  color: #fff;
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.35);
}
.inside-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: -0.35rem 0 0.75rem;
}
.legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--steel-200);
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--chip-border, rgba(255, 255, 255, 0.12));
  box-shadow: inset 3px 0 0 var(--chip, #64748b);
  padding-left: 0.55rem;
}
.scale-note {
  margin: -0.35rem 0 0.75rem;
  font-size: 0.7rem;
  color: var(--steel-400);
  line-height: 1.35;
  font-variant-numeric: tabular-nums;
}
.labor-detail {
  margin: 0.35rem 0 0.65rem;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 0.8rem;
}
.labor-detail summary {
  cursor: pointer;
  color: var(--steel-300);
  font-weight: 500;
  margin-bottom: 0.35rem;
}
.labor-detail .summary-line {
  font-size: 0.78rem;
}
.preview-svg-wrap {
  background: #0c1220;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  padding: 0.75rem;
  margin-bottom: 0.85rem;
}
.preview-svg-wrap.door-editable {
  touch-action: none;
  user-select: none;
}
.preview-svg-wrap svg {
  width: 100%;
  height: auto;
  display: block;
}
.door-pos-hint {
  margin: -0.35rem 0 0.65rem;
  font-size: 0.8rem;
}
.btn-sm {
  font-size: 0.8rem;
  padding: 0.25rem 0.55rem;
}
.drawing-canvas .door-op {
  cursor: grab;
}
.drawing-canvas .door-op:active {
  cursor: grabbing;
}
.summary-line {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.85rem;
  padding: 0.3rem 0;
  color: var(--steel-300);
}
.summary-line strong {
  color: var(--steel-100);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.summary-total {
  margin-top: 0.65rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 1.05rem;
}
.summary-total strong {
  color: #fff;
  font-size: 1.25rem;
}
.disclaimer {
  margin-top: 0.65rem;
  font-size: 0.78rem;
  color: var(--steel-400);
  line-height: 1.4;
}
.banner {
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  font-size: 0.85rem;
  margin-bottom: 0.85rem;
}
.banner.warn {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: #fcd34d;
}
.banner.info {
  background: rgba(59, 130, 246, 0.12);
  border: 1px solid rgba(59, 130, 246, 0.3);
  color: #93c5fd;
}
.banner.ok {
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.3);
  color: #86efac;
}
.banner.err {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
}

/* Estimate screen */
.estimate-hero {
  text-align: center;
  padding: 1.5rem 1rem;
}
.estimate-hero .price {
  font-size: clamp(2rem, 5vw, 2.75rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 0.35rem 0;
}
.estimate-hero .sub {
  color: var(--steel-300);
  font-size: 0.95rem;
  max-width: 40ch;
  margin: 0.5rem auto 0;
}
.bom-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.bom-table th,
.bom-table td {
  text-align: left;
  padding: 0.45rem 0.4rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  vertical-align: top;
}
.bom-table th {
  color: var(--steel-400);
  font-weight: 500;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.bom-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.bom-table .sku {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--steel-300);
  max-width: 9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bom-table .bom-total-sep td {
  border-top: 2px solid rgba(255, 255, 255, 0.18);
  padding-top: 0.55rem;
}
.bom-table .bom-total-final td {
  background: rgba(59, 130, 246, 0.12);
}
.bom-table .bom-total-row td {
  font-size: 0.92em;
}
.bom-cat {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--accent-light);
  margin-right: 0.35rem;
  opacity: 0.9;
}
.actions-stack {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-top: 1.25rem;
  /* Clear iOS Safari bottom chrome / home indicator so primary CTAs stay tappable */
  padding-bottom: max(1.5rem, calc(env(safe-area-inset-bottom, 0px) + 4.5rem));
}
.actions-stack .btn {
  width: 100%;
  min-height: 2.75rem;
}

/* Modal — scrollable; sticky actions above Safari bottom bar */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 100;
  padding: max(0.75rem, env(safe-area-inset-top, 0px)) 0.75rem max(0.75rem, env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
@media (min-width: 640px) {
  .modal-backdrop {
    align-items: center;
    padding: 1rem;
  }
}
.modal {
  position: relative;
  width: min(420px, 100%);
  max-height: min(92dvh, 100%);
  max-height: min(92vh, 100%);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--navy-900);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 1.25rem 1.25rem 0;
  margin: 0.5rem 0;
  box-sizing: border-box;
}
.modal h3 {
  margin: 0 0 0.35rem;
  padding-right: 2rem; /* room for close ✕ */
}
.modal p {
  margin: 0 0 1rem;
  color: var(--steel-300);
  font-size: 0.9rem;
}
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: stretch;
  position: sticky;
  bottom: 0;
  z-index: 2;
  margin-top: 1rem;
  margin-left: -1.25rem;
  margin-right: -1.25rem;
  padding: 0.85rem 1.25rem;
  /* Extra space under Confirm for Safari bottom bar + home indicator */
  padding-bottom: max(1rem, calc(env(safe-area-inset-bottom, 0px) + 1.25rem + 3.25rem));
  background: linear-gradient(to top, var(--navy-900) 70%, rgba(10, 15, 26, 0.92));
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0 0 14px 14px;
}
.modal-actions .btn {
  flex: 1 1 auto;
  min-height: 2.75rem;
  min-width: 7rem;
}
@media (min-width: 640px) {
  .modal-actions {
    justify-content: flex-end;
    padding-bottom: max(1rem, env(safe-area-inset-bottom, 0px));
  }
  .modal-actions .btn {
    flex: 0 1 auto;
  }
}
.hidden {
  display: none !important;
}

/* Admin */
.admin-grid {
  display: grid;
  gap: 1rem;
}
@media (min-width: 960px) {
  .admin-grid {
    grid-template-columns: 1fr 1fr;
  }
}
/* Layout editor always full viewport width under the 2-col grid */
.admin-layout-full {
  grid-column: 1 / -1;
  width: 100%;
}
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  border-radius: 8px;
}
.table-scroll .bom-table {
  min-width: 640px;
}
.bom-scroll {
  max-height: 480px;
  overflow: auto;
}
.labels-scroll {
  max-height: 420px;
  overflow: auto;
}
.drawing-canvas {
  background: #fff;
  color: #111;
  border-radius: 8px;
  overflow: auto;
  border: 1px solid rgba(15, 23, 41, 0.12);
  /* Allow browser pinch-zoom on empty canvas; drag targets set touch-action:none below */
  touch-action: manipulation;
  -webkit-overflow-scrolling: touch;
}
.drawing-canvas svg {
  width: 100%;
  min-height: 420px;
  display: block;
  user-select: none;
  touch-action: manipulation;
}
/* Only interactive pieces capture multi-touch for drag; rest of panel stays pinch-zoomable */
.drawing-canvas .comp,
.drawing-canvas .din-rail,
.drawing-canvas .door-op,
.drawing-canvas .rail-handle,
.drawing-canvas [data-rotate-chip],
.preview-svg-wrap.door-editable .door-op {
  touch-action: none;
}
/* Large interactive layout editor (admin) */
.drawing-canvas.layout-editor {
  min-height: min(78vh, 900px);
  max-height: none;
  width: 100%;
  background: #f8fafc;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 0 0 1px rgba(15, 23, 41, 0.06);
  position: relative;
}
.drawing-canvas.layout-editor svg {
  width: 100%;
  height: auto;
  min-height: min(72vh, 860px);
  max-width: 100%;
  transform-origin: 0 0;
}
.layout-zoom-controls {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}
.layout-zoom-controls .zoom-label {
  font-size: 0.8rem;
  color: var(--steel-300);
  min-width: 3.2rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.drawing-footnote {
  margin: 0.5rem 0 0;
  font-size: 0.78rem;
  color: var(--steel-400);
}
.rail-tools {
  margin: 0.5rem 0 0.75rem;
  padding: 0;
  border-radius: 10px;
  border: 1px solid rgba(59, 130, 246, 0.35);
  background: rgba(15, 23, 41, 0.75);
  overflow: hidden;
}
.rail-tools-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  flex-wrap: wrap;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
  font-size: 0.9rem;
  color: var(--steel-100);
}
.rail-tools-summary::-webkit-details-marker {
  display: none;
}
.rail-tools-summary::before {
  content: "▸";
  display: inline-block;
  width: 1rem;
  color: var(--accent-light);
  font-size: 0.85rem;
  flex: 0 0 auto;
  transition: transform 0.12s ease;
}
.rail-tools[open] > .rail-tools-summary::before {
  transform: rotate(90deg);
}
.rail-tools-title {
  font-weight: 700;
  margin-right: auto;
}
.rail-tools-summary .hint {
  font-size: 0.8rem;
}
.rail-tools-body {
  padding: 0 0.75rem 0.7rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.rail-tools-help {
  margin: 0.55rem 0 0.5rem !important;
  font-size: 0.82rem;
  color: var(--steel-300);
}
.rail-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  max-height: 220px;
  overflow: auto;
}
.rail-list-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.55rem;
  padding: 0.4rem 0.5rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(10, 15, 26, 0.5);
}
.rail-list-row.is-selected {
  border-color: #f97316;
  box-shadow: 0 0 0 1px rgba(249, 115, 22, 0.35);
}
.rail-meta {
  min-width: 9rem;
}
.rail-rotate-btn {
  font-weight: 700;
}
.rail-len-input {
  width: 4.5rem;
  background: var(--navy-900);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  color: var(--steel-100);
  padding: 0.25rem 0.4rem;
}
.layout-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.65rem;
}
.layout-toolbar #undo-layout:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.admin-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

/* —— Mobile admin configurator (phone testing / zoom) —— */
@media (max-width: 768px) {
  /* Sticky topbar covers the layout when page-zoomed; use static + compact chrome */
  .topbar {
    position: relative;
    top: auto;
    padding: 0.5rem 0.75rem;
    flex-wrap: wrap;
    gap: 0.45rem;
    z-index: 20;
  }
  .topbar .brand span.sub {
    display: none;
  }
  .topbar-actions {
    gap: 0.35rem;
  }
  .topbar-actions .btn {
    padding: 0.35rem 0.55rem;
    font-size: 0.8rem;
  }
  .shell {
    padding: 0.75rem 0.65rem 3.5rem;
  }
  .hero-mini {
    margin-bottom: 0.75rem;
  }
  .hero-mini h1 {
    font-size: 1.25rem;
  }
  .hero-mini p {
    font-size: 0.88rem;
  }

  /* Detail view: hide marketing chrome; keep a compact sticky tool strip */
  body.admin-detail .topbar,
  body.admin-detail .hero-mini {
    display: none;
  }
  body.admin-detail .shell {
    padding: 0.4rem 0.45rem 3rem;
    max-width: none;
  }
  body.admin-detail .admin-toolbar {
    position: sticky;
    top: 0;
    z-index: 45;
    margin: 0 -0.45rem 0.65rem;
    padding: 0.45rem 0.45rem;
    background: rgba(10, 15, 26, 0.96);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    gap: 0.35rem;
  }
  body.admin-detail .admin-toolbar .btn {
    padding: 0.4rem 0.55rem;
    font-size: 0.8rem;
  }
  body.admin-detail .print-layout-card > h2 {
    font-size: 1.05rem;
    margin-bottom: 0.35rem;
  }
  body.admin-detail .print-layout-card > .lede {
    font-size: 0.82rem;
    margin-bottom: 0.5rem;
  }
  body.admin-detail .rail-tools-summary {
    padding: 0.45rem 0.55rem;
  }
  body.admin-detail .rail-tools-body {
    padding: 0 0.55rem 0.55rem;
  }
  body.admin-detail .rail-list {
    max-height: 140px;
  }
  .drawing-canvas.layout-editor {
    min-height: min(70vh, 720px);
    /* Overscroll isolation so page chrome doesn't steal pan/zoom feel as badly */
    overscroll-behavior: contain;
  }
  .drawing-canvas.layout-editor svg {
    min-height: min(65vh, 680px);
  }
  .layout-toolbar {
    gap: 0.4rem;
  }
  .layout-toolbar .hint {
    font-size: 0.75rem;
    flex: 1 1 100%;
  }
}
.notes-box {
  min-height: 100px;
  resize: vertical;
}
.cutlist-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}
.cutlist-notes {
  margin: 0.35rem 0 0.75rem;
}
.cutlist-notes summary {
  cursor: pointer;
  user-select: none;
}
.cutlist-cost-table {
  font-size: 0.9rem;
}
.label-table {
  width: 100%;
  font-size: 0.78rem;
  border-collapse: collapse;
}
.label-table th,
.label-table td {
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 0.3rem 0.4rem;
}
.label-scheme-note {
  font-size: 0.88rem;
  max-width: 52rem;
}
.label-row-field td:first-child {
  border-left: 3px solid #3b82f6;
}
.label-row-door td:first-child {
  border-left: 3px solid #a855f7;
}
.label-row-power td:first-child {
  border-left: 3px solid #f59e0b;
}
.print-label-legend {
  margin-top: 0.4rem;
  font-size: 8.5pt;
  color: #475569;
}
.hint {
  color: var(--steel-400);
  font-size: 0.85em;
}
.print-only {
  display: none;
}
/* Running header/footer for print package sections (screen-hidden via .print-only) */
.print-doc-header,
.print-doc-footer {
  display: none;
}
.print-cover {
  margin-bottom: 1.5rem;
}
.print-brand {
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #334155;
  font-weight: 600;
}
.print-meta {
  width: 100%;
  max-width: 420px;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.9rem;
}
.print-meta th,
.print-meta td {
  border: 1px solid #cbd5e1;
  padding: 0.35rem 0.55rem;
  text-align: left;
}
.print-meta th {
  width: 38%;
  background: #f1f5f9;
  font-weight: 600;
}
.print-disclaimer {
  font-size: 0.8rem;
  color: #475569;
  max-width: 36rem;
}
.print-notes {
  margin-top: 0.75rem;
  font-size: 0.9rem;
}
.print-io {
  margin: 0.5rem 0;
  font-size: 0.9rem;
}

@media print {
  /*
   * Real @page margins (not body padding). Chrome ignores body padding after
   * page breaks when @page margin is 0, so headers/footers sat flush to the edge.
   * Still uncheck “Headers and footers” in the print dialog so Chrome does not
   * stamp URL/date into the margin band.
   */
  @page {
    size: letter;
    margin: 0.5in;
  }
  html {
    background: #fff !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  body {
    background: #fff !important;
    color: #000 !important;
    margin: 0 !important;
    padding: 0 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .topbar,
  .admin-toolbar,
  .hero-mini,
  .no-print {
    display: none !important;
  }
  .print-only {
    display: block !important;
  }
  .print-doc-header {
    display: flex !important;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.75rem;
    flex-wrap: wrap;
    border-bottom: 1.5px solid #0f172a;
    padding: 0 0 0.35rem;
    margin: 0 0 0.5rem;
    font-size: 8pt;
    color: #0f172a;
    /* Keep running header off the paper edge even if a section restarts a page */
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
  }
  .print-doc-header-left {
    display: flex;
    align-items: baseline;
    gap: 0.55rem;
    min-width: 0;
  }
  .print-doc-brand {
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    font-size: 8pt;
  }
  .print-doc-sheet {
    font-weight: 600;
    color: #334155;
  }
  .print-doc-header-right {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem 0.85rem;
    color: #334155;
    justify-content: flex-end;
  }
  .print-doc-footer {
    display: flex !important;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.75rem;
    flex-wrap: wrap;
    border-top: 1px solid #94a3b8;
    padding: 0.35rem 0 0;
    margin: 0.5rem 0 0;
    font-size: 7.5pt;
    color: #475569;
  }
  .print-doc-footer-disclaimer {
    flex: 1 1 14rem;
    min-width: 0;
  }
  .print-doc-footer-meta {
    white-space: nowrap;
    color: #334155;
    font-weight: 500;
  }
  .shell {
    max-width: none;
    padding: 0 !important;
    margin: 0 !important;
  }
  /* Detail view screen chrome used negative margins; neutralize for print */
  body.admin-detail .shell {
    padding: 0 !important;
    margin: 0 !important;
  }
  body.admin-detail .admin-toolbar {
    display: none !important;
    margin: 0 !important;
  }
  .admin-grid {
    display: block !important;
  }
  .card,
  .print-section {
    border: 1px solid #94a3b8 !important;
    background: #fff !important;
    color: #000 !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    margin: 0 0 0.4rem;
    padding: 0.4rem 0.55rem;
    break-inside: auto;
  }
  .print-section h2 {
    margin: 0 0 0.35rem;
    font-size: 13pt;
  }
  .print-config-card {
    break-after: avoid;
  }
  .print-config-card .grid-2 {
    gap: 0.35rem 1rem;
    margin-bottom: 0.25rem;
  }
  .print-config-card .field {
    margin: 0;
  }
  .print-config-card .field label {
    margin-bottom: 0.1rem;
  }
  /* Config + BOM share pages; only layout & labels force a new page */
  .print-page-break {
    break-before: page;
    page-break-before: always;
  }
  .print-cover {
    break-after: page;
    page-break-after: always;
    margin: 0;
  }
  .print-cover h1 {
    margin: 0.25rem 0 0.5rem;
    font-size: 18pt;
  }
  .print-meta {
    margin: 0.5rem 0;
  }
  .print-disclaimer {
    margin: 0.5rem 0 0;
  }
  .print-bom-lede {
    margin: 0 0 0.35rem;
    font-size: 9pt;
    color: #334155;
  }
  .print-notes {
    margin-top: 0.35rem;
    font-size: 9pt;
  }
  .print-io {
    margin: 0.25rem 0 0.15rem;
    font-size: 9pt;
  }
  /* Config card on-screen totals stay no-print; cover + BOM body rows carry print totals */
  .print-config-card .summary-line {
    display: none !important;
  }
  /* Keep materials/labor/total with BOM lines — never a lone Total on a blank sheet */
  .bom-table .bom-total-row {
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .bom-table .bom-total-sep td {
    border-top: 2px solid #0f172a !important;
    padding-top: 0.35rem !important;
  }
  .bom-table .bom-total-final td {
    background: #f1f5f9 !important;
    font-size: 9.5pt;
  }
  .print-bom-total-note {
    margin: 0.35rem 0 0;
    font-size: 8pt;
    color: #475569;
  }
  .print-layout-card {
    break-before: page;
    page-break-before: always;
    break-inside: avoid;
    page-break-inside: avoid;
    border: none !important;
    padding: 0 !important;
    margin: 0 !important;
  }
  .print-layout-card h2 {
    margin: 0 0 0.25rem;
    font-size: 12pt;
  }
  .drawing-canvas {
    border: none !important;
    overflow: visible;
    background: #fff !important;
    padding: 0 !important;
  }
  .drawing-canvas svg {
    min-height: 0 !important;
    max-height: 9.6in;
    width: 100%;
    height: auto;
    display: block;
  }
  /* Hide layout editor chrome in print */
  .rail-controls-layer,
  .rail-rotate-chip,
  .rail-handle,
  .rail-hit {
    display: none !important;
  }
  .bom-scroll,
  .labels-scroll,
  .table-scroll {
    max-height: none !important;
    /* Screen uses min-width:640px + scroll; in print that pushes row rules past the card border */
    overflow: hidden !important;
    max-width: 100% !important;
    width: 100% !important;
  }
  .table-scroll .bom-table {
    min-width: 0 !important;
  }
  .bom-table,
  .label-table {
    color: #000;
    font-size: 8.5pt;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    table-layout: fixed;
    border-collapse: collapse;
    border-spacing: 0;
  }
  /*
   * Visible row separators between BOM items (what print used before).
   * Table stays max-width 100% so lines no longer spill past the card edge.
   */
  .bom-table th,
  .bom-table td,
  .label-table th,
  .label-table td {
    border-top: none !important;
    border-left: none !important;
    border-right: none !important;
    border-bottom: 1px solid #94a3b8 !important;
    color: #000 !important;
    padding: 0.2rem 0.3rem;
    overflow: hidden;
    vertical-align: top;
  }
  .bom-table thead th {
    border-bottom: 1.5px solid #0f172a !important;
    font-weight: 600;
  }
  .bom-table col.bom-col-sku { width: 13%; }
  .bom-table col.bom-col-desc { width: 38%; }
  .bom-table col.bom-col-brand { width: 13%; }
  .bom-table col.bom-col-qty { width: 7%; }
  .bom-table col.bom-col-unit { width: 14%; }
  .bom-table col.bom-col-ext { width: 15%; }
  .bom-table .sku {
    max-width: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  /* Description column only — total rows use colspan so money is also nth-child(2);
     never let overflow-wrap:anywhere split $x,xxx.xx across lines. */
  .bom-table tbody tr:not(.bom-total-row) td:nth-child(2) {
    word-wrap: break-word;
    overflow-wrap: anywhere;
    white-space: normal;
  }
  .bom-table td.num,
  .bom-table th.num {
    white-space: nowrap !important;
    overflow-wrap: normal !important;
    word-break: keep-all !important;
    font-variant-numeric: tabular-nums;
  }
  .bom-table .bom-total-row td.num {
    white-space: nowrap !important;
  }
  .bom-table thead {
    display: table-header-group;
  }
  .bom-table .bom-total-sep td {
    border-top: 2px solid #0f172a !important;
    border-bottom: 1px solid #94a3b8 !important;
  }
  .bom-table .bom-total-final td {
    border-bottom: 1px solid #0f172a !important;
  }
  /*
   * Legacy: if any tfoot remains, treat as body rows (not repeating footer).
   * Active totals live in tbody.bom-total-row so they flow with line items.
   */
  .bom-table tfoot {
    display: table-row-group;
  }
  .bom-table .sku {
    color: #334155 !important;
  }
  .lede,
  h2 {
    color: #0f172a !important;
  }
  a {
    color: #000 !important;
    text-decoration: none !important;
  }
  .footer-note {
    display: none !important;
  }
}

.footer-note {
  margin-top: 2rem;
  text-align: center;
  font-size: 0.75rem;
  color: var(--steel-400);
}

/* Admin jobs board */
.admin-inline-select {
  max-width: 9.5rem;
  font-size: 0.75rem;
  padding: 0.25rem 0.35rem;
  border-radius: 6px;
  border: 1px solid var(--border, rgba(255, 255, 255, 0.12));
  background: var(--navy-950, #0a0f1a);
  color: inherit;
}
.admin-ops-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: flex-end;
}
.admin-ops-bar label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: var(--steel-400, #94a3b8);
}
.admin-ops-bar select,
.admin-ops-notes {
  font: inherit;
  font-size: 0.875rem;
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border, rgba(255, 255, 255, 0.12));
  background: var(--navy-950, #0a0f1a);
  color: inherit;
  min-width: 10rem;
}
.admin-ops-notes {
  width: 100%;
  min-width: 0;
  resize: vertical;
}
.admin-pre {
  white-space: pre-wrap;
  font-family: inherit;
  font-size: 0.875rem;
  background: var(--navy-950, #0a0f1a);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
}
.admin-template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
}
.admin-template-card {
  border: 1px solid var(--border, rgba(255, 255, 255, 0.1));
  border-radius: 8px;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.admin-template-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
