:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #637083;
  --line: #d9e0ea;
  --accent: #1f6feb;
  --accent-dark: #175bc7;
  --ok: #15803d;
  --warn: #a16207;
  --danger: #b42318;
  --soft-blue: #eaf2ff;
  --soft-green: #ecfdf3;
  --soft-yellow: #fffbeb;
  --soft-red: #fff1f0;
}

* {
  box-sizing: border-box;
}

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

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

button {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  min-height: 40px;
  padding: 0 14px;
}

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

button:disabled {
  background: #a6b4c8;
  cursor: not-allowed;
}

button.secondary {
  background: #eef3f8;
  color: var(--text);
  border: 1px solid var(--line);
}

button.secondary:hover {
  background: #dfe8f2;
}

.shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

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

h1,
h2,
h3,
p {
  margin: 0;
}

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

h2 {
  font-size: 19px;
}

h3 {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 8px;
  text-transform: uppercase;
}

.topbar p {
  color: var(--muted);
  margin-top: 6px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  margin-bottom: 14px;
}

.status,
.badge {
  border-radius: 999px;
  padding: 6px 10px;
  background: var(--soft-blue);
  color: #174ea6;
  font-size: 13px;
  white-space: nowrap;
}

.top-status {
  display: grid;
  justify-items: end;
  gap: 8px;
}

.badge.success {
  background: var(--soft-green);
  color: var(--ok);
}

.badge.configured,
.badge.active {
  background: var(--soft-green);
  color: var(--ok);
}

.badge.not-configured,
.badge.provisioning {
  background: var(--soft-yellow);
  color: var(--warn);
}

.badge.failed {
  background: var(--soft-red);
  color: var(--danger);
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.controls-row,
.actions,
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.auth-grid {
  display: grid;
  grid-template-columns: minmax(220px, 360px) auto minmax(120px, 180px) auto;
  align-items: end;
  gap: 12px;
  margin-top: 16px;
}

.auth-message {
  margin-top: 12px;
}

.mode-tabs {
  display: inline-flex;
  gap: 4px;
  margin: 0 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px;
  background: white;
}

.tab-button {
  min-height: 34px;
  background: transparent;
  color: var(--muted);
}

.tab-button:hover,
.tab-button.active {
  background: var(--soft-blue);
  color: #174ea6;
}

.controls-row {
  justify-content: flex-start;
  margin-bottom: 14px;
}

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

select,
input,
textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--text);
}

select,
input {
  min-height: 38px;
  padding: 0 10px;
}

.dropzone {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 190px;
  border: 2px dashed #9fb4d0;
  border-radius: 8px;
  background: #fbfdff;
  text-align: center;
  transition:
    border-color 120ms ease,
    background 120ms ease;
}

.dropzone.active {
  background: var(--soft-blue);
  border-color: var(--accent);
}

.dropzone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
}

.dropzone-copy {
  display: grid;
  gap: 8px;
  padding: 24px;
}

.dropzone-copy strong {
  font-size: 20px;
}

.dropzone-copy span {
  color: var(--muted);
  max-width: 560px;
}

.actions {
  margin-top: 14px;
  justify-content: flex-start;
}

.batch-panel {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.progress-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.progress-bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5edf6;
}

.progress-bar span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 160ms ease;
}

.invoice-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.invoice-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 260px;
  min-height: 34px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: white;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.invoice-tab:hover,
.invoice-tab.active {
  background: var(--soft-blue);
  color: #174ea6;
}

.invoice-tab span {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 2px 6px;
  background: #eef3f8;
  color: var(--muted);
  font-size: 11px;
}

.invoice-tab.failed span,
.invoice-tab.submission_failed span {
  background: var(--soft-red);
  color: var(--danger);
}

.invoice-tab.submitted span,
.invoice-tab.created span,
.invoice-tab.reviewed span {
  background: var(--soft-green);
  color: var(--ok);
}

.field-columns,
.review-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-top: 16px;
}

.field-list {
  display: grid;
  gap: 8px;
}

.field-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fbfdff;
}

.field-pill code {
  color: var(--accent);
}

.editor-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.editor-grid label {
  color: var(--text);
}

.editor-grid input,
.editor-grid select {
  width: 100%;
}

.review-workspace {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  gap: 18px;
  margin-top: 16px;
  align-items: start;
}

.compact-title {
  align-items: center;
}

.compact-title h3 {
  margin-bottom: 0;
}

.source-preview-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfdff;
}

.source-thumb {
  display: block;
  width: 100%;
  height: 320px;
  margin-top: 12px;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--text);
}

.source-thumb:hover {
  background: white;
  border-color: var(--accent);
}

.source-preview-media,
.source-preview-media img,
.source-preview-media iframe {
  width: 100%;
  height: 100%;
}

.source-preview-media {
  background: #eef3f8;
}

.source-preview-media img {
  display: block;
  object-fit: contain;
}

.source-preview-media iframe {
  display: block;
  border: 0;
  pointer-events: none;
}

