:root {
  --primary: #f97316;
  --primary-dark: #c2410c;
  --public-primary: #6ca43a;
  --ink: #1f2937;
  --muted: #667085;
  --line: #e5e7eb;
  --surface: #ffffff;
  --canvas: #f7f8fa;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 16px;
  background:
    linear-gradient(135deg, rgba(249, 115, 22, 0.14), transparent 36%),
    var(--canvas);
}

.login-panel {
  width: min(100%, 390px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 32px;
  box-shadow: 0 18px 42px rgba(31, 41, 55, 0.10);
}

.login-logo {
  width: 178px;
  height: auto;
  margin-bottom: 22px;
}

h1,
h2,
p {
  margin-top: 0;
}

.login-panel h1 {
  margin-bottom: 4px;
  font-size: 28px;
}

.muted,
.module-grid p,
.topbar span,
.kpi-card span {
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 16px;
  margin-top: 28px;
}

label {
  display: grid;
  gap: 6px;
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cfd4dc;
  border-radius: 6px;
  padding: 11px 12px;
  background: #fff;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: 3px solid rgba(249, 115, 22, 0.22);
  border-color: var(--primary);
}

button {
  border: 0;
  border-radius: 6px;
  padding: 11px 14px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-weight: 750;
}

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

a {
  color: inherit;
}

.ghost-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.ghost-button:hover {
  background: #f3f4f6;
}

.form-error {
  margin: 0;
  color: #b42318;
  font-weight: 650;
}

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

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  text-decoration: none;
}

.topbar-brand img {
  width: 134px;
  height: auto;
  flex: 0 0 auto;
}

.topbar-brand div {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.topnav a {
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 700;
}

.topnav a:hover {
  background: #f3f4f6;
  color: var(--ink);
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 34px auto 56px;
}

.narrow-shell {
  width: min(820px, calc(100% - 32px));
}

.page-heading {
  margin-bottom: 24px;
}

.page-heading-row {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
}

.eyebrow {
  margin-bottom: 6px;
  color: var(--primary-dark);
  font-weight: 800;
  text-transform: uppercase;
  font-size: 13px;
}

.page-heading h1 {
  font-size: 32px;
  margin-bottom: 0;
}

.kpi-grid,
.module-grid {
  display: grid;
  gap: 16px;
}

.kpi-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 28px;
}

