:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #1b1f24;
  --muted: #5d6673;
  --accent: #2459d6;
  --accent-ink: #ffffff;
  --accent-soft: #e6edfc;
  --high: #c62828;
  --high-soft: #fde8e8;
  --medium: #b45f00;
  --medium-soft: #fff1dc;
  --low: #6b7280;
  --low-soft: #eef0f3;
  --ok: #1d7a46;
  --ok-soft: #e3f4ea;
  --focus: #2459d6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1f242c;
    --border: #2c333d;
    --text: #e6e9ee;
    --muted: #9aa4b2;
    --accent: #6c9cff;
    --accent-ink: #0b1220;
    --accent-soft: #1c2a47;
    --high: #ff7b7b;
    --high-soft: #3a1d1f;
    --medium: #ffb454;
    --medium-soft: #3a2a14;
    --low: #9aa4b2;
    --low-soft: #242a33;
    --ok: #5fd08f;
    --ok-soft: #173426;
    --focus: #8fb3ff;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1216;
  --surface: #171b21;
  --surface-2: #1f242c;
  --border: #2c333d;
  --text: #e6e9ee;
  --muted: #9aa4b2;
  --accent: #6c9cff;
  --accent-ink: #0b1220;
  --accent-soft: #1c2a47;
  --high: #ff7b7b;
  --high-soft: #3a1d1f;
  --medium: #ffb454;
  --medium-soft: #3a2a14;
  --low: #9aa4b2;
  --low-soft: #242a33;
  --ok: #5fd08f;
  --ok-soft: #173426;
  --focus: #8fb3ff;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a { color: var(--accent); }
a:hover { text-decoration: underline; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; font-size: .9em; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

.skip-link { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; }
.skip-link:focus { left: 8px; }

.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Layout ---------- */

.topbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1100px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-size: 15px;
}
.status-line { color: var(--muted); font-size: 13px; flex: 1; min-width: 180px; }
.status-line .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--ok); vertical-align: 1px; }
.status-line .dot.warn { background: var(--medium); }
.status-line .dot.bad { background: var(--high); }
.status-line .dot.busy { background: var(--accent); animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: .3; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .status-line .dot.busy { animation: none; } }

.tabs { max-width: 1100px; margin: 0 auto; padding: 0 16px; display: flex; gap: 4px; overflow-x: auto; }
.tab {
  appearance: none; border: 0; background: none; color: var(--muted); cursor: pointer;
  padding: 10px 14px; font: inherit; font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tab .count { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 6px; border-radius: 10px; background: var(--high-soft); color: var(--high); font-size: 12px; }

main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 80px; }

/* ---------- Generic components ---------- */

.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 7px 14px; font: inherit; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none; line-height: 1.3;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--high); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px 18px; }

.banner { border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.banner.warn { background: var(--medium-soft); color: var(--text); border: 1px solid color-mix(in srgb, var(--medium) 40%, transparent); }
.banner.bad { background: var(--high-soft); border: 1px solid color-mix(in srgb, var(--high) 40%, transparent); }
.banner.info { background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); }

