:root {
  --bg: #f6f3ec;
  --paper: #fffdf8;
  --ink: #15130f;
  --ink-2: #302b20;
  --muted: #766f62;
  --muted-2: #a79d8c;
  --border: #d9cfbc;
  --grid: rgba(21, 19, 15, .045);
  --yellow: #ffd21f;
  --yellow-soft: #fff2a8;
  --blue: #2f60d7;
  --green: #1f8a5b;
  --red: #be4138;
  --shadow-soft: 0 8px 22px rgba(21, 19, 15, .08);
  --radius: 8px;
  --mono: "SFMono-Regular", "Cascadia Code", "JetBrains Mono", Consolas, monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-width: 0;
  background:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px),
    var(--bg);
  background-size: 28px 28px;
  color: var(--ink);
  font-family: var(--sans);
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

.page-shell {
  width: min(1240px, calc(100vw - 48px));
  margin: 0 auto;
  padding: 18px 0 26px;
}

body[data-view="agent"] .page-shell {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

body[data-view="agent"] main,
body[data-view="agent"] #agentView,
body[data-view="agent"] .agent-layout {
  height: 100%;
  min-height: 0;
}

.flow-header {
  position: sticky;
  top: 12px;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 16px;
  align-items: center;
  margin: 0 0 14px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, .94);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(10px);
}

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

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 2px solid var(--ink);
  border-radius: 6px;
  background: var(--yellow);
  box-shadow: 4px 4px 0 var(--ink);
  font-weight: 950;
  font-size: 18px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.08;
}

h1 {
  font-size: 22px;
}

h2 {
  font-size: 18px;
}

h3 {
  font-size: 14px;
}

.subtitle {
  max-width: 760px;
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

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

.nav-pill,
.button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 850;
  white-space: nowrap;
}

.nav-pill,
.button {
  padding: 0 12px;
}

.nav-pill.active,
.button.primary {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--yellow);
}

.icon-button {
  width: 34px;
  padding: 0;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
}

.nav-logout {
  flex: 0 0 auto;
  font-size: 15px;
  font-weight: 900;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
  white-space: nowrap;
}

.status-current {
  background: #dff3e8;
  border-color: #94cdb1;
  color: #12563b;
}

.status-reference {
  background: #e5ecff;
  border-color: #b9c9f5;
  color: #244caa;
}

.status-candidate,
.status-open {
  background: #fff2a8;
  border-color: #d7aa00;
  color: #5b4700;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.doc-section,
.chat-sidebar,
.terminal-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, .95);
  box-shadow: var(--shadow-soft);
}

.doc-section {
  padding: 14px;
  min-width: 0;
}

.panel-head,
.terminal-head,
.panel-subhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-head > div,
.terminal-head > div,
.panel-subhead > div {
  min-width: 0;
}

.compact-subhead {
  align-items: flex-start;
  margin-bottom: 8px;
}

.helper-text {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.detail-close {
  display: none;
  flex: 0 0 auto;
}

.agent-layout {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  gap: 14px;
  align-items: stretch;
  min-height: calc(100dvh - 142px);
}

.chat-sidebar {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-height: 0;
  padding: 12px;
  overflow: hidden;
}

.chat-sidebar-actions {
  display: flex;
  gap: 7px;
  align-items: center;
}

.chat-close-button,
.chat-menu-button,
.chat-new-mobile {
  display: none;
}

.chat-search {
  margin-bottom: 10px;
}

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

.chat-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 32px;
  gap: 6px;
  align-items: stretch;
}

.chat-item {
  min-width: 0;
  width: 100%;
  max-width: 100%;
  padding: 9px 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--paper);
  color: var(--ink-2);
  text-align: left;
}

.chat-row.active .chat-item,
.chat-item.active {
  border-color: var(--ink);
  background: var(--yellow-soft);
}

.chat-item strong {
  display: block;
  overflow: hidden;
  color: var(--ink);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-item span {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-delete-button {
  width: 32px;
  min-height: 100%;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--paper);
  color: #77736a;
  opacity: .9;
}

.chat-delete-button:hover {
  border-color: var(--red);
  color: var(--red);
  opacity: 1;
}

.chat-delete-button svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.terminal-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
  padding: 12px;
}

