/* Galley Owl component styles. Requires tokens.css. Keeps existing class names. */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.5 var(--font-ui); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { font-family: var(--font-body); font-weight: 400; letter-spacing: -0.01em; margin: 0; line-height: 1.15; text-wrap: balance; }
h1 { font-size: clamp(28px, 3.4vw, 38px); }
h2 { font-size: 30px; }
h3 { font-size: 24px; }
h4 { font: 600 17px/1.35 var(--font-ui); margin: 0; }
p { margin: 0; text-wrap: pretty; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; padding: 12px max(24px, calc((100vw - 1240px) / 2)); background: var(--bg); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; font: 500 20px var(--font-body); color: var(--text); text-decoration: none; }
.brand:hover { text-decoration: none; color: var(--text); }
.brand-mark { width: 26px; height: 26px; display: block; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: transparent; color: var(--text); font-weight: 500; cursor: pointer; transition: background .15s, border-color .15s; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { border-color: transparent; color: var(--text-2); font-weight: 400; }
.btn.ghost:hover { color: var(--text); }
.btn.small { padding: 5px 12px; font-size: 13px; }
.btn.danger { border-color: var(--error); color: var(--error); }
.btn.danger:hover { background: var(--error-soft); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Surfaces */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 22px; }
.card > h3:first-child { font: 600 15px var(--font-ui); margin-bottom: 14px; }
.grid { display: grid; gap: 20px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); }
.grid.stats { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.stat { background: var(--surface); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; }
.stat .label, .stat small { font-size: 12px; color: var(--text-3); }
.stat .value, .stat strong { font-size: 22px; font-weight: 500; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

/* Library */
.hero { display: flex; flex-direction: column; gap: 20px; }
.hero h1 { font-size: clamp(40px, 5.5vw, 64px); line-height: 1.02; letter-spacing: -0.025em; }
.hero p { font: 20px/1.5 var(--font-body); color: var(--text-2); max-width: 34ch; }
.dropzone { border: 1.5px dashed var(--border-strong); border-radius: var(--radius); padding: 32px 20px; text-align: center; background: var(--bg); cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.checklist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.checklist li { display: flex; gap: 12px; align-items: baseline; color: var(--text-2); }
.checklist li::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex: none; transform: translateY(-3px); }
.checklist li strong { color: var(--text); font-weight: 500; }
.projects { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 16px; }
.project-card { display: flex; gap: 16px; align-items: flex-start; padding: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); color: var(--text); text-decoration: none; transition: border-color .15s, box-shadow .15s; }
.project-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow); text-decoration: none; color: var(--text); }
.project-card h3 { font-size: 20px; }

/* Score ring: SVG with track + arc. Arc stroke uses var(--ok|--warning|--error). */
.ring { position: relative; flex: none; width: 84px; height: 84px; display: grid; place-items: center; }
.ring svg { position: absolute; inset: 0; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 5; stroke-linecap: round; }
.ring circle:first-child { stroke: var(--surface-2); }
.ring span, .ring b { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.project-card .ring { width: 56px; height: 56px; }
.project-card .ring span, .project-card .ring b { font-size: 16px; }

/* Verdict + pills */
.verdict { display: inline-flex; padding: 3px 10px; border-radius: 99px; font-size: 13px; font-weight: 500; }
.verdict.ready { background: var(--ok-soft); color: var(--ok); }
.verdict.nearly { background: var(--warning-soft); color: var(--warning); }
.verdict.revise { background: var(--error-soft); color: var(--error); }
.pill { display: inline-flex; align-items: center; min-width: 20px; justify-content: center; padding: 0 7px; border-radius: 99px; font-size: 12px; background: var(--surface-2); color: var(--text-2); font-variant-numeric: tabular-nums; }
.pill.error { background: var(--error-soft); color: var(--error); }
.pill.ai { background: var(--ai-soft); color: var(--ai); font-size: 10px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }

/* Project header */
.project-head { display: flex; flex-wrap: wrap; gap: 24px; align-items: center; padding-bottom: 24px; border-bottom: 1px solid var(--border); }
.project-head .meta { font-size: 14px; color: var(--text-2); }
.counts { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.count { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); }
.count::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--info); }
.count.error::before { background: var(--error); }
.count.warning::before { background: var(--warning); }
.count.info::before { background: transparent; border: 1.5px solid var(--info); }

