:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #1b2430;
  --muted: #5d6b7a;
  --line: #dde3ea;
  --brand: #0f5e9c;
  --brand-ink: #ffffff;
  --brand-soft: #e7f0f8;
  --ok: #1f7a4d;
  --warn: #a35a00;
  --err: #b42318;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11161c; --card: #19212a; --ink: #e6edf3; --muted: #9aa8b6; --line: #2a3541;
    --brand: #4c9be0; --brand-ink: #0b1520; --brand-soft: #1b2b3b;
    --ok: #4cc38a; --warn: #f0a74a; --err: #ff7b72;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11161c; --card: #19212a; --ink: #e6edf3; --muted: #9aa8b6; --line: #2a3541;
  --brand: #4c9be0; --brand-ink: #0b1520; --brand-soft: #1b2b3b;
  --ok: #4cc38a; --warn: #f0a74a; --err: #ff7b72;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
[hidden] { display: none !important; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 24px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 36px; height: 36px; border-radius: 9px; background: var(--brand); display: grid; place-items: center; }
.logo svg { width: 20px; height: 20px; stroke: var(--brand-ink); stroke-width: 2.2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
h1 { font-size: 17px; margin: 0; }
.sub { margin: 0; color: var(--muted); font-size: 13px; }
.user { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--muted); }

main { padding: 24px max(16px, env(safe-area-inset-right, 0px)) 64px max(16px, env(safe-area-inset-left, 0px)); }
.view, .narrow { margin: 0 auto; }
.narrow { max-width: 860px; }
.wide { max-width: 1440px; }
.view { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.view > *, .filters, .detail { min-width: 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.center { text-align: center; padding: 48px 20px; }
.center h2 { margin: 0 0 6px; }
.muted { color: var(--muted); }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 640px) { .grid { grid-template-columns: 1fr; } .top { padding: 12px 16px; } }
.field { display: grid; gap: 6px; margin: 0 0 16px; border: 0; padding: 0; min-width: 0; }
.field > span, .field legend { font-weight: 600; font-size: 13px; padding: 0; }
.field em { font-style: normal; font-weight: 400; color: var(--muted); margin-left: 4px; }
input, select {
  font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 11px; width: 100%; min-width: 0;
}
input:focus, select:focus, .drop:focus-visible, button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 2px; }
.chip input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chip span {
  display: inline-block; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--bg); cursor: pointer; font-size: 14px; user-select: none;
}
.chip input:checked + span { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 600; }
.chip input:focus-visible + span { outline: 2px solid var(--brand); }

