:root {
  --bg: #f6f7f9; --card: #fff; --text: #1c1f24; --muted: #6b7280; --line: #e5e7eb;
  --accent: #2563eb; --accent-hover: #1d4ed8; --danger: #dc2626; --row-hover: #f1f5f9;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111317; --card: #1a1d23; --text: #e5e7eb; --muted: #9ca3af; --line: #2a2f37;
    --accent: #3b82f6; --accent-hover: #60a5fa; --danger: #f87171; --row-hover: #20242b; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Segoe UI", sans-serif;
  background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
h1 { font-size: 18px; margin: 0; }
button { font: inherit; padding: 6px 12px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); cursor: pointer; }
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-hover); }
button.ghost { background: transparent; }
button.danger { color: var(--danger); }
button:disabled { opacity: .5; cursor: default; }
input { font: inherit; padding: 7px 10px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); }
input:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.error { color: var(--danger); min-height: 1.5em; margin: 0; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 28px;
  width: min(360px, 100%); display: grid; gap: 14px; }
.card label { display: grid; gap: 4px; color: var(--muted); font-size: 13px; }
.card input { color: var(--text); }

.topbar { display: flex; align-items: center; gap: 16px; padding: 12px 20px; background: var(--card);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 2; }
.spacer { flex: 1; }
#crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; min-width: 0; }
#crumbs button { border: 0; padding: 2px 6px; background: none; color: var(--accent); }
#crumbs button:last-child { color: var(--text); font-weight: 600; }
#crumbs .sep { color: var(--muted); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; padding: 14px 20px 6px; }
.toolbar input[type=search] { margin-left: auto; width: min(240px, 100%); }

.uploads { margin: 8px 20px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.upload-row { display: grid; grid-template-columns: 1fr 160px 70px; gap: 10px; align-items: center; padding: 4px 0; }
.upload-row .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
progress { width: 100%; height: 8px; }

.listing { position: relative; margin: 8px 20px 40px; background: var(--card); border: 1px solid var(--line);
  border-radius: 8px; overflow: hidden; min-height: 200px; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
td { padding: 6px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--row-hover); }
td.name { word-break: break-all; }
td.name button.link { border: 0; background: none; padding: 0; color: inherit; text-align: left; }
td.name button.link:hover { color: var(--accent); text-decoration: underline; }
.icon { display: inline-block; width: 20px; }
td.size, th.size { width: 100px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td.date, th.date { width: 160px; white-space: nowrap; color: var(--muted); }
td.act { width: 1%; white-space: nowrap; text-align: right; }
td.act button { padding: 3px 8px; font-size: 12px; margin-left: 2px; }
#empty { padding: 40px 0; }
.drop-hint { position: absolute; inset: 0; display: grid; place-items: center; font-size: 18px; color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent); border: 2px dashed var(--accent); border-radius: 8px; }

dialog { border: 1px solid var(--line); border-radius: 10px; padding: 0; background: var(--card); color: var(--text);
  width: min(960px, 94vw); }
dialog::backdrop { background: rgba(0,0,0,.45); }
.editor, .viewer { display: flex; flex-direction: column; height: min(80vh, 800px); }
.editor header, .editor footer, .viewer header { display: flex; align-items: center; gap: 12px; padding: 10px 14px; }
.editor header, .viewer header { border-bottom: 1px solid var(--line); justify-content: space-between; }
.editor footer { border-top: 1px solid var(--line); justify-content: flex-end; }
.editor textarea { flex: 1; border: 0; resize: none; padding: 12px 14px; font: 13px/1.5 ui-monospace, Menlo, monospace;
  background: var(--card); color: var(--text); }
#viewer-body { flex: 1; display: grid; place-items: center; overflow: auto; padding: 12px; }
#viewer-body img, #viewer-body video { max-width: 100%; max-height: 100%; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 8px 16px; border-radius: 8px; z-index: 10; max-width: 90vw; }
.toast.err { background: var(--danger); color: #fff; }

@media (max-width: 640px) {
  td.date, th.date { display: none; }
  .topbar { flex-wrap: wrap; gap: 8px; }
  .toolbar input[type=search] { margin-left: 0; width: 100%; }
}
