:root {
  --bg: #f6f7fb; --panel: #ffffff; --panel-2: #f1f3f9; --border: #e3e6ef; --text: #1d2130; --muted: #6b7288;
  --accent: #4f46e5; --accent-2: #eef0ff; --accent-text: #fff; --danger: #dc2626; --danger-bg: #fdecec;
  --ok: #16a34a; --row-hover: #f5f6fd; --row-sel: #e9ebff; --shadow: 0 10px 30px rgba(20, 24, 50, .12);
  --folder: #f5b73b; --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1117; --panel: #171a23; --panel-2: #1e2230; --border: #2a2f3f; --text: #e6e8f0; --muted: #8d94ab;
    --accent: #7c74ff; --accent-2: #25244a; --danger: #f87171; --danger-bg: #3a1d20; --ok: #4ade80;
    --row-hover: #1d2130; --row-sel: #262a4a; --shadow: 0 10px 30px rgba(0, 0, 0, .5); --folder: #f0b43c;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1117; --panel: #171a23; --panel-2: #1e2230; --border: #2a2f3f; --text: #e6e8f0; --muted: #8d94ab;
  --accent: #7c74ff; --accent-2: #25244a; --danger: #f87171; --danger-bg: #3a1d20; --ok: #4ade80;
  --row-hover: #1d2130; --row-sel: #262a4a; --shadow: 0 10px 30px rgba(0, 0, 0, .5); --folder: #f0b43c;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased;
}
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
button { font: inherit; color: inherit; }
input { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel); cursor: pointer; white-space: nowrap; font-weight: 500;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--panel-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-bg); border-color: var(--danger); }
.btn.danger.solid { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.block { width: 100%; justify-content: center; height: 42px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; border: 0;
  background: transparent; cursor: pointer; color: var(--muted);
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-bg); }
.icon-btn.on { color: var(--accent); background: var(--accent-2); }

/* login */
.login-body { display: grid; place-items: center; padding: 16px;
  background: radial-gradient(1200px 600px at 10% -10%, var(--accent-2), transparent), var(--bg); }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; padding: 36px 28px; box-shadow: var(--shadow); text-align: center; }
.login-logo { color: var(--accent); margin-bottom: 8px; }
.login-logo svg { width: 48px; height: 48px; stroke: none; }
.login-card h1 { margin: 4px 0; font-size: 22px; }
.login-card form { margin-top: 22px; display: grid; gap: 12px; }
.pw-wrap { position: relative; }
.pw-wrap input { width: 100%; height: 44px; padding: 0 44px 0 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel-2); outline: none; }
.pw-wrap input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-2); }
.pw-wrap .icon-btn { position: absolute; right: 5px; top: 5px; }
.error { color: var(--danger); min-height: 20px; margin: 0; }
.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* app layout */
.app { display: flex; flex-direction: column; height: 100%; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; font-size: 16px; white-space: nowrap; }
.brand .logo { width: 28px; height: 28px; stroke: none; color: var(--accent); }
.brand small { font-weight: 400; color: var(--muted); font-size: 13px; }
.search { flex: 1; max-width: 420px; margin-left: auto; position: relative; }
.search svg { position: absolute; left: 10px; top: 9px; color: var(--muted); width: 16px; height: 16px; }
.search input { width: 100%; height: 34px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel-2); padding: 0 12px 0 32px; outline: none; }
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-2); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 16px; }
.crumbs { display: flex; align-items: center; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; height: 36px; padding: 0 6px; }
.crumbs::-webkit-scrollbar { display: none; }
.crumbs button { border: 0; background: none; padding: 4px 7px; border-radius: 6px; cursor: pointer; white-space: nowrap; color: var(--muted); display: inline-flex; align-items: center; gap: 5px; }
.crumbs button:hover { background: var(--panel-2); color: var(--text); }
.crumbs button:last-of-type { color: var(--text); font-weight: 600; }
.crumbs .sep { color: var(--muted); opacity: .6; }
.crumbs .edit { margin-left: auto; }
.crumbs input { flex: 1; border: 0; outline: none; background: transparent; height: 100%; font-family: ui-monospace, monospace; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: 42px; z-index: 30; min-width: 190px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow); padding: 6px; }
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; padding: 8px 10px; border-radius: 6px; cursor: pointer; text-align: left; }
.menu button:hover { background: var(--panel-2); }

.selbar { display: flex; align-items: center; gap: 8px; margin: 0 16px 10px; padding: 8px 12px; border-radius: 10px;
  background: var(--accent-2); border: 1px solid var(--accent); animation: slide .15s ease-out; }
.selbar .count { font-weight: 600; margin-right: auto; }
@keyframes slide { from { opacity: 0; transform: translateY(-4px); } }

.content { flex: 1; overflow: auto; margin: 0 16px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); position: relative; }
table { width: 100%; border-collapse: collapse; }
thead th { position: sticky; top: 0; z-index: 2; background: var(--panel); text-align: left; font-weight: 600; font-size: 12px;
  text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--border); user-select: none; }
