:root {
  color-scheme: dark;
  --bg: #0e1114;
  --bg-rail: #11171a;
  --panel: #171c21;
  --panel-soft: #1b2228;
  --panel-strong: #202a30;
  --line: rgba(221, 232, 225, 0.14);
  --line-strong: rgba(221, 232, 225, 0.24);
  --text: #f1f5ef;
  --muted: #9ca8a2;
  --faint: #6f7b76;
  --green: #91d99d;
  --green-strong: #63c774;
  --amber: #e9c76d;
  --rose: #e7867a;
  --blue: #8fb9d8;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(145, 217, 157, 0.04), transparent 340px),
    var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.topbar {
  min-height: 76px;
  padding: 14px 18px;
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto minmax(190px, auto);
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(17, 23, 26, 0.96);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(16px);
}

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

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

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--green);
  color: #09120d;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0;
  flex: 0 0 auto;
}

h1 {
  font-size: 25px;
  line-height: 1.05;
}

.brand-block p,
.work-header p,
.frame-head p,
.guide-layout p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  margin-top: 4px;
}

.top-menu {
  display: flex;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0c1013;
}

.top-menu button {
  min-height: 34px;
  border: 0;
  border-radius: 8px;
  padding: 0 13px;
  color: var(--muted);
  background: transparent;
  font-size: 13px;
  font-weight: 760;
}

.top-menu button.is-active {
  color: #07110a;
  background: var(--green);
}

.runtime-state {
  justify-self: end;
  display: grid;
  grid-template-columns: auto auto;
  column-gap: 8px;
  row-gap: 1px;
  align-items: center;
  min-width: 166px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.state-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--amber);
  box-shadow: 0 0 0 4px rgba(233, 199, 109, 0.12);
  grid-row: span 2;
}

.runtime-state strong {
  font-size: 12px;
  line-height: 1.1;
}

.runtime-state small {
  color: var(--muted);
  font-size: 11px;
}

.runtime-state.is-ok .state-dot {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(145, 217, 157, 0.13);
}

.runtime-state.is-error .state-dot {
  background: var(--rose);
  box-shadow: 0 0 0 4px rgba(231, 134, 122, 0.14);
}

.workspace {
  display: grid;
  grid-template-columns: 318px minmax(0, 1fr);
  min-height: calc(100vh - 76px);
}

.side-panel,
.main-panel,
.guide-panel {
  padding: 16px;
}

.side-panel {
  border-right: 1px solid var(--line);
  background: var(--bg-rail);
}

.side-section {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(23, 28, 33, 0.7);
}

.side-section + .side-section {
  margin-top: 12px;
}

.section-row,
.frame-head,
.work-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.section-label,
label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 840;
  text-transform: uppercase;
  letter-spacing: 0;
}

select,
input {
  width: 100%;
  min-height: 38px;
  margin-top: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #11161b;
  padding: 0 10px;
  outline: none;
}

select:focus,
input:focus {
  border-color: rgba(145, 217, 157, 0.55);
  box-shadow: 0 0 0 3px rgba(145, 217, 157, 0.1);
}

.form-grid {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.primary-action {
  width: 100%;
  min-height: 40px;
  margin-top: 14px;
  border: 0;
  border-radius: 8px;
  color: #07110a;
  background: var(--green);
  font-weight: 850;
}

.primary-action:hover {
  background: var(--green-strong);
}

.primary-action:disabled {
  cursor: progress;
  opacity: 0.72;
}

.persona-rail {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.persona-pill {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 9px;
  align-items: center;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #11161b;
  color: inherit;
  text-align: left;
}

.persona-pill.is-active {
  border-color: color-mix(in srgb, var(--accent) 74%, white 8%);
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--accent) 18%, transparent), transparent 60%),
    #11161b;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #07110a;
  font-size: 12px;
  font-weight: 900;
}

.persona-pill strong {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.persona-pill small {
  color: var(--muted);
  font-size: 11px;
}

.compact-disclaimer {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

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

.work-header {
  align-items: center;
  min-height: 72px;
  padding: 4px 2px 14px;
}

.work-header h2 {
  font-size: 21px;
  line-height: 1.16;
}

.scenario-chip,
.decision-status {
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--panel);
  padding: 8px 11px;
  font-size: 12px;
  font-weight: 820;
  white-space: nowrap;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.metric-card,
.frame {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.02) inset;
}

.metric-card {
  min-height: 112px;
  padding: 14px;
}

.metric-card span,
.metric-card small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.metric-card strong {
  display: block;
  margin: 10px 0 8px;
  font-size: 25px;
  line-height: 1.05;
}

.metric-card.is-negative strong {
  color: var(--rose);
}

.metric-card.is-positive strong {
  color: var(--green);
}

.analysis-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 12px;
  align-items: start;
}

.frame {
  padding: 14px;
  overflow: hidden;
}

