@import url("https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600;9..144,700&family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap");

/* ---------------------------------------------------------------
   Poststelle — tokens
   Dark-ink ledger sidebar against a warm paper working surface.
   Registry codes, dates and statuses read in mono, like a stamped
   file number; everything else reads in a plain working typeface.
   --------------------------------------------------------------- */
:root {
  color-scheme: light;

  --ink: #1e1810;
  --ink-raised: #2b2118;
  --paper: #f6f3ea;
  --paper-raised: #ffffff;
  --rule: #e1dacb;
  --muted: #7a7059;
  --tan: #b7a98c;
  --cream-text: #f3efe4;

  --accent-red: #a8382b;
  --accent-red-ink: #7e2a20;
  --accent-teal: #2e6b58;
  --accent-amber: #a97a24;
  --accent-blue: #33526e;
  --accent-gray: #6b6456;

  --font-display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --font-body: "Inter", -apple-system, Segoe UI, Helvetica, Arial, sans-serif;
  --font-mono: "IBM Plex Mono", "Consolas", monospace;

  font-family: var(--font-body);
  color: var(--ink);
  background: var(--paper);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow-x: hidden;
  overflow-y: auto;
}

a {
  color: inherit;
}

/* ---------------------------------------------------------------
   Shell layout — dark sidebar + paper content area
   --------------------------------------------------------------- */
.app-shell {
  display: block;
  min-height: 100vh;
  overflow-x: hidden;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 236px;
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--ink);
  color: var(--cream-text);
  padding: 22px 18px 18px;
  border-right: 1px solid #120e09;
}

.sidebar-brand {
  padding-bottom: 20px;
  margin-bottom: 18px;
  border-bottom: 1px solid rgba(243, 239, 228, 0.14);
}

.sidebar-brand .mark {
  display: block;
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.sidebar-brand .mark::before {
  content: "✉ ";
  color: var(--accent-red);
}

.sidebar-brand .tagline {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--tan);
  letter-spacing: 0.01em;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-nav a {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 5px;
  color: var(--tan);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  border-left: 2px solid transparent;
}

.sidebar-nav a .step {
  font-family: var(--font-mono);
  font-size: 11px;
  color: rgba(243, 239, 228, 0.35);
}

.sidebar-nav a:hover {
  background: var(--ink-raised);
  color: var(--cream-text);
}

.sidebar-nav a[aria-current="page"] {
  background: var(--ink-raised);
  color: var(--cream-text);
  border-left-color: var(--accent-red);
}

.sidebar-nav a[aria-current="page"] .step {
  color: var(--accent-red);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid rgba(243, 239, 228, 0.14);
}

.mode-note {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--tan);
  letter-spacing: 0.04em;
}

.mode-note .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-amber);
  flex: 0 0 auto;
}

.mode-note strong {
  color: var(--cream-text);
  font-weight: 600;
}

.logout-button {
  width: 100%;
  margin-top: 12px;
  justify-content: center;
  border-color: rgba(243, 239, 228, 0.18);
  color: var(--cream-text);
}

.logout-button:hover {
  background: var(--ink-raised);
  border-color: rgba(243, 239, 228, 0.32);
}

/* ---------------------------------------------------------------
   Login
   --------------------------------------------------------------- */
.login-page {
  min-height: 100vh;
  background: var(--paper);
}

.login-shell {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.login-panel {
  width: min(100%, 420px);
  padding: 28px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--paper-raised);
  box-shadow: 0 20px 70px rgba(30, 24, 16, 0.12);
}

.login-brand {
  margin: 0 0 24px;
  padding: 0 0 18px;
}

.login-form {
  display: grid;
  gap: 16px;
  margin-top: 24px;
}

.login-form input {
  width: 100%;
  height: 40px;
  border: 1px solid var(--rule);
  border-radius: 5px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14px;
  padding: 0 10px;
}

/* ---------------------------------------------------------------
   Page shell
   --------------------------------------------------------------- */
.page-shell {
  max-width: 1180px;
  width: calc(100% - 236px);
  min-width: 0;
  min-height: 100vh;
  margin-left: 236px;
  padding: 40px 44px 56px;
  overflow: visible;
  display: flex;
  flex-direction: column;
}

.page-shell.narrow {
  max-width: 640px;
}

.page-header {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--rule);
}

.eyebrow {
  display: block;
  margin: 0 0 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-red);
}

h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 32px;
  line-height: 1.15;
  letter-spacing: -0.01em;
}

h2 {
  margin: 0;
  padding: 16px 18px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  line-height: 1.2;
}

p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14.5px;
  line-height: 1.5;
  max-width: 46em;
}

