:root {
  --bg: #faf9f6;
  --text: #1e293b;
  --text-mid: #475569;
  --text-muted: #64748b;
  --text-faint: #94a3b8;
  --border: #e7e5e0;
  --card-bg: #fff;
  --hover-bg: #f8f7f4;
  --green-dark: #1a3a1a;
  --green-accent: #5a9a5a;
  --green-light: #f0f7f0;
  --green-border: #d4e5d4;
  --sev-critical: #dc2626;
  --sev-critical-bg: #fef2f2;
  --sev-warning: #92400e;
  --sev-warning-badge: #ca8a04;
  --sev-warning-bg: #fffbeb;
  --sev-info: #1e40af;
  --sev-info-badge: #3b82f6;
  --sev-info-bg: #eff6ff;
  --sev-ok: #16a34a;
  --sev-ok-bg: #f0fdf4;
  --bar-good: #22c55e;
  --bar-mid: #eab308;
  --bar-bad: #ef4444;
  --bar-bg: #e2e8f0;
  --accent-blue: #0284c7;
  --mono: 'SF Mono', 'Fira Code', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; padding: 0; margin: 0; font-size: 14px; line-height: 1.5; }
code, .mono { font-family: var(--mono); font-size: 12px; }
h1 { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
h2 { font-size: 15px; font-weight: 600; color: var(--text-mid); margin: 28px 0 12px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }

/* Sidebar */
.sidebar { position: fixed; left: 0; top: 0; width: 180px; height: 100vh; background: var(--card-bg); border-right: 1px solid var(--border); padding: 20px 12px; overflow-y: auto; z-index: 10; }
.sidebar .logo { font-size: 14px; font-weight: 700; color: var(--green-dark); margin-bottom: 16px; padding: 0 8px; }
.sidebar nav { font-size: 12px; }
.sidebar nav a { display: block; padding: 5px 10px; color: var(--text-muted); text-decoration: none; border-radius: 4px; margin: 1px 0; transition: all 0.1s; }
.sidebar nav a:hover { background: var(--green-light); color: var(--green-dark); }
.sidebar nav a.active { background: var(--green-dark); color: #fff; }
.sidebar nav .nav-label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-faint); padding: 10px 10px 3px; }
.sidebar nav a.nav-l2,
.sidebar nav div.nav-l2,
.sidebar nav a.nav-l3,
.sidebar nav div.nav-l3 { display: none !important; }
.sidebar nav a.nav-l2.nav-show,
.sidebar nav div.nav-l2.nav-show,
.sidebar nav a.nav-l3.nav-show,
.sidebar nav div.nav-l3.nav-show { display: block !important; }

/* Main content */
.main { margin-left: 180px; padding: 0 24px 24px; display: flex; flex-direction: column; align-items: center; }
.main > * { width: 100%; max-width: 780px; }