.terminal-head {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--paper);
  color: var(--ink);
}

.terminal-head .eyebrow {
  color: var(--muted);
}

.messages {
  display: grid;
  align-content: start;
  gap: 14px;
  min-height: 0;
  max-height: none;
  margin: 0;
  padding: 22px 16px 18px;
  overflow: auto;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.message {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.message-role {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.message-body {
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1.48;
  min-width: 0;
}

.message.user .message-body {
  white-space: pre-wrap;
}

.message.user .message-body {
  justify-self: end;
  max-width: min(640px, 88%);
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 16px 16px 4px 16px;
  background: #f1eadc;
  color: var(--ink);
}

.message.assistant .message-body {
  max-width: min(760px, 100%);
}

.markdown-body p {
  margin: 0 0 10px;
}

.markdown-body p:last-child {
  margin-bottom: 0;
}

.markdown-body h3,
.markdown-body h4,
.markdown-body h5 {
  margin: 12px 0 7px;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.25;
}

.markdown-body h3:first-child,
.markdown-body h4:first-child,
.markdown-body h5:first-child {
  margin-top: 0;
}

.markdown-body ol,
.markdown-body ul {
  margin: 8px 0 12px;
  padding-left: 22px;
}

.markdown-body li + li {
  margin-top: 4px;
}

.markdown-body strong {
  color: var(--ink);
}

.markdown-body code {
  padding: 1px 4px;
  border: 1px solid rgba(47, 96, 215, .18);
  border-radius: 4px;
  background: rgba(47, 96, 215, .08);
  color: #244caa;
  font-family: var(--mono);
  font-size: .92em;
}

.markdown-body pre {
  max-width: 100%;
  margin: 10px 0;
  padding: 10px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #f4f0e7;
}

.markdown-body pre code {
  padding: 0;
  border: 0;
  background: transparent;
  white-space: pre;
}

.markdown-body a {
  color: #244caa;
  text-decoration: underline;
}

.message-sources {
  grid-column: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.source-chip {
  display: inline-flex;
  max-width: 220px;
  min-height: 22px;
  align-items: center;
  padding: 0 7px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-actions {
  grid-column: 1;
  display: flex;
  gap: 6px;
  align-items: center;
}

.feedback-button {
  min-height: 26px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--paper);
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
}

.feedback-button:hover {
  border-color: var(--ink);
  color: var(--ink);
}

.feedback-form {
  grid-column: 1;
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #f4f0e7;
}

.feedback-row {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px 34px;
  gap: 6px;
  align-items: end;
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--paper);
  box-shadow: 0 5px 14px rgba(21, 19, 15, .06);
}

.composer textarea {
  min-height: 34px;
  max-height: 150px;
  padding: 7px 8px;
  border: 0;
  background: transparent;
  line-height: 1.35;
  resize: none;
}

.composer textarea:focus {
  outline: none;
}

.composer-icon-button {
  position: relative;
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: #f6f3ec;
  color: var(--ink);
  font-size: 17px;
  font-weight: 950;
  line-height: 1;
}

.composer-icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.2;
}

.composer-icon-button:hover {
  border-color: var(--ink);
}

.voice-button {
  border-color: transparent;
  background: transparent;
  color: #6d6a62;
}

.voice-button:hover {
  border-color: transparent;
  background: #eee7d7;
  color: var(--ink);
}

.send-button {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--yellow);
}

.voice-button[data-state="recording"] {
  border-color: var(--red);
  background: #ffe6e2;
  color: var(--red);
  animation: voicePulse 1.1s ease-in-out infinite;
}

.voice-button[data-state="processing"] {
  border-color: #d7aa00;
  background: #fff9d9;
  color: #5b4700;
}

@keyframes voicePulse {
  0% {
    box-shadow: 0 0 0 0 rgba(190, 65, 56, .28);
  }
  70% {
    box-shadow: 0 0 0 8px rgba(190, 65, 56, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(190, 65, 56, 0);
  }
}

.voice-status {
  margin: 8px 0 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--paper);
  color: var(--ink);
  font-size: 13px;
}

textarea {
  min-height: 40px;
  padding: 9px 10px;
  overflow: hidden;
  resize: vertical;
}

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

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.scenarios-grid,
.docs-grid,
.glossary-grid,
.objects-grid,
.rules-grid,
.events-grid,
.questions-grid {
  display: grid;
  gap: 14px;
  align-items: start;
}

.agent-layout > *,
.scenarios-grid > *,
.docs-grid > *,
.glossary-grid > *,
.objects-grid > *,
.rules-grid > *,
.events-grid > *,
.questions-grid > * {
  min-width: 0;
}

.scenarios-grid {
  grid-template-columns: minmax(0, 1.28fr) minmax(360px, .72fr);
}

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

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

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

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

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

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

.filters.compact {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 150px 90px 130px;
  gap: 6px;
  margin-bottom: 8px;
}

.glossary-filters {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px 136px;
  gap: 6px;
  margin-bottom: 8px;
}

.objects-filters,
.rules-filters,
.events-filters,
.questions-filters {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px 136px;
  gap: 6px;
  margin-bottom: 8px;
}

.questions-filters {
  grid-template-columns: minmax(0, 1fr) 140px 90px;
}

.archive-toggle {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--paper);
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

.archive-toggle input {
  width: 14px;
  height: 14px;
  margin: 0;
}

.table-wrap {
  max-height: 660px;
  max-width: 100%;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.doc-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--paper);
  font-size: 12px;
}

