:root {
  --page-bg: #eceff3;
  --panel: rgba(10, 20, 34, 0.92);
  --panel-border: rgba(255, 255, 255, 0.08);
  --paper: #ffffff;
  --ink: #1d2733;
  --muted: #798493;
  --soft: #f1f3f5;
  --line: #d8dde3;
  --navy: #1d3042;
  --orange: #004e7a;
  --shadow: 0 22px 52px rgba(22, 31, 45, 0.14);
}

* {
  box-sizing: border-box;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0.72)),
    linear-gradient(135deg, #eff2f5 0%, #e3e8ee 100%);
}

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

button {
  cursor: pointer;
  border: 0;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
}

.control-panel input,
.control-panel textarea,
.control-panel select {
  border-radius: 20px;
}

textarea {
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: #c4cdd7;
}

.app-shell {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  min-height: 100vh;
}

.control-panel {
  padding: 20px;
  background: var(--panel);
  color: #fff;
  border-right: 1px solid var(--panel-border);
  overflow-y: auto;
}

.panel-section {
  margin-bottom: 14px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
}

.brand-block {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 12px;
  align-items: center;
}

.brand-logo {
  width: 64px;
  height: 64px;
  object-fit: contain;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  padding: 6px;
}

.eyebrow {
  margin: 0 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 10px;
  color: #92a3b4;
}

.brand-block h1,
.workspace-bar h2,
.section-heading h2 {
  margin: 0;
}

.brand-block h1 {
  font-size: 24px;
}

.muted,
.helper-text {
  margin: 10px 0 0;
  color: #b4c0cb;
  font-size: 12px;
  line-height: 1.5;
}

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

.section-heading h2 {
  font-size: 15px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 5px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: #eef4f9;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.badge.accent {
  background: rgba(0, 78, 122, 0.18);
  color: #d4ecf8;
}

.inline-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.primary-btn,
.ghost-btn,
.secondary-btn {
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

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

.ghost-btn {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.secondary-btn {
  background: #eef2f6;
  color: var(--navy);
}

#addItemBtn {
  border-radius: 0;
}

.status-text {
  margin: 10px 0 0;
  font-size: 12px;
}

.workspace {
  padding: 24px;
}

.workspace-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.workspace-bar h2 {
  font-size: 28px;
}

.view-mode-badge {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.status-pill {
  margin: 0;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(34, 122, 89, 0.1);
  color: #227a59;
  font-size: 12px;
  font-weight: 700;
}

.public-state {
  display: none;
  margin: 0 0 18px;
  padding: 18px 20px;
  border: 1px solid rgba(0, 78, 122, 0.18);
  background: rgba(0, 78, 122, 0.08);
  color: #004e7a;
  font-size: 14px;
  line-height: 1.6;
}

.public-state.is-visible {
  display: block;
}

.public-state.is-error {
  border-color: rgba(168, 53, 53, 0.18);
  background: rgba(168, 53, 53, 0.08);
  color: #8d2b2b;
}

.public-actions {
  display: none;
  justify-content: flex-end;
  padding: 18px 0 0;
}

.paper {
  width: min(100%, 830px);
  min-height: 1120px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  box-shadow: var(--shadow);
  padding: 0 40px 0;
  overflow: hidden;
}

.paper-topline {
  height: 6px;
  margin: 0 -40px 28px;
  background: linear-gradient(90deg, var(--navy) 0 49%, var(--orange) 49% 68%, transparent 68% 100%);
}

.invoice-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 34px;
}

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

.invoice-logo {
  width: 75px;
  height: 75px;
  object-fit: contain;
}

.brand-title-stack {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 75px;
}

.brand-word {
  margin: 0 0 2px;
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.01em;
  color: #004e7a;
}

.brand-subtitle {
  margin: 0;
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.04em;
  color: #828282;
}

.invoice-title {
  margin: 0;
  font-size: 30px;
  font-weight: 500;
  letter-spacing: 0;
  color: #111827;
  text-align: right;
}

.invoice-meta {
  display: grid;
  grid-template-columns: 1.6fr 1.2fr 1.2fr 1.2fr;
  gap: 10px;
  margin-bottom: 18px;
}

.meta-card {
  min-height: 70px;
  padding: 10px 14px;
  background: linear-gradient(180deg, #f5f6f8 0%, #eaedf0 100%);
  border-left: 1px solid #d7dce1;
}

.meta-card:first-child {
  border-left: 0;
}

.meta-card span {
  display: block;
  margin-bottom: 7px;
  font-size: 11px;
  color: #666f79;
}

.meta-card input {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-size: 12px;
  font-weight: 400;
  color: #1a222d;
}

.meta-card.emphasis input {
  font-size: 18px;
  font-weight: 700;
  color: #0f1720;
}

.meta-card strong {
  font-size: 18px;
  font-weight: 700;
}

.customer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.customer-grid label {
  color: #7b858f;
}

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

.items-section {
  margin-bottom: 22px;
}

.table-head,
.item-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1.8fr) 72px 86px 98px;
  gap: 7px;
}