/* ---------------------------------------------------------------
   Controls
   --------------------------------------------------------------- */
.toolbar {
  flex: 0 0 auto;
  display: flex;
  gap: 16px;
  align-items: end;
  margin-bottom: 20px;
}

.search-label input[type="search"] {
  min-width: 240px;
  height: 38px;
  border: 1px solid var(--rule);
  border-radius: 5px;
  background: var(--paper-raised);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14px;
  padding: 0 10px;
}

.search-label input[type="search"]:focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: 2px;
}

.result-count {
  margin-left: auto;
  padding-bottom: 9px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

label {
  display: grid;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent-gray);
  letter-spacing: 0.02em;
}

select,
input[type="file"] {
  min-width: 190px;
  height: 38px;
  border: 1px solid var(--rule);
  border-radius: 5px;
  background: var(--paper-raised);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14px;
  padding: 0 10px;
}

select:focus-visible,
input[type="file"]:focus-visible,
.button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: 2px;
}

input[type="file"] {
  height: auto;
  min-height: 40px;
  padding: 8px 10px;
}

.form-panel {
  display: grid;
  gap: 18px;
  padding: 24px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--paper-raised);
}

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

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 16px;
  border: 1px solid var(--ink);
  border-radius: 5px;
  background: var(--ink);
  color: var(--cream-text);
  font-family: var(--font-body);
  font-size: 13.5px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
}

.button:hover {
  background: var(--ink-raised);
}

.button:active {
  transform: translateY(1px);
}

.button.secondary {
  background: transparent;
  color: var(--ink);
  border-color: var(--rule);
}

.button.secondary:hover {
  background: var(--paper);
  border-color: var(--tan);
}

.button:disabled {
  cursor: progress;
  opacity: 0.6;
}

/* ---------------------------------------------------------------
   Result / status messaging
   --------------------------------------------------------------- */
.result-box {
  padding: 16px 18px;
  border: 1px solid var(--rule);
  border-left: 3px solid var(--accent-teal);
  border-radius: 6px;
  background: #f4faf7;
  color: var(--ink);
  font-size: 14px;
}

.result-box.error {
  border-left-color: var(--accent-red);
  background: #fbf2f0;
}

.result-box strong {
  font-family: var(--font-display);
  font-weight: 600;
}

.result-box dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 14px;
  margin: 12px 0;
}

.result-box dt {
  color: var(--muted);
  font-weight: 600;
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding-top: 2px;
}

.result-box dd {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 14px;
}

.result-box h3 {
  margin: 14px 0 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent-gray);
}

.result-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.result-list li {
  display: grid;
  gap: 3px;
  padding: 8px 10px;
  border: 1px solid var(--rule);
  border-radius: 5px;
  background: var(--paper-raised);
}

.result-list span {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

/* ---------------------------------------------------------------
   Summary cards
   --------------------------------------------------------------- */
.summary-grid {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.summary-card {
  padding: 18px 16px;
  border: 1px solid var(--rule);
  border-top: 3px solid var(--accent-gray);
  border-radius: 6px;
  background: var(--paper-raised);
}

.summary-card.accent-imported {
  border-top-color: var(--accent-gray);
}
.summary-card.accent-ready {
  border-top-color: var(--accent-blue);
}
.summary-card.accent-review {
  border-top-color: var(--accent-amber);
}
.summary-card.accent-submitted {
  border-top-color: var(--accent-red);
}

.summary-card strong {
  display: block;
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 600;
  line-height: 1;
}

.summary-card span {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

/* ---------------------------------------------------------------
   Tables
   --------------------------------------------------------------- */
.table-panel {
  min-width: 0;
  flex: 1 1 auto;
  overflow: visible;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--paper-raised);
}

table {
  width: 100%;
  min-width: 0;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--rule);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--paper);
  color: var(--accent-gray);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

tbody tr:hover {
  background: #fbfaf6;
}

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

td strong,
td span {
  display: block;
}

td strong {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14.5px;
}

td span {
  color: var(--muted);
  font-size: 12.5px;
  margin-top: 2px;
}

td.mono,
.register-id {
  font-family: var(--font-mono);
  font-size: 13px;
}

.actions-column {
  width: 110px;
  text-align: right;
}

.status-message {
  padding: 18px;
  color: var(--muted);
  font-size: 14px;
}

/* ---------------------------------------------------------------
   Ledger list — the shared row component for Templates and
   Companies: content-width, not a stretched table, so labels and
   actions sit close together instead of leaving a dead gap between
   a short value and a right-aligned action.
   --------------------------------------------------------------- */
.list-panel {
  max-width: 640px;
}

.list-panel.wide {
  max-width: 820px;
}

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

.ledger-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--rule);
}

