:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --text: #1c2430;
  --muted: #667085;
  --line: #e4e8ef;
  --hover: #eef2f8;
  --sel: #dbe7ff;
  --sel-line: #9bbcff;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --danger: #dc2626;
  --shadow: 0 10px 30px rgba(16, 24, 40, .14), 0 2px 6px rgba(16, 24, 40, .06);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --panel: #1a1e26;
    --text: #e7eaf0;
    --muted: #98a2b3;
    --line: #2a303b;
    --hover: #232934;
    --sel: #1f3463;
    --sel-line: #3d64c4;
    --accent: #4f83ff;
    --danger: #f05252;
    --shadow: 0 10px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
svg { width: 20px; height: 20px; flex: none; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: inherit; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 14px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--panel); white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  border: 0; background: transparent; color: var(--muted); flex: none;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
select {
  height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); padding: 0 8px;
}

/* ---------- login ---------- */
#login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 340px; text-align: center; background: var(--panel); border: 1px solid var(--line);
  border-radius: 24px; padding: 32px 24px 24px; box-shadow: var(--shadow);
}
.login-logo svg { width: 64px; height: 64px; }
.login-card h1 { margin: 6px 0 2px; font-size: 22px; }
.login-sub { margin: 0; color: var(--muted); }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: 22px 0 6px; min-height: 16px; }
.pin-dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--muted); transition: .15s; }
.pin-dots i.on { background: var(--accent); border-color: var(--accent); transform: scale(1.1); }
.pin-dots.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.login-err { min-height: 20px; margin: 4px 0 8px; color: var(--danger); font-size: 13px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.keypad button {
  height: 60px; border-radius: 16px; border: 1px solid var(--line); background: var(--bg);
  font-size: 22px; font-weight: 500; display: grid; place-items: center; transition: transform .05s;
}
.keypad button:hover { background: var(--hover); }
.keypad button:active { transform: scale(.95); }
.keypad button.ok { background: var(--accent); border-color: var(--accent); color: #fff; }
.keypad svg { width: 24px; height: 24px; }

/* ---------- layout ---------- */
#app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--panel);
  border-bottom: 1px solid var(--line); flex: none;
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font-weight: 600; font-size: 18px; width: 228px; flex: none; }
.brand svg { width: 32px; height: 32px; }
.search {
  flex: 1; max-width: 640px; display: flex; align-items: center; gap: 10px; height: 42px; padding: 0 14px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 21px; color: var(--muted);
}
.search:focus-within { border-color: var(--accent); background: var(--panel); }
.search input { flex: 1; border: 0; outline: 0; background: transparent; min-width: 0; color: var(--text); }
#logoutBtn { margin-left: auto; }

.layout { flex: 1; display: flex; min-height: 0; }
.sidebar {
  width: 260px; flex: none; padding: 14px 12px; display: flex; flex-direction: column; gap: 10px;
  overflow-y: auto; background: var(--panel); border-right: 1px solid var(--line);
}
.new-btn { height: 44px; padding: 0 20px 0 16px; border-radius: 14px; box-shadow: 0 2px 6px rgba(37, 99, 235, .3); font-weight: 600; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: 10px; color: inherit; text-decoration: none;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis; border: 1px solid transparent;
}
.nav-item span { overflow: hidden; text-overflow: ellipsis; }
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--sel); font-weight: 600; }
.nav-item.drop { border-color: var(--accent); background: var(--sel); }
.nav-folders .nav-item { padding-left: 28px; color: var(--muted); }
.nav-folders .nav-item svg { width: 18px; height: 18px; color: #e0a526; }
.storage { margin-top: auto; padding: 12px; color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); }
.storage b { color: var(--text); }
.scrim { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.toolbar { display: flex; align-items: center; gap: 10px; padding: 12px 20px 8px; flex-wrap: wrap; }
.crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; flex: 1; min-width: 0; font-size: 18px; }
.crumbs a {
  color: inherit; text-decoration: none; padding: 4px 10px; border-radius: 8px; border: 1px solid transparent;
  max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.crumbs a:hover { background: var(--hover); }
.crumbs a:last-child { font-weight: 600; }
.crumbs a.drop { border-color: var(--accent); background: var(--sel); }
.crumbs .sep { color: var(--muted); }
.tools { display: flex; align-items: center; gap: 6px; }

.selbar {
  display: flex; align-items: center; gap: 8px; margin: 0 20px 6px; padding: 4px 8px; border-radius: 22px;
  background: var(--sel); flex-wrap: wrap;
}
.selbar #selCount { font-weight: 600; margin-right: 8px; }
.sel-actions { display: flex; gap: 2px; flex-wrap: wrap; }
.sel-actions .btn { height: 32px; padding: 0 10px; }

.content { flex: 1; overflow-y: auto; padding: 6px 20px 100px; position: relative; }

/* ---------- items: grid ---------- */
.items.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.item {
  position: relative; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel);
  user-select: none; -webkit-user-select: none; cursor: default; outline: none;
}
.item:hover { background: var(--hover); }
.item:focus-visible { border-color: var(--accent); }
.item.selected { background: var(--sel); border-color: var(--sel-line); }
.item.drop { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; background: var(--sel); }
.item.dragging { opacity: .45; }
.grid .item { display: flex; flex-direction: column; padding: 8px; }
.grid .thumb { aspect-ratio: 4 / 3; border-radius: 8px; display: grid; place-items: center; overflow: hidden; background: var(--bg); }
.grid .item.folder .thumb { background: transparent; }
.grid .thumb svg { width: 56px; height: 56px; }
.grid .item.folder .thumb svg { width: 72px; height: 72px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.grid .name { margin-top: 8px; padding: 0 4px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid .meta { padding: 0 4px; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid .meta .m-date { display: none; }
.check {
  position: absolute; top: 10px; left: 10px; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--muted);
  background: var(--panel); display: grid; place-items: center; opacity: 0; transition: opacity .1s; z-index: 1;
}
.check svg { width: 14px; height: 14px; color: #fff; opacity: 0; }
.item:hover .check, .has-sel .check, .touch .check { opacity: 1; }
.item.selected .check { background: var(--accent); border-color: var(--accent); }
.item.selected .check svg { opacity: 1; }
.more {
  position: absolute; top: 6px; right: 6px; width: 30px; height: 30px; background: var(--panel); opacity: 0;
}
.item:hover .more, .touch .more { opacity: 1; }
.grid .item .more { box-shadow: 0 1px 3px rgba(0, 0, 0, .15); }

/* ---------- items: list ---------- */
.items.list { display: flex; flex-direction: column; }
.list-head, .list .item {
  display: grid; grid-template-columns: 36px minmax(0, 1fr) 160px 100px 40px; align-items: center; gap: 8px;
}
.list-head { padding: 6px 8px; color: var(--muted); font-size: 12px; font-weight: 600; border-bottom: 1px solid var(--line); position: sticky; top: -6px; background: var(--bg); z-index: 2; }
.list-head span { cursor: pointer; }
.list-head span:hover { color: var(--text); }
.list .item { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: transparent; padding: 6px 8px; min-height: 48px; }
.list .item:hover { background: var(--hover); }
.list .item.selected { background: var(--sel); }
.list .thumb { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 6px; overflow: hidden; }
.list .thumb svg { width: 28px; height: 28px; }
.list .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.list .name small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.name small.mob { display: none; }
.grid .name small.loc { font-size: 12px; color: var(--muted); font-weight: 400; overflow: hidden; text-overflow: ellipsis; display: block; }
.list .meta { display: contents; color: var(--muted); font-size: 13px; }
.list .meta span { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .meta .m-size { text-align: right; }
.list .meta .m-dot { display: none; }
.grid .tw { display: contents; }
.list .tw { position: relative; width: 32px; height: 32px; }
.list .tw .check { top: 5px; left: 5px; }
.list .item:hover .thumb, .list .item.selected .thumb, .has-sel .list .thumb { opacity: 0; }
.list .more { position: static; opacity: .0; background: transparent; }
.list .item:hover .more, .touch .list .more { opacity: 1; }

.empty { display: grid; place-items: center; text-align: center; color: var(--muted); padding: 60px 20px; }
.empty > div > svg { width: 96px; height: 96px; color: var(--line); margin-bottom: 12px; }
.empty strong { display: block; color: var(--text); font-size: 17px; margin-bottom: 4px; }
.empty .btn { margin: 16px 4px 0; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 50%, transparent); }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- drop overlay ---------- */
.drop-overlay {
  position: absolute; inset: 8px; border: 3px dashed var(--accent); border-radius: 18px; z-index: 20;
  background: color-mix(in srgb, var(--accent) 10%, transparent); display: none; place-items: center; pointer-events: none;
}
.drop-overlay.show { display: grid; }
.drop-box { background: var(--accent); color: #fff; padding: 18px 28px; border-radius: 16px; display: flex; flex-direction: column; align-items: center; gap: 6px; box-shadow: var(--shadow); }
.drop-box svg { width: 36px; height: 36px; }
.drop-box span { opacity: .9; font-size: 13px; }

/* ---------- context menu ---------- */
.menu {
  position: fixed; z-index: 60; min-width: 210px; padding: 6px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow);
}
.menu button {
  width: 100%; display: flex; align-items: center; gap: 12px; padding: 8px 12px; border: 0; background: transparent;
  border-radius: 8px; text-align: left;
}
.menu button:hover, .menu button:focus-visible { background: var(--hover); outline: none; }
.menu button.danger { color: var(--danger); }
.menu button svg { color: var(--muted); }
.menu button.danger svg { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

/* ---------- modal ---------- */
.modal-wrap { position: fixed; inset: 0; z-index: 70; background: rgba(10, 14, 20, .45); display: grid; place-items: center; padding: 16px; }
.modal {
  width: 100%; max-width: 440px; background: var(--panel); border-radius: 18px; padding: 22px; box-shadow: var(--shadow);
  max-height: calc(100vh - 32px); display: flex; flex-direction: column;
}
.modal h2 { margin: 0 0 12px; font-size: 18px; }
.modal p { margin: 0 0 12px; color: var(--muted); overflow-wrap: anywhere; }
.modal input[type=text] {
  width: 100%; height: 42px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); outline: 0;
}
.modal input[type=text]:focus { border-color: var(--accent); }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.picker { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.picker-crumbs { padding: 8px 10px; border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 2px; align-items: center; font-size: 13px; }
.picker-crumbs a { color: var(--accent); cursor: pointer; padding: 2px 4px; border-radius: 6px; }
.picker-crumbs a:hover { background: var(--hover); }
.picker-list { overflow-y: auto; height: 280px; }
.picker-list button {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 0; background: transparent; text-align: left;
  border-bottom: 1px solid var(--line);
}
.picker-list button:hover { background: var(--hover); }
.picker-list button:disabled { opacity: .45; cursor: not-allowed; }
.picker-list svg { color: #e0a526; }
.picker-list .none { padding: 30px; text-align: center; color: var(--muted); }
.link-box { display: flex; gap: 8px; }
.link-box input { flex: 1; }

/* ---------- uploads ---------- */
.uploads {
  position: fixed; right: 20px; bottom: 20px; width: 380px; max-width: calc(100vw - 32px); z-index: 50;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden;
}
.up-head { display: flex; align-items: center; gap: 4px; padding: 8px 8px 8px 16px; background: var(--bg); font-weight: 600; }
.up-head span { flex: 1; }
.uploads.min .up-list { display: none; }
.uploads.min #upToggle svg { transform: rotate(180deg); }
.up-list { max-height: 300px; overflow-y: auto; }
.up-row { display: grid; grid-template-columns: 28px minmax(0, 1fr) 32px; gap: 10px; align-items: center; padding: 8px 8px 8px 14px; border-top: 1px solid var(--line); }
.up-row .thumb svg { width: 26px; height: 26px; }
.up-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.up-sub { font-size: 12px; color: var(--muted); }
.up-sub.err { color: var(--danger); }
.bar { height: 4px; background: var(--line); border-radius: 2px; margin-top: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.up-row.done .bar i { background: #16a34a; }
.up-row .ok-mark { color: #16a34a; }

/* ---------- preview ---------- */
.preview { position: fixed; inset: 0; z-index: 80; background: rgba(8, 10, 14, .94); color: #fff; display: flex; flex-direction: column; }
.pv-head { display: flex; align-items: center; gap: 6px; padding: 8px 12px; }
.pv-head .icon-btn { color: #dfe3ea; }
.pv-head .icon-btn:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.pv-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pv-body { flex: 1; min-height: 0; display: grid; place-items: center; padding: 0 64px 24px; }
.pv-body img, .pv-body video { max-width: 100%; max-height: 100%; border-radius: 6px; }
.pv-body iframe { width: 100%; height: 100%; border: 0; background: #fff; border-radius: 6px; }
.pv-body audio { width: min(520px, 100%); }
.pv-body pre {
  width: 100%; height: 100%; margin: 0; overflow: auto; background: #151922; color: #e6e9ef; padding: 18px; border-radius: 10px;
  font: 13px/1.55 ui-monospace, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere;
}
.pv-none { text-align: center; }
.pv-none svg { width: 96px; height: 96px; }
.pv-none p { color: #aab2c0; }
.pv-nav {
  position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 48px; border-radius: 50%; border: 0;
  background: rgba(255, 255, 255, .1); color: #fff; display: grid; place-items: center;
}
.pv-nav:hover { background: rgba(255, 255, 255, .22); }
.pv-nav.prev { left: 10px; }
.pv-nav.next { right: 10px; }

/* ---------- toasts ---------- */
.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: #1f2937; color: #fff; padding: 10px 18px; border-radius: 10px; box-shadow: var(--shadow); animation: up .2s; max-width: calc(100vw - 32px); }
.toast.err { background: var(--danger); }
@keyframes up { from { transform: translateY(10px); opacity: 0; } }

.fab {
  position: fixed; right: 20px; bottom: 20px; width: 56px; height: 56px; border-radius: 18px; border: 0; z-index: 30;
  background: var(--accent); color: #fff; box-shadow: 0 6px 16px rgba(37, 99, 235, .45); display: grid; place-items: center;
}
.fab svg { width: 26px; height: 26px; }
.only-mobile { display: none; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .only-mobile { display: grid; }
  .hide-mobile { display: none; }
  .brand { width: auto; }
  .brand span { display: none; }
  .topbar { padding: 8px 12px; gap: 6px; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 65; transform: translateX(-100%); transition: transform .2s;
    box-shadow: var(--shadow); width: 280px;
  }
  .sidebar.open { transform: none; }
  .scrim.show { display: block; position: fixed; inset: 0; z-index: 64; background: rgba(0, 0, 0, .35); }
  .toolbar { padding: 10px 16px 6px; }
  .crumbs { font-size: 16px; flex-basis: 100%; order: 2; }
  .tools { margin-left: auto; }
  .content { padding: 4px 16px 100px; }
  .selbar { margin: 0 16px 6px; }
  .sel-actions .btn span { display: none; }
  .items.grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
  .list-head, .list .item { grid-template-columns: 36px minmax(0, 1fr) 40px; }
  .list-head .h-date, .list-head .h-size { display: none; }
  .list .meta .m-date, .list .meta .m-size { display: none; }
  .list .name small.mob { display: block; }
  .pv-body { padding: 0 8px 12px; }
  .pv-nav { display: none; }
  .uploads { right: 16px; bottom: 88px; }
}