.table-head {
  margin-bottom: 8px;
}

.table-head span {
  padding: 10px 8px;
  font-size: 11px;
  line-height: 1;
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
  background: var(--navy);
}

.table-head span:nth-child(1),
.table-head span:nth-child(3),
.table-head span:nth-child(4) {
  background: var(--orange);
}

.items-container {
  display: grid;
  gap: 10px;
}

.item-row {
  align-items: start;
  padding: 10px 0;
  background: #f1f2f4;
}

.item-index {
  display: flex;
  justify-content: center;
  padding-top: 12px;
  font-size: 12px;
  color: #3a4450;
}

.item-description {
  display: grid;
  gap: 4px;
  padding: 8px 4px 8px 0;
}

.item-title {
  border: 0;
  background: transparent;
  padding: 0;
  border-radius: 0;
  font-size: 15px;
  color: #004e7a;
}

.item-detail {
  min-height: 34px;
  border: 0;
  background: transparent;
  padding: 0;
  border-radius: 0;
  font-size: 11px;
  line-height: 1.45;
  color: #636d78;
}

.item-qty,
.item-price {
  margin-top: 8px;
  border: 0;
  background: transparent;
  padding: 0;
  border-radius: 0;
  text-align: center;
  font-size: 13px;
}

.item-amount-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  padding: 8px 10px 8px 0;
}

.item-amount {
  font-size: 13px;
  font-weight: 400;
}

.delete-item-btn {
  padding: 0;
  background: transparent;
  font-size: 11px;
  color: var(--orange);
}

.note-and-summary {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 26px;
  align-items: start;
  margin-bottom: 24px;
}

.payment-block h4 {
  margin: 0 0 10px;
  font-size: 18px;
  font-weight: 400;
}

.payment-block label {
  color: #6d7680;
}

.payment-block textarea {
  border: 0;
  padding: 0;
  border-radius: 0;
  background: transparent;
  font-size: 11px;
  line-height: 1.6;
  color: #666f79;
}

.payment-bank {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  margin-top: 12px;
}

.payment-bank span {
  display: block;
  margin-bottom: 6px;
  font-size: 11px;
  color: #1d2733;
}

.payment-bank strong {
  font-size: 11px;
  font-weight: 400;
  line-height: 1.45;
  color: #666f79;
}

.summary-block {
  display: grid;
  gap: 8px;
  padding: 6px 0;
}

.summary-row {
  display: grid;
  grid-template-columns: 1fr 1.25fr;
  align-items: stretch;
}

.summary-row > span {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 14px;
  min-height: 40px;
  background: var(--orange);
  color: #fff;
  font-size: 12px;
}

.summary-input-group {
  display: grid;
  grid-template-columns: 76px 1fr;
  min-height: 40px;
  background: var(--navy);
  color: #fff;
}

.summary-row input,
.summary-input-group strong {
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #fff;
}

.summary-row input {
  padding: 0 10px;
  text-align: center;
  font-size: 12px;
}

.summary-row input#subTotal {
  text-align: right;
  padding-right: 14px;
}

.subtotal-group {
  grid-template-columns: 1fr;
}

.summary-input-group strong {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 14px;
  font-size: 13px;
  font-weight: 400;
}

.total-row .summary-input-group strong {
  font-size: 16px;
  font-weight: 700;
}

.paper-footer {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 20px;
  margin-top: auto;
  margin-bottom: 0;
}

.footer-copy {
  max-width: 300px;
}

.thanks {
  margin: 0 0 8px;
  font-size: 15px;
  font-weight: 700;
  text-transform: uppercase;
}

.small-text {
  margin: 0;
  font-size: 10px;
  line-height: 1.5;
  color: #666f79;
}

.signature-block {
  text-align: center;
  min-width: 220px;
}

.signature-block strong {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  color: #004e7a;
}

.contact-band {
  margin: auto -40px 0;
  padding: 16px 40px;
  background: var(--navy);
  color: #d7dde6;
}

.contact-line {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  font-size: 10px;
}

.contact-line + .contact-line {
  margin-top: 6px;
}

.manual-locked .workspace input,
.manual-locked .workspace textarea,
.manual-locked .workspace select,
.manual-locked .workspace #addItemBtn,
.manual-locked .workspace .delete-item-btn,
.manual-locked #saveCustomerBtn,
.manual-locked #generateLinkBtn,
.manual-locked #searchQuotesBtn,
.manual-locked #loadQuoteBtn {
  pointer-events: none;
  opacity: 0.75;
}

