:root {
  --sub: var(--demo-sub, #6d28d9);
  --active-glow: rgba(13, 110, 100, 0.22);
}

.run-label, .speed-label {
  font-size: 0.75rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.run-label select, .speed-label select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  max-width: 280px;
}

.btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.8rem;
}

.btn:hover { border-color: var(--accent); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-sm { font-size: 0.72rem; padding: 0.25rem 0.5rem; }

.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.org-stage {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0.75rem 1.25rem 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  /* ヘッダー下を1画面に収める（高さ固定 → 下のピコピコを防ぐ） */
  height: calc(100vh - var(--demo-chrome-h, 6.75rem) - 0.5rem);
  max-height: calc(100vh - var(--demo-chrome-h, 6.75rem) - 0.5rem);
  overflow: hidden;
}

.score-bar {
  display: grid;
  grid-template-columns: repeat(3, auto) 1fr auto;
  gap: 0.75rem 1rem;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  margin-bottom: 0;
  flex-shrink: 0;
}

.score-chip {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
}

.chip-label { font-size: 0.7rem; color: var(--demo-text-secondary, var(--muted)); font-weight: 600; }

.chip-value { font-size: 1.25rem; font-weight: 700; color: var(--demo-heading, var(--text)); }

.chip-badge, .chip-badge.pass, .chip-badge.revise {
  font-size: 0.65rem;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.chip-badge.pass { background: var(--demo-pass-bg, rgba(34, 197, 94, 0.2)); color: var(--pass); font-weight: 700; }
.chip-badge.revise { background: var(--demo-revise-bg, rgba(245, 158, 11, 0.2)); color: var(--revise); font-weight: 700; }

.phase-chip {
  display: flex;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
  justify-self: end;
}

.progress-bar {
  grid-column: 1 / -1;
  height: 4px;
  background: var(--surface-2);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--sub));
  transition: width 0.35s ease;
}

/* --- スポットライト（固定高 · ジャンプ防止） --- */
.spotlight-panel {
  flex-shrink: 0;
  height: var(--spotlight-h, 11.5rem);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.65rem 0.85rem 0.75rem;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 2px 16px rgba(11, 29, 58, 0.08);
}

.spotlight-head {
  margin-bottom: 0.4rem;
  flex-shrink: 0;
}

.spotlight-phase {
  font-size: 0.78rem;
  color: var(--demo-accent-strong, var(--accent));
  font-weight: 700;
  white-space: nowrap;
}

.spotlight-inner {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  gap: 0.75rem;
  overflow: hidden;
}

/* --- 組織図 + タイムライン（残り高さを分割） --- */
.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(240px, 0.95fr) minmax(280px, 1.05fr);
  gap: 0.65rem;
  overflow: hidden;
}

.org-panel,
.timeline-panel,
.spotlight-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.org-panel,
.timeline-panel {
  padding: 0.65rem 0.85rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.org-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.timeline-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.5rem;
  flex-shrink: 0;
}

.panel-head h2 { font-size: 0.95rem; color: var(--demo-heading, var(--text)); font-weight: 700; }

.panel-head p, .panel-note { font-size: 0.72rem; color: var(--demo-text-secondary, var(--muted)); }

.org-unit { margin-bottom: 0.85rem; }

.unit-label {
  font-size: 0.68rem;
  color: var(--demo-text-secondary, var(--muted));
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.4rem;
}

.unit-note {
  margin-left: 0.35rem;
  color: var(--sub);
  text-transform: none;
  letter-spacing: 0;
}

.unit-members { display: flex; flex-direction: column; gap: 0.35rem; }

.member-card {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.member-card.idle { opacity: 1; color: var(--demo-muted, var(--muted)); }
.member-card.idle .member-name { color: var(--demo-text-secondary, var(--muted)); }
.member-card.parent-only { border-style: dashed; }
.member-card.done { border-color: rgba(34, 197, 94, 0.35); }
.member-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--active-glow);
  opacity: 1;
}

/* 擬人化バスト（shared/member-portraits.js） */
.member-portrait {
  width: 44px;
  height: 52px;
  flex-shrink: 0;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid var(--portrait-accent, var(--border));
  background: #fff;
  box-shadow: 0 1px 4px rgba(11, 29, 58, 0.1);
  line-height: 0;
}