.doc-table th,
.doc-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  line-height: 1.35;
}

.doc-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f1eadc;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
}

.dense-table tbody tr {
  cursor: pointer;
}

.dense-table tbody tr:hover,
.dense-table tbody tr.active {
  background: #fff9d9;
}

.scenario-title {
  display: block;
  max-width: 360px;
  color: var(--ink);
  font-weight: 850;
}

.scenario-sub {
  display: block;
  max-width: 360px;
  margin-top: 3px;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scenario-editor {
  position: sticky;
  top: 104px;
  max-height: calc(100vh - 126px);
  overflow: auto;
}

.scenario-form,
.comment-form {
  display: grid;
  gap: 9px;
}

.simple-steps-field {
  min-height: 140px;
  border-color: #d7aa00;
  background: #fff9d9;
  color: var(--ink);
  line-height: 1.45;
}

.form-grid.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.comments-panel {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.comments-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.comment {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff9d9;
}

.comment strong {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
}

.comment p {
  margin: 0;
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1.42;
  white-space: pre-wrap;
}

.comment time {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
}

.docs-list-panel {
  position: sticky;
  top: 104px;
}

.glossary-list-panel {
  position: sticky;
  top: 104px;
}

.object-list-panel {
  position: sticky;
  top: 104px;
}

.rule-list-panel,
.event-list-panel,
.question-list-panel {
  position: sticky;
  top: 104px;
}

.docs-list {
  display: grid;
  gap: 7px;
  max-height: 650px;
  margin-top: 10px;
  overflow: auto;
}

.doc-item,
.glossary-item,
.object-item,
.rule-item,
.event-item,
.question-item {
  padding: 9px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--paper);
  text-align: left;
}

.doc-item.active,
.glossary-item.active,
.object-item.active,
.rule-item.active,
.event-item.active,
.question-item.active {
  border-color: var(--ink);
  background: var(--yellow-soft);
}

.doc-item strong,
.glossary-item strong,
.object-item strong,
.rule-item strong,
.event-item strong,
.question-item strong {
  display: block;
  color: var(--ink);
  font-size: 12px;
}

.doc-item span,
.glossary-item span,
.object-item span,
.rule-item span,
.event-item span,
.question-item span {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.glossary-list {
  display: grid;
  gap: 7px;
  max-height: 650px;
  overflow: auto;
}

.object-list {
  display: grid;
  gap: 7px;
  max-height: 650px;
  overflow: auto;
}

.rule-list,
.event-list,
.question-list {
  display: grid;
  gap: 7px;
  max-height: 650px;
  overflow: auto;
}

.glossary-item p,
.object-item p,
.rule-item p,
.event-item p,
.question-item p {
  display: -webkit-box;
  margin: 6px 0 0;
  overflow: hidden;
  color: var(--ink-2);
  font-size: 12px;
  line-height: 1.35;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.is-archived-item {
  border-style: dashed;
  background: #f7f3ea;
  opacity: .82;
}

.is-archived-chip {
  border-style: dashed;
  background: #f7f3ea;
  color: var(--muted);
}

.glossary-editor {
  position: sticky;
  top: 104px;
  max-height: calc(100vh - 126px);
  overflow: auto;
}

.object-editor {
  position: sticky;
  top: 104px;
  max-height: calc(100vh - 126px);
  overflow: auto;
}

.rule-editor,
.event-editor,
.question-editor {
  position: sticky;
  top: 104px;
  max-height: calc(100vh - 126px);
  overflow: auto;
}

.glossary-editor .status-pill,
.object-editor .status-pill,
.rule-editor .status-pill,
.event-editor .status-pill,
.question-editor .status-pill {
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.glossary-form,
.object-form,
.rule-form,
.event-form,
.question-form {
  display: grid;
  gap: 9px;
}

.term-definition-field {
  min-height: 96px;
  border-color: #94cdb1;
  background: #f3fbf6;
  line-height: 1.45;
}

.domain-meaning-field {
  min-height: 104px;
  border-color: #94cdb1;
  background: #f3fbf6;
  color: var(--ink);
  line-height: 1.45;
}

.rule-statement-field {
  min-height: 108px;
  border-color: #d7aa00;
  background: #fff9d9;
  color: var(--ink);
  line-height: 1.45;
}

.event-trigger-field {
  min-height: 108px;
  border-color: #8fb7e7;
  background: #f4f8ff;
  color: var(--ink);
  line-height: 1.45;
}

.question-short-field,
.question-full-field,
.question-answer-field {
  color: var(--ink);
  line-height: 1.45;
}

.question-short-field {
  min-height: 70px;
  border-color: #d7aa00;
  background: #fff9d9;
  font-weight: 800;
}

.question-full-field {
  min-height: 120px;
  border-color: #94cdb1;
  background: #f3fbf6;
}

.question-answer-field {
  min-height: 156px;
  padding-right: 48px;
  border-color: #8fb7e7;
  background: #f4f8ff;
}

.voice-textarea-control {
  position: relative;
}

.voice-textarea-control .voice-button {
  position: absolute;
  right: 8px;
  bottom: 8px;
  background: rgba(255, 253, 248, .92);
}

.glossary-scenario-refs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 26px;
}

.object-ref-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 26px;
}

.event-ref-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 26px;
}

.scenario-history-panel {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, .7);
}

