/* ccforge web frontend */

:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1c2330;
  --muted: #5f6b7a;
  --line: #e1e5eb;
  --accent: #2357c6;
  --accent-soft: #e8eefc;
  --error: #c62f2f;
  --error-soft: #fdecec;
  --warning: #a86100;
  --warning-soft: #fdf3e2;
  --info: #3f6f8f;
  --info-soft: #e9f2f8;
  --ok: #217a45;
  --ok-soft: #e6f4ec;
  --code: #f0f2f5;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 2px 8px rgba(20, 30, 50, .05);
  --radius: 8px;
  --on-accent: #ffffff;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --panel: #1c2027;
    --text: #e3e7ee;
    --muted: #9aa5b4;
    --line: #2d333d;
    --accent: #7aa2f7;
    --accent-soft: #233150;
    --error: #ff7b7b;
    --error-soft: #3a2224;
    --warning: #f0b35a;
    --warning-soft: #3a2f1c;
    --info: #8cc3e8;
    --info-soft: #1e3140;
    --ok: #6fd39a;
    --ok-soft: #1c3527;
    --code: #262b33;
    --shadow: none;
    --on-accent: #10141b;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--sans); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.boot { padding: 40px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.grow { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: 16px; }
.hidden { display: none !important; }

/* layout */
.topbar {
  height: 48px; display: flex; align-items: center; gap: 16px; padding: 0 16px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 16px; color: var(--text); letter-spacing: -.01em; }
.brand span { color: var(--accent); }
.crumbs { color: var(--muted); display: flex; gap: 6px; align-items: center; }
.crumbs a { color: var(--text); }
.user { display: flex; gap: 10px; align-items: center; color: var(--muted); }
.shell { display: grid; grid-template-columns: 260px 1fr; min-height: calc(100vh - 48px); }
.sidebar { border-right: 1px solid var(--line); background: var(--panel); padding: 12px 8px; overflow-y: auto; height: calc(100vh - 48px); position: sticky; top: 48px; }
.main { padding: 24px 32px; min-width: 0; max-width: 1400px; }
.main.wide { max-width: none; }
.main > .mobile-only { display: none; }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; position: static; height: auto; border-right: none; border-bottom: 1px solid var(--line); }
  .menu-open .sidebar { display: block; }
  .main { padding: 16px; }
  .main > .mobile-only { display: inline-flex; margin-bottom: 12px; }
  .user .name { display: none; }
  .links { grid-template-columns: 1fr; gap: 4px; }
  .links > dd { margin-bottom: 8px; }
}

