:root {
  --bg: #f5f6f8; --card: #ffffff; --ink: #14181f; --muted: #5d6675; --line: #e2e5ea;
  --accent: #2f5bd8; --accent-ink: #fff;
  --ok: #157a3f; --ok-bg: #e3f4ea; --bad: #b42318; --bad-bg: #fde8e6; --warn: #8a5a00; --warn-bg: #fdf1d6;
  --nw: #4b5563; --nw-bg: #eceef2; --code: #f0f2f5; --sel: #eef3ff;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1218; --card: #171b23; --ink: #e7eaf0; --muted: #98a2b3; --line: #2a303b;
    --accent: #6d8eff; --accent-ink: #0b0e14;
    --ok: #5fd08b; --ok-bg: #12301f; --bad: #ff8a7f; --bad-bg: #3a1714; --warn: #f2c35b; --warn-bg: #362a10;
    --nw: #b7c0cf; --nw-bg: #232934; --code: #10141b; --sel: #1d2638;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1218; --card: #171b23; --ink: #e7eaf0; --muted: #98a2b3; --line: #2a303b;
  --accent: #6d8eff; --accent-ink: #0b0e14;
  --ok: #5fd08b; --ok-bg: #12301f; --bad: #ff8a7f; --bad-bg: #3a1714; --warn: #f2c35b; --warn-bg: #362a10;
  --nw: #b7c0cf; --nw-bg: #232934; --code: #10141b; --sel: #1d2638;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.86em; }
code { background: var(--code); padding: 0.1em 0.35em; border-radius: 4px; }
button { font: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.5; }
.muted { color: var(--muted); }
.small { font-size: 0.86em; }

.top { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px;
  padding: 10px max(16px, 3vw); background: var(--card); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.1rem; color: var(--accent); }
.brand span { color: var(--ink); }
.pill { background: var(--ok-bg); color: var(--ok); border-radius: 999px; padding: 2px 10px; font-size: 0.8rem; font-weight: 600; white-space: nowrap; }
.spacer { flex: 1; }
.tier { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.tier button { background: transparent; border: 0; padding: 6px 12px; color: var(--muted); white-space: nowrap; }
.tier button[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

main { max-width: 1240px; margin: 0 auto; padding: 20px max(16px, 3vw) 40px; display: grid; gap: 18px; }
.intro h1 { font-size: clamp(1.35rem, 2.6vw, 1.9rem); line-height: 1.2; margin: 6px 0 10px; }
.intro p { margin: 0 0 8px; max-width: 78ch; }
.intro .fine { color: var(--muted); font-size: 0.9em; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; min-width: 0; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; margin-bottom: 10px; }
.card h2 { font-size: 1.02rem; margin: 0; }
.run { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.primary { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 8px; padding: 8px 14px; font-weight: 600; }
.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; }
.link { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; padding: 6px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr[data-repo] { cursor: pointer; }
tr[data-repo]:hover td { background: var(--sel); }
tr.sel td { background: var(--sel); }
tr.sel td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.repo { font-weight: 600; white-space: nowrap; }
.detail { color: var(--muted); font-size: 0.82em; margin-top: 4px; max-width: 46ch; }
.badge { display: inline-block; border-radius: 6px; padding: 1px 8px; font-size: 0.8rem; font-weight: 700; white-space: nowrap; background: var(--nw-bg); color: var(--nw); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.limit-note { margin: 12px 0 0; padding: 10px 12px; border-radius: 8px; background: var(--warn-bg); color: var(--ink); font-size: 0.9em; overflow-wrap: anywhere; }
.limit-note code { background: transparent; padding: 0; }

.grid { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 18px; align-items: start; }
.actions { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; margin: 12px 0; }
.actions button { border-radius: 8px; padding: 9px 10px; text-align: left; border: 1px solid var(--line); background: var(--card); color: var(--ink); }
.actions .breaker:not(:disabled):hover { border-color: var(--bad); background: var(--bad-bg); }
.actions .fix { border-color: var(--ok); color: var(--ok); font-weight: 600; }
.actions .fix:hover { background: var(--ok-bg); }
details { border-top: 1px solid var(--line); padding-top: 10px; }
summary { cursor: pointer; color: var(--accent); }
textarea { width: 100%; min-height: 300px; margin-top: 10px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--code); color: var(--ink);
  font: 12.5px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; resize: vertical; }
.editor-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.files { margin-top: 12px; display: grid; gap: 6px; font-size: 0.9em; }
.files code.gate { background: var(--ok-bg); color: var(--ok); font-weight: 700; }

.tabs { display: flex; flex-wrap: wrap; gap: 4px; }
.tabs button { background: transparent; border: 1px solid transparent; border-radius: 8px; padding: 5px 10px; color: var(--muted); }
.tabs button[aria-selected="true"] { border-color: var(--line); background: var(--sel); color: var(--ink); font-weight: 600; }
.tabs b { color: var(--bad); }
.tab { max-height: 560px; overflow: auto; }
.issue, .mail { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.issue.open { border-left: 4px solid var(--bad); }
.issue.closed { border-left: 4px solid var(--ok); }
.mail.bad { border-left: 4px solid var(--bad); }
.mail.good { border-left: 4px solid var(--ok); }
.issue-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; }
.issue .title, .mail-head { font-weight: 650; overflow-wrap: anywhere; }
.issue .num { font-size: 0.85em; }
.state { border-radius: 999px; padding: 1px 9px; font-size: 0.78rem; font-weight: 700; }
.state.open { background: var(--bad-bg); color: var(--bad); }
.state.closed { background: var(--ok-bg); color: var(--ok); }
pre { white-space: pre-wrap; overflow-wrap: anywhere; margin: 8px 0 0; background: var(--code); padding: 10px; border-radius: 8px; }
.flash { animation: flash 1.6s ease-out 1; }
@keyframes flash { 0% { box-shadow: 0 0 0 4px var(--accent); } 100% { box-shadow: 0 0 0 0 transparent; } }

.timeline ol { list-style: none; margin: 0; padding: 0; }
.ev { display: grid; grid-template-columns: 18px 150px minmax(0, 1fr); gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line); align-items: baseline; }
.ev .ic { text-align: center; color: var(--muted); }
.ev.alert .ic { color: var(--bad); }
.ev.resolved .ic, .ev.fix .ic { color: var(--ok); }
.ev .when { color: var(--muted); font-size: 0.86em; white-space: nowrap; }
.ev .what { overflow-wrap: anywhere; }
.ev.alert .what { color: var(--bad); font-weight: 600; }
.ev.alert .what .repo, .ev.resolved .what .repo { color: var(--ink); }

#toast { position: fixed; width: max-content; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); max-width: min(560px, calc(100vw - 32px));
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.25); z-index: 10; font-weight: 600; }
#toast.bad { background: var(--bad); color: #fff; }
#toast.good { background: var(--ok); color: #fff; }
.foot { color: var(--muted); font-size: 0.9em; text-align: center; }
.foot a { color: var(--accent); }

@media (max-width: 900px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .top { position: static; }
  #repo-table thead { display: none; }
  #repo-table, #repo-table tbody { display: block; }
  #repo-table tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 10px; row-gap: 4px; padding: 10px 8px; border-bottom: 1px solid var(--line); }
  #repo-table tr.sel { background: var(--sel); box-shadow: inset 3px 0 0 var(--accent); }
  #repo-table td { display: block; border: 0; padding: 0; background: transparent !important; box-shadow: none !important; }
  #repo-table td:nth-child(1) { grid-column: 1; }
  #repo-table td:nth-child(2) { grid-column: 2; grid-row: 1; justify-self: end; }
  #repo-table td:nth-child(3) { grid-column: 1 / -1; font-size: 0.86em; }
  #repo-table td:nth-child(4) { grid-column: 1; }
  #repo-table td:nth-child(5) { grid-column: 2; justify-self: end; align-self: start; }
  .detail { max-width: none; }
}
@media (max-width: 560px) {
  .spacer { display: none; }
  .tier { width: 100%; }
  .tier button { flex: 1; }
  .ev { grid-template-columns: 16px minmax(0, 1fr); }
  .ev .when { grid-column: 2; }
  .ev .what { grid-column: 2; }
  td, th { padding: 8px 6px; }
  textarea { min-height: 240px; }
}
