:root {
  color-scheme: light;
  --bg: #eef3f0;
  --panel: #ffffff;
  --ink: #10201d;
  --muted: #64736f;
  --line: #d7e1dd;
  --brand: #0f766e;
  --brand-dark: #0b5d57;
  --amber: #c27a13;
  --blue: #2563eb;
  --shadow: 0 20px 55px rgba(17, 43, 38, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(15, 118, 110, 0.10), rgba(238, 243, 240, 0) 360px),
    var(--bg);
}

body:not(.is-authenticated) .topbar,
body:not(.is-authenticated) .print-header,
body:not(.is-authenticated) .print-watermark,
body:not(.is-authenticated) .app-shell {
  display: none;
}

body.is-authenticated .entry-screen {
  display: none;
}

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

button {
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: max(18px, env(safe-area-inset-top)) 28px 18px;
  background: rgba(238, 243, 240, 0.88);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid rgba(215, 225, 221, 0.9);
}

.print-header {
  display: none;
}

.print-watermark {
  display: none;
}

.entry-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.entry-card {
  width: min(100%, 420px);
  display: grid;
  gap: 18px;
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.entry-card h1 {
  font-size: 32px;
}

.entry-copy {
  color: var(--muted);
  line-height: 1.5;
}

.entry-card label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.entry-card input {
  min-height: 48px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--ink);
  background: #fff;
}

.entry-card input:focus {
  outline: 3px solid rgba(15, 118, 110, 0.18);
  border-color: var(--brand);
}

.entry-error {
  min-height: 20px;
  color: #b42318;
  font-size: 14px;
  font-weight: 700;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.1;
}

h2 {
  font-size: 22px;
}

h3 {
  font-size: 20px;
}

