:root {
  --bg: #f6f0e5;
  --panel: rgba(255, 251, 245, 0.92);
  --line: rgba(167, 135, 89, 0.22);
  --text: #191715;
  --muted: #6b645b;
  --accent: #bf8533;
  --accent-dark: #955e16;
  --shadow: 0 24px 60px rgba(62, 47, 20, 0.12);
  --radius: 24px;
  --ui-font: "Avenir Next", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--ui-font);
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(209, 159, 77, 0.18), transparent 28%),
    radial-gradient(circle at bottom right, rgba(95, 133, 146, 0.12), transparent 22%),
    linear-gradient(180deg, #f8f5ef 0%, #f1ebde 100%);
}

body {
  padding: 24px;
}

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(31, 24, 15, 0.28);
  backdrop-filter: blur(10px);
  padding: 24px;
}

.login-overlay.visible {
  display: flex;
}

.login-card {
  width: min(460px, 100%);
  background: rgba(255, 251, 245, 0.98);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: 0 28px 60px rgba(54, 41, 18, 0.16);
  padding: 24px;
}

.login-card h2 {
  margin: 0 0 10px;
  font-size: 32px;
  letter-spacing: -0.04em;
}

.login-copy {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.5;
}

.login-actions {
  margin-top: 16px;
}

.login-hint {
  margin: 14px 0 0;
  color: var(--accent-dark);
  font-size: 13px;
}

.app-shell {
  display: grid;
  gap: 20px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
}

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

.topbar h1 {
  margin: 0 0 8px;
  font-size: clamp(34px, 4vw, 52px);
  line-height: 0.96;
  letter-spacing: -0.05em;
}

.topbar-copy {
  margin: 0;
  max-width: 760px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
}

.topbar-stats {
  display: flex;
  gap: 12px;
  flex-wrap: nowrap;
  justify-content: flex-end;
}

.topbar-right {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: flex-end;
}

