:root {
  --bg: #0f1115; --bg2: #161922; --bg3: #1d2130; --line: #262b3a; --fg: #e6e8ee; --dim: #8b93a7;
  --acc: #6c8cff; --acc2: #4f6fe8; --ok: #3ecf8e; --warn: #f5a524; --bad: #f05d6c; --r: 10px;
  --shadow: 0 10px 40px rgba(0,0,0,.45);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root { --bg: #f6f7fb; --bg2: #ffffff; --bg3: #eef0f6; --line: #e1e4ee; --fg: #1b1f2a; --dim: #6a7185;
    --shadow: 0 10px 40px rgba(20,30,60,.15); color-scheme: light; }
}
* { box-sizing: border-box; }
/* default icon size; more specific rules (.fi, .logo, .empty …) override it */
svg { width: 18px; height: 18px; flex: none; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--fg); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--acc); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.dim { color: var(--dim); }
.small { font-size: 12px; }
.grow { flex: 1; }
.row { display: flex; align-items: center; gap: 8px; }
.wrap { flex-wrap: wrap; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--bg3);
  padding: 6px 10px; border-radius: 8px; cursor: pointer; white-space: nowrap; transition: .12s; min-height: 34px; }
.btn:hover { border-color: var(--acc); }
.btn.primary { background: var(--acc); border-color: var(--acc); color: #fff; }
.btn.primary:hover { background: var(--acc2); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--bg3); border-color: var(--line); }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg, .ico svg { width: 18px; height: 18px; flex: none; }
.input { width: 100%; padding: 7px 10px; min-height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); outline: none; }
.input:focus { border-color: var(--acc); }
label.chk { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; padding: 4px 0; }
label.chk input { margin-top: 3px; }

