:root {
  color-scheme: light;
  --ink: #17212b;
  --muted: #66717f;
  --line: #d9e0e7;
  --panel: #ffffff;
  --page: #f4f7f9;
  --accent: #116b61;
  --accent-dark: #0a4d46;
  --warn: #b45309;
  --danger: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
}

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

button,
.file-button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 6px;
  cursor: pointer;
}

button:hover,
.file-button:hover {
  background: var(--accent-dark);
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 9px;
  background: white;
  color: var(--ink);
}

input[type="number"] {
  appearance: textfield;
  -moz-appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

textarea {
  min-height: 72px;
  resize: vertical;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  padding: 20px 28px 16px;
  background: white;
  border-bottom: 1px solid var(--line);
}

.topbar h1 {
  margin: 2px 0 0;
  font-size: 24px;
  line-height: 1.2;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0;
}

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

.file-button {
  display: inline-flex;
  align-items: center;
}

.file-button input {
  display: none;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 10px 28px 0;
  background: white;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.tab {
  background: transparent;
  color: var(--muted);
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  min-width: 86px;
}

.tab:hover,
.tab.active {
  background: transparent;
  color: var(--accent-dark);
  border-bottom-color: var(--accent);
}

main {
  padding: 22px 28px 32px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metrics article,
.panel,
.quote-preview {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metrics article {
  padding: 16px;
}

.metrics span {
  display: block;
  color: var(--muted);
  margin-bottom: 6px;
}

.metrics strong {
  font-size: 28px;
}

.split,
.quote-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.75fr);
  gap: 16px;
}

.quote-layout {
  grid-template-columns: minmax(560px, 1.1fr) minmax(420px, 0.9fr);
}

#inventory .split {
  grid-template-columns: minmax(0, 1.25fr) minmax(300px, 0.85fr);
  align-items: start;
}

.panel {
  padding: 16px;
  min-width: 0;
}

.section-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.section-title h2 {
  margin: 0;
  font-size: 18px;
}

.section-title input {
  max-width: 280px;
}

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

label {
  color: var(--muted);
  display: grid;
  gap: 5px;
}

.line-actions,
.inline-form,
.customer-form,
.settings-form,
.inventory-new-form {
  display: grid;
  gap: 10px;
  margin: 14px 0;
}

.hidden {
  display: none !important;
}

.form-title {
  margin: 14px 0 8px;
  font-size: 14px;
  color: var(--muted);
}

.line-actions {
  grid-template-columns: repeat(3, max-content);
}

.inline-form {
  grid-template-columns: 1.1fr 1.5fr 130px max-content;
}

#movementForm {
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  align-items: start;
}

.inventory-new-form {
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  align-items: start;
}

#inventory .inventory-new-form button,
#inventory #movementForm button[type="submit"] {
  min-width: 130px;
}

#inventory #movementForm .selected-pn {
  grid-column: 1 / -1;
}

.customer-form {
  grid-template-columns: minmax(220px, 2fr) minmax(90px, 0.7fr) minmax(150px, 1.35fr) minmax(110px, 1.35fr) max-content max-content;
}

.customer-form textarea {
  grid-column: span 2;
  min-height: 72px;
}

.customer-form textarea[name="ship"] {
  grid-column: 1 / span 2;
}

.customer-form textarea[name="bill"] {
  grid-column: 3 / span 2;
}

.customer-form button {
  align-self: start;
}

.settings-panel {
  max-width: 760px;
}

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

.settings-form button {
  align-self: end;
  max-width: 160px;
}

.formula-box {
  margin-top: 8px;
}

.formula-lock {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) max-content;
  gap: 10px;
  max-width: 520px;
}

.formula-panel {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  background: #f8fbfb;
}

.formula-panel p {
  margin: 0 0 8px;
}

.formula-panel pre {
  margin: 0;
  white-space: pre-wrap;
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.45;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.table-wrap.tall {
  max-height: 58vh;
}

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

th,
td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  background: #edf3f3;
  color: #26343f;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
  position: sticky;
  top: 0;
  z-index: 1;
}

tr.low td {
  background: #fff7ed;
}

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

.selected-pn {
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #eef6f5;
  padding: 4px 10px;
  color: var(--muted);
}

.selected-pn strong {
  color: var(--ink);
  margin-left: 6px;
}

.selected-pn button {
  margin-left: auto;
  min-height: 28px;
  padding: 0 10px;
}

tr.selected-row td {
  background: #dff3ef;
  font-weight: 700;
}

.amount {
  text-align: right;
  white-space: nowrap;
}