.member-portrait .portrait-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.member-portrait[data-subagent="true"] {
  box-shadow: 0 0 0 1px rgba(109, 40, 217, 0.25), 0 1px 4px rgba(11, 29, 58, 0.1);
}

.member-card.active .member-portrait,
.member-portrait--active {
  border-color: var(--demo-accent-strong, var(--accent));
  box-shadow: 0 0 0 2px var(--active-glow);
}

.member-portrait--active {
  width: 48px;
  height: 56px;
}

.member-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
  color: #fff;
}

.member-info { flex: 1; min-width: 0; }

.member-name { display: block; font-size: 0.82rem; font-weight: 700; color: var(--demo-heading, var(--text)); }

.member-role { display: block; font-size: 0.68rem; color: var(--demo-text-secondary, var(--muted)); }

.member-badge {
  display: inline-block;
  font-size: 0.58rem;
  padding: 0.05rem 0.3rem;
  border-radius: 3px;
  margin-top: 0.15rem;
  margin-right: 0.2rem;
}

.member-badge.sub { background: var(--demo-sub-bg, #ede9fe); color: var(--sub); font-weight: 600; }
.member-badge.ro { background: var(--demo-revise-bg, #ffedd5); color: var(--revise); font-weight: 600; }
.member-badge.parent { background: #e0f2f1; color: var(--demo-accent-strong, var(--accent)); font-weight: 600; }

.member-agent {
  display: block;
  font-size: 0.6rem;
  color: var(--muted);
  font-family: ui-monospace, monospace;
}

.member-status {
  font-size: 0.65rem;
  color: var(--muted);
  white-space: nowrap;
}

.member-card.active .member-status { color: var(--demo-accent-strong, var(--accent)); font-weight: 700; }
.member-card.active .member-name { color: var(--demo-heading, var(--text)); }

.gate-legend {
  margin-top: 0.75rem;
  font-size: 0.68rem;
  color: var(--muted);
  display: flex;
  gap: 1rem;
}

.legend-item { display: flex; align-items: center; gap: 0.3rem; }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.dot.subagent { background: var(--sub); }
.dot.readonly { background: var(--revise); }
.dot.parent { background: var(--accent); }

.org-headcount {
  margin-top: 0.65rem;
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.5;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.active-card {
  min-height: 0;
  max-height: 100%;
  overflow-y: auto;
  padding-right: 0.35rem;
}

.placeholder { color: var(--muted); font-size: 0.8rem; line-height: 1.45; }

.active-head {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 0.45rem;
}

.active-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}

.active-name { font-weight: 700; font-size: 0.92rem; color: var(--demo-heading, var(--text)); }

.active-role { font-size: 0.78rem; color: var(--demo-text-secondary, var(--muted)); }

.active-badges { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.35rem; }

.pill {
  font-size: 0.62rem;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.pill.sub { border-color: rgba(109, 40, 217, 0.35); color: var(--sub); background: var(--demo-sub-bg, #ede9fe); }
.pill.ro { border-color: rgba(245, 158, 11, 0.5); color: var(--revise); }
.pill.parent { color: var(--muted); }
.pill.agent { font-family: ui-monospace, monospace; color: var(--accent); }

.active-summary { font-size: 0.78rem; margin-bottom: 0.35rem; line-height: 1.45; color: var(--demo-text, var(--text)); }

.active-score {
  display: inline-block;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  margin-bottom: 0.5rem;
}

.active-score.pass { background: var(--demo-pass-bg, #dcfce7); color: var(--pass); }
.active-score.revise { background: var(--demo-revise-bg, #ffedd5); color: var(--revise); }

.fix-list {
  font-size: 0.72rem;
  padding-left: 1rem;
  color: var(--demo-text-secondary, var(--muted));
  margin: 0;
}

.evidence-box {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.evidence-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.35rem;
}

.evidence-head h3 { font-size: 0.78rem; color: var(--demo-text-secondary, var(--muted)); font-weight: 600; }

.evidence-pre {
  flex: 1;
  min-height: 0;
  background: var(--demo-surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem;
  font-size: 0.65rem;
  line-height: 1.4;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, "Cascadia Code", monospace;
}

.hidden { display: none !important; }

.timeline-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
}

.timeline-hint {
  padding: 1rem 0.75rem;
  font-size: 0.78rem;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 8px;
  text-align: center;
  cursor: default;
}

.tl-hint-text {
  opacity: 0.9;
}

.timeline-item {
  display: grid;
  grid-template-columns: 3rem 1.2rem 4rem 1fr auto 8rem;
  gap: 0.5rem;
  align-items: center;
  padding: 0.45rem 0.5rem;
  border-radius: 6px;
  font-size: 0.75rem;
  cursor: pointer;
  border-left: 3px solid transparent;
}

.timeline-item:hover { background: var(--surface-2); }
.timeline-item.past { opacity: 1; color: var(--demo-muted, var(--muted)); }
.timeline-item.past .tl-who { color: var(--demo-text-secondary, var(--muted)); }
.timeline-item.current {
  background: var(--surface-2);
  border-left-color: var(--accent);
}

@keyframes tl-appear {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.timeline-item.tl-appear {
  animation: tl-appear 0.35s ease-out;
}

.tl-time { color: var(--demo-muted, var(--muted)); font-family: monospace; }
.tl-sub { color: var(--sub); font-weight: 600; }
.tl-sub.prep { color: var(--demo-text-secondary, #64748b); font-size: 0.65rem; }
.tl-who { font-weight: 700; color: var(--demo-heading, var(--text)); }
.tl-what { color: var(--demo-text-secondary, var(--muted)); }
.tl-artifact { font-family: monospace; font-size: 0.65rem; color: var(--demo-muted, var(--muted)); text-align: right; }

.tl-score {
  font-weight: 700;
  font-size: 0.68rem;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  text-align: center;
}

.tl-score.pass { background: var(--demo-pass-bg, #dcfce7); color: var(--pass); }
.tl-score.revise { background: var(--demo-revise-bg, #ffedd5); color: var(--revise); }

/* 完成LPは下からオーバーレイ（メインレイアウトを押し下げない） */
.preview-panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  margin: 0;
  padding: 0.75rem 1.25rem 1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 12px 12px 0 0;
  box-shadow: 0 -4px 24px rgba(11, 29, 58, 0.12);
  transform: translateY(100%);
  transition: transform 0.3s ease;
  pointer-events: none;
}

.preview-panel.is-open {
  transform: translateY(0);
  pointer-events: auto;
}

.preview-close {
  position: absolute;
  top: 0.65rem;
  right: 1rem;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
  z-index: 2;
}

.preview-close:hover { border-color: var(--accent); }

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
  padding-right: 2.5rem;
}

.preview-header h2 {
  color: var(--demo-heading, var(--text));
  font-size: 0.95rem;
}

.preview-header .btn-sm + .btn-sm {
  margin-left: 0.25rem;
}

.preview-frame-wrap {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.preview-frame-wrap iframe {
  width: 100%;
  height: min(42vh, 420px);
  border: none;
  display: block;
}

body.preview-open::after {
  content: "";
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 55;
  pointer-events: none;
}

.app-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 1320px;
  margin: 0 auto;
  padding: 0.35rem 1.25rem;
  font-size: 0.68rem;
  color: var(--demo-muted, var(--muted));
  opacity: 1;
  pointer-events: none;
  z-index: 5;
}

body.preview-open .app-footer {
  display: none;
}

@media (max-width: 900px) {
  .org-stage {
    max-height: none;
    overflow: visible;
    min-height: auto;
  }

  .spotlight-panel {
    height: auto;
    min-height: 14rem;
    max-height: 16rem;
  }

  .spotlight-inner {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(200px, 40vh) minmax(180px, 35vh);
    overflow: visible;
  }

  .score-bar {
    grid-template-columns: 1fr 1fr;
  }
  .phase-chip { grid-column: 1 / -1; justify-self: start; }
  .timeline-item {
    grid-template-columns: 2.5rem 1rem 1fr;
    grid-template-rows: auto auto;
  }
  .tl-artifact { grid-column: 1 / -1; text-align: left; }
}

@media (min-height: 800px) {
  :root {
    --spotlight-h: 12.5rem;
  }
}
