:root {
  --bg: #f7f7f4;
  --surface: #ffffff;
  --surface-alt: #f1f3f5;
  --text: #1f2328;
  --muted: #6b7280;
  --line: #dfe3e6;
  --accent: #1f6feb;
  --accent-soft: #dbeafe;
  --expert: #fff7df;
  --persona: #ecf5ff;
  --danger: #c2410c;
  --ok: #15803d;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #18191b;
    --surface: #232426;
    --surface-alt: #1e1f21;
    --text: #e8e8e8;
    --muted: #a3a3a3;
    --line: #373a3d;
    --accent: #60a5fa;
    --accent-soft: #1f3553;
    --expert: #3a321d;
    --persona: #1e2c3b;
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

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

.app-shell {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.mobile-icon-btn,
.mobile-title,
.mobile-drawer-head,
.mobile-settings-controls,
.drawer-backdrop {
  display: none;
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.top-tabs {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-alt);
  padding: 3px;
}

.top-tab {
  min-height: 30px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 5px 12px;
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
}

.top-tab.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.brand {
  font-weight: 700;
  white-space: nowrap;
}

.role-picker,
.session-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

select,
input {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-alt);
  color: var(--text);
  padding: 7px 9px;
}

.session-dropdown {
  position: relative;
  width: 310px;
  color: var(--text);
}

.session-trigger {
  width: 100%;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-alt);
  color: var(--text);
  padding: 7px 9px;
  cursor: pointer;
}

.session-trigger span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-chevron {
  flex: 0 0 auto;
  color: var(--muted);
}

.session-menu-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 140;
  width: min(380px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.14);
  overflow: hidden;
}

.session-current-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.session-current-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: text;
  font-weight: 700;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-inline-input {
  flex: 1;
  min-width: 0;
}

.btn.compact {
  padding: 6px 9px;
  font-size: 13px;
}

.session-menu-items {
  max-height: 280px;
  overflow-y: auto;
  padding: 6px;
}

.session-menu-item {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 3px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  padding: 9px;
  cursor: pointer;
  text-align: left;
}

.session-menu-item:hover,
.session-menu-item.active {
  border-color: var(--line);
  background: var(--surface-alt);
}

.session-option-title {
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-option-meta {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
}

.dot.busy {
  background: #f59e0b;
}

.dot.error {
  background: #ef4444;
}

.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  padding: 7px 12px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn:hover {
  background: var(--surface-alt);
}

.btn.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

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

.main {
  flex: 1;
  min-height: 0;
  display: flex;
}

.tab-view[hidden] {
  display: none;
}

.scout-view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.manual-view {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  background: var(--bg);
}

.chat-pane {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 28px;
  text-align: center;
}

.welcome-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--accent-soft);
  display: grid;
  place-items: center;
  font-size: 28px;
}

.welcome h1 {
  font-size: 22px;
  margin: 0;
}

.welcome p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
  max-width: 520px;
}

.messages {
  flex: 1;
  overflow-y: auto;
  display: none;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
}

.message {
  display: flex;
  gap: 10px;
  max-width: 86%;
}

.message.expert {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message.persona {
  align-self: flex-start;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.message.expert .avatar {
  background: var(--expert);
}

.message.persona .avatar {
  background: var(--accent-soft);
}

.bubble-meta {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.bubble {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 13px;
  line-height: 1.65;
  white-space: normal;
  word-break: break-word;
}

.message.expert .bubble {
  background: var(--surface);
}

.message.persona .bubble {
  background: var(--persona);
  white-space: pre-wrap;
}

.thought-card {
  margin-bottom: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-alt);
  overflow: hidden;
  white-space: normal;
}

.thought-card summary {
  cursor: pointer;
  padding: 4px 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  user-select: none;
}

.thought-body {
  padding: 0 8px 7px;
}

.thought-display,
.thought-editor {
  width: 100%;
  color: var(--text);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.thought-display {
  cursor: text;
}

.thought-editor {
  min-height: 38px;
  max-height: 110px;
  margin-top: 1px;
  padding: 7px 8px;
}

.thought-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 4px;
}

.thought-save {
  display: none;
}

.thought-card.editing .thought-save {
  display: inline-flex;
}

.add-thought-btn {
  margin-bottom: 6px;
  border: 1px dashed var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: var(--radius);
  padding: 3px 7px;
  cursor: pointer;
  font-size: 12px;
  line-height: 1.4;
}

.add-thought-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.message.persona .thought-card,
.message.persona .add-thought-btn {
  margin-top: 6px;
  margin-bottom: 0;
}

.message-content {
  white-space: pre-wrap;
  word-break: break-word;
}

.typing {
  display: flex;
  gap: 4px;
  padding: 7px 0;
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: pulse 1.2s infinite;
}

.typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes pulse {
  0%,
  70%,
  100% {
    opacity: 0.35;
    transform: scale(0.8);
  }
  35% {
    opacity: 1;
    transform: scale(1);
  }
}

.composer {
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding: 12px 18px;
}

.history-banner {
  margin-bottom: 10px;
  color: var(--danger);
  font-size: 13px;
}

.thought-row {
  margin-bottom: 10px;
}

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

.composer-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

textarea {
  width: 100%;
  min-height: 44px;
  max-height: 140px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-alt);
  color: var(--text);
  padding: 11px 13px;
  line-height: 1.55;
}

#thoughtInput {
  min-height: 58px;
  max-height: 120px;
  font-size: 13px;
}

