:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --line: #d8dee8;
  --text: #172033;
  --muted: #657086;
  --blue: #1264d8;
  --blue-dark: #0a4ca6;
  --danger: #b42318;
  --ok: #157347;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, "Microsoft YaHei", sans-serif;
}

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

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  min-height: 36px;
  padding: 7px 12px;
}

button.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

button.primary:hover {
  background: var(--blue-dark);
}

.button-link {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 7px 12px;
  text-decoration: none;
}

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

button.icon {
  width: 36px;
  padding: 0;
}

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

input[readonly] {
  background: #f3f6fa;
  color: var(--muted);
  cursor: not-allowed;
}

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

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

.form-section-title {
  margin: 8px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  color: var(--text);
  font-size: 15px;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 220px;
}

.brand img {
  width: 116px;
  height: 42px;
  object-fit: contain;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.nav button.active {
  border-color: var(--blue);
  color: var(--blue);
  background: #eef5ff;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(420px, 0.95fr) minmax(520px, 1.05fr);
  gap: 18px;
  padding: 18px;
}

.page-shell {
  max-width: 1280px;
  margin: 0 auto;
  padding: 18px;
}

.local-version {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

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

.page-header h2,
.page-header p {
  margin: 0;
}

.page-header p {
  margin-top: 4px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
}

.panel + .panel {
  margin-top: 14px;
}

.panel h2,
.panel h3 {
  margin: 0 0 14px;
}

.panel h2 {
  font-size: 18px;
}

.panel h3 {
  font-size: 15px;
}

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

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

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

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

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

.empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

.notice {
  border: 1px solid #f4d58d;
  border-radius: 8px;
  background: #fff8e6;
  color: #765100;
  margin-bottom: 12px;
  padding: 10px 12px;
}

.danger-notice {
  border-color: #f0b4ad;
  background: #fff1f0;
  color: var(--danger);
}

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

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

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

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

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  white-space: nowrap;
}

.quote-row {
  display: grid;
  grid-template-columns: 1fr 112px 96px 36px;
  gap: 8px;
  align-items: end;
  margin-bottom: 8px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 28px;
  background: rgba(15, 23, 42, 0.48);
}

.modal-card {
  width: min(760px, 100%);
  max-height: calc(100vh - 56px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 22px 60px rgba(15, 23, 42, 0.28);
}

.quote-modal {
  width: min(980px, 100%);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  max-height: calc(100vh - 72px);
}

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

.modal-header h2,
.modal-header p {
  margin: 0;
}

.modal-actions {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  border-bottom: 0;
  background: #fff;
}

.modal-body {
  max-height: calc(100vh - 170px);
  overflow: auto;
  padding: 16px;
}

.quote-modal .modal-body {
  max-height: none;
  min-height: 0;
}

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

.detail-item {
  display: grid;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.detail-item strong {
  color: var(--muted);
  font-size: 13px;
}

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

.quote-sheet {
  width: 794px;
  min-height: 1123px;
  margin: 0 auto;
  background: #fff;
  color: #000;
  padding: 54px 70px 38px;
  box-shadow: 0 12px 34px rgba(18, 31, 56, 0.13);
  font-family: Arial, Helvetica, sans-serif;
}

.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.sheet-logo {
  width: 255px;
  height: auto;
  object-fit: contain;
  display: block;
  margin: 0;
}

.company-block {
  width: 320px;
  padding-top: 50px;
  text-align: right;
  font-size: 12px;
  line-height: 1.2;
}

.company-name {
  display: inline-block;
  font-size: 18px;
  font-weight: 400;
  line-height: 1.2;
}

.address-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 70px;
  margin-top: 34px;
  font-size: 17px;
  line-height: 1.35;
}

.address-row h3 {
  margin: 0 0 5px;
  font-size: 17px;
}

.quote-title {
  margin-top: 36px;
  text-align: right;
  font-size: 30px;
  font-weight: 700;
}

.invoice-title {
  margin-top: 18px;
  text-align: right;
  font-size: 30px;
  font-weight: 700;
}

.invoice-address-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 70px;
  margin-top: 34px;
  font-size: 16px;
  line-height: 1.35;
}

.invoice-bill-to {
  font-size: 16px;
}

.invoice-bill-to strong,
.invoice-delivery strong {
  font-weight: 700;
}

.invoice-meta-row {
  margin: 28px 0 18px;
}

.meta-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 80px;
  margin: 38px 0 42px;
  font-size: 15px;
}

