:root {
  --brand: #0052cc;
  --brand-deep: #013b93;
  --brand-soft: #e9f2ff;
  --ink: #15263b;
  --muted: #66788f;
  --line: #d6e0ec;
  --line-strong: #c7d4e3;
  --surface: #ffffff;
  --surface-subtle: #f8fbff;
  --page:
    radial-gradient(circle at top left, rgba(0, 82, 204, 0.12), transparent 30%),
    linear-gradient(180deg, #f4f8fc 0%, #eaf1f8 100%);
  --shadow: 0 18px 38px rgba(13, 38, 76, 0.08);
  --shadow-soft: 0 10px 26px rgba(13, 38, 76, 0.06);
  --warning: #a65215;
  --warning-bg: #fff4e7;
  --success: #0b6e4f;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "DM Sans", sans-serif;
  color: var(--ink);
  background: var(--page);
  font-size: 14px;
}

button,
input,
select {
  font: inherit;
}

button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.app-shell {
  width: 100%;
  min-height: 100vh;
  padding: 16px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 14px;
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow-soft);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--brand), var(--brand-deep));
  color: #fff;
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  letter-spacing: 0.06em;
  box-shadow: 0 12px 28px rgba(0, 82, 204, 0.22);
}

.brand-name,
.brand-subtitle,
.header-copy h1,
.header-copy p,
.section-tag,
.card-header h2,
.section-heading-row h3,
.field label,
.group-label {
  margin: 0;
}

.brand-name {
  color: var(--brand);
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.96rem;
  font-weight: 700;
}

.brand-subtitle {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.8rem;
}

.header-copy {
  text-align: right;
}

.header-copy h1 {
  color: var(--brand);
  font-family: "Space Grotesk", sans-serif;
  font-size: clamp(1.22rem, 1.9vw, 1.75rem);
}

.header-copy p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.84rem;
}

.app-grid {
  display: grid;
  grid-template-columns: 320px minmax(0, 1.55fr) 360px;
  grid-template-areas:
    "controls preview project"
    "info preview project";
  gap: 14px;
  align-items: start;
}

.panel-controls {
  grid-area: controls;
}

.panel-preview {
  grid-area: preview;
}

.panel-info {
  grid-area: info;
}

.panel-project {
  grid-area: project;
}

.card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 0;
}

.summary-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.card-header h2 {
  font-family: "Space Grotesk", sans-serif;
  font-size: 1rem;
  color: var(--ink);
}

.section-tag {
  color: var(--brand);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.64rem;
  font-weight: 700;
}

.panel-controls {
  padding-bottom: 14px;
}

.panel-project {
  padding-bottom: 14px;
}

.control-section {
  padding: 14px 16px 0;
}

.control-section + .control-section {
  padding-top: 16px;
}

.section-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.section-heading-row h3 {
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.88rem;
  color: var(--ink);
}

.helper-banner {
  margin: 0 0 14px;
  padding: 10px 12px;
  border: 1px solid #d5e4fb;
  border-radius: 12px;
  background: var(--brand-soft);
  color: #3f5f82;
  font-size: 0.8rem;
  line-height: 1.4;
}

.helper-note {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.35;
}