body.public-mode .app-shell {
  display: block;
}

body.public-mode .control-panel,
body.public-mode .workspace-bar {
  display: none;
}

body.public-mode .workspace {
  padding: 24px 0;
}

body.public-mode .public-state {
  width: min(100%, 830px);
  margin: 0 auto 18px;
}

body.public-mode .public-actions {
  display: flex;
}

body.public-mode .paper input,
body.public-mode .paper textarea,
body.public-mode .paper select,
body.public-mode .paper button {
  pointer-events: none;
}

body.public-mode .public-actions button {
  pointer-events: auto;
}

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

  .control-panel {
    position: sticky;
    top: 0;
    z-index: 10;
  }
}

@media (max-width: 860px) {
  .workspace {
    padding: 14px;
  }

  .paper {
    width: 100%;
    min-height: auto;
    padding: 0 18px;
  }

  .paper-topline,
  .contact-band {
    margin-left: -18px;
    margin-right: -18px;
  }

  .contact-band {
    padding-left: 18px;
    padding-right: 18px;
  }

  .invoice-header,
  .invoice-meta,
  .customer-grid,
  .note-and-summary,
  .paper-footer,
  .payment-bank,
  .contact-line,
  .workspace-bar {
    display: grid;
    grid-template-columns: 1fr;
  }

  .table-head,
  .item-row {
    grid-template-columns: 40px 1fr;
  }

  .table-head span:nth-child(n + 3),
  .item-row > :nth-child(n + 3) {
    grid-column: 2;
  }

  .summary-row {
    grid-template-columns: 1fr;
  }

  .summary-row > span {
    justify-content: flex-start;
  }

  .summary-input-group {
    grid-template-columns: 84px 1fr;
  }

  .inline-actions {
    flex-direction: column;
  }
}

@page {
  size: A4;
  margin: 0;
}

@media print {
  html,
  body {
    margin: 0;
    background: #fff;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .app-shell {
    display: block;
    min-height: auto;
  }

  .control-panel,
  .workspace-bar,
  .no-print {
    display: none !important;
  }

  .workspace {
    padding: 0;
  }

  .paper {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-height: 297mm;
    box-shadow: none;
    padding: 0 12mm;
    overflow: visible;
  }

  .invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 12mm;
    margin-bottom: 28px;
  }

  .invoice-meta {
    display: grid;
    grid-template-columns: 1.6fr 1.2fr 1.2fr 1.2fr;
    gap: 10px;
    margin-bottom: 18px;
  }

  .customer-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 16px;
  }

  .note-and-summary {
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 26px;
    align-items: start;
    margin-bottom: 24px;
  }

  .payment-bank {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
  }

  .paper-footer {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 20px;
    margin-top: 32px;
    margin-bottom: 0;
  }

  .paper-topline,
  .contact-band {
    margin-left: -12mm;
    margin-right: -12mm;
  }

  .contact-band {
    margin-top: auto;
    padding-left: 12mm;
    padding-right: 12mm;
  }

  input,
  textarea,
  select {
    border-color: transparent;
    appearance: none;
    -webkit-appearance: none;
    box-shadow: none;
    outline: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  textarea {
    white-space: pre-wrap;
    overflow: visible;
  }

  .invoice-header,
  .invoice-meta,
  .customer-grid,
  .note-and-summary,
  .paper-footer,
  .payment-bank,
  .contact-line {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  .table-head,
  .item-row {
    grid-template-columns: 44px minmax(0, 1.8fr) 72px 86px 98px;
  }

  .item-row {
    display: grid;
    align-items: start;
    padding: 10px 0;
  }

  .summary-row {
    display: grid;
    grid-template-columns: 1fr 1.25fr;
    align-items: stretch;
  }

  .summary-input-group {
    display: grid;
    grid-template-columns: 76px 1fr;
    min-height: 40px;
  }

  .subtotal-group {
    grid-template-columns: 1fr;
  }

  .table-head span,
  .summary-row > span,
  .summary-input-group strong,
  .contact-line span,
  .thanks,
  .brand-word,
  .brand-subtitle,
  .invoice-title {
    white-space: nowrap;
  }

  .meta-card input,
  .item-title,
  .item-qty,
  .item-price,
  .item-amount,
  .summary-row input {
    line-height: 1.2;
  }

  .item-detail,
  .payment-block textarea,
  .small-text {
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  .contact-line {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: center;
  }

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

  .table-head span:nth-child(n + 3),
  .item-row > :nth-child(n + 3) {
    grid-column: auto;
  }

  .summary-block {
    align-self: start;
  }

  .item-row,
  .meta-card,
  .summary-row {
    break-inside: avoid;
  }
}
