:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --line: #d9ddd3;
  --text: #1d2520;
  --muted: #667064;
  --accent: #1f7a5a;
  --accent-strong: #145a43;
  --warn: #9a6a16;
  --danger: #b84a4a;
  --shadow: 0 8px 24px rgba(29, 37, 32, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

a {
  color: var(--accent-strong);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.topbar {
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 24px;
  height: 60px;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  color: var(--text);
  font-size: 18px;
  font-weight: 760;
  letter-spacing: 0;
}

.nav {
  display: flex;
  gap: 16px;
  margin-right: auto;
}

.nav a {
  color: var(--muted);
  font-weight: 620;
}

.logout-form {
  align-items: center;
  display: flex;
  gap: 10px;
  margin-left: auto;
}

.user-chip {
  background: #eef3ed;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  padding: 4px 10px;
}

.page {
  margin: 0 auto;
  max-width: 1240px;
  padding: 28px;
}

.narrow {
  margin: 0 auto;
  max-width: 760px;
}

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

h1,
h2 {
  letter-spacing: 0;
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.15;
}

h2 {
  font-size: 18px;
  margin-bottom: 14px;
}

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

.panel,
.table-shell {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  padding: 20px;
}

.table-shell {
  overflow-x: auto;
  padding: 0;
}

table {
  border-collapse: collapse;
  min-width: 760px;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 14px;
  text-align: left;
  vertical-align: top;
}

th {
  background: #f0f3ef;
  color: #485249;
  font-size: 12px;
  font-weight: 720;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

code {
  background: #f0f3ef;
  border-radius: 4px;
  color: #374139;
  display: inline-block;
  max-width: 280px;
  overflow-wrap: anywhere;
  padding: 2px 5px;
}

button,
.button-link {
  align-items: center;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: #ffffff;
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-weight: 700;
  justify-content: center;
  min-height: 38px;
  padding: 8px 14px;
}

button:hover,
.button-link:hover {
  background: var(--accent-strong);
  text-decoration: none;
}

.secondary-button {
  background: #eef3ed;
  border-color: #c7d5c7;
  color: var(--text);
}

.secondary-button:hover {
  background: #dfe9df;
}

.danger-button {
  background: #fff2f0;
  border-color: #e0b2aa;
  color: #8d3329;
  min-height: 32px;
  padding: 5px 10px;
}

.danger-button:hover {
  background: #f5d8d3;
}

.ghost-button,
.ghost-link {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  display: inline-flex;
  font: inherit;
  font-weight: 650;
  min-height: 38px;
  padding: 8px 14px;
}

.ghost-button:hover,
.ghost-link:hover {
  background: #eef3ed;
  text-decoration: none;
}

.auth-shell {
  display: grid;
  min-height: calc(100vh - 116px);
  place-items: center;
}

.auth-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-width: 420px;
  padding: 28px;
  width: 100%;
}

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

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

label {
  display: grid;
  gap: 6px;
}

label span {
  color: #3f493f;
  font-weight: 680;
}

input,
textarea,
select {
  background: #ffffff;
  border: 1px solid #cbd2c7;
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  min-height: 38px;
  padding: 8px 10px;
  width: 100%;
}

textarea {
  resize: vertical;
}

input:disabled,
textarea:disabled,
select:disabled {
  background: #f2f3f0;
  color: #687166;
}

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

.check {
  align-items: center;
  display: flex;
  flex-direction: row;
  gap: 8px;
}

.check input {
  min-height: auto;
  width: auto;
}

.form-actions,
.actions,
.sticky-actions {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.form-actions {
  grid-column: 1 / -1;
}

.sticky-actions {
  background: rgba(246, 247, 244, 0.94);
  border-top: 1px solid var(--line);
  bottom: 0;
  margin: 8px -28px -28px;
  padding: 14px 28px;
  position: sticky;
}

.alert {
  background: #fff2f0;
  border: 1px solid #e6b8b0;
  border-radius: 8px;
  color: #8d3329;
  margin-bottom: 16px;
  padding: 10px 12px;
}

.success-alert {
  background: #eef8ef;
  border-color: #b9d8be;
  color: #275f35;
}

.warning-alert {
  background: #fff7e8;
  border-color: #e6c77f;
  color: #7a4c00;
}

.missing-list {
  margin: 8px 0 0;
  padding-left: 20px;
}

.missing-list li {
  margin: 4px 0;
}

.status {
  background: #edf5e8;
  border: 1px solid #cfdfc4;
  border-radius: 999px;
  color: #315a2d;
  display: inline-flex;
  font-size: 12px;
  font-weight: 720;
  padding: 3px 9px;
}

.summary-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 20px;
}

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

.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 4px;
  min-height: 88px;
  padding: 16px;
}

.metric span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.metric strong {
  font-size: 18px;
  overflow-wrap: anywhere;
}

.split-grid {
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

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

.section-head h2 {
  margin: 0;
}

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

.row-action,
.record {
  align-items: center;
  background: #fbfcfa;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 12px;
}

.row-action {
  align-items: flex-end;
}

.export-controls,
.stamp-upload {
  align-items: flex-end;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.export-controls label {
  min-width: 150px;
}

.export-controls .check {
  min-width: auto;
  padding-bottom: 8px;
}

.stamp-upload {
  background: #fbfcfa;
  border: 1px solid var(--line);
  border-radius: 8px;
  justify-content: flex-start;
  margin-bottom: 12px;
  padding: 12px;
}

.stamp-upload label {
  min-width: 260px;
}

.row-action span,
.record span {
  color: var(--muted);
  display: block;
  font-size: 12px;
}

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

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

.inline-actions form {
  margin: 0;
}

.compact-button,
.compact-link {
  min-height: 32px;
  padding: 5px 10px;
}

.import-hint {
  margin-top: 12px;
}

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

.data-form {
  display: grid;
  gap: 2px;
}

.document-nav {
  background: rgba(246, 247, 244, 0.96);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  padding: 8px;
  position: sticky;
  top: 72px;
  z-index: 15;
}

.document-nav a {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font-weight: 720;
  padding: 8px 12px;
}

.document-nav a:hover {
  background: #eef3ed;
  text-decoration: none;
}

.document-section {
  scroll-margin-top: 132px;
}

.subsection {
  border-top: 1px solid #e4e8df;
  display: grid;
  gap: 14px;
  padding-top: 16px;
}

.subsection + .subsection {
  margin-top: 18px;
}

.subsection h3 {
  font-size: 15px;
  line-height: 1.25;
  margin: 0;
}

.section-head.compact {
  margin-bottom: 0;
}

.item-cards {
  display: grid;
  gap: 16px;
  margin-top: 16px;
}

.item-section-list {
  display: grid;
  gap: 14px;
}

.item-card {
  background: #fbfcfa;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 14px;
  padding: 16px;
}

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

.item-card-head h3 {
  font-size: 16px;
  line-height: 1.25;
  margin: 0;
}

.item-card-section {
  border-top: 1px solid #e4e8df;
  display: grid;
  gap: 10px;
  padding-top: 14px;
}

.item-card-section h4 {
  color: #465146;
  font-size: 13px;
  font-weight: 760;
  letter-spacing: 0;
  margin: 0;
}

.item-card-section-accent {
  background: #f4f8f3;
  border: 1px solid #cfdfc4;
  border-radius: 8px;
  padding: 12px;
}

.item-card-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
}

.item-textarea textarea {
  min-height: 150px;
}

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

.items-table table {
  min-width: 2400px;
}

.items-table td {
  padding: 7px;
}

.items-table input {
  min-width: 105px;
}

.items-table th:first-child,
.items-table td:first-child {
  left: 0;
  position: sticky;
  z-index: 2;
}

.items-table th:first-child {
  background: #f0f3ef;
}

.items-table td:first-child {
  background: #ffffff;
}

.totals-grid {
  margin-top: 16px;
}

@media (max-width: 860px) {
  .topbar {
    align-items: flex-start;
    height: auto;
    padding: 14px;
  }

  .nav,
  .logout-form,
  .page-head,
  .split-grid {
    align-items: stretch;
    flex-direction: column;
  }

  .page {
    padding: 18px;
  }

  .document-nav {
    position: static;
  }

  .form-grid,
  .item-card-grid,
  .summary-grid,
  .split-grid {
    grid-template-columns: 1fr;
  }

  .sticky-actions {
    margin: 0 -18px -18px;
    padding: 12px 18px;
  }
}
