:root {
  --app-bg: #e9e9e5;
  --canvas: #f8f8f5;
  --card: #ffffff;
  --chrome: #171a17;
  --chrome-2: #222622;
  --hairline: #dedfd9;
  --hairline-strong: #c9cbc4;
  --accent: #ec5b32;
  --accent-soft: #fff0ea;
}

html { background: var(--app-bg); }
body {
  color: #222522;
  font-family: "Noto Sans SC", sans-serif;
  background: var(--app-bg);
}
.noise { opacity: .07; }

.topbar {
  height: 60px;
  padding: 0 18px;
  grid-template-columns: 1fr auto 1fr;
  border-bottom: 0;
  background: rgba(23,26,23,.97);
  box-shadow: 0 1px 0 rgba(255,255,255,.06), 0 8px 24px rgba(20,23,20,.12);
}
.brand { color: #f7f7f2; font-size: 13px; letter-spacing: .01em; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--accent); box-shadow: none; }
.project-switch { border-color: rgba(255,255,255,.1); background: rgba(255,255,255,.06); color: #e7e8e2; }
.live-dot { background: #72c790; box-shadow: 0 0 0 3px rgba(114,199,144,.14); }
.topbar .icon-btn, .topbar .save-state { color: #a9ada7; }
.topbar .btn.ghost { border-color: rgba(255,255,255,.16); color: #eceee8; }
.topbar .btn.warm { border-color: transparent; background: var(--accent); color: #fff; }

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 304px;
  grid-template-areas:
    "workflow workflow"
    "stage inspector";
  align-items: start;
  gap: 12px;
  min-height: calc(100vh - 60px);
  padding: 12px 18px 18px;
}
.panel { border: 1px solid var(--hairline); border-radius: 12px; background: var(--canvas); box-shadow: 0 2px 10px rgba(32,36,31,.035); }

.sidebar {
  grid-area: workflow;
  position: static;
  display: block;
  width: auto;
  height: auto;
  padding: 0;
  overflow: visible;
  border: 0;
  background: transparent;
  box-shadow: none;
}
.sidebar > .eyebrow, .sidebar h1, .sidebar .lede, .team-card, .rule-note { display: none; }
.pipeline {
  display: grid;
  grid-template-columns: repeat(9, minmax(104px, 1fr));
  gap: 0;
  overflow: hidden;
  border: 1px solid var(--hairline);
  border-radius: 12px;
  background: rgba(248,248,245,.96);
  box-shadow: 0 2px 10px rgba(32,36,31,.035);
}
.step {
  position: relative;
  display: grid;
  grid-template-columns: 26px minmax(0,1fr);
  grid-template-rows: auto auto;
  gap: 1px 8px;
  min-height: 64px;
  padding: 12px 10px;
  border-right: 1px solid var(--hairline);
  color: #8d918b;
  text-align: left;
}
.step:last-child { border-right: 0; }
.step:not(:last-child)::after { display: none; }
.step .num {
  grid-row: 1 / 3;
  align-self: center;
  width: 25px;
  height: 25px;
  border-color: #d1d3cd;
  border-radius: 8px;
  background: #fff;
  font-family: "Space Grotesk", sans-serif;
  font-size: 9px;
}
.step strong { align-self: end; overflow: hidden; color: #4b504b; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.step .gate { justify-self: start; overflow: hidden; max-width: 100%; padding: 0; border: 0; color: #969a94; font-size: 8px; text-overflow: ellipsis; white-space: nowrap; }
.step.done { background: #fbfcfa; }
.step.done .num { border-color: #b9d7c5; background: #eaf5ee; color: #34724f; }
.step.done .gate { color: #4d8d6b; }
.step.active { background: #fff; }
.step.active::before { position: absolute; right: 10px; bottom: 0; left: 10px; height: 3px; border-radius: 3px 3px 0 0; background: var(--accent); content: ""; }
.step.active .num { border-color: var(--chrome); background: var(--chrome); color: #fff; box-shadow: none; }
.step.active strong { color: #171a17; }
.step:disabled { cursor: not-allowed; opacity: .58; }

.stage { grid-area: stage; min-width: 0; min-height: calc(100vh - 148px); overflow: clip; background: var(--canvas); }
.stage-head {
  min-height: 86px;
  padding: 20px 26px 17px;
  align-items: center;
  border-bottom-color: var(--hairline);
  background: rgba(255,255,255,.64);
}
.stage-head h2 { margin-top: 5px; font-family: "Noto Sans SC", sans-serif; font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.stage-head .eyebrow { color: #868b84; font-family: "Space Grotesk", sans-serif; }
.stage-head-actions { flex-wrap: wrap; justify-content: flex-end; }
.focus-toggle { min-height: 31px; border-color: var(--hairline); background: #fff; color: #5d625c; }
.focus-toggle:hover, .focus-toggle[aria-pressed="true"] { border-color: var(--chrome); background: var(--chrome); color: #fff; }
.inspector-toggle[aria-pressed="true"] { border-color: var(--hairline); background: #fff; color: #5d625c; }
.status-pill { border: 1px solid #e3d9cf; border-radius: 8px; background: #f6eee8; color: #9e4b33; }
.view-mode-switch { border-color: var(--hairline); background: #eeefeb; }
.mode-btn.active { background: #fff; }

.stage-content { padding: 24px 28px 32px; overflow: visible; }
.stage-footer { padding: 14px 28px; border-top-color: var(--hairline); background: rgba(248,248,245,.95); }
.stage-footer .btn.primary { background: var(--chrome); }

.confirmation-gate {
  margin-bottom: 16px;
  padding: 12px 14px;
  border-color: #ead6cc;
  border-radius: 10px;
  background: #fff7f2;
}
.confirmation-gate .gate-icon { width: 32px; height: 32px; background: var(--accent); box-shadow: none; }
.confirmation-gate strong { font-size: 11px; }
.confirmation-gate p { font-size: 9px; }
.strategy-ribbon { border: 1px solid #eadbd3; border-left: 3px solid var(--accent); border-radius: 9px; background: #fff8f4; }

.document-card, .analysis-card, .people-section, .brain-library, .brain-timeline, .brain-console, .episode-tools, .source-coverage {
  border-color: var(--hairline);
  border-radius: 10px;
  background: var(--card);
  box-shadow: none;
}
.episode-tools { background: #f0f1ed; }
.source-coverage { background: #f4f5f1; }
.asset-card, .episode, .person-row, .brain-entity, .story-card { border-color: var(--hairline); border-radius: 10px; box-shadow: none; }
.asset-card:hover { border-color: var(--hairline-strong); box-shadow: 0 8px 20px rgba(34,38,33,.06); }
.screenplay-doc { background: #fff; }
.screenplay-scene h4 { border-left-color: var(--accent); background: #f3f3ef; }
.evidence-panel { border-color: var(--hairline); border-radius: 10px; background: #f0f1ed; }
.story-visual { background: linear-gradient(145deg,#262b27,#121512); }
.shot-timeline { border-color: var(--hairline); background: #e7e8e3; }

.inspector {
  grid-area: inspector;
  position: sticky;
  display: block;
  top: 72px;
  height: calc(100vh - 90px);
  padding: 18px;
  overflow: auto;
  background: #f5f6f2;
  scrollbar-width: thin;
}
.inspector-head { min-height: 24px; }
.score-card { margin: 14px 0; border-radius: 10px; background: var(--chrome); }
.stage-context-section { margin: 0; border-color: var(--hairline); border-radius: 10px; background: #fff; }
.privacy-note { background: #e9ebe6; }

.confirm-modal.brain-running, .brain-running .confirm-modal { width: min(640px,100%); }
.brain-running .modal-close { opacity: .35; cursor: not-allowed; }
.brain-run-head { display: flex; align-items: end; justify-content: space-between; margin-bottom: 10px; }
.brain-run-head span { display: block; color: var(--accent); font-family: "Space Grotesk",sans-serif; font-size: 9px; font-weight: 700; letter-spacing: .12em; }
.brain-run-head strong { display: block; margin-top: 4px; font-size: 15px; }
.brain-run-head b { color: #747a73; font-family: "Space Grotesk",sans-serif; font-size: 18px; }
.brain-run-progress { height: 6px; margin-bottom: 16px; overflow: hidden; border-radius: 999px; background: #e4e5e0; }
.brain-run-progress i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg,var(--accent),#f39a55); transition: width .35s ease; }
.brain-run-list { display: grid; gap: 7px; }
.brain-run-step { display: grid; grid-template-columns: 28px 1fr; gap: 9px; align-items: center; padding: 9px 10px; border: 1px solid var(--hairline); border-radius: 9px; background: #f6f7f3; color: #969a94; }
.brain-run-step > i { display: grid; width: 24px; height: 24px; place-items: center; border-radius: 7px; background: #e7e9e4; font-family: "Space Grotesk",sans-serif; font-size: 9px; font-style: normal; }
.brain-run-step span strong, .brain-run-step span small { display: block; }
.brain-run-step span strong { font-size: 11px; }
.brain-run-step span small { margin-top: 2px; font-size: 9px; line-height: 1.4; }
.brain-run-step.running { border-color: #efb39e; background: #fff5f0; color: #7c3824; }
.brain-run-step.running > i { background: var(--accent); color: #fff; animation: brainPulse .8s ease-in-out infinite alternate; }
.brain-run-step.done { border-color: #c8ddd0; background: #f2f8f4; color: #376a50; }
.brain-run-step.done > i { background: #d9ecdf; color: #2e6b4a; }
.brain-run-note { margin: 12px 0 0; color: #8a8e88; font-size: 9px; text-align: center; }
.brain-running .modal-actions { display: none; }
@keyframes brainPulse { from { opacity: .55; transform: scale(.94); } to { opacity: 1; transform: scale(1); } }

body.inspector-collapsed .workspace { grid-template-columns: minmax(0,1fr); grid-template-areas: "workflow" "stage"; }
body.inspector-collapsed .inspector { display: none; }
body.focus-mode .workspace { grid-template-columns: minmax(0,1fr); grid-template-areas: "stage"; max-width: 1240px; margin: 0 auto; }
body.focus-mode .sidebar, body.focus-mode .inspector { display: none; }
body.focus-mode .stage { width: 100%; }

@media (min-width: 1680px) {
  .workspace { grid-template-columns: minmax(0,1fr) 320px; padding-right: 22px; padding-left: 22px; }
  .stage-content { padding-right: 34px; padding-left: 34px; }
}

@media (max-width: 1240px) {
  .workspace { grid-template-columns: minmax(0,1fr); grid-template-areas: "workflow" "stage"; }
  .inspector { display: none; }
  .inspector-toggle { display: none; }
  .pipeline { overflow-x: auto; }
  .step { min-width: 112px; }
}

@media (max-width: 820px) {
  .topbar { height: 58px; padding: 0 12px; }
  .workspace { display: grid; min-height: calc(100vh - 58px); padding: 8px; }
  .sidebar { margin: 0; padding: 0; }
  .pipeline { display: flex; gap: 0; border-radius: 10px; }
  .step { display: grid; min-width: 78px; min-height: 50px; padding: 8px; text-align: left; }
  .step .num { margin: 0; }
  .step strong { display: block; font-size: 9px; }
  .step .gate { display: none; }
  .stage { min-height: calc(100vh - 124px); border-radius: 10px; }
  .stage-head { min-height: 78px; padding: 16px 18px; }
  .stage-head h2 { font-size: 21px; }
  .stage-content { padding: 18px; }
  .stage-footer { padding: 12px 18px; }
  .focus-toggle { display: none; }
  .view-mode-switch { display: inline-flex; }
}

@media (max-width: 540px) {
  .topbar { grid-template-columns: 1fr auto; }
  .brand > span:last-child { display: none; }
  .stage-head { display: flex; align-items: center; }
  .stage-head-actions { margin-top: 0; }
  .status-pill { display: none; }
  .view-mode-switch { margin-left: 0; }
  .confirmation-gate { grid-template-columns: 32px 1fr; }
  .strategy-ribbon { display: block; }
  .strategy-ribbon span { display: block; margin-top: 5px; text-align: left; }
}