.fitting-chips {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.fitting-chip {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-subtle);
  color: var(--ink);
  font-weight: 700;
  font-size: 0.82rem;
  text-align: center;
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.fitting-chip:hover {
  transform: translateY(-1px);
  border-color: #b7ccef;
}

.fitting-chip.is-active {
  border-color: rgba(0, 82, 204, 0.26);
  background: linear-gradient(180deg, rgba(0, 82, 204, 0.12), rgba(0, 82, 204, 0.06));
  color: var(--brand);
  box-shadow: 0 10px 22px rgba(0, 82, 204, 0.12);
}

.controls {
  display: grid;
  gap: 12px;
}

.control-group {
  display: grid;
  gap: 10px;
}

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

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

.field label,
.group-label {
  color: var(--brand-deep);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.field-control {
  position: relative;
}

.field input,
.field select {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.field input.has-unit {
  padding-right: 44px;
}

.field select {
  padding-right: 38px;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(0, 82, 204, 0.1);
}

.field-unit {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  pointer-events: none;
}

.field small {
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.35;
}

.view-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.action-section {
  padding-top: 12px;
}

.primary-actions,
.project-actions,
.summary-actions,
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.primary-button,
.secondary-button,
.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 8px 13px;
  border-radius: 10px;
  font-size: 0.82rem;
  border: 1px solid transparent;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.primary-button {
  background: linear-gradient(135deg, var(--brand), var(--brand-deep));
  color: #fff;
  box-shadow: 0 10px 24px rgba(0, 82, 204, 0.18);
}

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

.danger-button {
  background: #fff4f2;
  border-color: #f2c7c2;
  color: #a5392f;
}

.primary-button:hover,
.secondary-button:hover,
.danger-button:hover,
.view-button:hover,
.fitting-chip:hover {
  transform: translateY(-1px);
}

.view-button {
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-weight: 700;
  font-size: 0.78rem;
  cursor: pointer;
  transition: border-color 0.16s ease, background 0.16s ease, color 0.16s ease;
}

.view-button:hover {
  border-color: #b7ccef;
}

.view-button.is-active {
  border-color: rgba(0, 82, 204, 0.26);
  background: rgba(0, 82, 204, 0.08);
  color: var(--brand);
}

.preview-header {
  align-items: flex-start;
}

.preview-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.preview-note {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid #d5e4fb;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-deep);
  font-size: 0.74rem;
  font-weight: 700;
}

.viewer {
  position: relative;
  min-height: 680px;
  height: min(78vh, 940px);
  margin: 12px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  overflow: hidden;
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.98), rgba(231, 239, 248, 0.96) 52%, rgba(220, 231, 242, 0.98)),
    linear-gradient(180deg, #f9fbfe 0%, #e8f0f7 100%);
}

.viewer canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.label-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.dimension-line {
  position: absolute;
  height: 2px;
  transform-origin: 0 50%;
  background: var(--brand);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.45);
}

.dimension-line.length {
  background: #0b1724;
}

.dimension-extension {
  position: absolute;
  height: 2px;
  transform-origin: 0 50%;
  background: rgba(0, 82, 204, 0.68);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.35);
}

.dimension-cap {
  position: absolute;
  width: 10px;
  height: 10px;
  border: 2px solid var(--brand);
  border-radius: 50%;
  background: #fff;
  transform: translate(-50%, -50%);
}

.dimension-label {
  position: absolute;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid rgba(0, 82, 204, 0.2);
  background: rgba(255, 255, 255, 0.96);
  color: var(--brand-deep);
  font-size: 0.78rem;
  font-weight: 700;
  transform: translate(-50%, -50%);
  white-space: nowrap;
  box-shadow: 0 10px 22px rgba(0, 82, 204, 0.12);
}

.axis-indicator {
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: 82px;
  height: 82px;
  border: 1px solid rgba(0, 82, 204, 0.12);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 10px 24px rgba(13, 38, 76, 0.08);
}

.axis {
  position: absolute;
  left: 18px;
  bottom: 18px;
  height: 2px;
  transform-origin: 0 50%;
}

.axis span {
  position: absolute;
  right: -10px;
  top: -12px;
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
}

.axis-x {
  width: 40px;
  background: #0f172a;
}

.axis-x span {
  color: #0f172a;
}

.axis-y {
  width: 42px;
  background: #2563eb;
  transform: rotate(-90deg);
}

.axis-y span {
  color: #2563eb;
}

.axis-z {
  width: 44px;
  background: #0ea5a4;
  transform: rotate(-32deg);
}

.axis-z span {
  color: #0ea5a4;
}

.warnings {
  display: grid;
  gap: 8px;
  padding: 12px 16px 0;
}

.project-meta,
.project-summary,
.project-list-section,
.project-actions {
  padding: 14px 16px 0;
}

.project-label {
  display: block;
  margin-bottom: 6px;
  color: var(--brand-deep);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.project-name-input {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.project-totals {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 14px 16px 0;
}

.total-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(247,250,255,0.98));
}

.total-card-wide {
  grid-column: 1 / -1;
}

.total-card span,
.piece-meta-label {
  display: block;
  color: var(--muted);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.total-card strong {
  display: block;
  margin-top: 8px;
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.96rem;
}

.project-summary h3,
.project-list-section h3 {
  margin: 0 0 10px;
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.86rem;
}

.type-summary {
  display: grid;
  gap: 8px;
}

.type-summary-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfdff;
}

.project-pieces {
  display: grid;
  gap: 10px;
}