/* Top rail */
.top-rail { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 12px 0 8px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.level-pills { display: flex; gap: 0; background: var(--card-bg); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.level-pill { flex: 1; padding: 6px 12px; text-align: center; cursor: pointer; font-size: 12px; font-weight: 500; color: var(--text-muted); border-right: 1px solid var(--border); transition: all 0.15s; user-select: none; }
.level-pill:last-child { border-right: none; }
.level-pill:hover { background: var(--hover-bg); }
.level-pill.active { background: var(--green-dark); color: #fff; }
.l2 { height: 0; overflow: hidden; opacity: 0; transition: opacity 0.2s; }
.l2.visible { height: auto; overflow: visible; opacity: 1; }
.l3 { height: 0; overflow: hidden; opacity: 0; transition: opacity 0.2s; }
.l3.visible { height: auto; overflow: visible; opacity: 1; }

/* Apple progress */
.apple-progress { position: fixed; bottom: 0; left: 180px; right: 0; height: 36px; background: var(--card-bg); border-top: 1px solid var(--border); display: flex; align-items: center; padding: 0 calc(50% - 390px); z-index: 5; }
.apple-track { width: 100%; max-width: 780px; height: 4px; background: var(--bar-bg); border-radius: 2px; position: relative; margin: 0 auto; }
.apple-dot { position: absolute; top: -12px; font-size: 20px; transition: left 0.15s; }

/* Header */
.header { background: linear-gradient(135deg, var(--green-light) 0%, var(--card-bg) 60%); border: 1px solid var(--green-border); border-radius: 8px; padding: 20px 24px; margin-bottom: 20px; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 1px 3px rgba(0,0,0,0.06); }
.header-left h1 { color: var(--green-dark); }
.header-left h1::before { content: "🍎 "; }
.header-left .subtitle { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

/* Sections */
section { padding-top: 20px; margin-top: 8px; border-top: 2px solid var(--border); scroll-margin-top: 60px; }
section:first-of-type { border-top: none; margin-top: 0; padding-top: 0; }
.section-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 1.5px; color: var(--text-faint); margin-bottom: 12px; }

/* BLUF */
.bluf { background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; padding: 20px 24px; margin-bottom: 20px; box-shadow: 0 1px 3px rgba(0,0,0,0.06); }
.bluf-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: var(--text-faint); margin-bottom: 6px; }
.bluf-summary { font-size: 15px; line-height: 1.6; }
.bluf-counts { display: flex; gap: 12px; margin-top: 12px; font-size: 12px; }
.bluf-count { padding: 3px 12px; border-radius: 4px; font-weight: 600; }
.bluf-count.crit { background: var(--sev-critical-bg); color: var(--sev-critical); }
.bluf-count.warn { background: var(--sev-warning-bg); color: var(--sev-warning); }
.bluf-count.info { background: var(--sev-info-bg); color: var(--sev-info); }

/* System info */
.sysinfo { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.sysinfo-item { background: var(--card-bg); border: 1px solid var(--border); border-radius: 6px; padding: 12px 16px; text-align: center; }
.sysinfo-val { font-size: 18px; font-weight: 700; color: var(--text); font-family: var(--mono); }
.sysinfo-denom { font-size: 12px; font-weight: 400; color: var(--text-faint); }
.sysinfo-label { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.5px; margin-top: 2px; }
.sysinfo-bar { height: 4px; background: var(--bar-bg); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.sysinfo-fill { height: 100%; border-radius: 2px; }

/* Cards */
.card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; padding: 16px 20px; margin: 12px 0; box-shadow: 0 1px 3px rgba(0,0,0,0.04); }

/* Matrix */
.matrix-row { display: flex; align-items: center; margin: 6px 0; flex-wrap: nowrap; overflow: hidden; }
.matrix-label { width: 90px; font-size: 13px; color: var(--text-mid); flex-shrink: 0; }
.matrix-val { font-size: 13px; color: var(--text-muted); margin-left: 8px; width: 30px; text-align: right; font-family: var(--mono); flex-shrink: 0; }
.matrix-issue { font-size: 12px; color: var(--text-muted); margin-left: 8px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: fixed; }
th { text-align: left; padding: 8px 12px; color: var(--text-mid); font-weight: 600; border-bottom: 2px solid var(--border); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
td { padding: 6px 12px; border-bottom: 1px solid #f1f5f9; vertical-align: top; word-wrap: break-word; overflow-wrap: break-word; }
tr:hover { background: var(--hover-bg); }
code { word-break: break-all; }
.action-cmd { background: #f1f5f9; padding: 2px 8px; border-radius: 3px; font-family: var(--mono); font-size: 11px; color: var(--text); display: inline-block; margin-top: 2px; word-break: break-all; }

/* Findings */
.finding { padding: 10px 0; border-bottom: 1px solid #f1f5f9; }
.finding:last-child { border-bottom: none; }
.finding-fix { font-size: 13px; color: var(--text-mid); margin-top: 6px; padding-left: 16px; border-left: 2px solid var(--border); word-wrap: break-word; overflow-wrap: break-word; }

/* Focus / actions */
.focus-box { background: var(--card-bg); border: 2px solid var(--green-accent); border-radius: 8px; padding: 20px; margin: 20px 0; }
.focus-box h2 { border-bottom: none; margin: 0 0 12px; color: var(--text); font-size: 16px; }
.focus-item { padding: 8px 0; font-size: 14px; border-bottom: 1px solid #f1f5f9; }
.focus-item:last-child { border-bottom: none; }
.score-gain { display: inline-block; background: var(--sev-ok-bg); color: var(--sev-ok); font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 3px; margin-left: 6px; }

/* Sparkline */
.spark-container { background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; padding: 16px 20px; }
.spark-stats { display: flex; gap: 24px; margin-top: 8px; font-size: 12px; color: var(--text-muted); font-family: var(--mono); }
.spark-stats b { color: var(--text); }
.spike { background: var(--sev-critical-bg); border-left: 3px solid var(--bar-bad); padding: 8px 12px; margin: 6px 0; font-size: 13px; border-radius: 0 4px 4px 0; }

/* Knowledge cards */
.knowledge { background: var(--hover-bg); border: 1px solid var(--border); border-radius: 6px; margin: 8px 0; font-size: 13px; }
.knowledge summary { padding: 8px 12px; cursor: pointer; color: var(--accent-blue); font-weight: 500; }
.knowledge summary:hover { background: #f1f5f9; }
.knowledge .k-section { padding: 6px 12px 6px 24px; color: var(--text-mid); line-height: 1.6; }
.knowledge .k-section b { color: var(--text); }

/* Trade-offs */
.tradeoff { background: var(--sev-warning-bg); border: 1px solid #fde68a; border-radius: 6px; padding: 12px 16px; margin: 8px 0; font-size: 13px; }
.tradeoff-gain { color: var(--sev-ok); }
.tradeoff-lose { color: var(--sev-critical); }

/* Trend */
.trend-card { font-size: 15px; }
.trend-up { color: var(--sev-ok); }
.trend-down { color: var(--sev-critical); }
.trend-flat { color: var(--text-muted); }

/* JSON download */
.json-download { display: inline-block; margin-top: 12px; padding: 6px 16px; background: var(--green-dark); color: #fff; border: none; border-radius: 4px; font-size: 12px; font-weight: 500; cursor: pointer; text-decoration: none; font-family: var(--mono); }
.json-download:hover { opacity: 0.9; }

/* Footer */
footer { margin-top: 32px; padding: 16px 0 52px; border-top: 1px solid var(--border); font-size: 11px; color: var(--text-faint); text-align: center; }

/* Responsive */
@media (max-width: 900px) {
  .sidebar { display: none; }
  .main { margin-left: 0; }
  .apple-progress { left: 0; }
  .sysinfo { grid-template-columns: repeat(2, 1fr); }
}
