/* One place for every colour and size. Pages use these variables only. */
:root {
  --bg: #F6F6F4;
  --surface: #FFFFFF;
  --surface-2: #FAFAFA;
  --muted-bg: #F4F4F5;
  --segment-bg: #EAEAE7;
  --ink: #18181B;
  --ink-2: #27272A;
  --ink-3: #3F3F46;
  --muted: #52525B;
  --faint: #71717A;
  --line: #E4E4E7;
  --line-2: #F0F0F2;
  --line-strong: #D4D4D8;
  --primary: #1D4ED8;
  --primary-ink: #1E3A8A;
  --primary-soft: #EEF2FF;
  --focus-ring: #DBEAFE;
  --danger: #B42318;
  --danger-soft: #FEE4E2;
  --danger-ink: #912018;
  --ok-soft: #DCFCE7;
  --ok-ink: #166534;
  --move-soft: #E0E7FF;
  --move-ink: #3730A3;
  --warn-soft: #FFF7ED;
  --warn-line: #FED7AA;
  --warn-ink: #9A3412;
  --scrim: rgba(24, 24, 27, 0.45);
  --media-bg: #18181B;
  --font: 'PingFang SC', 'Microsoft YaHei', system-ui, sans-serif;
  --mono: ui-monospace, Menlo, Consolas, monospace;
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 10px;
  --r-xl: 12px;
  --h-btn: 40px;
  --h-btn-sm: 32px;
  --h-btn-lg: 44px;
  --shadow-dialog: 0 12px 32px rgba(0, 0, 0, 0.18);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 14px; line-height: 1.5; }