.user-card {
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-radius: 18px;
  background: rgba(255, 251, 245, 0.92);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.user-card-copy {
  min-width: 0;
}

.user-card-copy strong {
  display: block;
  margin-top: 4px;
  font-size: clamp(18px, 2vw, 22px);
  letter-spacing: -0.03em;
}

.user-card-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.stat-card,
.panel,
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.stat-card {
  min-width: 132px;
  border-radius: 18px;
  padding: 14px 16px;
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat-card strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
  letter-spacing: -0.03em;
}

.workspace {
  display: block;
}

.panel {
  border-radius: var(--radius);
  backdrop-filter: blur(12px);
}

.sidebar-head,
.action-row,
.preview-head,
.number-card-main {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.sidebar-head {
  margin-bottom: 14px;
}

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

.sidebar h2,
.preview h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.03em;
}

.search-field,
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.search-field {
  margin-bottom: 10px;
}

.search-field span,
.field span {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #554d44;
}

.number-grid > .field > span,
.form-grid > .field > span {
  display: flex;
  align-items: flex-end;
  min-height: 2.8em;
  line-height: 1.25;
}

input,
textarea,
button {
  font: inherit;
}

input,
textarea {
  width: 100%;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  color: var(--text);
  padding: 12px 14px;
}

textarea {
  min-height: 104px;
  resize: vertical;
  line-height: 1.45;
}

input:focus,
textarea:focus {
  outline: 2px solid rgba(191, 133, 51, 0.18);
  border-color: rgba(191, 133, 51, 0.42);
}

.button {
  border: 0;
  border-radius: 14px;
  padding: 11px 15px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:disabled {
  cursor: wait;
  opacity: 0.9;
}

.button.is-busy {
  filter: saturate(0.88);
}

.button-primary {
  background: linear-gradient(135deg, #ca933d 0%, #aa7322 100%);
  color: white;
  box-shadow: 0 16px 24px rgba(158, 102, 27, 0.18);
}

.button-secondary {
  background: white;
  border: 1px solid var(--line);
  color: var(--text);
}

.sidebar-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(28, 22, 14, 0.18);
  backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  z-index: 25;
}

.drawer-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

.records-drawer {
  position: fixed;
  top: 20px;
  left: 20px;
  bottom: 20px;
  width: min(340px, calc(100vw - 40px));
  padding: 16px;
  overflow: auto;
  z-index: 30;
  transform: translateX(calc(-100% - 30px));
  transition: transform 0.22s ease;
}

.records-drawer.open {
  transform: translateX(0);
}

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

.record-item {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
  border-radius: 18px;
  padding: 12px;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.record-item:hover {
  transform: translateY(-1px);
  border-color: rgba(191, 133, 51, 0.34);
}

.record-item.active {
  border-color: rgba(191, 133, 51, 0.5);
  background: rgba(255, 248, 238, 0.96);
}

.record-item-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.record-item-title {
  font-size: 14px;
  line-height: 1.3;
}

.record-item-status {
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.record-item-status.draft {
  background: rgba(117, 132, 151, 0.12);
  color: #475163;
}

.record-item-status.issued {
  background: rgba(84, 132, 93, 0.14);
  color: #2f5a3b;
}

.record-item-body,
.record-item-meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.main-area {
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(340px, 460px) minmax(760px, 1fr);
  align-items: start;
}

.editor {
  padding: 18px;
  position: sticky;
  top: 20px;
  max-height: calc(100vh - 56px);
  overflow: auto;
}

.preview {
  padding: 18px;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  gap: 10px;
  margin-bottom: 16px;
}

.action-feedback {
  min-height: 20px;
  margin: -4px 0 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.action-feedback.is-dirty {
  color: #8b6a33;
}

.action-feedback.is-success {
  color: #2f5a3b;
}

.action-feedback.is-error {
  color: #9b3434;
}

.action-group {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
  min-width: 0;
}

.action-group-secondary {
  justify-self: end;
}

.action-group .button {
  white-space: nowrap;
  padding: 9px 12px;
  font-size: 14px;
  line-height: 1.15;
  border-radius: 12px;
}

.card {
  border-radius: 20px;
  padding: 16px;
}

.number-card-main {
  display: grid;
  gap: 12px;
}

.number-card-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.number-card-copy {
  min-width: 0;
  width: 100%;
}

.card-title {
  margin: 0 0 8px;
  color: var(--accent-dark);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 13px;
}

.number-preview {
  width: 100%;
  max-width: none;
  font-size: clamp(14px, 1.35vw, 18px);
  font-weight: 800;
  line-height: 1.12;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
}

.number-note {
  max-width: none;
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.pill-stack {
  display: flex;
  gap: 10px;
  flex-wrap: nowrap;
  justify-content: flex-end;
  align-items: center;
}

.pill {
  border-radius: 999px;
  background: rgba(117, 132, 151, 0.12);
  color: #475163;
  padding: 9px 12px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.pill-accent {
  background: rgba(191, 133, 51, 0.14);
  color: var(--accent-dark);
}

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

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

.form-sections {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}

.form-section {
  border-top: 1px solid rgba(167, 135, 89, 0.18);
  padding-top: 14px;
}

.form-section:first-child {
  border-top: 0;
  padding-top: 0;
}

.form-section h3 {
  margin: 0 0 12px;
  color: var(--accent-dark);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 14px;
}

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

.form-grid .field.full {
  grid-column: 1 / -1;
}

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

.preview-tools,
.preview-meta {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
}

.preview-tools {
  align-items: center;
}

.tool-readout,
.meta-chip {
  border-radius: 12px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  background: rgba(255, 251, 245, 0.9);
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.preview-meta {
  margin: 14px 0;
}

.paper-frame {
  background: linear-gradient(180deg, #e3d7c0 0%, #d4bb94 100%);
  border-radius: 24px;
  padding: 14px;
  box-shadow: 0 26px 46px rgba(74, 58, 26, 0.16);
}

.paper {
  position: relative;
  width: 100%;
  aspect-ratio: 1545 / 2000;
  overflow: hidden;
  border-radius: 12px;
  background: white;
}

.paper img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.overlay {
  position: absolute;
  inset: 0;
  color: #171717;
  font-family: "Helvetica Neue", Arial, sans-serif;
  --paper-scale: 1;
  --text-multiplier: 1.32;
}

.preview-value {
  position: absolute;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
  padding: calc(var(--paper-scale) * 4px) calc(var(--paper-scale) * 6px);
  line-height: 1.16;
  font-size: calc(var(--paper-scale) * 18px * var(--text-multiplier));
}

.preview-value.small {
  font-size: calc(var(--paper-scale) * 14.5px * var(--text-multiplier));
}

.preview-value.tiny {
  font-size: calc(var(--paper-scale) * 12.4px * var(--text-multiplier));
  line-height: 1.12;
}

.preview-value.compact {
  line-height: 1.08;
}

.preview-value.vcenter {
  display: flex;
  justify-content: center;
  align-items: center;
}

.preview-value.vcenter-start {
  display: flex;
  align-items: center;
}

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

@media (max-width: 1500px) {
  .main-area {
    grid-template-columns: minmax(340px, 420px) minmax(640px, 1fr);
  }

  .topbar-right {
    max-width: 100%;
  }

  .topbar-stats {
    flex-wrap: wrap;
  }
}

@media (max-width: 1280px) {
  .main-area {
    grid-template-columns: 1fr;
  }

  .editor,
  .preview {
    position: static;
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 720px) {
  body {
    padding: 16px;
  }

  .topbar,
  .topbar-right,
  .user-card,
  .sidebar-head,
  .preview-head,
  .number-card-header,
  .number-card-main {
    flex-direction: column;
  }

  .number-card-header {
    align-items: flex-start;
  }

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

  .action-group {
    flex-wrap: wrap;
  }

  .action-group-secondary {
    justify-self: start;
  }

  .preview-tools,
  .preview-meta {
    flex-wrap: wrap;
  }

  .number-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .field-wide {
    grid-column: auto;
  }

  .pill-stack {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .number-preview {
    white-space: normal;
  }

  .number-grid > .field > span,
  .form-grid > .field > span {
    min-height: 0;
  }

  .records-drawer {
    left: 12px;
    right: 12px;
    top: 12px;
    bottom: 12px;
    width: auto;
  }

  .user-card-actions {
    width: 100%;
    justify-content: flex-start;
  }
}

@media print {
  @page {
    size: A4 portrait;
    margin: 0;
  }

  body {
    background: white;
    padding: 0;
  }

  .topbar,
  .records-drawer,
  .drawer-backdrop,
  .editor,
  .preview-head,
  .preview-meta {
    display: none !important;
  }

  .workspace,
  .main-area {
    display: block;
  }

  .preview {
    padding: 0;
    border: 0;
    box-shadow: none;
    background: transparent;
  }

  .paper-frame {
    background: transparent;
    box-shadow: none;
    padding: 0;
    border-radius: 0;
  }

  .paper {
    width: 210mm;
    height: 297mm;
    aspect-ratio: auto;
    max-width: none;
    border-radius: 0;
    margin: 0;
    overflow: hidden;
  }

  .paper img {
    display: none !important;
  }

  .overlay {
    inset: 0;
  }
}
