:root {
  --bg: #f5f5f4;
  --surface: #ffffff;
  --surface-subtle: #f5f5f4;
  --surface-hover: #fafaf9;
  --border: #e7e5e4;
  --border-strong: #d6d3d1;
  --ink: #0c0a09;
  --ink-muted: #57534e;
  --ink-faint: #78716c;
  --brand: #4a711c;
  --primary: #0c0a09;
  --primary-hover: #292524;
  --primary-fg: #ffffff;
  --success: #047857;
  --success-bg: #ecfdf5;
  --success-border: #a7f3d0;
  --warning: #92400e;
  --warning-bg: #fffbeb;
  --warning-border: #fcd34d;
  --destructive: #b91c1c;
  --destructive-bg: #fef2f2;
  --destructive-border: #fecaca;
  --forbidden: #7c2d12;
  --forbidden-bg: #fff7ed;
  --forbidden-border: #fdba74;
  --radius: 12px;
  --radius-sm: 8px;
  --control-h: 44px;
  --shadow-sm: 0 1px 2px rgba(12, 10, 9, 0.04);
  --shadow-lg: 0 12px 32px rgba(12, 10, 9, 0.14);
  --font-sans:
    'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
    sans-serif;
  --font-mono: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a {
  color: inherit;
}

h1,
h2,
h3 {
  letter-spacing: -0.01em;
}

h3 {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 12px;
}

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}
[tabindex='-1']:focus {
  outline: none;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  background: var(--primary);
  color: var(--primary-fg);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  z-index: 1000;
  text-decoration: none;
  font-weight: 600;
}
.skip-link:focus {
  left: 12px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Environment banner: legal status of the program, always visible. */
.env-banner {
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  padding: 6px 16px;
  border-bottom: 1px solid var(--border);
}
.env-banner--warning {
  background: var(--warning-bg);
  color: var(--warning);
  border-color: var(--warning-border);
}
.env-banner--success {
  background: var(--success-bg);
  color: var(--success);
  border-color: var(--success-border);
}
.env-banner--info {
  background: var(--surface);
  color: var(--ink);
}

.public-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0 16px;
  padding: 8px 16px;
}

/* Authentication screens */
.auth-stage {
  min-height: calc(100vh - 34px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 32px 16px;
}
.auth-brand img {
  display: block;
  height: 52px;
  width: auto;
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 32px;
}
.auth-card h1 {
  margin: 0 0 6px;
  font-size: 24px;
  font-weight: 650;
}
.auth-card .btn-primary {
  width: 100%;
  margin-top: 8px;
}

/* Workspace layout */
.workspace-layout {
  display: flex;
  min-height: calc(100vh - 34px);
}

.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 6px;
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -0.02em;
}

.sidebar-brand img {
  display: block;
  height: 36px;
  width: auto;
}

.sidebar-group-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  padding: 4px 12px 6px;
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-link {
  display: flex;
  align-items: center;
  min-height: 42px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  color: var(--ink-muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 15px;
}
.nav-link:hover {
  background: var(--surface-subtle);
  color: var(--ink);
}
.nav-link[aria-current='page'] {
  background: var(--surface-subtle);
  color: var(--ink);
  font-weight: 650;
  box-shadow: inset 3px 0 0 var(--brand);
}

.sidebar-spacer {
  flex: 1;
}

.workspace-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  min-height: 60px;
  padding: 10px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.topbar-issuer {
  font-weight: 600;
  font-size: 15px;
}
.topbar-issuer .muted {
  font-weight: 400;
}

.identity-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  font-size: 14px;
  color: var(--ink-muted);
}
.identity-pill .mono {
  color: var(--ink);
  font-weight: 600;
}

.content-area {
  padding: 32px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

/* Section tabs: related screens under one navigation entry */
.section-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin: -8px 0 28px;
  overflow-x: auto;
}
.section-tabs:empty {
  display: none;
}
.section-tab {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 14px;
  color: var(--ink-muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 15px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
}
.section-tab:hover {
  color: var(--ink);
}
.section-tab[aria-current='page'] {
  color: var(--ink);
  font-weight: 650;
  border-bottom-color: var(--ink);
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.page-header h1,
#app-root > h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 650;
  line-height: 1.2;
}
#app-root > h1 {
  margin-bottom: 24px;
}
.page-header .muted {
  font-size: 15px;
}
.page-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 24px;
  margin-bottom: 20px;
}
.card h2 {
  margin: 0 0 16px;
  font-size: 18px;
  font-weight: 650;
}
.card > .table-wrap:first-child {
  margin: -8px -8px 0;
}
.card.mt-lg {
  margin-top: 0;
}
.card--flush {
  padding: 8px;
}
.card--flush > .muted {
  padding: 16px;
  margin: 0;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 20px;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px 20px;
}
.grid-issue {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 20px;
  align-items: start;
}
.grid-issue > .card:last-child {
  position: sticky;
  top: 24px;
}