.scenario-history-chip {
  background: #f3fbf6;
  color: #12563b;
}

.rule-ref-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 26px;
}

.scenario-ref-chip,
.object-ref-chip,
.event-ref-chip,
.rule-ref-chip {
  display: inline-flex;
  max-width: 240px;
  min-height: 24px;
  align-items: center;
  padding: 0 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #f4f6ff;
  color: #244caa;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

button.scenario-ref-chip:hover,
button.object-ref-chip:hover,
button.event-ref-chip:hover,
button.rule-ref-chip:hover {
  border-color: #244caa;
  background: #e5ecff;
}

.reference-tooltip {
  position: fixed;
  z-index: 5000;
  width: min(360px, calc(100vw - 16px));
  padding: 12px 13px;
  border: 1px solid #cbbfa9;
  border-radius: 8px;
  background: rgba(255, 253, 248, .98);
  box-shadow: 0 14px 34px rgba(45, 42, 36, .18);
  color: var(--ink);
  pointer-events: none;
}

.reference-tooltip[hidden] {
  display: none;
}

.reference-tooltip-kind {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.reference-tooltip-title {
  display: block;
  font-size: 14px;
  line-height: 1.25;
}

.reference-tooltip-meta {
  margin: 6px 0 0;
  color: #7b7367;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.35;
}

.reference-tooltip-description {
  margin: 8px 0 0;
  color: #3d3932;
  font-size: 12px;
  font-weight: 650;
  line-height: 1.45;
}

.doc-content {
  max-height: 690px;
  margin: 0;
  padding: 12px;
  overflow: auto;
  border: 1px solid #2d2a24;
  border-radius: 7px;
  background: #181713;
  color: #fffdf8;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.48;
  white-space: pre-wrap;
}

.corrections-panel {
  max-width: 980px;
  margin: 0 auto;
}

.matrix-panel {
  display: grid;
  gap: 12px;
}

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

.matrix-summary-card {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--paper);
}

.matrix-summary-card strong {
  display: block;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 18px;
}

.matrix-summary-card span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.matrix-filters {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 190px 90px;
  gap: 6px;
}

.matrix-table-wrap {
  max-height: 690px;
}

.matrix-table {
  min-width: 1120px;
}

.matrix-table th:nth-child(1),
.matrix-table td:nth-child(1) {
  width: 96px;
}

.matrix-table th:nth-child(3),
.matrix-table th:nth-child(4),
.matrix-table th:nth-child(5) {
  width: 210px;
}

.matrix-id-button {
  min-height: 26px;
  padding: 0 8px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: var(--yellow-soft);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 900;
}

.matrix-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.matrix-chip,
.matrix-empty {
  display: inline-flex;
  max-width: 150px;
  min-height: 23px;
  align-items: center;
  padding: 0 7px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #f4f6ff;
  color: #244caa;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

button.matrix-chip:hover,
.matrix-id-button:hover {
  border-color: #244caa;
  background: #e5ecff;
}

.matrix-empty {
  background: rgba(246, 243, 236, .72);
  color: var(--muted);
}

.corrections-list {
  display: grid;
  gap: 10px;
}

.correction-card,
.empty-state {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--paper);
}

.empty-state {
  padding: 18px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.correction-card {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.correction-head {
  display: flex;
  gap: 12px;
  align-items: start;
  justify-content: space-between;
}

.correction-block {
  padding: 9px 10px;
  border: 1px solid rgba(217, 207, 188, .82);
  border-radius: 7px;
  background: rgba(246, 243, 236, .72);
}

.correction-block.client {
  background: #fff9d9;
}

.correction-block strong {
  display: block;
  margin-bottom: 4px;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
}

.correction-block p {
  margin: 0;
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1.42;
  white-space: pre-wrap;
}

.correction-analysis {
  padding: 10px;
  border: 1px solid rgba(47, 96, 215, .18);
  border-radius: 7px;
  background: #f4f6ff;
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1.45;
}

.correction-analysis.markdown-body h3,
.correction-analysis.markdown-body h4,
.correction-analysis.markdown-body h5,
.correction-analysis.markdown-body strong {
  color: var(--ink);
}

.correction-analysis.markdown-body code {
  color: #244caa;
  background: rgba(47, 96, 215, .08);
  border-color: rgba(47, 96, 215, .18);
}

.login-body {
  min-width: 320px;
}

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

.login-card {
  width: min(460px, 100%);
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, .96);
  box-shadow: var(--shadow-soft);
}

.login-copy {
  margin: 16px 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

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

.form-error {
  margin: 0;
  color: var(--red);
  font-size: 13px;
  font-weight: 800;
}

[hidden] {
  display: none !important;
}

@media (max-width: 980px) {
  body[data-view="agent"] {
    overflow: hidden;
  }

  .page-shell {
    width: min(100% - 24px, 760px);
    padding: 12px 0 18px;
  }

  body[data-view="agent"] .page-shell {
    height: 100dvh;
    min-height: 0;
    padding-bottom: 12px;
  }

  .flow-header {
    top: 8px;
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 12px;
  }

  .brand-line {
    align-items: flex-start;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
    box-shadow: 3px 3px 0 var(--ink);
    font-size: 16px;
  }

  h1 {
    font-size: 20px;
  }

  .subtitle {
    font-size: 12px;
  }

  .header-actions {
    justify-content: flex-start;
    flex-wrap: nowrap;
    margin: 0 -2px;
    padding: 1px 2px 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .nav-pill {
    flex: 0 0 auto;
  }

  .agent-layout,
  .scenarios-grid,
  .glossary-grid,
  .objects-grid,
  .rules-grid,
  .events-grid,
  .questions-grid,
  .docs-grid {
    grid-template-columns: 1fr;
  }

  .agent-layout {
    position: relative;
    height: 100%;
    min-height: 0;
  }

  .chat-sidebar,
  .terminal-panel {
    min-height: 0;
  }

  .chat-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 45;
    width: min(330px, calc(100vw - 46px));
    padding: 12px;
    border-radius: 0 var(--radius) var(--radius) 0;
    transform: translateX(-110%);
    transition: transform .18s ease;
  }

  .chat-list {
    max-height: none;
    overflow: auto;
  }

  .terminal-panel {
    height: 100%;
    min-height: 0;
  }

  .messages {
    max-height: none;
  }

  #agentView.chat-drawer-open::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 44;
    background: rgba(21, 19, 15, .22);
  }

  #agentView.chat-drawer-open .chat-sidebar {
    transform: translateX(0);
  }

  .chat-menu-button,
  .chat-new-mobile,
  .chat-close-button {
    display: inline-flex;
  }

  .scenario-editor,
  .docs-list-panel,
  .glossary-list-panel,
  .object-list-panel,
  .rule-list-panel,
  .event-list-panel,
  .question-list-panel,
  .glossary-editor,
  .object-editor,
  .rule-editor,
  .event-editor,
  .question-editor {
    position: static;
    max-height: none;
  }

  .table-wrap {
    max-height: 460px;
  }

  .doc-table {
    min-width: 720px;
  }

  .scenario-title,
  .scenario-sub {
    max-width: 300px;
  }

  .glossary-list,
  .object-list,
  .rule-list,
  .event-list,
  .question-list,
  .docs-list {
    max-height: 430px;
  }

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

  .corrections-panel {
    max-width: none;
  }
}

@media (min-width: 701px) and (max-width: 980px) {
  body[data-view="agent"] {
    overflow: auto;
  }

  .agent-layout {
    grid-template-columns: 260px minmax(0, 1fr);
  }

  .chat-sidebar {
    position: static;
    width: auto;
    border-radius: var(--radius);
    transform: none;
    transition: none;
  }

  .chat-menu-button,
  .chat-new-mobile,
  .chat-close-button {
    display: none;
  }
}

@media (max-width: 640px) {
  body {
    background-size: 22px 22px;
  }

  .page-shell {
    width: min(100% - 16px, 520px);
    padding-top: 8px;
  }

  body[data-view="agent"] .page-shell {
    width: 100%;
    padding: 8px 8px 10px;
  }

  .flow-header {
    top: 6px;
    padding: 10px;
  }

  .brand-line {
    gap: 10px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    font-size: 14px;
  }

  .eyebrow {
    font-size: 10px;
  }

  h1 {
    font-size: 19px;
  }

  h2 {
    font-size: 17px;
  }

  .subtitle {
    max-width: 100%;
    font-size: 12px;
  }

  .nav-pill,
  .button,
  .icon-button {
    min-height: 32px;
    font-size: 12px;
  }

  .nav-pill,
  .button {
    padding: 0 10px;
  }

  .doc-section {
    padding: 12px;
  }

  body[data-view="agent"] .flow-header {
    position: relative;
    top: 0;
    margin-bottom: 8px;
    border-radius: 0 0 var(--radius) var(--radius);
  }

  .panel-head,
  .terminal-head,
  .panel-subhead,
  .correction-head {
    align-items: flex-start;
  }

  .terminal-panel {
    min-height: 0;
    padding: 8px;
  }

  .terminal-head {
    align-items: center;
    margin-bottom: 0;
    padding: 8px;
  }

  .terminal-head h2 {
    overflow: hidden;
    font-size: 15px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .messages {
    max-height: none;
    padding: 14px 8px;
  }

  .message {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .message-sources,
  .message-actions,
  .feedback-form {
    grid-column: 1;
  }

  .composer {
    grid-template-columns: minmax(0, 1fr) 34px 34px;
    padding: 7px;
  }

  .composer textarea {
    max-height: 140px;
    overflow: auto;
  }

  .feedback-row {
    display: grid;
    grid-template-columns: 1fr;
  }

  .filters.compact,
  .glossary-filters,
  .objects-filters,
  .rules-filters,
  .events-filters,
  .questions-filters,
  .matrix-filters {
    display: flex;
    gap: 6px;
    margin: 0 -2px 8px;
    padding: 0 2px 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .filters.compact input,
  .glossary-filters input,
  .objects-filters input,
  .rules-filters input,
  .events-filters input,
  .questions-filters input,
  .matrix-filters input {
    flex: 1 0 188px;
  }

  .filters.compact select,
  .glossary-filters select,
  .objects-filters select,
  .rules-filters select,
  .events-filters select,
  .questions-filters select,
  .matrix-filters select {
    width: auto;
    min-width: 86px;
    flex: 0 0 auto;
  }

  #roleFilter {
    max-width: 136px;
  }

  #statusFilter,
  #glossarySectionFilter,
  #objectContextFilter,
  #ruleCategoryFilter,
  #eventContextFilter,
  #questionStatusFilter,
  #matrixGapFilter {
    max-width: 142px;
  }

  .form-grid.two {
    grid-template-columns: 1fr;
  }

  .table-wrap {
    max-height: 390px;
  }

  .doc-table {
    min-width: 680px;
    font-size: 11px;
  }

  .matrix-table {
    min-width: 980px;
  }

  .doc-table th,
  .doc-table td {
    padding: 8px;
  }

  .scenario-title,
  .scenario-sub {
    max-width: 260px;
  }

  .simple-steps-field {
    min-height: 120px;
  }

  .glossary-list,
  .object-list,
  .rule-list,
  .event-list,
  .question-list,
  .docs-list {
    max-height: 360px;
  }

  .glossary-editor .status-pill,
  .object-editor .status-pill,
  .rule-editor .status-pill,
  .event-editor .status-pill,
  .question-editor .status-pill {
    max-width: 140px;
  }

  .term-definition-field,
  .domain-meaning-field,
  .rule-statement-field,
  .event-trigger-field,
  .question-full-field {
    min-height: 88px;
  }

  .scenario-ref-chip,
  .object-ref-chip,
  .event-ref-chip,
  .rule-ref-chip,
  .matrix-chip {
    max-width: 150px;
  }

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

  .detail-close {
    display: inline-flex;
  }

  .scenario-editor,
  .glossary-editor,
  .object-editor,
  .rule-editor,
  .event-editor,
  .question-editor {
    display: none;
    position: fixed;
    inset: 86px 8px 8px;
    z-index: 40;
    max-height: calc(100dvh - 94px);
    overflow: auto;
    border-color: var(--ink);
    background: rgba(255, 253, 248, .98);
    box-shadow: 0 18px 42px rgba(21, 19, 15, .22);
  }

  #scenariosView.detail-open::before,
  #glossaryView.detail-open::before,
  #objectsView.detail-open::before,
  #rulesView.detail-open::before,
  #eventsView.detail-open::before,
  #questionsView.detail-open::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 39;
    background: rgba(21, 19, 15, .18);
  }

  #scenariosView.detail-open .scenario-editor,
  #glossaryView.detail-open .glossary-editor,
  #objectsView.detail-open .object-editor,
  #rulesView.detail-open .rule-editor,
  #eventsView.detail-open .event-editor,
  #questionsView.detail-open .question-editor {
    display: block;
  }

  .scenario-editor .panel-head,
  .glossary-editor .panel-head,
  .object-editor .panel-head,
  .rule-editor .panel-head,
  .event-editor .panel-head,
  .question-editor .panel-head {
    position: sticky;
    top: -12px;
    z-index: 1;
    align-items: flex-start;
    margin: -12px -12px 10px;
    padding: 12px;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 253, 248, .98);
  }

  .scenario-editor .panel-head h2,
  .glossary-editor .panel-head h2,
  .object-editor .panel-head h2,
  .rule-editor .panel-head h2,
  .event-editor .panel-head h2,
  .question-editor .panel-head h2 {
    display: -webkit-box;
    max-height: 42px;
    overflow: hidden;
    line-height: 1.15;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }

  .scenario-editor .status-pill,
  .glossary-editor .status-pill,
  .object-editor .status-pill,
  .rule-editor .status-pill,
  .event-editor .status-pill,
  .question-editor .status-pill {
    display: none;
  }

  .scenario-form .button.primary,
  .glossary-form .button.primary,
  .object-form .button.primary,
  .rule-form .button.primary,
  .event-form .button.primary,
  .question-form .button.primary {
    width: 100%;
  }

  .login-shell {
    padding: 14px;
  }
}

