:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel2: #1e222b;
  --line: #2a2f3a;
  --text: #e6e8ec;
  --muted: #949aa6;
  --accent: #4c8dff;
  --ok: #3fb950;
  --warn: #d29922;
  --err: #f85149;
}

* { box-sizing: border-box; }

/* hidden must always hide. The browser's own [hidden] rule loses to any author
   display rule: .job's display:flex kept the "В очереди…" spinner on every page
   load, and the montage preview once showed both players at the same time. */
[hidden] { display: none !important; }

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

body.centered {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--panel2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* ---------------------------------------------------------------- topbar */

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.nav { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.nav a {
  padding: 6px 12px;
  border-radius: 7px;
  color: var(--muted);
  white-space: nowrap;
}
.nav a:hover { background: var(--panel2); color: var(--text); text-decoration: none; }
.nav a.on { background: var(--accent); color: #fff; }
.brand { font-weight: 700; color: var(--text) !important; letter-spacing: .5px; }

.meters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.meter {
  padding: 4px 10px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.meter.warn { color: var(--warn); border-color: var(--warn); }

.linkbtn {
  background: none;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  padding: 4px 6px;
}
.linkbtn:hover { color: var(--err); }

/* ----------------------------------------------------------------- layout */

main { padding: 16px; max-width: 1500px; margin: 0 auto; }

.cols {
  display: grid;
  grid-template-columns: minmax(340px, 480px) 1fr;
  gap: 16px;
  align-items: start;
}
@media (max-width: 900px) { .cols { grid-template-columns: 1fr; } }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
}
.card.wide { max-width: none; }
.card.login { width: min(380px, 100%); }

h1 { margin: 0 0 4px; font-size: 20px; }
h2 { margin: 20px 0 10px; font-size: 15px; color: var(--muted); font-weight: 600; }
h2:first-child { margin-top: 0; }
.sub { margin: 0 0 16px; color: var(--muted); font-size: 12px; }
.hint { color: var(--muted); font-size: 12px; }

/* ------------------------------------------------------------------ forms */

label { display: block; margin-bottom: 14px; color: var(--muted); font-size: 12px; }

input[type=email], input[type=password], input[type=text], input[type=search], textarea, select {
  width: 100%;
  margin-top: 6px;
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  resize: vertical;
}
textarea:focus, input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=range] { width: 100%; margin-top: 8px; accent-color: var(--accent); }
input[type=file] { margin-top: 6px; color: var(--muted); font-size: 12px; }

.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin: -4px 0 14px;
  font-size: 12px;
  color: var(--muted);
}
.price { color: var(--warn); }
.sliders { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

button.primary {
  width: 100%;
  padding: 11px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  font: 600 14px/1 inherit;
  cursor: pointer;
}
button.primary:hover:not(:disabled) { filter: brightness(1.12); }
button.primary:disabled { opacity: .45; cursor: not-allowed; }

.err { color: var(--err); font-size: 12px; margin: 10px 0 0; }
.error {
  background: rgba(248, 81, 73, .12);
  border: 1px solid var(--err);
  color: var(--err);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  margin: 0 0 14px;
}

/* -------------------------------------------------------------- job state */

.job {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  padding: 12px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
}
.spinner.small { width: 12px; height: 12px; border-width: 2px; }
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

.result { margin-top: 14px; }
.result img, .result video { width: 100%; border-radius: 8px; display: block; }
.result audio { width: 100%; }

/* ------------------------------------------------------------------ tiles */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.list { display: grid; gap: 10px; }

.tile {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;
}
.tile img, .tile video { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; }
.tile .cap {
  margin: 0;
  padding: 6px 8px;
  font-size: 11px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tile.s-failed { border-color: var(--err); }
.tile.s-queued, .tile.s-running { border-color: var(--warn); }

.pickable { cursor: pointer; transition: border-color .12s; }
.pickable:hover { border-color: var(--accent); }
.pickable.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }

.ph {
  display: grid;
  place-items: center;
  aspect-ratio: 16/9;
  color: var(--muted);
  font-size: 11px;
  background: repeating-linear-gradient(45deg, transparent, transparent 8px, rgba(255,255,255,.02) 8px, rgba(255,255,255,.02) 16px);
}
.ph.small { aspect-ratio: auto; padding: 10px; }

.rowitem {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px;
}
.rowitem audio { width: 100%; }
.rowitem .cap { margin: 6px 0 0; font-size: 11px; color: var(--muted); }

.picked { margin-bottom: 12px; }
.picked img { width: 100%; border-radius: 8px; display: block; }
.uploader { padding: 10px; border: 1px dashed var(--line); border-radius: 8px; }

/* ---------------------------------------------------------------- history */

.filters { display: flex; gap: 8px; margin-bottom: 14px; }
.filters select { width: auto; margin-top: 0; }

.hist { width: 100%; border-collapse: collapse; font-size: 13px; }
.hist th {
  text-align: left;
  padding: 8px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .4px;
  border-bottom: 1px solid var(--line);
}
.hist td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.hist tr.s-failed { background: rgba(248, 81, 73, .05); }
.nowrap { white-space: nowrap; color: var(--muted); font-size: 12px; }

.params { max-width: 520px; }
.prompt {
  white-space: pre-wrap;
  max-height: 4.5em;
  overflow: hidden;
  word-break: break-word;
}
.meta { color: var(--muted); font-size: 11px; margin-top: 4px; }
.meta.err { color: var(--err); }

/* A failure, explained. The raw provider text is still there - folded away,
   because the first thing an operator needs is what to do, not a JSON dump. */
.diag {
  border-left: 2px solid var(--err);
  margin-top: 6px;
  padding-left: 8px;
}
.diag-head { align-items: center; display: flex; flex-wrap: wrap; gap: 6px; }
.diag-title { color: var(--err); font-size: 12px; font-weight: 600; }
.diag-tries {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 10px;
  padding: 1px 6px;
}
.diag-hint { color: var(--muted); font-size: 11px; margin-top: 3px; }
.raw {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 11px;
  margin: 6px 0 0;
  max-height: 220px;
  overflow: auto;
  padding: 8px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* What can be done about it, in the cell where a finished row shows its file. */
.acts { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.act {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  display: inline-block;
  font: inherit;
  font-size: 11px;
  padding: 5px 9px;
  text-align: left;
  text-decoration: none;
  white-space: nowrap;
}
.act:hover { border-color: var(--accent); text-decoration: none; }
/* The free move on a task that may already be paid for - so it leads. */
.act.lead { border-color: var(--accent); color: var(--accent); }
/* A retry the provider has already refused once: offered, but not invitingly. */
.act.risky { color: var(--muted); }
.act[disabled] { cursor: default; opacity: .5; }
.act.ok { border-color: var(--ok); color: var(--ok); }

/* The same explanation inside the preview modal, where the raw error is shown. */
.modal-diag {
  border-left: 2px solid var(--err);
  margin: 0 0 6px;
  padding-left: 8px;
}

.thumb { width: 160px; border-radius: 6px; display: block; }
.hist audio { width: 200px; }

.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .3px;
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--muted);
  margin-right: 3px;
}
.b-done { color: var(--ok); border-color: var(--ok); }
.b-failed { color: var(--err); border-color: var(--err); }
.b-queued, .b-running { color: var(--warn); border-color: var(--warn); }
.b-image { color: #a371f7; border-color: #a371f7; }
.b-video { color: #4c8dff; border-color: #4c8dff; }
.b-voice { color: #2dd4bf; border-color: #2dd4bf; }

.pager { display: flex; gap: 14px; align-items: center; justify-content: center; margin-top: 16px; color: var(--muted); }

/* ------------------------------------------------- notifications & activity */

.bell {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 5px 7px;
}
.bell:hover { border-color: var(--accent); }
.bell.off { filter: grayscale(1); opacity: .6; }

/* Sits between the header and the page, so it is visible wherever you navigate -
   the point being that a running job is never out of sight. */
.activity {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 8px 16px;
}
.act-head {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .4px;
  margin-bottom: 6px;
  text-transform: uppercase;
}
.act-row {
  align-items: center;
  display: flex;
  font-size: 12px;
  gap: 8px;
  padding: 3px 0;
}
.act-row .dot {
  background: var(--warn);
  border-radius: 50%;
  flex: none;
  height: 8px;
  width: 8px;
}
.act-kind { color: var(--muted); flex: none; width: 70px; }
.act-cap {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.act-status { color: var(--muted); flex: none; }
.act-row.mine .act-cap { color: var(--text); }
.act-row.mine .act-kind { color: var(--accent); }

.toasts {
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: fixed;
  right: 16px;
  z-index: 50;
}
.toast {
  animation: toastin .25s ease-out;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--ok);
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .45);
  cursor: pointer;
  max-width: 340px;
  padding: 10px 14px;
}
.toast strong { display: block; font-size: 13px; }
.toast span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.toast.t-failed { border-left-color: var(--err); }
.toast.out { opacity: 0; transition: opacity .3s; }
@keyframes toastin { from { opacity: 0; transform: translateX(16px); } }

/* ------------------------------------------------------- preview & prompts */

.openable { cursor: zoom-in; }
.tile.openable img, .tile.openable video { transition: opacity .12s; }
.tile.openable:hover img, .tile.openable:hover video { opacity: .82; }

body.modal-open { overflow: hidden; }

.modal { position: fixed; inset: 0; z-index: 60; }
.modal-back { position: absolute; inset: 0; background: rgba(0, 0, 0, .72); }
.modal-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  display: flex;
  gap: 0;
  left: 50%;
  max-height: 90vh;
  max-width: min(1200px, 94vw);
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: max-content;
}
.modal-card.loading {
  align-items: center;
  justify-content: center;
  min-height: 160px;
  min-width: 220px;
}
.modal-x {
  background: rgba(0, 0, 0, .55);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 3px 9px 5px;
  position: absolute;
  right: 8px;
  top: 8px;
  z-index: 2;
}
.modal-x:hover { border-color: var(--accent); }

.modal-media {
  align-items: center;
  background: #000;
  border-radius: 10px 0 0 10px;
  display: flex;
  justify-content: center;
  min-width: 0;
  overflow: hidden;
}
.modal-media img, .modal-media video {
  display: block;
  max-height: 88vh;
  max-width: 100%;
  object-fit: contain;
}
.modal-media audio { margin: 40px 24px; width: 320px; }
.modal-media .ph { aspect-ratio: auto; margin: 60px 40px; }

.modal-side {
  display: flex;
  flex-direction: column;
  flex: none;
  overflow-y: auto;
  padding: 16px;
  width: 340px;
}
.modal-badges { align-items: center; display: flex; gap: 4px; margin-bottom: 10px; }
.modal-id { color: var(--muted); font-size: 11px; margin-left: auto; }
.modal-facts {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.7;
  margin-bottom: 14px;
}
.modal-label {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .4px;
  margin-bottom: 5px;
  text-transform: uppercase;
}
/* The whole point of the window: the prompt in full, scrollable and selectable. */
.modal-prompt {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 12.5px;
  line-height: 1.55;
  max-height: 40vh;
  overflow-y: auto;
  padding: 10px;
  user-select: text;
  white-space: pre-wrap;
  word-break: break-word;
}
.modal-error {
  color: var(--err);
  font-size: 12px;
  margin-bottom: 10px;
  white-space: pre-wrap;
  word-break: break-word;
}
.modal-src { color: var(--muted); font-size: 11px; margin-top: 10px; }
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.btnlike, .copyprompt.wide {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  display: inline-block;
  font: inherit;
  font-size: 12px;
  padding: 7px 12px;
  text-decoration: none;
}
.btnlike:hover, .copyprompt.wide:hover {
  border-color: var(--accent);
  text-decoration: none;
}
.copyprompt.ok { border-color: var(--ok); color: var(--ok); }

.linklike {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  padding: 0;
}

/* Small copy button that sits in a history row. */
.copyprompt {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
  float: right;
  font-size: 11px;
  line-height: 1;
  margin-left: 6px;
  padding: 3px 6px;
}
.copyprompt:hover { border-color: var(--accent); color: var(--text); }

.peek {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  font-size: 11px;
  padding: 0;
}
.peek:hover { text-decoration: underline; }
.tile .peek {
  background: rgba(0, 0, 0, .6);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text);
  padding: 2px 6px;
  position: absolute;
  right: 5px;
  top: 5px;
}
.tile { position: relative; }

/* A clamped prompt used to just stop mid-sentence with nothing to say so. */
.prompt.clamped {
  -webkit-mask-image: linear-gradient(180deg, #000 60%, transparent 100%);
  mask-image: linear-gradient(180deg, #000 60%, transparent 100%);
}
.prompt.open { max-height: none; }
.expand {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  font-size: 11px;
  margin-top: 2px;
  padding: 0;
}
.expand:hover { text-decoration: underline; }

@media (max-width: 900px) {
  .modal-card { flex-direction: column; max-width: 96vw; width: 96vw; }
  .modal-media { border-radius: 10px 10px 0 0; }
  .modal-media img, .modal-media video { max-height: 45vh; }
  .modal-side { width: auto; }
}

/* --------------------------------------------------------- quality picker */

.field { margin-bottom: 14px; }
.fieldlabel {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-bottom: 6px;
}
.seg { display: flex; gap: 6px; }
.segopt { cursor: pointer; margin: 0; }
.segopt input { position: absolute; opacity: 0; pointer-events: none; }
.segopt span {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  display: block;
  font-size: 12px;
  padding: 6px 14px;
  transition: border-color .12s, color .12s;
}
.segopt:hover span { border-color: var(--accent); }
.segopt input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.segopt input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* A service whose key is missing. Shown and struck out rather than hidden: an
   absent option reads as "never built", a disabled one as "go configure it". */
.segopt.off { cursor: not-allowed; }
.segopt.off span { opacity: .45; }
.segopt.off:hover span { border-color: var(--line); }

/* ---------------------------------------------------------- voice library */

/* .modal-card is a side-by-side flex row built for the preview; the library is
   a column of its own that scrolls. */
.modal-card.vlib {
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  padding: 18px;
  width: min(860px, 94vw);
}
.modal-card.vlib h2 { font-size: 16px; margin: 0; padding-right: 32px; }
.modal-card.vlib .hint { margin: 0; }

.vlib-filters { display: flex; flex-wrap: wrap; gap: 6px; }
.vlib-filters input, .vlib-filters select { margin-top: 0; width: auto; }
.vlib-filters input[type=search] { flex: 1 1 200px; }
.vlib-filters button { margin-top: 0; width: auto; }

.vlib-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}
.vlib-card {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
}
.vlib-name { font-size: 13px; font-weight: 600; }
.vlib-meta { color: var(--muted); font-size: 11px; }
.vlib-card audio { width: 100%; }
.vlib-card .vlib-add { font-size: 12px; margin-top: auto; padding: 6px 10px; width: 100%; }
.vlib-more { margin: 0 auto; width: auto; }

/* An extra per-character charge our estimate cannot see. */
.badge.b-rate { align-self: flex-start; background: #7a4a0f; color: #ffd8a8; }

@media (max-width: 900px) {
  .modal-card.vlib { max-height: 92vh; width: 96vw; }
}

/* -------------------------------------------------------------- montage */

.track { margin-bottom: 12px; }
.lane {
  align-items: stretch;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 2px;
  min-height: 46px;
  overflow: hidden;
  padding: 3px;
}
.lane .ph { align-self: center; margin: 0 auto; }

/* flex-grow carries the timeline share, so the strip is a real proportion of
   the result rather than a row of equal boxes. */
.piece {
  align-items: center;
  background: var(--accent);
  border-radius: 5px;
  color: #fff;
  cursor: grab;
  display: flex;
  flex-basis: 0;
  font-size: 11px;
  gap: 4px;
  justify-content: space-between;
  min-width: 64px;
  overflow: hidden;
  padding: 4px 6px;
  user-select: none;
  white-space: nowrap;
}
.piece.audio { background: #2f6f4f; cursor: default; }
.piece.dragging { opacity: .45; }
.piece.dragover { outline: 2px dashed #fff; outline-offset: -3px; }
.piece-name { overflow: hidden; text-overflow: ellipsis; }
.piece-tools { display: flex; flex: none; gap: 2px; }
.piece-tools button {
  background: rgba(0, 0, 0, .28);
  border: none;
  border-radius: 3px;
  color: #fff;
  cursor: pointer;
  font: inherit;
  line-height: 1;
  margin: 0;
  padding: 2px 4px;
  width: auto;
}
.piece-tools button:hover { background: rgba(0, 0, 0, .55); }

.audiopick { cursor: pointer; }
.audiopick.sel { outline: 2px solid var(--accent); outline-offset: 2px; }

.preview { border: 1px solid var(--line); border-radius: 8px; margin: 10px 0; padding: 8px; }
/* Fixed box so swapping players does not make the page jump, and the two
   <video> elements sit on top of each other rather than stacking. */
.preview .stage {
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}
.preview video {
  display: block;
  height: 100%;
  left: 0;
  object-fit: contain;
  position: absolute;
  top: 0;
  width: 100%;
}
.preview audio { display: none; }

.badge.b-montage { background: #4a3f7a; color: #d9d2ff; }

/* ------------------------------------------------------------------- tags */

/* One pill for a tag everywhere. The colour is its group's, handed in as --tag,
   so a Geo tag reads as Geo on every page without a legend. */
.tag {
  --tag: #8b949e;
  align-items: center;
  background: color-mix(in srgb, var(--tag) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--tag) 75%, transparent);
  border-radius: 999px;
  color: var(--text);
  display: inline-flex;
  font-size: 11px;
  gap: 4px;
  line-height: 18px;
  padding: 0 8px;
  white-space: nowrap;
}
.tag-x {
  background: none;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  line-height: 1;
  margin-right: -3px;
  padding: 0;
}
.tag-x:hover { color: var(--err); }

.taglist, .tagline { align-items: center; display: flex; flex-wrap: wrap; gap: 4px; }
.taglist { margin-top: 6px; }
.tag-add {
  background: none;
  border: 1px dashed var(--line);
  border-radius: 999px;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 11px;
  line-height: 18px;
  padding: 0 8px;
}
.tag-add:hover { border-color: var(--accent); color: var(--text); text-decoration: none; }

/* The list under a picker. It unfolds in place rather than floating: the
   preview's side panel scrolls, and would clip anything drawn over it. */
.tagpop {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
  padding: 8px;
}
.tagpop input[type=search] { margin-top: 0; padding: 6px 8px; }
.tagpop .hint { margin: 0; }
.tagpop-list { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
.tagpop-title { font-size: 13px; font-weight: 600; }
.tagpop-foot { font-size: 11px; }
.tagpop-actions { align-items: center; display: flex; gap: 12px; justify-content: space-between; }
.tagpop-actions .linklike { font-size: 12px; }
.tagpop-actions .primary { font-size: 13px; padding: 8px 16px; width: auto; }

.tagsec { align-items: baseline; display: flex; gap: 8px; }
.tagsec-name {
  color: var(--muted);
  flex: none;
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 76px;
}
.tagsec-opts { display: flex; flex-wrap: wrap; gap: 4px; min-width: 0; }

/* A tag as a checkbox: faint until chosen, filled and ticked once it is. */
.tagchk { cursor: pointer; display: inline-block; margin: 0; }
.tagchk input { opacity: 0; pointer-events: none; position: absolute; }
.tagchk .tag { opacity: .55; transition: opacity .12s; }
.tagchk:hover .tag { opacity: .85; }
.tagchk input:checked + .tag {
  background: color-mix(in srgb, var(--tag) 42%, transparent);
  opacity: 1;
}
.tagchk input:checked + .tag::before { content: '✓'; }
.tagchk input:focus-visible + .tag { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Tagging without leaving the list. Sits opposite .peek in the tile's other
   corner, and lights up once the file carries tags, so an unmarked file is
   visible at a glance. */
.tagbtn {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 11px;
  line-height: 1;
  padding: 3px 6px;
  white-space: nowrap;
}
.tagbtn:hover { border-color: var(--accent); }
.tagbtn.on { border-color: var(--accent); color: var(--accent); }
.tagbtn-n { font-size: 10px; margin-left: 3px; }
.tile .tagbtn { background: rgba(0, 0, 0, .6); left: 5px; position: absolute; top: 5px; }
.rowacts { align-items: center; display: flex; gap: 10px; margin-top: 6px; }
.taglist .tagbtn { flex: none; }

/* In <body>, not in the tile: .tile hides its overflow and would cut it off.
   Absolute, so it travels with the page rather than the viewport. */
.tagquick {
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
  margin-top: 0;
  max-width: calc(100vw - 16px);
  position: absolute;
  width: 320px;
  z-index: 40;
}

.modal-tags-label { margin-top: 12px; }
.tagsaved { color: var(--ok); letter-spacing: 0; margin-left: 6px; text-transform: none; }

/* The switch in the header. Lit up while a filter is on, because a filter nobody
   notices is how files seem to vanish. */
.tagfilter-wrap { align-items: center; display: flex; margin-left: 8px; position: relative; }
.tagfilter {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  max-width: 280px;
  overflow: hidden;
  padding: 4px 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tagfilter:hover { border-color: var(--accent); color: var(--text); }
.tagfilter.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.tagfilter.on:has(+ .tagfilter-x) { border-radius: 999px 0 0 999px; }
.tagfilter-x {
  background: var(--accent);
  border: 1px solid var(--accent);
  border-left-color: rgba(255, 255, 255, .35);
  border-radius: 0 999px 999px 0;
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  line-height: 1;
  padding: 4px 9px 5px 7px;
}
.tagfilter-x:hover { filter: brightness(1.15); }
.tagpop.tagpop-float {
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
  left: 0;
  margin-top: 0;
  padding: 12px;
  position: absolute;
  top: calc(100% + 8px);
  width: min(440px, 92vw);
  z-index: 30;
}

.filternote { color: var(--accent); font-size: 12px; font-weight: 400; }

/* The header list lives inside <nav>, whose link rule would pad and grey it. */
.nav .tagpop a { border-radius: 0; color: var(--accent); padding: 0; white-space: normal; }
.nav .tagpop a:hover { background: none; text-decoration: underline; }

/* A hint inside a tile grid spans the row instead of squeezing into one cell. */
.grid > .hint { grid-column: 1 / -1; margin: 0; }

/* ---- /tags */

.tagsadmin { margin: 0 auto; max-width: 920px; }
.tagsadmin .sub { max-width: 680px; }
.tnew, .trow-edit { align-items: center; display: flex; flex-wrap: wrap; gap: 6px; }
.tnew input[type=text], .trow-edit input[type=text] { flex: 1 1 200px; margin-top: 0; padding: 7px 10px; width: auto; }
.trow-edit select { margin-top: 0; padding: 7px 10px; width: auto; }
.tnew-group { margin-bottom: 8px; }

.swatches { display: flex; gap: 4px; }
.swatch { cursor: pointer; margin: 0; }
.swatch input { opacity: 0; pointer-events: none; position: absolute; }
.swatch span {
  background: var(--tag);
  border: 2px solid transparent;
  border-radius: 50%;
  display: block;
  height: 22px;
  width: 22px;
}
.swatch input:checked + span { border-color: #fff; }
.swatch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.tgroup { border-top: 1px solid var(--line); padding: 14px 0 6px; }
.tgroup-view, .trow-view { align-items: center; display: flex; flex-wrap: wrap; gap: 10px; }
.tgroup-view h2 { color: var(--text); font-size: 15px; margin: 0; }
.tgroup-dot { background: var(--tag); border-radius: 50%; flex: none; height: 10px; width: 10px; }
.trow-acts { display: flex; font-size: 12px; gap: 14px; margin-left: auto; }
.trow-acts .linklike { font-size: 12px; }
.linklike.danger { color: var(--muted); }
.linklike.danger:hover { color: var(--err); }
.tlist { margin: 6px 0 8px 20px; }
.trow { border-bottom: 1px dashed var(--line); padding: 6px 0; }
.tcount { color: var(--muted); font-size: 12px; }
a.tcount:hover { color: var(--accent); }
.tgroup .tnew { margin-left: 20px; }
