:root {
  color-scheme: dark;
  --bg:         #0d0d0d;
  --bg-surface: #16161c;
  --bg-input:   #111118;
  --border:     #2a2a36;
  --fg:         #e2e2e8;
  --fg-dim:     #8888a0;
  --accent:     #5c6bc0;
  --link:       #9fa8da;
  --success:    #7fc99a;
  --warning:    #e8c06a;
  --error:      #ef8f99;
  --monbooru:   #ef8f99;
  --peer:       var(--monbooru);
  --danger:     #9d2235;
  --on-danger:  var(--fg);
  --scrim:      #000;
  --font-mono:  "JetBrains Mono", "Fira Mono", "Courier New", monospace;
  --heat-0:     #1b1b25;
  --heat-1:     #4a5595;
  --heat-2:     var(--accent);
  --heat-3:     #7583d8;
  --heat-4:     #93a0ef;
}

#content { flex: 1; padding: 16px; width: 100%; max-width: 1000px; margin: 0 auto; }
#content.content-wide { max-width: 1280px; }
.content-scroll { flex: 1; min-height: 0; overflow-y: auto; }

.pause-toggle, .pause-toggle form { display: inline-flex; }
.pause-btn.paused { color: var(--warning); }

#landing {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 16px;
}
#landing .landing-logo { height: 84px; width: auto; object-fit: contain; }
#landing h1 {
  font-size: 28px; letter-spacing: 4px; text-transform: uppercase; font-weight: bold;
}
#landing .add-form { width: 100%; max-width: 860px; }
#landing .links { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 24px; margin-top: 4px; }
#landing .field-hint { color: var(--fg-dim); font-size: 12px; }

.add-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: stretch; }
.add-row .search-input-wrap { flex: 1 1 220px; }
.add-row button { padding-left: 16px; padding-right: 16px; }
.queue-actions { display: contents; }

.queue-table td, .watch-table td { vertical-align: top; }

.queue-table { table-layout: fixed; min-width: 540px; }
.queue-table th:nth-child(1) { width: 116px; }
.queue-table th:nth-child(3) { width: 104px; }
.queue-table th:nth-child(4) { width: 116px; }
.queue-table th:nth-child(5) { width: 96px; }
.queue-table th:nth-child(6) { width: 192px; }
.queue-table th:nth-child(7) { width: 168px; }
.queue-table .actions, .watch-table .actions { flex-direction: column; }
.queue-table .actions button, .watch-table .actions button { white-space: nowrap; }
@media (max-width: 1000px) {
  .queue-table th:nth-child(4), .queue-table td:nth-child(4),
  .queue-table th:nth-child(5), .queue-table td:nth-child(5) { width: 0; padding: 0; overflow: hidden; }
}
@media (max-width: 780px) {
  .queue-table th:nth-child(3), .queue-table td:nth-child(3) { width: 0; padding: 0; overflow: hidden; }
  .queue-table th:nth-child(7) { width: 112px; }
  .queue-table .actions button { white-space: normal; }
}

.queue-table .job-row td { overflow: hidden; }

.watch-table { table-layout: fixed; min-width: 576px; }
.watch-table td { overflow: hidden; }
.watch-table th:nth-child(1) { width: 156px; }
.watch-table th:nth-child(3) { width: 116px; }
.watch-table th:nth-child(4) { width: 124px; }
.watch-table th:nth-child(5) { width: 104px; }
.watch-table th:nth-child(6) { width: 96px; }
.watch-table th:nth-child(7) { width: 168px; }
.watch-table select { width: 100%; }
.watch-table .field-hint { color: var(--fg-dim); }
@media (max-width: 1000px) {
  .watch-table th:nth-child(3), .watch-table td:nth-child(3),
  .watch-table th:nth-child(6), .watch-table td:nth-child(6) { width: 0; padding: 0; overflow: hidden; }
}
@media (max-width: 780px) {
  .watch-table th:nth-child(7) { width: 112px; }
  .watch-table .actions button { white-space: normal; }
}
.queue-site, .queue-gallery { white-space: nowrap; text-overflow: ellipsis; }
.queue-url { word-break: break-all; }
.queue-view { font-size: 12px; margin-left: 6px; white-space: nowrap; }
.queue-sent { font-size: 12px; margin-left: 6px; color: var(--fg-dim); cursor: help; }
.job-kind { margin-left: 0; color: var(--link); white-space: nowrap; }
.job-lane { display: block; color: var(--fg-dim); font-size: 11px; }

