/* codeanalyzer web app — light/dark, no external assets */

:root {
  color-scheme: light dark;
  --bg: #f7f7f5;
  --panel: #ffffff;
  --panel-2: #fbfbfa;
  --ink: #1d1c1a;
  --muted: #6b6862;
  --line: #e4e1db;
  --accent: #3b6ea5;
  --accent-ink: #ffffff;
  --crit: #b3261e;
  --high: #c2410c;
  --med: #a16207;
  --low: #1d6a8c;
  --info: #6b6862;
  --ok: #3f9142;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 8px 24px rgba(0, 0, 0, .06);
  --radius: 10px;
  --sidebar-w: 320px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141518;
    --panel: #1c1e22;
    --panel-2: #212429;
    --ink: #e8e6e3;
    --muted: #9a978f;
    --line: #2c2f35;
    --accent: #7aa7d8;
    --accent-ink: #10151b;
    --crit: #ff6b5e;
    --high: #ff9552;
    --med: #e5b95c;
    --low: #6cc4e8;
    --info: #9a978f;
    --ok: #6bbd6e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

/* Several components set display in CSS, which would beat the hidden attribute. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 ui-sans-serif, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
}

.mono, code, pre, input, textarea, select {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

h1 { font-size: 19px; margin: 0 0 2px; letter-spacing: -.01em; }
h2 { font-size: 13px; margin: 0 0 10px; letter-spacing: .02em; }
h3 { font-size: 15px; margin: 0; }
.muted { color: var(--muted); font-weight: 400; }

/* ------------------------------------------------------------------ topbar */
.topbar {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; letter-spacing: -.01em; }
.brand svg { color: var(--accent); }
.brand em { color: var(--muted); font-style: normal; font-size: 11px; font-weight: 400; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.run-state { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }

.spinner {
  width: 13px; height: 13px; flex: none;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------ layout */
.layout { display: flex; height: calc(100vh - 52px); }

.sidebar {
  width: var(--sidebar-w);
  flex: none;
  border-right: 1px solid var(--line);
  background: var(--panel-2);
  overflow-y: auto;
  padding: 14px;
}
.sidebar.hidden { display: none; }

.main { flex: 1; overflow-y: auto; padding: 22px 24px 60px; }

.panel { margin-bottom: 22px; }

/* ------------------------------------------------------------------- forms */
.field { margin-bottom: 12px; }
.field.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: 4px;
}

input[type=text], input[type=number], input[type=search], select, textarea {
  width: 100%;
  padding: 7px 9px;
  font-size: 13px;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
textarea { resize: vertical; }

.path-row { display: flex; gap: 6px; }
.path-row input { flex: 1; }

.markers { margin: 5px 0 0; font-size: 11.5px; color: var(--muted); min-height: 14px; }
.markers b { color: var(--ok); font-weight: 600; }

.toggles label {
  display: flex; align-items: center; gap: 7px;
  text-transform: none; letter-spacing: 0; font-size: 13px;
  color: var(--ink); margin-bottom: 5px;
}
.checks { display: flex; flex-wrap: wrap; gap: 5px 10px; }
.checks label {
  display: flex; align-items: center; gap: 6px;
  text-transform: none; letter-spacing: 0; font-size: 12.5px;
  color: var(--ink); margin: 0;
}

.btn {
  padding: 7px 12px;
  font: inherit;
  font-size: 13px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: default; }
.linkish {
  background: none; border: 0; padding: 0; font: inherit;
  color: var(--accent); cursor: pointer; text-decoration: underline;
}

.error { color: var(--crit); font-size: 12.5px; margin: 8px 0 0; }

.options summary { cursor: pointer; font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
.options[open] summary { margin-bottom: 12px; }

/* ---------------------------------------------------------------- dropzone */
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 14px; margin-bottom: 12px;
  border: 1.5px dashed var(--line); border-radius: var(--radius);
  color: var(--muted); font-size: 12.5px; text-align: center;
}
.dropzone strong { color: var(--ink); font-size: 13px; font-weight: 600; }
.dropzone.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }

/* ----------------------------------------------------------------- history */
.history { list-style: none; margin: 0; padding: 0; }
.history li {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 9px; margin-bottom: 5px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); cursor: pointer; font-size: 12.5px;
}
.history li:hover { border-color: var(--accent); }
.history li.active { border-color: var(--accent); box-shadow: inset 2px 0 0 var(--accent); }
.history .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--muted); }
.history .dot.ok { background: var(--ok); }
.history .dot.warn { background: var(--med); }
.history .dot.bad { background: var(--crit); }
.history .dot.run { background: var(--accent); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.history .h-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history .h-meta { color: var(--muted); font-variant-numeric: tabular-nums; }
.history .h-del {
  border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0 2px; font-size: 13px;
}
.history .h-del:hover { color: var(--crit); }

/* ------------------------------------------------------------------ result */
.empty {
  height: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 6px; color: var(--muted);
}
.empty h2 { font-size: 16px; color: var(--ink); text-transform: none; letter-spacing: 0; }
.empty p { margin: 0; }

.result-head { margin-bottom: 16px; }
.result-head p { margin: 0; font-size: 12px; word-break: break-all; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow);
}
.card.wide { margin-top: 10px; }
.card.scroll { padding: 0; overflow-x: auto; }
.card .k { font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.card .v { font-size: 22px; font-weight: 650; margin-top: 1px; letter-spacing: -.02em; }
.card.score { display: flex; align-items: center; gap: 12px; }

.gauge {
  --pct: 0; --g: var(--muted);
  width: 54px; height: 54px; border-radius: 50%; flex: none;
  background: conic-gradient(var(--g) calc(var(--pct) * 1%), var(--line) 0);
  display: grid; place-items: center;
}
.gauge span {
  width: 40px; height: 40px; border-radius: 50%; background: var(--panel);
  display: grid; place-items: center; font-weight: 700; font-size: 14px;
}

.bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; display: flex; margin-top: 6px; }
.bar i { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 7px; font-size: 12px; color: var(--muted); }
.legend b { font-weight: 600; }