.kpi-card,
.module-grid article {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.kpi-card {
  padding: 22px;
  display: grid;
  gap: 10px;
}

.kpi-card strong {
  font-size: 34px;
}

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

.module-grid article {
  padding: 22px;
  min-height: 142px;
}

.module-grid h2 {
  font-size: 18px;
  margin-bottom: 8px;
}

.module-grid p {
  margin-bottom: 0;
  line-height: 1.5;
}

.module-grid .text-link {
  display: inline-block;
  margin-top: 16px;
}

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

.button-link,
.secondary-link,
.secondary-button,
.ghost-link,
.danger-button {
  border-radius: 6px;
  padding: 11px 14px;
  text-decoration: none;
  font-weight: 750;
  line-height: 1;
}

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

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

.secondary-button,
.secondary-link,
.ghost-link {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.danger-button {
  border: 1px solid #fecdca;
  background: #fff;
  color: #b42318;
}

.secondary-button:hover,
.secondary-link:hover,
.ghost-link:hover,
.danger-button:hover {
  background: #f3f4f6;
}

.text-link {
  color: var(--primary-dark);
  font-weight: 750;
  text-decoration: none;
}

.text-link:hover {
  text-decoration: underline;
}

.notice {
  border: 1px solid rgba(108, 164, 58, 0.28);
  border-radius: 8px;
  padding: 12px 14px;
  background: rgba(108, 164, 58, 0.10);
  color: #315f20;
  font-weight: 700;
}

.table-surface,
.form-surface {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

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

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

th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

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

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

.form-surface {
  display: grid;
  gap: 18px;
  padding: 24px;
}

.form-section {
  display: grid;
  gap: 16px;
}

.form-section + .form-section {
  border-top: 1px solid var(--line);
  padding-top: 20px;
}

.form-section h2 {
  margin-bottom: 0;
  font-size: 18px;
}

.form-grid {
  display: grid;
  gap: 16px;
}

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

.address-grid {
  grid-template-columns: 140px 1fr 120px;
}

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

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

.document-meta-grid {
  grid-template-columns: 180px 180px 1fr;
}

.line-editor {
  display: grid;
  gap: 8px;
}

.line-editor-head,
.line-editor-row {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(280px, 1fr) 100px 150px 90px;
}

.line-editor-head {
  background: var(--public-primary);
  border-radius: 6px;
  color: #fff;
  padding: 9px 10px;
  font-size: 13px;
  font-weight: 800;
}

.line-editor-rows {
  display: grid;
  gap: 8px;
}

.fixed-footer-preview {
  border-top: 1px solid var(--public-primary);
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding-top: 14px;
}

.fixed-footer-preview p {
  margin: 6px 0 0;
}

.document-preview {
  display: grid;
  gap: 22px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
}

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

.document-preview-header p {
  margin-bottom: 4px;
}

.document-preview h2 {
  color: var(--public-primary);
}

.address-preview {
  display: grid;
  gap: 3px;
  line-height: 1.45;
}

.totals-box {
  width: min(100%, 360px);
  justify-self: end;
  display: grid;
  gap: 6px;
}

.totals-box p {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr 130px;
  margin: 0;
}

.totals-box strong {
  text-align: right;
}

.preline {
  white-space: pre-line;
}

.document-footer {
  border-top: 1px solid var(--public-primary);
  color: var(--muted);
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  font-size: 13px;
  margin-top: 8px;
  padding-top: 16px;
  text-align: center;
}

.document-footer p {
  margin: 0;
}

.document-preview table th:last-child,
.document-preview table td:last-child,
.print-page table th:last-child,
.print-page table td:last-child {
  text-align: right;
}

.document-preview table th,
.print-page table th {
  background: var(--public-primary);
  color: #fff;
}

.print-body {
  background: #fff;
}

.print-page {
  width: 190mm;
  min-height: 270mm;
  margin: 0 auto;
  padding: 18mm 0;
  color: #1f2937;
}

.print-header,
.print-meta-grid {
  display: grid;
  grid-template-columns: 1fr 68mm;
  gap: 18mm;
}

.print-header {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 28mm;
}

.print-header img {
  width: 56mm;
  height: auto;
}

.print-header p,
.print-meta p {
  margin: 0 0 3px;
}

.print-meta-grid {
  margin-bottom: 18mm;
}

.print-meta {
  display: grid;
  gap: 3px;
}

.print-meta p {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.print-page h1 {
  color: var(--public-primary);
  font-size: 24px;
  margin-bottom: 10mm;
}

@media print {
  @page {
    margin: 18mm;
  }

  .print-page {
    margin: 0;
    padding: 28mm 0 34mm;
    width: auto;
  }

  .print-header {
    position: fixed;
    top: 0;
    right: 0;
    width: 100%;
  }

  .print-page .document-footer {
    bottom: 0;
    left: 0;
    position: fixed;
    right: 0;
  }
}

@media (max-width: 820px) {
  .kpi-grid,
  .module-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 12px 16px;
  }

  .topbar-brand img {
    width: 104px;
  }

  .topnav {
    margin-left: 0;
  }

  .page-heading-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .button-row,
  .form-actions {
    justify-content: flex-start;
  }

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

  .two-columns,
  .address-grid,
  .three-columns,
  .four-columns,
  .fixed-footer-preview,
  .document-footer,
  .document-meta-grid,
  .line-editor-head,
  .line-editor-row {
    grid-template-columns: 1fr;
  }

  .line-editor-head {
    display: none;
  }

  .document-preview-header {
    flex-direction: column;
  }
}
