:root {
  --surface: #fbf9f4;
  --surface-dim: #dbdad5;
  --surface-lowest: #ffffff;
  --surface-low: #f5f3ee;
  --surface-mid: #f0eee9;
  --surface-high: #eae8e3;
  --surface-highest: #e4e2dd;
  --ink: #1b1c19;
  --ink-soft: #444748;
  --muted: #747878;
  --outline: #c4c7c7;
  --primary: #000000;
  --sage: #56624f;
  --sage-soft: #d7e4cc;
  --earth: #aa7863;
  --earth-soft: #ffdbcd;
  --error: #ba1a1a;
  --shadow-soft: 0 10px 40px rgba(27, 28, 25, 0.05);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--surface);
  color: var(--ink);
  font-family: "Work Sans", Inter, ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0;
  overflow: hidden;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(27, 28, 25, 0.38);
  backdrop-filter: blur(10px);
}

.auth-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  padding: 28px;
  border: 1px solid rgba(196, 199, 199, 0.55);
  border-radius: 24px;
  background: var(--surface-lowest);
  box-shadow: 0 28px 80px rgba(27, 28, 25, 0.2);
}

.auth-panel h1 {
  margin-bottom: 0;
}

.auth-intro,
.auth-message {
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.45;
}

.auth-message {
  min-height: 22px;
  color: var(--error);
  font-size: 13px;
}

.auth-panel label {
  display: grid;
  gap: 7px;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.auth-panel input {
  width: 100%;
  min-height: 44px;
  border: 1px solid rgba(116, 120, 120, 0.35);
  border-radius: 14px;
  background: var(--surface-low);
  color: var(--ink);
  padding: 10px 12px;
  letter-spacing: 0;
  text-transform: none;
}

.app-shell.auth-blocked {
  filter: blur(4px);
  pointer-events: none;
}

button,
textarea,
input {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--primary);
  color: var(--surface-lowest);
  padding: 9px 16px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

button.secondary,
.operator-toggle {
  background: var(--surface-lowest);
  border-color: rgba(116, 120, 120, 0.24);
  color: var(--ink-soft);
}

button:hover {
  transform: translateY(-1px);
}

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

h1,
h2,
h3 {
  font-family: "Libre Caslon Text", Georgia, serif;
  font-weight: 400;
}

h1 {
  margin-bottom: 0;
  font-size: 28px;
  line-height: 34px;
}

h2 {
  margin: 0;
  font-size: 24px;
  line-height: 30px;
}

h3 {
  margin: 0 0 6px;
  font-size: 22px;
  line-height: 28px;
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 272px minmax(390px, 1fr) minmax(360px, 460px);
  gap: 0;
  overflow: hidden;
}

.rail,
.chat-column,
.body-panel {
  min-width: 0;
}

.rail {
  height: 100vh;
  overflow: hidden;
  padding: 32px 16px;
  border-right: 1px solid rgba(196, 199, 199, 0.5);
  background: var(--surface-low);
}

.body-panel {
  height: 100vh;
  overflow: auto;
  display: grid;
  gap: 20px;
  align-content: start;
  padding: 32px 24px;
  border-left: 1px solid rgba(196, 199, 199, 0.45);
  background: rgba(245, 243, 238, 0.72);
}

.rail-head,
.cycle-strip,
.next-act,
.panel,
.chat-panel,
.operator-panel {
  border: 1px solid rgba(196, 199, 199, 0.45);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow-soft);
}

.rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 8px 28px;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.rail-actions {
  display: flex;
  gap: 8px;
}

.user-badge {
  margin: -14px 8px 20px;
  padding: 8px 10px;
  border: 1px solid rgba(196, 199, 199, 0.45);
  border-radius: 12px;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--earth);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.icon-button {
  width: 48px;
  min-height: 48px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border-radius: 14px;
  background: var(--earth);
  color: var(--surface-lowest);
}

.icon-button.quiet {
  background: var(--surface-lowest);
  border-color: rgba(116, 120, 120, 0.24);
  color: var(--ink-soft);
}

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

.panel-head {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(196, 199, 199, 0.35);
}

