:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --line: #d8dee5;
  --text: #18202a;
  --muted: #667085;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --danger: #b42318;
  --warning: #b54708;
  --ok: #027a48;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

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

a {
  color: var(--accent-strong);
  text-decoration: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: 58px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 164px;
  color: var(--text);
  font-weight: 700;
}

.brand-mark {
  width: 30px;
  height: 30px;
  display: inline-grid;
  place-items: center;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
}

.nav {
  display: flex;
  gap: 2px;
  flex: 1;
  overflow-x: auto;
}

.nav a {
  padding: 10px 12px;
  border-radius: 6px;
  color: var(--muted);
  white-space: nowrap;
}

.nav a.active,
.nav a:hover {
  background: #e6f4f1;
  color: var(--accent-strong);
}

.userbar {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.shell {
  width: min(1320px, calc(100% - 32px));
  margin: 18px auto 48px;
}

.page-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

h1 {
  margin: 0;
  font-size: 24px;
}

h2 {
  margin: 0 0 12px;
  font-size: 17px;
}

.workspace-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.workspace-head.compact {
  align-items: center;
}

.workspace-head h2 {
  margin: 4px 0 0;
  font-size: 22px;
}

.eyebrow {
  display: inline-block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.grid {
  display: grid;
  gap: 14px;
}

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

.grid.two {
  grid-template-columns: 1.1fr .9fr;
}

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

.dashboard-grid {
  grid-template-columns: minmax(0, 1fr) 360px;
  align-items: start;
  margin-top: 14px;
}

.side-rail {
  display: grid;
  gap: 14px;
}

.panel,
.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.panel {
  padding: 16px;
}

.panel-lite {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: #fbfdff;
}

.panel-lite summary {
  cursor: pointer;
  font-weight: 700;
}

.metric {
  padding: 14px;
  color: var(--text);
}

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

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

.metric:hover {
  border-color: var(--accent);
}

.metric-grid,
.load-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}

.metric-grid > div,
.load-summary > div {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
}

.metric-grid span,
.load-summary span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
}

.metric-grid strong,
.load-summary strong {
  display: block;
  overflow-wrap: anywhere;
}

.compact-metrics strong {
  font-size: 14px;
}

.toolbar {
  display: flex;
  gap: 10px;
  align-items: end;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.toolbar form {
  display: contents;
}

label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
  background: #fff;
}

textarea {
  min-height: 86px;
  resize: vertical;
}

.field {
  min-width: 180px;
}

.field.wide {
  min-width: 320px;
}

.actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

button,
.button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 8px 12px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  cursor: pointer;
}

.button.secondary,
button.secondary {
  background: #fff;
  color: var(--accent-strong);
}

button.danger,
.button.danger {
  background: #fff;
  border-color: var(--danger);
  color: var(--danger);
}

button.danger:hover,
.button.danger:hover {
  background: #fff5f5;
}

table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #eef2f6;
  color: var(--muted);
  font-size: 12px;
}

.status.sent,
.status.viewed {
  background: #eef4ff;
  color: #175cd3;
}

.status.ok,
.status.completed,
.status.active {
  background: #ecfdf3;
  color: var(--ok);
}

.status.failed,
.status.declined,
.status.expired,
.status.revoked,
.status.blocked {
  background: #fef3f2;
  color: var(--danger);
}

.status.draft,
.status.pending {
  background: #fffaeb;
  color: var(--warning);
}

.status.missing {
  background: #fef3f2;
  color: var(--danger);
}

.debug-sql {
  margin: 10px 0;
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0b1220;
  color: #e5e7eb;
  font-size: 13px;
  line-height: 1.45;
}

.debug-details {
  border: 1px solid var(--line);
  border-radius: 6px;
  margin-bottom: 10px;
  background: #fff;
}

.debug-details summary {
  cursor: pointer;
  padding: 10px 12px;
  font-weight: 700;
}

.debug-details table {
  border-top: 1px solid var(--line);
}

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

.flash {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #ecfdf3;
  color: var(--ok);
}

.flash.err {
  background: #fef3f2;
  color: var(--danger);
}

.copy-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.token-reveal {
  margin-bottom: 14px;
  border-color: #99d6cc;
}

.inline-form {
  margin: 0;
}

code {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

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

.login-box {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
}

.login-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.check-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
  max-height: 280px;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.check-item {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 8px;
  border: 1px solid #eef2f6;
  border-radius: 6px;
}

.check-item input {
  width: auto;
  min-height: auto;
  margin-top: 3px;
}

.inline-check {
  min-height: 38px;
  align-items: center;
  margin-bottom: 0;
  background: #fff;
}

.inline-check input {
  margin-top: 0;
}

.template-presets {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.seg-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0 0 14px;
}

.seg-tabs a {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
}

.seg-tabs a.active,
.seg-tabs a:hover {
  border-color: var(--accent);
  background: #f0fdfa;
  color: var(--accent-strong);
}

.consumer-board {
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr) 290px;
  gap: 14px;
  align-items: start;
}