textarea:focus,
select:focus,
input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.side-panel {
  width: 330px;
  border-left: 1px solid var(--line);
  background: var(--surface);
  overflow-y: auto;
  flex-shrink: 0;
}

.panel-section {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.panel-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.panel-section h2,
.panel-section h3 {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.persona-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.persona-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface-alt);
  color: var(--muted);
  font-size: 20px;
  transition: background 260ms ease, color 260ms ease;
}

.persona-avatar.revealed {
  background: var(--accent-soft);
  color: var(--text);
}

.persona-name {
  font-weight: 700;
}

.tag {
  display: inline-block;
  margin-top: 4px;
  border-radius: 999px;
  padding: 2px 8px;
  color: var(--accent);
  background: var(--accent-soft);
  font-size: 12px;
}

.secret-pill {
  display: inline-flex;
  min-width: 28px;
  max-width: 100%;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  background: var(--surface);
  color: var(--muted);
  line-height: 1.45;
  transition: background 260ms ease, border-color 260ms ease, color 260ms ease, opacity 260ms ease;
}

.stat-value.secret-pill {
  width: fit-content;
}

.secret-pill.locked,
.secret-paragraph.locked {
  color: var(--muted);
  background: var(--surface-alt);
}

.secret-pill.revealed {
  justify-content: flex-start;
  border-color: var(--accent-soft);
  background: var(--accent-soft);
  color: var(--accent);
}

.secret-paragraph {
  min-height: 34px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 10px;
  background: var(--surface-alt);
  color: var(--muted);
  line-height: 1.7;
  transition: background 260ms ease, border-color 260ms ease, color 260ms ease, opacity 260ms ease;
}

.secret-paragraph.revealed {
  border-color: var(--accent-soft);
  background: var(--surface);
  color: var(--muted);
}

.newly-revealed {
  animation: revealFade 520ms ease-out;
}

.detector-status {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-alt);
  color: var(--muted);
  padding: 9px 10px;
  font-size: 13px;
}

.scout-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--surface), var(--surface-alt));
}

.scout-head h2 {
  margin: 0 0 3px;
  font-size: 18px;
  letter-spacing: 0;
}

.scout-head p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.scout-counter {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  padding: 5px 10px;
  font-weight: 800;
  font-size: 13px;
}

.scout-counter.complete {
  border-color: rgba(21, 128, 61, 0.35);
  background: rgba(21, 128, 61, 0.1);
  color: var(--ok);
}

.scout-section h3 {
  text-transform: none;
  letter-spacing: 0;
}

.scout-fields {
  display: grid;
  gap: 2px;
}

.scout-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 34px;
  padding: 6px 0;
  border-top: 1px solid rgba(127, 127, 127, 0.08);
  font-size: 13px;
}

.scout-field:first-child {
  border-top: 0;
}

.scout-field span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
}

.scout-field strong,
.persona-header .secret-pill {
  min-width: 36px;
  max-width: 190px;
  overflow-wrap: anywhere;
  text-align: right;
  font-weight: 600;
  line-height: 1.45;
}

.scout-field.state-hidden strong,
.secret-pill.locked {
  color: var(--muted);
  font-style: italic;
  opacity: 0.7;
}