/* Key-value facts (document detail, settlement, rectification) */
.grid-3 > div > .muted:first-child {
  font-size: 14px;
  margin-bottom: 4px;
}
.grid-3 strong {
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 18px;
}
.field label {
  font-size: 14px;
  font-weight: 550;
  color: var(--ink);
}
.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: var(--control-h);
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  transition:
    border-color 0.12s ease,
    box-shadow 0.12s ease;
}
.field textarea {
  min-height: 88px;
  resize: vertical;
}
.field input:hover,
.field select:hover,
.field textarea:hover {
  border-color: var(--ink-faint);
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(12, 10, 9, 0.12);
}
.field input[type='checkbox'] {
  min-height: 0;
  width: auto;
}
.field-hint {
  font-size: 14px;
  color: var(--ink-muted);
}

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px 4px;
  margin: 0 0 16px;
}
legend {
  font-size: 14px;
  font-weight: 600;
  padding: 0 6px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--control-h);
  padding: 0 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  font-weight: 550;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition:
    background 0.12s ease,
    border-color 0.12s ease;
}
.btn:hover:not(:disabled) {
  background: var(--surface-subtle);
  border-color: var(--ink-faint);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-fg);
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}
.btn-danger {
  background: var(--surface);
  border-color: var(--destructive-border);
  color: var(--destructive);
}
.btn-danger:hover:not(:disabled) {
  background: var(--destructive-bg);
  border-color: var(--destructive);
}
.modal-dialog .btn-danger {
  background: var(--destructive);
  border-color: var(--destructive);
  color: #ffffff;
}
.btn-ghost {
  border-color: transparent;
  background: transparent;
}
.btn-block {
  width: 100%;
}
.btn-sm {
  min-height: 36px;
  padding: 0 12px;
  font-size: 14px;
}
.btn-lg {
  min-height: 48px;
  font-size: 16px;
}

.actions-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.segmented {
  display: inline-flex;
  padding: 4px;
  gap: 4px;
  border-radius: 10px;
  background: #e7e5e4;
  flex-wrap: wrap;
}
.segmented button {
  border: 0;
  background: transparent;
  min-height: 38px;
  padding: 0 16px;
  border-radius: 7px;
  font: inherit;
  font-size: 15px;
  font-weight: 550;
  cursor: pointer;
  color: var(--ink-muted);
}
.segmented button:hover {
  color: var(--ink);
}
.segmented button[aria-pressed='true'] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(12, 10, 9, 0.12);
}

.alert {
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 15px;
}
.alert--success {
  background: var(--success-bg);
  border-color: var(--success-border);
  color: var(--success);
}
.alert--warning {
  background: var(--warning-bg);
  border-color: var(--warning-border);
  color: var(--warning);
}
.alert--destructive {
  background: var(--destructive-bg);
  border-color: var(--destructive-border);
  color: var(--destructive);
}
.alert--forbidden {
  background: var(--forbidden-bg);
  border-color: var(--forbidden-border);
  color: var(--forbidden);
}
.alert-title {
  font-weight: 650;
  display: block;
  margin-bottom: 2px;
}
.alert .btn {
  color: var(--ink);
}
.alert .btn-primary {
  color: var(--primary-fg);
}
.alerts-stack .alert {
  margin-bottom: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--ink);
  white-space: nowrap;
}
.badge--success {
  background: var(--success-bg);
  border-color: var(--success-border);
  color: var(--success);
}
.badge--warning {
  background: var(--warning-bg);
  border-color: var(--warning-border);
  color: var(--warning);
}
.badge--destructive {
  background: var(--destructive-bg);
  border-color: var(--destructive-border);
  color: var(--destructive);
}
.badge--forbidden {
  background: var(--forbidden-bg);
  border-color: var(--forbidden-border);
  color: var(--forbidden);
}

/* Tables */
.table-wrap {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}
th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
th {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
tbody tr:last-child td {
  border-bottom: 0;
}
tbody tr:hover td {
  background: var(--surface-hover);
}
tr.row-link {
  cursor: pointer;
}
td a {
  font-weight: 600;
  text-decoration: none;
}
td a:hover {
  text-decoration: underline;
}
td.actions-row,
td .actions-row {
  gap: 6px;
}
th.num,
.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.mono {
  font-family: var(--font-mono);
  font-size: 0.92em;
}
.muted {
  color: var(--ink-muted);
}
.nowrap {
  white-space: nowrap;
}

/* List toolbar: filters + search */
.list-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.list-toolbar .field {
  margin: 0;
}
.search-input {
  min-height: 40px;
  width: 260px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 15px;
  background: var(--surface);
}
.search-input:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(12, 10, 9, 0.12);
}
.load-more {
  display: flex;
  justify-content: center;
  padding: 12px 0 4px;
}

/* Totals */
.summary-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 0;
  font-variant-numeric: tabular-nums;
}
.summary-row--total {
  border-top: 1px solid var(--border);
  margin-top: 8px;
  padding-top: 12px;
  font-size: 20px;
  font-weight: 700;
}
.summary-aside {
  max-width: 340px;
  margin: 16px 0 0 auto;
}

