:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --border: #2a2f3a;
  --text: #e6e8ee;
  --muted: #8b92a3;
  --accent: #4f8cff;
  --accent-2: #3a74e6;
  --danger: #e5484d;
  --ok: #30a46c;
  --radius: 8px;
  font-family: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-size: 14px; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--panel-2);
  cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #3a4150; background: #252a35; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--danger); }
.btn.icon { padding: 6px 8px; }
.btn.active { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }

input[type=text], input[type=password], select {
  width: 100%; padding: 9px 11px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg); outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
select { width: auto; padding: 7px 10px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 12px; padding: 28px;
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 20px; color: var(--muted); }
.login-card label { display: block; margin: 12px 0 6px; color: var(--muted); font-size: 13px; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 20px; padding: 10px; }
.error { color: var(--danger); min-height: 20px; margin-top: 10px; font-size: 13px; }

/* ---------- dashboard layout ---------- */
.app { display: grid; grid-template-rows: 52px 1fr; height: 100vh; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 0 16px;
  border-bottom: 1px solid var(--border); background: var(--panel);
}
.brand { font-weight: 700; font-size: 16px; }
.bucket { color: var(--muted); font-size: 12px; }
.spacer { flex: 1; }
.main { display: grid; grid-template-columns: 280px 1fr; min-height: 0; }

.sidebar {
  border-right: 1px solid var(--border); background: var(--panel);
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar-head { padding: 12px; display: flex; gap: 8px; border-bottom: 1px solid var(--border); }
.tree { overflow: auto; padding: 8px 4px; flex: 1; }
.tree ul { list-style: none; margin: 0; padding-left: 14px; }
.tree > ul { padding-left: 0; }
.node {
  display: flex; align-items: center; gap: 4px; padding: 4px 6px;
  border-radius: 6px; cursor: pointer; user-select: none; white-space: nowrap;
}
.node:hover { background: var(--panel-2); }
.node.selected { background: rgba(79, 140, 255, .18); color: #fff; }
.node.drop { outline: 2px dashed var(--accent); }
.caret { width: 16px; text-align: center; color: var(--muted); flex: none; font-size: 10px; }
.node .label { overflow: hidden; text-overflow: ellipsis; }

.content { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
}
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; flex: 1; min-width: 200px; }
.crumbs a { cursor: pointer; text-decoration: none; color: var(--text); padding: 2px 4px; border-radius: 4px; }
.crumbs a:hover { background: var(--panel-2); }
.crumbs .sep { color: var(--muted); }
.search { max-width: 220px; }

.files { flex: 1; overflow: auto; padding: 16px; position: relative; }
.files.dragover::after {
  content: 'Drop files or folders to upload here';
  position: absolute; inset: 8px; border: 2px dashed var(--accent); border-radius: 12px;
  display: grid; place-items: center; background: rgba(79, 140, 255, .08);
  font-size: 16px; color: var(--accent); pointer-events: none;
}
.empty { color: var(--muted); text-align: center; padding: 60px 0; }

/* grid view */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  overflow: hidden; cursor: pointer; display: flex; flex-direction: column; position: relative;
}
.card:hover { border-color: #3a4150; }
.thumb {
  aspect-ratio: 4 / 3; background: var(--panel-2); display: grid; place-items: center;
  overflow: hidden; position: relative;
}
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .ext { font-size: 34px; }
.thumb .ext small { display: block; text-align: center; font-size: 11px; color: var(--muted); margin-top: 4px; }
.play-badge {
  position: absolute; width: 38px; height: 38px; border-radius: 50%;
  background: rgba(0, 0, 0, .6); display: grid; place-items: center; color: #fff; font-size: 14px;
}
.meta { padding: 8px 10px; }
.meta .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.meta .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.card .actions { position: absolute; top: 6px; right: 6px; display: none; gap: 4px; }
.card:hover .actions { display: flex; }
.card .actions .btn { padding: 3px 7px; font-size: 12px; background: rgba(15, 17, 21, .85); }

/* list view */
table.list { width: 100%; border-collapse: collapse; }
.list th, .list td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.list th { color: var(--muted); font-weight: 500; cursor: pointer; user-select: none; position: sticky; top: -16px; background: var(--bg); }
.list tr.row { cursor: pointer; }
.list tr.row:hover td { background: var(--panel); }
.list .num { text-align: right; white-space: nowrap; }
.list td.nm { display: flex; align-items: center; gap: 8px; }
.list .ico { width: 34px; height: 34px; border-radius: 5px; overflow: hidden; background: var(--panel-2); display: grid; place-items: center; flex: none; }
.list .ico img { width: 100%; height: 100%; object-fit: cover; }
.list .row-actions { white-space: nowrap; text-align: right; }
.list .row-actions .btn { padding: 3px 8px; font-size: 12px; }

/* upload panel */
.uploads {
  position: fixed; right: 16px; bottom: 16px; width: 360px; max-width: calc(100vw - 32px);
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .5); display: none; z-index: 20;
}
.uploads.show { display: block; }
.uploads header { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--border); font-weight: 600; }
.uploads .items { max-height: 300px; overflow: auto; }
.up-item { padding: 8px 14px; border-bottom: 1px solid var(--border); }
.up-item .row1 { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.up-item .row1 span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-item .stat { color: var(--muted); flex: none; }
.up-item.done .stat { color: var(--ok); }
.up-item.failed .stat { color: var(--danger); }
.bar { height: 4px; background: var(--panel-2); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.bar.total { height: 6px; margin: 0; border-radius: 0; }
.bar div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.up-item.done .bar div { background: var(--ok); }
.up-item.failed .bar div { background: var(--danger); }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .7); display: none; place-items: center; z-index: 30; padding: 16px; }
.modal.show { display: grid; }
.modal-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  width: 100%; max-width: 420px; padding: 20px;
}
.modal-box h3 { margin: 0 0 12px; }
.modal-box p { color: var(--muted); margin: 0 0 12px; word-break: break-word; }
.modal-box .hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.viewer .modal-box { max-width: min(1100px, 100%); padding: 0; overflow: hidden; }
.viewer-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.viewer-head .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.viewer-body { background: #000; display: grid; place-items: center; max-height: 78vh; min-height: 200px; }
.viewer-body video, .viewer-body img { max-width: 100%; max-height: 78vh; display: block; }
.viewer-body iframe { width: 100%; height: 78vh; border: 0; background: #fff; }
.viewer-body audio { width: 90%; margin: 40px 0; }
.viewer-body .nopreview { color: var(--muted); padding: 60px 20px; text-align: center; }
.viewer-foot { padding: 8px 14px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--border); }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--border); padding: 10px 16px;
  border-radius: 8px; z-index: 40; display: none;
}
.toast.show { display: block; }
.toast.err { border-color: var(--danger); color: #ffb4b6; }

@media (max-width: 760px) {
  .main { grid-template-columns: 1fr; grid-template-rows: 200px 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); }
  .bucket { display: none; }
  .search { max-width: none; flex: 1; }
}

/* video preview badge */
.pv {
  font-size: 11px; padding: 2px 7px; border-radius: 10px; border: 1px solid var(--border);
  background: rgba(15, 17, 21, .85); color: var(--muted); white-space: nowrap; cursor: default;
}
.card > .pv { position: absolute; left: 6px; top: 6px; z-index: 1; }
.list .pv { margin-left: 8px; }
.pv.ok { color: #7ee2a8; border-color: rgba(48, 164, 108, .5); }
button.pv.none { cursor: pointer; }
button.pv.none:hover { color: var(--text); border-color: var(--accent); }