.piece-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfdff;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.piece-card.is-selected {
  border-color: rgba(0, 82, 204, 0.32);
  background: rgba(0, 82, 204, 0.05);
  box-shadow: 0 12px 24px rgba(0, 82, 204, 0.12);
}

.piece-card-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.piece-card h4 {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.9rem;
}

.piece-card p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
}

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

.piece-meta {
  padding: 8px 10px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--line);
}

.piece-meta strong {
  display: block;
  margin-top: 6px;
}

.piece-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.piece-notes {
  margin-top: 10px;
}

.piece-notes textarea {
  width: 100%;
  min-height: 68px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  resize: vertical;
}

.mini-button {
  min-height: 34px;
  padding: 7px 10px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: #fff;
  font-weight: 700;
  font-size: 0.76rem;
  cursor: pointer;
}

.quantity-input {
  width: 74px;
  min-height: 34px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.mini-button.is-active {
  border-color: rgba(0, 82, 204, 0.26);
  color: var(--brand);
  background: rgba(0, 82, 204, 0.08);
}

.empty-state {
  padding: 12px;
  border: 1px dashed var(--line-strong);
  border-radius: 12px;
  color: var(--muted);
  background: rgba(255,255,255,0.72);
}

.summary-panel {
  margin-top: 14px;
  padding-bottom: 16px;
}

.summary-customer,
.summary-project,
.summary-pieces,
.summary-totals {
  padding: 14px 16px 0;
}

.summary-block {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfdff;
}

.summary-block h3 {
  margin: 0 0 10px;
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.88rem;
}

.summary-list {
  display: grid;
  gap: 10px;
}

.summary-piece-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr 0.6fr 0.8fr;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.summary-piece-row strong,
.summary-piece-row span {
  display: block;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.44);
  backdrop-filter: blur(4px);
}

.modal-dialog {
  position: relative;
  width: min(760px, calc(100% - 24px));
  margin: 48px auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 24px 60px rgba(13, 38, 76, 0.16);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px 0;
}

.lead-form {
  padding: 16px 18px 18px;
}

.modal-grid {
  margin-bottom: 16px;
}

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-size: 1.3rem;
  cursor: pointer;
}

.toast {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 80;
  padding: 10px 12px;
  border-radius: 12px;
  background: #0f172a;
  color: #fff;
  box-shadow: 0 14px 30px rgba(15, 23, 42, 0.18);
}

.warning {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--warning-bg);
  color: var(--warning);
  font-size: 0.8rem;
  line-height: 1.4;
}

.warning.ok {
  background: rgba(11, 110, 79, 0.08);
  color: var(--success);
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 12px 16px 16px;
}

.info-card {
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(247, 250, 255, 0.98));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.info-card span {
  display: block;
  color: var(--muted);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.info-card strong {
  display: block;
  margin-top: 6px;
  color: var(--ink);
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.88rem;
  line-height: 1.24;
}

.disclaimer-bar {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid #d7e5fa;
  border-radius: 14px;
  background: rgba(0, 82, 204, 0.07);
  color: var(--brand-deep);
  font-size: 0.8rem;
  line-height: 1.45;
  box-shadow: var(--shadow-soft);
}

.build-marker {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 30;
  padding: 7px 10px;
  border: 1px solid rgba(0, 82, 204, 0.18);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--brand-deep);
  font-size: 0.72rem;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(13, 38, 76, 0.1);
}

@media (max-width: 1180px) {
  .app-grid {
    grid-template-columns: 1fr;
    grid-template-areas: none;
  }

  .viewer {
    min-height: 520px;
  }

  .info-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

}

@media (max-width: 760px) {
  .app-shell {
    padding: 12px;
  }

  .app-header {
    flex-direction: column;
    align-items: flex-start;
    padding: 16px;
  }

  .header-copy {
    text-align: left;
  }

  .preview-actions {
    align-items: flex-start;
  }

  .fitting-chips,
  .field-grid,
  .info-grid,
  .project-totals,
  .piece-grid,
  .summary-piece-row,
  .modal-grid {
    grid-template-columns: 1fr;
  }

  .viewer {
    min-height: 380px;
    height: 58vh;
    margin: 12px;
  }

  .preview-note {
    min-height: auto;
    padding: 8px 12px;
  }

  .axis-indicator {
    width: 84px;
    height: 84px;
  }
}