.drop {
  display: grid; justify-items: center; gap: 6px; text-align: center;
  padding: 40px 20px; border: 2px dashed var(--line); border-radius: var(--radius);
  background: var(--card); cursor: pointer; transition: border-color .15s, background .15s;
}
.drop svg { width: 36px; height: 36px; stroke: var(--brand); stroke-width: 1.8; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.drop strong { font-size: 17px; }
.drop:hover, .drop.over { border-color: var(--brand); background: var(--brand-soft); }
.drop.disabled { opacity: .5; cursor: not-allowed; }

.queue-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-weight: 600; }
.queue { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; max-height: 420px; overflow: auto; }
.item { padding: 10px 0; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item-top { display: flex; align-items: center; gap: 12px; }
.fname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fsize { color: var(--muted); font-size: 13px; white-space: nowrap; }
.fstatus { font-size: 13px; font-weight: 600; min-width: 72px; text-align: right; white-space: nowrap; }
.item.done .fstatus { color: var(--ok); }
.item.error .fstatus { color: var(--err); }
.item.skipped .fstatus, .item.cancelled .fstatus { color: var(--warn); }
.bar { height: 4px; background: var(--line); border-radius: 4px; margin-top: 8px; overflow: hidden; }
.bar > div { height: 100%; background: var(--brand); transition: width .2s; }
.item.done .bar > div { background: var(--ok); }
.item.error .bar > div { background: var(--err); }
.item.queued .bar { visibility: hidden; height: 0; margin: 0; }
.msg { font-size: 13px; color: var(--muted); margin-top: 4px; }
.item.error .msg { color: var(--err); }

.actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.check input { width: auto; }
.btns { display: flex; align-items: center; gap: 12px; margin-left: auto; }

button { font: inherit; cursor: pointer; }
.primary {
  background: var(--brand); color: var(--brand-ink); border: 0; border-radius: 8px;
  padding: 10px 22px; font-weight: 600;
}
.primary:disabled { opacity: .45; cursor: not-allowed; }
.link { background: none; border: 0; color: var(--brand); padding: 0; font-size: 14px; }
.icon { background: none; border: 0; color: var(--muted); font-size: 20px; line-height: 1; padding: 0 4px; }
.icon:hover { color: var(--err); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 10px;
  background: var(--ink); color: var(--card); font-weight: 600; box-shadow: 0 6px 24px rgba(0,0,0,.2);
}
.toast.warn { background: var(--warn); color: #fff; }

/* ---------- shell */
.tabs { display: flex; gap: 4px; background: var(--bg); padding: 4px; border-radius: 10px; }
.tab { padding: 8px 18px; border-radius: 7px; color: var(--muted); text-decoration: none; font-weight: 600; }
.tab[aria-current="page"] { background: var(--card); color: var(--brand); box-shadow: 0 1px 2px rgba(15,40,70,.12); }
.top { flex-wrap: wrap; }
.dept select { padding: 6px 10px; width: auto; }
.hint { color: var(--muted); font-size: 13px; min-height: 1.2em; }
.hint.warn { color: var(--warn); font-weight: 600; }
.ghost, .secondary { font: inherit; font-weight: 600; border-radius: 8px; padding: 9px 16px; background: var(--card); color: var(--brand); border: 1px solid var(--line); }
.secondary { border-color: var(--brand); }
.notice { margin-top: 12px; padding: 12px 14px; border-radius: 10px; background: color-mix(in srgb, var(--warn) 12%, var(--card)); border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent); }
.notice p { margin: 0 0 10px; font-weight: 600; }
.notice-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- files */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 14px 16px; }
.search { flex: 999 1 380px; min-width: 0; display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 0 12px; }
.search svg { width: 18px; height: 18px; stroke: var(--muted); stroke-width: 2; fill: none; stroke-linecap: round; flex: none; }
.search input { border: 0; background: transparent; padding: 10px 0; }
.search input:focus { outline: none; }
.search:focus-within { outline: 2px solid var(--brand); outline-offset: 1px; }
.inline { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.inline select { width: auto; color: var(--ink); }
.files-layout { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 16px; }
.filters { flex: 1 1 220px; max-width: 260px; display: grid; gap: 4px; padding: 18px; }
.filters-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.chips.small .chip span { padding: 4px 10px; font-size: 13px; }
.results { flex: 999 1 520px; min-width: 0; padding: 0; overflow: hidden; }
.results-head, .results-foot { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; padding: 14px 18px; }
.results-head { border-bottom: 1px solid var(--line); }
.results-foot { border-top: 1px solid var(--line); }
.table-wrap { overflow-x: auto; }
table { width: 100%; min-width: 620px; border-collapse: collapse; }
th { text-align: left; font-size: 12px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); font-weight: 600; padding: 10px 8px; }
th:first-child, td:first-child { padding-left: 18px; }
th:last-child, td:last-child { padding-right: 18px; }
td { padding: 11px 8px; border-top: 1px solid var(--line); vertical-align: middle; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: color-mix(in srgb, var(--brand-soft) 50%, transparent); }
tbody tr.sel { background: var(--brand-soft); box-shadow: inset 3px 0 0 var(--brand); }
tbody tr:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.name-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.ticon { width: 20px; height: 20px; flex: none; stroke: var(--muted); stroke-width: 2; fill: none; stroke-linejoin: round; stroke-linecap: round; }
tr.sel .ticon { stroke: var(--brand); }
.name-text { display: flex; flex-direction: column; min-width: 0; }
.nm { font-weight: 600; overflow-wrap: anywhere; }
.sub-line { display: block; font-size: 12px; color: var(--muted); }
.d1 { display: block; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 36px 18px; cursor: default; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.s-new { background: var(--brand-soft); color: var(--brand); }
.s-reviewed { background: color-mix(in srgb, var(--warn) 14%, var(--card)); color: var(--warn); }
.s-approved { background: color-mix(in srgb, var(--ok) 14%, var(--card)); color: var(--ok); }
.s-used { background: var(--bg); color: var(--muted); }
.s-archive { background: var(--bg); color: var(--muted); text-decoration: line-through; }

.detail { flex: 1 1 320px; max-width: 400px; padding: 0; overflow: hidden; }
.preview { background: #12202e; aspect-ratio: 16 / 9; display: flex; align-items: center; justify-content: center; }
.preview video, .preview img { width: 100%; height: 100%; object-fit: contain; display: block; }
.no-preview { color: #d6dee6; text-align: center; padding: 16px; font-size: 14px; }
.no-preview a { color: #9fd0ff; }
.detail-body { display: grid; gap: 12px; padding: 18px; }
.detail-body .field { margin: 0; }
.d-name { font-size: 16px; overflow-wrap: anywhere; }
.small-text { font-size: 13px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-row button { flex: 1 1 110px; }
.grid.two { grid-template-columns: 1fr 1fr; gap: 12px; }
textarea { font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; width: 100%; resize: vertical; }
.save-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
@media (max-width: 1099px) { .filters, .detail { max-width: none; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