.lookup-status { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--fg-dim); margin-top: 6px; }
.lk-on { color: var(--success); }
.lk-off { color: var(--fg-dim); }
#landing .lookup-status { justify-content: center; }

.queue-summary span { display: block; overflow-wrap: break-word; }
.job-time { display: block; color: var(--fg-dim); font-size: 12px; }
.job-reason { display: inline-block; max-width: 40ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; color: var(--fg-dim); font-size: 12px; }
.queue-summary .job-reason { display: block; }
.ptr-sent { color: var(--fg-dim); font-size: 12px; white-space: nowrap; }
.queue-table .job-row:has(+ .items-row) td { border-bottom: none; }
.items-row td { border-top: none; padding-top: 0; }
.items-row details { margin-left: 16px; border-left: 2px solid var(--accent); padding-left: 12px; }
.items-row summary { color: var(--fg-dim); padding: 2px 0; }
.job-phase { margin-left: 6px; }
.job-phase-downloading, .job-phase-pushing { color: var(--link); }
.job-phase-finished { color: var(--fg-dim); }
.job-items { padding: 4px 8px 8px 16px; font-size: 13px; display: grid; grid-template-columns: minmax(90px, 1fr) minmax(120px, 1.7fr) auto; column-gap: 16px; row-gap: 1px; align-items: baseline; }
.item-row { display: contents; }
.item-subj { color: var(--fg-dim); min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-left: 1px solid var(--border); padding: 2px 0 2px 12px; }
.item-subj a { color: inherit; }
.item-out { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-view { white-space: nowrap; }
.item-debug { margin-left: 6px; font-size: 12px; color: var(--fg-dim); }
.item-debug:hover { color: var(--link); }
.job-items > .more-items { grid-column: 1 / -1; margin-left: 0; border-left: none; padding-left: 0; }
.more-items > .job-items { padding: 4px 0 0; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.add-bar { margin-bottom: 14px; }

.st-queued, .st-running { color: var(--link); }
.st-succeeded, .o-created { color: var(--success); }
.st-partial, .st-interrupted { color: var(--warning); }
.st-failed, .o-failed { color: var(--error); }
.st-canceled { color: var(--fg-dim); }
.o-duplicate, .o-enriched, .o-matched, .o-replaced, .o-skipped_archive, .o-skipped_unsupported, .o-canceled, .o-merge { color: var(--fg-dim); }
.o-pending, .o-downloaded, .o-uploaded { color: var(--link); }
.o-capped, .o-warn { color: var(--warning); }

.settings-shell { display: flex; align-items: stretch; flex: 1; min-height: 0; }

#content.settings-content { max-width: none; margin: 0; overflow-y: auto; min-height: 0; }
@media (max-width: 768px) {
  .settings-shell { flex-direction: column; }
  #sidebar { width: auto; border-right: none; border-bottom: 1px solid var(--border); padding: 0; overflow-y: visible; }
  #sidebar .settings-nav { flex-direction: row; flex-wrap: wrap; padding: 8px; }
}

.sites-title-link { margin-left: auto; font-size: 12px; font-weight: normal; white-space: nowrap; }

.settings-cols > .settings-sub-wide { flex-basis: 100%; }

.settings-cols > .field input[type=text], .settings-cols > .field select { width: 100%; max-width: none; }

.contrib-table td { text-align: left; min-width: 0; }

.field label.checkbox-inline { display: flex; align-items: center; gap: 6px; }
.downloads-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 28px; margin-bottom: 4px; }
.downloads-grid .field { margin-bottom: 0; }
.gdl-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.gdl-row input[type=text] { width: 18ch; }
.settings-section .field.gdl-field { margin: 10px 0 0; }
@media (min-width: 570px) {
  .gdl-raw, .gdl-raw form { display: flex; flex-direction: column; }
  .gdl-raw form { flex: 1; }
  .gdl-raw textarea { flex: 1; min-height: 60px; }
}
.gdl-progress { display: flex; align-items: center; gap: 10px; margin: 6px 0 2px; }
.gdl-bar { flex: 1; }
.gdl-pct { color: var(--fg-dim); font-variant-numeric: tabular-nums; }

.hint-warn { display: block; color: var(--warning); font-size: 12px; }
textarea { width: 100%; min-height: 80px; }
.site-search { margin: 12px 0 10px; }
.site-search .search-input-wrap input { background: var(--bg-input); }
.site-search:has(.search-table) .search-input-wrap input { border-bottom: none; }
.search-table { background: var(--bg-input); }
.search-table th:nth-child(1), .search-table td:nth-child(1) { width: 20%; }
.search-table th:nth-child(2), .search-table td:nth-child(2) { width: auto; }
.search-table th:nth-child(3), .search-table td:nth-child(3) { width: 14%; }
.search-table th:nth-child(4), .search-table td:nth-child(4) { width: 14%; }
.search-table th:nth-child(5), .search-table td:nth-child(5) { width: 80px; }
.sites-group { font-size: 12px; color: var(--fg-dim); margin: 14px 0 4px; }
.sites-table { table-layout: fixed; }
.sites-table th, .sites-table td { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sites-table th:nth-child(1), .sites-table td:nth-child(1) { width: 19%; }
.sites-table th:nth-child(2), .sites-table td:nth-child(2) { width: 110px; }
.sites-table th:nth-child(4), .sites-table td:nth-child(4) { width: 10%; }
.sites-table th:nth-child(5), .sites-table td:nth-child(5) { width: 165px; }
.sites-table th:nth-child(6), .sites-table td:nth-child(6) { width: 208px; }
.sites-table .actions { flex-wrap: nowrap; }
.sites-table td.site-actions { overflow: visible; }
.chain-table th:nth-child(1), .chain-table td:nth-child(1) { width: 30px; text-align: center; }
.chain-table th:nth-child(2), .chain-table td:nth-child(2) { width: 15%; }
.chain-table th:nth-child(3), .chain-table td:nth-child(3) { width: 90px; }
.chain-table th:nth-child(4), .chain-table td:nth-child(4) { width: auto; }
.chain-table th:nth-child(5), .chain-table td:nth-child(5) { width: 22%; }
.chain-table th:nth-child(6), .chain-table td:nth-child(6) { width: 180px; }
.chain-table .actions button { white-space: nowrap; }

.lookup-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 0 32px; }
.lookup-fields input[type=number] { width: 7ch; }
.lookup-budget-left { color: var(--success); white-space: nowrap; }
.lookup-budget-left.spent { color: var(--warning); }
.chain-cols { display: flex; gap: 12px; }
.chain-col { flex: 1; min-width: 170px; }
.chain-col h4 { margin-bottom: 6px; color: var(--fg-dim); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; }
.chain-col ul { list-style: none; margin: 0; padding: 4px; border: 1px solid var(--border); min-height: 140px; max-height: 320px; overflow-y: auto; }
.chain-col li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0 6px; padding: 2px 6px; border: 1px solid var(--border); margin-bottom: 4px; cursor: grab; background: var(--bg-surface); }
.chain-moves { display: flex; gap: 4px; flex-shrink: 0; }
#chain-on .chain-move[data-move="chain-on"],
#chain-off .chain-move[data-move="up"],
#chain-off .chain-move[data-move="down"],
#chain-off .chain-move[data-move="chain-off"] { display: none; }