.badge {
  display: inline-flex; align-items: center; gap: 4px; border-radius: 6px; padding: 1px 7px;
  font-size: 12px; font-weight: 600; background: var(--low-soft); color: var(--muted); white-space: nowrap;
}
.badge.high { background: var(--high-soft); color: var(--high); }
.badge.medium { background: var(--medium-soft); color: var(--medium); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.new { background: var(--accent); color: var(--accent-ink); }

label { font-weight: 600; font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; font-weight: 400; margin: 2px 0 0; }
input[type="text"], input[type="password"], input[type="number"], input[type="search"], input[type="url"], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px;
}
textarea { min-height: 84px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; }
.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 4px; }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; margin-bottom: 8px; cursor: pointer; }
.check input { margin-top: 4px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- Connect screen ---------- */

.connect { max-width: 560px; margin: 48px auto; padding: 0 16px; }
.connect h1 { font-size: 24px; margin: 12px 0 6px; }
.connect ol { padding-left: 20px; }
.connect li { margin-bottom: 6px; }
.connect details { margin: 12px 0; }
.connect summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.error-text { color: var(--high); font-weight: 600; margin: 8px 0 0; }

/* ---------- Feed ---------- */

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
@media (max-width: 760px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat { padding: 12px 14px; cursor: pointer; text-align: left; font: inherit; color: inherit; }
.stat:hover { border-color: var(--accent); }
.stat .num { font-size: 26px; font-weight: 700; line-height: 1.1; }
.stat .lbl { color: var(--muted); font-size: 13px; }
.stat.high .num { color: var(--high); }
.stat.medium .num { color: var(--medium); }

.filters { padding: 12px 14px; margin-bottom: 14px; display: grid; gap: 10px; grid-template-columns: 2fr 1fr 1fr 1fr; align-items: end; }
.filters .field { margin: 0; }
.filters label { font-size: 12px; color: var(--muted); }
.filters-bottom { grid-column: 1 / -1; display: flex; gap: 14px; flex-wrap: wrap; align-items: center; }
@media (max-width: 760px) { .filters { grid-template-columns: 1fr 1fr; } .filters .search { grid-column: 1 / -1; } }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmented button { appearance: none; border: 0; background: var(--surface); color: var(--muted); padding: 6px 12px; font: inherit; font-weight: 600; font-size: 13px; cursor: pointer; }
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }

.day-heading { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 22px 0 8px; font-weight: 700; }

.item { display: flex; margin-bottom: 8px; overflow: hidden; }
.item .stripe { width: 5px; flex: none; background: var(--low); }
.item.high .stripe { background: var(--high); }
.item.medium .stripe { background: var(--medium); }
.item .body { padding: 10px 14px; flex: 1; min-width: 0; }
.item.reviewed { opacity: .6; }
.item .top { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 4px; }
.item .title { font-weight: 600; font-size: 15.5px; color: var(--text); text-decoration: none; overflow-wrap: anywhere; }
.item .title:hover { color: var(--accent); text-decoration: underline; }
.item .meta { color: var(--muted); font-size: 13px; margin-top: 2px; overflow-wrap: anywhere; }
.item .chips { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.chip { font-size: 12px; padding: 1px 7px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
.item .actions { display: flex; gap: 6px; align-items: flex-start; padding: 10px 12px 0 0; flex: none; }
.item details { margin-top: 6px; font-size: 13px; }
.item summary { cursor: pointer; color: var(--muted); font-weight: 600; }
.item details ul { margin: 6px 0; padding-left: 18px; }
.item pre { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--surface-2); padding: 8px 10px; border-radius: 6px; margin: 6px 0; font-size: 12.5px; max-height: 260px; overflow: auto; }
.focus-file { color: var(--high); font-weight: 600; }
@media (max-width: 600px) { .item { flex-wrap: wrap; } .item .actions { padding: 0 14px 10px 19px; } }

.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty h3 { color: var(--text); margin: 0 0 6px; }
.list-footer { display: flex; justify-content: center; margin: 16px 0; }

/* ---------- Targets ---------- */

.program { margin-bottom: 12px; }
.program-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.program-head h3 { margin: 0; font-size: 17px; }
.program-body { padding: 10px 18px 14px; }
.repo-row { display: flex; gap: 10px; align-items: baseline; padding: 6px 0; border-bottom: 1px dashed var(--border); flex-wrap: wrap; font-size: 14px; }
.repo-row:last-child { border-bottom: 0; }
.repo-row .url { overflow-wrap: anywhere; }
.repo-row .state { margin-left: auto; font-size: 13px; color: var(--muted); }
.repo-row .state.bad { color: var(--high); }

dialog { border: 1px solid var(--border); border-radius: 14px; padding: 0; width: min(720px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(10, 14, 20, .5); }
.dialog-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.dialog-head h2 { margin: 0; font-size: 18px; flex: 1; }
.dialog-body { padding: 16px 20px; max-height: calc(100vh - 200px); overflow: auto; }
.dialog-foot { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
.repo-edit { display: grid; grid-template-columns: 1fr 120px 1fr auto; gap: 6px; margin-bottom: 6px; align-items: center; }
.repo-edit-head { font-size: 12px; color: var(--muted); font-weight: 600; }
@media (max-width: 640px) { .repo-edit { grid-template-columns: 1fr auto; } .repo-edit .opt { grid-column: 1 / 2; } .repo-edit-head { display: none; } }

/* ---------- Settings ---------- */

.settings-grid { display: grid; gap: 14px; }
.settings-section h2 { font-size: 17px; margin: 0 0 4px; }
.settings-section > p { margin-top: 0; }
.channel { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; }
.channel h3 { margin: 0 0 6px; font-size: 15px; display: flex; gap: 8px; align-items: center; }
.kw-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.kw-table th { text-align: left; font-size: 12px; color: var(--muted); padding: 4px 6px; }
.kw-table td { padding: 3px 6px; border-top: 1px solid var(--border); }
.kw-table input { padding: 4px 8px; }
.kw-scroll { max-height: 380px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.weight-pos { color: var(--ok); }
.weight-neg { color: var(--high); }
.savebar { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--border); padding: 10px 16px; margin: 16px -16px 0; display: flex; gap: 10px; align-items: center; justify-content: flex-end; }

/* ---------- Help ---------- */

.help h2 { font-size: 18px; margin-top: 26px; }
.help h2:first-child { margin-top: 0; }
.help table { border-collapse: collapse; width: 100%; font-size: 14px; }
.help th, .help td { text-align: left; border-bottom: 1px solid var(--border); padding: 6px 8px; vertical-align: top; }

/* ---------- Toast ---------- */

.toast-wrap { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 50; display: grid; gap: 8px; width: min(520px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; display: flex; gap: 10px; align-items: center; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.toast .grow { flex: 1; }
.toast button { color: inherit; border-color: color-mix(in srgb, var(--bg) 40%, transparent); background: transparent; }
.toast.bad { background: var(--high); color: #fff; }
.mt { margin-top: 12px; }

/* ---------- Programs (catalog) ---------- */

.cat-item { display: flex; gap: 12px; padding: 12px 16px; margin-bottom: 8px; align-items: flex-start; }
.cat-item.watched { border-color: color-mix(in srgb, var(--ok) 55%, var(--border)); }
.cat-main { flex: 1; min-width: 0; }
.cat-main .top { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.cat-main .title { font-weight: 600; font-size: 15.5px; color: var(--text); text-decoration: none; margin-right: 4px; overflow-wrap: anywhere; }
.cat-main .title:hover { color: var(--accent); text-decoration: underline; }
.cat-main .meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.cat-main .chips { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.cat-main details { margin-top: 6px; font-size: 13px; }
.cat-main summary { cursor: pointer; color: var(--muted); font-weight: 600; }
.cat-main ul { margin: 6px 0; padding-left: 18px; }
.cat-action { flex: none; }
@media (max-width: 600px) { .cat-item { flex-direction: column; } }