/* ---------------------------------------------------------------- controls */
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 14px; }
.controls input[type=search] { flex: 1; min-width: 200px; }
.inline-check {
  display: flex; align-items: center; gap: 6px; margin: 0;
  text-transform: none; letter-spacing: 0; font-size: 12.5px; color: var(--muted);
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 999px; padding: 4px 11px; font-size: 12.5px; cursor: pointer;
}
.chip[aria-pressed="false"] { opacity: .4; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.chip .n { color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- findings */
h2.sec { font-size: 14px; margin: 26px 0 9px; display: flex; gap: 8px; align-items: baseline; }

details.rule {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); margin-bottom: 7px; overflow: hidden;
}
details.rule > summary {
  cursor: pointer; padding: 10px 13px; display: flex; gap: 10px;
  align-items: center; list-style: none; font-size: 13.5px;
}
details.rule > summary::-webkit-details-marker { display: none; }
.badge {
  font-size: 9.5px; font-weight: 700; letter-spacing: .06em;
  padding: 2px 6px; border-radius: 5px; border: 1px solid currentColor; flex: none;
}
.sev-CRITICAL { color: var(--crit); }
.sev-HIGH { color: var(--high); }
.sev-MEDIUM { color: var(--med); }
.sev-LOW { color: var(--low); }
.sev-INFO { color: var(--info); }
.rule-name { font-weight: 600; }
.count { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.hint { padding: 0 13px 9px; color: var(--muted); font-size: 12.5px; }
.items { border-top: 1px solid var(--line); }
.item {
  padding: 9px 13px; border-bottom: 1px solid var(--line);
  font-size: 13px; cursor: pointer;
}
.item:last-child { border-bottom: 0; }
.item:hover { background: var(--panel-2); }
.item.nolink { cursor: default; }
.loc { color: var(--accent); font-size: 12px; }
.msg { margin-top: 2px; }
.snip {
  margin-top: 5px; padding: 5px 8px; border-radius: 6px;
  background: color-mix(in srgb, var(--ink) 5%, transparent);
  font-size: 12px; color: var(--muted); overflow-x: auto; white-space: pre;
}
.rel { margin-top: 4px; color: var(--muted); font-size: 12px; }
.rel div { padding-left: 12px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px 12px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--panel-2); }

/* ------------------------------------------------------------------ drawer */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(760px, 92vw);
  background: var(--panel); border-left: 1px solid var(--line);
  box-shadow: var(--shadow); z-index: 40;
  display: flex; flex-direction: column;
}
.drawer-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 10px;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
}
.drawer-head .mono { font-size: 13px; word-break: break-all; }
.drawer-head .muted { font-size: 12px; }
.drawer-msg { padding: 10px 14px; font-size: 13px; border-bottom: 1px solid var(--line); }
.code { flex: 1; overflow: auto; padding: 8px 0 24px; font-size: 12.5px; line-height: 1.55; }
.code .row { display: flex; }
.code .row.hit { background: color-mix(in srgb, var(--med) 16%, transparent); }
.code .row.hit .ln { box-shadow: inset 2px 0 0 var(--med); }
.code .ln {
  flex: none; width: 58px; padding: 0 10px 0 12px; text-align: right;
  color: var(--muted); user-select: none; font-variant-numeric: tabular-nums;
}
.code .src { white-space: pre; padding-right: 16px; }
.tok-str { color: var(--ok); }
.tok-com { color: var(--muted); font-style: italic; }
.tok-kw { color: var(--accent); }
.tok-num { color: var(--high); }