/* Scenario catalog uses page scrolling for the table and a full reading/editing modal for details. */
body.modal-open {
  overflow: hidden;
}

#scenariosView .scenarios-grid {
  grid-template-columns: 1fr;
}

#scenariosView .table-wrap {
  max-height: none;
  overflow-x: auto;
  overflow-y: visible;
}

#scenariosView .doc-table {
  min-width: 980px;
}

#scenariosView .scenario-title,
#scenariosView .scenario-sub {
  max-width: 560px;
}

#scenariosView.detail-open::before {
  content: none !important;
}

#scenariosView .modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 39;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: rgba(21, 19, 15, .26);
}

#scenariosView.detail-open .modal-backdrop {
  display: block;
}

#scenariosView .scenario-editor {
  display: none;
  position: fixed;
  inset: 18px;
  z-index: 40;
  width: min(1240px, calc(100vw - 36px));
  max-height: calc(100dvh - 36px);
  margin: 0 auto;
  overflow: auto;
  border-color: var(--ink);
  background: rgba(255, 253, 248, .99);
  box-shadow: 0 22px 54px rgba(21, 19, 15, .24);
}

#scenariosView.detail-open .scenario-editor {
  display: block;
}

#scenariosView .scenario-editor .panel-head {
  position: sticky;
  top: -12px;
  z-index: 2;
  align-items: center;
  margin: -14px -14px 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 253, 248, .98);
  backdrop-filter: blur(10px);
}

