.app-header + main {
  flex: 1;
  padding-bottom: var(--app-footer-reserve, 4rem);
}

body {
  --app-footer-reserve: 4rem;
  --footer-version-reserve: 14rem;
  display: flex;
  flex-direction: column;
}

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 1.4rem clamp(1rem, 3vw, 2.5rem);
  background: #132238;
  color: #ffffff;
}

.app-header h1 {
  margin: 0;
  font-size: clamp(1.35rem, 3vw, 2rem);
}

.header-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.button {
  border: 0;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-weight: 750;
}

.button-primary {
  background: #f4b63e;
  color: #172033;
}

.button-secondary {
  background: #ffffff;
  color: #172033;
}

.btn-finalize-invoice {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.08rem;
  min-height: 3.4rem;
  padding: 0.55rem 1rem;
  border: 1px solid #198754;
  background: #198754;
  color: #ffffff;
  font-weight: 800;
  line-height: 1.25;
  text-align: center;
  white-space: normal;
}

.btn-finalize-invoice:hover {
  background: #157347;
  border-color: #157347;
}

.btn-finalize-invoice:focus-visible {
  outline: 3px solid rgba(25, 135, 84, 0.35);
  outline-offset: 2px;
}

.btn-finalize-invoice:disabled {
  border-color: #8bbfa4;
  background: #8bbfa4;
  color: #ffffff;
  cursor: not-allowed;
  opacity: 0.85;
}

.btn-cancel-invoice {
  border: 1px solid #c43a3a;
  background: #fff7f7;
  color: #9d2c2c;
  font-weight: 800;
}

.btn-cancel-invoice:hover {
  border-color: #9d2c2c;
  background: #ffe7e7;
}

.btn-cancel-invoice:focus-visible {
  outline: 3px solid rgba(196, 58, 58, 0.28);
  outline-offset: 2px;
}

.btn-cancel-invoice:disabled {
  border-color: #e1a6a6;
  background: #fff4f4;
  color: #b97878;
  cursor: not-allowed;
}

.active-invoice-status {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0 0 0.55rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid #d7deea;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 8px 18px rgba(23, 32, 51, 0.06);
}

.active-invoice-status[hidden] {
  display: none;
}

.active-invoice-number,
.archive-invoice-number {
  font-weight: 850;
  white-space: nowrap;
}

.invoice-status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 0.18rem 0.5rem;
  font-size: 0.72rem;
  font-weight: 850;
  line-height: 1.15;
  text-align: center;
  white-space: nowrap;
  vertical-align: middle;
}

.invoice-status-reserved {
  background: #fff7d6;
  color: #6e4b00;
}

.invoice-status-issued {
  background: #e9f8ef;
  color: #155c32;
}