/* Issue lines */
.line-row {
  display: grid;
  grid-template-columns: minmax(120px, 2fr) 64px 92px 64px minmax(120px, 1.2fr) 150px 40px;
  gap: 8px;
  align-items: end;
  padding-bottom: 4px;
  border-bottom: 1px dashed var(--border);
  margin-bottom: 12px;
}
.line-row .field {
  margin-bottom: 8px;
}
.line-row .field input,
.line-row .field select {
  padding: 10px;
  font-size: 15px;
}
.line-row .field label {
  font-size: 13px;
  white-space: nowrap;
}
.line-remove {
  min-height: var(--control-h);
  width: 40px;
  padding: 0;
  color: var(--ink-faint);
}
.issue-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.line-exemption {
  grid-column: 1 / -1;
}

.details-box {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  background: var(--surface-subtle);
}
.details-box summary {
  cursor: pointer;
  font-weight: 550;
  font-size: 14px;
  color: var(--ink-muted);
}
.details-box p {
  overflow-wrap: anywhere;
}

/* Collapsible panel (secondary sections of a document) */
details.card > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
details.card > summary::-webkit-details-marker {
  display: none;
}
details.card > summary::after {
  content: '▾';
  font-size: 20px;
  color: var(--ink-faint);
  transition: transform 0.15s ease;
}
details.card:not([open]) > summary::after {
  transform: rotate(-90deg);
}
details.card > summary h2 {
  margin: 0;
}
details.card[open] > summary {
  margin-bottom: 16px;
}

.modal-dialog {
  width: min(560px, calc(100vw - 32px));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 28px;
  background: var(--surface);
  color: var(--ink);
}
.modal-dialog::backdrop {
  background: rgba(12, 10, 9, 0.45);
}
.modal-dialog h2 {
  margin: 0 0 12px;
  font-size: 20px;
  font-weight: 650;
}
.modal-dialog p {
  margin: 6px 0;
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 12px 0;
  font-size: 15px;
  cursor: pointer;
}
.checkbox-row input {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  flex-shrink: 0;
  accent-color: var(--ink);
}

/* Toasts float above content and never shift the layout. */
.toast-region {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 60;
  width: min(440px, calc(100vw - 32px));
}
.toast-region .alert {
  margin: 0;
  box-shadow: var(--shadow-lg);
  font-weight: 550;
}

.mobile-only {
  display: none;
}

@media (max-width: 960px) {
  .grid-issue {
    grid-template-columns: 1fr;
  }
  .grid-issue > .card:last-child {
    position: static;
  }
  .line-row {
    grid-template-columns: 1fr 1fr 1fr;
  }
  .line-row .field:first-child {
    grid-column: 1 / -1;
  }
}

@media (max-width: 860px) {
  .mobile-only {
    display: inline-flex;
  }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100vh;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.16s ease;
  }
  .sidebar.is-open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(12, 10, 9, 0.35);
    z-index: 30;
  }
  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr;
  }
  .content-area {
    padding: 20px 16px;
  }
  .topbar {
    padding: 10px 16px;
  }
  .topbar-issuer .muted {
    display: none;
  }
  .page-header h1,
  #app-root > h1 {
    font-size: 24px;
  }
  .search-input {
    width: 100%;
  }
  .card {
    padding: 18px;
  }
}

.is-hidden {
  display: none !important;
}
.mt-xs {
  margin-top: 4px;
}
.mt-sm {
  margin-top: 8px;
}
.mt-md {
  margin-top: 16px;
}
.mt-lg {
  margin-top: 24px;
}
.mb-sm {
  margin: 0 0 12px;
}
.mb-md {
  margin: 0 0 16px;
}
.mb-lg {
  margin: 0 0 20px;
}
.actions-row--end {
  justify-content: flex-end;
}
.actions-row--between {
  justify-content: space-between;
}
.field--end {
  justify-content: flex-end;
}
.w-compact {
  width: 180px;
}

/* Folded creation forms */
.card--create > summary h2 {
  font-size: 16px;
}
.card--create:not([open]) {
  padding-top: 18px;
  padding-bottom: 18px;
}
td .actions-row {
  flex-wrap: nowrap;
}

.quick-panel {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
}
.quick-panel h3 {
  margin: 0 0 12px;
}

.combo {
  position: relative;
}
.combo-list {
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 320px;
  overflow-y: auto;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--surface, #fff);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgb(12 10 9 / 0.12);
}
.combo-option {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.combo-option[aria-selected='true'],
.combo-option:hover {
  background: var(--bg);
}
.combo-hint {
  color: var(--muted, #78716c);
  font-size: 14px;
  white-space: nowrap;
}
.combo-option--create .combo-label {
  color: var(--brand);
  font-weight: 600;
}
.combo-empty {
  padding: 10px 12px;
  color: var(--muted, #78716c);
}
.quick-panel[hidden],
.combo-list[hidden] {
  display: none;
}
.quick-panel form > .btn-ghost {
  margin-left: 8px;
}
