:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --text: #181a1f;
  --muted: #68707d;
  --border: #dfe2e8;
  --border-strong: #c8cdd6;
  --accent: #2857d9;
  --accent-soft: #e8edff;
  --danger: #c62f3c;
  --new: #2857d9;
  --progress: #ad6b00;
  --fixed: #7651c9;
  --verified: #247d4b;
  --rejected: #68707d;
  --radius: 10px;
  --shadow: 0 12px 36px rgb(20 25 35 / 16%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318;
    --surface: #181b21;
    --surface-raised: #20242c;
    --text: #f1f3f6;
    --muted: #9aa3b1;
    --border: #303640;
    --border-strong: #424a57;
    --accent: #7194ff;
    --accent-soft: #202d56;
    --danger: #ff6b77;
    --new: #7194ff;
    --progress: #e5a94d;
    --fixed: #b39aee;
    --verified: #58b77c;
    --rejected: #9aa3b1;
    --shadow: 0 16px 44px rgb(0 0 0 / 45%);
  }
}

* { box-sizing: border-box; }
html { font-size: 14px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  line-height: 1.45;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
button, a, input, select, textarea, summary { outline: none; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 48%, transparent); outline-offset: 2px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 4px; font-size: 1.8rem; letter-spacing: -0.03em; }
h2 { margin-bottom: 16px; font-size: 1.08rem; }
h3 { margin: 24px 0 8px; font-size: 0.95rem; }
small, .meta, .muted, .hint { color: var(--muted); }
.mono, code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.topbar { position: sticky; top: 0; z-index: 20; border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(12px); }
.topbar-inner { max-width: 1200px; height: 56px; margin: auto; padding: 0 20px; display: flex; align-items: center; gap: 32px; }
.brand { color: var(--text); font-size: 1.15rem; font-weight: 750; letter-spacing: -0.03em; }
.topbar nav { display: flex; height: 100%; gap: 4px; }
.topbar nav a { display: flex; align-items: center; padding: 0 12px; color: var(--muted); border-bottom: 2px solid transparent; }
.topbar nav a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.counter { min-width: 24px; height: 24px; padding: 2px 7px; border-radius: 999px; display: inline-grid; place-items: center; background: var(--accent); color: white; font-variant-numeric: tabular-nums; font-size: 0.78rem; font-weight: 700; }
.counter.subtle { background: var(--accent-soft); color: var(--accent); }
.shell { max-width: 1200px; margin: 0 auto; padding: 32px 20px 72px; }
.shell-public { min-height: 100vh; display: grid; place-items: center; }

.button { min-height: 34px; padding: 6px 12px; border: 1px solid var(--border-strong); border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--surface); color: var(--text); cursor: pointer; font-weight: 600; }
.button:hover { border-color: var(--accent); text-decoration: none; }
.button.primary { border-color: var(--accent); background: var(--accent); color: white; }
.button.ghost { border-color: transparent; background: transparent; }
.button.danger { color: var(--danger); }
.button.disabled { opacity: 0.45; cursor: default; }
.button.wide { width: 100%; }
.icon-button { min-width: 32px; min-height: 32px; padding: 4px; border: 0; border-radius: 7px; background: transparent; cursor: pointer; }