/* Layout + side nav */
.layout { display: grid; grid-template-columns: 212px minmax(0, 1fr); gap: 40px; align-items: start; padding-top: 24px; }
.sidenav { position: sticky; top: 76px; display: flex; flex-direction: column; gap: 1px; }
.sidenav .group, .sidenav h6 { font: 600 11px var(--font-ui); letter-spacing: .07em; text-transform: uppercase; color: var(--text-3); padding: 18px 10px 6px; margin: 0; }
.sidenav a { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: var(--radius-sm); color: var(--text-2); font-size: 14px; text-decoration: none; }
.sidenav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.sidenav a.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: inset 0 0 0 1px var(--border); }
.sidenav a .pill { margin-left: auto; }
@media (max-width: 819px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 20px; padding-top: 16px; }
  .sidenav { position: static; flex-direction: row; gap: 6px; overflow-x: auto; margin: 0 -24px; padding: 0 24px 4px; scrollbar-width: none; }
  .sidenav .group, .sidenav h6 { display: none; }
  .sidenav a { flex: none; white-space: nowrap; border: 1px solid var(--border); border-radius: 99px; padding: 7px 12px; background: var(--surface); }
  .sidenav a.active { background: var(--text); color: var(--bg); border-color: var(--text); box-shadow: none; }
}

/* Filters */
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.filters select { padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); font-size: 13px; }
.filters .count-label, .filters > span:last-child { margin-left: auto; font-size: 13px; color: var(--text-3); }

/* Finding card */
.finding { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; transition: opacity .2s, border-color .3s; }
.finding + .finding { margin-top: 12px; }
.finding.done { opacity: .55; }
.finding.flash { border-color: var(--accent); }
.finding .meta { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; font-size: 12px; color: var(--text-3); }
.finding .detail { color: var(--text-2); }
.finding .actions { display: flex; gap: 8px; padding-top: 4px; }
.sev { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; font-size: 12px; color: var(--info); }
.sev::before { content: ""; width: 7px; height: 7px; border-radius: 50%; border: 1.5px solid currentColor; }
.finding.error .sev, .sev.error { color: var(--error); }
.finding.warning .sev, .sev.warning { color: var(--warning); }
.finding.error .sev::before, .sev.error::before, .finding.warning .sev::before, .sev.warning::before { background: currentColor; }
.excerpt, .quote { margin: 0; background: var(--bg); border-radius: var(--radius); padding: 14px 18px; font: 18px/1.55 var(--font-body); color: var(--text); }
.excerpt + .excerpt { margin-top: 6px; }
.excerpt .tag { font-family: var(--font-mono); }
.fix { display: flex; gap: 10px; font-size: 14px; }
.fix::before { content: "Fix"; font-weight: 600; color: var(--ok); }
.fix strong:first-child { display: none; }

/* Tags */
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 99px; font-size: 12px; background: var(--surface-2); color: var(--text-2); }
.tag small, .tag .n { color: var(--text-3); }

/* Bars + charts */
.bar-row { display: grid; grid-template-columns: minmax(0, 150px) minmax(0, 1fr) 72px; gap: 12px; align-items: center; font-size: 13px; color: var(--text-2); }
.bar-row + .bar-row { margin-top: 10px; }
.bar-row > :last-child { text-align: right; font: 12px var(--font-mono); font-variant-numeric: tabular-nums; }
.bar-track { position: relative; height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; background: var(--accent); transition: width .4s; }
.bar-fill.warn { background: var(--warning); }
.bar-fill.bad { background: var(--error); }
.chart { width: 100%; display: block; overflow: visible; }
.chart text { font: 11px var(--font-mono); fill: var(--text-3); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--text-2); }
.legend span::before { content: ""; display: inline-block; width: 14px; height: 2px; margin-right: 6px; vertical-align: middle; background: var(--c, var(--accent)); }
.heat { display: grid; gap: 3px; font-size: 13px; }
.heat .cell { height: 18px; border-radius: 3px; background: color-mix(in oklch, var(--accent) calc(var(--v, 0) * 100%), var(--surface-2)); }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.table-wrap table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table-wrap th { text-align: left; padding: 12px 16px; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }
.table-wrap td { padding: 12px 16px; border-top: 1px solid var(--border); }
.table-wrap td.num, .table-wrap th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap tr.click { cursor: pointer; }
.table-wrap tr.click:hover td { background: var(--bg); }

