:root {
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #f0f2f5; --border: #e3e6eb;
  --text: #15181e; --muted: #5d6572; --faint: #8b93a0;
  --accent: #4f46e5; --accent-soft: #eef0ff;
  --red: #c62828; --red-soft: #fdecec; --amber: #a15c00; --amber-soft: #fff4e0;
  --green: #1b7f3b; --green-soft: #e7f6ec; --blue: #1d5fbf; --blue-soft: #e8f0fd;
  --add-bg: #e9f8ee; --add-num: #cdeed7; --del-bg: #fdeeee; --del-num: #f8d4d4; --hunk-bg: #eef1f8;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --radius: 12px; --gutter: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --surface: #171a21; --surface-2: #1e222b; --border: #2a2f3a;
    --text: #e7e9ee; --muted: #a2a9b6; --faint: #6f7785;
    --accent: #8b85ff; --accent-soft: #23234a;
    --red: #ff7b7b; --red-soft: #3a1c1f; --amber: #f2b45a; --amber-soft: #36290f;
    --green: #5fd38a; --green-soft: #13301f; --blue: #79aaff; --blue-soft: #172743;
    --add-bg: #12281b; --add-num: #173423; --del-bg: #2e1517; --del-num: #3a1b1e; --hunk-bg: #1b2030;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  overflow-x: hidden;
}
a { color: var(--accent); text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
.boot { padding: 40vh 0 0; text-align: center; color: var(--muted); }
.wrap { max-width: 980px; margin: 0 auto; padding: 0 var(--gutter); }

/* top bar */
.top {
  position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border); padding-top: env(safe-area-inset-top);
}
.top .row { display: flex; align-items: center; gap: 8px; min-height: 52px; }
.top h1 { font-size: 17px; margin: 0; flex: 1; font-weight: 650; }
.icon-btn {
  border: 0; background: transparent; width: 40px; height: 40px; border-radius: 10px;
  display: grid; place-items: center; color: var(--muted); flex: none;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }
.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* segmented filters & tabs */
.seg { display: flex; gap: 6px; overflow-x: auto; padding: 0 0 10px; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg button {
  flex: none; border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: 6px 12px; font-size: 14px; color: var(--muted); white-space: nowrap;
}
.seg button.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.seg .n { opacity: .7; margin-left: 4px; font-variant-numeric: tabular-nums; }

.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  flex: 1 0 auto; text-align: center; padding: 10px 12px 9px; color: var(--muted); font-size: 14px; font-weight: 550;
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs a.on { color: var(--text); border-bottom-color: var(--accent); }
.tabs .n { font-weight: 500; color: var(--faint); margin-left: 3px; }

/* cards & lists */
.list { display: flex; flex-direction: column; gap: 8px; padding: 12px 0 calc(40px + env(safe-area-inset-bottom)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
a.card { color: inherit; display: block; }
a.card:active { background: var(--surface-2); }
.meta { color: var(--muted); font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.meta .sep::before { content: "·"; color: var(--faint); }
.mr-title { font-weight: 600; margin: 3px 0 6px; overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.chip.red { background: var(--red-soft); color: var(--red); }
.chip.amber { background: var(--amber-soft); color: var(--amber); }
.chip.green { background: var(--green-soft); color: var(--green); }
.chip.blue { background: var(--blue-soft); color: var(--blue); }
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.empty { text-align: center; color: var(--muted); padding: 48px 12px; }
.section-h { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); margin: 18px 2px 8px; }

/* MR header */
.mr-head { padding: 14px 0 0; cursor: pointer; }
.mr-head .inline-code { overflow-wrap: anywhere; }
.mr-head .t { font-size: 16px; font-weight: 650; line-height: 1.3; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.mr-head.open .t { -webkit-line-clamp: unset; }

/* review banner */
.banner { display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); margin-top: 12px; font-size: 14px; }
.banner .grow { flex: 1; min-width: 0; }
.banner.warn { background: var(--amber-soft); border-color: transparent; }
.banner.err { background: var(--red-soft); border-color: transparent; }
.dot-pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); flex: none; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; transform: scale(.8); } }

.btn {
  border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 8px 14px;
  font-size: 14px; font-weight: 600; white-space: nowrap; min-height: 38px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger-confirm { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn:disabled { opacity: .5; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* overview */
.verdict { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.verdict b { font-size: 18px; }
.summary { margin: 0; color: var(--text); }
.find { display: block; color: inherit; padding: 10px 0; border-top: 1px solid var(--border); }
.find:first-of-type { border-top: 0; padding-top: 2px; }
.find .ft { font-weight: 600; margin: 3px 0 2px; }
.find .loc { font-family: var(--mono); font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
ol.plain, ul.plain { margin: 0; padding-left: 20px; }
ol.plain li, ul.plain li { margin: 6px 0; }
.check { display: flex; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); align-items: flex-start; }
.check:first-child { border-top: 0; }
.check input { width: 20px; height: 20px; margin: 1px 0 0; flex: none; accent-color: var(--accent); }
.check.done .s { text-decoration: line-through; color: var(--faint); }
.check .e { color: var(--muted); font-size: 13px; }
details > summary { cursor: pointer; color: var(--accent); font-size: 14px; list-style: none; padding: 4px 0; }
details > summary::-webkit-details-marker { display: none; }
.prose { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; color: var(--text); }
.inline-code, .prose code { font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }

/* files */
.progress { height: 4px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin: 12px 0 2px; }
.progress i { display: block; height: 100%; background: var(--green); transition: width .2s; }
.file { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; content-visibility: auto; contain-intrinsic-size: auto 64px; }
.file.viewed { opacity: .6; }
.file-h { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; cursor: pointer; }
.file-h .grow { flex: 1; min-width: 0; }
.imp { width: 10px; height: 10px; border-radius: 3px; margin-top: 6px; flex: none; background: var(--faint); }
.imp.critical { background: var(--red); } .imp.high { background: var(--amber); } .imp.medium { background: var(--blue); } .imp.low { background: var(--border); }
.path { font-family: var(--mono); font-size: 13px; overflow-wrap: anywhere; line-height: 1.35; }
.path .dir { color: var(--faint); }
.reason { color: var(--muted); font-size: 13px; margin-top: 2px; }
.stat { font-family: var(--mono); font-size: 12px; white-space: nowrap; }
.stat .a { color: var(--green); } .stat .d { color: var(--red); }
.viewed-box { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); padding: 2px 0 0; }
.viewed-box input { width: 18px; height: 18px; accent-color: var(--green); margin: 0; }

/* diff */
.diff { border-top: 1px solid var(--border); font-family: var(--mono); font-size: 12.5px; line-height: 1.5; }
.wrap-off .diff { overflow-x: auto; }
.hunk { background: var(--hunk-bg); color: var(--muted); padding: 4px 10px; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ln { display: grid; grid-template-columns: 3.4em 1fr; min-height: 1.5em; }
.ln .no { text-align: right; padding: 0 8px 0 4px; color: var(--faint); user-select: none; cursor: pointer; font-size: 11.5px; padding-top: 1px; }
.ln .cd { padding: 0 10px 0 6px; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; tab-size: 2; }
.wrap-off .ln .cd { white-space: pre; overflow-wrap: normal; word-break: normal; }
.ln.add { background: var(--add-bg); } .ln.add .no { background: var(--add-num); }
.ln.del { background: var(--del-bg); } .ln.del .no { background: var(--del-num); }
.ln.add .cd::before { content: "+"; position: absolute; margin-left: -9px; color: var(--green); }
.ln.del .cd::before { content: "−"; position: absolute; margin-left: -9px; color: var(--red); }
.ln.sel { outline: 2px solid var(--accent); outline-offset: -2px; }
.ln .no:active { color: var(--accent); }
.more { display: block; width: 100%; border: 0; border-top: 1px solid var(--border); background: var(--surface-2); padding: 10px; color: var(--accent); font-size: 13px; }
.diff .note-slot { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif; font-size: 14px; line-height: 1.45; padding: 8px; background: var(--surface-2); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.thread { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; margin-bottom: 6px; }
.thread:last-child { margin-bottom: 0; }
.thread .who { font-size: 12px; color: var(--muted); font-weight: 600; }

/* drafts */
.draft { display: flex; flex-direction: column; gap: 8px; }
.draft .dh { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.draft .dt { font-weight: 600; }
.draft textarea {
  width: 100%; min-height: 84px; resize: vertical; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); color: var(--text); padding: 10px; font: 15px/1.45 inherit; font-family: inherit;
}
.draft textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: var(--surface); }
.draft .fix { font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--surface-2); border-radius: 8px; padding: 8px 10px; margin-top: 4px; }
.draft.published { opacity: .75; }
.draft.discarded { opacity: .5; }
.saved-hint { font-size: 12px; color: var(--faint); margin-left: auto; }

/* flow */
.flow-box { overflow: auto; max-height: 75vh; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; -webkit-overflow-scrolling: touch; }
.flow-box svg { max-width: none !important; height: auto; }
.flow-box.fit svg { max-width: 100% !important; }
.flow-box .changed .nodeLabel, .flow-box .changed .nodeLabel *, .flow-box .changed text { color: #111 !important; fill: #111 !important; }
pre.src { font-family: var(--mono); font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }

/* login */
.login { max-width: 360px; margin: 18vh auto 0; padding: 0 var(--gutter); }
.login h1 { font-size: 22px; margin: 0 0 16px; }
.login input { width: 100%; font-size: 16px; padding: 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); margin-bottom: 10px; }
.login .btn { width: 100%; padding: 12px; }
.err-text { color: var(--red); font-size: 14px; min-height: 20px; }

#toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100vw - 32px); z-index: 50;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 720px) {
  body { font-size: 15px; }
  .ln { grid-template-columns: 3.4em 3.4em 1fr; }
  .ln .no.o { display: block; }
  .list { padding-top: 16px; }
}
@media (max-width: 719px) { .ln .no.o { display: none; } }
