:root {
  --ink: #1f2933;
  --muted: #667085;
  --line: #d8dee8;
  --paper: #ffffff;
  --panel: #f7f9fc;
  --accent: #0f766e;
  --accent-dark: #0b5f59;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

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

.login-panel {
  display: grid;
  gap: 14px;
  width: min(380px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.12);
}

.login-panel h1 {
  margin: 0 0 4px;
  font-size: 24px;
  text-align: center;
}

.login-error {
  color: #b42318;
  font-size: 13px;
  text-align: center;
}

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

button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  cursor: pointer;
}

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

.app {
  display: grid;
  grid-template-columns: minmax(520px, 0.95fr) minmax(520px, 1.05fr);
  min-height: 100vh;
}

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

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

.topbar h1 {
  margin: 0;
  font-size: 24px;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
}

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

.actions button,
.section-title button,
.settings-toggle,
.preview-tabs button {
  min-height: 42px;
  border-radius: 6px;
  padding: 7px 12px;
  line-height: 1.15;
}

.settings-toggle {
  width: 100%;
  background: #ffffff;
  color: var(--accent);
}

.settings-toggle:hover {
  color: #ffffff;
}

.seller-settings {
  margin-top: 14px;
}

.settings-actions {
  display: flex;
  gap: 10px;
}

.secondary-button {
  background: #ffffff;
  color: #b42318;
  border-color: #f1a29b;
}

.secondary-button:hover {
  background: #b42318;
  color: #ffffff;
}

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

.modal-panel {
  width: min(720px, 100%);
  max-height: 80vh;
  overflow: auto;
  padding: 18px;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
}

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

.modal-header h2 {
  margin: 0;
  font-size: 18px;
}

.draft-list {
  display: grid;
  gap: 10px;
}

.draft-item {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.draft-item span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.empty-state {
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

.pdf-export-wrapper {
  position: fixed;
  left: 0;
  top: 0;
  width: 210mm;
  background: #ffffff;
  opacity: 0.01;
  pointer-events: none;
  z-index: 9999;
}

.pdf-export-document {
  width: 210mm !important;
  padding: 16mm;
  background: #ffffff;
  box-sizing: border-box;
}

.actions span {
  font-size: 12px;
  opacity: 0.86;
}

.export-option {
  display: inline-grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  column-gap: 6px;
  min-height: 42px;
  padding: 5px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #ffffff;
  color: #344054;
  line-height: 1.15;
}

.export-option input {
  width: auto;
  grid-row: 1 / span 2;
}

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

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

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

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

.section-actions {
  display: flex;
  gap: 8px;
}

.section-title h2 {
  margin: 0;
}

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

label {
  display: grid;
  gap: 6px;
  color: #344054;
  font-size: 13px;
}

.wide {
  grid-column: 1 / -1;
}

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

.bilingual-pair label {
  height: 100%;
}

.bilingual-pair textarea {
  min-height: 112px;
  height: 100%;
}

.item-options {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
}

.option-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 4px 8px;
  border: 1px solid #d0d7e2;
  border-radius: 6px;
  background: #ffffff;
}

.option-check input {
  width: auto;
}

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

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

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

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

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

.edit-table {
  min-width: 720px;
}

th,
td {
  border: 1px solid var(--line);
  padding: 7px;
  vertical-align: middle;
}

th {
  background: var(--panel);
  font-size: 12px;
  color: #344054;
  text-align: center;
}

.edit-table input {
  min-width: 78px;
  border: 0;
  border-radius: 0;
  padding: 6px;
}

.delete-row {
  width: 32px;
  min-height: 32px;
  border-radius: 6px;
  background: #b42318;
  border-color: #b42318;
}

.preview-area {
  padding: 22px;
  background: #dfe6ef;
  overflow: auto;
}

.preview-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.preview-tabs button {
  background: white;
  color: var(--ink);
  border-color: #cbd5e1;
}

.preview-tabs button.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.document {
  display: none;
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto 24px;
  padding: 16mm;
  background: white;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.16);
  font-family: "Times New Roman", Arial, serif;
  font-size: 11pt;
  color: #111827;
}

.document.active {
  display: block;
}

.doc-company {
  text-align: center;
  border-bottom: 2px solid #111827;
  padding-bottom: 8px;
  margin-bottom: 12px;
}

.doc-company h2 {
  margin: 0 0 4px;
  font-size: 18pt;
}

.doc-title {
  text-align: center;
  font-weight: 700;
  font-size: 16pt;
  margin: 14px 0;
  letter-spacing: 0;
}

.doc-meta-table {
  margin-bottom: 12px;
}

.doc-meta-table td {
  width: 25%;
  border: 1px solid #111827;
  padding: 6px 8px;
  vertical-align: top;
}

.doc-meta-table strong {
  display: block;
  font-size: 9pt;
}

.party-table {
  margin-bottom: 12px;
}

.party-table td {
  width: 50%;
  border: 1px solid #111827;
  padding: 8px;
  vertical-align: top;
}

.doc-table th,
.doc-table td {
  border: 1px solid #111827;
  padding: 5px;
}

.doc-table th {
  background: #f2f4f7;
}

.right {
  text-align: right;
}

.center {
  text-align: center;
}

.total-row td {
  font-weight: 700;
}

.notes {
  margin-top: 14px;
  line-height: 1.45;
}

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

  .document {
    width: 100%;
    min-height: auto;
  }
}

@media print {
  @page {
    size: A4;
    margin: 10mm;
  }

  body {
    background: white;
  }

  .workspace,
  .preview-tabs {
    display: none;
  }

  .app {
    display: block;
  }

  .preview-area {
    padding: 0;
    background: white;
  }

  .document {
    display: none;
    width: auto;
    min-height: auto;
    margin: 0;
    padding: 12mm;
    box-shadow: none;
  }

  .document.active {
    display: block;
  }
}