.invoice-status-cancelled {
  background: #ffe8e8;
  color: #9d2c2c;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

.application-view {
  padding: clamp(1rem, 4vw, 2.5rem);
}

.landing-view {
  grid-area: nav;
}

.landing-nav {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  position: sticky;
  top: 1rem;
}

.nav-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 6.75rem;
  border: 1px solid #d8c9b5;
  border-left: 0.38rem solid var(--card-accent, #c58a1d);
  border-radius: 8px;
  padding: 1.2rem;
  background: #fffaf2;
  color: #172033;
  box-shadow: 0 12px 26px rgba(23, 32, 51, 0.08);
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.25;
  text-align: left;
}

.nav-card:hover {
  background: #ffffff;
  transform: translateY(-1px);
}

.nav-card[aria-current="page"] {
  border-color: var(--card-accent, #c58a1d);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(34, 93, 171, 0.14), 0 12px 26px rgba(23, 32, 51, 0.08);
}

.nav-card-amber {
  --card-accent: #c58a1d;
}

.nav-card-terracotta {
  --card-accent: #b85c38;
}

.nav-card-sage {
  --card-accent: #6f8f63;
}

.nav-card-teal {
  --card-accent: #287f83;
}

.workspace {
  display: grid;
  grid-template-areas:
    "nav preview";
  grid-template-columns: minmax(220px, 300px) minmax(0, 210mm);
  gap: 1.5rem;
  align-items: start;
  justify-content: center;
  max-width: calc(210mm + 300px + 1.5rem);
  margin: 0 auto;
}

.workspace:not([data-active-view="home"]) {
  grid-template-areas: "nav editor preview";
  grid-template-columns: minmax(220px, 300px) minmax(320px, 420px) minmax(0, 210mm);
  max-width: calc(210mm + 720px + 3rem);
}

.app-footer {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 2.8rem;
  padding: 0.35rem 0.75rem;
  border-top: 1px solid #d7deea;
  background: #ffffff;
  box-shadow: 0 -4px 14px rgba(23, 32, 51, 0.06);
  font-size: 0.78rem;
  line-height: 1.25;
  text-align: left;
}

.app-footer .app-footer-inner {
  gap: 0.15rem 0.8rem;
  width: 100%;
  max-width: 100%;
}

.app-footer p {
  margin: 0;
}

.footer-credits {
  min-width: 0;
  max-width: calc(100% - (var(--footer-version-reserve) * 2));
  text-align: center;
}

.footer-government {
  color: #172033;
  font-weight: 700;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.15rem 0.55rem;
  margin-top: 0;
  max-width: calc(100% - (var(--footer-version-reserve) * 2));
  text-align: center;
}

.app-footer a {
  color: #172033;
  font-weight: 600;
  text-decoration: none;
}

.app-footer a:hover {
  text-decoration: underline;
}

.app-version {
  position: absolute;
  top: 50%;
  right: 0;
  color: #7f8998;
  font-size: 0.68rem;
  line-height: 1.2;
  text-align: right;
  transform: translateY(-50%);
  overflow-wrap: anywhere;
}

.editor-panel,
.preview-panel {
  min-width: 0;
}

.preview-panel {
  grid-area: preview;
}

.editor-panel {
  grid-area: editor;
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  overflow: auto;
  padding: 1.25rem;
  border: 1px solid #d7deea;
  border-radius: 12px;
  background: #ffffff;
  box-shadow: 0 12px 35px rgba(23, 32, 51, 0.08);
}

.editor-panel-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 0.75rem;
}

.editor-panel-header h2 {
  margin-bottom: 0.5rem;
}

.panel-close-button {
  width: 2rem;
  height: 2rem;
  border: 1px solid #c7cfdb;
  border-radius: 8px;
  background: #ffffff;
  color: #172033;
  font-weight: 800;
}

.panel-help {
  color: #526078;
}

.invoice-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 0.75rem;
  margin: 0 0 0.8rem;
  padding: 0.8rem;
  border: 1px solid #d7deea;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 10px 24px rgba(23, 32, 51, 0.08);
}

.invoice-actions .button {
  flex: 1 1 9rem;
  min-width: min(100%, 9rem);
}

.invoice-actions .btn-finalize-invoice {
  flex: 1.5 1 18rem;
  min-width: min(100%, 18rem);
}

.workspace[data-active-view="customers"] form,
.workspace[data-active-view="customers"] .invoice-archive-panel,
.workspace[data-active-view="archive"] form,
.workspace[data-active-view="archive"] .customers-panel {
  display: none;
}

.workspace[data-active-view="customers"] .editor-panel > h2,
.workspace[data-active-view="customers"] .editor-panel > .panel-help,
.workspace[data-active-view="archive"] .editor-panel > h2,
.workspace[data-active-view="archive"] .editor-panel > .panel-help {
  display: none;
}

.numbering-panel,
.numbering-field,
.workspace[data-active-view="numbering"] fieldset,
.workspace[data-active-view="debtor"] .numbering-panel,
.workspace[data-active-view="debtor"] .numbering-field,
.workspace[data-active-view="debtor"] .issue-details-fieldset,
.workspace[data-active-view="debtor"] .charge-fieldset,
.workspace[data-active-view="debtor"] .signature-account-fieldset,
.workspace[data-active-view="service"] .numbering-panel,
.workspace[data-active-view="service"] .invoice-only-field,
.workspace[data-active-view="charge"] .numbering-panel,
.workspace[data-active-view="charge"] .numbering-field,
.workspace[data-active-view="charge"] .issue-details-fieldset,
.workspace[data-active-view="charge"] .debtor-fieldset,
.workspace[data-active-view="charge"] .signature-account-fieldset {
  display: none;
}

