:root {
  color-scheme: light;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  --ink: #172033;
  --muted: #657083;
  --line: #dbe3ee;
  --soft: #f6f8fb;
  --paper: #ffffff;
  --accent: #006c67;
  --accent-2: #b44d2e;
  --accent-soft: #dff3ef;
  --shadow: 0 18px 55px rgba(23, 32, 51, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #eef3f7;
  color: var(--ink);
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

body:not(.is-authenticated) {
  grid-template-columns: 1fr;
}

body:not(.is-authenticated) .sidebar,
body:not(.is-authenticated) .app-shell {
  display: none;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  border-radius: 8px;
  min-height: 38px;
  padding: 0 14px;
  cursor: pointer;
}

button:hover {
  border-color: #9fb0c3;
}

.primary-button {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.auth-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(238, 243, 247, 0.92)),
    #eef3f7;
}

body.is-authenticated .auth-gate {
  display: none;
}

.auth-card {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  background: var(--paper);
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

.auth-brand strong,
.auth-brand span {
  display: block;
}

.auth-brand strong {
  font-size: 22px;
}

.auth-brand span {
  color: var(--muted);
  margin-top: 2px;
}

.auth-error {
  min-height: 18px;
  margin: 0;
  color: #a33120;
  font-size: 13px;
}

.sidebar {
  background: #142237;
  color: #fff;
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #f2be5c;
  color: #142237;
  font-weight: 900;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  margin-top: 3px;
  color: #aebbd0;
  font-size: 13px;
}

.workspace-card {
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.07);
  display: grid;
  gap: 4px;
}

.workspace-card span,
.workspace-card small {
  color: #aebbd0;
  font-size: 12px;
}

.workspace-card strong {
  color: #fff;
  font-size: 15px;
}

.workspace-card select {
  min-height: 36px;
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.workspace-card option {
  color: var(--ink);
}

nav {
  display: grid;
  gap: 8px;
}

.nav-button {
  width: 100%;
  color: #d9e2ef;
  background: transparent;
  border-color: transparent;
  text-align: left;
  justify-content: flex-start;
}

.nav-button.active,
.nav-button:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.app-shell {
  min-width: 0;
  padding: 24px;
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  letter-spacing: 0;
  font-weight: 800;
  text-transform: uppercase;
}

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

h1 {
  font-size: 30px;
}

h2 {
  font-size: 17px;
}

.actions,
.inline-actions,
.dialog-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.user-chip {
  max-width: 220px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 11px;
  background: var(--paper);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.compact-select {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.compact-select select {
  width: auto;
  min-width: 112px;
  min-height: 36px;
}

.output-language select {
  min-width: 104px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.report-hero {
  min-height: 112px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 16px;
  padding: 20px;
  background:
    linear-gradient(90deg, rgba(0, 108, 103, 0.12), rgba(180, 77, 46, 0.08)),
    #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  box-shadow: 0 8px 20px rgba(23, 32, 51, 0.05);
}

.report-hero h2 {
  font-size: 25px;
}

.total-strip {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.total-chip {
  min-width: 140px;
  border: 1px solid rgba(0, 108, 103, 0.22);
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.76);
}

.total-chip span,
.total-chip strong {
  display: block;
}

.total-chip span {
  color: var(--muted);
  font-size: 12px;
}

.total-chip strong {
  margin-top: 3px;
  font-size: 18px;
}

.metric {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 8px 20px rgba(23, 32, 51, 0.05);
}

.metric span {
  color: var(--muted);
  display: block;
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

.split-layout,
.documents-layout,
.issuer-layout,
.report-grid {
  display: grid;
  gap: 16px;
}

.split-layout {
  grid-template-columns: minmax(0, 1.7fr) minmax(280px, 0.8fr);
}

.documents-layout {
  grid-template-columns: minmax(360px, 0.95fr) minmax(0, 1.25fr);
}

.issuer-layout {
  grid-template-columns: minmax(260px, 0.55fr) minmax(0, 1.45fr);
}

.report-grid {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  margin-bottom: 16px;
}

.report-panel {
  margin-top: 16px;
}

.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-header {
  min-height: 58px;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}

.toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 14px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
}

input,
select {
  min-height: 40px;
  padding: 0 12px;
}

textarea {
  min-height: 84px;
  resize: vertical;
  padding: 10px 12px;
}

.toolbar select {
  max-width: 180px;
}

.table-wrap {
  overflow: auto;
}

.table-wrap.tall {
  max-height: calc(100vh - 220px);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f7f9fc;
  color: #44546a;
  text-align: left;
  font-size: 12px;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: #f7fbfa;
}

.numeric {
  text-align: right;
  white-space: nowrap;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 800;
  background: var(--accent-soft);
  color: var(--accent);
}

.status-pill.billed {
  background: #edf1f7;
  color: #526174;
}

.status-list {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.status-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.document-detail {
  padding: 16px;
  display: grid;
  gap: 14px;
}

.company-list {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.company-row {
  text-align: left;
  min-height: 54px;
  display: grid;
  align-content: center;
  background: #fff;
}

.company-row.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.company-row strong,
.company-row span {
  display: block;
}

.company-row span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.company-editor {
  padding: 16px;
  display: grid;
  gap: 16px;
}

.brand-preview {
  min-height: 104px;
  border: 1px dashed #aac0cf;
  border-radius: 8px;
  background: #f8fbfd;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.brand-preview img {
  max-width: min(520px, 92%);
  max-height: 88px;
  object-fit: contain;
}

.form-grid,
.asset-grid {
  display: grid;
  gap: 12px;
}

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

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

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

.empty-state {
  min-height: 220px;
  place-items: center;
  color: var(--muted);
}

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

.detail-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--soft);
}

.detail-box span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

dialog {
  border: 0;
  border-radius: 10px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.38);
}

.dialog-card {
  width: min(460px, calc(100vw - 28px));
  padding: 20px;
  display: grid;
  gap: 14px;
}

.wide-dialog {
  width: min(760px, calc(100vw - 28px));
}

#payment-preview-dialog .wide-dialog {
  width: min(1188px, calc(100vw - 36px));
  max-height: calc(100vh - 36px);
  overflow: auto;
}

#payment-preview {
  display: block;
  padding: 0;
  overflow: auto;
}

#payment-preview .payment-template {
  margin: 0 auto;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.checkbox-row {
  display: flex;
  align-items: center;
  color: var(--ink);
}

.checkbox-row input {
  width: auto;
  min-height: 0;
}

.muted {
  color: var(--muted);
  margin: 0;
  font-size: 13px;
}

.danger-button {
  border-color: #bd5a48;
  color: #9f2f1e;
}

.status-pill.draft {
  background: #edf1f7;
  color: #526174;
}

.status-pill.issued {
  background: #dff3ef;
  color: #006c67;
}

.status-pill.cancelled {
  background: #f9e4df;
  color: #9f2f1e;
}

.status-pill.paid {
  background: #e9f3df;
  color: #3f7021;
}

.payment-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.issuer-manager {
  display: grid;
  grid-template-columns: minmax(220px, 0.65fr) minmax(0, 1.35fr);
  gap: 16px;
}

.issuer-manager .company-list {
  max-height: 360px;
  overflow: auto;
  padding: 0;
}

.audit-table tbody tr {
  cursor: default;
}

.audit-summary {
  max-width: 520px;
  color: var(--muted);
  line-height: 1.4;
}

.pdf-stage {
  position: fixed;
  left: -10000px;
  top: 0;
  width: 1120px;
  background: #fff;
  padding: 0;
  z-index: -1;
}

.payment-template {
  width: 1120px;
  min-height: 780px;
  padding: 26px 28px;
  background: #fff;
  color: #111827;
  font-family: Arial, "Segoe UI", sans-serif;
  font-size: 13px;
}

.payment-template.cancelled {
  position: relative;
}

.payment-template.cancelled::after {
  content: "CANCELLED";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  transform: rotate(-18deg);
  color: rgba(159, 47, 30, 0.14);
  font-size: 110px;
  font-weight: 900;
  pointer-events: none;
}

.payment-template-masthead {
  position: relative;
  min-height: 52px;
  padding: 7px 0 8px;
  border-bottom: 1px solid #222;
}

.payment-template-company {
  font-weight: 800;
}

.payment-template-name {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 9px;
  text-align: center;
  font-size: 17px;
  font-weight: 900;
}

.payment-template-no,
.payment-template-date {
  position: absolute;
  right: 0;
  text-align: right;
}

.payment-template-no {
  top: 7px;
}

.payment-template-date {
  bottom: 9px;
}

.payment-template table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 12px;
}

.payment-template .summary-col {
  width: 135px;
}

.payment-template .amount-col {
  width: 165px;
}

.payment-template .currency-col {
  width: 72px;
}

.payment-template .inv-label-col {
  width: 98px;
}

.payment-template .date-col {
  width: 136px;
}

.payment-template .invoice-label-col {
  width: 92px;
}

.payment-template .invoice-col {
  width: auto;
}

.payment-template th,
.payment-template td {
  position: static;
  border: 1px solid #222;
  height: 28px;
  padding: 5px 7px;
  background: #fff;
  color: #111827;
  vertical-align: middle;
}

.payment-template th {
  font-size: 10px;
  text-align: left;
  font-weight: 800;
}

.payment-template .summary-label,
.payment-template .sub-label,
.payment-template .row-label {
  background: #f5f5f5;
}

.payment-template .summary-value,
.payment-template .summary-total {
  font-size: 15px;
  line-height: 1.2;
}

.payment-template .numeric {
  text-align: right;
}

.payment-template .amount-cell {
  font-size: 13px;
}

.payment-template .currency-cell {
  text-align: center;
  font-weight: 800;
}

.payment-template .date-cell {
  text-align: center;
}

.payment-template .invoice-cell {
  text-align: center;
}

.payment-template .description-cell {
  width: auto;
}

.payment-template .sign-title {
  text-align: center;
  font-size: 10px;
  font-weight: 800;
}

.payment-template .sign-box {
  height: 82px;
}

.payment-template-note {
  margin: 10px 0 0;
  color: #44546a;
  font-size: 10px;
}

#toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 360px;
  background: #142237;
  color: #fff;
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: 0.18s ease;
}

#toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 980px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
  }

  .workspace-card {
    min-width: 210px;
  }

  nav {
    display: flex;
  }

  .nav-button {
    white-space: nowrap;
  }

  .metric-grid,
  .split-layout,
  .documents-layout,
  .issuer-layout,
  .issuer-manager,
  .report-grid,
  .form-grid,
  .asset-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }
}
