:root {
  --bg: #0d1014;
  --panel: #151a21;
  --panel-2: #1b222b;
  --line: #2a3441;
  --text: #e6ebf2;
  --muted: #8b98a9;
  --accent: #63c7a8;
  --accent-2: #4a9bff;
  --warn: #e0a94a;
  --bad: #e06464;
  --ok: #54c08a;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
h1, h2, h3 { line-height: 1.2; }
h1 { font-size: 24px; margin: 0 0 6px; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 16px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
pre { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; white-space: pre-wrap; word-break: break-word; margin: 0 0 8px; }
code { background: var(--panel-2); border-radius: 4px; padding: 1px 5px; font-size: .92em; }
pre code { background: none; padding: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  padding: 14px 22px; border-bottom: 1px solid var(--line); background: #10151b;
  position: sticky; top: 0; z-index: 5; flex-wrap: wrap;
}
.brand a { color: var(--text); font-weight: 700; letter-spacing: .01em; }
.brand span { color: var(--muted); font-size: 12px; margin-left: 8px; text-transform: uppercase; letter-spacing: .12em; }
.topbar nav { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.topbar nav a { color: var(--muted); }
.topbar nav a:hover { color: var(--text); }
.inline { display: inline; }
button.link { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; padding: 0; }
button.link:hover { color: var(--text); text-decoration: underline; }

.stats { display: flex; gap: 10px; flex-wrap: wrap; padding: 16px 22px 0; }
.stats div { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; color: var(--muted); font-size: 13px; }
.stats span { color: var(--text); font-weight: 700; margin-right: 4px; }

main { padding: 18px 22px 40px; max-width: 1400px; margin: 0 auto; }
footer { color: #5d6a7a; font-size: 12px; text-align: center; padding: 20px; }

.filters { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; margin-bottom: 18px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
input[type=text], input[type=password], input[type=number], select, textarea {
  background: #0f141a; color: var(--text); border: 1px solid var(--line); border-radius: 7px;
  padding: 9px 10px; font: inherit; width: 100%;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(74, 155, 255, .35); border-color: var(--accent-2); }
button, .button {
  display: inline-block; background: var(--accent); color: #08110d; border: 0; border-radius: 7px;
  padding: 9px 16px; font: inherit; font-weight: 650; cursor: pointer; text-decoration: none;
}
button:hover, .button:hover { filter: brightness(1.07); text-decoration: none; }
button.secondary, .button.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
button.danger { background: var(--bad); color: #180808; }

.flash { padding: 11px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); margin: 0 0 16px; }
.flash.error { border-color: #613030; background: #26171a; color: #ffb9b9; }
.flash.success { border-color: #2c5944; background: #14251d; color: #b8f3d6; }
.flash.warning { border-color: #5c4a25; background: #241f15; color: #f0d39a; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.card .thumb { display: block; aspect-ratio: 4 / 3; background: #0b0f13; overflow: hidden; }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.placeholder { display: flex; height: 100%; align-items: center; justify-content: center; color: #3f4a58; text-transform: uppercase; letter-spacing: .2em; font-size: 12px; }
.card-body { padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-weight: 600; }
.card-title a { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prompt-preview { margin: 0; color: #aab6c5; font-size: 13px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { display: inline-block; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; padding: 2px 7px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge.ok { color: #9ff0c8; border-color: #2c5944; background: #14251d; }
.badge.bad { color: #ffb0b0; border-color: #613030; background: #26171a; }
.badge.busy { color: #bcd9ff; border-color: #2f4c74; background: #142033; }
.badge.warn { color: #f0d39a; border-color: #5c4a25; background: #241f15; }
.error-text { color: #f2a3a3; font-size: 12px; }

.empty { background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); padding: 28px; text-align: center; color: var(--muted); }
.pager { display: flex; gap: 6px; margin-top: 20px; }
.pager a { padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); }
.pager a.current { background: var(--panel-2); color: var(--text); }

.detail-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.breadcrumb { margin: 0 0 10px; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, 1fr); gap: 16px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; min-width: 0; }
.composed { border-color: #2f4c74; background: #111b28; }
.meta { display: grid; grid-template-columns: 100px 1fr; gap: 6px 12px; margin: 0; font-size: 13px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; overflow-wrap: anywhere; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.gallery figure { margin: 0; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.gallery img { width: 100%; display: block; aspect-ratio: 1; object-fit: cover; }
.gallery figcaption { padding: 8px 10px; overflow: hidden; }
.actions-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; align-items: start; }
.panel.action.danger { border-color: #4a2626; }

.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }
/* Settings tabs. Without JavaScript the bar is a row of in-page links and
   every panel stays stacked; tabs.js hides the inactive panels. The hidden
   rule must stay stronger than any display rule on a panel. */
.tabs {
  display: flex; flex-wrap: wrap; gap: 4px; margin: 0 0 14px; border-bottom: 1px solid var(--line);
  scroll-margin-top: 60px;
}
.tabs a {
  padding: 8px 14px; margin-bottom: -1px; color: var(--muted);
  border: 1px solid transparent; border-bottom: 0; border-radius: 8px 8px 0 0;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a[aria-selected="true"] { color: var(--text); background: var(--panel); border-color: var(--line); font-weight: 600; }
[data-tab-panel][hidden] { display: none; }
[data-tab-panel], #prompt-files { scroll-margin-top: 60px; }

.prompt-files td:first-child { word-break: break-all; }
.prompt-file-start { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 14px 0 0; }
.prompt-editor { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.prompt-editor h3 { color: var(--text); text-transform: none; letter-spacing: 0; font-size: 15px; margin: 0 0 10px; }
.editor-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.editor-head h3 { margin: 0; }
.prompt-editor textarea { min-height: 220px; }
@media (max-width: 600px) {
  .prompt-files .col-modified { display: none; }
}
.settings-field { margin-bottom: 18px; }
.settings-field > label { font-weight: 600; color: var(--text); }
.settings-field textarea { min-height: 90px; }
label.checkbox { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
label.checkbox input { width: auto; }
.body-parts { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.body-part { background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; padding: 14px; min-width: 0; }
.body-part header { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.body-part h3 { margin: 0; color: var(--text); text-transform: none; letter-spacing: 0; font-size: 15px; }
.body-part header p { margin: 2px 0 0; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.thumbs img { width: 76px; height: 76px; object-fit: cover; display: block; border: 1px solid var(--line); border-radius: 6px; background: #0b0f13; }
.body-part .thumb { position: relative; width: 76px; }
.body-part .thumb-action {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 3px 2px; border-radius: 0 0 6px 6px;
  font-size: 10px; font-weight: 600; line-height: 1.3; background: rgba(13, 16, 20, .82);
  color: var(--text); border: 0; opacity: 0; transition: opacity .12s ease;
}
.body-part .thumb:hover .thumb-action, .body-part .thumb:focus-within .thumb-action { opacity: 1; }
@media (hover: none), (pointer: coarse) {
  .body-part .thumb-action { opacity: 1; }
}
.body-part-upload { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 6px; }
.body-part-upload input[type=file] { flex: 1 1 170px; min-width: 0; font-size: 12px; color: var(--muted); }
.body-part-upload input[type=file]::file-selector-button {
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 10px; margin-right: 8px; font: inherit; font-size: 12px; cursor: pointer;
}
.js .body-part-upload button[type=submit] { display: none; }
.upload-hint { margin: 0 0 12px; }

.crop-dialog {
  width: min(940px, calc(100vw - 28px)); max-height: calc(100vh - 28px); padding: 0; overflow: auto;
  color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
}
.crop-dialog::backdrop { background: rgba(0, 0, 0, .62); }
.crop-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 18px; border-bottom: 1px solid var(--line); }
.crop-head h2 { margin: 0; }
.crop-close { background: none; border: 0; color: var(--muted); font-size: 26px; line-height: 1; padding: 0 4px; cursor: pointer; }
.crop-close:hover { color: var(--text); }
.crop-stage { display: flex; align-items: center; justify-content: center; padding: 14px; background: #0b0f13; min-height: 220px; }
.crop-wrap { position: relative; overflow: hidden; touch-action: none; user-select: none; }
.crop-wrap canvas { display: block; }
.crop-box {
  position: absolute; border: 1px solid #fff; cursor: move; outline: none;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .56);
}
.crop-box:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 9999px rgba(0, 0, 0, .56), 0 0 0 2px var(--accent); }
.crop-handle { position: absolute; width: 14px; height: 14px; background: #fff; border: 1px solid #0b0f13; border-radius: 3px; }
.crop-handle[data-handle=nw] { left: -7px; top: -7px; cursor: nwse-resize; }
.crop-handle[data-handle=n] { left: calc(50% - 7px); top: -7px; cursor: ns-resize; }
.crop-handle[data-handle=ne] { right: -7px; top: -7px; cursor: nesw-resize; }
.crop-handle[data-handle=e] { right: -7px; top: calc(50% - 7px); cursor: ew-resize; }
.crop-handle[data-handle=se] { right: -7px; bottom: -7px; cursor: nwse-resize; }
.crop-handle[data-handle=s] { left: calc(50% - 7px); bottom: -7px; cursor: ns-resize; }
.crop-handle[data-handle=sw] { left: -7px; bottom: -7px; cursor: nesw-resize; }
.crop-handle[data-handle=w] { left: -7px; top: calc(50% - 7px); cursor: ew-resize; }
.crop-box.aspect-locked .crop-handle[data-handle=n],
.crop-box.aspect-locked .crop-handle[data-handle=e],
.crop-box.aspect-locked .crop-handle[data-handle=s],
.crop-box.aspect-locked .crop-handle[data-handle=w] { display: none; }
.crop-controls { display: flex; flex-wrap: wrap; gap: 0 14px; padding: 14px 18px 0; }
.crop-controls label { flex: 1 1 150px; margin-bottom: 10px; }
#crop-size-info { margin: 0; padding: 0 18px 4px; }
#crop-error { margin: 8px 18px 0; }
.crop-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 18px 18px; }

.lora-picker { margin: 6px 0 4px; }
.lora-picker select[multiple] {
  width: 100%; font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 6px;
}
/* Two body-part selects with their live status lines (bodypart.js). */
.bodypart-pair { margin: 2px 0 6px; }
.bodypart-pair [data-bodypart-status] { margin: 2px 0 10px; }
.lora-weights { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.lora-weight-row { display: flex; align-items: center; gap: 8px; }
.lora-weight-name {
  flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--muted);
  padding: 4px 8px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
}
.lora-weight-row input[type=number] { width: 90px; }
.lora-list { margin: 0 0 6px; padding-left: 18px; }
.lora-list li { margin-bottom: 2px; word-break: break-all; }

#submit-progress ul { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.submit-row { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
.submit-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 13px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.submit-status { flex: 0 0 auto; font-size: 12px; color: var(--muted); }
.submit-row[data-status=uploading] .submit-status { color: var(--warn); }
.submit-row[data-status=ok] { border-color: var(--ok); }
.submit-row[data-status=ok] .submit-status { color: var(--ok); }
.submit-row[data-status=error] { border-color: var(--bad); }
.submit-row[data-status=error] .submit-status { color: var(--bad); word-break: break-word; }

.dir-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.stage-toggle { display: flex; flex-wrap: wrap; gap: 18px; margin-bottom: 10px; }
.stage-toggle .radio, label.radio { display: inline-flex; align-items: center; gap: 6px; }
/* The ID display rules must never beat the hidden attribute, or the JS
   stage toggle silently stops working. */
#single-options, #multi-options { border-top: 1px solid var(--line); margin-top: 10px; padding-top: 10px; display: flex; flex-direction: column; gap: 8px; }
#single-options h3, #multi-options h3 { margin: 0; }
#single-options[hidden], #multi-options[hidden] { display: none; }
.dir-card { display: flex; gap: 10px; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.dir-card .thumb { flex: 0 0 84px; align-self: stretch; display: block; background: #0b0f13; }
.dir-card .thumb img { width: 84px; height: 100%; min-height: 84px; object-fit: cover; display: block; }
.dir-card .placeholder { display: flex; align-items: center; justify-content: center; height: 84px; color: var(--muted); font-size: 11px; }
.dir-card .card-body { flex: 1 1 auto; min-width: 0; padding: 8px 10px; }
.dir-card .card-title { word-break: break-word; margin-bottom: 2px; }
button.small { padding: 4px 10px; font-size: 12px; }
.breadcrumb strong { word-break: break-all; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.prompt-cell { max-width: 420px; overflow-wrap: anywhere; color: #b9c5d4; }

/* Queue page */
.queue-number { white-space: nowrap; }
.queue-inputs, .queue-lora-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.queue-inputs li, .queue-lora-list li { word-break: break-all; }
.queue-prompt { max-height: 8rem; overflow-y: auto; white-space: pre-wrap; color: #b9c5d4; }
.queue-loras { margin-top: 6px; }
button.queue-cancel { padding: 2px 9px; font-size: 13px; line-height: 1.4; }

/* Logs page */
.log-controls input[type=number] { width: 110px; }
.log-presets { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.log-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.log-head h2 { margin: 0 0 4px; }
.log-meta { margin: 0; word-break: break-all; }
.log-output {
  max-height: 70vh; overflow-y: auto; margin: 0;
  font-size: 12.5px; line-height: 1.45;
  white-space: pre-wrap; word-break: break-word;
}

.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 26px; }
.login h1 { font-size: 22px; }
.login button { width: 100%; margin-top: 4px; }

@media (max-width: 800px) {
  .detail-grid { grid-template-columns: 1fr; }
  main { padding: 14px; }
}
