:root {
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-2: #f1f3f7;
  --hover: #eef1f6;
  --border: #e3e6ec;
  --text: #1c2230;
  --text-2: #5b6474;
  --text-3: #8a93a3;
  --accent: #2f6fed;
  --accent-soft: #e4ecfd;
  --accent-text: #1d4fc4;
  --danger: #d93a3a;
  --shadow: 0 1px 2px rgb(16 24 40 / .06), 0 8px 24px rgb(16 24 40 / .10);
  --shadow-lg: 0 24px 64px rgb(16 24 40 / .22);
  --radius: 12px;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --surface: #191d25;
    --surface-2: #20252f;
    --hover: #232937;
    --border: #2b3140;
    --text: #e6e9ef;
    --text-2: #a3abba;
    --text-3: #6f7889;
    --accent: #6f9bff;
    --accent-soft: #22304f;
    --accent-text: #a9c2ff;
    --danger: #ff6b6b;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px rgb(0 0 0 / .35);
    --shadow-lg: 0 24px 64px rgb(0 0 0 / .5);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input { font: inherit; color: inherit; }
svg { display: block; flex: none; }
[hidden] { display: none !important; }

#app {
  display: grid;
  grid-template: "top top" 64px "side main" 1fr / 248px 1fr;
  height: 100vh;
}
#app.booting > * { visibility: hidden; }

/* Top bar */
.topbar { grid-area: top; display: flex; align-items: center; gap: 12px; padding: 0 16px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-size: 20px; font-weight: 600; letter-spacing: -.01em; width: 220px; }
.brand img { width: 32px; height: 32px; }
.topbar .menu-toggle { display: none; }
.search { flex: 1; max-width: 720px; display: flex; align-items: center; gap: 10px; height: 46px; padding: 0 16px; background: var(--surface-2); border-radius: 23px; transition: background .15s, box-shadow .15s; }
.search:focus-within { background: var(--surface); box-shadow: var(--shadow); }
.search input { flex: 1; border: 0; outline: 0; background: none; font-size: 15px; }
.search-icon { color: var(--text-2); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 600; font-size: 15px; display: grid; place-items: center; }

/* Sidebar */
.sidebar { grid-area: side; padding: 8px 12px 16px; display: flex; flex-direction: column; gap: 4px; overflow: auto; }
.new-btn { display: inline-flex; align-items: center; gap: 12px; align-self: flex-start; height: 56px; padding: 0 24px 0 18px; margin-bottom: 12px; border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); font-weight: 500; font-size: 15px; transition: box-shadow .15s, background .15s; }
.new-btn:hover { background: var(--hover); }
nav a { display: flex; align-items: center; gap: 14px; height: 36px; padding: 0 16px; border-radius: 18px; color: var(--text); text-decoration: none; font-weight: 500; }
nav a:hover { background: var(--hover); }
nav a.active { background: var(--accent-soft); color: var(--accent-text); }
nav a.drop-target { outline: 2px solid var(--accent); }
.storage { margin-top: auto; padding: 16px; color: var(--text-2); font-size: 13px; }
.storage .bar { height: 4px; border-radius: 2px; background: var(--border); margin: 8px 0 6px; overflow: hidden; }
.storage .bar > div { height: 100%; background: var(--accent); width: 0; }

