/* Cato base layout and components, following SINKER-STYLE.md. */
*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 var(--fs-body)/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--selection); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-weight: 600; margin: 0; }
h1 { font-size: var(--fs-title); }
h2 { font-size: var(--fs-value); }
code, .mono { font-family: Consolas, "Cascadia Mono", monospace; font-size: 12px; }
.muted { color: var(--muted); }
.small { font-size: var(--fs-small); }
.ok { color: var(--accent); font-weight: 600; }
.fail { color: var(--danger); font-weight: 600; }
.warn { color: var(--warning); }
.hidden { display: none !important; }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--hover-border) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--hover-border); border-radius: 4px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- App shell ---------- */
.app { min-height: 100vh; display: grid; grid-template-rows: var(--header-h) 1fr auto; grid-template-columns: var(--sidebar-w) 1fr; grid-template-areas: "header header" "side main" "side footer"; }
.app-header { grid-area: header; display: flex; align-items: center; gap: 12px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.logo { width: 28px; height: 28px; border-radius: 8px; background: var(--accent-fill); color: var(--accent); display: grid; place-items: center; font-weight: 600; font-size: 15px; flex: none; }
.app-title { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.app-title a { color: var(--text); }
.app-title .subtitle { color: var(--muted); position: relative; top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.app-header .nav-toggle { display: none; }

.app-side { grid-area: side; background: var(--surface); border-right: 1px solid var(--border); padding: 12px 0; }
.nav-group { margin-top: 10px; }
.nav-label { font-size: var(--fs-small); font-weight: 600; color: var(--muted); text-transform: uppercase; margin: 8px 18px 4px; }
.nav a { display: flex; align-items: center; gap: 10px; margin: 2px 8px; padding: 9px 10px; border-radius: var(--radius-item); color: var(--text); }
.nav-group a { margin-left: 22px; }
.nav a:hover { background: var(--row-hover); text-decoration: none; }
.nav a.active { background: var(--nav-selected); }
.nav a.soon { color: var(--muted); pointer-events: none; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--idle); flex: none; }
.dot.live { background: var(--live); }

.app-main { grid-area: main; padding: var(--gap); min-width: 0; }
.app-footer { grid-area: footer; padding: 14px var(--gap); color: var(--muted); font-size: var(--fs-small); border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 6px 16px; }

.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 18px; }
.page-head .subtitle { color: var(--muted); }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

@media (max-width: 767px) {
  .app { grid-template-columns: 1fr; grid-template-areas: "header" "main" "footer"; }
  .app-side { position: fixed; top: var(--header-h); left: 0; bottom: 0; width: min(300px, 85vw); z-index: 30; transform: translateX(-100%); transition: transform .15s ease; overflow-y: auto; }
  .app.nav-open .app-side { transform: none; box-shadow: 0 0 28px rgba(0,0,0,.55); }
  .app-header .nav-toggle { display: inline-flex; }
  .app-title .subtitle { display: none; }
  .nav a, .btn, .input, select.input { min-height: 40px; }
}

/* ---------- Cards, sections ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); padding: 16px; margin-bottom: 18px; }
.card.flush { padding: 0; overflow: hidden; }
.card > .card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.card.flush > .card-head { padding: 14px 16px 0; }
.card-head > .btn { margin-left: auto; }
.card-head > .section-label { margin: 0; }
.section-label { font-size: var(--fs-small); font-weight: 600; color: var(--muted); text-transform: uppercase; margin: 0 0 6px; }
.value { font-size: var(--fs-value); }
.empty { color: var(--muted); text-align: center; margin: 24px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 0 18px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); padding: 14px 16px; }
.stat .value { font-size: 22px; font-weight: 600; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 14px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface-alt); color: var(--text); font: inherit; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--hover); border-color: var(--hover-border); text-decoration: none; }
.btn.accent { background: var(--accent-fill); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { background: var(--danger-fill); border-color: var(--danger); }
.btn.accent:hover, .btn.danger:hover { background: var(--hover); border-color: var(--hover-border); }
.btn.small { padding: 4px 10px; font-size: var(--fs-small); }
.btn.link { background: none; border-color: transparent; color: var(--accent); padding-left: 4px; padding-right: 4px; }
.btn:disabled, .btn.disabled { opacity: .45; pointer-events: none; }
.btn-row { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 16px; }
form.inline { display: inline; }

/* ---------- Forms ---------- */
.form-row { display: grid; grid-template-columns: 210px 1fr; gap: 10px; align-items: center; margin-bottom: 10px; }
.form-row > label:first-child { color: var(--muted); }
.form-row .help { grid-column: 2; color: var(--muted); font-size: var(--fs-small); margin-top: -6px; }
.form-row .error-text { grid-column: 2; color: var(--danger); font-size: var(--fs-small); margin-top: -6px; }
@media (max-width: 767px) { .form-row { grid-template-columns: 1fr; gap: 4px; } .form-row .help, .form-row .error-text { grid-column: 1; margin-top: 0; } }
.input { width: 100%; padding: 6px 8px; background: var(--input); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font: inherit; caret-color: var(--accent); }
.input:focus { outline: none; border-color: var(--accent); }
.input.invalid { border-color: var(--danger); }
textarea.input { min-height: 90px; resize: vertical; }
select.input { appearance: none; padding-right: 28px; min-height: 32px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='4'%3E%3Cpath d='M.75.75 4 3.25 7.25.75' fill='none' stroke='%238b9bb4' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }
input[type=color].input { padding: 2px; height: 32px; width: 56px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { appearance: none; width: 16px; height: 16px; margin: 0; border-radius: var(--radius-check); border: 1px solid var(--border); background: var(--input); display: grid; place-items: center; cursor: pointer; flex: none; }
.check input:hover { border-color: var(--hover-border); }
.check input:checked { background: var(--accent-fill); border-color: var(--accent); }
.check input:checked::after { content: ""; width: 8px; height: 4px; border: solid #fff; border-width: 0 0 2px 2px; border-radius: 1px; transform: rotate(-45deg) translate(1px, -1px); }
.toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.toggle input { appearance: none; width: 40px; height: 22px; border-radius: 11px; background: var(--track); position: relative; margin: 0; cursor: pointer; flex: none; transition: background .12s; }
.toggle input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .12s; }
.toggle input:checked { background: var(--accent-toggle); }
.toggle input:checked::after { left: 21px; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px 16px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th { background: var(--header-row); color: var(--muted); font-size: var(--fs-small); font-weight: 600; text-align: left; padding: 8px 10px; white-space: nowrap; }
.table td { padding: 6px 8px 6px 10px; border-top: 1px solid var(--splitter); vertical-align: middle; }
.table tbody tr:hover { background: var(--row-hover); }
.table td.actions { text-align: right; white-space: nowrap; }
.table td.num, .table th.num { text-align: right; }

/* ---------- Badges, flashes ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--border); font-size: var(--fs-small); color: var(--muted); white-space: nowrap; }
.badge.accent { color: var(--accent); border-color: var(--accent-fill); }
.badge.danger { color: var(--danger); border-color: var(--danger-fill); }
.badge.warning { color: var(--warning); border-color: #4a3a12; }
.cell-flex { display: flex; align-items: center; gap: 8px; min-width: 160px; }
.swatch { flex: none; width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: var(--c, var(--idle)); }
.flash { border: 1px solid var(--border); border-left: 3px solid var(--accent); background: var(--surface); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; display: flex; gap: 10px; }
.flash.error { border-left-color: var(--danger); }
.flash.warning { border-left-color: var(--warning); }
.flash button { margin-left: auto; background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; }
.secret-box { display: flex; gap: 8px; align-items: center; background: var(--input); border: 1px solid var(--accent); border-radius: var(--radius); padding: 10px 12px; word-break: break-all; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); }

/* ---------- Auth and installer pages ---------- */
.center-page { min-height: 100vh; display: grid; place-items: center; padding: 28px 16px; }
.dialog { width: 100%; max-width: 460px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-dialog); padding: 22px; box-shadow: 0 0 28px rgba(0,0,0,.55); }
.dialog.wide { max-width: 640px; }
.dialog::before { content: ""; display: block; width: 36px; height: 3px; border-radius: 2px; background: var(--accent); margin-bottom: 14px; }
.dialog.danger::before { background: var(--danger); }
.dialog h1 { margin-bottom: 4px; }
.dialog .lead { color: var(--muted); margin: 10px 0 20px; line-height: 20px; }
.dialog .form-row { grid-template-columns: 150px 1fr; }
@media (max-width: 520px) { .dialog .form-row { grid-template-columns: 1fr; } }
.footnote { text-align: center; margin-top: 14px; }
.steps { display: flex; gap: 6px; margin-bottom: 16px; }
.steps span { flex: 1; height: 3px; border-radius: 2px; background: var(--track); }
.steps span.done { background: var(--accent); }

/* ---------- Pager ---------- */
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 10px 16px; color: var(--muted); }

/* ---------- Video Seed ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--border); background: var(--surface-alt); border-radius: 999px; padding: 2px 4px 2px 12px; }
.chip.active { border-color: var(--accent); }
.chip a { color: var(--text); }
.chip button { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 14px; padding: 0 6px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px; }
.filters .input { width: auto; flex: 0 1 auto; }
.filters .search { flex: 1 1 260px; min-width: 200px; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form .input { flex: 1; }
.input.narrow { max-width: 180px; }
.seed-table td { vertical-align: top; }
.seed-table .row-title { color: var(--text); font-weight: 600; }
.seed-table tr.closed .row-title { color: var(--muted); font-weight: 400; text-decoration: line-through; text-decoration-color: var(--idle); }
.poster-col { width: 44px; padding-right: 0 !important; }
.thumb { width: 32px; height: 48px; border-radius: 4px; object-fit: cover; display: block; background: var(--surface-alt); }
.empty-thumb { border: 1px dashed var(--border); }
.label-pill { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.label-pill .swatch { background: var(--c, var(--idle)); }
.log-badge { margin-left: 6px; padding: 0 6px; }
.inline-status { min-height: 28px; padding: 3px 26px 3px 8px; width: auto; }
.inline-status.saved { border-color: var(--accent); }
.due-overdue { color: var(--danger); font-weight: 600; }
.due-week { color: var(--warning); }
.save-view summary { cursor: pointer; margin: 0; }
.save-view form { margin-top: 10px; max-width: 480px; }
.seed-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 18px; align-items: start; }
@media (max-width: 1100px) { .seed-layout { grid-template-columns: 1fr; } }
.seed-head { display: flex; gap: 18px; align-items: flex-start; }
.seed-head .poster { flex: none; width: 154px; }
.seed-head .poster img, .poster-empty { width: 154px; aspect-ratio: 2 / 3; object-fit: cover; border-radius: var(--radius-item); border: 1px solid var(--border); display: block; background: var(--surface-alt); }
.seed-fields, .seed-meta { flex: 1; min-width: 0; }
@media (max-width: 640px) { .seed-head { flex-direction: column; } .seed-head .poster, .seed-head .poster img, .poster-empty { width: 110px; } }
.overview { color: var(--muted); line-height: 20px; margin: 0 0 14px; max-width: 70ch; }
.notes { border-left: 3px solid var(--border); padding-left: 10px; }
dl.meta { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; margin: 0 0 14px; }
dl.meta dt { color: var(--muted); }
dl.meta dd { margin: 0; }
.found-card { border-color: var(--accent); }
.danger-zone { text-align: right; margin-bottom: 18px; }
details.card > summary { cursor: pointer; list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before { content: "▸ "; }
details.card[open] > summary::before { content: "▾ "; }
details.card[open] > summary { margin-bottom: 12px; }
.episode-picker { display: grid; gap: 6px; }
.season { border: 1px solid var(--splitter); border-radius: var(--radius-item); padding: 8px 10px; }
.season-head { gap: 10px; flex-wrap: wrap; }
.season details > summary { cursor: pointer; margin: 6px 0 0 24px; }
.episode-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px 14px; padding: 10px 0 4px 24px; }
.episode-grid input:disabled { opacity: .45; }
.timeline { list-style: none; margin: 14px 0 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 18px; border-left: 1px solid var(--border); margin-left: 4px; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 4px; width: 9px; height: 9px; border-radius: 50%; background: var(--idle); }
.timeline li.system { color: var(--muted); font-size: var(--fs-small); }
.timeline li.custom::before { background: var(--accent); }
.timeline li.custom .note { background: var(--surface-alt); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; margin-top: 4px; color: var(--text); }
.timeline .when { font-size: var(--fs-small); color: var(--muted); }
.note-form textarea { min-height: 64px; }
.table th a.sort { color: inherit; }
.table th a.sort:hover { color: var(--text); text-decoration: none; }
.seed-table td:nth-child(n+6) { white-space: nowrap; }

/* ---------- Video Barn ---------- */
.filters .input.year { width: 92px; }
.barn-table td { vertical-align: top; }
.barn-table .row-title { color: var(--text); font-weight: 600; }
.loc { display: inline-flex; align-items: center; gap: 4px; margin-right: 8px; white-space: nowrap; }
.loc .dot { width: 8px; height: 8px; }
.loc.offline { color: var(--muted); }
.meter { width: 90px; height: 6px; background: var(--track); border-radius: 3px; overflow: hidden; display: inline-block; vertical-align: middle; margin-right: 6px; }
.meter.wide { width: 100%; height: 12px; display: block; margin: 14px 0 8px; }
.meter span { display: block; height: 100%; background: var(--warning); width: 0; }
.meter span.full { background: var(--accent); }
.meter.wide span { background: var(--accent); }
.meter.wide span.busy { width: 35%; animation: autolink-slide 1.1s ease-in-out infinite; }
@keyframes autolink-slide { from { transform: translateX(-120%); } to { transform: translateX(320%); } }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-bottom: 12px; }
.legend .cell { width: 14px; height: 14px; min-width: 0; padding: 0; }
.grid-season { margin-bottom: 12px; }
.grid-head { display: flex; gap: 10px; align-items: baseline; margin-bottom: 6px; }
.ep-cells { display: flex; flex-wrap: wrap; gap: 4px; }
.cell { display: inline-grid; place-items: center; min-width: 30px; height: 26px; padding: 0 4px; border-radius: 4px; font-size: var(--fs-small); border: 1px solid var(--border); cursor: default; }
.cell.present { background: var(--accent-fill); border-color: var(--accent); color: var(--accent-text); }
.cell.dup { background: #0c4a6e; border-color: var(--uploading); color: #e0f2fe; }
.cell.missing { background: var(--danger-fill); border-color: var(--danger); color: var(--text); }
.cell.extra { background: var(--surface-alt); border-color: var(--modified); color: var(--modified); }
.cell.future { background: transparent; border-style: dashed; color: var(--muted); }
.loc-row { padding: 8px 0; border-top: 1px solid var(--splitter); }
.loc-row:first-of-type { border-top: 0; }
.dup-group { padding: 8px 0; border-top: 1px solid var(--splitter); }
.path { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pad { padding: 10px 16px; }
tr.group-start td { border-top: 1px solid var(--border); }
.candidates { display: grid; gap: 8px; }
.candidate { display: flex; gap: 12px; align-items: center; border: 1px solid var(--splitter); border-radius: var(--radius-item); padding: 8px; }
.candidate:hover { background: var(--row-hover); }
.cand-poster { width: 46px; height: 69px; object-fit: cover; border-radius: 4px; flex: none; display: block; background: var(--surface-alt); }
.cand-body { flex: 1; min-width: 0; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-head { flex-wrap: wrap; }
.barn-table td.num { white-space: nowrap; }