.meta-line {
  display: grid;
  grid-template-columns: 126px 12px 1fr;
  gap: 4px;
  margin-bottom: 7px;
}

.meta-line strong {
  font-weight: 700;
}

.sheet-table th,
.sheet-table td {
  border-bottom: none;
  padding: 3px 6px;
  color: #000;
  font-size: 14px;
}

.sheet-table thead th {
  border-bottom: 1px solid #000;
  font-size: 15px;
}

.sheet-table .num {
  text-align: right;
  white-space: nowrap;
}

.item-desc {
  white-space: pre-line;
}

.totals {
  margin-top: 12px;
  display: grid;
  justify-content: end;
  gap: 4px;
  font-size: 15px;
}

.total-line {
  display: grid;
  grid-template-columns: 150px 110px;
  gap: 18px;
}

.total-line.grand {
  border-top: 1px solid #000;
  padding-top: 6px;
  font-weight: 700;
}

.invoice-total-row {
  display: grid;
  grid-template-columns: 145px 1fr 70px 140px 108px;
  gap: 6px;
  margin-top: 14px;
  padding: 3px 6px;
  color: #000;
  font-size: 14px;
}

.invoice-total-row .num {
  text-align: right;
}

.invoice-vat-summary {
  width: 300px;
  margin: 34px 0 0 auto;
  color: #000;
  font-size: 14px;
}

.invoice-vat-summary div {
  display: grid;
  grid-template-columns: 1fr 24px 92px;
  gap: 8px;
  align-items: center;
  padding: 4px 0;
}

.invoice-vat-summary div + div {
  border-top: 1px solid #000;
}

.invoice-vat-summary .grand {
  margin-top: 8px;
  font-weight: 700;
}

.invoice-vat-summary span:nth-child(2),
.invoice-vat-summary span:nth-child(3) {
  text-align: right;
}

.invoice-statement {
  margin-top: 42px;
  color: #000;
  font-size: 14px;
  line-height: 1.35;
}

.invoice-statement p {
  margin: 0 0 12px;
}

.bank {
  margin-top: 90px;
  border-top: 1px solid #000;
  padding-top: 12px;
  font-size: 14px;
  line-height: 1.45;
}

.status-pill {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 8px;
  background: #eef5ff;
  color: var(--blue);
  font-size: 12px;
}

.paid {
  color: var(--ok);
  font-weight: 700;
}

.void {
  color: var(--danger);
  font-weight: 700;
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .page-header {
    align-items: stretch;
    flex-direction: column;
  }

  .quote-sheet {
    transform: scale(0.86);
    transform-origin: top center;
    margin-bottom: -150px;
  }
}

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

@media print {
  html,
  body {
    background: #fff;
    margin: 0;
  }

  .topbar,
  .page-shell,
  .modal-header,
  .modal-actions {
    display: none !important;
  }

  .modal-backdrop {
    position: static;
    display: block;
    padding: 0;
    background: #fff;
  }

  .modal-card {
    width: auto;
    max-height: none;
    overflow: visible;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .modal-body {
    max-height: none;
    overflow: visible;
    padding: 0;
  }

  .panel {
    border: 0;
    padding: 0;
  }

  .quote-sheet {
    width: 210mm;
    min-height: 297mm;
    margin: 0;
    box-shadow: none;
    transform: none;
    padding: 16mm 18mm 12mm;
  }
}