/* login */
.center { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.card { background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; padding: 26px; width: 100%; max-width: 380px; box-shadow: var(--shadow); }
.card h1 { margin: 0 0 4px; font-size: 22px; display: flex; gap: 10px; align-items: center; }
.card form { display: grid; gap: 12px; margin-top: 18px; }
.err { color: var(--bad); min-height: 1.2em; font-size: 13px; }
.sep { display: flex; align-items: center; gap: 10px; color: var(--dim); font-size: 12px; }
.sep::before, .sep::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.logo { width: 30px; height: 30px; color: var(--acc); }

/* layout */
.app { display: flex; flex-direction: column; height: 100%; }
header.top { display: flex; align-items: center; gap: 8px; padding: 6px 12px; min-height: 48px; border-bottom: 1px solid var(--line); background: var(--bg2); position: sticky; top: 0; z-index: 5; }
header.top .brand { font-weight: 650; display: flex; align-items: center; gap: 8px; font-size: 16px; }
.search { max-width: 340px; }
.toolbar { display: flex; gap: 6px; padding: 6px 12px; align-items: center; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.crumbs { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; min-width: 0; flex: 1; }
.crumbs a { padding: 4px 6px; white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; border-radius: 6px; color: var(--fg); display: inline-flex; align-items: center; }
.crumbs a:hover { background: var(--bg3); }
.crumbs span.s { color: var(--dim); }
main { flex: 1; overflow: auto; position: relative; }
.selbar { display: flex; gap: 6px; align-items: center; padding: 6px 12px; background: color-mix(in srgb, var(--acc) 14%, var(--bg2)); border-bottom: 1px solid var(--line); flex-wrap: wrap; }

/* file table */
table.files { width: 100%; border-collapse: collapse; }
table.files th { text-align: left; font-weight: 500; color: var(--dim); font-size: 12px; padding: 6px 10px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); cursor: pointer; user-select: none; z-index: 1; }
table.files td { vertical-align: middle; padding: 5px 10px; border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent); white-space: nowrap; }
table.files tr.f:hover td { background: var(--bg2); }
table.files tr.sel td { background: color-mix(in srgb, var(--acc) 16%, transparent) !important; }
table.files td.name { width: 100%; max-width: 0; overflow: hidden; text-overflow: ellipsis; }
table.files td.name a { vertical-align: middle; color: var(--fg); display: inline-flex; align-items: center; gap: 10px; max-width: 100%; }
table.files td.name a span { overflow: hidden; text-overflow: ellipsis; }
table.files td.c { width: 34px; padding-right: 0; }
table.files td.num, table.files th.num { text-align: right; color: var(--dim); }
td.act { width: 1%; }
td.act .btn { padding: 4px 6px; }
.fi { width: 20px; height: 20px; flex: none; }
.fi.dir { color: #f2b84b; }
.fi.img { color: #3ecf8e; } .fi.vid { color: #f05d6c; } .fi.aud { color: #c27bff; }
.fi.arc { color: #f5a524; } .fi.code { color: #6c8cff; } .fi.doc { color: #4fb3ff; } .fi.file { color: var(--dim); }
.badge { font-size: 11px; padding: 1px 6px; border-radius: 99px; background: var(--bg3); border: 1px solid var(--line); color: var(--dim); margin-left: 6px; }
.badge.share { color: var(--acc); border-color: color-mix(in srgb, var(--acc) 40%, transparent); }
.empty { padding: 60px 20px; text-align: center; color: var(--dim); }
.empty svg { width: 54px; height: 54px; opacity: .5; }


/* drop overlay */
.drop { position: fixed; inset: 0; background: color-mix(in srgb, var(--acc) 22%, transparent); border: 3px dashed var(--acc);
  display: grid; place-items: center; font-size: 22px; font-weight: 600; z-index: 50; pointer-events: none; }

/* modals */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal { background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; width: 100%; overflow-x: hidden; max-width: 520px; max-height: 92vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal.wide { max-width: 900px; }
.modal.full { max-width: 96vw; height: 92vh; display: flex; flex-direction: column; }
.modal header { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg2); z-index: 1; }
.modal header h3 { margin: 0; font-size: 16px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal .body { padding: 18px; display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
.modal.full .body { flex: 1; min-height: 0; padding: 0; display: flex; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
.preview { flex: 1; display: grid; place-items: center; overflow: auto; background: #000; }
.preview img, .preview video { max-width: 100%; max-height: 100%; }
.preview iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.preview audio { width: min(600px, 90%); }
textarea.editor { flex: 1; width: 100%; resize: none; border: 0; outline: none; background: var(--bg); padding: 14px; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; tab-size: 4; }
.list { display: grid; gap: 8px; }
.item { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex; gap: 10px; align-items: center; background: var(--bg); }
.item .main { flex: 1; min-width: 0; }
.item .main div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.linkbox { display: flex; gap: 6px; }
.linkbox input { font-family: ui-monospace, monospace; font-size: 12px; }
h4 { margin: 8px 0 0; font-size: 13px; color: var(--dim); text-transform: uppercase; letter-spacing: .04em; }
.tree { max-height: 340px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.tree a { display: flex; gap: 8px; align-items: center; padding: 6px 10px; color: var(--fg); }
.tree a:hover { background: var(--bg3); }

/* uploads panel */
.uploads { position: fixed; right: 16px; bottom: 16px; width: min(400px, calc(100vw - 32px)); background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); z-index: 30; overflow: hidden; }
.uploads header { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); font-weight: 600; }
.uploads .ul { max-height: 300px; overflow: auto; }
.up { padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: 13px; }
.up .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.bar { height: 5px; background: var(--bg3); border-radius: 9px; overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; width: 0; background: var(--acc); transition: width .2s; }
.up.done .bar i { background: var(--ok); }
.up.error .bar i { background: var(--bad); }
.up .btn { padding: 2px 6px; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 9px 16px; border-radius: 99px; z-index: 60; box-shadow: var(--shadow); font-weight: 500; max-width: 90vw; }
.toast.bad { background: var(--bad); color: #fff; }
.menu { position: fixed; z-index: 45; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 5px; min-width: 180px; }
.menu button { display: flex; gap: 10px; align-items: center; width: 100%; padding: 7px 10px; border: 0; background: none; border-radius: 6px; cursor: pointer; text-align: left; }
.menu button:hover { background: var(--bg3); }
.menu button.danger { color: var(--bad); }
.menu svg { width: 16px; height: 16px; }
.disk { font-size: 12px; color: var(--dim); }
.share-hero { padding: 28px 16px 8px; text-align: center; }
.share-hero h2 { margin: 6px 0; word-break: break-word; }
.dropzone { margin: 16px; border: 2px dashed var(--line); border-radius: 14px; padding: 34px 16px; text-align: center; color: var(--dim); cursor: pointer; transition: .15s; }
.dropzone:hover, .dropzone.on { border-color: var(--acc); color: var(--fg); background: color-mix(in srgb, var(--acc) 8%, transparent); }
.dropzone svg { width: 42px; height: 42px; }
.note { margin: 0 auto; max-width: 700px; white-space: pre-wrap; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; text-align: left; }
.container { max-width: 1000px; margin: 0 auto; }

/* meta line under file names: only on small screens */
.meta { display: none; font-size: 11.5px; color: var(--dim); margin-top: 1px; }
table.files td.name .nm { display: flex; flex-direction: column; min-width: 0; }
table.files td.name .nm > span:first-child { overflow: hidden; text-overflow: ellipsis; }
.crumbs { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
.crumbs::-webkit-scrollbar { display: none; }
.tools { display: flex; gap: 6px; align-items: center; }

/* ---------- tablet ---------- */
@media (max-width: 900px) {
  .btn .lbl { display: none; }
  .hide-md { display: none !important; }
}

/* ---------- phone ---------- */
@media (max-width: 640px) {
  body { font-size: 15px; }
  .hide-sm { display: none !important; }
  header.top { padding: 6px 8px; gap: 4px; }
  header.top .search { max-width: none; }
  header.top .btn.ghost { padding: 6px 8px; }
  .toolbar { padding: 6px 8px; row-gap: 4px; }
  .toolbar .crumbs { flex: 1 1 100%; order: -1; }
  .toolbar .tools { flex: 1; justify-content: space-between; }
  .toolbar .tools .btn { flex: 1; justify-content: center; }
  .selbar { padding: 6px 8px; gap: 4px; }
  .selbar .btn { padding: 6px 8px; }
  table.files td { padding: 7px 6px; }
  table.files td.c { width: 30px; padding-left: 10px; }
  table.files th { padding: 6px; }
  .meta { display: block; }
  .fi { width: 24px; height: 24px; }
  td.act .btn { padding: 6px; }
  .modal-bg { padding: 0; align-items: end; }
  .modal { max-width: none !important; max-height: 94vh; border-radius: 14px 14px 0 0; }
  .modal.full { height: 100%; max-height: 100vh; border-radius: 0; }
  .modal .body { padding: 14px; }
  .modal footer { padding: 10px 14px; }
  .modal footer .btn { flex: 1; justify-content: center; }
  .uploads { right: 0; bottom: 0; width: 100%; border-radius: 12px 12px 0 0; }
  .uploads .ul { max-height: 40vh; }
  .item { padding: 8px 10px; }
  .share-hero { padding: 18px 12px 4px; }
  .dropzone { margin: 12px; padding: 24px 12px; }
  .card { padding: 20px; }
  .menu { left: 0 !important; right: 0; top: auto !important; bottom: 0; border-radius: 14px 14px 0 0; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
  .menu button { padding: 12px 14px; font-size: 15px; }
  .menu-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 44; }
}
@media (min-width: 641px) { .hide-lg { display: none !important; } }
.share-hero > svg.fi { width: 44px; height: 44px; }
table.files td.c input, table.files th input { margin: 0; vertical-align: middle; }
@media (max-width: 640px) {
  .sharebar .crumbs { flex: 1 1 auto !important; order: 0 !important; }
  .share-hero > svg.fi { width: 38px; height: 38px; }
  .dropzone { padding: 18px 12px; }
  .dropzone svg { width: 32px; height: 32px; }
}

/* ---------- viewer ---------- */
.viewer { flex: 1; min-height: 0; display: flex; flex-direction: column; width: 100%; }
.viewer > .preview { flex: 1; min-height: 0; }
.viewer-msg { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 30px 16px; text-align: center; }
.viewer-msg > svg.fi { width: 56px; height: 56px; }
.vm-name { font-weight: 600; word-break: break-all; }
.preview img { object-fit: contain; cursor: zoom-in; }
.preview img.zoom { max-width: none; max-height: none; cursor: zoom-out; }
.preview.audio { display: flex; flex-direction: column; gap: 20px; background: var(--bg); }
.preview.audio > svg.fi { width: 72px; height: 72px; }
.cm-host { flex: 1; min-height: 0; overflow: hidden; display: flex; }
.cm-host > .cm-editor { flex: 1; height: 100%; }
.cm-host .cm-editor.cm-focused { outline: none; }
.btn.on { background: var(--bg3); border-color: var(--acc); }
.modal.full header { gap: 4px; padding: 8px 10px 8px 16px; }
.modal.full header h3 { font-size: 15px; }

/* markdown */
.md-scroll { flex: 1; overflow: auto; background: var(--bg); }
.md-body { max-width: 860px; margin: 0 auto; padding: 24px 28px 60px; line-height: 1.65; font-size: 15px; word-wrap: break-word; }
.md-body h1, .md-body h2 { border-bottom: 1px solid var(--line); padding-bottom: .3em; }
.md-body h1 { font-size: 1.9em; } .md-body h2 { font-size: 1.45em; } .md-body h3 { font-size: 1.2em; }
.md-body h1, .md-body h2, .md-body h3, .md-body h4 { margin: 1.4em 0 .6em; line-height: 1.25; }
.md-body > :first-child { margin-top: 0; }
.md-body code { font: .88em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--bg3); padding: .15em .4em; border-radius: 5px; }
.md-body pre { background: var(--bg2); border: 1px solid var(--line); padding: 12px 14px; border-radius: 8px; overflow: auto; line-height: 1.45; }
.md-body pre code { background: none; padding: 0; font-size: 13px; }
.md-body blockquote { margin: 0; padding: 0 1em; color: var(--dim); border-left: 3px solid var(--line); }
.md-body table { border-collapse: collapse; display: block; overflow: auto; }
.md-body th, .md-body td { border: 1px solid var(--line); padding: 6px 12px; }
.md-body tr:nth-child(2n) td { background: var(--bg2); }
.md-body img { max-width: 100%; border-radius: 6px; }
.md-body hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }
.md-body ul, .md-body ol { padding-left: 1.6em; }
.md-body li + li { margin-top: .25em; }
.md-body input[type=checkbox] { margin-right: 6px; }

/* settings */
.settings { display: grid; gap: 14px; min-width: 0; }
.set-card { border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: grid; gap: 10px; min-width: 0; background: var(--bg); }
.set-card h4 { margin: 0; }
.set-card p { margin: -4px 0 0; }
.set-card > .btn { justify-self: start; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; }
.item .main > div:first-child { display: flex; align-items: center; gap: 6px; }
.item > svg { width: 18px; height: 18px; color: var(--dim); }
.modal .body { min-width: 0; }
.list { min-width: 0; }

/* login */
.login-box { display: grid; gap: 10px; margin-top: 18px; }
.login-box form { display: grid; gap: 10px; margin: 0; }

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .set-card { padding: 12px; }
  .set-card > .btn { justify-self: stretch; justify-content: center; }
  .md-body { padding: 16px 16px 50px; font-size: 15px; }
  .modal.full header { padding: 6px 6px 6px 12px; }
  .modal.full header .btn { padding: 6px; }
}
.menu .submenu { border-left: 2px solid var(--line); margin: 2px 0 4px 18px; padding-left: 4px; }
.menu button.sub span { flex: 1; }
