@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Sans:wght@400;500;600;700&display=swap');

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #484f58;
  --border: #30363d;
  --accent: #58a6ff;
  --accent-hover: #79c0ff;

  --critical-bg: rgba(248, 81, 73, 0.1);
  --critical-border: #f85149;
  --critical-text: #ff7b72;
  --warning-bg: rgba(210, 153, 34, 0.1);
  --warning-border: #d29922;
  --warning-text: #e3b341;
  --suggestion-bg: rgba(88, 166, 255, 0.1);
  --suggestion-border: #58a6ff;
  --suggestion-text: #79c0ff;
  --success-text: #56d364;

  --font-sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'IBM Plex Mono', 'Menlo', 'Consolas', monospace;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg-primary: #ffffff;
    --bg-secondary: #f6f8fa;
    --bg-tertiary: #eaeef2;
    --text-primary: #1f2328;
    --text-secondary: #636c76;
    --text-muted: #afb8c1;
    --border: #d0d7de;
    --accent: #0969da;
    --accent-hover: #0550ae;

    --critical-bg: rgba(207, 34, 46, 0.08);
    --critical-border: #cf222e;
    --critical-text: #cf222e;
    --warning-bg: rgba(154, 103, 0, 0.08);
    --warning-border: #9a6700;
    --warning-text: #9a6700;
    --suggestion-bg: rgba(9, 105, 218, 0.08);
    --suggestion-border: #0969da;
    --suggestion-text: #0969da;
    --success-text: #1a7f37;
  }
}

/* Manual light override */
:root[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f6f8fa;
  --bg-tertiary: #eaeef2;
  --text-primary: #1f2328;
  --text-secondary: #636c76;
  --text-muted: #afb8c1;
  --border: #d0d7de;
  --accent: #0969da;
  --accent-hover: #0550ae;

  --critical-bg: rgba(207, 34, 46, 0.08);
  --critical-border: #cf222e;
  --critical-text: #cf222e;
  --warning-bg: rgba(154, 103, 0, 0.08);
  --warning-border: #9a6700;
  --warning-text: #9a6700;
  --suggestion-bg: rgba(9, 105, 218, 0.08);
  --suggestion-border: #0969da;
  --suggestion-text: #0969da;
  --success-text: #1a7f37;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background 0.2s, color 0.2s;
}

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.header-logo {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text-primary);
  white-space: nowrap;
}