a { color: var(--primary); }
a:hover { color: var(--primary-ink); }
h1 { margin: 0; font-size: 24px; font-weight: 600; }
h2 { margin: 0; font-size: 18px; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-in { max-width: 1240px; margin: 0 auto; padding: 0 24px; min-height: 56px; display: flex; flex-wrap: wrap; align-items: center; gap: 32px; }
.brand { font-size: 16px; font-weight: 600; }
.nav { display: flex; flex-wrap: wrap; gap: 4px; flex: 1 1 auto; }
.nav a { padding: 8px 12px; border-radius: var(--r-sm); color: var(--ink-3); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.who { display: flex; align-items: center; gap: 16px; color: var(--muted); }
.linkbtn { border: 0; background: none; padding: 8px 0; font: inherit; color: var(--ink-3); cursor: pointer; }
.linkbtn:hover { color: var(--ink); }

/* ---------- layout */
.page { max-width: 1240px; margin: 0 auto; padding: 32px 24px; display: flex; flex-direction: column; gap: 24px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
.stack-4 { display: flex; flex-direction: column; gap: 4px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.split { display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-start; padding: 24px; max-width: 1240px; margin: 0 auto; }
.split > aside { flex: 1 1 220px; max-width: 260px; }
.split > main { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; gap: 20px; }

/* ---------- buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: var(--h-btn); padding: 0 16px; border-radius: var(--r-md);
       border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font: inherit; text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); color: var(--ink); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #FFFFFF; font-weight: 600; }
.btn-primary:hover { background: var(--primary-ink); border-color: var(--primary-ink); color: #FFFFFF; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #FFFFFF; font-weight: 600; }
.btn-danger:hover { background: var(--danger-ink); border-color: var(--danger-ink); color: #FFFFFF; }
.btn-danger-ghost { color: var(--danger); }
.btn-outline-primary { border-color: var(--primary); color: var(--primary); font-weight: 600; }
.btn-sm { height: var(--h-btn-sm); padding: 0 12px; border-radius: var(--r-sm); }
.btn-lg { height: var(--h-btn-lg); }
.btn-block { width: 100%; }
.btn[disabled], .btn[aria-busy="true"] { opacity: 0.6; cursor: default; pointer-events: none; }
.textbtn { border: 0; background: none; font: inherit; font-size: 13px; color: var(--ink-3); padding: 4px 6px; cursor: pointer; }
.textbtn:hover { color: var(--ink); }
.textbtn.danger { color: var(--danger); }
.textbtn.primary { color: var(--primary); }

/* ---------- forms */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 500; }
.input { height: var(--h-btn); padding: 0 12px; border: 1px solid var(--line-strong); border-radius: var(--r-md); font: inherit; color: var(--ink); background: var(--surface); width: 100%; }
.input:focus { outline: 3px solid var(--focus-ring); border-color: var(--primary); }
.input.mono { font-family: var(--mono); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.hint { color: var(--muted); font-size: 13px; }
.err { color: var(--danger); font-size: 13px; }
.card-form { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 28px; display: flex; flex-direction: column; gap: 20px; }

/* ---------- login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl); padding: 40px 32px; display: flex; flex-direction: column; gap: 20px; }
.login-card h1 { font-size: 22px; }

/* ---------- table */
.table-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 12px 20px; font-weight: 500; color: var(--muted); border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
td { padding: 14px 20px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.actions { text-align: right; }
td.actions .row { justify-content: flex-end; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

/* ---------- badges */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px; white-space: nowrap; }
.badge-ok { background: var(--ok-soft); color: var(--ok-ink); }
.badge-gray { background: var(--muted-bg); color: var(--muted); }
.badge-del { background: var(--danger-soft); color: var(--danger-ink); }
.badge-move { background: var(--move-soft); color: var(--move-ink); }
.tag-small { padding: 0 8px; border-radius: 999px; background: var(--muted-bg); color: var(--muted); font-size: 12px; font-weight: 400; }

/* ---------- folder tree */
.tree-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 12px 8px; }
.tree-title { padding: 4px 8px 8px; color: var(--muted); font-size: 13px; }
.tree { display: flex; flex-direction: column; gap: 2px; }
.tree-row { display: flex; align-items: center; min-height: 34px; border-radius: var(--r-sm); }
.tree-row:hover { background: var(--surface-2); }
.tree-row.on { background: var(--primary-soft); }
.tree-row.on .tree-name { color: var(--primary); font-weight: 600; }
.tree-arrow { width: 22px; height: 28px; flex: 0 0 22px; border: 0; background: none; color: var(--faint); font-size: 10px; cursor: pointer; padding: 0; }
.tree-arrow:disabled { cursor: default; }
.tree-name { flex: 1 1 auto; min-width: 0; padding: 6px 8px 6px 0; color: var(--ink-2); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border: 0; background: none; font: inherit; text-align: left; cursor: pointer; }
.tree-name:hover { color: var(--ink); }
.tree-empty { padding: 8px; color: var(--muted); font-size: 13px; }

/* ---------- folder header */
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; color: var(--muted); }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--ink); }

/* ---------- toolbar */
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.toolbar .input { flex: 1 1 280px; max-width: 360px; width: auto; }
.segmented { display: inline-flex; padding: 3px; background: var(--segment-bg); border-radius: var(--r-md); gap: 2px; }
.segmented button { height: 34px; padding: 0 14px; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--ink-3); font: inherit; cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }

/* ---------- sections and grids */
.section { display: flex; flex-direction: column; gap: 10px; }
.section-head { display: flex; justify-content: space-between; gap: 12px; }
.section-head h2 { font-size: 13px; font-weight: 500; color: var(--muted); }
.folder-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.folder-tile { display: flex; align-items: center; gap: 10px; height: 52px; padding: 0 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); color: var(--ink); text-decoration: none; }
.folder-tile:hover { border-color: var(--line-strong); color: var(--ink); }
.folder-tile .name { flex: 1 1 auto; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.asset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.asset-card { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; color: var(--ink); text-align: left; padding: 0; font: inherit; cursor: pointer; }
.asset-card:hover { border-color: var(--line-strong); }
.asset-card:focus-visible { outline: 3px solid var(--focus-ring); }
.thumb { position: relative; aspect-ratio: 16 / 10; background: var(--line); display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.duration { position: absolute; right: 8px; bottom: 8px; padding: 0 6px; border-radius: 4px; background: rgba(24, 24, 27, 0.75); color: #FFFFFF; font-size: 12px; }
.asset-meta { padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.asset-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.more { display: flex; justify-content: center; padding-top: 8px; }

/* ---------- dialogs */
dialog { border: 0; padding: 0; border-radius: var(--r-xl); box-shadow: var(--shadow-dialog); background: var(--surface); color: var(--ink); max-width: calc(100vw - 32px); }
dialog::backdrop { background: var(--scrim); }
.dlg { width: 440px; max-width: 100%; padding: 28px; display: flex; flex-direction: column; gap: 20px; }
.dlg.wide { width: 560px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 12px; }
.dlg-preview { display: flex; flex-wrap: wrap; width: 960px; max-width: 100%; }
.dlg-media { flex: 1 1 520px; min-height: 360px; max-height: 80vh; background: var(--media-bg); display: flex; align-items: center; justify-content: center; }
.dlg-media img, .dlg-media video { max-width: 100%; max-height: 80vh; display: block; }
.dlg-side { flex: 0 0 280px; padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.dl { margin: 0; display: grid; grid-template-columns: 64px 1fr; row-gap: 8px; column-gap: 8px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; word-break: break-all; }
.iconbtn { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border: 0; border-radius: var(--r-sm); background: none; color: var(--ink-3); cursor: pointer; flex: 0 0 auto; }
.iconbtn:hover { background: var(--muted-bg); }
.keybox { display: flex; gap: 8px; align-items: stretch; }
.keybox code { flex: 1 1 auto; min-width: 0; padding: 10px 12px; background: var(--muted-bg); border: 1px solid var(--line); border-radius: var(--r-md); font-family: var(--mono); font-size: 13px; word-break: break-all; }
.warn { padding: 12px 14px; background: var(--warn-soft); border: 1px solid var(--warn-line); border-radius: var(--r-md); color: var(--warn-ink); }
.dest { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--muted-bg); border-radius: var(--r-md); }
.dest .path { flex: 1 1 auto; font-weight: 500; word-break: break-all; }
.drop { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; height: 140px; border: 1.5px dashed #A1A1AA; border-radius: var(--r-lg); background: var(--surface-2); cursor: pointer; text-align: center; }
.drop.over { border-color: var(--primary); background: var(--primary-soft); }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.filelist { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--r-md); max-height: 260px; overflow-y: auto; }
.filelist .item { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line-2); }
.filelist .item:last-child { border-bottom: 0; }
.filelist .fname { flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.st { flex: 0 0 auto; font-size: 13px; }
.st-ok { color: var(--ok-ink); }
.st-run { color: var(--primary); }
.st-err { color: var(--danger); }
.st-wait { color: var(--muted); }
.picker { display: flex; flex-direction: column; gap: 2px; max-height: 320px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--r-md); padding: 6px; }
.pick { display: flex; align-items: center; gap: 6px; min-height: 36px; padding-right: 8px; border: 0; border-radius: var(--r-sm); background: none; color: var(--ink-2); font: inherit; text-align: left; cursor: pointer; }
.pick:hover { background: var(--surface-2); }
.pick[aria-checked="true"] { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.pick .here { margin-left: auto; color: var(--muted); font-size: 12px; font-weight: 400; }

/* ---------- toast */
.toast { position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%); background: var(--ink); color: #FFFFFF; padding: 10px 16px; border-radius: var(--r-md); z-index: 1000; max-width: calc(100vw - 32px); }

/* ---------- small helpers */
.head-center { align-items: center; }
.minw0 { min-width: 0; }
.gap12 { gap: 12px; }
.tbl-users { min-width: 820px; }
.tbl-logs { min-width: 720px; }
th.right { text-align: right; }
.push-down { margin-top: auto; }
.dlg-side > .row:first-child { justify-content: space-between; flex-wrap: nowrap; align-items: flex-start; }
.dlg-side h2 { min-width: 0; font-size: 16px; white-space: normal; word-break: break-all; }
.dest .textbtn { flex: 0 0 auto; }
.picker + .textbtn { align-self: flex-start; padding-left: 0; }
@media (max-width: 720px) {
  .split { padding: 16px; }
  .split > aside { max-width: none; }
  .page { padding: 24px 16px; }
  .topbar-in { gap: 8px 24px; padding: 8px 16px; }
}