.scout-field.state-unlocked strong,
.secret-pill.revealed {
  color: var(--text);
}

.scout-field.state-activated strong,
.secret-pill.activated {
  border-radius: 6px;
  background: rgba(21, 128, 61, 0.1);
  color: var(--ok);
  padding: 2px 7px;
}

.fear-box {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-alt);
  padding: 10px 11px;
  transition: border-color 260ms ease, background 260ms ease, color 260ms ease;
}

.fear-box p {
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
  font-size: 13px;
}

.fear-box.placeholder {
  opacity: 0.78;
}

.fear-box.revealed {
  border-color: rgba(194, 65, 12, 0.25);
  background: rgba(194, 65, 12, 0.08);
  animation: fearUnfold 520ms ease-out;
}

.fear-box.revealed p {
  color: var(--text);
}

@keyframes fearUnfold {
  from {
    opacity: 0.45;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes revealFade {
  from {
    opacity: 0.2;
    transform: translateY(3px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.scout-field.newly-revealed,
.newly-revealed {
  animation: revealFade 680ms ease-out;
}

.manual-body {
  width: min(860px, 100%);
  margin: 0 auto;
  padding: 28px 20px 64px;
}

.manual-body section {
  margin-bottom: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 16px 18px;
}

.manual-body h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
  font-size: 18px;
}

.manual-body .num {
  color: var(--accent);
  font-weight: 800;
}

.manual-body h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.manual-body p,
.manual-body li {
  color: var(--muted);
  line-height: 1.75;
  font-size: 14px;
}

.manual-body ul {
  margin: 0;
  padding-left: 20px;
}

.manual-body code {
  border-radius: 5px;
  background: var(--surface-alt);
  padding: 1px 5px;
  color: var(--text);
}

.manual-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 13px;
}

.manual-body th {
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  padding: 8px 10px;
  text-align: left;
}

.manual-body td {
  border-bottom: 1px solid rgba(127, 127, 127, 0.12);
  color: var(--text);
  line-height: 1.55;
  padding: 9px 10px;
  vertical-align: top;
}

.manual-body tr:last-child td {
  border-bottom: 0;
}

.manual-body .tag {
  margin-top: 0;
}

.manual-cover {
  margin-bottom: 20px;
  border-bottom: 1px solid var(--line);
  padding: 28px 0 24px;
  text-align: center;
}

.manual-cover .welcome-icon {
  margin: 0 auto 12px;
}

.manual-cover h1 {
  margin: 0 0 4px;
  font-size: 28px;
}

.manual-cover p {
  margin: 0;
  color: var(--muted);
}

.manual-meta {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.manual-meta span {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  padding: 4px 10px;
  font-size: 13px;
}

.manual-layers {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.manual-layers .layer-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-alt);
  padding: 12px 14px;
}

.layer-card h4 {
  margin: 0 0 6px;
  font-size: 14px;
}

.layer-card ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.layer-card li {
  color: var(--muted);
  font-size: 13px;
  padding: 2px 0;
}

.layer-l1 {
  border-left: 3px solid var(--accent);
}

.layer-l2 {
  border-left: 3px solid #f59e0b;
}

.layer-l3 {
  border-left: 3px solid #60a5fa;
}

.layer-l4 {
  border-left: 3px solid var(--ok);
}

.manual-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-alt);
  margin: 12px 0;
  padding: 14px 16px;
}

.manual-card ol {
  margin: 0;
  padding-left: 20px;
}

.rule-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
}

.rule-list li {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid rgba(127, 127, 127, 0.12);
  padding: 7px 0;
}

.rule-list li:last-child {
  border-bottom: 0;
}

.rule-list .icon {
  flex: 0 0 22px;
}

.faq-item {
  margin-bottom: 12px;
}

.faq-item:last-child {
  margin-bottom: 0;
}

.faq-q {
  margin-bottom: 2px;
  color: var(--accent) !important;
  font-weight: 700;
}

.faq-a {
  margin-top: 0;
}

.manual-footer-note {
  border-top: 1px solid var(--line);
  color: var(--muted);
  margin-top: 28px;
  padding: 24px 0 0;
  text-align: center;
  line-height: 1.55;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat {
  background: var(--surface-alt);
  border-radius: var(--radius);
  padding: 9px;
}

.stat-label {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 3px;
}

.stat-value {
  font-weight: 700;
  font-size: 14px;
}

.priority {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.8;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  color: var(--surface);
  background: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 1000;
}

.dashboard-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 360px 1fr;
}