thead th.sortable { cursor: pointer; }
thead th.sortable:hover { color: var(--text); }
thead th .arrow { font-size: 10px; margin-left: 3px; }
tbody tr { border-bottom: 1px solid var(--border); cursor: default; }
tbody tr:last-child { border-bottom: 0; }
tbody tr:hover { background: var(--row-hover); }
tbody tr.selected { background: var(--row-sel); }
td { padding: 7px 12px; vertical-align: middle; white-space: nowrap; }
td.name { width: 100%; max-width: 0; }
.name-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.name-cell .ico { width: 22px; height: 22px; stroke-width: 1.7; }
.name-cell a { color: var(--text); text-decoration: none; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.name-cell a:hover { color: var(--accent); text-decoration: underline; }
.name-cell .dot { opacity: .72; }
.link-target { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.col-check { width: 36px; padding-right: 0; }
.col-size, .col-date, .col-mode { color: var(--muted); font-variant-numeric: tabular-nums; }
.col-mode { font-family: ui-monospace, monospace; font-size: 12px; }
.row-actions { display: flex; gap: 2px; justify-content: flex-end; opacity: 0; transition: opacity .1s; }
tr:hover .row-actions, tr.selected .row-actions, .row-actions:focus-within { opacity: 1; }
.row-actions .icon-btn { width: 30px; height: 30px; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; margin: 0; vertical-align: middle; }
.ico.folder { color: var(--folder); fill: color-mix(in srgb, var(--folder) 30%, transparent); }
.ico.image { color: #0ea5e9; } .ico.video { color: #db2777; } .ico.audio { color: #9333ea; } .ico.archive { color: #b45309; }
.ico.code { color: #16a34a; } .ico.pdf { color: #dc2626; } .ico.text { color: var(--muted); } .ico.file { color: var(--muted); }

.empty { padding: 60px 20px; text-align: center; color: var(--muted); }
.empty svg { width: 48px; height: 48px; stroke-width: 1.3; margin-bottom: 8px; }
.statusbar { display: flex; justify-content: space-between; gap: 12px; padding: 8px 18px; color: var(--muted); font-size: 12px; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; background: color-mix(in srgb, var(--panel) 60%, transparent); z-index: 3; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* drop overlay */
.drop { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: color-mix(in srgb, var(--accent) 16%, transparent);
  backdrop-filter: blur(2px); pointer-events: none; }
.drop-box { border: 3px dashed var(--accent); border-radius: 18px; padding: 44px 60px; background: var(--panel); text-align: center; box-shadow: var(--shadow); }
.drop-box svg { width: 44px; height: 44px; color: var(--accent); }
.drop-box h2 { margin: 10px 0 4px; }

/* uploads panel */
.uploads { position: fixed; right: 16px; bottom: 16px; width: 380px; max-width: calc(100vw - 32px); z-index: 40; background: var(--panel);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
.uploads header { display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: var(--panel-2); font-weight: 600; }
.uploads header .title { flex: 1; }
.uploads .total { height: 3px; background: var(--border); }
.uploads .total div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.uploads ul { list-style: none; margin: 0; padding: 4px 0; max-height: 300px; overflow: auto; }
.uploads li { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 7px 12px; font-size: 13px; }
.uploads li .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uploads li .s { color: var(--muted); font-size: 12px; }
.uploads li .bar { grid-column: 1 / -1; height: 4px; border-radius: 2px; background: var(--border); overflow: hidden; }
.uploads li .bar div { height: 100%; background: var(--accent); width: 0; transition: width .15s; }
.uploads li.done .bar div { background: var(--ok); }
.uploads li.err .bar div { background: var(--danger); width: 100% !important; }
.uploads li.err .s { color: var(--danger); }
.uploads.collapsed ul { display: none; }

/* dialogs */
dialog { border: 1px solid var(--border); border-radius: 14px; padding: 0; background: var(--panel); color: var(--text); box-shadow: var(--shadow); width: min(440px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(10, 12, 20, .45); backdrop-filter: blur(2px); }
.dlg { padding: 22px; }
.dlg h3 { margin: 0 0 8px; font-size: 17px; }
.dlg p { margin: 0 0 12px; color: var(--muted); white-space: pre-line; word-break: break-word; }
.dlg input[type=text] { width: 100%; height: 40px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel-2); padding: 0 12px; outline: none; }
.dlg input[type=text]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-2); }
.dlg .list { max-height: 160px; overflow: auto; background: var(--panel-2); border-radius: 8px; padding: 8px 12px; margin: 0 0 12px; font-size: 13px; font-family: ui-monospace, monospace; }
.dlg .btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }

dialog.preview { width: min(1100px, calc(100vw - 32px)); height: min(86vh, 900px); }
dialog.preview[open] { display: flex; flex-direction: column; }
.preview header { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.preview header .t { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview .body { flex: 1; overflow: auto; display: grid; place-items: center; background: var(--panel-2); min-height: 0; }
.preview .body img, .preview .body video { max-width: 100%; max-height: 100%; object-fit: contain; }
.preview .body iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.preview .body pre { margin: 0; place-self: stretch; padding: 16px; font: 12.5px/1.55 ui-monospace, "SF Mono", Menlo, Consolas, monospace; white-space: pre; tab-size: 4; }
.preview .note { padding: 30px; text-align: center; color: var(--muted); }

/* toasts */
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: 20px; z-index: 60; display: grid; gap: 8px; justify-items: center; }
.toast { background: #1f2333; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); max-width: min(560px, calc(100vw - 32px)); animation: slide .2s ease-out; display: flex; gap: 8px; align-items: center; }
.toast.error { background: #b91c1c; }
.toast.ok svg { color: #4ade80; }

@media (max-width: 760px) {
  .col-mode, .col-date { display: none; }
  .brand small, .btn .lbl { display: none; }
  .btn { padding: 0 10px; }
  .row-actions { opacity: 1; }
  .row-actions .hide-sm { display: none; }
  .topbar { padding: 8px 12px; }
  .toolbar { padding: 10px 12px; }
  .crumbs { flex-basis: 100%; }
  .content { margin: 0 12px; }
  .selbar { margin: 0 12px 10px; }
  .uploads { right: 12px; bottom: 12px; }
  .toasts { bottom: auto; top: 12px; }
}