.case-list,
.consumer-detail,
.consumer-rail {
  min-width: 0;
}

.case-list,
.consumer-detail,
.rail-block {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

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

.case-list-head,
.detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.case-list-head {
  margin-bottom: 4px;
}

.case-list-head h2,
.detail-head h2 {
  margin: 0;
}

.case-card {
  width: 100%;
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.case-card:hover,
.case-card.active {
  border-color: var(--accent);
  background: #f8fffd;
}

.case-card.attention {
  border-left: 4px solid var(--warning);
}

.case-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.case-top strong,
.case-preview,
.case-meta {
  min-width: 0;
  overflow-wrap: anywhere;
}

.case-preview {
  color: var(--text);
  font-size: 13px;
}

.case-meta {
  color: var(--muted);
  font-size: 12px;
}

.consumer-detail {
  padding: 16px;
}

.detail-empty,
.empty-state {
  min-height: 220px;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  color: var(--muted);
}

.empty-state {
  min-height: 180px;
  padding: 16px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

.empty-state strong,
.detail-empty strong {
  color: var(--text);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.detail-item {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
}

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

.detail-item strong {
  display: block;
  overflow-wrap: anywhere;
}

.detail-band {
  display: grid;
  gap: 4px;
  margin: 14px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.detail-band.ok {
  background: #ecfdf3;
  border-color: #abefc6;
}

.detail-band.warn {
  background: #fffaeb;
  border-color: #fedf89;
}

.detail-band.neutral {
  background: #f8fafc;
}

.detail-band span,
.detail-band small {
  color: var(--muted);
}

.public-agent-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}

.recipient-list {
  display: grid;
  gap: 6px;
  margin: 0 0 14px;
  padding: 0;
  list-style: none;
}

.recipient-list li {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.rail-block {
  padding: 14px;
}

.preset-link {
  display: grid;
  gap: 4px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
}

.preset-link span,
.link-list span,
.event-list small {
  color: var(--muted);
  font-size: 12px;
}

.preset-link.active,
.preset-link:hover {
  border-color: var(--accent);
  background: #f0fdfa;
}

.field-builder {
  display: grid;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.template-form-section {
  display: grid;
  gap: 10px;
}

.contract-editor {
  min-height: 360px;
  line-height: 1.5;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

.variable-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.variable-chip {
  min-height: 30px;
  padding: 5px 10px;
  border-radius: 999px;
  border-color: var(--line);
  background: #fff;
  color: var(--accent-strong);
  font-size: 12px;
}

.variable-chip:hover {
  border-color: var(--accent);
  background: #f0fdfa;
}

.field-row {
  display: grid;
  grid-template-columns: minmax(160px, 1.2fr) minmax(120px, .8fr) 130px 130px 96px 96px;
  gap: 8px;
  align-items: center;
}

.template-picker {
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.load-summary {
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.send-form {
  margin-top: 14px;
}

.small-button {
  min-height: 30px;
  padding: 5px 9px;
  font-size: 12px;
}

.public-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 18px auto 42px;
}

.public-card {
  max-width: 640px;
  margin: 14vh auto 0;
}

.public-contract-grid {
  grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
  align-items: start;
}

.public-document pre {
  min-height: 420px;
  max-height: 68vh;
  overflow: auto;
  margin: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 16px/1.65 Arial, sans-serif;
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
}

.public-audit-grid {
  max-width: 780px;
  margin-top: 12px;
}

.public-decline-form {
  margin-top: 12px;
}

.public-decline-form input {
  min-width: 0;
}

.field-stack {
  display: grid;
  gap: 10px;
}

.chip-list,
.link-list,
.event-list {
  display: grid;
  gap: 8px;
}

.chip {
  display: inline-flex;
  width: max-content;
  min-height: 28px;
  align-items: center;
  padding: 4px 9px;
  border-radius: 999px;
  background: #eef2f6;
  color: var(--text);
  font-size: 12px;
}

.link-list a {
  display: grid;
  gap: 3px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  color: var(--text);
}

.link-list a:last-child {
  border-bottom: 0;
}

.event-list div {
  display: grid;
  gap: 5px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}

.event-list div:last-child {
  border-bottom: 0;
}

@media (max-width: 860px) {
  .public-shell {
    width: min(100% - 20px, 1180px);
    margin-top: 12px;
  }

  .topbar {
    height: auto;
    align-items: flex-start;
    flex-direction: column;
    padding: 12px;
  }

  .grid.stats,
  .grid.two,
  .grid.two-tight,
  .dashboard-grid,
  .template-presets,
  .field-row,
  .consumer-board,
  .detail-grid,
  .public-contract-grid {
    grid-template-columns: 1fr;
  }

  .workspace-head {
    align-items: stretch;
    flex-direction: column;
  }

  .field,
  .field.wide {
    min-width: 100%;
  }

  .public-document pre {
    min-height: 0;
    max-height: none;
    overflow: visible;
    padding: 18px;
    font-size: 18px;
    line-height: 1.75;
  }
}