.ledger-row:last-child {
  border-bottom: none;
}

.ledger-row:hover {
  background: #fbfaf6;
}

.ledger-row-main {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  flex: 1 1 auto;
}

.template-region {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent-gray);
}

.ledger-row-main strong {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14.5px;
}

.muted-strong {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 14px;
  color: var(--muted);
}

.ledger-meta {
  color: var(--muted);
  font-size: 12.5px;
}

.ledger-row-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
}

.selection-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
}

.selection-bar strong {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-blue);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.selection-bar span {
  color: var(--muted);
  font-size: 12.5px;
}

.job-select {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  cursor: pointer;
}

.job-select input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.job-select span {
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--tan);
  border-radius: 4px;
  background: var(--paper-raised);
}

.job-select input:checked + span {
  border-color: var(--accent-blue);
  background: var(--accent-blue);
  box-shadow: inset 0 0 0 3px var(--paper-raised);
}

.job-select input:disabled + span {
  opacity: 0.35;
  background: var(--paper);
  cursor: not-allowed;
}

.job-select:has(input:focus-visible) span {
  outline: 2px solid var(--accent-blue);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------
   Signature element — postmark status stamps
   Rendered instead of plain status pills: a dashed, slightly
   rotated cancellation mark, colour-coded by pipeline stage.
   --------------------------------------------------------------- */
.status-stamp {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 78px;
  padding: 4px 8px 3px;
  border: 1.5px dashed currentColor;
  border-radius: 3px;
  transform: rotate(-1.5deg);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
  background: color-mix(in srgb, currentColor 7%, transparent);
}

.status-stamp--imported,
.status-stamp--skipped,
.status-stamp--unknown {
  color: var(--accent-gray);
}
.status-stamp--ready {
  color: var(--accent-blue);
}
.status-stamp--pending {
  color: var(--accent-amber);
}
.status-stamp--needs_review {
  color: var(--accent-amber);
}
.status-stamp--submitted {
  color: var(--accent-red-ink);
}
.status-stamp--sent,
.status-stamp--completed {
  color: var(--accent-teal);
}
.status-stamp--failed {
  color: var(--accent-red);
  background: color-mix(in srgb, var(--accent-red) 10%, transparent);
}
.status-stamp--active {
  color: var(--accent-teal);
}
.status-stamp--inactive {
  color: var(--accent-gray);
}
.status-stamp--local {
  color: var(--accent-blue);
}

/* ---------------------------------------------------------------
   Preview panel
   --------------------------------------------------------------- */
.preview-panel {
  min-height: 0;
  flex: 1 1 auto;
  margin-top: 22px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--paper-raised);
}

.preview-panel header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--rule);
}

.preview-panel h2,
.preview-panel p {
  padding: 0;
  margin: 0;
}

.preview-panel p {
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 12.5px;
}

.preview-panel iframe {
  display: block;
  width: 100%;
  height: calc(100% - 72px);
  min-height: 420px;
  border: 0;
  background: var(--paper);
}

pre {
  max-width: 360px;
  margin: 0;
  white-space: pre-wrap;
  font: 12px/1.4 var(--font-mono);
}

/* ---------------------------------------------------------------
   Responsive
   --------------------------------------------------------------- */
@media (max-width: 980px) {
  .app-shell {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .sidebar {
    position: static;
    width: auto;
    height: auto;
    max-height: 74px;
    flex-direction: row;
    align-items: center;
    padding: 12px 16px;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid #120e09;
  }

  .sidebar-brand {
    padding: 0 16px 0 0;
    margin: 0 16px 0 0;
    border-bottom: none;
    border-right: 1px solid rgba(243, 239, 228, 0.14);
    flex: 0 0 auto;
  }

  .sidebar-nav {
    flex-direction: row;
    gap: 4px;
  }

  .sidebar-nav a {
    border-left: none;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
  }

  .sidebar-nav a[aria-current="page"] {
    border-left-color: transparent;
    border-bottom-color: var(--accent-red);
  }

  .sidebar-footer {
    margin-top: 0;
    margin-left: auto;
    padding-top: 0;
    padding-left: 16px;
    border-top: none;
    border-left: 1px solid rgba(243, 239, 228, 0.14);
    flex: 0 0 auto;
  }
}

@media (max-width: 720px) {
  .page-shell {
    width: 100%;
    min-height: calc(100vh - 74px);
    margin-left: 0;
    padding: 24px 18px 40px;
  }

  .page-header,
  .toolbar {
    display: grid;
  }

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

  select {
    width: 100%;
  }

  .preview-panel iframe {
    min-height: 320px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .button {
    transition: none;
  }
}