#site-edit-dialog { width: 720px; max-width: 94vw; max-height: 88vh; overflow-y: auto; }
#chain-dialog { width: 520px; max-width: 94vw; }
#item-debug-dialog { width: 820px; max-width: 94vw; max-height: 88vh; overflow-y: auto; }
.debug-log-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.debug-log {
  background: var(--bg-input);
  border: 1px solid var(--border);
  padding: 10px 12px;
  max-height: 52vh;
  overflow: auto;
  white-space: pre;
  font-size: 12px;
}

.htmx-indicator { display: none; }
.htmx-request.htmx-indicator,
.htmx-request .htmx-indicator { display: inline; }

.dialog-panel .field > input[type=text], .dialog-panel .field > input[type=password],
.dialog-panel .field > select, .dialog-panel .field > textarea { max-width: none; }
.export-block {
  background: var(--bg-input);
  border: 1px solid var(--border);
  padding: 8px 10px;
  font-size: 12px;
  max-height: 50vh;
  overflow: auto;
  margin: 6px 0 0;
}
.export-block span { display: block; white-space: pre; }
.export-block .exp-add { color: var(--success); }
.export-block .exp-del { color: var(--error); text-decoration: line-through; opacity: 0.75; }
.maprows { display: flex; flex-direction: column; gap: 4px; margin-bottom: 4px; }
.maprow { display: flex; gap: 8px; align-items: center; }
.maprow input, .maprow select { max-width: 240px; }
.maprow .field-hint { white-space: nowrap; }
.maprow-del { color: var(--fg-dim); }
.maprow-del:hover { color: var(--error); }

