:root {
  /* Dark theme — Catppuccin Macchiato */
  --bg: #24273a;           /* Base */
  --bg-secondary: #1e2030; /* Mantle */
  --bg-tertiary: #2b2f47;  /* between Base and Surface 0 */
  --border: #494d64;       /* Surface 1 */
  --text: #b8c0e0;         /* Subtext 1 (softer than Text) */
  --text-muted: #8087a2;   /* Overlay 1 (softer muted) */
  --accent: #8aadf4;       /* Blue */
  --success: #a6da95;      /* Green */
  --error: #ed8796;        /* Red */
  --warning: #f5a97f;      /* Peach */
  --info: #7dc4e4;         /* Sky */
  --font-mono: "JetBrains Mono", "Fira Code", "Courier New", monospace;
  --font-sans: "Source Sans Pro", "Microsoft Yahei", sans-serif;
  --font-heading: "Lato", "Microsoft Yahei", sans-serif;
  --radius: 6px;
}

@media (prefers-color-scheme: light) {
  :root {
    /* Light theme — Catppuccin Latte */
    --bg: #eff1f5;           /* Base */
    --bg-secondary: #e6e9ef; /* Mantle */
    --bg-tertiary: #e6e9ef;  /* Mantle (closer to Base) */
    --border: #bcc0cc;       /* Surface 1 */
    --text: #5c5f77;         /* Subtext 1 (softer than Text) */
    --text-muted: #8c8fa1;   /* Overlay 1 (softer muted) */
    --accent: #1e66f5;       /* Blue */
    --success: #40a02b;      /* Green */
    --error: #d20f39;        /* Red */
    --warning: #fe640b;      /* Peach */
    --info: #04a5e5;         /* Sky */
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
*::-webkit-scrollbar-track {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background: var(--border);
  border: 2px solid var(--bg);
  border-radius: 6px;
}
*::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body.dragging {
  outline: 2px dashed var(--accent);
  outline-offset: -6px;
}

header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

header h1 {
  font-size: 18px;
  font-weight: 600;
  font-family: var(--font-mono);
}

header h1 span {
  color: var(--accent);
}

.header-file {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.file-name {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Drop zone ─────────────────────────────────────────────────────────────── */

.drop-zone {
  flex: 1;
  margin: 20px;
  border: 2px dashed var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.drop-zone:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 4%, transparent);
}

.drop-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
  padding: 20px;
}

.drop-icon {
  font-size: 32px;
  color: var(--text-muted);
  line-height: 1;
}

.drop-sub {
  font-size: 13px;
  color: var(--text-muted);
}

/* ── Toolbar ───────────────────────────────────────────────────────────────── */

.app {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

.chips {
  display: flex;
  gap: 6px;
}

.chip {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 3px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s, opacity 0.15s;
}
.chip[aria-pressed="false"] {
  opacity: 0.45;
}
.chip[data-level="error"][aria-pressed="true"] {
  color: var(--error);
  border-color: color-mix(in srgb, var(--error) 45%, transparent);
  background: color-mix(in srgb, var(--error) 12%, transparent);
}
.chip[data-level="warning"][aria-pressed="true"] {
  color: var(--warning);
  border-color: color-mix(in srgb, var(--warning) 45%, transparent);
  background: color-mix(in srgb, var(--warning) 12%, transparent);
}
.chip[data-level="note"][aria-pressed="true"] {
  color: var(--info);
  border-color: color-mix(in srgb, var(--info) 45%, transparent);
  background: color-mix(in srgb, var(--info) 12%, transparent);
}
.chip[data-level="none"][aria-pressed="true"] {
  color: var(--text);
  border-color: var(--border);
}
.chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.toolbar input[type="search"] {
  flex: 1;
  min-width: 180px;
}

.toolbar input[type="text"] {
  flex: 1;
  min-width: 200px;
  font-family: var(--font-mono);
  font-size: 12px;
}

a.loc-path:hover {
  text-decoration: underline;
}

.host-switch {
  position: relative;
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-tertiary);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.host-switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.host-switch span {
  position: relative;
  z-index: 1;
  flex: 1;
  min-width: 62px;
  padding: 3px 10px;
  text-align: center;
  color: var(--text-muted);
  transition: color 0.15s;
}
/* The pill slides to whichever half is active. `*` does not match pseudo-elements,
   so it needs its own border-box or the 1px border pushes it past the track. */
.host-switch::before {
  content: "";
  position: absolute;
  box-sizing: border-box;
  top: 2px;
  bottom: 2px;
  left: 2px;
  width: calc(50% - 4px);
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  transition: transform 0.15s;
}
.host-switch:has(:checked)::before {
  transform: translateX(calc(100% + 4px));
}
.host-switch:not(:has(:checked)) span:first-of-type,
.host-switch:has(:checked) span:last-of-type {
  color: var(--accent);
  font-weight: 600;
}
.host-switch:has(:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
}

.result-count {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Layout ────────────────────────────────────────────────────────────────── */

.layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.panel {
  overflow-y: auto;
  padding: 12px 16px;
}
.panel-left {
  border-right: 1px solid var(--border);
}

/* ── Findings list ─────────────────────────────────────────────────────────── */

.findings {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.finding {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  width: 100%;
  text-align: left;
  background: var(--bg-secondary);
  border: 1px solid transparent;
  border-left: 3px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  transition: background 0.1s, border-color 0.1s;
}
.finding:hover {
  background: var(--bg-tertiary);
}
.finding.selected {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.finding[data-level="error"] {
  border-left-color: var(--error);
}
.finding[data-level="warning"] {
  border-left-color: var(--warning);
}
.finding[data-level="note"] {
  border-left-color: var(--info);
}
.finding.suppressed {
  opacity: 0.55;
}

.finding-body {
  flex: 1;
  min-width: 0;
}

.finding-rule {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.finding-message {
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.finding-loc {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sev-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 3px;
  flex-shrink: 0;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.findings-empty {
  font-size: 13px;
  color: var(--text-muted);
  padding: 8px 0;
}

/* ── Detail pane ───────────────────────────────────────────────────────────── */

.detail-empty {
  font-size: 13px;
  color: var(--text-muted);
}

.detail-rule {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  overflow-wrap: anywhere;
}

.detail-tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin: 8px 0;
}

.tag {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
}

.detail-message {
  font-size: 14px;
  line-height: 1.6;
  margin: 8px 0 12px;
  overflow-wrap: anywhere;
}

.section {
  margin-bottom: 14px;
}

.section-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.kv {
  display: grid;
  grid-template-columns: minmax(90px, max-content) 1fr;
  gap: 2px 12px;
  font-size: 13px;
}
.kv dt {
  color: var(--text-muted);
}
.kv dd {
  font-family: var(--font-mono);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.loc-entry {
  margin-bottom: 8px;
}

.loc-path {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  overflow-wrap: anywhere;
}

.loc-note {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

pre.snippet,
pre.raw {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 8px 10px;
  margin-top: 4px;
  overflow-x: auto;
  white-space: pre;
  tab-size: 4;
}

pre.raw {
  max-height: 320px;
  overflow-y: auto;
}

.help-text {
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  color: var(--text);
  overflow-wrap: anywhere;
}

.detail a {
  color: var(--accent);
}

/* ── Run metadata ──────────────────────────────────────────────────────────── */

.run-meta {
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  padding: 8px 20px;
  font-size: 13px;
  flex-shrink: 0;
  max-height: 40vh;
  overflow-y: auto;
}

.run-meta summary {
  cursor: pointer;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.run-meta[open] summary {
  margin-bottom: 8px;
}

.run-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  margin-bottom: 6px;
  background: var(--bg-tertiary);
}

.run-card-title {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 4px;
}

.run-note {
  font-size: 12px;
  color: var(--error);
  font-family: var(--font-mono);
  overflow-wrap: anywhere;
}

/* ── Form controls ─────────────────────────────────────────────────────────── */

select,
input[type="text"],
input[type="search"],
textarea {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  padding: 6px 10px;
  outline: none;
  transition: border-color 0.15s;
}

select:focus,
input:focus,
textarea:focus {
  border-color: var(--accent);
}

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23656d76' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 28px;
}

.btn {
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  padding: 6px 14px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.btn-secondary {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.warn-note {
  font-size: 13px;
  color: var(--error);
  padding: 8px 20px;
  font-family: var(--font-mono);
  overflow-wrap: anywhere;
}

.hidden {
  display: none !important;
}

@media (max-width: 900px) {
  body {
    height: auto;
    overflow: visible;
  }
  .layout {
    grid-template-columns: 1fr;
    overflow: visible;
  }
  .panel {
    overflow-y: visible;
  }
  .panel-left {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}

footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 15px;
  color: var(--text-muted);
  flex-shrink: 0;
}

footer a {
  color: var(--accent);
  text-decoration: none;
}
footer a:hover {
  text-decoration: underline;
}

@media (max-width: 700px) {
  footer {
    flex-direction: column;
    align-items: flex-start;
    font-size: 13px;
  }
}
