/* ShipSafe v2 Workbench Enhancements: Dark Theme, IDE Code Evidence, Auto-Fix Diff, Release Gate & Trends */

:root[data-theme="dark"] {
  --bg: #0b111a;
  --paper: #111926;
  --side: #0e1521;
  --ink: #e8eef5;
  --muted: #93a4b8;
  --line: #213044;
  --line-strong: #2f435e;
  --blue: #4f9cf9;
  --blue-hover: #73b2ff;
  --blue-soft: rgba(79, 156, 249, 0.14);
  --green: #34d399;
  --green-soft: rgba(52, 211, 153, 0.14);
  --red: #fb7185;
  color-scheme: dark;
}

:root[data-theme="dark"] .topbar,
:root[data-theme="dark"] .mobile-report-actions {
  background: rgba(11, 17, 26, 0.94);
  border-color: var(--line);
}
:root[data-theme="dark"] .panel,
:root[data-theme="dark"] .finding,
:root[data-theme="dark"] .report-summary,
:root[data-theme="dark"] .history-card,
:root[data-theme="dark"] .compare-panel,
:root[data-theme="dark"] .recent-panel,
:root[data-theme="dark"] .scope-panel,
:root[data-theme="dark"] .workbench-frame,
:root[data-theme="dark"] .report-empty,
:root[data-theme="dark"] .report-boundary,
:root[data-theme="dark"] .prompt-block,
:root[data-theme="dark"] .example-recheck-bar,
:root[data-theme="dark"] .info-banner,
:root[data-theme="dark"] dialog {
  background: var(--paper);
  border-color: var(--line);
  color: var(--ink);
}
:root[data-theme="dark"] .sidebar {
  background: var(--side);
  border-color: var(--line);
}
:root[data-theme="dark"] .sidebar nav a {
  color: #cbd5e1;
}
:root[data-theme="dark"] .sidebar nav a.active,
:root[data-theme="dark"] .sidebar nav a[aria-current="page"] {
  background: rgba(79, 156, 249, 0.16);
  color: #93c5fd;
  border-color: rgba(79, 156, 249, 0.35);
}
:root[data-theme="dark"] .evidence-block,
:root[data-theme="dark"] .finding-body .evidence-block,
:root[data-theme="dark"] .prompt-block pre,
:root[data-theme="dark"] .finding-body .prompt-block pre,
:root[data-theme="dark"] textarea,
:root[data-theme="dark"] input,
:root[data-theme="dark"] select,
:root[data-theme="dark"] .finding-search input,
:root[data-theme="dark"] .finding-search select,
:root[data-theme="dark"] #finding-search,
:root[data-theme="dark"] #finding-category {
  background: #090f18;
  border-color: var(--line-strong);
  color: #e6edf6;
}
:root[data-theme="dark"] .finding-search input::placeholder {
  color: #7b8fa6;
}
:root[data-theme="dark"] .report-actions .button.secondary,
:root[data-theme="dark"] .mobile-report-actions .button.secondary,
:root[data-theme="dark"] .finding-locate,
:root[data-theme="dark"] .copy-prompt {
  background: #172436;
  border-color: #334a68;
  color: #e8eef5;
}
:root[data-theme="dark"] .prompt-block h4,
:root[data-theme="dark"] .finding-body h4,
:root[data-theme="dark"] .finding-body p,
:root[data-theme="dark"] .finding-name,
:root[data-theme="dark"] .report-summary p,
:root[data-theme="dark"] .report-boundary li {
  color: #dce6f2;
}
:root[data-theme="dark"] .finding summary small,
:root[data-theme="dark"] .finding-rule,
:root[data-theme="dark"] .report-metadata,
:root[data-theme="dark"] .privacy-note p {
  color: #94a3b8;
}
:root[data-theme="dark"] .button.secondary,
:root[data-theme="dark"] .copy-prompt {
  background: #172436;
  border-color: #334a68;
  color: #e8eef5;
}
:root[data-theme="dark"] .button.secondary:hover,
:root[data-theme="dark"] .copy-prompt:hover {
  background: #1f3149;
  border-color: var(--blue);
  color: #ffffff;
}
:root[data-theme="dark"] .button.primary {
  background: #2563eb;
  border-color: #3b82f6;
  color: #ffffff;
}
:root[data-theme="dark"] .filter {
  background: #142030;
  border-color: var(--line-strong);
  color: #cbd5e1;
}
:root[data-theme="dark"] .filter.active {
  background: #2563eb;
  border-color: #3b82f6;
  color: #ffffff;
}
:root[data-theme="dark"] .category-status b {
  background: rgba(251, 146, 60, 0.16);
  color: #fdba74;
  border-color: rgba(251, 146, 60, 0.3);
}
:root[data-theme="dark"] .category-status b.pass {
  background: rgba(52, 211, 153, 0.14);
  color: #6ee7b7;
  border-color: rgba(52, 211, 153, 0.28);
}
:root[data-theme="dark"] .category-select {
  color: #93c5fd;
}
:root[data-theme="dark"] .text-button {
  color: #7cc0ff;
}
:root[data-theme="dark"] #view-report :is(.evidence-block, .prompt-block pre) {
  color: #e6edf6;
  background: #090f18;
  border-color: var(--line-strong);
}
:root[data-theme="dark"] #view-report .severity.critical { background: rgba(251, 113, 133, 0.18); color: #fda4af; }
:root[data-theme="dark"] #view-report .severity.high { background: rgba(251, 146, 60, 0.18); color: #fdba74; }
:root[data-theme="dark"] #view-report .severity.medium { background: rgba(250, 204, 21, 0.16); color: #fde047; }
:root[data-theme="dark"] #view-report .severity.low { background: rgba(96, 165, 250, 0.18); color: #93c5fd; }
:root[data-theme="dark"] #view-report .category-row b { color: #fdba74; }
:root[data-theme="dark"] #view-report .category-row b.pass { color: #6ee7b7; }
:root[data-theme="dark"] #view-report .report-actions .button.secondary {
  background: #172436;
  border-color: #334a68;
  color: #e8eef5;
}
:root[data-theme="dark"] .score-ring b { color: #f8fafc; }
:root[data-theme="dark"] .score-ring small { color: #94a3b8; }
:root[data-theme="dark"] .unlock-panel.unlock-ready {
  background: linear-gradient(180deg, #132236 0%, #101b2a 100%);
  border-color: #2c4a70;
}
:root[data-theme="dark"] .toast {
  background: #1e293b;
  color: #f8fafc;
  border: 1px solid #3b82f6;
}

/* Theme toggle & topbar alignment */
.theme-toggle {
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--paper);
  font-size: 12px;
  color: var(--muted);
  transition: border-color 160ms ease, color 160ms ease;
}
.theme-toggle:hover {
  border-color: var(--blue);
  color: var(--ink);
}

/* Security Grade & Suppressed Strip */
.report-grade-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}
.grade-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.grade-pass { background: var(--green-soft); color: var(--green); border: 1px solid rgba(22, 94, 66, 0.25); }
.grade-good { background: var(--blue-soft); color: var(--blue); border: 1px solid rgba(15, 76, 129, 0.25); }
.grade-warn { background: #fef3c7; color: #92400e; border: 1px solid #f59e0b44; }
.grade-fail { background: #fee2e2; color: #991b1b; border: 1px solid #ef444444; }
:root[data-theme="dark"] .grade-warn { background: rgba(245, 158, 11, 0.16); color: #fcd34d; }
:root[data-theme="dark"] .grade-fail { background: rgba(239, 68, 68, 0.16); color: #fca5a5; }

.suppressed-pill {
  font-size: 12px;
  color: var(--muted);
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
}

/* Release Gate Panel */
.release-gate-panel { margin-bottom: 14px; }
.gate-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
}
.gate-item {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--bg);
}
.gate-item strong { display: block; font-size: 13px; line-height: 1.3; }
.gate-item small { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; line-height: 1.4; }
.gate-icon {
  flex: 0 0 20px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  margin-top: 1px;
}
.gate-pass .gate-icon { background: var(--green-soft); color: var(--green); }
.gate-warn .gate-icon { background: #fef3c7; color: #92400e; }
.gate-block .gate-icon { background: #fee2e2; color: #b91c1c; }
:root[data-theme="dark"] .gate-warn .gate-icon { background: rgba(245, 158, 11, 0.2); color: #fcd34d; }
:root[data-theme="dark"] .gate-block .gate-icon { background: rgba(239, 68, 68, 0.22); color: #fda4af; }

/* View Mode Switch (List vs By-File) & Triage */
.report-view-toggle {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg);
}
.report-view-toggle button {
  border: 0;
  background: transparent;
  padding: 5px 11px;
  font-size: 12px;
  color: var(--muted);
}
.report-view-toggle button.is-active {
  background: var(--paper);
  color: var(--ink);
  font-weight: 600;
}

.triage-progress {
  margin: 10px 0;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper);
  font-size: 13px;
}
.triage-bar { width: 100%; height: 8px; accent-color: var(--green); }
.triage-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0 6px;
}
.triage-chip {
  padding: 3px 10px;
  font-size: 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--muted);
  transition: border-color 150ms ease, background 150ms ease, color 150ms ease;
}
.triage-chip.is-active {
  border-color: var(--blue);
  background: var(--blue-soft);
  color: var(--blue);
  font-weight: 600;
}
.finding[data-triage="fixed"] summary,
.finding[data-triage="ignored"] summary {
  opacity: 0.72;
}

/* IDE Code Context & Auto-Fix Diff Card */
.evidence-ide {
  margin: 8px 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #0d1522;
  color: #dbe7f3;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.55;
  overflow-x: auto;
  padding: 8px 0;
}
.code-ctx-line {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  padding: 1px 12px 1px 0;
}
.code-ctx-line.is-hit {
  background: #311c27;
  border-left: 3px solid #f87171;
}
.code-ctx-ln {
  text-align: right;
  padding-right: 12px;
  color: #64748b;
  user-select: none;
  font-variant-numeric: tabular-nums;
}
.code-ctx-src { white-space: pre; }
.tok-kw { color: #7dd3fc; }
.tok-str { color: #86efac; }
.tok-num { color: #fcd34d; }
.tok-cmt { color: #64748b; font-style: italic; }
.tok-mask { color: #fda4af; background: rgba(244, 63, 94, 0.18); padding: 0 4px; border-radius: 3px; }

.autofix-card {
  margin: 12px 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
  background: var(--bg);
}
.autofix-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  font-weight: 600;
}
.autofix-actions { display: flex; align-items: center; gap: 8px; }
.autofix-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
}
.autofix-diff {
  font-family: var(--font-mono);
  font-size: 12.5px;
  overflow-x: auto;
}
.diff-line {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  padding: 5px 12px;
  white-space: pre;
}
.diff-del { background: rgba(239, 68, 68, 0.11); color: #b91c1c; }
.diff-add { background: rgba(16, 185, 129, 0.12); color: #065f46; }
:root[data-theme="dark"] .diff-del { background: rgba(239, 68, 68, 0.18); color: #fca5a5; }
:root[data-theme="dark"] .diff-add { background: rgba(16, 185, 129, 0.18); color: #6ee7b7; }

/* File-grouped findings view */
.file-group-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  margin-bottom: 12px;
  overflow: hidden;
}
.file-group-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.file-group-head code { font-family: var(--font-mono); word-break: break-all; }
.file-group-count {
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}
.file-group-count.is-danger { background: #fee2e2; color: #b91c1c; }
.file-group-count.is-warn { background: #fef3c7; color: #92400e; }
:root[data-theme="dark"] .file-group-count.is-danger { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }
:root[data-theme="dark"] .file-group-count.is-warn { background: rgba(245, 158, 11, 0.2); color: #fcd34d; }
.file-group-items { padding: 10px; display: grid; gap: 8px; }

/* Extra export buttons in repair pack */
.export-actions-secondary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.export-actions-secondary .button {
  font-size: 12px;
  padding: 6px 10px;
}

/* History Trend Chart */
.history-trend { margin-bottom: 16px; }
.history-trend-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}
.history-trend-head strong { display: block; font-size: 15px; }
.history-trend-head small { color: var(--muted); font-size: 12px; }
.trend-kpis { display: flex; gap: 14px; font-size: 13px; color: var(--muted); }
.trend-kpis b { color: var(--ink); font-variant-numeric: tabular-nums; }
.trend-up { color: var(--green) !important; }
.trend-down { color: var(--red) !important; }
.trend-svg { width: 100%; height: 112px; display: block; }
.trend-grid { stroke: var(--line); stroke-dasharray: 3 3; stroke-width: 1; }
.trend-area { fill: var(--blue-soft); }
.trend-line { fill: none; stroke: var(--blue); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.trend-dot { fill: var(--paper); stroke: var(--blue); stroke-width: 2; }

/* Guide Integration Panel (CLI & MCP) */
.guide-integration {
  margin-top: 16px;
}
.guide-integration pre {
  background: #0d1522;
  color: #e2e8f0;
  padding: 12px 14px;
  border-radius: 7px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  overflow-x: auto;
  margin: 8px 0 0;
}
.guide-integration-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
  margin-top: 10px;
}

/* ==========================================================================
   Report Redesign: Top Release-Gate Banner, Demoted Score Ring,
   Unified IDE Evidence, Finding-Card Paywall Preview & Desktop Sticky Rail
   ========================================================================== */

.release-gate-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  margin: 0 0 18px;
  padding: 14px 18px;
  border-radius: 10px;
  border: 1px solid var(--line);
  border-left-width: 4px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 140ms ease, background-color 140ms ease, box-shadow 140ms ease;
}
.release-gate-banner:hover {
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.06);
}
.release-gate-banner:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}
.release-gate-banner.is-block {
  background: #fef2f2;
  border-color: #fecaca;
  border-left-color: #dc2626;
  color: #7f1d1d;
}
.release-gate-banner.is-warn {
  background: #fffbeb;
  border-color: #fde68a;
  border-left-color: #d97706;
  color: #78350f;
}
.release-gate-banner.is-pass {
  background: #ecfdf5;
  border-color: #a7f3d0;
  border-left-color: #16a34a;
  color: #14532d;
}
:root[data-theme="dark"] .release-gate-banner.is-block {
  background: rgba(220, 38, 38, 0.14);
  border-color: rgba(248, 113, 113, 0.32);
  border-left-color: #f87171;
  color: #fecaca;
}
:root[data-theme="dark"] .release-gate-banner.is-warn {
  background: rgba(217, 119, 6, 0.16);
  border-color: rgba(251, 191, 36, 0.34);
  border-left-color: #fbbf24;
  color: #fde68a;
}
:root[data-theme="dark"] .release-gate-banner.is-pass {
  background: rgba(22, 163, 74, 0.16);
  border-color: rgba(74, 222, 128, 0.34);
  border-left-color: #4ade80;
  color: #bbf7d0;
}
.gate-banner-icon {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
}
.release-gate-banner.is-block .gate-banner-icon { background: #dc2626; color: #ffffff; }
.release-gate-banner.is-warn .gate-banner-icon { background: #d97706; color: #ffffff; }
.release-gate-banner.is-pass .gate-banner-icon { background: #16a34a; color: #ffffff; }
.gate-banner-copy {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 2px;
}
.gate-banner-copy strong {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.3;
}
.gate-banner-copy small {
  font-size: 13px;
  line-height: 1.45;
  opacity: 0.9;
}
.gate-banner-cta {
  flex: none;
  font-size: 12.5px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid currentColor;
  white-space: nowrap;
  opacity: 0.88;
}
.release-gate-banner:hover .gate-banner-cta {
  opacity: 1;
}
.release-gate-panel.is-highlighted {
  box-shadow: 0 0 0 2px var(--blue), 0 8px 24px rgba(40, 84, 202, 0.16);
  transition: box-shadow 220ms ease;
}

/* Visually demote secondary 0/100 score ring so gate banner leads hierarchy */
.report-summary {
  grid-template-columns: 90px minmax(0, 1fr);
  gap: 16px;
  padding: 18px 20px;
}
.report-summary .score-ring {
  width: 84px;
  height: 84px;
  border-width: 1px;
  border-color: var(--line);
  background: var(--bg);
  box-shadow: none;
}
.report-summary .score-ring b {
  font-size: 20px;
  font-weight: 600;
  line-height: 1.1;
  color: var(--ink);
}
.report-summary .score-ring small {
  font-size: 9px;
  letter-spacing: -0.02em;
  margin-top: 2px;
  color: var(--muted);
}
.report-summary .score-dial .dial-track,
.report-summary .score-dial-critical .dial-track {
  stroke: var(--line);
  stroke-width: 4.5;
}
.report-summary .score-dial .dial-progress {
  stroke-width: 4.5;
}
.report-summary .score-dial-critical .dial-progress {
  stroke: #b91c1c;
  opacity: 0.85;
}
:root[data-theme="dark"] .report-summary .score-ring {
  background: #101826;
}
:root[data-theme="dark"] .report-summary .score-dial-critical .dial-progress {
  stroke: #f87171;
  opacity: 0.92;
}

/* Unified single-block IDE evidence containing .evidence-block */
#view-report .evidence-ide .evidence-block,
.evidence-ide .evidence-block {
  display: block;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #e2e8f0;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  white-space: pre;
  overflow: visible;
}

/* Finding-card forward paywall preview (locked generic pseudocode diff) */
.autofix-preview.autofix-locked-card {
  margin: 12px 0 14px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--paper);
}
.autofix-preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.autofix-preview-head strong {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}
.autofix-preview-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue);
  white-space: nowrap;
}
.autofix-blurred-stage {
  position: relative;
  overflow: hidden;
}
.autofix-blurred-diff {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 6px 0;
  filter: blur(4px);
  user-select: none;
  pointer-events: none;
  opacity: 0.72;
}
.autofix-locked-overlay {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 14px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  background: var(--bg);
}
.autofix-locked-overlay span {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.45;
  flex: 1 1 220px;
}
.autofix-unlock-btn {
  flex: none;
  padding: 7px 14px;
  font-size: 13px;
}

/* Desktop sticky right-aside delivery card without mobile bar conflict */
.aside-sticky-group {
  display: grid;
  gap: 12px;
}
@media (min-width: 1001px) {
  .report-aside {
    align-self: stretch;
    position: static;
    display: flex;
    flex-direction: column;
    gap: 16px;
  }
  .aside-sticky-group {
    position: sticky;
    top: 20px;
  }
}
@media (max-width: 1000px) {
  .aside-sticky-group {
    position: static;
  }
}
@media (max-width: 640px) {
  .release-gate-banner {
    flex-wrap: wrap;
    padding: 12px 14px;
    gap: 10px;
  }
  .gate-banner-cta {
    margin-left: auto;
  }
  .report-summary {
    grid-template-columns: 1fr;
  }
  .autofix-unlock-btn {
    width: 100%;
  }
}
