:root {
  --bg: #0a0a0c;
  --surface: #121216;
  --raised: #19191e;
  --soft: #222228;
  --line: #2b2b33;
  --line-strong: #40404a;
  --text: #f4f1e9;
  --muted: #9d9aa3;
  --gold: #d6b778;
  --safe: #8fcba1;
  --warning: #e1b56f;
  --danger: #ee7f88;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 80% -20%, rgba(214, 183, 120, 0.1), transparent 32rem),
    var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button,
a,
input,
textarea,
select {
  outline: none;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

button {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  color: var(--text);
  background: var(--soft);
  cursor: pointer;
}

button:hover {
  border-color: #67636c;
  background: #2b2a31;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

button.primary {
  border-color: var(--gold);
  color: #1b160b;
  background: var(--gold);
  font-weight: 800;
}

h1,
h2,
h3,
p,
blockquote,
dl {
  margin-top: 0;
}

.hidden {
  display: none !important;
}

.eyebrow {
  margin-bottom: 7px;
  color: var(--gold);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.17em;
}

.gate {
  min-height: 100vh;
  padding: 40px 20px;
  display: grid;
  place-items: center;
}

.gate-card {
  width: min(100%, 500px);
  padding: 38px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: linear-gradient(145deg, rgba(25, 25, 30, 0.98), rgba(12, 12, 15, 0.98));
  box-shadow: 0 32px 100px rgba(0, 0, 0, 0.42);
}

.gate-card img {
  width: 130px;
  margin-bottom: 28px;
}

.gate-card h1 {
  margin-bottom: 12px;
  font-size: 38px;
  letter-spacing: -0.04em;
}

.gate-card > p:not(.eyebrow) {
  margin-bottom: 26px;
  color: var(--muted);
  line-height: 1.7;
}

.gate-card label,
.workflow-card label {
  display: block;
  margin: 13px 0 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.gate-card input,
.workflow-card textarea,
.transition-item textarea,
.transition-item select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  color: var(--text);
  background: #09090b;
}

.gate-card input {
  min-height: 46px;
  padding: 0 13px;
}

.gate-card button {
  width: 100%;
  min-height: 46px;
  margin-top: 18px;
  border-color: var(--gold);
  color: #1b160b;
  background: var(--gold);
  font-weight: 850;
}

.error-copy {
  min-height: 18px;
  margin-top: 10px;
  display: block;
  color: var(--danger);
  font-size: 12px;
}

.control-shell {
  min-height: 100vh;
}

.control-header {
  min-height: 72px;
  padding: 10px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 11, 14, 0.96);
  backdrop-filter: blur(20px);
  display: flex;
  align-items: center;
  gap: 22px;
  position: sticky;
  z-index: 20;
  top: 0;
}

.control-brand {
  min-width: 220px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.control-brand img {
  width: 70px;
}

.control-brand p,
.control-brand strong {
  margin: 0;
}

.control-brand p {
  color: var(--muted);
  font-size: 9px;
  font-weight: 850;
  letter-spacing: 0.2em;
}

.control-brand strong {
  font-size: 15px;
}

.provider-truth {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.provider-badge,
.connection-state,
.status-chip,
.count {
  padding: 6px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  font-size: 9px;
  font-weight: 850;
  letter-spacing: 0.06em;
}

.provider-badge.manual {
  border-color: rgba(143, 203, 161, 0.4);
  color: var(--safe);
  background: rgba(60, 112, 75, 0.13);
}

.provider-badge.disabled {
  color: var(--muted);
}

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

.connection-state {
  color: var(--warning);
}

.connection-state.online {
  color: var(--safe);
}

.boundary-banner {
  min-height: 42px;
  padding: 10px 22px;
  border-bottom: 1px solid #453a27;
  color: #d8c59f;
  background: rgba(51, 41, 25, 0.72);
  display: flex;
  align-items: center;
  gap: 18px;
  font-size: 11px;
}

.boundary-banner span:last-child {
  margin-left: auto;
  color: var(--muted);
}

.control-grid {
  min-height: calc(100vh - 115px);
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
}

.queue-panel {
  height: calc(100vh - 115px);
  padding: 24px 18px 16px;
  border-right: 1px solid var(--line);
  background: rgba(14, 14, 17, 0.88);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 115px;
}

.panel-heading,
.card-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.panel-heading h1 {
  margin-bottom: 0;
  font-size: 21px;
}

.count {
  min-width: 34px;
  text-align: center;
}

.queue-filters {
  margin: 18px 0 12px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}

.queue-filters button {
  min-height: 32px;
  padding: 0 7px;
  border-color: transparent;
  color: var(--muted);
  background: transparent;
  font-size: 10px;
}

.queue-filters button.active {
  border-color: var(--line);
  color: var(--text);
  background: var(--soft);
}

.queue-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 7px;
}

.queue-item {
  width: 100%;
  min-height: 0;
  padding: 13px;
  border-color: var(--line);
  text-align: left;
  background: #151519;
  display: block;
}

.queue-item.active {
  border-color: var(--gold);
  background: #211e18;
}

.queue-item-top,
.queue-item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.queue-item-top span:first-child {
  color: var(--gold);
  font-size: 9px;
  font-weight: 800;
}

.queue-item-time {
  color: var(--muted);
  font-size: 9px;
}

.queue-item p {
  margin: 9px 0;
  overflow: hidden;
  color: #dfdcd4;
  font-size: 11px;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.queue-item-meta {
  color: var(--muted);
  font-size: 9px;
}

.queue-state {
  color: var(--safe);
}

.queue-state.failed {
  color: var(--danger);
}

.poll-note,
.field-note,
.card-copy,
.empty-copy {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.6;
}

.poll-note {
  margin: 12px 0 0;
}

.workbench {
  min-width: 0;
  padding: 30px clamp(22px, 4vw, 58px) 80px;
}

.workbench-empty {
  min-height: 58vh;
  display: grid;
  align-content: center;
  justify-items: center;
  text-align: center;
}

.workbench-empty h2 {
  margin-bottom: 10px;
  font-size: 34px;
}

.workbench-empty > p:last-child {
  max-width: 560px;
  color: var(--muted);
  line-height: 1.7;
}

.task-workflow {
  width: min(100%, 1260px);
  margin: 0 auto;
}

.task-overview,
.workflow-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(19, 19, 23, 0.94);
  box-shadow: 0 18px 55px rgba(0, 0, 0, 0.18);
}

.task-overview {
  padding: 24px;
  position: relative;
}

.task-overview h2 {
  margin-bottom: 0;
  font-size: 26px;
}

.task-overview > .status-chip {
  position: absolute;
  top: 24px;
  right: 24px;
  color: var(--safe);
}

.task-meta {
  margin: 18px 0 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.task-meta div {
  padding: 9px 11px;
  border-radius: 10px;
  background: var(--soft);
}

.task-meta dt {
  color: var(--muted);
  font-size: 9px;
}

.task-meta dd {
  margin: 4px 0 0;
  overflow-wrap: anywhere;
  font-size: 11px;
}

.task-overview blockquote {
  margin: 18px 0;
  padding: 16px 18px;
  border-left: 3px solid var(--gold);
  color: #f0ece3;
  background: #0d0d10;
  font-size: 14px;
  line-height: 1.75;
  white-space: pre-wrap;
}

.risk-strip {
  display: flex;
  align-items: center;
  gap: 20px;
  color: var(--muted);
  font-size: 10px;
}

.risk-strip strong {
  margin-left: 4px;
  color: var(--text);
}

.workflow-rail {
  margin: 14px 0;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(13, 13, 16, 0.96);
  display: flex;
  gap: 5px;
  position: sticky;
  z-index: 10;
  top: 86px;
}

.workflow-rail a {
  flex: 1;
  padding: 8px 6px;
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  text-decoration: none;
  font-size: 9px;
}

.workflow-rail a:hover {
  color: var(--text);
  background: var(--soft);
}

.workflow-card {
  margin-top: 14px;
  padding: 24px;
  scroll-margin-top: 142px;
}

.workflow-card h2 {
  margin-bottom: 0;
  font-size: 21px;
}

.workflow-card h3 {
  margin-bottom: 0;
  font-size: 15px;
}

.stage-number {
  color: #514d45;
  font-size: 30px;
  font-weight: 900;
  letter-spacing: -0.05em;
}

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

.guardrails {
  margin: 17px 0;
}

.guardrails span {
  padding: 6px 9px;
  border: 1px solid #4d3c3e;
  border-radius: 999px;
  color: #e5afb4;
  background: rgba(110, 47, 55, 0.1);
  font-size: 9px;
}

.turn-consent {
  margin: 13px 0 17px !important;
  padding: 12px;
  border: 1px solid #514429;
  border-radius: 11px;
  background: rgba(83, 65, 31, 0.12);
  display: flex !important;
  align-items: flex-start;
  gap: 10px;
}

.turn-consent input {
  width: 16px;
  height: 16px;
  margin: 2px 0 0;
  accent-color: var(--gold);
}

.turn-consent span {
  min-width: 0;
}

.turn-consent strong,
.turn-consent small {
  display: block;
}

.turn-consent strong {
  color: #e8dcc2;
  font-size: 11px;
}

.turn-consent small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.55;
}

.button-row {
  margin: 14px 0 10px;
}

.button-row.end {
  justify-content: flex-end;
}

.workflow-card textarea {
  min-height: 130px;
  padding: 13px;
  resize: vertical;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 11px;
  line-height: 1.55;
}

.workflow-card textarea[readonly] {
  color: #cbc7bd;
  background: #0d0d10;
}

.import-zone {
  margin-top: 25px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.validation-box {
  margin-top: 12px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 10px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.validation-box.neutral {
  color: var(--muted);
  background: #101013;
}

.validation-box.valid {
  border-color: rgba(143, 203, 161, 0.4);
  color: var(--safe);
  background: rgba(60, 112, 75, 0.1);
}

.validation-box.invalid {
  border-color: rgba(238, 127, 136, 0.42);
  color: #efb0b6;
  background: rgba(112, 38, 46, 0.1);
}

.nir-summary {
  margin: 16px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.nir-summary span {
  padding: 6px 9px;
  border-radius: 999px;
  color: var(--muted);
  background: var(--soft);
  font-size: 9px;
}

.nir-table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 11px;
}

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

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

th {
  color: var(--muted);
  background: #0e0e11;
  font-weight: 750;
}

td {
  overflow-wrap: anywhere;
}

.atom-type {
  color: var(--gold);
  font-weight: 800;
}

.transition-list {
  margin-top: 17px;
  display: grid;
  gap: 9px;
}

.transition-item {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #101013;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 180px minmax(220px, 1fr);
  gap: 10px;
  align-items: start;
}

.transition-item h3 {
  margin-bottom: 6px;
  font-size: 12px;
}

.transition-item p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
}

.transition-item select {
  min-height: 38px;
  padding: 0 10px;
}

.transition-item textarea {
  min-height: 70px;
  padding: 9px;
  resize: vertical;
  font-size: 10px;
}

.query-grid,
.policy-grid,
.expression-grid {
  margin-top: 17px;
  display: grid;
  gap: 9px;
}

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

.query-grid article,
.expression-grid article {
  min-width: 0;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #101013;
}

.query-grid article > span,
.expression-grid article > span,
.approval-line > span {
  color: var(--gold);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.query-grid ul {
  margin: 9px 0 0;
  padding-left: 17px;
  color: #d1cdc4;
  font-size: 10px;
  line-height: 1.6;
}

.query-grid p,
.expression-grid p {
  margin: 9px 0 0;
  color: #d1cdc4;
  font-size: 11px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.query-grid .forbidden {
  border-color: #453536;
}

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

.policy-check {
  min-height: 72px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #101013;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
}

.policy-check span {
  color: var(--muted);
  font-size: 9px;
}

.policy-check strong {
  color: var(--safe);
  font-size: 10px;
}

.policy-check.failed strong {
  color: var(--danger);
}

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

.phone-message {
  margin-top: 10px;
  padding: 13px;
  border-radius: 14px 14px 14px 4px;
  color: #1c1a17;
  background: #ebe6dc;
  font-size: 11px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.approval-line {
  margin-top: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.approval-line strong {
  font-size: 11px;
}

.audit-timeline {
  margin: 16px 0 0;
  padding-left: 22px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.7;
}

.audit-timeline li {
  padding: 3px 0;
}

.following-control {
  width: min(100%, 1260px);
  margin: 0 auto 18px;
  padding: 20px;
  border: 1px solid rgba(214, 183, 120, 0.26);
  border-radius: 18px;
  background:
    linear-gradient(145deg, rgba(30, 27, 22, 0.94), rgba(17, 17, 21, 0.97));
}

.following-control-heading,
.following-control-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.following-control-heading h2 {
  margin-bottom: 0;
  font-size: 21px;
}

.following-control-actions {
  justify-content: flex-end;
}

.following-control-boundary {
  margin: 11px 0 15px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.6;
}

.following-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.following-summary-grid article {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #101013;
}

.following-summary-grid span {
  color: var(--gold);
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.following-summary-grid strong,
.following-summary-grid small {
  display: block;
  overflow-wrap: anywhere;
}

.following-summary-grid strong {
  margin-top: 7px;
  font-size: 12px;
}

.following-summary-grid small {
  margin-top: 5px;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.45;
}

.following-detail-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.following-detail-grid details {
  min-width: 0;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(12, 12, 15, 0.72);
}

.following-detail-grid summary {
  color: #ded9cf;
  cursor: pointer;
  font-size: 10px;
  font-weight: 750;
}

.following-detail-grid details > div,
.following-detail-grid ol {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.65;
}

.following-detail-grid ol {
  padding-left: 18px;
}

.following-detail-grid li {
  margin-bottom: 5px;
}

.following-data-list {
  display: grid;
  gap: 6px;
}

.following-data-list article {
  padding: 8px 9px;
  border-radius: 8px;
  background: var(--soft);
}

.following-data-list strong,
.following-data-list small {
  display: block;
}

.following-data-list strong {
  color: var(--text);
  font-size: 9px;
}

.following-data-list small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 8px;
  line-height: 1.5;
}

.toast-region {
  position: fixed;
  z-index: 50;
  right: 20px;
  bottom: 20px;
  width: min(calc(100% - 40px), 420px);
  display: grid;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  color: var(--text);
  background: rgba(28, 28, 33, 0.97);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  font-size: 11px;
}

.toast.error {
  border-color: rgba(238, 127, 136, 0.45);
  color: #efb0b6;
}

@media (max-width: 1180px) {
  .provider-truth {
    display: none;
  }

  .control-grid {
    grid-template-columns: 290px minmax(0, 1fr);
  }

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

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

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

@media (max-width: 820px) {
  .control-header {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .control-brand {
    flex: 1;
  }

  .header-actions {
    width: 100%;
  }

  .boundary-banner {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .boundary-banner span:last-child {
    margin-left: 0;
  }

  .control-grid {
    display: block;
  }

  .queue-panel {
    width: 100%;
    height: auto;
    max-height: 48vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    position: static;
  }

  .workbench {
    padding: 22px 14px 60px;
  }

  .workflow-rail {
    overflow-x: auto;
    top: 8px;
  }

  .workflow-rail a {
    min-width: 110px;
  }

  .task-meta,
  .query-grid {
    grid-template-columns: 1fr;
  }

  .transition-item {
    grid-template-columns: 1fr;
  }

  .following-control-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .following-control-actions {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .following-summary-grid,
  .following-detail-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
