:root {
  color-scheme: dark;
  --bg: #0f1115; --panel: #171a21; --panel2: #1e222b; --hover: #232833; --line: #262a33;
  --text: #e6e8ec; --muted: #8b93a1; --accent: #5b9dff; --accent-soft: #1d3357; --danger: #ff6b6b;
  --radius: 10px; --side: 240px;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted); } .small { font-size: 12px; } .err { color: var(--danger); min-height: 1.2em; margin: 0; }

.btn { border: 1px solid var(--line); background: var(--panel2); padding: 8px 14px; border-radius: 8px; cursor: pointer; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.icon-btn { background: none; border: 0; width: 34px; height: 34px; border-radius: 8px; cursor: pointer; font-size: 16px; display: inline-grid; place-items: center; flex: none; }
.icon-btn:hover { background: var(--hover); }
input[type=text], input[type=password], input[type=search], input[type=number], select, textarea {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(340px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 32px 28px; display: flex; flex-direction: column; gap: 12px; align-items: stretch; text-align: center; }
.login-card img { align-self: center; }
.login-card h1 { margin: 0 0 8px; font-size: 22px; }

/* layout */
.app { display: flex; height: 100%; }
.side { width: var(--side); flex: none; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 14px 10px; gap: 6px; }
.brand { display: flex; gap: 10px; align-items: center; font-weight: 700; font-size: 18px; padding: 4px 8px 10px; }
.new-wrap { padding: 0 4px 8px; }
.new { padding: 10px 18px; border-radius: 12px; font-size: 15px; box-shadow: 0 2px 8px #0006; }
.plus { font-size: 18px; margin-right: 4px; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a { display: flex; gap: 12px; align-items: center; padding: 8px 12px; border-radius: 999px; color: var(--text); text-decoration: none; }
.side nav a i { font-style: normal; width: 20px; text-align: center; }
.side nav a:hover { background: var(--hover); }
.side nav a.on { background: var(--accent-soft); color: #cfe0ff; font-weight: 600; }
.side nav a.drop-on { outline: 2px dashed var(--accent); }
.storage { margin-top: auto; padding: 12px; }
.storage .bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-bottom: 6px; }
.storage .bar span { display: block; height: 100%; background: var(--accent); width: 0; }
.logout { margin: 4px 12px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.top { display: flex; gap: 10px; align-items: center; padding: 10px 16px; }
.search { flex: 1; max-width: 720px; display: flex; align-items: center; gap: 8px; background: var(--panel2);
  border: 1px solid var(--line); border-radius: 999px; padding: 2px 6px 2px 14px; }
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; border: 0; background: none; padding: 8px 0; min-width: 0; }
.search select { border: 0; background: transparent; color: var(--muted); max-width: 110px; }
.bar2 { position: relative; display: flex; align-items: center; gap: 10px; padding: 4px 16px 8px; min-height: 44px; }
.crumbs { flex: 1; display: flex; align-items: center; gap: 2px; flex-wrap: wrap; font-size: 18px; min-width: 0; }
.crumbs a { color: var(--text); text-decoration: none; padding: 3px 8px; border-radius: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.crumbs a:hover, .crumbs a.drop-on { background: var(--hover); }
.crumbs .sep { color: var(--muted); }
.sortbox { display: flex; align-items: center; gap: 2px; }
.sortbox select { padding: 5px 8px; }

.selbar { position: absolute; inset: 2px 16px 6px; z-index: 5; display: flex; align-items: center; gap: 8px; padding: 0 8px; background: var(--accent-soft);
  border-radius: 999px; overflow: hidden; }
body.dragging .selbar { display: none !important; }
.selbar #selCount { white-space: nowrap; }
.sel-actions { display: flex; gap: 2px; margin-left: auto; flex-wrap: wrap; }

/* items */
.list { flex: 1; overflow: auto; padding: 4px 16px 90px; outline: none; user-select: none; -webkit-user-select: none; align-content: start; }
.list.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.section-label { grid-column: 1 / -1; color: var(--muted); font-size: 13px; font-weight: 600; margin: 6px 2px -2px; }
.item { position: relative; border-radius: var(--radius); cursor: pointer; }
.grid .item { background: var(--panel); border: 1px solid var(--line); display: flex; flex-direction: column; overflow: hidden; }
.grid .item:hover { background: var(--hover); }
.grid .item .thumb { aspect-ratio: 4/3; display: grid; place-items: center; background: var(--panel2); font-size: 44px; overflow: hidden; margin: 0 6px; border-radius: 8px; }
.grid .item .thumb img { width: 100%; height: 100%; object-fit: cover; }
.grid .item .meta { display: flex; align-items: center; gap: 8px; padding: 10px 10px; order: -1; }
.grid .item.folder { flex-direction: row; }
.grid .item.folder .thumb { display: none; }
.grid .item.folder .meta { flex: 1; }
.grid .item:not(.folder) { padding-bottom: 6px; }
.item .ic { font-size: 18px; flex: none; width: 22px; text-align: center; }
.item .nm { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.item .more { opacity: .7; width: 28px; height: 28px; font-size: 15px; }
.item .star { color: #ffd166; font-size: 12px; }
.item.sel { background: var(--accent-soft) !important; border-color: var(--accent) !important; }
.item.drop-on { outline: 2px dashed var(--accent); outline-offset: -2px; }
.item.cut { opacity: .5; }

.list.rows { display: block; }
.rows .head, .rows .item { display: grid; grid-template-columns: 1fr 160px 110px 40px; align-items: center; gap: 10px; padding: 0 10px; }
.rows .head { color: var(--muted); font-size: 12px; font-weight: 600; height: 34px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); z-index: 1; }
.rows .item { height: 46px; border-bottom: 1px solid var(--line); border-radius: 0; }
.rows .item:hover { background: var(--hover); }
.rows .item .meta { display: flex; gap: 12px; align-items: center; min-width: 0; }
.rows .item .thumb { display: none; }
.rows .item .c2, .rows .item .c3 { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rows .item .loc { color: var(--muted); font-size: 12px; margin-left: 8px; }
.rows.trashview .head, .rows.trashview .item { grid-template-columns: 1fr 160px 110px 40px; }

.empty { position: absolute; inset: 140px 0 0; display: grid; place-items: center; text-align: center; color: var(--muted); pointer-events: none; padding: 20px; }
.empty big { display: block; font-size: 54px; margin-bottom: 8px; }
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 4px; }
.drop-hint { position: absolute; inset: 8px; border: 3px dashed var(--accent); border-radius: 16px; background: #5b9dff22;
  display: grid; place-items: end center; pointer-events: none; z-index: 20; padding-bottom: 40px; }
.drop-hint div { background: var(--accent); color: #fff; padding: 12px 22px; border-radius: 999px; font-size: 15px; }

/* context menu */
.menu { position: fixed; z-index: 60; min-width: 220px; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px;
  padding: 6px 0; box-shadow: 0 10px 30px #000a; }
.menu button { display: flex; gap: 12px; width: 100%; text-align: left; background: none; border: 0; padding: 8px 16px; cursor: pointer; }
.menu button:hover { background: var(--hover); }
.menu button i { font-style: normal; width: 18px; text-align: center; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }
.menu .danger { color: var(--danger); }

/* dialogs */
.dlg { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(460px, calc(100% - 24px)); }
.dlg::backdrop { background: #000a; }
.dlg form { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.dlg h2 { margin: 0; font-size: 18px; }
.dlg .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.dlg input[type=text] { width: 100%; }
.tree { max-height: 320px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 4px; }
.tree div { padding: 6px 8px; border-radius: 6px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree div:hover { background: var(--hover); }
.tree div.on { background: var(--accent-soft); }
.tree div.off { opacity: .4; pointer-events: none; }
.sharebox { display: flex; gap: 6px; }
.sharebox input { flex: 1; min-width: 0; }
.share-list { display: flex; flex-direction: column; gap: 6px; max-height: 200px; overflow: auto; }
.share-list div { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.share-list code { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.details { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; font-size: 13px; }
.details dt { color: var(--muted); } .details dd { margin: 0; word-break: break-all; }

/* uploads */
.uploads { position: fixed; right: 16px; bottom: 16px; width: min(380px, calc(100% - 32px)); background: var(--panel2); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 10px 30px #000a; z-index: 50; overflow: hidden; }
.uploads header { display: flex; align-items: center; gap: 4px; padding: 8px 8px 8px 14px; background: var(--panel); font-weight: 600; }
.uploads header span { flex: 1; }
.uploads ul { list-style: none; margin: 0; padding: 0; max-height: 280px; overflow: auto; }
.uploads.min ul { display: none; }
.uploads li { padding: 8px 14px; border-top: 1px solid var(--line); font-size: 13px; }
.uploads li .ln { display: flex; gap: 8px; align-items: center; }
.uploads li .ln span:first-child { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uploads li .pb { height: 4px; background: var(--line); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.uploads li .pb i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.uploads li.done .pb i { background: #3ecf8e; } .uploads li.fail .pb i { background: var(--danger); width: 100% !important; }
.uploads li .x { background: none; border: 0; color: var(--muted); cursor: pointer; }

/* viewer */
.viewer { position: fixed; inset: 0; z-index: 70; background: #0a0b0e; display: flex; flex-direction: column; }
.viewer header { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: #0008; }
.vname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.vtools { display: flex; gap: 4px; }
.vbody { flex: 1; min-height: 0; display: grid; place-items: center; padding: 12px; overflow: auto; }
.vbody img, .vbody video { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px; }
.vbody audio { width: min(600px, 100%); }
.vbody iframe { width: 100%; height: 100%; border: 0; background: #fff; border-radius: 4px; }
.vbody .textwrap { width: min(1100px, 100%); height: 100%; display: flex; flex-direction: column; gap: 8px; }
.vbody textarea, .vbody pre { flex: 1; width: 100%; margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px;
  font: 13px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; color: var(--text); overflow: auto; white-space: pre; tab-size: 4; resize: none; }
.vbody .doc { width: min(820px, 100%); height: 100%; overflow: auto; background: #fff; color: #222; border-radius: 6px; padding: 40px 48px; place-self: start center; }
.vbody .doc p { margin: 0 0 .7em; } .vbody .doc h3 { margin: 1em 0 .5em; }
.vbody .sheet { width: 100%; height: 100%; display: flex; flex-direction: column; place-self: stretch; }
.sheet .tabs { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 6px; }
.sheet .tabs button { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; cursor: pointer; white-space: nowrap; }
.sheet .tabs button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.sheet .tw { flex: 1; overflow: auto; background: var(--panel); border-radius: 6px; }
.sheet table { border-collapse: collapse; font-size: 13px; }
.sheet td, .sheet th { border: 1px solid var(--line); padding: 3px 8px; white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.sheet th { background: var(--panel2); color: var(--muted); position: sticky; top: 0; font-weight: 500; }
.sheet td.rn { color: var(--muted); background: var(--panel2); position: sticky; left: 0; text-align: right; }
.vbody .nopv { text-align: center; color: var(--muted); }
.vbody .nopv big { font-size: 72px; display: block; }
.vnav { position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 72px; border: 0; border-radius: 10px; background: #0007; color: #fff;
  font-size: 40px; cursor: pointer; }
.vnav:hover { background: #000c; } .vnav.prev { left: 10px; } .vnav.next { right: 10px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #2d3340; color: #fff; padding: 10px 18px;
  border-radius: 8px; z-index: 90; box-shadow: 0 6px 20px #0008; display: flex; gap: 14px; align-items: center; max-width: calc(100% - 32px); }
.toast button { background: none; border: 0; color: var(--accent); font-weight: 600; cursor: pointer; }
.scrim { display: none; }
.only-mobile { display: none; }

@media (max-width: 760px) {
  .only-mobile { display: inline-grid; }
  .side { position: fixed; z-index: 40; inset: 0 auto 0 0; transform: translateX(-105%); transition: transform .2s; box-shadow: 0 0 30px #000; }
  .side.open { transform: none; }
  .scrim.open { display: block; position: fixed; inset: 0; background: #0008; z-index: 39; }
  .top { padding: 8px 10px; }
  .search select { display: none; }
  .bar2 { padding: 2px 10px 6px; }
  .crumbs { font-size: 16px; }
  .list { padding: 4px 10px 100px; }
  .list.grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
  .rows .head { display: none; }
  .rows .item { grid-template-columns: 1fr 40px; height: 56px; }
  .rows .item .c2, .rows .item .c3 { display: none; }
  .rows .item .loc { display: none; }
  .selbar { inset: 0 10px 4px; }
  .new-wrap { display: none; }
  .fab { position: fixed; right: 18px; bottom: 22px; width: 58px; height: 58px; border-radius: 18px; z-index: 30; font-size: 28px; padding: 0; }
  .vnav { display: none; }
  .vbody .doc { padding: 20px; }
  .menu.sheetmenu { left: 0 !important; right: 0; top: auto !important; bottom: 0; border-radius: 14px 14px 0 0; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .menu.sheetmenu button { padding: 12px 20px; }
}
@media (min-width: 761px) { .fab { display: none; } }