.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 30; }

/* ------------------------------------------------------------------- modal */
.modal { position: fixed; inset: 0; display: grid; place-items: center; z-index: 50; background: rgba(0,0,0,.4); }
.modal-card {
  width: min(560px, 92vw); max-height: 82vh; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow); padding: 14px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.browse-path { font-size: 12.5px; color: var(--muted); word-break: break-all; }
.browse-list { list-style: none; margin: 10px 0; padding: 0; overflow-y: auto; flex: 1; }
.browse-list li {
  padding: 7px 9px; border-radius: 7px; cursor: pointer; font-size: 13px;
  display: flex; align-items: center; gap: 8px;
}
.browse-list li:hover { background: var(--panel-2); }
.modal-foot { display: flex; justify-content: space-between; gap: 8px; }

/* -------------------------------------------------------------------- menu */
.menu { position: relative; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 9px; box-shadow: var(--shadow); padding: 5px; min-width: 170px;
}
.menu-list a {
  display: block; padding: 6px 9px; border-radius: 6px;
  color: var(--ink); text-decoration: none; font-size: 13px;
}
.menu-list a:hover { background: var(--panel-2); }
.menu-list a span { color: var(--muted); font-size: 11.5px; }

/* ------------------------------------------------------------------- toast */
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 14px; box-shadow: var(--shadow); font-size: 13px; z-index: 60;
  max-width: min(560px, 90vw);
}
.toast.bad { border-color: var(--crit); color: var(--crit); }

/* -------------------------------------------------------------- responsive */
@media (max-width: 860px) {
  .sidebar { position: fixed; top: 52px; bottom: 0; left: 0; z-index: 25; box-shadow: var(--shadow); }
  .sidebar.hidden { display: none; }
  .main { padding: 16px 14px 60px; }
}

/* -------------------------------------------------------------- demo mode */
.banner {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline;
  padding: 10px 13px; margin-bottom: 16px;
  border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: 8px; background: var(--panel); font-size: 13px;
}
.banner a { color: var(--accent); }

.samples { display: flex; flex-direction: column; gap: 6px; }
.sample {
  text-align: left; padding: 9px 11px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--panel); color: var(--ink);
  cursor: pointer; font: inherit; font-size: 12.5px;
}
.sample:hover { border-color: var(--accent); }
.sample b { display: block; font-size: 13px; margin-bottom: 2px; }
.sample span { color: var(--muted); }

.demo-note { margin: 8px 0 0; font-size: 11.5px; color: var(--muted); }