.mobile-dashboard-bar {
  display: none;
}

.session-list {
  border-right: 1px solid var(--line);
  background: var(--surface);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.list-head {
  padding: 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dashboard-debug-control {
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
}

.dashboard-debug-control input {
  width: 18px;
  height: 18px;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
}

.dashboard-debug-control small {
  margin-left: auto;
  color: var(--muted);
  font-size: 11px;
}

.session-items {
  overflow-y: auto;
  padding: 8px;
}

.session-item {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  padding: 11px;
  cursor: pointer;
}

.session-item:hover,
.session-item.active {
  background: var(--surface-alt);
  border-color: var(--line);
}

.session-title {
  font-weight: 700;
  margin-bottom: 6px;
}

.session-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.dashboard-main {
  min-width: 0;
  padding: 20px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

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

.card {
  padding: 14px;
}

.card .value {
  font-weight: 800;
  font-size: 22px;
  margin-top: 6px;
}

.panel {
  margin-bottom: 16px;
  overflow: hidden;
}

.panel-title {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  font-weight: 700;
}

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

.table th,
.table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

.table th {
  color: var(--muted);
  font-weight: 600;
  background: var(--surface-alt);
}

.content-cell {
  white-space: pre-wrap;
  line-height: 1.55;
  max-width: 560px;
}

.empty {
  padding: 36px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 860px) {
  .app-shell {
    min-height: 100dvh;
  }

  .topbar {
    min-height: 52px;
    align-items: center;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px;
  }

  .mobile-icon-btn {
    display: inline-flex;
    width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-size: 18px;
  }

  .mobile-title {
    display: flex;
    align-items: center;
    min-width: 0;
    flex: 1;
    justify-content: center;
  }

  .mobile-title .mobile-session-dropdown {
    width: min(100%, 360px);
  }

  .mobile-title .session-trigger {
    min-height: 36px;
    padding: 7px 10px;
  }

  .mobile-title .session-menu-panel {
    left: 50%;
    width: min(92vw, 380px);
    transform: translateX(-50%);
  }

  .topbar-left {
    display: none;
  }

  .top-tabs {
    order: 10;
    width: 100%;
    justify-content: center;
  }

  .top-tab {
    flex: 1;
  }

  .topbar-right {
    display: contents;
  }

  .topbar-right .status,
  .topbar-right #exportBtn {
    display: none;
  }

  .topbar-right #newBtn {
    width: auto;
    white-space: nowrap;
  }

  .main {
    overflow: hidden;
  }

  .chat-pane {
    min-height: 0;
  }

  .welcome {
    justify-content: flex-start;
    padding: 22px 14px;
  }

  .messages {
    padding: 14px 12px;
  }

  .message {
    max-width: 96%;
  }

  .drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 180;
    background: rgba(0, 0, 0, 0.26);
  }

  body.drawer-open .drawer-backdrop {
    display: block;
  }

  .side-panel {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 200;
    display: block;
    width: min(86vw, 340px);
    max-height: none;
    border-left: 0;
    border-right: 1px solid var(--line);
    border-top: 0;
    transform: translateX(-102%);
    transition: transform 0.18s ease;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.18);
  }

  body.drawer-open .side-panel {
    transform: translateX(0);
  }

  .mobile-drawer-head,
  .mobile-settings-controls {
    display: block;
  }

  .mobile-drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px;
    border-bottom: 1px solid var(--line);
  }

  .mobile-settings-controls select {
    width: 100%;
  }

  .panel-section {
    padding: 12px;
  }

  .panel-actions {
    grid-template-columns: 1fr;
  }

  .composer {
    padding: 10px 12px;
  }

  .composer-row {
    gap: 8px;
  }

  .composer-row .btn {
    min-width: 64px;
  }

  .dashboard-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
  }

  .mobile-dashboard-bar {
    position: sticky;
    top: 0;
    z-index: 60;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.06);
  }

  .mobile-dashboard-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }

  .mobile-dashboard-row .dashboard-debug-control {
    min-height: 32px;
  }

  .mobile-dashboard-bar select {
    width: 100%;
  }

  .mobile-dashboard-meta {
    overflow: hidden;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.4;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .session-list {
    display: none;
  }

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

  .dashboard-main {
    padding: 12px;
  }

  .panel {
    overflow-x: auto;
  }

  .manual-layers {
    grid-template-columns: 1fr;
  }

  .manual-body {
    padding: 18px 12px 48px;
  }

  .manual-body section {
    padding: 14px;
  }

  .manual-cover {
    padding-top: 18px;
  }
}