.header-tagline {
  color: var(--text-muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.icon-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.4rem;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.icon-btn:hover {
  color: var(--text-primary);
  background: var(--bg-tertiary);
  border-color: var(--border);
}

.icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

/* Main */
.main {
  flex: 1;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem;
}

/* Input section */
.input-section {
  margin-bottom: 1.5rem;
}

.input-section label {
  display: block;
  font-weight: 500;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.json-input {
  width: 100%;
  min-height: 160px;
  max-height: 60vh;
  padding: 0.75rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.6;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  resize: vertical;
  outline: none;
  transition: border-color 0.15s;
}

.json-input::placeholder {
  color: var(--text-muted);
}

.json-input:focus {
  border-color: var(--accent);
}

.button-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.btn {
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 0.875rem;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text-primary);
  background: var(--bg-tertiary);
}

.btn .spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Error message */
.error-msg {
  margin-top: 0.75rem;
  padding: 0.6rem 0.75rem;
  background: var(--critical-bg);
  border: 1px solid var(--critical-border);
  border-radius: 6px;
  color: var(--critical-text);
  font-size: 0.85rem;
}

.info-msg {
  margin-top: 0.75rem;
  padding: 0.6rem 0.75rem;
  background: var(--suggestion-bg);
  border: 1px solid var(--suggestion-border);
  border-radius: 6px;
  color: var(--suggestion-text);
  font-size: 0.85rem;
}

/* Results */
.results-section {
  margin-top: 1rem;
}

.empty-state {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 2rem 1.5rem;
  text-align: center;
  color: var(--text-secondary);
}

.empty-state h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.75rem;
}

.empty-state p {
  font-size: 0.85rem;
  line-height: 1.7;
  max-width: 540px;
  margin: 0 auto;
}

/* Stats bar */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.stat-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  text-align: center;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  font-family: var(--font-mono);
  line-height: 1.2;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-value.red { color: var(--critical-text); }
.stat-value.amber { color: var(--warning-text); }
.stat-value.green { color: var(--success-text); }

/* Findings */
.findings-group {
  margin-bottom: 1.5rem;
}

.findings-group-header {
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.5rem 0;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.findings-group-header.critical { color: var(--critical-text); }
.findings-group-header.warning { color: var(--warning-text); }
.findings-group-header.suggestion { color: var(--suggestion-text); }

.finding-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.5rem;
  overflow: hidden;
  transition: border-color 0.15s;
}

.finding-card.critical {
  background: var(--critical-bg);
  border-color: color-mix(in srgb, var(--critical-border) 40%, transparent);
}

.finding-card.warning {
  background: var(--warning-bg);
  border-color: color-mix(in srgb, var(--warning-border) 40%, transparent);
}

.finding-card.suggestion {
  background: var(--suggestion-bg);
  border-color: color-mix(in srgb, var(--suggestion-border) 40%, transparent);
}

.finding-header {
  padding: 0.75rem 1rem;
}

.finding-title-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.badge.critical {
  background: var(--critical-border);
  color: #fff;
}

.badge.warning {
  background: var(--warning-border);
  color: #fff;
}

.badge.suggestion {
  background: var(--suggestion-border);
  color: #fff;
}

.badge.ai {
  background: #8b5cf6;
  color: #fff;
}

.finding-title {
  font-weight: 600;
  font-size: 0.9rem;
}

.finding-desc {
  margin-top: 0.4rem;
  font-size: 0.835rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.finding-nodes {
  margin-top: 0.4rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.finding-fix-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.5rem;
  font-size: 0.835rem;
  color: var(--accent);
  cursor: pointer;
  background: none;
  border: none;
  font-family: var(--font-sans);
  padding: 0;
}

.finding-fix-toggle:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

.finding-fix-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.finding-fix-toggle .arrow {
  transition: transform 0.2s;
  font-size: 0.75rem;
}

.finding-fix-toggle.open .arrow {
  transform: rotate(90deg);
}

.finding-fix-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.finding-fix-body.open {
  max-height: 500px;
}

.finding-fix-content {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.835rem;
  line-height: 1.6;
  color: var(--text-secondary);
  background: color-mix(in srgb, var(--bg-secondary) 50%, transparent);
}

/* Settings panel */
.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}

.settings-overlay.open {
  opacity: 1;
  visibility: visible;
}

.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 380px;
  max-width: 100vw;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  z-index: 201;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
}

.settings-panel.open {
  transform: translateX(0);
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.settings-header h2 {
  font-size: 1rem;
  font-weight: 600;
}

.settings-body {
  flex: 1;
  padding: 1.25rem;
  overflow-y: auto;
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-weight: 500;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
}

.input-row {
  display: flex;
  gap: 0.5rem;
}

.form-input {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
  transition: border-color 0.15s;
}

.form-input:focus {
  border-color: var(--accent);
}

.form-select {
  width: 100%;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
}

.form-select:focus {
  border-color: var(--accent);
}

.settings-note {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-top: 1rem;
  padding: 0.75rem;
  background: var(--bg-tertiary);
  border-radius: 6px;
}

.settings-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

/* Footer */
.footer {
  padding: 1.25rem 1.5rem;
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

.footer a {
  color: var(--text-secondary);
  text-decoration: none;
}

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

.footer-sep {
  margin: 0 0.5rem;
}

/* Responsive */
@media (max-width: 768px) {
  .header {
    padding: 0.6rem 1rem;
  }

  .header-tagline {
    display: none;
  }

  .main {
    padding: 1rem;
  }

  .stats-bar {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  .stat-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    text-align: left;
    padding: 0.75rem 1rem;
  }

  .stat-value {
    font-size: 1.25rem;
    order: 2;
  }

  .stat-label {
    margin-top: 0;
    order: 1;
  }

  .button-row {
    flex-direction: column;
  }

  .btn {
    justify-content: center;
  }

  .settings-panel {
    width: 100vw;
  }
}