.site-last { color: var(--fg-dim); font-size: 12px; }

.ptr-shell { padding: 8px 0 32px; }
.ptr-state { text-transform: uppercase; letter-spacing: 1px; font-size: 14px; }
.ptr-state-syncing { color: var(--link); }
.ptr-state-ready { color: var(--success); }
.ptr-state-paused { color: var(--warning); }
.ptr-state-error { color: var(--error); }
.gdl-bar, .ptr-bar { height: 8px; background: var(--bg-input); border: 1px solid var(--border); }
.gdl-bar-fill, .ptr-bar-fill { height: 100%; background: var(--accent); }
.ptr-progress { display: flex; align-items: center; gap: 12px; margin: 8px 0; }
.ptr-progress .ptr-bar { flex: 1; }
.ptr-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0; }
.ptr-line > p { min-width: 0; overflow-wrap: anywhere; }
.ptr-activity { margin: 4px 0 14px; }
.ptr-activity-total { color: var(--fg-dim); font-size: 12px; margin-bottom: 6px; }
.ptr-activity-scroll { overflow-x: auto; }
.ptr-activity-months { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); column-gap: 2px; height: 14px; margin-left: 30px; min-width: 624px; font-size: 10px; color: var(--fg-dim); }
.ptr-activity-months span { grid-row: 1; white-space: nowrap; }
.ptr-activity-body { display: flex; }
.ptr-activity-daylabels { display: grid; grid-template-rows: repeat(7, 1fr); width: 30px; flex-shrink: 0; font-size: 10px; color: var(--fg-dim); }
.ptr-activity-daylabels span { display: flex; align-items: center; }
.ptr-activity-grid { display: grid; grid-template-rows: repeat(7, auto); grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 2px; flex: 1; min-width: 624px; }
.ptr-activity-grid .ptr-day { width: auto; height: auto; aspect-ratio: 1; margin: 0; }
.ptr-day { width: 10px; height: 10px; margin: 1px; background: var(--heat-0); }
.ptr-day-1 { background: var(--heat-1); }
.ptr-day-2 { background: var(--heat-2); }
.ptr-day-3 { background: var(--heat-3); }
.ptr-day-4 { background: var(--heat-4); }
.ptr-activity-legend { display: flex; align-items: center; justify-content: flex-end; gap: 3px; margin-top: 4px; font-size: 10px; color: var(--fg-dim); }
