:root {
  --surface: #ffffff;
  --surface-muted: #f7f7f8;
  --ink: #101114;
  --ink-muted: #5f6368;
  --line: #d9dce3;
  --line-strong: #101114;
  --accent: #002fa7;
  --accent-soft: #e8efff;
  --danger: #e4002b;
  --font: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--surface-muted);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

.is-hidden {
  display: none !important;
}

.inline-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 24px;
  padding: 24px 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--line-strong);
}

.top-actions {
  display: flex;
  align-items: end;
  gap: 10px;
}

.user-summary {
  min-width: 150px;
  padding: 6px 0;
  text-align: right;
}

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

.user-summary span {
  color: var(--ink-muted);
  font-size: 12px;
}

.login-screen {
  min-height: 100vh;
  place-items: center;
  padding: 32px;
}

.login-card {
  width: min(520px, 100%);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  padding: 28px;
}

.login-card h1 {
  margin-bottom: 24px;
}

.login-tabs {
  margin-bottom: 18px;
}

.login-form {
  display: grid;
  gap: 12px;
}

.auth-message {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid var(--accent);
  color: var(--accent);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

h1,
h2,
h3,
h4,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 36px;
  line-height: 1.05;
  font-weight: 700;
}

h2 {
  margin-bottom: 14px;
  font-size: 24px;
  line-height: 1.2;
}

h3 {
  margin-bottom: 10px;
  font-size: 16px;
  line-height: 1.25;
}

.role-switch,
.tool-nav,
.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  border: 1px solid var(--line-strong);
  background: var(--surface);
}

.role-switch button,
.tool-nav button,
.segmented button {
  min-height: 38px;
  padding: 0 14px;
  border: 0;
  border-right: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
}

.role-switch button:last-child,
.tool-nav button:last-child,
.segmented button:last-child {
  border-right: 0;
}

.role-switch button.active,
.tool-nav button.active,
.segmented button.active {
  background: var(--accent);
  color: var(--surface);
}

.tool-nav {
  margin: 24px 32px 0;
}

main {
  padding: 24px 32px 56px;
}

.container-tool-frame {
  display: block;
  width: 100%;
  min-height: calc(100vh - 190px);
  border: 1px solid var(--line-strong);
  background: var(--surface);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid.two {
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.75fr);
}

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

.panel {
  background: var(--surface);
  border: 1px solid var(--line-strong);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line-strong);
}

.panel-body {
  padding: 16px;
}