@media (max-width: 520px) {
  .btn {
    padding: 8px 10px;
  }

  .message {
    max-width: 100%;
  }

  .avatar {
    width: 28px;
    height: 28px;
  }

  .bubble {
    padding: 9px 11px;
  }

  .chat-input-row,
  .composer-row {
    align-items: stretch;
  }

  textarea {
    min-height: 46px;
  }
}

@media (max-height: 640px) and (max-width: 860px) {
  .welcome {
    gap: 10px;
    padding-top: 14px;
  }

  .welcome-icon {
    width: 44px;
    height: 44px;
    font-size: 22px;
  }

  .welcome h1 {
    font-size: 18px;
  }

  .side-panel {
    max-height: none;
  }
}

body.modal-open {
  overflow: hidden;
}

.persona-setup-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.5);
}

.persona-setup-backdrop[hidden] {
  display: none;
}

.persona-setup-dialog {
  display: flex;
  width: min(920px, 100%);
  height: min(860px, calc(100dvh - 40px));
  max-height: min(860px, calc(100dvh - 40px));
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.22);
}

.persona-setup-dialog form {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
}

.persona-setup-head,
.persona-setup-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
}

.persona-setup-head {
  flex: 0 0 auto;
  border-bottom: 1px solid var(--line);
}

.persona-setup-head h2,
.persona-form-section h3,
.runtime-debug-head h2,
.runtime-debug-section h3 {
  margin: 0;
  letter-spacing: 0;
}

.persona-setup-head h2 {
  font-size: 18px;
}