.workspace[data-active-view="numbering"] .numbering-panel,
.workspace[data-active-view="numbering"] .numbering-field,
.workspace[data-active-view="numbering"] .issue-details-fieldset {
  display: block;
}

.workspace[data-active-view="numbering"] .template-controls,
.workspace[data-active-view="numbering"] .service-setting-field,
.workspace[data-active-view="debtor"] .service-setting-field,
.workspace[data-active-view="debtor"] .charge-fieldset,
.workspace[data-active-view="debtor"] .signature-account-fieldset {
  display: none;
}

.workspace[data-active-view="numbering"] .customers-panel,
.workspace[data-active-view="numbering"] .invoice-archive-panel,
.workspace[data-active-view="debtor"] .customers-panel,
.workspace[data-active-view="debtor"] .invoice-archive-panel,
.workspace[data-active-view="service"] .customers-panel,
.workspace[data-active-view="service"] .invoice-archive-panel,
.workspace[data-active-view="charge"] .customers-panel,
.workspace[data-active-view="charge"] .invoice-archive-panel,
.workspace[data-active-view="home"] .editor-panel {
  display: none;
}

.workspace[data-active-view="service"] .debtor-fieldset,
.workspace[data-active-view="service"] .charge-fieldset {
  display: none;
}

.numbering-summary {
  display: grid;
  gap: 0.75rem;
  margin: 0 0 1rem;
}

.numbering-summary div,
.invoice-number-card {
  display: block;
  padding: 0.85rem;
  border: 1px solid #d7deea;
  border-radius: 8px;
  background: #fffaf2;
}

.numbering-summary dt,
.invoice-number-label {
  display: block;
  margin-bottom: 0.3rem;
  color: #4d5b73;
  font-size: 0.82rem;
  font-weight: 700;
}

.numbering-summary dd,
.invoice-number-card input {
  margin: 0;
  color: #172033;
  font-size: 1.4rem;
  font-weight: 850;
  letter-spacing: 0;
}

.numbering-warning {
  color: #8a1f11;
  font-weight: 700;
}

.invoice-number-card {
  margin: 0 0 1rem;
}

.invoice-number-card input {
  display: block;
  width: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.invoice-number-card input:focus {
  outline: 2px solid rgba(28, 83, 142, 0.32);
  outline-offset: 3px;
}

.invoice-number-card input::placeholder {
  color: #7b879a;
  font-size: 1rem;
  font-weight: 700;
}

.invoice-number-card-manual {
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.invoice-number-card-manual .invoice-number-label {
  margin-bottom: 0.35rem;
  color: #172033;
  font-size: 0.88rem;
  font-weight: 700;
  line-height: normal;
}

body .invoice-number-card-manual input:not([readonly]) {
  width: 100%;
  margin: 0;
  padding: 0.68rem 0.75rem;
  border: 1px solid #b7c1d1;
  border-radius: 8px;
  background: #ffffff;
  color: #172033;
  font-size: 0.88rem;
  font-weight: 500;
  line-height: normal;
}

.invoice-number-card-manual input:not([readonly]):focus {
  outline: 3px solid rgba(34, 93, 171, 0.2);
  outline-offset: 2px;
  border-color: #225dab;
}

.invoice-number-card-manual input:not([readonly])::placeholder {
  color: #757575;
  font: inherit;
  opacity: 1;
}

fieldset {
  margin: 0 0 1rem;
  border: 1px solid #d7deea;
  border-radius: 10px;
  padding: 1rem;
}

legend {
  padding: 0 0.4rem;
  font-weight: 800;
}

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

.field {
  display: block;
  min-width: 0;
  font-size: 0.88rem;
  font-weight: 700;
}

.numbering-mode-field,
.numbering-mode-field > select {
  font-size: 0.95rem;
}

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

.issue-date-field {
  grid-column: 1 / -1;
}

.field input,
.field textarea,
.field > select {
  margin-top: 0.35rem;
  font-weight: 500;
}

#invoice-form :where(input:not([readonly]):not(:disabled), textarea:not([readonly]):not(:disabled), select:not(:disabled)) {
  background-color: #ffffff;
}

#invoice-form :where(input[readonly], textarea[readonly], input:disabled, textarea:disabled, select:disabled) {
  background-color: #f2f4f7;
}