.page-heading { margin-bottom: 24px; display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.eyebrow { display: block; margin-bottom: 4px; color: var(--muted); font-size: 0.74rem; font-weight: 750; letter-spacing: 0.08em; text-transform: uppercase; }
.back-link { display: inline-block; margin-bottom: 8px; color: var(--muted); }
.panel { margin-bottom: 16px; padding: 20px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.section-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.section-heading h2 { margin-bottom: 2px; }
.section-heading p { color: var(--muted); }

.kpi-grid { margin-bottom: 16px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.kpi { min-height: 112px; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; justify-content: space-between; background: var(--surface); color: var(--muted); }
.kpi:hover { border-color: var(--accent); text-decoration: none; }
.kpi strong { color: var(--text); font-size: 2rem; font-variant-numeric: tabular-nums; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 16px; }
.activity-list, .thread { margin: 0; padding: 0; list-style: none; }
.activity-list li { padding: 12px 0; border-top: 1px solid var(--border); display: flex; gap: 10px; }
.activity-list li:first-child { border-top: 0; }
.activity-list a { display: block; color: var(--text); }
.activity-list .meta { display: block; margin-top: 2px; font-size: 0.82rem; }
.avatar { width: 30px; height: 30px; flex: 0 0 30px; border-radius: 50%; display: inline-grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-size: 0.78rem; font-weight: 750; }
.user-cell { display: inline-flex; align-items: center; gap: 8px; }
.empty-inline, .empty-state { padding: 32px 16px; display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--muted); text-align: center; }
.empty-inline strong, .empty-state strong { color: var(--text); }
.error-state { max-width: 460px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 8px; border-top: 1px solid var(--border); text-align: left; vertical-align: middle; }
thead th { padding-top: 0; border: 0; color: var(--muted); font-size: 0.78rem; font-weight: 600; }
.strong-link { color: var(--text); font-weight: 650; }
.status-counts { display: inline-flex; flex-wrap: wrap; gap: 5px; font-size: 0.76rem; font-variant-numeric: tabular-nums; }
.status-counts span { min-width: 22px; padding: 2px 5px; border-radius: 5px; background: color-mix(in srgb, currentColor 12%, transparent); text-align: center; white-space: nowrap; }
.status-counts b { font-weight: 750; }
.status-counts .is-zero { color: var(--muted); opacity: 0.55; }
.status-new { --status-color: var(--new); color: var(--new); }
.status-in_progress { --status-color: var(--progress); color: var(--progress); }
.status-fixed { --status-color: var(--fixed); color: var(--fixed); }
.status-verified { --status-color: var(--verified); color: var(--verified); }
.status-rejected { --status-color: var(--rejected); color: var(--rejected); }

label { display: grid; gap: 6px; color: var(--muted); font-size: 0.84rem; font-weight: 600; }
input, select, textarea { min-height: 36px; padding: 7px 9px; border: 1px solid var(--border-strong); border-radius: 7px; background: var(--surface); }
textarea { resize: vertical; }
.form-panel form { display: grid; gap: 12px; }
.form-panel.narrow { max-width: 680px; }
.field-error { margin: -6px 0 0; color: var(--danger); font-size: 0.82rem; }
.toggle { display: inline-flex; grid-auto-flow: column; align-items: center; gap: 7px; cursor: pointer; }
.toggle input { min-height: auto; }
.project-list { display: grid; }
.project-row { padding: 14px 4px; border-top: 1px solid var(--border); display: grid; grid-template-columns: minmax(180px, 1fr) auto 120px 20px; align-items: center; gap: 16px; color: var(--text); }
.project-row:first-child { border-top: 0; }
.project-row:hover { text-decoration: none; }
.project-row small { display: block; margin-top: 2px; }

.tabs { margin: -8px 0 20px; border-bottom: 1px solid var(--border); display: flex; gap: 4px; overflow-x: auto; scrollbar-width: thin; }
.tabs a { padding: 10px 12px; border-bottom: 2px solid transparent; color: var(--muted); white-space: nowrap; }
.tabs a[aria-current="page"] { border-bottom-color: var(--accent); color: var(--text); font-weight: 650; }
.filter-bar { margin-bottom: 12px; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-wrap: wrap; align-items: end; gap: 10px; background: var(--surface); }
.filter-bar fieldset { margin: 0; padding: 0; border: 0; }
.filter-bar legend { margin-bottom: 5px; color: var(--muted); font-size: 0.78rem; font-weight: 600; }
.chip-group { display: flex; gap: 5px; }
.chip { min-height: 32px; padding: 5px 9px; border: 1px solid var(--border); border-radius: 999px; display: inline-flex; align-items: center; gap: 5px; background: var(--surface); cursor: pointer; }
.chip input { min-height: 0; accent-color: currentColor; }
.group-toggle { margin-left: auto; }
.comments-panel { padding: 0; overflow: hidden; }
.comment-row { min-height: 82px; padding: 10px 14px; border-top: 1px solid var(--border); display: grid; grid-template-columns: 8px 62px minmax(200px, 1fr) auto 100px; align-items: center; gap: 12px; }
.comment-row:first-child { border-top: 0; }
.unread-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.unread-dot.is-read { background: var(--border-strong); }
.comment-thumb { width: 62px; height: 54px; border: 1px solid var(--border); border-radius: 7px; display: grid; place-items: center; overflow: hidden; background: var(--bg); }
.comment-thumb img { width: auto; height: auto; max-width: 100%; max-height: 100%; object-fit: contain; }
.comment-title a { display: block; max-width: 100%; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.comment-meta { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 10px; color: var(--muted); font-size: 0.78rem; }
.severity-critical { color: var(--danger); font-weight: 700; }
.status-badge { padding: 3px 7px; border: 1px solid currentColor; border-radius: 999px; font-size: 0.76rem; font-weight: 650; white-space: nowrap; }
.comment-stats { display: grid; gap: 4px; color: var(--muted); font-size: 0.76rem; text-align: right; }
.comments-panel.grouped .comment-row { border-top-width: 0; }
.comments-panel.grouped .comment-row.page-start { margin-top: 32px; border-top-width: 1px; }
.comments-panel.grouped .comment-row.page-start::before { content: attr(data-page); position: absolute; margin-top: -56px; color: var(--muted); font: 0.76rem ui-monospace, monospace; }
.load-more { margin: 12px auto; display: flex; width: max-content; }
.two-column { display: grid; grid-template-columns: minmax(280px, 0.7fr) minmax(0, 1.3fr); gap: 16px; align-items: start; }
.stack-row { padding: 12px 0; border-top: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.stack-row:first-child { border-top: 0; }
.stack-row strong, .stack-row small { display: block; margin-top: 4px; }
.row-actions { display: flex; gap: 6px; }
.invite-active { color: var(--verified); }
.invite-used { color: var(--accent); }
.invite-expired, .invite-revoked { color: var(--rejected); }
.code-block { min-width: 0; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--bg); }
.code-block-header { padding: 7px; border-bottom: 1px solid var(--border); display: flex; justify-content: flex-end; background: var(--surface); }
.code-block pre { margin: 0; padding: 14px; overflow-x: hidden; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }
.notice { padding: 14px; border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border)); border-radius: 8px; background: var(--accent-soft); }

.comment-layout { display: grid; grid-template-columns: minmax(0, 3fr) minmax(340px, 2fr); gap: 16px; align-items: start; }
.comment-title-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.media-panel h2 { color: var(--muted); font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.05em; }
.screenshot { width: 100%; padding: 0; border: 1px solid var(--border); border-radius: 8px; display: block; overflow: hidden; background: var(--bg); cursor: zoom-in; }
.screenshot img { width: 100%; max-height: 560px; display: block; object-fit: contain; }
.screenshot-natural { width: min(100%, var(--natural-width)); margin-right: auto; }
.screenshot-placeholder { min-height: 180px; border: 1px dashed var(--border-strong); border-radius: 8px; display: grid; place-items: center; color: var(--muted); background: var(--bg); }
.detail-column { min-width: 0; }
.project-ref { display: flex; justify-content: space-between; gap: 12px; }
.segmented { margin: 16px 0; display: flex; flex-wrap: wrap; gap: 5px; }
.segmented button { min-height: 32px; padding: 5px 8px; border: 1px solid currentColor; border-radius: 7px; background: transparent; cursor: pointer; }
.segmented button.is-current { border-color: var(--status-color); background: var(--status-color); color: white; font-weight: 700; cursor: default; }
.segmented button:disabled:not(.is-current) { opacity: 0.42; cursor: not-allowed; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.author-line { margin: 18px 0 12px; display: flex; gap: 9px; align-items: center; }
.author-line small { display: block; }
.comment-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.detail-meta { border-top: 1px solid var(--border); padding-top: 12px; display: flex; justify-content: space-between; }
.detail-links { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 12px; }
.passport summary { cursor: pointer; font-weight: 700; }
.passport-list > div { padding: 8px 0; border-top: 1px solid var(--border); display: grid; grid-template-columns: 90px minmax(0, 1fr); gap: 10px; }
.passport-list dt { color: var(--muted); }
.passport-list dd { margin: 0; overflow-wrap: anywhere; }
.styles-table th { width: 40%; color: var(--muted); font-weight: 500; }
.html-snippet { max-height: 240px; margin: 0; padding: 12px; border: 1px solid var(--border); border-radius: 7px; overflow: auto; background: var(--bg); white-space: pre-wrap; }
.thread li { padding: 12px 0; border-top: 1px solid var(--border); }
.reply-head { display: flex; justify-content: space-between; gap: 10px; }
.reply-head time { color: var(--muted); font-size: 0.78rem; }
.thread p { margin: 6px 0 0; white-space: pre-wrap; }
.system-line, .system-note { color: var(--muted); font-size: 0.82rem; }
.role-mark { margin-left: 4px; padding: 2px 5px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); font-size: 0.68rem; font-weight: 650; }
.thread-panel form { margin-top: 18px; display: grid; gap: 8px; }
.reply-actions { display: flex; align-items: end; justify-content: space-between; gap: 10px; }
.comment-nav { display: flex; gap: 6px; }

.auth-card { width: min(400px, 100%); padding: 28px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.auth-brand { display: inline-block; margin-bottom: 32px; }
.auth-card form { display: grid; gap: 12px; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; }
.token-reveal { margin: 16px 0; padding: 12px; border: 1px solid var(--progress); border-radius: 8px; background: color-mix(in srgb, var(--progress) 10%, transparent); }
.lightbox { width: min(96vw, 1400px); max-width: none; padding: 44px 12px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-raised); box-shadow: var(--shadow); }
.lightbox::backdrop { background: rgb(0 0 0 / 72%); }
.lightbox img { max-width: 100%; max-height: 86vh; margin: auto; display: block; }
.lightbox .icon-button { position: absolute; top: 8px; right: 8px; font-size: 1.5rem; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 100; max-width: 420px; padding: 12px 16px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-raised); box-shadow: var(--shadow); }
.toast.is-error { border-color: var(--danger); }
.access-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.access-chip { min-height: 28px; padding: 3px 8px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); cursor: pointer; }
.access-chip:hover { border-color: var(--danger); color: var(--danger); }
.access-actions { text-align: right; white-space: nowrap; }
.device-details { margin-top: 4px; color: var(--muted); font-size: 0.78rem; }
.device-details summary { cursor: pointer; }
.device-details ul { margin: 6px 0 0; padding-left: 18px; }
.is-revoked { color: var(--muted); opacity: 0.68; }
.install-page { width: min(760px, 100%); padding: 40px 0; }
.install-page > .brand { display: inline-block; margin-bottom: 56px; }
.install-page h1 { font-size: 2.5rem; }
.lead { max-width: 640px; color: var(--muted); font-size: 1.2rem; }
.install-page section { margin: 40px 0; }
.steps { padding: 0; list-style: none; }
.steps li { padding: 14px 0; border-top: 1px solid var(--border); display: grid; grid-template-columns: 40px 1fr; gap: 12px; }
.steps li > span { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.install-placeholder { min-height: 280px; }

@media (max-width: 800px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .dashboard-grid, .two-column, .comment-layout { grid-template-columns: 1fr; }
  .project-row { grid-template-columns: minmax(150px, 1fr) auto 18px; }
  .project-row time { display: none; }
  .comment-row { grid-template-columns: 8px 52px minmax(150px, 1fr) auto; }
  .comment-thumb { width: 52px; }
  .comment-stats { display: none; }
  .filter-bar { align-items: stretch; }
  .group-toggle { margin-left: 0; }
}

@media (max-width: 560px) {
  .topbar-inner { height: auto; min-height: 56px; padding: 8px 12px; gap: 10px; flex-wrap: wrap; }
  .topbar nav { order: 3; width: 100%; height: 38px; }
  .topbar nav a { flex: 1; justify-content: center; }
  .shell { padding: 24px 12px 56px; }
  .page-heading { align-items: flex-start; }
  .kpi-grid { gap: 8px; }
  .kpi { min-height: 92px; padding: 12px; }
  .panel { padding: 14px; }
  .project-row { grid-template-columns: minmax(0, 1fr) 18px; }
  .project-row > :first-child { grid-column: 1; grid-row: 1; }
  .project-row > .status-counts { grid-column: 1 / -1; grid-row: 2; }
  .project-row > [aria-hidden="true"] { grid-column: 2; grid-row: 1; }
  .tabs { flex-wrap: wrap; overflow-x: visible; }
  .comment-row { padding: 10px; grid-template-columns: 7px minmax(0, 1fr) auto; }
  .comment-thumb { display: none; }
  .comment-meta .mono { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .chip-group { width: 100%; flex-wrap: wrap; }
  .comment-heading { display: block; }
  .comment-nav { margin-top: 12px; }
  .field-grid { grid-template-columns: 1fr; }
  .inline-form, .stack-row, .reply-actions { align-items: stretch; flex-direction: column; }
  .row-actions { flex-wrap: wrap; }
  .access-table-wrap { overflow-x: visible; }
  .access-table, .access-table tbody, .access-table tr, .access-table td { display: block; width: 100%; }
  .access-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  .access-table tr { padding: 10px 0; border-top: 1px solid var(--border); }
  .access-table tr:first-child { border-top: 0; }
  .access-table td { padding: 5px 0; border: 0; display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 8px; }
  .access-table td::before { content: attr(data-label); color: var(--muted); font-size: 0.78rem; }
  .access-table .access-actions { display: block; text-align: left; }
  .access-table .access-actions .button { width: 100%; }
  .access-table-wrap + .button { width: 100%; }
  .section-heading { flex-direction: column; }
  .install-page h1 { font-size: 2rem; }
}
