* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0e0f12; --panel: #16181d; --panel2: #1b1e25; --border: #262a33;
  --text: #e8e8ea; --muted: #9aa0ab; --accent: #4f7cff; --accent2: #5d87ff;
  --danger: #ff6b6b; --ok: #5bd17a;
}
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column; min-height: 100vh;
}

.topbar {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px;
  background: var(--panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20; flex-wrap: wrap;
}
.brand { font-weight: 700; cursor: pointer; white-space: nowrap; }
.brand span { color: var(--accent); }
.spacer { flex: 1; }
.crumbs { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: .9rem; flex-wrap: wrap; }
.crumbs a { color: var(--muted); cursor: pointer; text-decoration: none; }
.crumbs a:hover { color: var(--text); }
.crumbs .sep { opacity: .5; }

.btn {
  background: var(--accent); color: #fff; border: none; border-radius: 8px;
  padding: 8px 14px; font-size: .9rem; font-weight: 600; cursor: pointer;
}
.btn:hover { background: var(--accent2); }
.btn.ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn.ghost:hover { background: var(--panel2); }
.btn.danger { background: var(--danger); }

.grid {
  flex: 1; display: grid; gap: 12px; padding: 18px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  align-content: start;
}
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px; cursor: pointer; position: relative; overflow: hidden;
  transition: border-color .15s, transform .05s;
}
.card:hover { border-color: #3a4453; }
.card:active { transform: scale(.99); }
.card .thumb {
  height: 92px; display: flex; align-items: center; justify-content: center;
  font-size: 2.6rem; margin-bottom: 10px; border-radius: 8px; background: var(--panel2);
  overflow: hidden;
}
.card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.card .name { font-size: .86rem; word-break: break-word; line-height: 1.3; max-height: 2.6em; overflow: hidden; }
.card .meta { color: var(--muted); font-size: .72rem; margin-top: 4px; }
.card .menu-btn {
  position: absolute; top: 8px; right: 8px; background: rgba(0,0,0,.4);
  border: none; color: #fff; width: 26px; height: 26px; border-radius: 6px;
  cursor: pointer; opacity: 0; font-size: 1rem;
}
.card:hover .menu-btn { opacity: 1; }
.empty { color: var(--muted); padding: 40px; text-align: center; grid-column: 1/-1; }

.drop-overlay {
  position: fixed; inset: 0; background: rgba(79,124,255,.15);
  border: 3px dashed var(--accent); display: none; align-items: center;
  justify-content: center; font-size: 1.6rem; z-index: 50; pointer-events: none;
}
.drop-overlay.show { display: flex; }

.tray {
  position: fixed; right: 16px; bottom: 16px; width: 340px; max-height: 50vh;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  z-index: 40; display: flex; flex-direction: column; box-shadow: 0 16px 40px rgba(0,0,0,.5);
}
.tray.hidden { display: none; }
.tray-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--border); font-weight: 600; }
.tray-head button { background: none; border: none; color: var(--muted); font-size: 1.2rem; cursor: pointer; }
.tray-body { overflow: auto; padding: 8px 14px; }
.up-item { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: .85rem; }
.up-item:last-child { border-bottom: none; }
.up-item .nm { display: flex; justify-content: space-between; gap: 8px; }
.up-item .nm span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 6px; background: var(--panel2); border-radius: 4px; margin-top: 6px; overflow: hidden; }
.bar > div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.up-item.err .bar > div { background: var(--danger); }
.up-item.done .bar > div { background: var(--ok); }

/* modal */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  width: min(94vw, 560px); max-height: 90vh; overflow: auto; padding: 22px;
}
.modal.wide { width: min(96vw, 980px); }
.modal h2 { font-size: 1.2rem; margin-bottom: 14px; }
.modal label { display: block; font-size: .85rem; color: var(--muted); margin: 12px 0 6px; }
.modal input[type=text], .modal textarea {
  width: 100%; background: var(--panel2); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 10px; font-size: .92rem; font-family: inherit;
}
.modal textarea { resize: vertical; min-height: 70px; word-break: break-all; }
.row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.node { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; }
.node .ic { font-size: 1.6rem; }
.node .info { flex: 1; min-width: 0; }
.node .info b { display: block; }
.node .info small { color: var(--muted); }
.node .qbar { height: 5px; background: var(--panel2); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.node .qbar > div { height: 100%; background: var(--accent); }
.note { color: var(--muted); font-size: .82rem; line-height: 1.5; }
.warn { color: #ffcf6b; }

/* viewer */
.viewer { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 70; display: flex; flex-direction: column; }
.viewer .vbar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; color: var(--text); }
.viewer .vbar .vname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer .vbody { flex: 1; display: flex; align-items: center; justify-content: center; overflow: auto; padding: 12px; }
.viewer img, .viewer video { max-width: 96vw; max-height: 84vh; }
.viewer .ztable { background: var(--panel); border-radius: 10px; padding: 16px; max-height: 80vh; overflow: auto; min-width: 320px; }
.viewer .ztable div { font-size: .85rem; padding: 3px 0; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: 16px; }
.viewer pre { background: var(--panel); padding: 16px; border-radius: 10px; max-width: 96vw; max-height: 84vh; overflow: auto; white-space: pre-wrap; }
.spin { width: 34px; height: 34px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: sp 1s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
.ctxmenu { position: fixed; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; z-index: 80; min-width: 150px; padding: 6px; box-shadow: 0 10px 30px rgba(0,0,0,.5); }
.ctxmenu button { display: block; width: 100%; text-align: left; background: none; border: none; color: var(--text); padding: 8px 10px; border-radius: 6px; cursor: pointer; font-size: .88rem; }
.ctxmenu button:hover { background: var(--panel2); }
.ctxmenu button.danger { color: var(--danger); }
