:root {
  --bg: #1c1d20; --panel: #222327; --raised: #2a2b30; --hover: #2a2c31; --line: #313238;
  --text: #e3e4e6; --muted: #959aa3; --accent: #5b8ad6; --sel: #2e4a76; --btn: #3a5c93;
  --folder: #e7b24a; --danger: #e5534b;
  color-scheme: dark;
}
* { box-sizing: border-box; scrollbar-width: thin; scrollbar-color: #3a3b42 transparent; }
html, body { height: 100%; margin: 0; }
body { font: 14px/1.45 Inter, "Segoe UI", system-ui, sans-serif; background: var(--bg); color: var(--text); }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.muted { color: var(--muted); }

.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.i-folder { fill: var(--folder); stroke: none; }
.files .i-drive { color: var(--accent); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--raised); color: var(--text); font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #45474f; background: #303137; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.icon { width: 38px; padding: 0; }
.btn.sm { width: 30px; height: 30px; border-color: transparent; background: none; color: var(--muted); }
.btn.sm:hover, .btn.sm.on { background: var(--raised); color: var(--text); }
.btn.primary { background: var(--btn); border-color: var(--btn); color: #fff; }
.btn.primary:hover { background: #4469a5; }
.btn.danger:hover { color: var(--danger); }
.btn.destructive { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.destructive:hover { background: #f0645c; }
.btn, td, .card, .side .item { transition: background-color .12s, border-color .12s, color .12s; }
@keyframes pop { from { opacity: 0; transform: scale(.97); } }

.app { height: 100%; display: grid; grid-template: "top top top" 60px "side files preview" 1fr "foot foot foot" 44px / 210px 1fr auto; }

.top { grid-area: top; display: flex; align-items: center; gap: 10px; padding: 0 12px; border-bottom: 1px solid var(--line); }
.nav { display: flex; gap: 6px; }
.nav .btn { background: none; border-color: transparent; }
.nav .btn:hover { background: var(--raised); }
.crumbs { flex: 1; min-width: 0; height: 38px; display: flex; align-items: center; gap: 4px; padding: 0 12px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--panel); white-space: nowrap; overflow: hidden; }
.crumbs a { padding: 2px 4px; border-radius: 4px; overflow: hidden; text-overflow: ellipsis; }
.crumbs a:hover { background: var(--raised); }
.crumbs a:first-child { display: flex; color: var(--muted); }
.crumbs .sep { color: var(--muted); }
.search { display: flex; align-items: center; gap: 8px; width: 230px; height: 38px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--muted); }
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; color: var(--text); font: inherit; }

.side { grid-area: side; padding: 14px 10px; overflow: auto; }
.side .group { display: flex; align-items: center; justify-content: space-between; margin: 18px 10px 6px; font-size: 13px; color: var(--muted); }
.side .item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; border: 1px solid transparent; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side .item span { overflow: hidden; text-overflow: ellipsis; }
.side .item:hover { background: var(--hover); }
.side .item.on { background: var(--raised); border-color: var(--line); }

.files { grid-area: files; overflow: auto; background: var(--panel); border-left: 1px solid var(--line); user-select: none; }
.ctx td, .card.ctx, .side .item.ctx { background: var(--hover); }
table { width: 100%; border-spacing: 0; padding: 0 8px 8px; table-layout: fixed; }
th { position: sticky; top: 0; z-index: 1; background: var(--panel); text-align: left; font-weight: 500; font-size: 13px; color: var(--muted);
  padding: 12px; border-bottom: 1px solid var(--line); cursor: pointer; user-select: none; }
th:hover { color: var(--text); }
th .i { width: 14px; height: 14px; vertical-align: -2px; margin-left: 4px; }
th.desc .i { transform: rotate(180deg); }
th.nosort { cursor: default; }
td { padding: 8px 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
td:not(.name) { color: var(--muted); }
th:nth-child(2) { width: 190px; } th:nth-child(3) { width: 100px; } th:nth-child(4) { width: 52px; }
td.name > div { display: flex; align-items: center; gap: 12px; min-width: 0; }
td.name > div > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
td.name small { display: block; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
tr[data-key] { cursor: default; }
tr[data-key]:hover td { background: var(--hover); }
tr.sel td, tr.sel:hover td { background: var(--sel); color: var(--text); }
tr td:first-child { border-radius: 8px 0 0 8px; }
tr td:last-child { border-radius: 0 8px 8px 0; }
.act button { opacity: 0; }
[data-key]:hover .act button, [data-key]:focus-within .act button, .sel .act button { opacity: 1; }
.empty { padding: 60px 20px; text-align: center; color: var(--muted); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; padding: 16px; }
.card { position: relative; padding: 8px; border-radius: 10px; border: 1px solid transparent; cursor: default; }
.card:hover { background: var(--hover); }
.card.sel { background: var(--sel); }
.card .thumb { aspect-ratio: 1; display: grid; place-items: center; overflow: hidden; border-radius: 8px; background: var(--raised); color: var(--muted); }
.card .thumb .i { width: 42px; height: 42px; stroke-width: 1.3; }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.card .label { margin-top: 8px; font-size: 13px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .act { position: absolute; top: 12px; right: 12px; }
.card .act .btn { background: #000a; }

.preview { grid-area: preview; width: 320px; padding: 16px; overflow: auto; border-left: 1px solid var(--line); position: relative; }
.preview .close { position: absolute; top: 20px; right: 20px; z-index: 2; background: #000a; }
.stage { aspect-ratio: 1; display: grid; place-items: center; overflow: hidden; border-radius: 10px; background: var(--raised); color: var(--muted); }
.stage.tall { aspect-ratio: 3 / 4; }
.stage img, .stage video { max-width: 100%; max-height: 100%; object-fit: contain; }
.stage iframe, .stage model-viewer { width: 100%; height: 100%; border: 0; background: #fff; }
.stage model-viewer { background: var(--raised); }
.stage pre { align-self: stretch; justify-self: stretch; margin: 0; padding: 12px; overflow: auto; font: 12px/1.5 ui-monospace, "Cascadia Code", monospace; color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; }
.stage .none, .stage .audio { display: grid; justify-items: center; gap: 12px; padding: 16px; text-align: center; }
.stage .none .i, .stage .audio .i { width: 56px; height: 56px; stroke-width: 1.2; }
.stage audio { width: 260px; }
.preview h2 { margin: 16px 0 2px; font-size: 16px; font-weight: 600; overflow-wrap: anywhere; }
.preview p { margin: 0 0 2px; font-size: 13px; }
.preview .actions { display: flex; gap: 8px; margin-top: 16px; }
.preview .actions .primary { flex: 1; }

.foot { grid-area: foot; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.views { display: flex; align-items: center; gap: 4px; }
.who { margin-right: 4px; }
.who b { color: var(--text); font-weight: 500; }
.link { margin-right: 12px; padding: 0; border: 0; background: none; color: var(--accent); font: inherit; cursor: pointer; }
.link:hover { text-decoration: underline; }

#login { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: var(--bg); }
#login[hidden] { display: none; }
#login form { width: min(340px, calc(100% - 32px)); display: grid; gap: 14px; padding: 28px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); }
#login h1 { margin: 0 0 4px; font-size: 20px; font-weight: 600; }
#login label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
#login input, .dialog input { height: 38px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; outline: 0; }
#login input:focus, .dialog input:focus { border-color: var(--accent); }
#loginError { margin: 0; min-height: 1.45em; font-size: 13px; color: var(--danger); }

#drop { position: fixed; inset: 0; z-index: 20; display: none; place-items: center; background: #2e4a7655; border: 3px dashed var(--accent); font-size: 22px; font-weight: 600; pointer-events: none; }
body.dragging #drop { display: grid; }
#uploads { position: fixed; right: 16px; bottom: 56px; z-index: 30; width: 300px; display: flex; flex-direction: column; gap: 8px; }
#uploads > div { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--raised); font-size: 13px; box-shadow: 0 8px 24px #0006; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#uploads > div { animation: pop .15s ease-out; }
#uploads > div.toast { cursor: pointer; white-space: normal; }
#uploads > div.failed { border-color: var(--danger); cursor: pointer; }

.menu { position: fixed; z-index: 50; min-width: 200px; padding: 5px; border: 1px solid var(--line); border-radius: 10px; background: #26272c;
  box-shadow: 0 12px 32px #0009; animation: pop .1s ease-out; transform-origin: top left; }
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; height: 34px; padding: 0 10px; border: 0; border-radius: 6px;
  background: none; color: var(--text); font: inherit; text-align: left; cursor: default; }
.menu button .i { width: 16px; height: 16px; color: var(--muted); }
.menu button:hover, .menu button:focus-visible { background: var(--sel); outline: 0; }
.menu button:hover .i, .menu button:focus-visible .i { color: var(--text); }
.menu button.danger, .menu button.danger .i { color: var(--danger); }
.menu button.danger:hover, .menu button.danger:focus-visible { background: #e5534b26; }
.menu hr { margin: 5px 6px; border: 0; border-top: 1px solid var(--line); }

.dialog { width: min(400px, calc(100% - 32px)); padding: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text);
  box-shadow: 0 24px 64px #000a; animation: pop .14s ease-out; }
.dialog::backdrop { background: #0009; backdrop-filter: blur(3px); }
.dialog form { display: grid; gap: 12px; padding: 22px; }
.dialog h2 { margin: 0; font-size: 17px; font-weight: 600; overflow-wrap: anywhere; }
.dialog p { margin: 0; color: var(--muted); }
.dialog .error { font-size: 13px; color: var(--danger); }
.dialog .error:empty { display: none; }
.dialog .row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
#uploads progress { display: block; width: 100%; margin-top: 6px; accent-color: var(--accent); }

@media (max-width: 760px) {
  .app { grid-template: "top" auto "files" 1fr "foot" 44px / 1fr; }
  .side { display: none; }
  .top { flex-wrap: wrap; padding: 10px; }
  .crumbs { order: 1; flex-basis: 100%; }
  .search { flex: 1; width: auto; }
  .btn .label { display: none; }
  .btn:has(.label) { width: 38px; padding: 0; }
  th:nth-child(2), td:nth-child(2) { display: none; }
  .act button { opacity: 1; }
  .who { display: none; }
  .preview { position: fixed; inset: 0; z-index: 10; width: auto; background: var(--bg); }
}
