:root {
  --bg: #f8fafd; --surface: #fff; --surface-2: #f0f4f9; --hover: #e9eef6; --sel: #c2e7ff; --sel-2: #d3e3fd;
  --text: #1f1f1f; --muted: #5f6368; --border: #dadce0; --accent: #0b57d0; --accent-text: #fff;
  --danger: #b3261e; --shadow: 0 1px 3px rgba(0,0,0,.15), 0 4px 12px rgba(0,0,0,.08);
  --radius: 12px; --side: 256px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1b1f; --surface: #232327; --surface-2: #2b2b30; --hover: #34343a; --sel: #004a77; --sel-2: #0b3b5e;
    --text: #e3e3e3; --muted: #a8abb0; --border: #3c3c43; --accent: #a8c7fa; --accent-text: #062e6f;
    --danger: #f2b8b5; --shadow: 0 2px 10px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.4 "Google Sans", Roboto, "Segoe UI", system-ui, sans-serif; overflow: hidden; }
body.simple { overflow: auto; display: flex; justify-content: center; padding: 40px 16px; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
svg { width: 20px; height: 20px; fill: currentColor; flex: none; }
[hidden] { display: none !important; }

/* ---------- simple pages ---------- */
.card { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); padding: 28px 32px; width: 100%; max-width: 620px; height: fit-content; }
.card h1 { display: flex; align-items: center; gap: 10px; font-size: 22px; font-weight: 500; margin: 0 0 20px; }
.card h2 { font-size: 16px; font-weight: 500; margin: 24px 0 8px; }
.card section + section { border-top: 1px solid var(--border); margin-top: 20px; }
.card label { display: block; margin: 12px 0; }
.card label.radio { display: flex; gap: 8px; align-items: center; margin-bottom: 4px; }
.card input:not([type=radio]) { display: block; width: 100%; margin-top: 4px; }
.muted { color: var(--muted); }
pre.copy { background: var(--surface-2); padding: 8px 12px; border-radius: 8px; overflow-x: auto; user-select: all; }
.alert { background: #fce8e6; color: #8c1d18; padding: 10px 14px; border-radius: 8px; }
input[type=text], input[type=password], input[type=search], input[type=number], input:not([type]), select {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; outline: none;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); padding: 8px 18px; border-radius: 20px; cursor: pointer; text-decoration: none; color: var(--text); font-weight: 500; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }

/* ---------- top bar ---------- */
.top { height: 64px; display: flex; align-items: center; gap: 12px; padding: 0 16px; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); font-size: 22px; width: calc(var(--side) - 32px); }
.search { flex: 1; max-width: 720px; display: flex; align-items: center; gap: 8px; background: var(--surface-2); border-radius: 24px; padding: 0 16px; height: 46px; }
.search:focus-within { background: var(--surface); box-shadow: var(--shadow); }
.search input { border: 0; background: transparent; flex: 1; box-shadow: none !important; padding: 0; height: 100%; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.top-actions select { border-radius: 20px; padding: 6px 10px; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent; cursor: pointer; color: var(--muted); text-decoration: none; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.only-mobile { display: none; }

/* ---------- layout ---------- */
.layout { display: flex; height: calc(100% - 64px); }
.side { width: var(--side); flex: none; padding: 4px 12px 16px 8px; overflow-y: auto; }
.main { flex: 1; min-width: 0; background: var(--surface); border-radius: 16px 0 0 0; display: flex; flex-direction: column; margin-right: 0; }
.btn-new { display: inline-flex; align-items: center; gap: 12px; border: 0; background: var(--surface); box-shadow: var(--shadow); padding: 16px 20px 16px 16px; border-radius: 16px; font-weight: 500; cursor: pointer; margin: 4px 0 16px 4px; }
.btn-new:hover { background: var(--hover); }

/* ---------- menus ---------- */
.menu-wrap { position: relative; }
.menu { position: absolute; z-index: 50; background: var(--surface); box-shadow: var(--shadow); border-radius: 8px; padding: 8px 0; min-width: 220px; }
#userMenu { right: 0; top: 44px; }
#newMenu { left: 4px; top: 64px; }
.menu button, .menu a { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 8px 16px; border: 0; background: none; cursor: pointer; color: var(--text); text-decoration: none; }
.menu button:hover, .menu a:hover { background: var(--hover); }
.menu button:disabled { opacity: .4; cursor: default; }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }
.menu-label { padding: 6px 16px 10px; color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.ctx { position: fixed; }

/* ---------- tree ---------- */
.tree ul { list-style: none; margin: 0; padding: 0 0 0 14px; }
.tree > ul { padding-left: 0; }
.tree .node { display: flex; align-items: center; height: 32px; border-radius: 16px; padding-right: 10px; cursor: pointer; white-space: nowrap; overflow: hidden; }
.tree .node:hover { background: var(--hover); }
.tree .node.active { background: var(--sel); font-weight: 500; }
.tree .node.drop { outline: 2px solid var(--accent); }
.tree .tw { width: 24px; height: 24px; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); transition: transform .15s; }
.tree .tw svg { width: 18px; height: 18px; }
.tree .tw.open { transform: rotate(90deg); }
.tree .tw.leaf { visibility: hidden; }
.tree .node > svg { margin-right: 8px; color: var(--muted); width: 18px; height: 18px; }
.tree .node span.lbl { overflow: hidden; text-overflow: ellipsis; }

/* ---------- bar / crumbs ---------- */
.bar { display: flex; align-items: center; min-height: 64px; padding: 8px 16px 8px 20px; gap: 8px; }
.crumbs { display: flex; align-items: center; flex-wrap: wrap; font-size: 22px; min-width: 0; flex: 1; }
.crumbs a { color: var(--text); text-decoration: none; padding: 2px 10px; border-radius: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.crumbs a:hover { background: var(--hover); }
.crumbs a.drop { outline: 2px solid var(--accent); }
.crumbs .sep { color: var(--muted); display: inline-flex; }
.selbar { display: flex; align-items: center; gap: 2px; background: var(--surface-2); border-radius: 24px; padding: 2px 4px 2px 16px; }
.selbar span { margin-right: 8px; white-space: nowrap; }

/* ---------- content ---------- */
.content { flex: 1; overflow-y: auto; padding: 0 16px 120px 20px; position: relative; outline: none; user-select: none; }
.group-title { font-weight: 500; margin: 16px 0 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.grid.folders { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.it { position: relative; border-radius: var(--radius); background: var(--surface-2); cursor: default; }
.it:hover { background: var(--hover); }
.it.sel { background: var(--sel-2); }
.it.drop { outline: 2px solid var(--accent); background: var(--sel); }
.it.cut { opacity: .45; }
.grid.folders .it { display: flex; align-items: center; gap: 12px; height: 48px; padding: 0 16px; }
.grid.folders .it .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.grid.files .it { display: flex; flex-direction: column; padding: 0 8px 8px; }
.grid.files .it .nm { display: flex; align-items: center; gap: 10px; height: 44px; padding: 0 6px; font-weight: 500; }
.grid.files .it .nm span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumb { aspect-ratio: 4/3; border-radius: 8px; background: var(--surface); overflow: hidden; display: flex; align-items: center; justify-content: center; position: relative; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb > svg { width: 56px; height: 56px; color: var(--muted); opacity: .7; }
.thumb .dur { position: absolute; right: 6px; bottom: 6px; background: rgba(0,0,0,.7); color: #fff; font-size: 12px; padding: 1px 6px; border-radius: 4px; display: flex; align-items: center; gap: 2px; }
.thumb .dur svg { width: 14px; height: 14px; }
.it .check { position: absolute; left: 6px; top: 6px; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: var(--accent-text); display: none; align-items: center; justify-content: center; z-index: 2; }
.it .check svg { width: 16px; height: 16px; }
.it.sel .check { display: flex; }
.ic-folder { color: var(--muted); }
.ic-image { color: #d93025; } .ic-video { color: #d93025; } .ic-audio { color: #e37400; } .ic-pdf { color: #d93025; } .ic-zip { color: #5f6368; } .ic-file { color: #1a73e8; }

/* list view */
.list { width: 100%; border-collapse: collapse; }
.list th { text-align: left; font-weight: 500; color: var(--muted); border-bottom: 1px solid var(--border); padding: 10px 8px; position: sticky; top: 0; background: var(--surface); z-index: 1; cursor: pointer; white-space: nowrap; }
.list td { padding: 0 8px; height: 48px; border-bottom: 1px solid var(--border); white-space: nowrap; color: var(--muted); }
.list td.n { color: var(--text); font-weight: 500; width: 60%; max-width: 0; overflow: hidden; text-overflow: ellipsis; }
.list td.n > div { display: flex; align-items: center; gap: 14px; }
.list td.n span { overflow: hidden; text-overflow: ellipsis; }
.list tr.it { background: none; }
.list tr.it:hover { background: var(--hover); }
.list tr.it.sel { background: var(--sel-2); }
.list tr.it.drop { outline: 2px solid var(--accent); outline-offset: -2px; }
.list .mini { width: 32px; height: 32px; border-radius: 4px; object-fit: cover; }
.empty { text-align: center; color: var(--muted); padding: 80px 16px; }
.empty svg { width: 120px; height: 120px; opacity: .3; display: block; margin: 0 auto 16px; }
.loading { position: absolute; inset: 0; display: flex; justify-content: center; padding-top: 80px; background: color-mix(in srgb, var(--surface) 60%, transparent); }
.spinner { width: 36px; height: 36px; border: 4px solid var(--sel); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.rubber { position: fixed; border: 1px solid var(--accent); background: color-mix(in srgb, var(--accent) 15%, transparent); z-index: 40; pointer-events: none; }

/* ---------- drop overlay ---------- */
.drop-overlay { position: fixed; inset: 0; z-index: 60; pointer-events: none; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 40px; border: 3px solid var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.drop-overlay div { background: var(--accent); color: var(--accent-text); padding: 14px 24px; border-radius: 24px; box-shadow: var(--shadow); }

/* ---------- uploads panel ---------- */
.uploads { position: fixed; right: 24px; bottom: 0; width: 380px; max-width: calc(100vw - 32px); background: var(--surface); box-shadow: var(--shadow); border-radius: 16px 16px 0 0; z-index: 55; overflow: hidden; }
.uploads-head { display: flex; align-items: center; padding: 6px 8px 6px 20px; background: var(--surface-2); font-weight: 500; }
.uploads-head span { flex: 1; }
.uploads-list { max-height: 320px; overflow-y: auto; }
.uploads.collapsed .uploads-list { display: none; }
.up { display: flex; align-items: center; gap: 12px; padding: 8px 12px 8px 20px; }
.up .info { flex: 1; min-width: 0; }
.up .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up .meta { font-size: 12px; color: var(--muted); }
.up .meta.err { color: var(--danger); }
.up .pbar { height: 4px; background: var(--surface-2); border-radius: 2px; margin-top: 4px; overflow: hidden; }
.up .pbar i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.up img.pv, .up .pv { width: 36px; height: 36px; border-radius: 4px; object-fit: cover; flex: none; display: flex; align-items: center; justify-content: center; background: var(--surface-2); }
.up .st svg { width: 22px; height: 22px; }
.up .st.ok { color: #188038; }
.up .st.err { color: var(--danger); }

/* ---------- modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 70; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 24px; padding: 24px; width: 100%; max-width: 440px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal.wide { max-width: 720px; }
.modal h3 { margin: 0 0 16px; font-size: 22px; font-weight: 400; }
.modal label { display: block; margin: 10px 0; }
.modal label > input, .modal label > select { display: block; width: 100%; margin-top: 4px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.modal .row { display: flex; gap: 12px; }
.modal .row > * { flex: 1; }
.picker { border: 1px solid var(--border); border-radius: 8px; height: 300px; overflow-y: auto; }
.picker .p-head { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); font-weight: 500; }
.picker .p-row { display: flex; align-items: center; gap: 10px; padding: 8px 14px; cursor: pointer; }
.picker .p-row:hover { background: var(--hover); }
.share-list { width: 100%; border-collapse: collapse; font-size: 13px; }
.share-list td, .share-list th { padding: 6px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.share-list input { width: 100%; font-size: 12px; padding: 4px 6px; }

/* ---------- lightbox ---------- */
.lightbox { position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.92); color: #fff; display: flex; align-items: center; justify-content: center; }
.lb-top { position: absolute; top: 0; left: 0; right: 0; height: 60px; display: flex; align-items: center; padding: 0 12px 0 24px; background: linear-gradient(rgba(0,0,0,.6), transparent); z-index: 2; }
.lb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; }
.lightbox .icon-btn { color: #fff; }
.lightbox .icon-btn:hover { background: rgba(255,255,255,.15); }
.lb-stage { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; padding: 64px 80px 24px; }
.lb-stage img, .lb-stage video { max-width: 100%; max-height: 100%; object-fit: contain; }
.lb-stage .lb-file { text-align: center; }
.lb-stage .lb-file svg { width: 96px; height: 96px; }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 56px; height: 56px; border-radius: 50%; border: 0; background: rgba(255,255,255,.1); color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; z-index: 2; }
.lb-nav:hover { background: rgba(255,255,255,.25); }
.lb-nav svg { width: 32px; height: 32px; }
.lb-prev { left: 12px; } .lb-next { right: 12px; }

.toast { position: fixed; left: 24px; bottom: 24px; background: #303134; color: #fff; padding: 14px 20px; border-radius: 8px; z-index: 90; box-shadow: var(--shadow); max-width: 480px; }
.toast.err { background: #8c1d18; }

@media (max-width: 760px) {
  .only-mobile { display: inline-flex; }
  .brand span, .top-actions select, #sortDir { display: none; }
  .brand { width: auto; }
  .side { position: fixed; left: 0; top: 64px; bottom: 0; background: var(--bg); z-index: 45; box-shadow: var(--shadow); transform: translateX(-100%); transition: transform .2s; }
  body.side-open .side { transform: none; }
  .main { border-radius: 16px 16px 0 0; }
  .grid, .grid.folders { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .crumbs { font-size: 18px; }
  .lb-stage { padding: 64px 0 0; }
  .list td.d2, .list th.d2 { display: none; }
}
