:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-soft: #f8faf9;
  --ink: #18201d;
  --muted: #68726e;
  --line: #dde3e0;
  --line-strong: #cbd4d0;
  --green: #176b4d;
  --green-soft: #e3f1eb;
  --blue: #2d5f8b;
  --blue-soft: #e8f0f7;
  --amber: #9b6615;
  --amber-soft: #f8eedb;
  --red: #a53a3a;
  --red-soft: #f8e7e7;
  --sidebar: #17221e;
  --shadow: 0 10px 30px rgba(19, 36, 29, 0.07);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, "Noto Sans SC", system-ui, sans-serif;
  letter-spacing: 0;
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 232px minmax(0, 1fr); }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 232px;
  background: var(--sidebar);
  color: #e9efec;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 26px; font-size: 17px; font-weight: 700; }
.brand-mark { width: 32px; height: 32px; display: grid; place-items: center; color: #daf0e5; background: #2b493e; border-radius: 7px; }
.brand-mark svg { width: 18px; }
.nav { display: grid; gap: 5px; }
.nav-item { height: 43px; border: 0; border-radius: 6px; color: #aebbb5; background: transparent; display: flex; align-items: center; gap: 11px; padding: 0 12px; text-align: left; }
.nav-item svg { width: 18px; }
.nav-item:hover { color: #fff; background: #22332d; }
.nav-item.active { color: #fff; background: #29473c; }
.sidebar-footer { margin-top: auto; padding: 15px 10px 2px; border-top: 1px solid #314139; display: grid; gap: 7px; font-size: 12px; color: #aebbb5; }
.mode-row { display: flex; align-items: center; gap: 7px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #65c99d; }
.version { color: #71837b; }

.main { grid-column: 2; min-width: 0; }
.topbar { height: 82px; background: rgba(255,255,255,.9); border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 34px; position: sticky; top: 0; z-index: 10; backdrop-filter: blur(8px); }
.topbar h1 { font-size: 20px; margin: 3px 0 0; font-weight: 650; }
.eyebrow, .step-label { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.status-pill { border: 1px solid var(--line); background: var(--surface-soft); color: var(--muted); border-radius: 999px; padding: 6px 10px; font-size: 12px; }
.status-pill.ready { color: var(--green); background: var(--green-soft); border-color: #c7e1d5; }
.mobile-menu { display: none !important; }

.view { display: none; padding: 30px 34px 46px; max-width: 1440px; margin: 0 auto; }
.view.active { display: block; }
.workspace-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(330px, .65fr); gap: 22px; min-height: calc(100vh - 158px); }
.input-pane, .run-pane, .panel, .comment-table-wrap, .prd-document { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.input-pane, .run-pane { padding: 24px; }
.input-pane { display: flex; flex-direction: column; }
.section-heading, .panel-heading, .prd-toolbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.section-heading { margin-bottom: 22px; }
.section-heading h2, .panel-heading h2, .prd-toolbar h2 { margin: 5px 0 0; font-size: 17px; }
.input-label, .project-field label, .field-label { display: block; font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 8px; }
textarea { flex: 1; min-height: 390px; width: 100%; resize: vertical; border: 1px solid var(--line-strong); border-radius: 6px; padding: 15px; color: var(--ink); line-height: 1.75; background: #fbfcfc; outline: none; }
textarea:focus, input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(23, 107, 77, .1); }
.input-footer { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-top: 10px; }
.input-footer strong { color: var(--ink); }
.project-field { margin-bottom: 20px; }
.project-field input { width: 100%; height: 42px; padding: 0 11px; border: 1px solid var(--line-strong); border-radius: 6px; outline: none; }
.mode-field { margin-bottom: 18px; }
.segmented-control { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; padding: 3px; border: 1px solid var(--line); border-radius: 7px; background: #eef2f0; }
.mode-button { min-height: 38px; border: 0; border-radius: 5px; display: flex; align-items: center; justify-content: center; gap: 7px; color: var(--muted); background: transparent; font-size: 12px; font-weight: 650; }
.mode-button svg { width: 15px; }
.mode-button.active { color: var(--green); background: var(--surface); box-shadow: 0 1px 4px rgba(19,36,29,.08); }
.mode-button:disabled { cursor: not-allowed; opacity: .48; }
.mode-message { display: block; color: var(--muted); font-size: 11px; margin-top: 7px; }

.primary-button, .secondary-button, .icon-button { border: 0; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: 6px; font-weight: 650; }
.primary-button { min-height: 43px; padding: 0 16px; color: #fff; background: var(--green); }
.primary-button:hover { background: #12583f; }
.primary-button:disabled { cursor: wait; opacity: .7; }
.secondary-button { min-height: 38px; padding: 0 13px; color: var(--ink); border: 1px solid var(--line-strong); background: var(--surface); }
.secondary-button:hover { background: var(--surface-soft); }
.primary-button svg, .secondary-button svg { width: 16px; }
.primary-button.compact { min-height: 35px; font-size: 13px; }
.full-width { width: 100%; }
.icon-button { width: 35px; height: 35px; background: transparent; color: var(--muted); }
.icon-button:hover { background: var(--surface-soft); color: var(--ink); }
.icon-button svg { width: 18px; }

.pipeline { display: grid; gap: 2px; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; margin-bottom: 18px; }
.pipeline-step { min-height: 68px; display: grid; grid-template-columns: 38px minmax(0,1fr) 22px; gap: 10px; align-items: center; padding: 10px 13px; background: var(--surface); border-bottom: 1px solid var(--line); }
.pipeline-step:last-child { border-bottom: 0; }
.step-icon { width: 34px; height: 34px; border-radius: 6px; display: grid; place-items: center; color: var(--blue); background: var(--blue-soft); }
.step-icon svg { width: 17px; }
.pipeline-step strong { display: block; font-size: 13px; margin-bottom: 4px; }
.pipeline-step span { color: var(--muted); font-size: 11px; }
.pipeline-step .step-state { width: 16px; color: #b8c1bd; }
.pipeline-step.running { background: #f7fbf9; }
.pipeline-step.running .step-state { color: var(--green); animation: pulse 1s infinite; }
.pipeline-step.done .step-state { color: var(--green); }
.privacy-note { display: flex; align-items: center; justify-content: center; gap: 6px; color: var(--muted); font-size: 11px; margin-top: 12px; }
.privacy-note svg { width: 14px; }
.inline-alert { margin-bottom: 12px; padding: 9px 11px; border-radius: 5px; color: var(--red); background: var(--red-soft); font-size: 12px; }

.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.metric { min-height: 112px; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; padding: 17px; }
.metric-label { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 12px; }
.metric-label svg { width: 16px; }
.metric-value { display: block; margin-top: 16px; font-size: 28px; font-weight: 700; }
.metric-note { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; }
.overview-grid { display: grid; grid-template-columns: minmax(0, .95fr) minmax(0, 1.05fr); gap: 18px; }
.panel { padding: 20px; }
.panel-heading { margin-bottom: 20px; }
.subtle { color: var(--muted); font-size: 11px; padding-top: 4px; }
.theme-chart { display: grid; gap: 18px; }
.chart-row { display: grid; grid-template-columns: 108px minmax(80px,1fr) 42px; align-items: center; gap: 12px; font-size: 12px; }
.chart-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chart-track { height: 9px; background: #edf1ef; border-radius: 2px; overflow: hidden; }
.chart-bar { height: 100%; background: var(--blue); border-radius: 2px; }
.chart-value { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }

.priority-list { display: grid; gap: 8px; }
.priority-item { width: 100%; min-height: 64px; border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 10px 12px; display: grid; grid-template-columns: 46px minmax(0,1fr) 54px 18px; gap: 9px; align-items: center; text-align: left; color: var(--ink); }
.priority-item:hover, .priority-item.active { border-color: #94b8a9; background: #f7fbf9; }
.priority-item > span:nth-child(2) { min-width: 0; }
.priority-item strong { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.priority-item small { display: block; color: var(--muted); margin-top: 4px; }
.priority-item .score { font-size: 18px; font-weight: 700; text-align: right; }
.priority-item > svg { width: 16px; color: var(--muted); }
.priority-badge, .clean-badge, .sentiment-badge { display: inline-flex; align-items: center; justify-content: center; width: fit-content; border-radius: 4px; padding: 4px 7px; font-size: 11px; font-weight: 700; }
.p0 { color: var(--red); background: var(--red-soft); }
.p1 { color: var(--amber); background: var(--amber-soft); }
.p2 { color: var(--blue); background: var(--blue-soft); }
.p3 { color: var(--muted); background: #edf1ef; }
.evidence-panel { margin-top: 18px; }
.evidence-layout { display: grid; grid-template-columns: minmax(0,1.2fr) minmax(250px,.8fr); gap: 22px; }
.evidence-quotes { display: grid; gap: 8px; }
.quote { padding: 12px 14px; background: var(--surface-soft); border-left: 3px solid var(--blue); font-size: 13px; line-height: 1.55; }
.score-breakdown { display: grid; gap: 10px; }
.score-line { display: grid; grid-template-columns: 70px 1fr 30px; align-items: center; gap: 9px; font-size: 11px; }
.score-line .track { height: 6px; background: #edf1ef; }
.score-line .fill { height: 100%; background: var(--green); }
.recommendation { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 13px; line-height: 1.6; }

.filter-bar { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 14px; }
.filter-button { border: 1px solid var(--line); background: var(--surface); border-radius: 5px; padding: 7px 10px; color: var(--muted); font-size: 12px; }
.filter-button.active { color: var(--green); border-color: #9cc3b2; background: var(--green-soft); }
.comment-table-wrap { overflow: hidden; }
.comment-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 12px; }
.comment-table th { color: var(--muted); background: var(--surface-soft); text-align: left; padding: 12px 15px; border-bottom: 1px solid var(--line); font-weight: 600; }
.comment-table td { padding: 13px 15px; border-bottom: 1px solid var(--line); vertical-align: top; line-height: 1.5; }
.comment-table tr:last-child td { border-bottom: 0; }
.comment-table th:first-child { width: 48%; }
.clean-valid { color: var(--green); background: var(--green-soft); }
.clean-low { color: var(--amber); background: var(--amber-soft); }
.clean-duplicate { color: var(--blue); background: var(--blue-soft); }
.clean-junk { color: var(--red); background: var(--red-soft); }
.sentiment-negative { color: var(--red); background: var(--red-soft); }
.sentiment-positive { color: var(--green); background: var(--green-soft); }
.sentiment-neutral { color: var(--muted); background: #edf1ef; }
.theme-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.theme-tag { display: inline-flex; align-items: center; min-height: 24px; padding: 3px 7px; border-radius: 4px; color: var(--blue); background: var(--blue-soft); font-size: 11px; white-space: nowrap; }

.prd-toolbar { margin-bottom: 16px; align-items: center; }
.prd-document { max-width: 900px; padding: 34px 42px; box-shadow: none; }
.prd-document h3 { font-size: 15px; margin: 25px 0 9px; }
.prd-document h3:first-child { margin-top: 0; }
.prd-document p, .prd-document li { color: #37413d; font-size: 13px; line-height: 1.75; }
.prd-document blockquote { margin: 10px 0; padding: 10px 14px; background: var(--surface-soft); border-left: 3px solid var(--green); font-size: 13px; }
.empty-state { min-height: 420px; display: grid; place-content: center; justify-items: center; text-align: center; color: var(--muted); }
.empty-state svg { width: 32px; height: 32px; }
.empty-state h2 { color: var(--ink); font-size: 17px; margin: 14px 0; }
.toast { position: fixed; right: 24px; bottom: 24px; transform: translateY(18px); opacity: 0; pointer-events: none; padding: 11px 14px; color: #fff; background: #1f2c27; border-radius: 6px; box-shadow: var(--shadow); font-size: 12px; transition: .2s ease; z-index: 40; }
.toast.show { transform: translateY(0); opacity: 1; }
.popover { position: fixed; right: 34px; top: 124px; width: 280px; padding: 13px; background: #1f2c27; color: #fff; border-radius: 6px; box-shadow: var(--shadow); z-index: 30; font-size: 11px; }
.popover strong, .popover span { display: block; }
.popover span { color: #c7d2cd; margin-top: 7px; line-height: 1.5; }

@keyframes pulse { 50% { opacity: .35; } }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 76px minmax(0,1fr); }
  .sidebar { width: 76px; padding: 22px 12px; }
  .brand { justify-content: center; padding: 0 0 26px; }
  .brand > span:last-child, .nav-item span, .sidebar-footer { display: none; }
  .nav-item { justify-content: center; padding: 0; }
  .main { grid-column: 2; }
  .workspace-grid, .overview-grid { grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .app-shell { display: block; }
  .sidebar { width: 232px; transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .sidebar .brand { justify-content: flex-start; padding-left: 8px; }
  .sidebar .brand > span:last-child, .sidebar .nav-item span, .sidebar .sidebar-footer { display: flex; }
  .sidebar .nav-item { justify-content: flex-start; padding: 0 12px; }
  .sidebar .sidebar-footer { display: grid; }
  .main { width: 100%; }
  .topbar { height: 72px; padding: 0 16px; }
  .mobile-menu { display: inline-flex !important; flex: 0 0 auto; margin-right: 8px; }
  .topbar > div:nth-child(2) { flex: 1; min-width: 0; }
  .topbar h1 { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .eyebrow { display: none; }
  .topbar-actions .status-pill { display: none; }
  .primary-button.compact span { display: none; }
  .primary-button.compact { width: 36px; padding: 0; }
  .view { padding: 18px 14px 32px; }
  .workspace-grid { min-height: auto; gap: 14px; }
  .input-pane, .run-pane, .panel { padding: 16px; }
  textarea { min-height: 300px; }
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .metric { min-height: 94px; padding: 13px; }
  .metric-value { margin-top: 12px; font-size: 23px; }
  .evidence-layout { grid-template-columns: 1fr; }
  .chart-row { grid-template-columns: 88px minmax(60px,1fr) 38px; gap: 8px; }
  .priority-item { grid-template-columns: 42px minmax(0,1fr) 42px 16px; }
  .comment-table { min-width: 720px; }
  .comment-table-wrap { overflow-x: auto; }
  .prd-document { padding: 22px 18px; }
  .popover { right: 14px; left: 14px; width: auto; top: 92px; }
}