.eyebrow {
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.top-actions,
.section-head,
.tabs,
.segmented,
.resource-row,
.signature-row {
  display: flex;
  align-items: center;
}

.top-actions {
  gap: 10px;
}

.primary-btn,
.secondary-btn,
.icon-btn,
.tabs button,
.segmented button {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 18px;
  font-weight: 750;
}

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

.secondary-btn {
  width: 100%;
  margin-top: 12px;
  border-color: var(--brand);
  color: var(--brand-dark);
  background: #e7f6f2;
}

.inline-form-btn {
  align-self: end;
  margin-top: 0;
}

.product-link-btn {
  margin-top: 0;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(360px, 0.88fr) minmax(500px, 1.12fr);
  gap: 18px;
  width: min(1380px, calc(100vw - 32px));
  margin: 18px auto 32px;
}

.panel {
  background: var(--panel);
  border: 1px solid rgba(215, 225, 221, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.input-panel,
.output-panel {
  padding: 20px;
}

.section-head {
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.section-head.compact {
  margin-top: 24px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  color: var(--brand-dark);
  background: #dff4ee;
  font-weight: 800;
}

.segmented {
  gap: 6px;
  padding: 5px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f6faf8;
}

.segmented button {
  flex: 1;
  border-color: transparent;
  background: transparent;
}

.segmented button.active,
.tabs button.active {
  background: var(--brand);
  color: #fff;
}

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

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.price-note {
  margin: -2px 0 4px;
  color: var(--brand-dark);
  font-size: 13px;
  font-weight: 800;
}

.fit-check {
  display: grid;
  gap: 14px;
  margin: 2px 0 6px;
  padding: 16px;
  border: 1px solid #b9d9d3;
  border-radius: 8px;
  background: #f4fbf8;
}

.fit-head,
.fit-grid {
  display: grid;
  gap: 12px;
}

.fit-head {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
}

.fit-head h3 {
  margin-top: 2px;
  font-size: 18px;
}

.fit-status {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  color: #fff;
  background: var(--brand);
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

.fit-status[data-tone="warn"] {
  background: var(--amber);
}

.fit-status[data-tone="neutral"] {
  background: var(--muted);
}

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

.fit-grid div {
  min-height: 82px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.fit-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.fit-grid strong {
  display: block;
  margin-top: 8px;
  font-size: 18px;
  line-height: 1.15;
}

.fit-note {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.45;
}

.datasheet-panel {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.datasheet-panel h3 {
  margin-top: 2px;
  font-size: 18px;
}

.datasheet-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.datasheet-links a,
.datasheet-missing {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfa;
  color: var(--brand-dark);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.datasheet-missing {
  color: var(--muted);
  background: #fff;
}

.proposal-datasheets {
  margin-top: 14px;
}

.reference-only input {
  color: #5d4b00;
  background: #fffbeb;
  border-color: #f1d36b;
}

.span-2 {
  grid-column: 1 / -1;
}

.hidden-field {
  display: none;
}

input,
select,
textarea {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.13);
}

.tabs {
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.tabs button {
  white-space: nowrap;
}

.view {
  display: none;
  padding-top: 18px;
}

.view.active {
  display: block;
}

.proposal-cover {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: stretch;
  padding: 22px;
  border: 1px solid #b9d9d3;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.12), rgba(15, 118, 110, 0.02)),
    #f6fbf9;
}

.proposal-cover h2 {
  margin-top: 6px;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1;
}

.proposal-cover p:not(.eyebrow) {
  max-width: 680px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.5;
}

.proposal-code-card {
  min-width: 150px;
  display: grid;
  align-content: center;
  justify-items: start;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.proposal-code-card span,
.proposal-metrics span,
.proposal-next span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.proposal-code-card strong {
  margin-top: 8px;
  color: var(--brand-dark);
  font-size: 32px;
}

.proposal-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.proposal-metrics div {
  min-height: 116px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.proposal-metrics strong {
  display: block;
  margin-top: 10px;
  font-size: clamp(22px, 2.8vw, 34px);
  line-height: 1.05;
}

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

.proposal-card,
.proposal-next {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: #fff;
}

.proposal-card-strong {
  border-color: #b9d9d3;
  background: #f8fbfa;
}

.proposal-card h3 {
  margin-top: 4px;
}

.proposal-next {
  margin-top: 12px;
  background: var(--brand);
  color: #fff;
}

.proposal-next .eyebrow,
.proposal-next span {
  color: #fff;
}

.proposal-next div {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.proposal-next span {
  min-height: 58px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
}

.hero-metrics,
.payment-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.hero-metrics div,
.payment-grid div {
  min-height: 104px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfa;
}

.hero-metrics span,
.payment-grid span,
.signature-row span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.hero-metrics strong,
.payment-grid strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(20px, 2.4vw, 32px);
  line-height: 1.1;
}

.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.summary-box,
.layout-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: #fff;
}

dl {
  display: grid;
  grid-template-columns: minmax(120px, 0.9fr) minmax(0, 1.1fr);
  gap: 10px 16px;
  margin: 16px 0 0;
}

dt {
  color: var(--muted);
  font-weight: 750;
}

dd {
  margin: 0;
  text-align: right;
  font-weight: 800;
}

.resource-row {
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.bill-source {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfa;
}

.bill-source a {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  padding: 0 12px;
  border-radius: 8px;
  color: #fff;
  background: var(--blue);
  text-decoration: none;
  font-weight: 800;
  white-space: nowrap;
}

.custom-products {
  margin-top: 20px;
  padding-top: 2px;
}

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

.add-product-grid .span-2 {
  grid-column: span 2;
}

.custom-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.custom-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfa;
}

.custom-item strong {
  display: block;
}

.custom-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.resource-row a {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--brand-dark);
  text-decoration: none;
  font-weight: 800;
}

.resource-summary {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #f8fbfa;
  font-size: 13px;
  font-weight: 800;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
}

th,
td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  text-align: right;
}

th:first-child,
td:first-child {
  text-align: left;
}

th {
  color: var(--muted);
  background: #f6faf8;
  font-size: 13px;
}

tr:last-child td {
  border-bottom: 0;
}

.bill-section-row td {
  color: #fff;
  background: var(--brand);
  font-weight: 900;
}

.acceptance {
  margin-top: 12px;
}

.acceptance p {
  margin-top: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.signature-row {
  justify-content: space-between;
  gap: 18px;
  margin-top: 22px;
}

.signature-block {
  flex: 1;
  min-height: 136px;
}

.signature-line,
.date-line {
  height: 42px;
  border-bottom: 1px solid var(--line);
}

.date-line {
  height: 34px;
}

.signature-block strong {
  display: block;
  min-height: 24px;
  margin: 8px 0 12px;
  font-size: 16px;
}

.signature-block span + .date-line {
  margin-top: 2px;
}

.layout-card {
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
  gap: 24px;
}

.layout-card p:not(.eyebrow) {
  margin-top: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.layout-grid {
  display: grid;
  grid-template-columns: minmax(120px, 0.8fr) minmax(0, 1.2fr);
  gap: 12px;
}

.layout-grid span {
  color: var(--muted);
  font-weight: 750;
}

.layout-grid strong {
  text-align: right;
}

@media (max-width: 1020px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .input-panel {
    order: 2;
  }

  .output-panel {
    order: 1;
  }
}

@media (max-width: 720px) {
  .topbar {
    padding-left: 16px;
    padding-right: 16px;
  }

  .app-shell {
    width: calc(100vw - 20px);
    margin-top: 10px;
  }

  .form-grid,
  .add-product-grid,
  .two-col,
  .proposal-cover,
  .proposal-grid,
  .layout-card {
    grid-template-columns: 1fr;
  }

  .span-2,
  .add-product-grid .span-2 {
    grid-column: auto;
  }

  .hero-metrics,
  .proposal-metrics,
  .payment-grid,
  .fit-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .proposal-next div {
    grid-template-columns: 1fr;
  }

  .bill-source {
    align-items: stretch;
    flex-direction: column;
  }
}

@media (max-width: 460px) {
  .fit-head,
  .fit-grid {
    grid-template-columns: 1fr;
  }
}

@media print {
  @page {
    size: A4 portrait;
    margin: 6mm;
  }

  html,
  body {
    width: 100%;
    background: #fff;
    color: #000;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .topbar,
  .input-panel,
  .tabs,
  .no-print {
    display: none;
  }

  .print-watermark {
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 0;
    display: block;
    width: 62%;
    max-width: 520px;
    opacity: 0.18;
    transform: translate(-50%, -50%);
    pointer-events: none;
  }

  .print-header {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    margin: 0 0 12px;
    padding: 0 0 10px;
    border-bottom: 2px solid #10201d;
  }

  .print-header p {
    color: #10201d;
    font-size: 16px;
    font-weight: 900;
  }

  .print-header h1 {
    margin-top: 2px;
    font-size: 22px;
  }

  .print-header strong {
    font-size: 16px;
  }

  .print-client-details {
    display: grid;
    grid-template-columns: 110px minmax(0, 1fr);
    gap: 5px 14px;
    margin-top: 8px;
    font-size: 12px;
  }

  .print-client-details dt {
    color: #10201d;
    font-weight: 800;
  }

  .print-client-details dd {
    text-align: left;
    font-weight: 700;
  }

  .custom-products {
    display: none;
  }

  .app-shell,
  .output-panel {
    position: relative;
    z-index: 1;
    display: block;
    width: 100%;
    margin: 0;
    padding: 0;
    background: transparent;
    box-shadow: none;
    border: 0;
  }

  .view {
    display: block;
    padding-top: 0;
    break-inside: auto;
    page-break-inside: auto;
  }

  #view-proposal,
  #view-summary {
    min-height: 240mm;
  }

  #view-products,
  #view-bill {
    min-height: 270mm;
  }

  .view + .view {
    page-break-before: always;
    break-before: page;
  }

  #view-layout {
    page-break-before: auto;
    break-before: auto;
    margin-top: 8mm;
  }

  .hero-metrics,
  .proposal-metrics,
  .payment-grid,
  .fit-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
  }

  .hero-metrics div,
  .proposal-metrics div,
  .payment-grid div,
  .fit-grid div,
  .proposal-cover,
  .proposal-card,
  .proposal-next,
  .summary-box,
  .layout-card,
  .bill-source,
  .table-wrap {
    background: rgba(255, 255, 255, 0.9);
    border-color: #cfd8d4;
    box-shadow: none;
  }

  .hero-metrics div,
  .proposal-metrics div,
  .payment-grid div,
  .fit-grid div {
    min-height: 78px;
    padding: 12px;
  }

  .hero-metrics span,
  .proposal-metrics span,
  .payment-grid span,
  .fit-grid span,
  .signature-row span,
  label,
  dt,
  .bill-source p {
    font-size: 11px;
  }

  .hero-metrics strong,
  .proposal-metrics strong,
  .payment-grid strong,
  .fit-grid strong {
    margin-top: 6px;
    font-size: 18px;
  }

  .two-col {
    gap: 10px;
    margin-top: 12px;
  }

  .summary-box,
  .proposal-card,
  .proposal-cover,
  .proposal-next,
  .layout-card {
    padding: 14px;
  }

  #view-summary .summary-box {
    min-height: 104mm;
  }

  h3 {
    font-size: 17px;
  }

  dl {
    gap: 9px 12px;
    margin-top: 12px;
  }

  dd {
    font-size: 12px;
  }

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

  input,
  select,
  textarea {
    min-height: 38px;
    padding: 7px 9px;
    border-radius: 6px;
    font-size: 12px;
  }

  .bill-source {
    align-items: center;
    margin-bottom: 8px;
    padding: 9px 10px;
  }

  .bill-source h3 {
    font-size: 15px;
  }

  .bill-source a,
  .resource-row,
  .resource-links,
  .resource-summary {
    display: none;
  }

  .table-wrap {
    overflow: visible;
    border-radius: 0;
  }

  table {
    min-width: 0;
    width: 100%;
    font-size: 10.4px;
    table-layout: fixed;
  }

  th,
  td {
    padding: 5px 6px;
    line-height: 1.23;
  }

  th:first-child,
  td:first-child {
    width: 42%;
  }

  thead {
    display: table-header-group;
  }

  tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .bill-section-row td {
    padding-top: 7px;
    padding-bottom: 7px;
  }

  .acceptance {
    margin-top: 10px;
  }

  .acceptance p {
    margin-top: 8px;
    font-size: 12px;
  }

  .signature-row {
    gap: 14px;
    margin-top: 18px;
  }

  .signature-block {
    min-height: 118px;
  }

  .signature-line {
    height: 36px;
  }

  .date-line {
    height: 28px;
  }

  .signature-block strong {
    min-height: 20px;
    margin: 6px 0 9px;
    font-size: 13px;
  }

  .layout-card {
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
    gap: 10px;
  }

  .layout-card p:not(.eyebrow),
  .layout-grid {
    font-size: 12px;
  }

  .layout-grid {
    gap: 6px;
  }

  #view-payment .payment-grid div {
    min-height: 74px;
  }

  #view-payment .summary-box,
  #view-layout .layout-card {
    padding: 14px;
  }
}
