:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1d1f23;
  --muted: #6b6f76;
  --line: #e2e0da;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --warn: #b5541c;
  --danger: #c0392b;
  --ok: #2e7d4f;
  --radius: 12px;

  /* one color per file category, used in bars, dots and badges */
  --cat-video: #1f6feb;
  --cat-audio: #8e44ad;
  --cat-subtitle: #16a085;
  --cat-image: #e8a33d;
  --cat-metadata: #95a5a6;
  --cat-disc_image: #c0392b;
  --cat-disc_structure: #e67e22;
  --cat-archive: #6d4c41;
  --cat-document: #2e7d4f;
  --cat-system: #7f8c8d;
  --cat-other: #bdc3c7;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --surface: #202328;
    --text: #eceef1;
    --muted: #9aa0a8;
    --line: #30343b;
    --accent: #4c8dff;
    --accent-text: #0d1117;
    --warn: #f0a35e;
    --cat-video: #4c8dff;
    --cat-metadata: #7f8c8d;
    --cat-other: #5d6670;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* --- header --- */

header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

nav {
  display: flex;
  gap: 4px;
  overflow-x: auto;
}

nav a {
  padding: 6px 10px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
}

nav a[aria-current="page"] {
  color: var(--text);
  background: var(--bg);
  font-weight: 600;
}

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

main[aria-busy="true"] {
  opacity: 0.6;
}

h1 {
  font-size: 1.5rem;
  margin: 8px 0 12px;
}

h1.path {
  overflow-wrap: anywhere;
}

h2 {
  font-size: 0.85rem;
  font-weight: 600;
  margin: 28px 0 8px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

a {
  color: var(--accent);
}

code,
pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.85rem;
}

.warn {
  color: var(--warn);
}

.crumbs {
  margin: 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 0 0 12px;
}

/* --- volumes --- */

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

.card.volume {
  color: inherit;
  text-decoration: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
}

.card.volume:hover {
  border-color: var(--accent);
}

.volume-head,
.volume-stats {
  display: flex;
  gap: 12px;
  align-items: baseline;
  flex-wrap: wrap;
}

.volume-head strong {
  font-size: 1.1rem;
}

.bar {
  display: flex;
  height: 10px;
  border-radius: 5px;
  overflow: hidden;
  background: var(--line);
}

.seg {
  display: block;
  min-width: 2px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin-top: 20px;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: -1px;
}

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.8rem;
  color: #fff;
  white-space: nowrap;
}

.cat-video { background: var(--cat-video); }
.cat-audio { background: var(--cat-audio); }
.cat-subtitle { background: var(--cat-subtitle); }
.cat-image { background: var(--cat-image); }
.cat-metadata { background: var(--cat-metadata); }
.cat-disc_image { background: var(--cat-disc_image); }
.cat-disc_structure { background: var(--cat-disc_structure); }
.cat-archive { background: var(--cat-archive); }
.cat-document { background: var(--cat-document); }
.cat-system { background: var(--cat-system); }
.cat-other { background: var(--cat-other); color: var(--text); }

/* --- facts --- */

.facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 16px;
  margin: 0 0 16px;
}

.facts dt {
  color: var(--muted);
}

.facts dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.hash {
  word-break: break-all;
}

details.raw summary {
  cursor: pointer;
  color: var(--accent);
  margin: 16px 0 8px;
}

details.raw pre {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  overflow: auto;
  max-height: 480px;
}

/* --- tables --- */

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

tbody tr:last-child td {
  border-bottom: none;
}

th.num,
td.num {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

table.files td:first-child {
  min-width: 280px;
}

tr.missing td {
  opacity: 0.55;
}

.path {
  overflow-wrap: anywhere;
}

a.path {
  color: var(--text);
  text-decoration: none;
}

a.path:hover {
  color: var(--accent);
  text-decoration: underline;
}

.pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 12px 0;
}

/* --- duplicates --- */

.group-head {
  display: flex;
  gap: 16px;
  align-items: baseline;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.group-head a {
  margin-left: auto;
}

ul.plain {
  list-style: none;
  margin: 0;
  padding: 0;
}

ul.plain li {
  padding: 3px 0;
}

/* --- forms --- */

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  min-height: 38px;
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

button.ghost {
  background: transparent;
  border-color: transparent;
}

button.danger {
  color: var(--danger);
}

input[type="text"],
input[type="url"],
input[type="password"],
select {
  width: 100%;
  min-height: 38px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
}

input:focus-visible,
select:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.label {
  font-size: 0.8rem;
  color: var(--muted);
}

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
  align-items: end;
}

.inline {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
}

.filter-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.settings {
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* --- toast --- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 40px);
  opacity: 0;
  pointer-events: none;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  transition: opacity 0.2s, transform 0.2s;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.error {
  background: var(--danger);
  color: #fff;
}

.toast.ok {
  background: var(--ok);
  color: #fff;
}

@media (max-width: 600px) {
  header {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .facts {
    grid-template-columns: 1fr;
    gap: 0 0;
  }

  .facts dd {
    margin-bottom: 8px;
  }

  table.files td:first-child {
    min-width: 200px;
  }
}
