:root {
  --bg: #eef2ef;
  --surface: #ffffff;
  --surface-soft: #f6f8f5;
  --ink: #17231d;
  --muted: #69746c;
  --line: #d9e0da;
  --brand: #4f8f2f;
  --brand-dark: #2f6820;
  --accent: #0d6f83;
  --warn: #b36a00;
  --radius: 8px;
  --shadow: 0 18px 45px rgba(31, 45, 35, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

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

button {
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  min-height: 38px;
  padding: 0 14px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

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

.secondary {
  background: #e6ece5;
  color: var(--ink);
  border: 1px solid var(--line);
}

.danger {
  background: #f7e4df;
  color: #9b2d18;
}

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

.sidebar {
  background: #16241c;
  color: #f7fbf6;
  display: flex;
  flex-direction: column;
  padding: 22px;
  gap: 24px;
}

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

.brand-block img {
  width: 66px;
  height: 48px;
  object-fit: contain;
  background: #fff;
  border-radius: 7px;
  padding: 5px;
}

.brand-block strong,
.brand-block span {
  display: block;
}

.brand-block span {
  color: #bdd3c2;
  margin-top: 3px;
}

.nav-tabs {
  display: grid;
  gap: 8px;
}

.nav-tabs button {
  background: transparent;
  color: #d9e8dc;
  text-align: left;
  border: 1px solid transparent;
}

.nav-tabs button.active,
.nav-tabs button:hover {
  background: #22372a;
  border-color: #3a5b42;
  color: #fff;
}

.sidebar-note {
  margin-top: auto;
  border-top: 1px solid #304836;
  padding-top: 18px;
}

.sidebar-note strong,
.sidebar-note span {
  display: block;
}

.sidebar-note span {
  color: #c6d5c9;
  font-size: 13px;
  line-height: 1.45;
  margin-top: 6px;
}

.workspace {
  padding: 28px;
  overflow: auto;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.page-header {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.page-header h1 {
  font-size: 30px;
  line-height: 1.1;
  margin: 0;
}

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

.header-actions,
.backup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(330px, 0.85fr);
  gap: 16px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  padding: 18px;
}

.panel h2 {
  font-size: 17px;
  margin: 0 0 14px;
}

.panel-help {
  color: var(--muted);
  line-height: 1.45;
  margin: -4px 0 12px;
}

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

.client-form,
.product-form {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 12px;
}

label {
  color: var(--muted);
  display: grid;
  gap: 5px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

label small {
  color: #7a867e;
  font-size: 11px;
  font-weight: 400;
  line-height: 1.3;
  text-transform: none;
}

input,
select,
textarea {
  background: #fff;
  border: 1px solid #cad5cd;
  border-radius: 6px;
  color: var(--ink);
  min-height: 38px;
  padding: 8px 10px;
  width: 100%;
}

textarea {
  line-height: 1.4;
  resize: vertical;
}

.wide-label {
  margin-top: 12px;
}

.add-item-row,
.manual-box {
  display: grid;
  gap: 8px;
}

.add-item-row {
  grid-template-columns: minmax(0, 1fr) 82px 100px;
  margin-bottom: 12px;
}

.manual-box {
  grid-template-columns: minmax(0, 1fr) minmax(112px, 1fr) 92px;
}

#manualDescription {
  grid-column: 1 / -1;
}

.product-search,
.client-search {
  position: relative;
}

.search-results {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px;
  box-shadow: var(--shadow);
  left: 0;
  right: 0;
  margin-top: 4px;
  max-height: 260px;
  overflow-y: auto;
  position: absolute;
  top: 100%;
  z-index: 20;
}

.search-results button {
  background: transparent;
  border: 0;
  border-radius: 0;
  display: block;
  min-height: auto;
  padding: 9px 12px;
  text-align: left;
  width: 100%;
}

.search-results button:hover,
.search-results button.active {
  background: var(--surface-soft);
}

.locked-note {
  background: #fdf3e3;
  border: 1px solid var(--warn);
  border-radius: 7px;
  color: #7a4c00;
  margin-bottom: 16px;
  padding: 10px 14px;
}

.invoice-badge {
  background: #eaf3e6;
  border: 1px solid var(--brand);
  border-radius: 999px;
  color: var(--brand-dark);
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  margin: 2px 4px 2px 0;
  padding: 6px 10px;
  white-space: nowrap;
}

.invoice-badge-void {
  background: #f7e4df;
  border-color: #9b2d18;
  color: #9b2d18;
}

.invoice-box {
  align-items: center;
  background: #f8faf8;
  border: 2px solid var(--brand);
  border-radius: 7px;
  display: grid;
  gap: 14px;
  grid-template-columns: 1fr auto;
  margin-top: 18px;
  padding: 14px;
}

.invoice-box .invoice-data p {
  margin: 2px 0;
}

.invoice-box .invoice-data strong {
  color: var(--brand-dark);
}

.invoice-box img {
  height: 110px;
  width: 110px;
}

.manual-entry {
  border-top: 1px solid var(--line);
  margin-top: 18px;
  padding-top: 18px;
}

.manual-entry h3 {
  color: var(--brand-dark);
  font-size: 13px;
  margin: 0 0 10px;
  text-transform: uppercase;
}

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

#quoteCodeBadge {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--brand-dark);
  font-weight: 700;
  padding: 7px 12px;
}

.table-wrap {
  overflow-x: auto;
}

.data-table {
  border-collapse: collapse;
  width: 100%;
}

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

.data-table th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.data-table td input,
.data-table td select {
  min-height: 32px;
  padding: 5px 7px;
}

.row-actions {
  display: flex;
  gap: 6px;
}

.row-actions button {
  min-height: 30px;
  padding: 0 9px;
}

.search {
  max-width: 360px;
}

.terms-list {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.term-item {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 7px;
  display: grid;
  gap: 8px;
  padding: 12px;
}

.file-button {
  align-items: center;
  background: #e6ece5;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  font-size: 15px;
  font-weight: 400;
  min-height: 38px;
  padding: 0 14px;
  text-transform: none;
}

.file-button input {
  display: none;
}

.data-file-status {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--muted);
  margin-top: 12px;
  padding: 10px 12px;
}

.quote-paper {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin: 12px auto 0;
  max-width: 960px;
  min-height: 700px;
  padding: 34px;
}

.quote-top {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  border-bottom: 3px solid var(--brand);
  padding-bottom: 16px;
}

.company-card,
.client-card {
  border: 1px solid #dce4dd;
  border-radius: 7px;
  padding: 14px;
}

.company-card {
  display: grid;
  grid-template-columns: 172px 1fr;
  gap: 14px;
  align-items: center;
}

.company-card img {
  display: block;
  justify-self: center;
  max-height: 117px;
  max-width: 164px;
  object-fit: contain;
}

.quote-paper h2,
.quote-paper h3,
.quote-paper p {
  margin: 0;
}

.quote-paper h2 {
  color: var(--brand-dark);
  font-size: 20px;
  margin-bottom: 7px;
}

.quote-paper h3 {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.quote-meta {
  align-items: end;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  margin: 18px 0;
}

.quote-title {
  grid-column: span 2;
}

.quote-title strong {
  display: block;
  font-size: 24px;
}

.meta-box {
  background: #f8faf8;
  border: 1px solid #dce4dd;
  border-radius: 7px;
  padding: 10px;
}

.meta-box span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-bottom: 3px;
}

.quote-lines {
  border-collapse: collapse;
  margin-top: 12px;
  width: 100%;
}

.quote-lines th,
.quote-lines td {
  border-bottom: 1px solid #dde6df;
  padding: 8px;
  text-align: left;
}

.quote-lines th {
  background: #edf4ec;
  color: #1d3525;
  font-size: 12px;
  text-transform: uppercase;
}

.quote-lines .num {
  text-align: right;
}

.quote-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 20px;
  margin-top: 18px;
}

.payment-box {
  background: #f8faf8;
  border: 1px solid #dce4dd;
  border-radius: 7px;
  line-height: 1.45;
  padding: 12px;
}

.offer-notes {
  background: #f8faf8;
  border: 1px solid #dce4dd;
  border-radius: 7px;
  line-height: 1.45;
  margin-top: 14px;
  padding: 12px;
}

.totals-box {
  border: 1px solid #dce4dd;
  border-radius: 7px;
  overflow: hidden;
}

.total-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 12px;
}

.total-row + .total-row {
  border-top: 1px solid #dce4dd;
}

.total-row.final {
  background: #1f3528;
  color: #fff;
  font-size: 18px;
  font-weight: 700;
}

.quote-footer {
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 28px;
  padding-top: 14px;
  border-top: 1px solid #dce4dd;
  font-size: 12px;
}

.invoice-paper {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: #111;
  font-size: 13px;
  margin: 12px auto 0;
  max-width: 960px;
  min-height: 700px;
  padding: 22px 26px;
}

.invoice-paper p {
  margin: 0 0 2px;
}

.invoice-head {
  align-items: start;
  border-bottom: 2px solid #222;
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr 110px 1fr;
  padding-bottom: 14px;
}

.invoice-emisor img {
  display: block;
  height: auto;
  margin-bottom: 8px;
  max-width: 340px;
  width: 100%;
}

.invoice-code-box {
  border: 2px solid #222;
  border-radius: 4px;
  padding: 6px 4px 8px;
  text-align: center;
}

.invoice-code-box strong {
  display: block;
  font-size: 40px;
  line-height: 1;
}

.invoice-code-box span {
  display: block;
  font-size: 11px;
  margin-top: 4px;
}

.invoice-doc {
  text-align: right;
}

.invoice-doc h1 {
  font-size: 22px;
  letter-spacing: 1px;
  margin: 0 0 2px;
}

.invoice-doc .invoice-original {
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.invoice-doc .invoice-number {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 6px;
}

.invoice-client-band {
  background: #eee;
  display: grid;
  gap: 6px 24px;
  grid-template-columns: 1fr 1fr;
  margin: 14px 0;
  padding: 12px 14px;
}

.invoice-lines {
  border-collapse: collapse;
  width: 100%;
}

.invoice-lines th,
.invoice-lines td {
  border-bottom: 1px solid #ddd;
  padding: 7px 6px;
  text-align: left;
}

.invoice-lines thead th {
  background: #555;
  color: #fff;
  font-size: 11px;
  text-transform: uppercase;
}

.invoice-lines .num {
  text-align: right;
}

.invoice-summary {
  align-items: end;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin-top: 16px;
}

.invoice-amount-words {
  font-size: 12px;
  max-width: 60%;
}

.invoice-totals {
  min-width: 260px;
  text-align: right;
}

.invoice-totals .total-line {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 2px 0;
}

.invoice-totals .total-final {
  border-top: 2px solid #222;
  font-size: 18px;
  font-weight: 700;
  margin-top: 6px;
  padding-top: 6px;
}

.invoice-cae-footer {
  align-items: center;
  border-top: 1px solid #ccc;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin-top: 24px;
  padding-top: 12px;
}

.invoice-cae-footer img {
  height: 90px;
  width: 90px;
}

.invoice-cae-footer .invoice-cae-text {
  font-size: 11px;
}

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

  .sidebar {
    position: static;
  }

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

  .nav-tabs button {
    text-align: center;
  }

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

  .quote-top,
  .quote-summary {
    grid-template-columns: 1fr;
  }
}

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

  .sidebar,
  .page-header,
  .editor-grid,
  #itemsTable,
  #view-quotes,
  #view-clients,
  #view-products,
  #view-settings,
  #view-quote > .panel,
  .locked-note {
    display: none !important;
  }

  .app-shell,
  .workspace,
  .view.active {
    display: block;
    margin: 0;
    padding: 0;
  }

  .quote-paper {
    border: 0;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    margin: 0;
    max-width: none;
    padding: 0 0 20mm;
    width: 100%;
    font-size: 13.5px;
  }

  .invoice-paper {
    border: 0;
    box-shadow: none;
    margin: 0;
    max-width: none;
    padding: 0 0 30mm;
    width: 100%;
  }

  .invoice-cae-footer {
    background: #fff;
    bottom: 0;
    left: 0;
    padding: 12px 26px;
    position: fixed;
    right: 0;
  }

  .quote-top {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 12mm;
    padding-bottom: 12px;
  }

  .company-card,
  .client-card {
    break-inside: avoid;
    min-height: 108px;
    padding: 12px;
  }

  .company-card {
    grid-template-columns: 152px minmax(0, 1fr);
    gap: 12px;
  }

  .company-card img {
    max-height: 110px;
    max-width: 147px;
  }

  .quote-paper h2 {
    font-size: 18px;
    margin-bottom: 5px;
  }

  .quote-paper h3 {
    font-size: 10px;
    margin-bottom: 5px;
  }

  .quote-meta {
    grid-template-columns: 1.5fr 1fr 1fr 1fr;
    gap: 9px;
    margin: 18px 0;
  }

  .quote-title {
    grid-column: span 1;
  }

  .quote-title strong {
    font-size: 23px;
  }

  .meta-box {
    padding: 9px;
  }

  .quote-lines th,
  .quote-lines td {
    padding: 7px 6px;
  }

  .quote-summary {
    break-inside: avoid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 14px;
    margin-top: 18px;
  }

  .payment-box {
    padding: 12px;
  }

  .total-row {
    padding: 8px 11px;
  }

  .total-row.final {
    font-size: 16px;
  }

  .quote-footer {
    background: #fff;
    bottom: 0;
    left: 0;
    margin-top: 0;
    padding-top: 10px;
    position: fixed;
    right: 0;
  }

  @page {
    size: A3 portrait;
    margin: 12mm;
  }
}
