:root {
  --bg: #f6f8fc;
  --panel: #ffffff;
  --line: #e3e7ee;
  --text: #1f2733;
  --muted: #6b7684;
  --brand: #2f6df6;
  --brand-dark: #1f57d6;
  --danger: #e2483d;
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.06);
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px;
}
button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.login-card {
  width: 100%; max-width: 380px; background: var(--panel); border-radius: 16px;
  box-shadow: var(--shadow); padding: 32px 28px; border: 1px solid var(--line);
}
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card .sub { color: var(--muted); margin: 0 0 20px; font-size: 13px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px;
  font-size: 14px; background: #fff; color: var(--text); outline: none;
}
.field input:focus, .field select:focus { border-color: var(--brand); }
.btn {
  border: none; border-radius: 9px; padding: 10px 16px; font-size: 14px; font-weight: 600;
  background: var(--brand); color: #fff; width: 100%;
}
.btn:hover { background: var(--brand-dark); }
.btn.secondary { background: #eef2f9; color: var(--text); }
.btn.secondary:hover { background: #e2e8f5; }
.btn.ghost { background: transparent; color: var(--brand); width: auto; padding: 6px 8px; }
.btn.small { width: auto; padding: 7px 12px; font-size: 13px; }
.err { color: var(--danger); font-size: 13px; margin: 8px 0 0; min-height: 18px; }
.link { color: var(--brand); background: none; border: none; cursor: pointer; font-size: 13px; padding: 0; }
details.setup { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 14px; }
details.setup summary { cursor: pointer; color: var(--muted); font-size: 13px; }

/* ---------- App shell ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 18px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.topbar .logo { font-weight: 700; font-size: 16px; color: var(--brand); display: flex; align-items: center; gap: 8px; }
.topbar .spacer { flex: 1; }
.topbar select, .topbar .user {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font-size: 13px;
}
.topbar .user { color: var(--muted); }

.toolbar {
  display: flex; align-items: center; gap: 10px; padding: 12px 18px; flex-wrap: wrap;
}
.crumbs { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 200px; font-size: 14px; flex-wrap: wrap; }
.crumbs a { color: var(--brand); cursor: pointer; text-decoration: none; }
.crumbs span.sep { color: var(--muted); }
.crumbs .cur { color: var(--text); font-weight: 600; }

.content { padding: 4px 18px 60px; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 2px 10px; }

.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px;
}
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow); position: relative; transition: transform .05s;
}
.card:hover { transform: translateY(-1px); border-color: #cfd8e6; }

.folder-card { display: flex; align-items: center; gap: 10px; padding: 14px; cursor: pointer; }
.folder-card .ico { font-size: 26px; }
.folder-card .fname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.file-card .thumb {
  aspect-ratio: 1 / 1; width: 100%; background: #eef1f6; display: flex; align-items: center;
  justify-content: center; overflow: hidden; cursor: pointer; position: relative;
}
.file-card .thumb img, .file-card .thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.file-card .thumb .ficon { font-size: 40px; color: var(--muted); }
.file-card .thumb .play {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 34px; color: #fff; text-shadow: 0 1px 6px rgba(0,0,0,.6); pointer-events: none;
}
.file-meta { padding: 9px 11px; }
.file-meta .fn { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta .fsub { font-size: 11px; color: var(--muted); margin-top: 2px; display: flex; justify-content: space-between; gap: 6px; }

.menu-btn {
  position: absolute; top: 6px; right: 6px; width: 28px; height: 28px; border-radius: 7px;
  border: none; background: rgba(255,255,255,.9); color: var(--text); font-size: 16px; line-height: 1;
  display: flex; align-items: center; justify-content: center; opacity: 0; box-shadow: var(--shadow);
}
.card:hover .menu-btn { opacity: 1; }

/* dropdown */
.dropdown {
  position: absolute; background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 6px 20px rgba(16,24,40,.16); padding: 6px; z-index: 50; min-width: 150px;
}
.dropdown button {
  display: flex; width: 100%; gap: 8px; align-items: center; padding: 8px 10px; border: none;
  background: none; border-radius: 7px; font-size: 13px; color: var(--text); text-align: left;
}
.dropdown button:hover { background: #f1f4fa; }
.dropdown button.danger { color: var(--danger); }

.empty-state { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty-state .big { font-size: 46px; margin-bottom: 10px; }

/* ---------- Upload tray ---------- */
.uploads {
  position: fixed; right: 18px; bottom: 18px; width: 320px; background: #fff; border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 10px 30px rgba(16,24,40,.18); z-index: 60; overflow: hidden;
}
.uploads header { padding: 10px 14px; font-weight: 600; border-bottom: 1px solid var(--line); font-size: 13px; }
.uploads .row { padding: 8px 14px; font-size: 12px; }
.uploads .row .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 5px; }
.bar { height: 6px; background: #eef1f6; border-radius: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); width: 0%; transition: width .15s; }
.bar.done > i { background: #21a35a; }
.bar.err > i { background: var(--danger); width: 100% !important; }

/* ---------- Modal ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(16,24,40,.5); display: flex; align-items: center;
  justify-content: center; z-index: 100; padding: 20px;
}
.modal {
  background: #fff; border-radius: 14px; width: 100%; max-width: 460px; box-shadow: var(--shadow);
  max-height: 85vh; overflow: auto;
}
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal header h3 { margin: 0; font-size: 16px; flex: 1; }
.modal .body { padding: 18px 20px; }
.modal .foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; }

.user-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.user-row .avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; }
.user-row .u-main { flex: 1; }
.user-row .u-main .un { font-weight: 600; }
.user-row .u-main .ue { font-size: 12px; color: var(--muted); }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 20px; background: #eef2f9; color: var(--muted); }
.tag.admin { background: #e8f0ff; color: var(--brand); }

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.9); z-index: 200; display: flex;
  align-items: center; justify-content: center; flex-direction: column;
}
.lightbox img, .lightbox video { max-width: 92vw; max-height: 82vh; border-radius: 6px; }
.lightbox .lb-name { color: #fff; margin-top: 14px; font-size: 14px; }
.lightbox .lb-close { position: absolute; top: 16px; right: 20px; color: #fff; font-size: 30px; background: none; border: none; }
.lightbox .lb-dl { position: absolute; top: 18px; right: 66px; color: #fff; font-size: 14px; background: rgba(255,255,255,.15); border: none; border-radius: 8px; padding: 8px 12px; }

@media (max-width: 560px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
  .uploads { left: 12px; right: 12px; width: auto; }
}
