:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --panel: #fdfdfc;
  --line: #deded8;
  --line-strong: #c7c7bf;
  --text: #161716;
  --muted: #666963;
  --accent: #245bdb;
  --ok: #147a4d;
  --warn: #a45f00;
  --bad: #b3261e;
  --pending: #7a5800;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent), white 38%);
  outline-offset: 2px;
}

button,
input,
select,
textarea {
  font: inherit;
}

select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--panel);
  color: var(--text);
}

select {
  min-height: 34px;
  padding: 6px 8px;
}

textarea {
  resize: vertical;
  min-height: 82px;
  padding: 8px;
}

.app-shell {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr) 334px;
  height: 100vh;
  overflow: hidden;
}

.sidebar,
.rightbar {
  min-width: 0;
  min-height: 0;
  gap: 10px;
  padding: 12px;
  border-right: 1px solid var(--line);
}

.sidebar {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.rightbar {
  display: grid;
  grid-template-rows: minmax(220px, 1.2fr) minmax(230px, 1fr) minmax(100px, auto);
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  border-right: 0;
  border-left: 1px solid var(--line);
}

.rightbar > .panel {
  display: flex;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
}

.main {
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 100vh;
  min-height: 0;
  padding: 12px;
  overflow: hidden;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
}

.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  color: var(--text);
  font-weight: 800;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  line-height: 1.1;
}

h2 {
  font-size: 16px;
  line-height: 1.25;
}

h3 {
  font-size: 14px;
  line-height: 1.3;
}

p,
small,
.eyebrow {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  min-width: 0;
}

.hidden {
  display: none !important;
}

.compact {
  padding: 12px;
}