.panel-head h2 {
  color: var(--ink-soft);
  font-family: "Work Sans", sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.panel-body {
  padding: 18px;
}

.engine-list,
.timeline-list {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.engine-item,
.timeline-item {
  width: 100%;
  min-height: 64px;
  display: grid;
  gap: 4px;
  justify-items: start;
  border: 1px solid transparent;
  border-radius: 16px;
  background: transparent;
  color: var(--ink-soft);
  text-align: left;
  text-transform: none;
  letter-spacing: 0;
}

.engine-item.active,
.timeline-item.selected {
  background: var(--sage-soft);
  border-color: rgba(86, 98, 79, 0.16);
  color: var(--sage);
}

.engine-item span,
.timeline-item span {
  color: var(--ink);
  font-size: 16px;
  font-weight: 700;
}

.engine-item small,
.timeline-item small,
.timeline-item b,
.message time,
.detail-head small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

.timeline-panel {
  max-height: calc(100vh - 328px);
}

.timeline-list {
  max-height: calc(100vh - 385px);
  overflow: auto;
}

.chat-column {
  height: 100vh;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto auto auto auto minmax(0, 1fr);
  gap: 16px;
  padding: 32px 40px;
  overflow: hidden;
  background:
    radial-gradient(at 0% 0%, rgba(245, 243, 238, 0.92), transparent 48%),
    radial-gradient(at 100% 100%, rgba(234, 232, 227, 0.9), transparent 44%),
    var(--surface);
}

.cycle-strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  padding: 18px 24px;
}

.cycle-main {
  min-width: 0;
}

.cycle-main h2 {
  margin-bottom: 6px;
  font-size: 26px;
  line-height: 32px;
}

.intent {
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.cycle-metrics {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.metric,
.soft-pill {
  min-height: 32px;
  border: 1px solid rgba(196, 199, 199, 0.45);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  padding: 7px 12px;
  font-size: 11px;
  font-weight: 600;
}

.soft-pill {
  color: var(--sage);
}

.stage-tabs {
  display: grid;
  grid-template-columns: repeat(7, minmax(46px, 1fr));
  gap: 8px;
  align-items: stretch;
  overflow: visible;
}

.stage-tab {
  min-width: 0;
  min-height: 54px;
  display: grid;
  place-items: center;
  gap: 2px;
  border-color: rgba(196, 199, 199, 0.4);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.64);
  color: var(--muted);
  letter-spacing: 0;
  text-transform: none;
}

.stage-tab span {
  font-family: "Libre Caslon Text", Georgia, serif;
  font-size: 22px;
  line-height: 24px;
}

.stage-tab small {
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.stage-tab.complete {
  color: var(--sage);
}

.stage-tab.live,
.stage-tab.selected {
  border-color: rgba(86, 98, 79, 0.28);
  background: var(--sage-soft);
  color: var(--sage);
}

.stage-tab.selected {
  box-shadow: inset 0 0 0 1px rgba(86, 98, 79, 0.22);
}

.next-act {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  padding: 14px 20px;
}

.mode-banner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  border: 1px solid rgba(170, 120, 99, 0.24);
  border-radius: 24px;
  background: rgba(255, 219, 205, 0.36);
  padding: 14px 18px;
}

.mode-banner[hidden] {
  display: none;
}

.mode-banner span {
  color: var(--earth);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.mode-banner p {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.45;
}

.next-act span {
  color: var(--earth);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.next-act p {
  margin: 0;
  color: var(--sage);
  font-weight: 600;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.alerts {
  display: grid;
  gap: 8px;
}

.alert {
  margin: 0;
  padding: 12px 16px;
  border: 1px solid rgba(170, 120, 99, 0.22);
  border-left: 4px solid var(--earth);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.74);
}

.alert.error {
  border-left-color: var(--error);
}

.alert.ok {
  border-left-color: var(--sage);
}

.chat-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.78);
}

.messages {
  min-height: 0;
  overflow: auto;
  padding: 28px;
  display: grid;
  gap: 20px;
  align-content: start;
}

.message {
  max-width: 82%;
  border: 1px solid rgba(196, 199, 199, 0.28);
  border-radius: 24px;
  background: var(--surface-lowest);
  padding: 18px 20px;
  box-shadow: 0 6px 24px rgba(27, 28, 25, 0.04);
}

.message.user {
  justify-self: end;
  border-top-right-radius: 8px;
}

.message.assistant {
  justify-self: start;
  border-top-left-radius: 8px;
  background: var(--surface-low);
}

.message header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  color: var(--earth);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.message p {
  margin: 0;
  color: var(--ink);
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.action-cards {
  display: grid;
  gap: 12px;
  padding: 0 28px 20px;
}

.action-card {
  border: 1px solid rgba(196, 199, 199, 0.42);
  border-radius: 28px;
  background: var(--surface-lowest);
  overflow: hidden;
  box-shadow: var(--shadow-soft);
}

.action-card.failed,
.action-card.expired {
  border-color: rgba(186, 26, 26, 0.35);
}

.card-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 24px;
}

.card-summary p {
  margin-bottom: 8px;
  color: var(--ink-soft);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.card-summary small {
  color: var(--sage);
  font-weight: 600;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  align-content: start;
  justify-content: flex-end;
  gap: 8px;
}

.confirm-box {
  display: grid;
  gap: 14px;
  padding: 24px;
  border-top: 1px solid rgba(196, 199, 199, 0.38);
  background: var(--surface-low);
}

.confirm-box span,
.cycle-card span,
.detail-head span {
  color: var(--earth);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.confirm-box p {
  margin: 5px 0 0;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 20px 24px;
  border-top: 1px solid rgba(196, 199, 199, 0.34);
  background: rgba(251, 249, 244, 0.82);
  backdrop-filter: blur(8px);
}

.composer textarea {
  width: 100%;
  min-height: 64px;
  max-height: 170px;
  border: 1px solid rgba(196, 199, 199, 0.38);
  border-radius: 28px;
  background: var(--surface-lowest);
  color: var(--ink);
  padding: 16px 20px;
  resize: vertical;
}

.composer textarea::placeholder {
  color: rgba(68, 71, 72, 0.48);
  font-style: italic;
}

.darshana {
  display: grid;
  gap: 14px;
  border: 1px solid rgba(196, 199, 199, 0.5);
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.68);
  padding: 16px;
  box-shadow: var(--shadow-soft);
}

.darshana-head {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 4px 0;
}

.darshana-head h2 {
  color: var(--ink);
  font-size: 24px;
  line-height: 30px;
}

.darshana-frame {
  min-height: 440px;
  overflow: hidden;
  border: 1px solid rgba(196, 199, 199, 0.38);
  border-radius: 24px;
  background: var(--surface);
}

.darshana iframe {
  display: block;
  width: 100%;
  min-height: 440px;
  border: 0;
}

.cycle-card {
  display: grid;
  gap: 6px;
}

.cycle-card b {
  font-family: "Libre Caslon Text", Georgia, serif;
  font-size: 24px;
  font-weight: 400;
}

.cycle-card p,
.cycle-card small {
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.stage-bars,
.mini-list {
  list-style: none;
  padding: 0;
  margin: 16px 0 0;
  display: grid;
  gap: 10px;
}

.stage-bars li {
  display: grid;
  grid-template-columns: 62px minmax(80px, 1fr) 52px;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

meter {
  width: 100%;
  height: 8px;
}

.point-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 0 18px 18px;
}

.point-chip {
  min-height: 32px;
  padding: 6px 10px;
  border-color: rgba(196, 199, 199, 0.44);
  background: var(--surface-lowest);
  color: var(--ink-soft);
  font-size: 12px;
  letter-spacing: 0;
  text-transform: none;
}

.point-chip.selected {
  border-color: rgba(86, 98, 79, 0.28);
  background: var(--sage-soft);
  color: var(--sage);
}

.point-chip.open {
  border-style: dashed;
  background: rgba(245, 243, 238, 0.72);
  color: var(--muted);
  cursor: default;
}

.point-detail {
  display: grid;
  gap: 10px;
  padding: 0 18px 18px;
}

.detail-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: baseline;
}

.link-list p {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
}

.evidence-card {
  display: grid;
  gap: 8px;
  border: 1px solid rgba(196, 199, 199, 0.36);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.68);
  padding: 14px;
}

.evidence-card span,
.payload-rows dt {
  color: var(--earth);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.evidence-card p {
  margin: 0;
  color: var(--ink);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.payload-rows {
  display: grid;
  gap: 6px;
  margin: 4px 0 0;
}

.payload-rows div {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 8px;
}

.payload-rows dd {
  margin: 0;
  color: var(--ink-soft);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--ink-soft);
}

.stat-row b {
  color: var(--ink);
  font-family: "Libre Caslon Text", Georgia, serif;
  font-size: 28px;
  font-weight: 400;
}

.mini-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

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

.empty {
  margin: 0;
}

.operator {
  display: grid;
  gap: 8px;
}

.operator-toggle {
  justify-self: start;
}

.operator-panel {
  padding: 18px;
}

.operator-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

pre {
  margin: 0;
  max-height: 360px;
  overflow: auto;
  border: 1px solid rgba(196, 199, 199, 0.36);
  border-radius: 18px;
  background: var(--surface-lowest);
  color: var(--ink);
  padding: 12px;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

@media (max-width: 1240px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr) minmax(350px, 430px);
  }

  .rail {
    display: none;
  }

  .body-panel {
    grid-column: auto;
    grid-template-columns: 1fr;
  }

  .operator {
    grid-column: auto;
  }
}

@media (max-width: 860px) {
  html,
  body {
    height: auto;
    overflow: auto;
  }

  .app-shell {
    height: auto;
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .rail,
  .chat-column,
  .body-panel {
    height: auto;
    overflow: visible;
    min-height: 0;
    padding: 20px;
    border: 0;
  }

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

  .timeline-panel,
  .timeline-list {
    max-height: none;
  }

  .cycle-strip,
  .mode-banner,
  .next-act,
  .card-summary,
  .composer {
    grid-template-columns: 1fr;
  }

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

  .cycle-metrics,
  .card-actions {
    justify-content: start;
  }

  .message {
    max-width: 100%;
  }

  .darshana,
  .darshana-frame,
  .darshana iframe {
    min-height: 380px;
  }
}

@media (max-width: 520px) {
  .rail-head {
    align-items: start;
  }

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

  .stage-bars li {
    grid-template-columns: 58px minmax(60px, 1fr) 46px;
  }

  .detail-head {
    grid-template-columns: 1fr;
  }
}