/* Main pane */
.main { grid-area: main; background: var(--surface); border-radius: 16px 0 0 0; margin-right: 0; display: flex; flex-direction: column; min-width: 0; outline: none; position: relative; }
.toolbar { display: flex; align-items: center; gap: 8px; min-height: 64px; padding: 8px 16px 8px 24px; }
.crumbs { display: flex; align-items: center; gap: 2px; font-size: 22px; min-width: 0; flex: 1; }
.crumbs button { padding: 4px 12px; border-radius: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 280px; }
.crumbs button:hover { background: var(--hover); }
.crumbs button.drop-target { outline: 2px solid var(--accent); }
.crumbs .sep { color: var(--text-3); }
.title { font-size: 22px; padding: 4px 0; flex: 1; }
.actions { display: flex; align-items: center; gap: 2px; }
.selbar { position: absolute; z-index: 3; top: 8px; left: 16px; right: 16px; display: flex; align-items: center; gap: 4px; padding: 4px 8px; height: 48px; border-radius: 24px; background: var(--surface-2); }
.selbar .count { margin: 0 12px 0 4px; font-weight: 500; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: var(--text-2); flex: none; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.on { background: var(--accent-soft); color: var(--accent-text); }
.seg { display: flex; border: 1px solid var(--border); border-radius: 20px; overflow: hidden; }
.seg button { width: 48px; height: 32px; display: grid; place-items: center; color: var(--text-2); }
.seg button.on { background: var(--accent-soft); color: var(--accent-text); }

.content { flex: 1; overflow: auto; padding: 0 16px 96px; }
.content.dragging-over { background: var(--accent-soft); }

/* List view */
.list { width: 100%; border-collapse: collapse; table-layout: fixed; }
.list th { position: sticky; top: 0; background: var(--surface); z-index: 1; text-align: left; font-weight: 500; color: var(--text-2); height: 48px; padding: 0 8px; border-bottom: 1px solid var(--border); user-select: none; }
.list th.sortable { cursor: pointer; }
.list th.sortable:hover { color: var(--text); }
.list th .arrow { display: inline-block; margin-left: 4px; }
.list td { height: 48px; padding: 0 8px; border-bottom: 1px solid var(--border); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-2); }
.list td.name { color: var(--text); font-weight: 500; }
.list .name-cell { display: flex; align-items: center; gap: 14px; overflow: hidden; }
.list .name-cell span { overflow: hidden; text-overflow: ellipsis; }
.list tr.row { cursor: default; user-select: none; }
.list tr.row:hover td { background: var(--hover); }
.list tr.row.selected td { background: var(--accent-soft); }
.list tr.row.drop-target td { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.list td:first-child { border-radius: 0; }
.col-mod { width: 200px; } .col-size { width: 120px; } .col-loc { width: 220px; } .col-act { width: 56px; }
.row-more { opacity: 0; }
tr.row:hover .row-more, tr.row.selected .row-more { opacity: 1; }

/* Grid view */
.section-label { color: var(--text-2); font-weight: 500; margin: 16px 8px 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(196px, 1fr)); gap: 16px; padding: 0 8px; }
.card { background: var(--surface-2); border-radius: var(--radius); overflow: hidden; user-select: none; display: flex; flex-direction: column; transition: background .1s; }
.card:hover { background: var(--hover); }
.card.selected { background: var(--accent-soft); }
.card.drop-target { box-shadow: inset 0 0 0 2px var(--accent); }
.card .card-head { display: flex; align-items: center; gap: 12px; padding: 0 4px 0 14px; height: 48px; font-weight: 500; }
.card .card-head span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .thumb { margin: 0 8px 8px; aspect-ratio: 4/3; border-radius: 8px; background: var(--surface); display: grid; place-items: center; overflow: hidden; }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.card .thumb svg { width: 56px; height: 56px; }
.card.folder { flex-direction: row; }
.card.folder .card-head { flex: 1; }

/* Empty states */
.empty { display: grid; place-items: center; text-align: center; padding: 96px 24px; color: var(--text-2); }
.empty svg { width: 96px; height: 96px; color: var(--text-3); margin: 0 auto 16px; }
.empty h2 { font-size: 20px; font-weight: 500; color: var(--text); margin: 0 0 6px; }
.empty p { margin: 0; }
.notice { margin: 0 24px 12px; padding: 12px 16px; border-radius: 10px; background: var(--surface-2); color: var(--text-2); display: flex; align-items: center; gap: 12px; }
.notice .spacer { flex: 1; }

/* Menus */
.menu { position: fixed; z-index: 50; min-width: 220px; padding: 6px 0; background: var(--surface); border-radius: 10px; box-shadow: var(--shadow-lg); border: 1px solid var(--border); }
.menu button { display: flex; align-items: center; gap: 14px; width: 100%; height: 36px; padding: 0 16px; text-align: left; color: var(--text); }
.menu button:hover, .menu button:focus-visible { background: var(--hover); outline: none; }
.menu button.danger { color: var(--danger); }
.menu button svg { color: var(--text-2); }
.menu button.danger svg { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }
.menu .menu-head { padding: 10px 16px 12px; }
.menu .menu-head strong { display: block; }
.menu .menu-head small { color: var(--text-2); }