#invoice-form :where(input:disabled, textarea:disabled, select:disabled) {
  color: #526078;
  opacity: 1;
  -webkit-text-fill-color: #526078;
}

.calculated-field input[readonly] {
  border-color: #cbd5e1;
  background: #f2f5f8;
  color: #172033;
  font-weight: 750;
  cursor: default;
}

.date-entry {
  position: relative;
  display: block;
  margin-top: 0.35rem;
}

.date-entry input {
  margin-top: 0;
}

.date-entry input[id] {
  width: 100%;
}

.date-picker-proxy {
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.template-controls {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.4rem;
}

.template-select {
  flex: 1 1 auto;
  min-width: 0;
  width: auto;
}

.template-select,
.template-button {
  min-height: 2.15rem;
  border: 1px solid #c7cfdb;
  border-radius: 6px;
  padding: 0.35rem 0.5rem;
  font-size: 0.76rem;
}

.date-picker-button {
  width: 100%;
  background: #ffffff;
  color: inherit;
  font-weight: 500;
  text-align: left;
}

.template-button {
  width: auto;
  background: #edf3fb;
  color: #1f4f8b;
  font-weight: 750;
}

.template-button-danger {
  background: #fff0f0;
  color: #9d2c2c;
}

.template-action-button {
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  width: 2.15rem;
  min-width: 2.15rem;
  padding: 0;
  border-radius: 6px;
  font-size: 1rem;
  line-height: 1;
}

.template-action-button-save {
  border-color: #157347;
  background: #198754;
  color: #ffffff;
}

.template-action-button-delete {
  border-color: #b02a37;
  background: #dc3545;
  color: #ffffff;
}

.template-action-button-save:hover:not(:disabled) {
  border-color: #146c43;
  background: #157347;
}

.template-action-button-delete:hover:not(:disabled) {
  border-color: #a52834;
  background: #bb2d3b;
}

.template-action-button:focus-visible {
  outline: 3px solid #1d4ed8;
  outline-offset: 2px;
}

.template-action-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.feature-panel {
  margin: 0 0 1rem;
  border: 1px solid #d7deea;
  border-radius: 10px;
  padding: 1rem;
  background: #fbfdff;
}

.feature-panel h3 {
  margin: 0 0 0.35rem;
}

.feature-help {
  margin: 0 0 0.8rem;
  color: #526078;
  font-size: 0.86rem;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.feature-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.75rem;
}

.archive-filters {
  align-items: end;
  margin: 0.75rem 0;
}

.invoice-archive-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 0 0 0.75rem;
}

.table-scroll {
  max-width: 100%;
  overflow-x: auto;
}

.records-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.records-table th,
.records-table td {
  border: 1px solid #d7deea;
  padding: 0.4rem;
  vertical-align: top;
}

.records-table th {
  background: #edf3fb;
  text-align: left;
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  min-width: 12rem;
}

.archive-detail {
  margin-top: 0.75rem;
  padding: 0.7rem;
  border: 1px solid #d7deea;
  border-radius: 8px;
  background: #ffffff;
  font-size: 0.84rem;
}

.archive-detail:empty {
  display: none;
}

.archive-detail dl {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 0.25rem 0.7rem;
  margin: 0.5rem 0 0;
}

.archive-detail dt {
  font-weight: 800;
}

.archive-detail dd {
  margin: 0;
}

.preview-panel > h2 {
  display: none;
}

.settings-dialog {
  width: min(92vw, 28rem);
  border: 1px solid #d7c4aa;
  border-radius: 8px;
  padding: 0;
  color: #172033;
  background: #fffaf2;
  box-shadow: 0 24px 60px rgba(19, 34, 56, 0.28);
}

.settings-dialog::backdrop {
  background: rgba(19, 34, 56, 0.55);
}

.settings-dialog form {
  padding: 1.25rem;
}

.settings-form-grid {
  display: grid;
  gap: 0.85rem;
  margin: 0 0 1rem;
}

.settings-field {
  display: grid;
  gap: 0.35rem;
  font-weight: 800;
}

