:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --card: #ffffff;
  --border: #dde3ef;
  --text: #14213d;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-2: #0f766e;
  --danger: #dc2626;
  --shadow: 0 18px 40px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(135deg, #eef4ff 0%, var(--bg) 100%);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px;
}

.hero {
  margin-bottom: 24px;
  padding: 24px 28px;
  border-radius: 24px;
  background: linear-gradient(90deg, #1d4ed8, #0f766e);
  color: white;
  box-shadow: var(--shadow);
  width: 100%;
}

.eyebrow {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.78rem;
  opacity: 0.8;
}

.hero h1 {
  margin: 0 0 8px;
  font-size: 1.8rem;
}

.hero p {
  margin: 0;
  max-width: 680px;
  line-height: 1.6;
  opacity: 0.95;
}

.layout {
  display: grid;
  gap: 24px;
  grid-template-columns: 1.15fr 0.85fr;
}

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 22px;
}

.panel-header,
.section-title-row,
.preview-head,
.actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.panel-header h2,
.preview-head h2,
.section-title-row h3 {
  margin: 0;
}

.mode-switch {
  display: inline-flex;
  gap: 8px;
  background: #f1f5f9;
  padding: 6px;
  border-radius: 999px;
}

.mode-btn,
.primary-btn,
.secondary-btn,
.ghost-btn {
  border: none;
  border-radius: 999px;
  padding: 10px 14px;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.mode-btn:hover,
.primary-btn:hover,
.secondary-btn:hover,
.ghost-btn:hover {
  transform: translateY(-1px);
}

.mode-btn {
  background: transparent;
  color: var(--muted);
}

.mode-btn.active {
  background: var(--accent);
  color: white;
}

.primary-btn {
  background: var(--accent);
  color: white;
}

.secondary-btn {
  background: #e2e8f0;
  color: var(--text);
}

.ghost-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
  font-weight: 600;
  color: var(--text);
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  background: #fcfdff;
  color: var(--text);
}

input:focus,
textarea:focus {
  outline: 2px solid rgba(37, 99, 235, 0.16);
  border-color: var(--accent);
}

.grid {
  display: grid;
  gap: 14px;
}

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

.items-section {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  background: #fbfdff;
}

.item-row {
  display: grid;
  gap: 10px;
  grid-template-columns: 2fr 0.8fr 1.1fr auto;
  margin-top: 10px;
  align-items: end;
}

.item-row .remove-item {
  padding: 10px 12px;
  border: 1px solid #fecaca;
  background: #fef2f2;
  color: var(--danger);
  border-radius: 10px;
  cursor: pointer;
}

.document-preview {
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px;
  background: white;
  min-height: 560px;
}

.print-document {
  display: none;
}

.document-preview .head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.document-preview .head h3 {
  margin: 0 0 6px;
  font-size: 1.4rem;
}

.logo-box {
  width: 120px;
  height: 84px;
  border-radius: 16px;
  /* border: 1px solid var(--border); */
  display: flex;
  align-items: center;
  justify-content: center;
  /* background: linear-gradient(135deg, #eff6ff, #ecfeff); */
  color: var(--accent);
  font-weight: 700;
  font-size: 0.82rem;
  text-align: center;
  padding: 8px;
}

.badge {
  display: inline-block;
  padding: 8px 12px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.8rem;
  background: #dcfce7;
  color: #166534;
}

.badge.pending {
  background: #fef3c7;
  color: #92400e;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 16px 0 20px;
  color: var(--muted);
}

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

.table th,
.table td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.table th {
  background: #f8fafc;
}

.summary {
  margin-top: 16px;
  display: grid;
  gap: 8px;
  max-width: 320px;
  margin-left: auto;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.95rem;
}

.summary-row.total {
  font-size: 1.05rem;
  font-weight: 700;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.notes-box {
  margin-top: 16px;
  padding: 12px;
  background: #f8fafc;
  border-radius: 12px;
  color: var(--muted);
  white-space: pre-wrap;
}

.saved-docs-section {
  margin-top: 18px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.saved-docs-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.saved-doc-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  background: #fbfdff;
}

.saved-doc-card strong {
  display: block;
  margin-bottom: 4px;
}

.status-message {
  min-height: 22px;
  color: var(--accent-2);
  font-size: 0.95rem;
  font-weight: 600;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
}

.modal-card {
  position: relative;
  width: min(780px, 100%);
  max-height: 80vh;
  overflow: hidden;
  background: white;
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 20px;
}

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

.saved-docs-modal-list {
  display: grid;
  gap: 10px;
  max-height: 50vh;
  overflow: auto;
  padding-right: 4px;
}

.modal-item {
  cursor: pointer;
}

.pagination {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.pagination .ghost-btn.active {
  background: var(--accent);
  color: white;
}

.hidden {
  display: none;
}

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

@media (max-width: 700px) {
  .app-shell {
    padding: 16px;
  }

  .two-columns,
  .item-row,
  .meta-grid {
    grid-template-columns: 1fr;
  }
  
  .meta-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .panel-header,
  .section-title-row,
  .actions,
  .preview-head {
    flex-direction: column;
    align-items: stretch;
  }
}

@media print {
  body {
    background: white;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .app-shell {
    max-width: none;
    padding: 0;
  }

  .hero,
  .form-panel,
  .actions,
  .mode-switch,
  .secondary-btn,
  .ghost-btn,
  .saved-docs-section,
  .preview-head,
  #print-document {
    display: none !important;
  }

  .preview-panel,
  #preview-section {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    background: white !important;
  }

  #document-preview {
    display: block !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    min-height: auto !important;
    color: #000;
    background: white !important;
    width: 100% !important;
  }
}