.section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.compact .section-header {
  padding: 0 0 10px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 64px;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.topbar h2 {
  margin-top: 2px;
  font-size: 22px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.secondary-button,
.primary-button {
  min-height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  padding: 6px 10px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

.primary-button {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.topbar-actions .primary-button,
.topbar-actions .secondary-button {
  white-space: nowrap;
}

.secondary-button:disabled,
.primary-button:disabled,
.incident-item:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.status-pill,
.tag,
.health {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 8px;
  border: 1px solid var(--line-strong);
  font-size: 12px;
  font-weight: 650;
}

.status-pill {
  border: 0;
}

.status-triage,
.status-mitigation {
  color: var(--bad);
  background: color-mix(in srgb, var(--bad), white 86%);
}

.status-approval {
  color: var(--pending);
  background: color-mix(in srgb, var(--pending), white 84%);
}

.status-approved {
  color: var(--pending);
  background: color-mix(in srgb, var(--pending), white 84%);
}

.status-resolved {
  color: var(--ok);
  background: color-mix(in srgb, var(--ok), white 84%);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.intro-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  min-height: 62px;
  padding: 9px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.intro-strip div {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.setup-panel {
  display: grid;
  gap: 8px;
  padding: 12px;
  background: #fffdf2;
  border: 1px solid #d9c86e;
  border-radius: 6px;
}

.setup-panel code,
.setup-panel pre {
  max-width: 100%;
  overflow: auto;
  margin: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fbfbfa;
  font-size: 12px;
}

.intro-strip strong,
.tool-state,
.event-label {
  font-size: 12px;
  font-weight: 750;
}

.metric {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 70px;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.metric span {
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 22px;
  line-height: 1.1;
}

.incident-item {
  display: flex;
  width: 100%;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  margin-top: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fbfbfa;
  color: var(--text);
  text-align: left;
}

.incident-item.active {
  border-color: var(--accent);
}

.role-list,
.service-list,
.tool-list,
.empty-list {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.phase-workspace {
  position: relative;
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
}

.phase-workspace.attention-blocked {
  animation: blocked-nudge 220ms ease-out;
}

.phase-header {
  min-height: 60px;
}

.phase-header h2 {
  margin: 1px 0 2px;
  font-size: 18px;
  line-height: 1.15;
}

.phase-progress {
  flex: 0 0 auto;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 11px;
}

.phase-view {
  min-height: 0;
  flex: 1;
  animation: phase-enter 220ms ease-out;
}

#triage-view {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
}

#mitigation-view,
#execution-view,
#scorecard-view {
  overflow: hidden;
  padding: 12px;
}

#mitigation-view {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}

#approval-view {
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(250px, 0.88fr);
  gap: 12px;
  align-items: start;
  overflow: auto;
  padding: 12px;
}

.phase-section {
  min-width: 0;
}

.phase-section-heading {
  display: grid;
  gap: 2px;
  margin-bottom: 8px;
}

.phase-section-heading h3 {
  font-size: 15px;
}

.phase-section .empty-list {
  padding: 0;
}

.blocked-feedback {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  margin: 10px 12px 0;
  padding: 9px 10px;
  border: 1px solid color-mix(in srgb, var(--bad), white 45%);
  border-left: 4px solid var(--bad);
  border-radius: 5px;
  background: color-mix(in srgb, var(--bad), white 94%);
  animation: blocked-nudge 220ms ease-out;
}

.blocked-feedback strong {
  color: var(--bad);
  font-size: 12px;
}

.blocked-feedback p {
  color: color-mix(in srgb, var(--bad), var(--text) 34%);
}

.service-list {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: minmax(78px, auto);
  align-content: start;
  min-height: 0;
  overflow: hidden;
}

.human-console {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: #f8f8f5;
}

.human-console-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.human-console-grid {
  display: grid;
  grid-template-columns: minmax(110px, 0.8fr) minmax(110px, 0.8fr) minmax(220px, 1.6fr);
  gap: 8px;
  align-items: end;
}

.human-console .field-label {
  margin-top: 0;
}

.human-note-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: stretch;
}

.human-note-row textarea {
  min-height: 34px;
  height: 34px;
  overflow: hidden;
  resize: none;
}

.human-note-row button {
  white-space: nowrap;
}

.human-console .detail-box {
  display: flex;
  min-height: 0;
  flex-wrap: wrap;
  gap: 4px 12px;
  padding: 6px 8px;
}

.human-console .detail-box h3,
.human-console .detail-box p {
  font-size: 11px;
}

.approval-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  align-items: start;
}

.approval-layout .form-panel,
.approval-layout .empty-list {
  padding: 0;
}

.approval-context {
  display: grid;
  gap: 8px;
}

.approval-context-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.approval-context-grid > div {
  display: grid;
  gap: 2px;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fbfbfa;
}

.approval-context-grid span,
.approval-context-copy strong,
.approval-change strong,
.approval-hypothesis > .row > strong {
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
  text-transform: uppercase;
}

.approval-context-grid strong {
  overflow-wrap: anywhere;
  font-size: 12px;
}

.approval-change {
  display: grid;
  gap: 3px;
  padding: 7px 9px;
  border-left: 3px solid var(--pending);
  background: color-mix(in srgb, var(--pending), white 95%);
}

.approval-context-copy,
.approval-hypothesis {
  display: grid;
  gap: 6px;
  padding-top: 7px;
  border-top: 1px solid var(--line);
}

.approval-context-copy > div {
  display: grid;
  gap: 2px;
}

.approval-hypothesis ul {
  display: grid;
  gap: 2px;
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.field-feedback {
  min-height: 17px;
  color: var(--bad);
  font-size: 11px;
  line-height: 1.35;
}

.execution-state {
  display: grid;
  height: 100%;
  place-content: center;
  gap: 12px;
}

.execution-summary {
  display: grid;
  gap: 10px;
  max-width: 620px;
  padding: 16px;
  border: 1px solid var(--line-strong);
  border-left: 4px solid var(--pending);
  border-radius: 5px;
  background: #f8f8f5;
}

.execution-summary.recovered {
  border-left-color: var(--ok);
}

.execution-summary h3 {
  font-size: 18px;
}

.execution-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.execution-metrics span {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
  font-size: 11px;
}

.execution-metrics strong {
  display: block;
  margin-top: 3px;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 18px;
}

.compact .role-list {
  padding: 0;
}

.field-label {
  display: block;
  margin: 8px 0 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.sidebar-note {
  margin-top: 8px;
}

.control-list {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.check-row {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  font-size: 13px;
  line-height: 1.35;
}

.check-row input {
  margin: 2px 0 0;
}

.divider {
  height: 1px;
  margin: 12px 0 8px;
  background: var(--line);
}

.form-panel {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.compact-form {
  padding-bottom: 0;
}

.detail-box {
  display: grid;
  gap: 5px;
  min-height: 96px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fbfbfa;
}

.role,
.service,
.record,
.tool-card {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fbfbfa;
  min-width: 0;
}

.service {
  gap: 3px;
  padding: 6px 8px;
  transition: opacity 180ms ease-out, transform 180ms ease-out;
}

.service .row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
}

.service h3 {
  font-size: 12px;
}

.service p {
  font-size: 10px;
  line-height: 1.3;
}

.service .health {
  min-height: 20px;
  padding: 1px 6px;
  font-size: 10px;
}

.service-status {
  display: grid;
  gap: 3px;
  justify-items: end;
}

.service-focused {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  transform: translateY(-2px);
}

.service-receded {
  opacity: 0.42;
  filter: grayscale(1);
}

.service-revoked {
  opacity: 0.48;
  filter: grayscale(1);
}

.service-blocked {
  outline: 2px solid var(--bad);
  outline-offset: -2px;
  animation: blocked-nudge 220ms ease-out;
}

.service-sweep {
  animation: service-sweep 260ms ease-out both;
  animation-delay: calc(var(--sweep-index) * 50ms);
}

.service-recovered {
  animation: recovered-enter 260ms ease-out;
}

.scope-marker {
  display: inline-flex;
  width: max-content;
  border-radius: 3px;
  padding: 2px 5px;
  background: #deded8;
  color: #484b47;
  font-size: 10px;
  font-weight: 750;
  text-transform: uppercase;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

.tool-card.unavailable {
  opacity: 0.62;
}

.tool-card.registered {
  border-color: color-mix(in srgb, var(--ok), white 55%);
}

.tool-card.status-changed {
  animation: capability-enter 220ms ease-out;
}

.tool-card summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.tool-state {
  color: var(--muted);
}

.rightbar .tool-list {
  gap: 4px;
  min-height: 0;
  padding: 6px;
  overflow: hidden;
}

.rightbar .tool-card {
  gap: 3px;
  padding: 6px 8px;
}

.rightbar .tool-card h3 {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 11px;
}

.rightbar .tool-card .tag {
  min-height: 20px;
  padding: 1px 6px;
  font-size: 10px;
}

.rightbar .tool-card summary {
  font-size: 11px;
}

.rightbar .tool-state {
  display: none;
}

.prompt-box {
  padding: 12px;
}

.prompt-box p {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fbfbfa;
  color: var(--text);
  font-size: 13px;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.row.wrap {
  align-items: flex-start;
  flex-wrap: wrap;
}

.meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.health-healthy {
  color: var(--ok);
}

.health-degraded {
  color: var(--warn);
}

.health-failing {
  color: var(--bad);
}

.timeline {
  display: grid;
  gap: 8px;
  min-height: 0;
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  margin: 0;
  padding: 12px;
  list-style: none;
}

.timeline li {
  display: grid;
  gap: 4px;
  padding: 9px;
  border-left: 3px solid var(--line-strong);
  background: #fbfbfa;
}

.timeline li.new-entry {
  animation: activity-enter 220ms ease-out;
}

.timeline summary {
  cursor: pointer;
}

.timeline details,
.timeline pre {
  min-width: 0;
  max-width: 100%;
}

.timeline pre {
  margin: 4px 0 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.event-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.timeline .tool {
  border-left-color: var(--accent);
}

.timeline .decision {
  border-left-color: var(--pending);
}

.timeline .success {
  border-left-color: var(--ok);
}

.timeline .error {
  border-left-color: var(--bad);
}

.timeline .blocked {
  border-left-color: var(--bad);
  background: color-mix(in srgb, var(--bad), white 95%);
}

.timeline .blocked .event-label,
.timeline .error .event-label {
  color: var(--bad);
}

.score-pass {
  border-left: 3px solid var(--ok);
}

.score-fail {
  border-left: 3px solid var(--bad);
}

.timeline time {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 11px;
}

.empty {
  padding: 12px;
  color: var(--muted);
  font-size: 13px;
}

.action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

@keyframes phase-enter {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes service-sweep {
  from {
    opacity: 0.25;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes recovered-enter {
  from {
    opacity: 0.55;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes blocked-nudge {
  0% {
    transform: translateX(0);
  }
  35% {
    transform: translateX(-4px);
  }
  70% {
    transform: translateX(3px);
  }
  100% {
    transform: translateX(0);
  }
}

@keyframes capability-enter {
  from {
    opacity: 0.5;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes activity-enter {
  from {
    opacity: 0.45;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

body:has(#webmcp-fallback:not(.hidden)) {
  height: auto;
  overflow: auto;
}

body:has(#webmcp-fallback:not(.hidden)) .app-shell {
  height: auto;
  min-height: 100vh;
  overflow: visible;
}

body:has(#webmcp-fallback:not(.hidden)) .main {
  height: auto;
  overflow: visible;
}

@media (min-width: 1181px) {
  .service-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .service .meta {
    display: none;
  }

  .rightbar .tool-card details {
    display: none;
  }

  .rightbar .prompt-box {
    padding: 8px;
  }

  .rightbar .prompt-box p {
    display: -webkit-box;
    padding: 8px;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
  }
}

@media (max-width: 1180px) {
  body {
    height: auto;
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 240px minmax(0, 1fr);
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .main {
    height: auto;
    overflow: visible;
  }

  .rightbar {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: none;
    grid-column: 1 / -1;
    height: auto;
    max-height: none;
    overflow: visible;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .rightbar .tool-state {
    display: block;
  }
}

@media (max-width: 760px) {
  .app-shell,
  .metric-grid,
  .intro-strip,
  .rightbar,
  #approval-view,
  #mitigation-view,
  .approval-layout,
  .human-console-grid,
  .service-list {
    grid-template-columns: 1fr;
  }

  .sidebar,
  .rightbar {
    border: 0;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .phase-workspace,
  #triage-view,
  .phase-view {
    min-height: auto;
    overflow: visible;
  }

  .timeline,
  .rightbar .tool-list {
    overflow: visible;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