#scenariosView .scenario-editor .panel-head h2 {
  display: block;
  max-width: 880px;
  max-height: none;
  overflow: visible;
  line-height: 1.12;
  font-family: var(--mono);
  font-size: 16px;
  -webkit-line-clamp: unset;
}

#scenariosView .scenario-editor .status-pill {
  display: inline-flex;
  margin-top: 0;
}

#scenariosView .scenario-editor .detail-close {
  display: inline-flex;
}

#scenariosView .scenario-form {
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
}

#scenariosView .scenario-form .form-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

#scenariosView .editable-label {
  gap: 4px;
  font-size: 10px;
}

#scenariosView .editable-field {
  width: 100%;
  min-height: 34px;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fffefa;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.38;
  text-transform: none;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  outline: none;
}

#scenariosView .editable-field:focus {
  border-color: #d7aa00;
  box-shadow: 0 0 0 3px rgba(255, 210, 31, .24);
}

#scenariosView .editable-field.is-readonly {
  background: #f7f1e5;
  color: var(--ink-2);
}

#scenariosView .editable-field-large {
  min-height: 118px;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.42;
}

#scenariosView .editable-field-tall {
  min-height: 76px;
}

#scenariosView .editable-field-code {
  min-height: 170px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 650;
  line-height: 1.42;
  white-space: pre-wrap;
}

#scenariosView .technical-details {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #f7f1e5;
}

#scenariosView .technical-details summary {
  padding: 8px 10px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
}

#scenariosView .technical-details[open] summary {
  border-bottom: 1px solid var(--border);
}

#scenariosView .technical-details .editable-label {
  padding: 8px;
}

#scenariosView .scenario-form .button.primary {
  min-height: 36px;
  margin-top: 2px;
  font-family: var(--mono);
}

@media (max-width: 700px) {
  #scenariosView .scenario-editor {
    inset: 8px;
    width: auto;
    max-height: calc(100dvh - 16px);
  }

  #scenariosView .scenario-form .form-grid.two {
    grid-template-columns: 1fr;
  }

  #scenariosView .editable-field {
    font-size: 12px;
  }

  #scenariosView .editable-field-large {
    min-height: 112px;
    font-size: 12px;
  }
}