.frame + .frame,
.scenario-frame {
  margin-top: 12px;
}

.frame-head {
  align-items: flex-start;
  margin-bottom: 12px;
}

h3 {
  font-size: 15px;
  line-height: 1.2;
}

.help-over {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--muted);
  background: #10151a;
  font-size: 11px;
  font-weight: 900;
  flex: 0 0 auto;
  cursor: help;
}

.help-over::after {
  content: attr(data-help);
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  width: min(300px, 74vw);
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0a0d10;
  color: var(--text);
  font-size: 12px;
  line-height: 1.35;
  font-weight: 560;
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition:
    opacity 120ms ease,
    transform 120ms ease;
  z-index: 30;
}

.help-over:hover::after,
.help-over:focus::after {
  opacity: 1;
  transform: translateY(0);
}

.timeline-chart {
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #11161b;
  margin-bottom: 12px;
}

.timeline-row {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) 116px;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.timeline-track {
  height: 16px;
  border-radius: 999px;
  background: #0b0f12;
  overflow: hidden;
  border: 1px solid rgba(221, 232, 225, 0.06);
}

.timeline-fill {
  height: 100%;
  min-width: 6%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), var(--green));
}

.timeline-row strong {
  color: var(--text);
  font-size: 12px;
  text-align: right;
}

.table-wrap {
  width: 100%;
  overflow: auto;
}

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

th,
td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--text);
  font-size: 11px;
  text-transform: uppercase;
}

td {
  color: var(--muted);
  font-size: 12px;
}

td strong {
  color: var(--text);
}

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

.decision-status {
  display: inline-flex;
  margin-bottom: 10px;
}

.decision-status.is-warning {
  color: #1b1403;
  background: var(--amber);
  border-color: transparent;
}

.decision-status.is-ok {
  color: #07110a;
  background: var(--green);
  border-color: transparent;
}

.warning-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px;
}

.warning-list li,
.backend-message,
.guide-note {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #11161b;
  color: var(--muted);
  padding: 10px;
  font-size: 12px;
  line-height: 1.4;
}

.backend-frame.is-error {
  border-color: rgba(231, 134, 122, 0.55);
}

.backend-frame.is-error .backend-message {
  color: #ffd5cf;
  border-color: rgba(231, 134, 122, 0.35);
  background: rgba(231, 134, 122, 0.08);
}

.scenario-frame {
  min-height: 220px;
}

.guide-panel {
  grid-column: 1 / -1;
}

.guide-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(280px, 0.85fr);
  gap: 12px;
}

.guide-layout h2 {
  font-size: 22px;
  margin-bottom: 14px;
}

.guide-steps {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.guide-steps article {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #11161b;
  padding: 12px;
}

.guide-steps strong {
  font-size: 14px;
}

.guide-note {
  margin-top: 14px;
  color: var(--text);
}

.hidden {
  display: none;
}

@media (max-width: 1180px) {
  .topbar {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .runtime-state {
    justify-self: stretch;
  }

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

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

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

@media (max-width: 820px) {
  .workspace {
    display: flex;
    flex-direction: column;
  }

  .topbar {
    position: static;
    min-height: 0;
    padding: 12px;
    gap: 10px;
  }

  h1 {
    font-size: 23px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  .runtime-state {
    grid-template-columns: auto 1fr auto;
    min-width: 0;
    padding: 8px 10px;
  }

  .runtime-state .state-dot {
    grid-row: auto;
  }

  .runtime-state small {
    text-align: right;
  }

  .main-panel {
    order: 1;
    padding: 14px 12px;
  }

  .side-panel {
    order: 2;
    border-right: 0;
    padding: 12px;
    border-bottom: 1px solid var(--line);
  }

  .persona-rail {
    display: flex;
    overflow-x: auto;
    padding-bottom: 2px;
    scroll-snap-type: x proximity;
  }

  .persona-pill {
    min-width: 168px;
    scroll-snap-align: start;
  }

  .top-menu {
    width: 100%;
  }

  .top-menu button {
    flex: 1;
  }

  .work-header,
  .frame-head {
    display: block;
  }

  .work-header {
    min-height: 0;
    padding-bottom: 10px;
  }

  .work-header h2 {
    font-size: 19px;
  }

  .scenario-chip {
    display: inline-flex;
    white-space: normal;
    line-height: 1.25;
    margin-top: 10px;
  }

  .guide-layout,
  .guide-steps {
    grid-template-columns: 1fr;
  }

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

  .metric-card {
    min-height: 104px;
    padding: 12px;
  }

  .metric-card strong {
    font-size: 22px;
  }

  .analysis-grid {
    gap: 10px;
  }

  .frame {
    padding: 12px;
  }

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

  .timeline-row strong {
    grid-column: 1 / -1;
    text-align: left;
  }
}
