:root {
  --cps-teal: #15a9a0;
  --cps-teal-dark: #128a83;
  --cps-bg-page: #e8eaea;
  --cps-bar: #f4f5f5;
  --cps-border: #d9dcdd;
  --cps-text: #2c3133;
  --cps-muted: #6b7378;
  --cps-ribbon: #1e6bca;
  --cps-table-head: #4a4f52;
  --cps-danger-bg: #fde8e8;
  --cps-danger-text: #9b1c1c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--cps-text);
  background: var(--cps-bg-page);
  min-height: 100vh;
}

.site-header {
  background: var(--cps-teal);
  color: #fff;
  padding: 0.85rem 1.5rem;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
}

.app-state {
  max-width: 36rem;
  margin: 2rem auto;
  padding: 1.25rem 1.5rem;
  border-radius: 4px;
  border: 1px solid var(--cps-border);
  background: #fff;
}

.app-state--error {
  background: var(--cps-danger-bg);
  border-color: #f5c2c2;
  color: var(--cps-danger-text);
  padding: 1.75rem 2rem;
}

.error-inner {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
}

.error-icon {
  opacity: 0.6;
  margin-bottom: 0.25rem;
}

.error-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1.3;
}

.error-body {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.6;
}

.error-hint {
  margin: 0.5rem 0 0;
  font-size: 0.875rem;
  opacity: 0.75;
  line-height: 1.5;
}

.app-state--loading {
  text-align: center;
  color: var(--cps-muted);
}

.app-state--gate {
  max-width: 32rem;
  margin: 2.5rem auto;
  text-align: center;
  padding: 2rem 1.75rem;
}

.gate-inner {
  max-width: 26rem;
  margin: 0 auto;
}

.gate-icon {
  display: flex;
  justify-content: center;
  margin-bottom: 1rem;
}

.gate-title {
  font-size: 1.35rem;
  font-weight: 700;
  margin: 0 0 0.85rem;
  line-height: 1.25;
}

.gate-text {
  margin: 0 0 1rem;
  line-height: 1.55;
  font-size: 1rem;
}

.gate-text--muted {
  font-size: 0.92rem;
  color: var(--cps-muted);
  margin-bottom: 0;
}

.is-hidden {
  display: none !important;
}

/* Same max-width as contract/PDF so the action bar does not stretch on ultrawide. */
.portal-column {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 1rem 2rem;
}

.action-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1rem;
  background: var(--cps-bar);
  border-bottom: 1px solid var(--cps-border);
}

.action-bar__amount-block {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.action-bar__total {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.1;
}

.action-bar__ref {
  font-size: 0.875rem;
  color: var(--cps-muted);
}

.action-bar__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.btn {
  font: inherit;
  cursor: pointer;
  border-radius: 4px;
  padding: 0.55rem 1.1rem;
  font-weight: 600;
  font-size: 0.9rem;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--cps-teal);
  color: #fff;
  border: 1px solid var(--cps-teal-dark);
}

.btn--primary:hover:not(:disabled) {
  background: var(--cps-teal-dark);
}

.btn--secondary {
  background: #fff;
  color: var(--cps-muted);
  border: 1px solid var(--cps-border);
}

.btn--secondary:hover:not(:disabled) {
  background: #fafafa;
}

.btn--icon {
  width: 2.4rem;
  height: 2.4rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: 1px solid var(--cps-border);
  color: var(--cps-muted);
}

.btn--icon:hover:not(:disabled) {
  background: #f8f9f9;
  color: var(--cps-text);
}

.btn--icon svg {
  width: 1.1rem;
  height: 1.1rem;
}

.main-wrap {
  max-width: none;
  margin: 0;
  padding: 1rem 0 0;
}

.doc-card {
  position: relative;
  background: #fff;
  border: 1px solid var(--cps-border);
  border-radius: 2px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  padding: 0;
  overflow: hidden;
}

.doc-card--pdf .doc-inner {
  display: none;
}

.doc-card--pdf .pdf-embed {
  display: block;
  width: 100%;
  min-height: 70vh;
  border: 0;
}