.persona-setup-head p,
.runtime-debug-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.persona-setup-unavailable {
  margin: auto 20px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.icon-btn {
  display: inline-grid;
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 22px;
}

.persona-setup-body {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.persona-form-section {
  min-width: 0;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.persona-form-section:nth-child(odd) {
  border-right: 1px solid var(--line);
}

.persona-form-section h3,
.persona-form-section > label:first-child {
  display: block;
  margin-bottom: 14px;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}

.persona-slider-grid {
  display: grid;
  gap: 14px;
}

.persona-range-field {
  display: grid;
  gap: 7px;
}

.persona-range-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.persona-range-label output {
  min-width: 42px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.persona-range-field input[type="range"],
.estimate-range {
  width: 100%;
  accent-color: var(--accent);
}

.compact-fields {
  display: grid;
  align-content: start;
  gap: 12px;
}

.compact-fields h3 {
  margin-bottom: 2px;
}

.compact-fields > label:not(.checkbox-field) {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.compact-fields select,
.persona-form-section textarea {
  width: 100%;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
}

.persona-tag-options {
  display: grid;
  gap: 12px;
}

.persona-tag-group {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.persona-tag-group legend {
  margin-bottom: 7px;
  padding: 0;
  color: var(--muted);
  font-size: 12px;
}

.persona-tag-group-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-check input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.tag-check span {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
}

.tag-check input:checked + span {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.persona-setup-actions {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  border-top: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 -6px 18px rgba(15, 23, 42, 0.06);
}

.persona-action-right {
  display: flex;
  gap: 10px;
}

.add-review-btn {
  display: block;
  margin: 7px 0 0;
  padding: 2px 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
}

.review-card {
  margin-top: 7px;
  border-top: 1px solid var(--line);
  white-space: normal;
}

.review-card summary {
  padding: 7px 0 4px;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
}

.review-body {
  padding: 4px 0 2px;
}

.review-feedback-field {
  display: grid;
  gap: 4px;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 11px;
}

.review-feedback-editor {
  min-height: 58px;
  max-height: 140px;
  padding: 7px 8px;
  resize: vertical;
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  line-height: 1.5;
}

.review-state-label {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
}

.estimate-grid {
  display: grid;
  gap: 4px;
}

.estimate-row {
  display: grid;
  grid-template-columns: 62px minmax(80px, 1fr) 34px auto;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  color: var(--muted);
  font-size: 11px;
}

.estimate-range {
  width: 100%;
  height: 20px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  accent-color: var(--accent);
}

.estimate-row output {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.estimate-na {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.estimate-actions {
  display: flex;
  min-height: 34px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
}

.estimate-mae {
  color: var(--muted);
  font-size: 11px;
}

.review-save {
  padding: 5px 10px;
  font-size: 12px;
}

.runtime-debug-panel {
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.runtime-debug-head,
.runtime-debug-section,
.runtime-prompt-details {
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

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

.runtime-debug-head h2 {
  font-size: 16px;
}

.debug-badge {
  padding: 3px 7px;
  border: 1px solid #b91c1c;
  border-radius: 999px;
  color: #b91c1c;
  font-size: 10px;
  font-weight: 700;
}

.runtime-debug-section h3 {
  margin-bottom: 10px;
  font-size: 12px;
}

.runtime-persona-parameters {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-alt);
}

.runtime-persona-parameters h3 {
  margin: 0 0 10px;
  font-size: 12px;
}

.session-persona-parameters {
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.session-persona-parameters > .btn {
  width: 100%;
}

.session-persona-parameters > div {
  margin-top: 12px;
}

.runtime-persona-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.runtime-persona-group {
  min-width: 0;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
}

.runtime-persona-group h4 {
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.runtime-persona-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 3px 0;
  font-size: 11px;
}

.runtime-persona-row span {
  min-width: 0;
  color: var(--muted);
}

.runtime-persona-row strong {
  min-width: 0;
  color: var(--text);
  text-align: right;
  overflow-wrap: anywhere;
}

.runtime-persona-constraints {
  margin: 0;
  color: var(--text);
  font-size: 11px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

@media (max-width: 520px) {
  .runtime-debug-head {
    align-items: center;
  }

  .runtime-persona-grid {
    grid-template-columns: 1fr;
  }
}

.runtime-state-grid {
  display: grid;
  gap: 9px;
}

.runtime-state-item > div:first-child {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
}

.runtime-state-item strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.runtime-state-track {
  height: 5px;
  margin-top: 4px;
  overflow: hidden;
  border-radius: 3px;
  background: var(--surface-alt);
}

.runtime-state-track i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.runtime-event-list,
.runtime-mechanism-list {
  display: grid;
  gap: 7px;
}

.runtime-event,
.mechanism-row {
  display: grid;
  gap: 3px;
  padding: 7px 8px;
  border-left: 3px solid var(--line);
  background: var(--surface-alt);
  font-size: 11px;
}

.runtime-event span {
  color: var(--muted);
}

.mechanism-row {
  grid-template-columns: 72px minmax(0, 1fr);
}

.mechanism-row span {
  color: var(--muted);
}

.mechanism-row.allowed {
  border-left-color: var(--ok);
}

.mechanism-row.blocked {
  border-left-color: var(--danger);
}

.mechanism-row.objection {
  border-left-color: var(--accent);
}

.runtime-prompt-details summary {
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
}

.runtime-prompt-details pre {
  max-height: 300px;
  overflow: auto;
  margin: 10px 0 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface-alt);
  color: var(--text);
  font-size: 11px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.debug-empty {
  color: var(--muted);
  font-size: 11px;
}

.dashboard-two-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.constraint-warning {
  padding: 10px 12px;
  border-bottom: 1px solid #f0c9c2;
  background: #fff3f0;
  color: #9c3425;
  font-size: 13px;
}

.compact-table th {
  width: 150px;
}

@media (max-width: 860px) {
  .persona-setup-backdrop {
    align-items: end;
    padding: 0;
  }

  .persona-setup-dialog {
    width: 100%;
    height: 94dvh;
    max-height: 94dvh;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 8px 8px 0 0;
  }

  .persona-setup-body {
    grid-template-columns: 1fr;
  }

  .persona-form-section:nth-child(odd) {
    border-right: 0;
  }

  .persona-setup-head,
  .persona-setup-actions,
  .persona-form-section {
    padding-right: 14px;
    padding-left: 14px;
  }

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

@media (max-width: 520px) {
  .persona-setup-actions {
    align-items: stretch;
  }

  .persona-action-right {
    flex: 1;
  }

  .persona-action-right .btn {
    flex: 1;
  }

  .estimate-row {
    grid-template-columns: 58px minmax(64px, 1fr) 32px auto;
  }
}