/* Dialogs */
dialog { border: 0; padding: 0; border-radius: 16px; background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); width: min(440px, calc(100vw - 32px)); }
dialog.wide { width: min(640px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(10 14 22 / .45); }
.dlg { padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.dlg h2 { margin: 0; font-size: 20px; font-weight: 500; }
.dlg p { margin: 0; color: var(--text-2); }
.dlg .field { width: 100%; height: 44px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); outline: 0; }
.dlg .field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.dlg .buttons { display: flex; justify-content: flex-end; gap: 8px; }
.btn { height: 38px; padding: 0 18px; border-radius: 19px; font-weight: 500; color: var(--accent-text); }
.btn:hover { background: var(--accent-soft); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary:disabled { opacity: .5; cursor: default; filter: none; }
.btn.danger { color: var(--danger); }
.btn.danger.primary { background: var(--danger); color: #fff; }
.picker { border: 1px solid var(--border); border-radius: 10px; height: 300px; overflow: auto; }
.picker-head { display: flex; align-items: center; gap: 4px; height: 44px; padding: 0 6px; border-bottom: 1px solid var(--border); font-weight: 500; }
.picker-item { display: flex; align-items: center; gap: 12px; width: 100%; height: 40px; padding: 0 14px; text-align: left; }
.picker-item:hover { background: var(--hover); }
.picker-item.disabled { opacity: .4; pointer-events: none; }
.picker-item span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kv { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 16px; align-items: center; max-height: 340px; overflow: auto; }
.kv .muted { color: var(--text-2); font-size: 13px; }
.secret { font-family: var(--mono); font-size: 13px; padding: 12px; border-radius: 8px; background: var(--surface-2); word-break: break-all; user-select: all; }
.code { font-family: var(--mono); font-size: 12.5px; padding: 12px; border-radius: 8px; background: var(--surface-2); white-space: pre-wrap; margin: 0; color: var(--text-2); }

/* Preview */
.preview { position: fixed; inset: 0; z-index: 40; background: rgb(8 10 14 / .92); display: grid; grid-template-rows: 64px 1fr; color: #e8eaf0; }
.preview-bar { display: flex; align-items: center; gap: 12px; padding: 0 12px 0 20px; }
.preview-bar .name { flex: 1; font-size: 16px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 12px; }
.preview .icon-btn { color: #c9cdd6; }
.preview .icon-btn:hover { background: rgb(255 255 255 / .1); color: #fff; }
.preview-body { position: relative; display: grid; place-items: center; overflow: hidden; padding: 0 72px 24px; }
.preview-body img, .preview-body video { max-width: 100%; max-height: calc(100vh - 100px); border-radius: 4px; }
.preview-body iframe { width: min(1000px, 100%); height: calc(100vh - 100px); border: 0; border-radius: 6px; background: #fff; }
.preview-body pre { width: min(1000px, 100%); height: calc(100vh - 100px); margin: 0; overflow: auto; padding: 20px 24px; border-radius: 6px; background: #1b1f27; color: #dfe3ea; font: 13px/1.55 var(--mono); white-space: pre-wrap; word-break: break-word; }
.preview-body audio { width: min(520px, 100%); }
.preview-none { text-align: center; color: #b7bcc7; }
.preview-none svg { width: 88px; height: 88px; margin: 0 auto 16px; }
.preview-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; background: rgb(255 255 255 / .08); color: #fff; }
.preview-nav:hover { background: rgb(255 255 255 / .16); }
.preview-nav.prev { left: 12px; } .preview-nav.next { right: 12px; }

/* Uploads */
.uploads { position: fixed; right: 24px; bottom: 0; z-index: 30; width: 360px; background: var(--surface); border-radius: 12px 12px 0 0; box-shadow: var(--shadow-lg); overflow: hidden; }
.uploads-head { display: flex; align-items: center; gap: 4px; height: 52px; padding: 0 8px 0 20px; background: var(--surface-2); font-weight: 500; }
.uploads-head span { flex: 1; }
.uploads-list { max-height: 280px; overflow: auto; }
.uploads.collapsed .uploads-list { display: none; }
.up { display: grid; grid-template-columns: 24px 1fr 24px; align-items: center; gap: 12px; padding: 10px 16px 10px 20px; }
.up .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up .pb { grid-column: 2; height: 3px; border-radius: 2px; background: var(--border); overflow: hidden; margin-top: -4px; }
.up .pb > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.up .st { color: var(--text-3); display: grid; place-items: center; }
.up.done .st { color: #1f9d55; }
.up.error .st { color: var(--danger); }
.up.error .nm { color: var(--danger); }

/* Toasts */
.toasts { position: fixed; left: 24px; bottom: 24px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast { display: flex; align-items: center; gap: 16px; min-width: 300px; max-width: 520px; padding: 12px 8px 12px 18px; border-radius: 8px; background: #2a2f3a; color: #f0f2f6; box-shadow: var(--shadow-lg); animation: rise .18s ease-out; }
.toast span { flex: 1; }
.toast button { color: #9fbcff; font-weight: 600; padding: 6px 10px; border-radius: 6px; }
.toast button:hover { background: rgb(255 255 255 / .08); }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

.drop-overlay { position: fixed; inset: 0; z-index: 35; display: none; place-items: center; background: rgb(47 111 237 / .12); border: 3px dashed var(--accent); pointer-events: none; }
.drop-overlay div { padding: 14px 24px; border-radius: 28px; background: var(--accent); color: #fff; font-weight: 600; box-shadow: var(--shadow-lg); }
.drop-overlay.on { display: grid; }

/* Signed out */
.signedout { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); text-align: center; }
.signedout img { width: 64px; height: 64px; margin: 0 auto 16px; }
.signedout h1 { font-weight: 500; font-size: 24px; margin: 0 0 20px; }

@media (max-width: 860px) {
  #app { grid-template: "top" 64px "main" 1fr / 1fr; }
  .topbar .menu-toggle { display: grid; }
  .brand { width: auto; }
  .brand span { display: none; }
  .sidebar { position: fixed; z-index: 45; top: 64px; bottom: 0; left: 0; width: 260px; background: var(--bg); box-shadow: var(--shadow-lg); transform: translateX(-110%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .main { border-radius: 16px 16px 0 0; }
  .col-mod, .col-loc, .list td.mod, .list td.loc { display: none; }
  .uploads { right: 0; width: 100%; }
  .toolbar { padding-left: 12px; }
}