.settings-dialog h2 {
  margin: 0 0 0.5rem;
}

.settings-dialog p {
  color: #526078;
}

body.page-font-compact {
  font-size: 0.94rem;
}

body.page-font-large {
  font-size: 1.1rem;
}

body.page-font-serif {
  font-family: Georgia, "Times New Roman", serif;
}

body.page-font-arial {
  font-family: Arial, Helvetica, sans-serif;
}

body.page-theme-teal {
  background: #eef6f5;
  color: #102f35;
}

body.page-theme-teal .app-header {
  background: #0f3f46;
}

body.page-theme-teal .nav-card {
  border-color: #bdd6d4;
  background: #f7ffff;
  color: #102f35;
}

body.page-theme-teal .editor-panel,
body.page-theme-teal .preview-panel,
body.page-theme-teal .customers-panel,
body.page-theme-teal .invoice-archive-panel,
body.page-theme-teal .settings-dialog {
  background: #fbffff;
}

body.page-theme-sage {
  background: #f1f5ec;
  color: #1f2d21;
}

body.page-theme-sage .app-header {
  background: #263d2c;
}

body.page-theme-sage .nav-card {
  border-color: #c9d8bf;
  background: #fbfff7;
  color: #1f2d21;
}

body.page-theme-sage .editor-panel,
body.page-theme-sage .preview-panel,
body.page-theme-sage .customers-panel,
body.page-theme-sage .invoice-archive-panel,
body.page-theme-sage .settings-dialog {
  background: #fdfff9;
}

@media (max-width: 1120px) {
  .workspace {
    grid-template-columns: minmax(180px, 240px) minmax(0, 1fr);
    max-width: none;
  }

  .workspace:not([data-active-view="home"]) {
    grid-template-columns: minmax(170px, 220px) minmax(280px, 34vw) minmax(520px, 1fr);
    overflow-x: auto;
  }
}

@media (max-width: 680px) {
  body {
    --app-footer-reserve: 6rem;
    --footer-version-reserve: 8rem;
  }

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

  .app-header {
    display: grid;
  }

  .landing-view,
  .application-view {
    padding: 1rem;
  }

  .workspace {
    grid-template-columns: minmax(140px, 38vw) minmax(0, 1fr);
    gap: 0.75rem;
    overflow-x: auto;
  }

  .workspace:not([data-active-view="home"]) {
    grid-template-columns: minmax(140px, 38vw) minmax(280px, 72vw) minmax(520px, 1fr);
  }

  .nav-card {
    min-height: 5.75rem;
    padding: 0.85rem;
    font-size: 0.85rem;
  }

  .invoice-actions {
    gap: 0.4rem;
    padding: 0.45rem;
  }

  .invoice-actions .button {
    padding: 0.55rem 0.35rem;
    font-size: 0.78rem;
  }

  .invoice-actions .btn-finalize-invoice {
    flex-basis: 100%;
    min-height: 3.4rem;
    padding: 0.55rem 0.75rem;
    font-size: 0.85rem;
  }

  .app-footer {
    min-height: 3.4rem;
    padding: 0.25rem 0.6rem;
  }

  .app-footer .app-footer-inner {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: 0.1rem 0.45rem;
  }

  .footer-credits {
    display: block;
    grid-column: 1 / -1;
    justify-self: center;
    max-width: 100%;
  }

  .app-footer a,
  .app-footer p {
    font-size: 0.68rem;
    line-height: 1.2;
  }

  .footer-credits p,
  .footer-links a {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .footer-developer-line::before {
    content: "";
    margin: 0;
  }

  .footer-links {
    display: grid;
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.08rem 0.4rem;
    max-width: 100%;
    width: 100%;
  }

  .footer-links a {
    text-align: center;
  }

  .app-version {
    position: static;
    grid-column: 1 / -1;
    justify-self: end;
    max-width: 8rem;
    font-size: 0.56rem;
    transform: none;
  }

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

  .feature-grid,
  .archive-detail dl {
    grid-template-columns: 1fr;
  }
}
.release-status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #ffd77d;
  border-radius: 999px;
  padding: 0.32rem 0.68rem;
  color: #172033;
  background: #f4b63e;
  font-size: 0.78rem;
  font-weight: 850;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
}