.pdf-thumb {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  background:
    linear-gradient(135deg, transparent 0 82%, #d8e2ee 82% 100%),
    white;
  color: #b42318;
  font-size: 34px;
  font-weight: 800;
  letter-spacing: 0;
}

.source-title {
  margin-top: 10px;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.invoice-paper {
  min-width: 0;
  border: 1px solid #cfd7e3;
  border-radius: 6px;
  background: white;
  box-shadow: 0 12px 28px rgba(23, 32, 51, 0.07);
}

.invoice-paper-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px;
  border-bottom: 2px solid var(--text);
}

.invoice-kicker {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.invoice-paper-header h2 {
  font-size: 24px;
}

.invoice-paper-header p {
  margin-top: 6px;
}

.total-summary {
  display: grid;
  align-content: start;
  justify-items: end;
  gap: 4px;
  min-width: 170px;
  text-align: right;
}

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

.total-summary strong {
  font-size: 28px;
  line-height: 1.05;
}

.invoice-section {
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
}

.invoice-section:last-child {
  border-bottom: 0;
}

.invoice-fields {
  grid-template-columns: repeat(3, minmax(130px, 1fr));
}

.line-editor {
  overflow-x: auto;
}

.item-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
}

.item-table th,
.item-table td {
  border-bottom: 1px solid var(--line);
  padding: 8px 6px;
  text-align: left;
  vertical-align: top;
}

.item-table th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.item-table input,
.item-table select {
  width: 100%;
  min-width: 86px;
}

.amount-heading,
.line-amount {
  position: sticky;
  right: 0;
  z-index: 1;
  background: white;
  box-shadow: -8px 0 10px rgba(255, 255, 255, 0.88);
  text-align: right !important;
  white-space: nowrap;
}

.line-amount {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  padding-top: 17px !important;
}

.json-details {
  margin-top: 16px;
}

.json-details summary {
  cursor: pointer;
  color: var(--accent);
}

textarea {
  width: 100%;
  min-height: 260px;
  margin: 10px 0;
  padding: 12px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.4;
}

.warnings,
.missing,
.diagnostics {
  border-radius: 6px;
}

.warnings,
.missing {
  padding: 12px;
  margin-top: 14px;
}

.warnings {
  background: var(--soft-yellow);
  color: var(--warn);
}

.missing {
  background: var(--soft-red);
  color: var(--danger);
}

.diagnostics {
  border-color: #f0b4ad;
  background: #fffafa;
}

.diagnostics-summary {
  margin-top: 12px;
  color: var(--danger);
}

.diagnostics-summary ul {
  margin: 8px 0 0;
  padding-left: 20px;
}

.diagnostics-summary code {
  color: var(--danger);
  background: #ffe5e2;
  border-radius: 4px;
  padding: 1px 4px;
}

.diagnostics-block {
  margin-top: 10px;
}

.diagnostics pre {
  margin-top: 12px;
}

.strong-actions {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.submit-toggle {
  display: inline-flex;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.submit-toggle input {
  min-height: auto;
  width: 16px;
  height: 16px;
  padding: 0;
}

.submission-progress {
  margin-top: 10px;
  border-radius: 6px;
  padding: 10px 12px;
  background: var(--soft-blue);
  color: #174ea6;
}

.submission-progress span {
  margin-left: 8px;
  overflow-wrap: anywhere;
}

pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: #111827;
  color: #e5e7eb;
  border-radius: 8px;
  padding: 14px;
  overflow: auto;
}

.source-modal {
  width: min(1100px, calc(100vw - 32px));
  height: min(820px, calc(100vh - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--text);
}

.source-modal::backdrop {
  background: rgba(17, 24, 39, 0.62);
}

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

.source-modal-body {
  height: calc(100% - 65px);
  background: #eef3f8;
}

.source-modal-body img,
.source-modal-body iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

.source-modal-body img {
  display: block;
  object-fit: contain;
}

.source-placeholder {
  display: grid;
  height: 100%;
  place-items: center;
  color: var(--muted);
}

.settings-copy {
  margin-top: 8px;
}

.settings-form,
.tenant-info-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.settings-form input,
.settings-form select {
  width: 100%;
}

.info-block {
  display: grid;
  gap: 4px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #fbfdff;
}

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

.info-block strong {
  overflow-wrap: anywhere;
  font-size: 14px;
}

.tenant-events {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.tenant-event-row {
  display: grid;
  grid-template-columns: minmax(190px, 0.8fr) minmax(220px, 1.4fr) minmax(185px, auto);
  gap: 12px 18px;
  align-items: start;
  border-bottom: 1px solid var(--line);
  padding: 8px 0;
  font-size: 13px;
}

.tenant-event-row strong,
.tenant-event-row span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.tenant-event-row time {
  justify-self: end;
  color: var(--muted);
}

@media (max-width: 860px) {
  .topbar,
  .top-status,
  .controls-row,
  .progress-line,
  .section-title {
    align-items: stretch;
    flex-direction: column;
  }

  .top-status {
    justify-items: stretch;
  }

  .status {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .auth-grid {
    grid-template-columns: 1fr;
  }

  .field-columns,
  .review-grid,
  .editor-grid,
  .review-workspace,
  .settings-form,
  .tenant-info-grid,
  .tenant-event-row {
    grid-template-columns: 1fr;
  }

  .tenant-event-row {
    gap: 4px;
  }

  .tenant-event-row time {
    justify-self: start;
  }

  .invoice-paper-header {
    display: grid;
  }

  .total-summary {
    justify-items: start;
    text-align: left;
  }

  .invoice-fields {
    grid-template-columns: 1fr;
  }

  .source-thumb {
    height: 220px;
  }
}