.quote-preview {
  padding: 18px;
  align-self: start;
  min-height: 760px;
  overflow: auto;
}

.quote-doc {
  width: 980px;
  max-width: 100%;
  margin: 0 auto;
  color: #000;
  font-family: Arial, Helvetica, sans-serif;
}

.quote-sheet {
  table-layout: fixed;
  border-collapse: collapse;
  min-width: 940px;
  width: 100%;
  background: white;
  font-size: 11px;
}

.quote-sheet col,
.quote-sheet td,
.quote-sheet th {
  border: 1px solid #000;
}

.quote-sheet td,
.quote-sheet th {
  padding: 3px 5px;
  vertical-align: middle;
  white-space: pre-line;
  color: #000;
  background: white;
  text-transform: none;
  letter-spacing: 0;
  position: static;
}

.quote-sheet th {
  font-weight: 700;
  text-align: center;
}

.quote-sheet .template-value {
  background: #fffdf2;
}

.quote-title td {
  position: relative;
  height: 55px;
  text-align: right;
  font-size: 22px;
  font-weight: 700;
}

.quote-title span {
  display: block;
  line-height: 55px;
  padding-right: 18px;
}

.address-row td,
.address-row th,
.meta-labels th,
.meta-labels td,
.meta-values td,
.meta-values th {
  height: 50px;
}

.company-cell {
  position: relative;
}

.company-logo {
  display: block;
  width: 190px;
  max-width: 55%;
  height: auto;
  margin-bottom: 4px;
}

.title-logo {
  position: absolute;
  left: 6px;
  top: 50%;
  width: 190px;
  max-width: 36%;
  transform: translateY(-50%);
  margin: 0;
}

.company-cell span {
  display: block;
  line-height: 1.2;
}

.items-head th {
  height: 38px;
}

.quote-sheet .amount {
  text-align: center;
  white-space: nowrap;
}

.quote-sheet .quote-center {
  text-align: center;
  vertical-align: middle;
}

.bank-cell {
  height: 140px;
  vertical-align: top;
  font-size: 8.6px;
  line-height: 1.18;
}

.summary-row th,
.summary-row td {
  min-height: 35px;
}

.summary-total th,
.summary-total td {
  height: 26px;
  font-weight: 700;
}

.sales-title td,
.terms-title td {
  height: 18px;
  font-weight: 700;
}

.terms-cell {
  height: 204px;
  vertical-align: top;
  font-size: 8.4px;
  line-height: 1.16;
}

.acceptance {
  height: 34px;
  font-weight: 700;
}

.acceptance span {
  float: right;
  margin-right: 190px;
}

.print-name {
  height: 46px;
  font-weight: 700;
}

@media (max-width: 980px) {
  .topbar,
  .split,
  .quote-layout {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }

  .inline-form,
  #movementForm,
  .inventory-new-form,
  .customer-form,
  .settings-form,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .customer-form textarea {
    grid-column: auto;
  }

  main,
  .topbar,
  .tabs {
    padding-left: 14px;
    padding-right: 14px;
  }
}

@media print {
  @page {
    size: letter portrait;
    margin: 0.22in;
  }

  body {
    background: white;
  }

  .topbar,
  .tabs,
  .panel,
  .metrics,
  .view:not(#quote),
  .line-actions {
    display: none !important;
  }

  main {
    padding: 0;
  }

  #quote,
  #quote.view {
    display: block;
  }

  .quote-layout {
    display: block;
  }

  .quote-preview {
    border: 0;
    padding: 0;
    min-height: 0;
    overflow: visible;
  }

  .quote-doc {
    width: 7.95in;
    max-width: 7.95in;
  }

  .quote-sheet {
    min-width: 0;
    width: 100%;
    font-size: 8px;
    page-break-inside: avoid;
  }

  .quote-sheet td,
  .quote-sheet th {
    padding: 2px 3px;
  }

  .quote-title td {
    height: 0.43in;
    font-size: 18px;
  }

  .quote-title span {
    line-height: 0.43in;
  }

  .title-logo {
    width: 1.45in;
  }

  .address-row td,
  .address-row th,
  .meta-labels th,
  .meta-labels td,
  .meta-values td,
  .meta-values th {
    height: 0.35in;
  }

  .items-head th {
    height: 0.28in;
  }

  .bank-cell {
    height: 1.18in;
    font-size: 6.8px;
    line-height: 1.08;
  }

  .terms-cell {
    height: 1.78in;
    font-size: 6.6px;
    line-height: 1.08;
  }

  .quote-sheet .template-value {
    background: white;
  }
}