/* Long-form reading */
.letter, .chapter-text { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: clamp(28px, 6vw, 64px) clamp(20px, 6vw, 72px); }
.letter > *, .chapter-text > * { max-width: var(--content-width); margin-left: auto; margin-right: auto; }
.letter { font: 19px/1.65 var(--font-body); }
.letter p + p, .letter ul, .letter ol { margin-top: 18px; }
.letter h2, .letter h3 { font-size: 22px; font-weight: 500; margin-top: 34px; margin-bottom: 4px; }
.letter .quote { background: none; padding: 0; font-size: clamp(24px, 3vw, 30px); line-height: 1.3; margin-bottom: 24px; }
.chapter-text p { font: 19px/1.7 var(--font-body); margin: 0; hyphens: auto; }
.chapter-text p + p { text-indent: 1.5em; }
.chapter-text h2 { text-align: center; font-style: italic; margin-bottom: 32px; }
mark { background: var(--warning-soft); color: inherit; border-bottom: 2px solid var(--warning); padding: 1px 0; cursor: pointer; }
mark.error { background: var(--error-soft); border-bottom-color: var(--error); }

/* Reader panel */
.reader-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px 18px; display: flex; flex-direction: column; gap: 8px; }
.reader-card blockquote, .reader-card .reaction { margin: 0; font: italic 18px/1.5 var(--font-body); }
.reader-card .loved { color: var(--ok); font-weight: 600; }
.reader-card .stumbled { color: var(--warning); font-weight: 600; }
.score-chip { display: inline-flex; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); font-size: 12px; font-variant-numeric: tabular-nums; }

/* Run progress */
.run-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; }
.run-panel .spent { font: 12px var(--font-mono); color: var(--text-3); }
.progress { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress > * { height: 100%; border-radius: 99px; background: var(--ai); transition: width .4s; }

/* Notices */
.notice { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; padding: 12px 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); font-size: 14px; color: var(--text-2); }
.notice.warn { background: var(--warning-soft); border-color: transparent; color: var(--text); }
.notice.err { background: var(--error-soft); border-color: transparent; color: var(--text); }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(20,16,10,.42); display: grid; place-items: center; padding: 20px; }
.modal { width: min(560px, 100%); max-height: calc(100vh - 40px); overflow: auto; background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 28px; display: flex; flex-direction: column; gap: 18px; }
.modal h2 { font-size: 28px; }
.modal footer, .modal .actions { display: flex; justify-content: flex-end; gap: 8px; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 99px; font-size: 14px; box-shadow: var(--shadow); }

/* Empty */
.empty { border: 1px dashed var(--border-strong); border-radius: var(--radius-lg); padding: 48px 24px; text-align: center; color: var(--text-3); }
.empty strong, .empty h3 { display: block; font: 400 22px var(--font-body); color: var(--text); margin-bottom: 6px; }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--text-3); }
.input, .field input:not([type="checkbox"]), .field select, .field textarea { font-size: 15px; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 11px; outline: none; width: 100%; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
input[type="checkbox"] { accent-color: var(--accent); }

/* Motion. All durations collapse under prefers-reduced-motion. */
@keyframes bbRise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes bbFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes bbPop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes bbToast { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes bbRing { from { stroke-dasharray: 0 1000; } }
@keyframes bbGrow { from { width: 0; } }
@keyframes bbGrowY { from { height: 0; } }
@keyframes bbWipe { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
@keyframes bbShimmer { from { transform: translateX(-100%); } to { transform: translateX(250%); } }
@keyframes bbPulse { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }
:root { --ease-out: cubic-bezier(.2,.7,.2,1); }
.tab-content, main > section:first-child { animation: bbRise .26s var(--ease-out) both; }
.ring circle:last-child { animation: bbRing 1s var(--ease-out) .1s both; }
.bar-fill { animation: bbGrow .8s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 45ms + 120ms); }
.chart { animation: bbWipe 1.2s cubic-bezier(.35,.6,.2,1) .15s both; }
.modal-backdrop { animation: bbFade .18s ease-out both; }
.modal { animation: bbPop .24s var(--ease-out) both; }
.toast { animation: bbToast .26s var(--ease-out) both; }
.progress > * { position: relative; overflow: hidden; }
.progress > *::after { content: ""; position: absolute; inset: 0; width: 40%; background: linear-gradient(90deg, transparent, rgba(255,255,255,.45), transparent); animation: bbShimmer 1.8s ease-in-out infinite; }
.pill.ai.running, .project-card .running { animation: bbPulse 1.8s ease-in-out infinite; }
/* Triage collapse: wrap each .finding in .finding-slot; add .leaving, then remove the node after 320ms. */
.finding-slot { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .32s var(--ease-out), opacity .2s; }
.finding-slot > .finding { min-height: 0; overflow: hidden; }
.finding-slot.leaving { grid-template-rows: 0fr; opacity: 0; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; animation-delay: 0ms !important; transition-duration: .01ms !important; } }