.home-tools {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.tool-entry {
  min-height: 180px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  text-align: left;
}

.tool-entry .number {
  display: block;
  margin-bottom: 28px;
  color: var(--accent);
  font-size: 48px;
  line-height: 1;
  font-weight: 700;
}

.tool-entry h2 {
  margin-bottom: 8px;
}

.tool-entry p {
  margin-bottom: 18px;
  color: var(--ink-muted);
  line-height: 1.6;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.primary,
.secondary,
.plain,
.danger {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
}

.primary {
  background: var(--accent);
  color: var(--surface);
}

.secondary {
  background: var(--accent-soft);
  color: var(--accent);
}

.danger {
  color: var(--danger);
}

.plain {
  border-color: var(--line);
}

.download-link,
.file-action {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.file-action {
  position: relative;
  overflow: hidden;
}

.file-action input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

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

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

.field label {
  color: var(--ink-muted);
  font-size: 12px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  background: var(--surface);
  color: var(--ink);
  padding: 7px 9px;
}

.field textarea {
  min-height: 74px;
  resize: vertical;
}

.section-stack {
  display: grid;
  gap: 16px;
}

.calculator-flow {
  display: grid;
  gap: 18px;
  width: min(1440px, 100%);
  margin: 0 auto;
}

.quote-flow {
  display: grid;
  gap: 18px;
  width: min(1500px, 100%);
  margin: 0 auto;
}

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

.material-choice-table.sales-material-table col:nth-child(1) { width: 22%; }
.material-choice-table.sales-material-table col:nth-child(2) { width: 58%; }
.material-choice-table.sales-material-table col:nth-child(3) { width: 20%; }
.material-choice-table.admin-material-table col:nth-child(1) { width: 14%; }
.material-choice-table.admin-material-table col:nth-child(2) { width: 22%; }
.material-choice-table.admin-material-table col:nth-child(3) { width: 12%; }
.material-choice-table.admin-material-table col:nth-child(4) { width: 10%; }
.material-choice-table.admin-material-table col:nth-child(5) { width: 10%; }
.material-choice-table.admin-material-table col:nth-child(6) { width: 32%; }

.material-choice-table td,
.material-choice-table th {
  vertical-align: middle;
}

.calculator-flow > .panel {
  scroll-margin-top: 16px;
}

.section-control {
  display: grid;
  grid-template-columns: 100px minmax(180px, 280px) 1fr;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding: 10px 12px;
  border-left: 4px solid var(--accent);
  background: var(--surface-muted);
}

.section-control label {
  font-weight: 700;
}

.section-control select {
  min-height: 34px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  padding: 4px 8px;
}

.section-control span {
  color: var(--ink-muted);
  font-size: 12px;
}

.dimension-warning {
  margin: 14px 0 0;
  padding: 10px 12px;
  border: 1px solid var(--danger);
  color: var(--danger);
  font-weight: 700;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  border: 1px solid var(--line);
  padding: 7px 8px;
  text-align: left;
  vertical-align: top;
  word-break: break-word;
}

th {
  background: var(--surface-muted);
  color: var(--ink);
  font-weight: 700;
}

td input,
td select {
  width: 100%;
  min-height: 30px;
  border: 1px solid var(--line);
  padding: 4px 6px;
}

.numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.formula-cell {
  color: var(--ink-muted);
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

tfoot th,
tfoot td {
  background: var(--surface-muted);
  border-top: 1px solid var(--line-strong);
  font-weight: 700;
}

.muted {
  color: var(--ink-muted);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
}

.retail-floor {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.quote-matrix-wrap {
  overflow-x: auto;
}

.quote-matrix {
  min-width: 860px;
}

.quote-matrix th:first-child {
  width: 190px;
}

.quote-matrix .current-size-row th,
.quote-matrix .current-size-row td {
  background: var(--accent-soft);
  border-color: var(--accent);
  font-weight: 700;
}

.matrix-note {
  margin: 10px 0 0;
  color: var(--ink-muted);
  font-size: 12px;
}

.summary-cell {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  padding: 12px;
}

.summary-cell span {
  display: block;
  color: var(--ink-muted);
  font-size: 12px;
}

.summary-cell strong {
  display: block;
  margin-top: 6px;
  color: var(--accent);
  font-size: 24px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.admin-only {
  display: none;
}

body.admin .admin-only {
  display: revert;
}

body.admin tr.admin-only {
  display: table-row;
}

.sales-note {
  padding: 10px 12px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  color: var(--accent);
}

.database-note {
  padding: 10px 12px;
  background: var(--accent-soft);
  border-left: 4px solid var(--accent);
  color: var(--accent);
}

body.admin .sales-note {
  display: none;
}

.catalog-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 16px;
}

.product-list {
  display: grid;
  gap: 10px;
  max-height: 650px;
  overflow: auto;
  padding-right: 4px;
}

.product-option {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 10px;
  align-items: start;
  padding: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  text-align: left;
}

.product-option.active {
  border-color: var(--accent);
  outline: 2px solid var(--accent-soft);
}

.product-option img,
.quote-image {
  display: block;
  width: 72px;
  height: 48px;
  object-fit: contain;
  border: 1px solid var(--line);
  background: var(--surface);
}

.product-option strong {
  display: block;
  margin-bottom: 4px;
}

.product-option span {
  display: block;
  color: var(--ink-muted);
  font-size: 12px;
  line-height: 1.45;
}

.quote-paper {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  padding: 20px;
  min-width: 1060px;
  min-height: 720px;
}

.print-panel .panel-body {
  overflow-x: auto;
}

.quote-title {
  text-align: center;
  border-bottom: 1px solid var(--line-strong);
  padding-bottom: 12px;
  margin-bottom: 12px;
}

.quote-title h2 {
  margin: 4px 0 0;
}

.quote-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line-strong);
  border-bottom: 0;
}

.quote-meta div {
  padding: 8px;
  border-bottom: 1px solid var(--line-strong);
}

.quote-meta div:nth-child(odd) {
  border-right: 1px solid var(--line-strong);
}

.quote-notice {
  margin-top: 10px;
  border: 1px solid var(--line-strong);
  padding: 10px;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-line;
}

.quote-controls .muted {
  line-height: 1.6;
  white-space: pre-line;
}

.quote-paper table {
  table-layout: auto;
}

.quote-paper th,
.quote-paper td {
  word-break: normal;
  overflow-wrap: anywhere;
  line-height: 1.45;
  padding: 8px;
}

.quote-cell-edit {
  width: 100%;
  min-width: 70px;
  min-height: 34px;
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 5px 6px;
  line-height: 1.45;
  field-sizing: content;
}

textarea.quote-cell-edit {
  min-height: 72px;
  resize: vertical;
  white-space: pre-wrap;
}

.quote-config-edit {
  min-width: 260px;
}

.compact-edit {
  min-width: 42px;
}

.payment-config {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.qr-preview,
.payment-qr-row img {
  width: 120px;
  height: 120px;
  object-fit: contain;
  border: 1px solid var(--line);
  margin-top: 8px;
}

.payment-paper {
  margin-top: 10px;
  border: 1px solid var(--line-strong);
  padding: 10px;
  line-height: 1.6;
}

.payment-account {
  white-space: pre-line;
}

.payment-qr-row {
  display: flex;
  gap: 24px;
  margin-top: 8px;
}

.payment-qr-row figure {
  margin: 0;
  text-align: center;
}

.payment-qr-row figcaption {
  margin-top: 4px;
  font-size: 12px;
}

.history-delete {
  margin-top: 8px;
}

.quote-paper.layout-compact {
  font-size: 12px;
}

.quote-paper.layout-compact th,
.quote-paper.layout-compact td {
  padding: 5px 6px;
}

.quote-paper.layout-dense {
  font-size: 10px;
}

.quote-paper.layout-dense th,
.quote-paper.layout-dense td {
  padding: 3px 4px;
}

.quote-paper.layout-dense textarea.quote-cell-edit {
  min-height: 46px;
}

.quote-paper.pdf-exporting .quote-cell-edit {
  border: 0;
  padding: 0;
  background: transparent;
}

.database-table {
  max-height: 680px;
  overflow: auto;
}

.database-flow {
  display: grid;
  gap: 18px;
  width: min(1600px, 100%);
  margin: 0 auto;
}

.cost-database-table {
  max-height: 68vh;
  border: 1px solid var(--line);
}

.cost-database-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
}

.save-status {
  color: var(--accent);
  font-size: 12px;
  white-space: nowrap;
}

.material-editor {
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line-strong);
}

.product-editor {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.product-config-field {
  grid-column: 1 / -1;
}

.compact-form {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.status-pill {
  display: inline-block;
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 2px 6px;
  font-size: 12px;
}

.print-only {
  display: none;
}

@media (max-width: 1080px) {
  .grid.two,
  .grid.three,
  .home-tools,
  .catalog-layout {
    grid-template-columns: 1fr;
  }

  .top-actions {
    align-items: start;
    flex-wrap: wrap;
  }

  .user-summary {
    min-width: 100%;
    text-align: left;
  }

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

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

  .section-control {
    grid-template-columns: 100px minmax(180px, 1fr);
  }

  .section-control span {
    grid-column: 2;
  }

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

  .tool-nav {
    display: grid;
    grid-auto-flow: row;
  }

  .spring-controls,
  .qr-upload-grid {
    grid-template-columns: 1fr;
  }
}

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

  .tool-nav {
    margin-left: 16px;
    margin-right: 16px;
  }

  .form-grid,
  .summary-grid,
  .compact-form {
    grid-template-columns: 1fr;
  }

  .section-control {
    grid-template-columns: 1fr;
  }

  .section-control span {
    grid-column: 1;
  }
}

@page {
  size: A4 landscape;
  margin: 10mm;
}

@media print {
  body {
    background: var(--surface);
  }

  .topbar,
  .tool-nav,
  #homeView,
  #calculatorView,
  #databaseView,
  .quote-controls,
  .no-print {
    display: none !important;
  }

  main {
    padding: 0;
  }

  .view {
    display: none !important;
  }

  #quoteView {
    display: block !important;
  }

  .grid.two,
  .catalog-layout {
    display: block;
  }

  .panel:not(.print-panel) {
    display: none;
  }

  .print-panel {
    border: 0;
  }

  .print-panel .panel-header {
    display: none;
  }

  .print-panel .panel-body {
    padding: 0;
  }

  .quote-paper {
    border: 0;
    padding: 0;
    min-height: 0;
  }

  th,
  td {
    padding: 5px 6px;
  }

  .quote-cell-edit {
    border: 0;
    padding: 0;
    background: transparent;
    resize: none;
  }
}