.ribbon {
  position: absolute;
  top: 0.85rem;
  left: -2.2rem;
  z-index: 1;
  background: var(--cps-ribbon);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: none;
  padding: 0.35rem 2.5rem;
  transform: rotate(-45deg);
  transform-origin: center;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.doc-inner {
  padding: 1.5rem 1.75rem 2rem;
}

.doc-top {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
  padding-top: 0.5rem;
}

.brand-block {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.logo-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo-mark {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.logo-mark span {
  display: block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--cps-teal);
}

.logo-text {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--cps-teal);
  letter-spacing: 0.02em;
}

.company-line {
  font-size: 0.8rem;
  color: var(--cps-text);
  line-height: 1.45;
  max-width: 22rem;
}

.doc-title-block {
  text-align: right;
}

.doc-title {
  margin: 0;
  font-size: 1.85rem;
  font-weight: 400;
  color: var(--cps-teal);
}

.doc-number {
  margin: 0.35rem 0 0;
  font-size: 0.95rem;
  color: var(--cps-text);
}

.details-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem 2rem;
  margin-bottom: 1.5rem;
  font-size: 0.875rem;
  line-height: 1.5;
}

@media (max-width: 640px) {
  .details-grid {
    grid-template-columns: 1fr;
  }

  .doc-title-block {
    text-align: left;
  }
}

.details-grid strong {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.95rem;
}

.meta-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.meta-list li {
  margin-bottom: 0.65rem;
}

.meta-list .label {
  color: var(--cps-muted);
  font-size: 0.8rem;
}

.lines-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.lines-table thead th {
  background: var(--cps-table-head);
  color: #fff;
  font-weight: 600;
  text-align: left;
  padding: 0.55rem 0.5rem;
  border: 1px solid var(--cps-table-head);
}

.lines-table thead th.num {
  text-align: center;
  width: 2.5rem;
}

.lines-table thead th.qty,
.lines-table thead th.rate,
.lines-table thead th.disc,
.lines-table thead th.amt {
  text-align: right;
  white-space: nowrap;
}

.lines-table tbody td {
  padding: 0.75rem 0.5rem;
  border-bottom: 1px solid #e8eaeb;
  vertical-align: top;
}

.lines-table tbody td.num {
  text-align: center;
  color: var(--cps-muted);
}

.lines-table tbody td.qty,
.lines-table tbody td.rate,
.lines-table tbody td.disc,
.lines-table tbody td.amt {
  text-align: right;
  white-space: nowrap;
}

.lines-table tbody tr:last-child td {
  border-bottom: none;
}

.line-desc {
  line-height: 1.45;
}

.pdf-embed {
  display: none;
}

.sign-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(44, 49, 51, 0.45);
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 0;
}

.sign-overlay[hidden] {
  display: none;
}

.sign-overlay__inner {
  flex: 1;
  max-width: 100%;
  background: #fff;
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
}

.sign-overlay__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: var(--cps-bar);
  border-bottom: 1px solid var(--cps-border);
  font-size: 0.9rem;
}

.sign-overlay__body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}

.sign-overlay__loading {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  font-size: 1rem;
  color: var(--cps-muted);
}

.sign-overlay__error {
  flex: 1;
  overflow: auto;
  padding: 1.25rem 1.5rem;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--cps-danger-text);
  background: var(--cps-danger-bg);
  border-bottom: 1px solid #f5c2c2;
}

.sign-overlay__frame {
  flex: 1;
  border: 0;
  width: 100%;
  min-height: 0;
}

.portal-banner {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.4;
}

.portal-banner--success {
  background: #d1fae5;
  color: #065f46;
  border-bottom: 1px solid #6ee7b7;
}

.portal-banner--info {
  background: #f3f4f6;
  color: var(--cps-text);
  border-bottom: 1px solid var(--cps-border);
}

.portal-banner--warn {
  background: #fef3c7;
  color: #92400e;
  border-bottom: 1px solid #fcd34d;
}

.completion-overlay {
  position: fixed;
  inset: 0;
  z-index: 1100;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.completion-overlay[hidden] {
  display: none;
}

.completion-inner {
  text-align: center;
  max-width: 26rem;
  width: 100%;
}

.completion-brand {
  margin-bottom: 1.75rem;
}

.completion-icon {
  margin: 0 auto 1rem;
  width: 3rem;
  height: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.completion-title {
  font-size: 1.85rem;
  font-weight: 700;
  margin: 0 0 0.75rem;
  color: var(--cps-text);
  line-height: 1.2;
}

.completion-body {
  font-size: 1rem;
  color: var(--cps-muted);
  line-height: 1.6;
  margin: 0 0 1.5rem;
}

.completion-redirect {
  font-size: 0.9rem;
  color: var(--cps-muted);
  margin: 0 0 1.5rem;
}

.completion-cta {
  font-size: 0.95rem;
  padding: 0.65rem 1.5rem;
}

@media print {
  .site-header,
  .action-bar {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .action-bar__actions {
    display: none;
  }

  .main-wrap {
    padding: 0;
    max-width: none;
  }

  .doc-card {
    box-shadow: none;
    border: 0;
  }

  .sign-overlay {
    display: none !important;
  }
}