/* sidebar */
.nav-group { margin: 14px 8px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.nav a { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 6px; color: var(--text); }
.nav a:hover { background: var(--bg); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav .count { margin-left: auto; color: var(--muted); font-size: 12px; }
.search { position: relative; margin: 0 4px 8px; }
.search input { width: 100%; }
.search-results {
  position: absolute; left: 0; right: 0; top: 36px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); z-index: 20; max-height: 360px; overflow-y: auto;
}
.search-results a { display: block; padding: 6px 10px; color: var(--text); border-bottom: 1px solid var(--line); }
.search-results a:hover, .search-results a.sel { background: var(--accent-soft); text-decoration: none; }

/* controls */
input, select, textarea {
  font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 9px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label.field { display: block; }
label.field > span { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
label.field input, label.field select, label.field textarea { width: 100%; }
.btn {
  font: inherit; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  padding: 6px 12px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--text);
}
.btn:hover { border-color: var(--muted); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--error); border-color: var(--error); }
.btn.danger.solid { background: var(--error); color: #fff; }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn.ghost { border-color: transparent; background: transparent; }

/* panels */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.stat { font-size: 26px; font-weight: 700; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.kv > dt { color: var(--muted); }
.kv > dd { margin: 0; }
.page-head { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 2px 0 0; }

/* tables */
table.list { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.list th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; background: var(--bg); }
table.list th, table.list td { padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tr:last-child td { border-bottom: none; }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: var(--accent-soft); }

/* badges and chips */
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--bg); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.badge.error { background: var(--error-soft); color: var(--error); border-color: transparent; }
.badge.warning { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.kind { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-family: var(--mono); font-size: 12px; padding: 2px 8px; border-radius: 6px; background: var(--code); color: var(--text); border: 1px solid var(--line); }
a.chip:hover { border-color: var(--accent); text-decoration: none; }
.chip.missing { border-style: dashed; border-color: var(--error); color: var(--error); }
.links { display: grid; grid-template-columns: 200px 1fr; gap: 10px 16px; align-items: start; }
.links > dt { color: var(--muted); padding-top: 2px; }
.links > dd { margin: 0; }

/* findings */
.finding { display: flex; gap: 10px; padding: 8px 12px; border-left: 3px solid var(--line); background: var(--panel); border-radius: 0 6px 6px 0; }
.finding + .finding { margin-top: 6px; }
.finding.error { border-left-color: var(--error); }
.finding.warning { border-left-color: var(--warning); }
.finding.info { border-left-color: var(--info); }
.finding > .badge { align-self: flex-start; margin-top: 2px; }
.finding .rule { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }
.finding .msg { word-break: break-word; }

/* rendered markdown */
.prose { max-width: 860px; overflow-wrap: anywhere; }
.prose p { margin: 0 0 .8em; }
.prose table { border-collapse: collapse; margin: .6em 0 1em; font-size: 13px; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--line); padding: 4px 8px; vertical-align: top; }
.prose th { background: var(--bg); }
.prose del { color: var(--error); }
.prose u { text-decoration-color: var(--accent); text-decoration-thickness: 2px; }
.prose code { background: var(--code); padding: 1px 4px; border-radius: 4px; }
.prose blockquote { margin: 0 0 1em; padding: 8px 14px; border-left: 3px solid var(--warning); background: var(--warning-soft); border-radius: 0 6px 6px 0; }
.prose blockquote p:last-child { margin: 0; }
.prose h1, .prose h2, .prose h3, .prose h4 { text-transform: none; letter-spacing: 0; color: var(--text); font-size: 15px; margin-top: 1.2em; }

/* tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 20px 0 16px; }
.tabs button { font: inherit; background: none; border: none; padding: 8px 14px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tabs .n { font-size: 11px; margin-left: 4px; }

/* editor */
.editor { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; min-height: 60vh; }
.editor textarea { width: 100%; height: 100%; min-height: 60vh; font: 13px/1.55 var(--mono); resize: vertical; tab-size: 2; }
.editor .preview { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 12px 16px; overflow: auto; max-height: 78vh; }
@media (max-width: 1100px) { .editor { grid-template-columns: 1fr; } }
.savebar { display: flex; gap: 8px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.savebar input { flex: 1; min-width: 220px; }
.help { font-size: 12.5px; }
.help code { background: var(--code); padding: 0 4px; border-radius: 3px; }

/* banners, toasts, modal */
.banner { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; }
.banner.error { background: var(--error-soft); color: var(--error); }
.banner.warning { background: var(--warning-soft); color: var(--warning); }
.banner.ok { background: var(--ok-soft); color: var(--ok); }
.banner.info { background: var(--info-soft); color: var(--info); }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--ok); box-shadow: 0 4px 16px rgba(0,0,0,.12); padding: 10px 14px; border-radius: 6px; max-width: 420px; }
.toast.error { border-left-color: var(--error); }
.modal-back { position: fixed; inset: 0; background: rgba(10, 15, 25, .45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border-radius: 10px; padding: 20px; width: 100%; max-width: 520px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal h2 { margin-bottom: 12px; }
.check-errors { margin: 0; padding-left: 18px; max-height: 40vh; overflow-y: auto; overflow-wrap: anywhere; }
.check-errors li { margin-bottom: 6px; }
.check-reason input { display: block; width: 100%; margin-top: 4px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* login */
.login { max-width: 400px; margin: 12vh auto; }
.login .card { padding: 28px; }

/* pdf */
.pdf { width: 100%; height: calc(100vh - 170px); border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { padding: 32px; text-align: center; color: var(--muted); }
.history li { margin-bottom: 8px; }

/* documents: CC components and open items */
.cc { display: inline-flex; align-items: center; gap: 4px; padding: 1px 6px 1px 8px; border: 1px solid var(--line); border-radius: 999px; font-size: 12px; background: var(--panel); }
.cc .badge { font-size: 10.5px; padding: 0 6px; }
.todo-mark { background: #ffd54f; color: #000; font-weight: 700; font-size: 11px; padding: 0 4px; border-radius: 3px; }

/* editor mode switch and visual editor */
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.segmented button { border: 0; background: var(--panel); color: var(--muted); padding: 4px 12px; font: inherit; font-size: 13px; cursor: pointer; }
.segmented button + button { border-left: 1px solid var(--line); }
.segmented button.active { background: var(--accent); color: var(--on-accent); }
.visual { border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.toolbar { display: flex; flex-wrap: wrap; gap: 2px; padding: 6px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 1; border-radius: 6px 6px 0 0; }
.toolbar .tool { min-width: 30px; height: 28px; padding: 0 8px; border: 1px solid transparent; border-radius: 4px; background: transparent; color: var(--text); font: inherit; font-size: 13px; cursor: pointer; }
.toolbar .tool:hover:not(:disabled) { background: var(--bg); border-color: var(--line); }
.toolbar .tool.active { background: var(--info-soft); color: var(--info); border-color: transparent; }
.toolbar .tool:disabled { opacity: 0.35; cursor: default; }
.toolbar .tool[title^="Refinement"] { font-weight: 700; }
.toolbar .tool[title^="Assignment"] { font-style: italic; }
.toolbar .tool[title^="Selection"] { text-decoration: underline; }
.toolbar .tool[title^="Deleted"] { text-decoration: line-through; }
.toolbar .sep { width: 1px; background: var(--line); margin: 2px 6px; }
.wysiwyg .ProseMirror { min-height: 55vh; padding: 12px 16px; outline: none; }
.wysiwyg .ProseMirror:focus-visible { box-shadow: inset 0 0 0 2px var(--info-soft); }
.wysiwyg table { border-collapse: collapse; margin: 8px 0; }
.wysiwyg td, .wysiwyg th { border: 1px solid var(--line); padding: 4px 8px; min-width: 3em; vertical-align: top; }
.wysiwyg .selectedCell { background: var(--info-soft); }
.frontmatter { margin-bottom: 8px; }
.frontmatter summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.frontmatter pre { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; font: 12px/1.5 var(--mono); overflow: auto; }

/* ProseMirror base styles (the editor's own style injection is off because of the CSP) */
.ProseMirror { position: relative; word-wrap: break-word; white-space: pre-wrap; white-space: break-spaces; font-variant-ligatures: none; font-feature-settings: "liga" 0; }
.ProseMirror pre { white-space: pre-wrap; }
.ProseMirror li { position: relative; }
.ProseMirror-hideselection *::selection { background: transparent; }
.ProseMirror-hideselection { caret-color: transparent; }
.ProseMirror [draggable][contenteditable=false] { user-select: text; }
.ProseMirror-selectednode { outline: 2px solid var(--info); }
li.ProseMirror-selectednode { outline: none; }
img.ProseMirror-separator { display: inline !important; border: none !important; margin: 0 !important; }
.ProseMirror-gapcursor { display: none; pointer-events: none; position: absolute; }
.ProseMirror-gapcursor:after { content: ""; display: block; position: absolute; top: -2px; width: 20px; border-top: 1px solid var(--text); animation: pm-cursor-blink 1.1s steps(2, start) infinite; }
@keyframes pm-cursor-blink { to { visibility: hidden; } }
.ProseMirror-focused .ProseMirror-gapcursor { display: block; }
.tableWrapper { overflow-x: auto; }

/* evaluation delivery */
.check { display: flex; gap: 8px; align-items: baseline; }
.banner ul { margin: 4px 0 0 18px; padding: 0; }

/* variables */
.vars input { width: 100%; }
.vars td:nth-child(3) { width: 4em; text-align: right; }

/* New project */
.wizard { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 24px; align-items: start; max-width: 1040px; }
.wizard-summary { position: sticky; top: 16px; display: grid; gap: 12px; }
.wizard-steps { list-style: none; display: flex; flex-wrap: wrap; gap: 4px; margin: 0; padding: 0; }
.wizard-steps button { background: transparent; border: 0; border-bottom: 2px solid var(--line); color: var(--muted); padding: 6px 10px; font: inherit; cursor: pointer; }
.wizard-steps button:disabled { cursor: default; opacity: .6; }
.wizard-steps .done button { color: var(--text); }
.wizard-steps .current button { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.choices { display: grid; gap: 8px; }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; cursor: pointer; }
.choice input { margin-top: 3px; flex: none; }
.choice-text { display: grid; gap: 2px; min-width: 0; overflow-wrap: anywhere; }
.factor-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.attacker-score { display: flex; gap: 12px; align-items: center; }
.attacker-score .score { font-size: 34px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.wizard-facts { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 12px; margin: 0; }
.wizard-facts dt { color: var(--muted); }
.wizard-facts dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 820px) {
  .wizard { grid-template-columns: minmax(0, 1fr); }
  .wizard-summary { position: static; grid-row: 1; }
}
