:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --ink: #172033;
  --muted: #697386;
  --line: #e2e7ef;
  --primary: #ef4444;
  --primary-dark: #d93232;
  --navy: #10182a;
  --blue: #356df3;
  --green: #16a36a;
  --amber: #d88a0b;
  --shadow: 0 14px 40px rgba(32, 45, 74, .08);
  --radius: 16px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 264px minmax(0, 1fr); }
.sidebar {
  background: var(--navy);
  color: white;
  height: 100vh;
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  padding: 26px 18px 20px;
  overflow-y: auto;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 0 8px 26px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  background: var(--primary); font-size: 14px; font-weight: 900;
}
.brand strong, .brand span { display: block; }
.brand strong { font-size: 15px; }
.brand span { color: #8f9bb3; font-size: 13px; margin-top: 2px; }
#stepNav { display: grid; gap: 4px; }
.nav-step {
  width: 100%; border: 0; background: transparent; color: #8f9bb3; padding: 10px;
  display: flex; align-items: center; gap: 11px; border-radius: 10px; text-align: left;
}
.nav-step:hover { background: #18233a; color: white; }
.nav-step.active { background: #222e48; color: white; }
.nav-step.complete .nav-number { background: var(--green); border-color: var(--green); color: white; }
.nav-step.locked { opacity: .48; cursor: not-allowed; }
.nav-number {
  width: 25px; height: 25px; flex: 0 0 auto; border: 1px solid #41506e; border-radius: 50%;
  display: grid; place-items: center; font-size: 11px; font-weight: 800;
}
.nav-step.active .nav-number { background: var(--primary); border-color: var(--primary); }
.nav-label { font-size: 13px; font-weight: 650; }
.sidebar-footer {
  margin-top: auto; border-top: 1px solid #26334e; padding: 18px 8px 0; display: grid; gap: 4px;
  color: #7f8ba3; font-size: 11px;
}
.sidebar-footer strong { color: #b8c1d2; }

.main { min-width: 0; padding-bottom: 70px; }
.topbar {
  height: 96px; background: rgba(255,255,255,.9); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; padding: 0 42px; gap: 18px; position: sticky; top: 0; z-index: 20;
  backdrop-filter: blur(12px);
}
.eyebrow { margin: 0 0 3px; color: var(--primary); font-size: 10px; font-weight: 900; letter-spacing: .16em; }
.topbar h1 { font-size: 21px; margin: 0; }
.project-actions { margin-left: auto; display: flex; gap: 8px; }
.mobile-menu { display: none !important; }

.workflow-bar {
  margin: 24px auto 0; max-width: 1160px; padding: 0 30px;
}
.workflow-bar > div:first-child { display: flex; gap: 9px; align-items: center; font-size: 13px; }
.workflow-bar strong { margin-right: 4px; }
.workflow-bar #workflowMessage { color: var(--muted); }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #9da5b3; box-shadow: 0 0 0 4px #e8ebf0; }
.status-dot.running { background: var(--blue); box-shadow: 0 0 0 4px #e5edff; animation: pulse 1.2s infinite; }
.status-dot.need-confirm { background: var(--amber); box-shadow: 0 0 0 4px #fff2d9; }
.status-dot.completed { background: var(--green); box-shadow: 0 0 0 4px #dff7ed; }
.status-dot.error { background: var(--primary); box-shadow: 0 0 0 4px #fee4e4; }
@keyframes pulse { 50% { opacity: .45; } }
.progress-track { height: 5px; background: #e5e8ee; border-radius: 99px; overflow: hidden; margin-top: 12px; }
.progress-track span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), #ff7a59); transition: width .35s ease; }

#alertHost { max-width: 1100px; margin: 18px auto 0; padding: 0 30px; }
.alert { border-radius: 12px; padding: 13px 16px; font-size: 13px; display: flex; justify-content: space-between; gap: 20px; }
.alert.error { background: #fff0f0; color: #a82020; border: 1px solid #ffd0d0; }
.alert.success { background: #eafaf3; color: #08784a; border: 1px solid #bdebd7; }
.alert button { border: 0; background: transparent; color: inherit; }

.step-panel { display: none; max-width: 1100px; margin: 0 auto; padding: 44px 30px 0; }
.step-panel.active { display: block; animation: enter .25s ease; }
@keyframes enter { from { opacity: 0; transform: translateY(6px); } }
.panel-heading { margin-bottom: 22px; }
.step-kicker { color: var(--primary); font-size: 10px; letter-spacing: .14em; font-weight: 900; }
.panel-heading h2 { margin: 6px 0 7px; font-size: 28px; letter-spacing: -.025em; }
.panel-heading p { margin: 0; color: var(--muted); font-size: 14px; max-width: 720px; line-height: 1.6; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.form-card { padding: 28px; display: grid; gap: 20px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.field { display: grid; gap: 8px; }
.field > span { font-size: 12px; font-weight: 800; color: #3d4759; }
.field small { color: var(--muted); font-size: 11px; }
input, textarea, select {
  width: 100%; border: 1px solid #d8dee8; border-radius: 10px; background: white; color: var(--ink);
  padding: 12px 13px; outline: none; transition: border .15s, box-shadow .15s;
}
textarea { resize: vertical; line-height: 1.6; }
input:focus, textarea:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(53,109,243,.12); }
.input-action { position: relative; }
.input-action input { padding-right: 45px; }
.input-action .icon-button { position: absolute; right: 5px; top: 5px; }
.icon-button { width: 34px; height: 34px; border: 0; background: transparent; border-radius: 8px; color: var(--muted); display: grid; place-items: center; }
.icon-button:hover { background: #eef1f6; }
.button {
  border: 1px solid transparent; border-radius: 9px; padding: 10px 15px; font-size: 12px; font-weight: 800;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; transition: transform .12s, background .12s;
}
.button:active { transform: translateY(1px); }
.button:disabled { opacity: .45; cursor: not-allowed; }
.button.primary { color: white; background: var(--primary); }
.button.primary:hover { background: var(--primary-dark); }
.button.secondary { background: #eef2f7; border-color: #dce2eb; color: #263248; }
.button.secondary:hover, .button.ghost:hover { background: #e6ebf2; }
.button.ghost { background: white; border-color: var(--line); color: #4d586b; }
.button.danger-ghost { background: white; border-color: #f4d3d3; color: #c03232; }
.button.large { min-height: 48px; font-size: 13px; }
.button.small { padding: 7px 10px; font-size: 11px; }
.button-row { display: flex; gap: 10px; }
.next-button { justify-self: end; }
.api-result { border-radius: 10px; padding: 12px 14px; display: flex; gap: 10px; align-items: center; font-size: 12px; }
.api-result span { width: 9px; height: 9px; border-radius: 50%; background: #a4abba; }
.api-result.neutral { background: #f3f5f8; color: var(--muted); }
.api-result.success { background: #e7f8f0; color: #08754a; }
.api-result.success span { background: var(--green); }
.api-result.error { background: #ffeded; color: #ad2626; }
.api-result.error span { background: var(--primary); }
.transcript-source { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.transcript-source legend { margin-bottom: 9px; color: #3d4759; font-size: 12px; font-weight: 800; }
.source-option {
  position: relative; display: flex; gap: 11px; align-items: center; padding: 15px;
  border: 1px solid var(--line); border-radius: 11px; background: #fff; cursor: pointer;
}
.source-option:has(input:checked) { border-color: var(--primary); background: #fffafa; box-shadow: 0 0 0 2px rgba(239,68,68,.08); }
.source-option input { width: auto; accent-color: var(--primary); }
.source-option strong, .source-option small { display: block; }
.source-option strong { font-size: 12px; margin-bottom: 3px; }
.source-option small { color: var(--muted); font-size: 10px; }
.upload-panel { display: grid; gap: 10px; }
.upload-dropzone {
  min-height: 130px; border: 1px dashed #b9c3d3; border-radius: 13px; background: #f9fbfd;
  display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 5px; color: var(--ink);
}
.upload-dropzone:hover { border-color: var(--blue); background: #f5f8ff; }
.upload-dropzone .upload-icon { padding: 7px 9px; border-radius: 7px; background: #e7edf7; color: #536079; font-size: 10px; font-weight: 900; }
.upload-dropzone strong { font-size: 13px; }
.upload-dropzone small { color: var(--muted); font-size: 10px; }
.upload-status { border-radius: 9px; padding: 11px 13px; display: flex; align-items: center; gap: 9px; font-size: 11px; }
.upload-status span { width: 8px; height: 8px; border-radius: 50%; background: #a4abba; }
.upload-status.neutral { color: var(--muted); background: #f3f5f8; }
.upload-status.success { color: #08754a; background: #e7f8f0; }
.upload-status.success span { background: var(--green); }
.upload-status.error { color: #ad2626; background: #ffeded; }
.upload-status.error span { background: var(--primary); }
.transcript-statistics { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.statistics-heading { padding: 12px 15px; display: flex; justify-content: space-between; background: #f8fafc; border-bottom: 1px solid var(--line); font-size: 11px; }
.statistics-heading span { color: var(--muted); }
.statistics-grid { display: grid; grid-template-columns: repeat(4, 1fr); }
.statistics-grid div { padding: 15px; min-width: 0; }
.statistics-grid div + div { border-left: 1px solid var(--line); }
.statistics-grid span, .statistics-grid strong { display: block; }
.statistics-grid span { margin-bottom: 6px; color: var(--muted); font-size: 9px; font-weight: 900; letter-spacing: .07em; text-transform: uppercase; }
.statistics-grid strong { overflow: hidden; color: #354056; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }

.result-card { min-height: 420px; }
.result-toolbar { display: flex; justify-content: space-between; align-items: center; padding: 15px 20px; border-bottom: 1px solid var(--line); color: #4f5b6e; font-size: 12px; }
.prose-output { padding: 24px 28px; line-height: 1.7; font-size: 14px; }
.prose-output h3 { margin: 22px 0 6px; font-size: 16px; }
.prose-output h3:first-child { margin-top: 0; }
.prose-output p { margin: 6px 0 14px; }
.prose-output ul { margin: 6px 0 18px; padding-left: 20px; }
.empty-state { color: #929aaa; text-align: center; padding: 70px 20px; }
.analysis-summary-grid { display: grid; grid-template-columns: 220px 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.metric-card { padding: 24px; display: flex; flex-direction: column; justify-content: center; min-height: 210px; }
.metric-card span { color: var(--muted); font-size: 11px; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.metric-card strong { display: block; margin: 12px 0 5px; color: var(--primary); font-size: 42px; line-height: 1; }
.metric-card small { color: var(--muted); }
.analysis-card { overflow: hidden; }
.analysis-card .prose-output { min-height: 150px; }
.analysis-card .empty-state { padding: 45px 20px; }
.content-structure-panel { margin-bottom: 16px; }
.content-structure-panel .prose-output { min-height: 125px; }
.analysis-structure-table { margin-bottom: 18px; }
.analysis-actions { display: flex; align-items: center; justify-content: flex-end; gap: 18px; }
.analysis-actions > span { color: var(--muted); font-size: 12px; }
.structure-target-card {
  margin-bottom: 16px; padding: 20px; display: grid; grid-template-columns: minmax(220px, 340px) auto 1fr;
  gap: 18px; align-items: end;
}
.word-match-status { min-height: 42px; border-radius: 9px; padding: 11px 13px; font-size: 12px; display: flex; align-items: center; }
.word-match-status.match { color: #08754a; background: #e7f8f0; }
.word-match-status.mismatch { color: #9b5b00; background: #fff3da; border: 1px solid #f0d39d; }

.table-card { overflow: hidden; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; min-width: 760px; }
th { background: #f8fafc; color: #798396; font-size: 10px; letter-spacing: .08em; text-transform: uppercase; text-align: left; }
th, td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
td:first-child { width: 62px; color: var(--muted); font-size: 12px; font-weight: 800; text-align: center; }
td:nth-child(2) { width: 190px; }
td:nth-child(3) { width: 120px; }
td:last-child { width: 46px; }
td input, td textarea { padding: 9px 10px; font-size: 12px; }
td textarea { min-height: 76px; }
.remove-row { border: 0; color: #a1a8b4; background: transparent; border-radius: 7px; padding: 8px; }
.remove-row:hover { color: var(--primary); background: #fff0f0; }
.table-footer { padding: 16px 18px; display: flex; align-items: center; gap: 16px; }
.table-footer > span { color: var(--muted); font-size: 12px; margin-left: auto; }
.document-editor { border: 0; background: #fbfcfe; min-height: 500px; font-family: Georgia, "Times New Roman", serif; font-size: 15px; padding: 22px; }
.scene-table td:nth-child(2), .scene-table td:nth-child(3) { width: 44%; }
.scene-table textarea { min-height: 120px; }

.style-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 18px; }
.style-card {
  border: 1px solid var(--line); background: white; border-radius: 14px; padding: 18px; min-height: 116px;
  text-align: left; box-shadow: 0 6px 22px rgba(32,45,74,.05);
}
.style-card:hover { border-color: #b9c6db; }
.style-card.selected { border: 2px solid var(--primary); padding: 17px; background: #fffafa; }
.style-card strong { display: block; font-size: 13px; margin-bottom: 7px; }
.style-card span { display: block; color: var(--muted); font-size: 11px; line-height: 1.5; }
.custom-style { padding: 20px; margin-bottom: 18px; }

.stack-list { display: grid; gap: 15px; }
.prompt-card { overflow: hidden; }
.prompt-card header { display: flex; align-items: center; justify-content: space-between; padding: 12px 18px; background: #f8fafc; border-bottom: 1px solid var(--line); }
.scene-badge { color: var(--primary); font-size: 11px; letter-spacing: .1em; font-weight: 900; }
.numbered-prompt-row { display: grid; grid-template-columns: 42px 1fr; gap: 10px; padding: 18px; }
.numbered-prompt-row > span { color: var(--primary); font-size: 18px; font-weight: 900; line-height: 1.6; text-align: right; }
.numbered-prompt-row textarea { min-height: 145px; border: 0; padding: 0; background: transparent; font-size: 13px; line-height: 1.65; }
.prompt-content { display: grid; grid-template-columns: 1fr 1.2fr; }
.prompt-content > div { padding: 18px; min-width: 0; }
.prompt-content > div + div { border-left: 1px solid var(--line); }
.prompt-content label { display: block; color: var(--muted); font-size: 10px; font-weight: 900; letter-spacing: .08em; margin-bottom: 8px; }
.prompt-content p, .prompt-content textarea { margin: 0; font-size: 12px; line-height: 1.65; }
.prompt-content textarea { min-height: 150px; border: 0; padding: 0; background: transparent; }
.title-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 22px; }
.title-card { display: block; cursor: pointer; position: relative; padding: 22px; min-height: 185px; }
.title-card input { width: auto; position: absolute; top: 18px; right: 18px; accent-color: var(--primary); }
.title-card:has(input:checked) { border: 2px solid var(--primary); padding: 21px; background: #fffafa; }
.title-card small { color: var(--primary); font-weight: 900; letter-spacing: .08em; }
.title-card strong, .title-card span { display: block; line-height: 1.45; }
.title-card strong { margin: 22px 0 12px; font-size: 15px; }
.title-card span { color: var(--muted); font-size: 13px; }

.export-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.export-card { padding: 25px; display: grid; grid-template-columns: 55px 1fr; gap: 17px; }
.export-card .button { grid-column: 1 / -1; }
.export-card h3 { margin: 2px 0 8px; font-size: 16px; }
.export-card p { color: var(--muted); margin: 0; font-size: 12px; line-height: 1.6; }
.file-icon { width: 52px; height: 58px; border-radius: 9px; background: #2b63c7; color: white; display: grid; place-items: center; font-weight: 900; }
.file-icon.txt { background: #5c6678; font-size: 11px; }
.completion-card { margin-top: 18px; padding: 20px; display: flex; align-items: center; gap: 14px; }
.completion-card > span { width: 38px; height: 38px; border-radius: 50%; background: #e5f8ef; color: var(--green); display: grid; place-items: center; font-weight: 900; }
.completion-card p { color: var(--muted); font-size: 12px; margin: 4px 0 0; }

.loading-overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(12,18,31,.72); color: white;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; backdrop-filter: blur(4px);
}
.loading-overlay span { color: #c3ccdc; font-size: 12px; }
.loader { width: 44px; height: 44px; border: 4px solid rgba(255,255,255,.2); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -280px; z-index: 50; width: 264px; transition: left .2s; }
  .sidebar.open { left: 0; box-shadow: 15px 0 50px rgba(0,0,0,.22); }
  .mobile-menu { display: grid !important; }
  .topbar { padding: 0 20px; }
  .project-actions .button { padding: 9px; font-size: 0; }
  .project-actions .button::first-letter { font-size: 12px; }
  .style-grid, .title-grid { grid-template-columns: 1fr 1fr; }
  .analysis-summary-grid { grid-template-columns: 1fr 1fr; }
  .metric-card { grid-column: 1 / -1; min-height: auto; }
  .structure-target-card { grid-template-columns: 1fr 1fr; }
  .word-match-status { grid-column: 1 / -1; }
}
@media (max-width: 620px) {
  .topbar { height: auto; min-height: 80px; flex-wrap: wrap; padding-block: 14px; }
  .topbar > div:nth-child(2) { flex: 1; }
  .project-actions { width: 100%; }
  .project-actions .button { flex: 1; font-size: 10px; }
  .workflow-bar, #alertHost, .step-panel { padding-left: 16px; padding-right: 16px; }
  .step-panel { padding-top: 32px; }
  .form-grid, .style-grid, .title-grid, .export-grid, .prompt-content, .analysis-summary-grid, .structure-target-card { grid-template-columns: 1fr; }
  .metric-card, .word-match-status { grid-column: auto; }
  .analysis-actions { align-items: stretch; flex-direction: column; }
  .transcript-source, .statistics-grid { grid-template-columns: 1fr; }
  .statistics-grid div + div { border-left: 0; border-top: 1px solid var(--line); }
  .prompt-content > div + div { border-left: 0; border-top: 1px solid var(--line); }
  .table-footer { flex-wrap: wrap; }
  .table-footer > span { margin-left: 0; }
  .table-footer .primary { width: 100%; }
}

html { background: #101827; }
body { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
.sidebar { padding-left: env(safe-area-inset-left); }
.main { padding-right: env(safe-area-inset-right); }
.install-card { margin:18px 0 0; padding:16px 18px; display:flex; align-items:center; justify-content:space-between; gap:16px; border-color:rgba(239,68,68,.28); background:linear-gradient(135deg,rgba(239,68,68,.10),rgba(255,255,255,.96)); }
.install-card[hidden] { display:none; }
.install-card p { margin:5px 0 0; color:var(--muted); }
@media (max-width:720px) {
  input,select,textarea,button { font-size:16px; }
  .main { padding-bottom:calc(24px + env(safe-area-inset-bottom)); }
  .install-card { align-items:flex-start; flex-direction:column; }
  .install-card .button { width:100%; }
  .document-editor { min-height:52vh; }
}