:root {
  --bg: #f8fafd; --surface: #fff; --card: #f0f4f9; --text: #1f1f1f; --muted: #5f6368;
  --line: #e1e3e1; --hover: #e8ebee; --sel: #c2e7ff; --sel-text: #001d35;
  --accent: #0b57d0; --accent-text: #fff; --accent-soft: #d3e3fd; --search: #e9eef6;
  --danger: #b3261e; --scrim: rgba(0,0,0,.45);
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 2px 6px 2px rgba(0,0,0,.15);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1b1b; --surface: #131314; --card: #1e1f20; --text: #e3e3e3; --muted: #a8abaf;
    --line: #3c4043; --hover: #2b2c2e; --sel: #004a77; --sel-text: #c2e7ff;
    --accent: #a8c7fa; --accent-text: #062e6f; --accent-soft: #0842a0; --search: #282a2c;
    --danger: #f2b8b5; --scrim: rgba(0,0,0,.65);
    --shadow: 0 1px 3px rgba(0,0,0,.6), 0 4px 8px 3px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.4 "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
svg { flex: none; }
[hidden] { display: none !important; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; display: inline-grid; place-items: center;
  color: var(--muted);
}
.icon-btn:hover { background: var(--hover); }
.icon-btn.on { background: var(--sel); color: var(--sel-text); }

/* ---------- shell */
.app { display: grid; grid-template: "top top" 64px "side main" 1fr / 256px 1fr; height: 100vh; height: 100dvh; }
.top { grid-area: top; display: flex; align-items: center; gap: 8px; padding: 8px 16px; }
.brand { display: flex; align-items: center; gap: 10px; width: 232px; font-size: 22px; color: var(--text); text-decoration: none; padding-left: 4px; }
.search {
  flex: 1; max-width: 720px; display: flex; align-items: center; gap: 4px;
  background: var(--search); border-radius: 28px; height: 48px; padding: 0 8px;
}
.search:focus-within { background: var(--surface); box-shadow: var(--shadow); }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; font-size: 16px; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: #0b8043; color: #fff; display: grid; place-items: center; font-weight: 600; }
.menu-toggle { display: none; }

.side { grid-area: side; padding: 8px 16px 16px 8px; display: flex; flex-direction: column; overflow-y: auto; }
.new-btn {
  display: inline-flex; align-items: center; gap: 12px; height: 56px; padding: 0 20px 0 16px; margin: 0 0 16px 4px;
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); font-weight: 500; align-self: flex-start;
}
.new-btn:hover { background: var(--hover); }
.nav a {
  display: flex; align-items: center; gap: 16px; height: 32px; padding: 0 12px 0 16px; border-radius: 16px;
  color: var(--text); text-decoration: none; margin-bottom: 2px;
}
.nav a:hover { background: var(--hover); }
.nav a.on { background: var(--sel); color: var(--sel-text); font-weight: 600; }
.nav a.drop { outline: 2px solid var(--accent); }
.storage { margin: 18px 0 0 16px; color: var(--muted); font-size: 13px; }
.bar { height: 4px; background: var(--line); border-radius: 2px; margin: 8px 0; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 2px; min-width: 2px; }

.main {
  grid-area: main; background: var(--surface); border-radius: 16px; margin: 0 16px 16px 0;
  display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative;
}
.toolbar { display: flex; align-items: center; gap: 8px; padding: 12px 12px 4px 24px; min-height: 64px; flex-wrap: wrap; }
.crumbs { display: flex; align-items: center; flex-wrap: wrap; font-size: 22px; min-width: 0; flex: 1; }
.crumbs button { padding: 4px 12px; border-radius: 20px; font-size: 22px; white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.crumbs button:first-child { margin-left: -12px; }
.crumbs button:hover { background: var(--hover); }
.crumbs button.drop { outline: 2px solid var(--accent); }
.crumbs .sep { color: var(--muted); }
.crumbs h1 { font-size: 22px; font-weight: 400; margin: 4px 0; }
.view-ctl { display: flex; align-items: center; gap: 8px; }
.seg { display: inline-flex; border: 1px solid var(--muted); border-radius: 18px; overflow: hidden; height: 32px; }
.seg button { width: 52px; display: grid; place-items: center; color: var(--text); }
.seg button + button { border-left: 1px solid var(--muted); }
.seg button.on { background: var(--sel); color: var(--sel-text); }
.upload-btn {
  display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 18px 0 12px; border-radius: 18px;
  background: var(--accent); color: var(--accent-text); font-weight: 600;
}
.upload-btn:hover { box-shadow: var(--shadow); }
.upload-btn svg { width: 20px; height: 20px; }
.empty .btn-fill { display: inline-flex; align-items: center; gap: 8px; margin-top: 20px; }
.sort {
  height: 32px; border: 1px solid var(--line); border-radius: 8px; padding: 0 8px; background: var(--surface);
}

.selbar {
  display: flex; align-items: center; gap: 4px; margin: 4px 16px 0; padding: 4px 8px; height: 48px;
  background: var(--card); border-radius: 24px;
}
.selbar .count { margin: 0 12px 0 4px; }
.note { margin: 0 24px; padding: 10px 16px; background: var(--card); border-radius: 8px; color: var(--muted); display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.note .link { color: var(--accent); font-weight: 600; padding: 6px 12px; border-radius: 16px; margin-left: auto; }
.note .link:hover { background: var(--hover); }

.content { flex: 1; overflow-y: auto; padding: 8px 24px 32px; outline: 0; position: relative; }
.content.dragging::after {
  content: "Drop files to upload"; position: absolute; inset: 8px; border: 2px dashed var(--accent);
  border-radius: 12px; background: color-mix(in srgb, var(--accent-soft) 45%, transparent);
  display: grid; place-items: center; font-size: 18px; color: var(--text); pointer-events: none;
}
.section-title { font-size: 14px; font-weight: 500; margin: 16px 0 12px; }

/* ---------- grid */
.folders { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.folder {
  display: flex; align-items: center; gap: 14px; height: 48px; padding: 0 4px 0 16px;
  background: var(--card); border-radius: 12px; user-select: none; cursor: default; min-width: 0;
}
.folder .name { flex: 1; font-weight: 500; }
.files { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.card {
  background: var(--card); border-radius: 12px; padding: 4px 4px 8px; display: flex; flex-direction: column;
  user-select: none; cursor: default; min-width: 0;
}
.card-head { display: flex; align-items: center; gap: 12px; height: 44px; padding: 0 0 0 12px; }
.card-head .name { flex: 1; font-weight: 500; }
.thumb {
  margin: 0 8px; aspect-ratio: 4 / 3.2; border-radius: 8px; background: var(--surface) no-repeat top center / cover;
  display: grid; place-items: center; overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb.has-thumb > svg { display: none; }
.thumb > svg { width: 64px; height: 64px; }
.meta { font-size: 12px; color: var(--muted); padding: 8px 12px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.item:hover { background: var(--hover); }
.item.sel, .item.sel:hover { background: var(--sel); color: var(--sel-text); }
.item.drop { outline: 2px solid var(--accent); outline-offset: -2px; }
.item.cut { opacity: .45; }
.more { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; color: inherit; }
.more:hover { background: color-mix(in srgb, currentColor 12%, transparent); }

/* ---------- list */
.list { width: 100%; border-collapse: collapse; table-layout: fixed; }
.list th { text-align: left; font-weight: 500; color: var(--text); height: 48px; border-bottom: 1px solid var(--line); padding: 0 8px; }
.list td { height: 48px; border-bottom: 1px solid var(--line); padding: 0 8px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list td.n { color: inherit; }
.list .row-name { display: flex; align-items: center; gap: 14px; min-width: 0; font-weight: 500; }
.list tr.item { user-select: none; cursor: default; }
.list tr.item.sel td { color: var(--sel-text); }
.list .c-mod { width: 180px; } .list .c-size { width: 110px; } .list .c-act { width: 48px; } .list .c-loc { width: 200px; }

.empty { text-align: center; color: var(--muted); padding: 72px 16px; }
.empty svg { margin-bottom: 12px; }
.empty h2 { color: var(--text); font-weight: 400; font-size: 22px; margin: 0 0 8px; }

/* ---------- popups */
.menu {
  position: fixed; z-index: 50; background: var(--surface); border-radius: 8px; box-shadow: var(--shadow);
  padding: 8px 0; min-width: 220px;
}
.menu button { display: flex; align-items: center; gap: 16px; width: 100%; height: 36px; padding: 0 20px 0 16px; text-align: left; color: var(--text); }
.menu button:hover { background: var(--hover); }
.menu button svg { color: var(--muted); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 8px 0; }

.scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 60; display: grid; place-items: center; padding: 16px; }
.dialog { background: var(--surface); border-radius: 28px; padding: 24px; width: min(400px, 100%); box-shadow: var(--shadow); }
.dialog h3 { font-size: 22px; font-weight: 400; margin: 0 0 16px; }
.dialog p { color: var(--muted); margin: 0 0 8px; }
.dialog input { width: 100%; height: 48px; padding: 0 14px; border: 1px solid var(--muted); border-radius: 6px; background: var(--surface); outline: 0; }
.dialog input:focus { border: 2px solid var(--accent); padding: 0 13px; }
.dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }
.btn-text { color: var(--accent); font-weight: 600; padding: 10px 16px; border-radius: 20px; }
.btn-text:hover { background: var(--hover); }
.btn-fill { background: var(--accent); color: var(--accent-text); font-weight: 600; padding: 10px 24px; border-radius: 20px; }
.btn-fill.danger { background: var(--danger); color: var(--surface); }

.toast {
  position: fixed; left: 24px; bottom: 24px; z-index: 70; background: #303030; color: #f2f2f2;
  border-radius: 4px; padding: 6px 8px 6px 16px; min-height: 48px; display: flex; align-items: center; gap: 12px;
  box-shadow: var(--shadow); max-width: calc(100vw - 48px);
}
.toast button { color: #a8c7fa; font-weight: 600; padding: 8px 12px; border-radius: 4px; }
.toast button:hover { background: rgba(255,255,255,.08); }

.uploads {
  position: fixed; right: 24px; bottom: 0; z-index: 65; width: min(360px, calc(100vw - 32px));
  background: var(--surface); border-radius: 16px 16px 0 0; box-shadow: var(--shadow); overflow: hidden;
}
.uploads header { display: flex; align-items: center; gap: 4px; padding: 6px 8px 6px 20px; background: var(--card); font-weight: 500; }
.uploads header span { flex: 1; }
.uploads ul { list-style: none; margin: 0; padding: 4px 0; max-height: 260px; overflow-y: auto; }
.uploads li { display: flex; align-items: center; gap: 12px; padding: 8px 16px; }
.uploads li .name { flex: 1; }
.ring { width: 22px; height: 22px; }
.ok { color: #188038; } .bad { color: var(--danger); }

/* ---------- preview */
.preview { position: fixed; inset: 0; z-index: 55; background: rgba(0,0,0,.88); display: flex; flex-direction: column; color: #e3e3e3; }
.preview header { display: flex; align-items: center; gap: 12px; height: 64px; padding: 0 12px 0 16px; flex: none; }
.preview header .name { flex: 1; font-size: 16px; }
.preview .icon-btn { color: #e3e3e3; }
.preview .icon-btn:hover { background: rgba(255,255,255,.1); }
.preview .stage { flex: 1; display: grid; place-items: center; min-height: 0; padding: 0 72px 24px; position: relative; }
.preview .stage > * { max-width: 100%; max-height: 100%; }
.preview iframe { width: min(1000px, 100%); height: 100%; border: 0; background: #fff; border-radius: 4px; }
.preview iframe.text { background: #fff; }
.preview img, .preview video { object-fit: contain; border-radius: 4px; }
.preview .nofile { text-align: center; background: #3c4043; padding: 32px 40px; border-radius: 12px; }
.preview .nofile .btn-fill { display: inline-block; margin-top: 16px; text-decoration: none; background: #a8c7fa; color: #062e6f; }
.preview .nav-btn { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(0,0,0,.5); }
.preview .loading { position: absolute; font-size: 16px; color: #c4c7c5; }
.preview .prev { left: 12px; } .preview .next { right: 12px; }

/* ---------- login */
.login-page { display: grid; place-items: center; min-height: 100vh; min-height: 100dvh; padding: 16px; }
.login {
  background: var(--surface); border-radius: 28px; padding: 40px 36px 36px; width: min(420px, 100%);
}
.login .brand { width: auto; margin-bottom: 28px; padding: 0; }
.login h1 { font-size: 30px; font-weight: 400; margin: 0 0 8px; }
.login p { color: var(--muted); margin: 0 0 28px; }
.login input {
  width: 100%; height: 54px; padding: 0 16px; border: 1px solid var(--muted); border-radius: 6px;
  background: var(--surface); outline: 0; font-size: 16px;
}
.login input:focus { border: 2px solid var(--accent); padding: 0 15px; }
.login .error { color: var(--danger); margin: 10px 0 0; display: flex; gap: 8px; align-items: center; font-size: 13px; }
.login .row { display: flex; justify-content: flex-end; margin-top: 32px; }

/* ---------- small screens */
@media (max-width: 800px) {
  .app { grid-template: "top" 64px "main" 1fr / 1fr; }
  .menu-toggle { display: inline-grid; }
  .brand { width: auto; } .brand span { display: none; }
  .side {
    position: fixed; z-index: 58; top: 0; bottom: 0; left: 0; width: 272px; background: var(--bg);
    padding-top: 16px; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow);
  }
  .app.drawer .side { transform: none; }
  .app.drawer::after { content: ""; position: fixed; inset: 0; background: var(--scrim); z-index: 57; }
  .main { margin: 0 8px 8px; }
  .toolbar { padding-left: 16px; }
  .content { padding: 8px 12px 96px; }
  .folders { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
  .files { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
  .list .c-mod, .list .c-loc, .list td:nth-child(2), .list td:nth-child(3), .list th:nth-child(2), .list th:nth-child(3) { display: none; }
  .preview .stage { padding: 0 8px 8px; }
  .preview .nav-btn { display: none; }
  .fab { display: grid !important; }
  .sort { display: none; }
}
.fab {
  display: none; position: fixed; right: 20px; bottom: 20px; z-index: 40; width: 56px; height: 56px; border-radius: 16px;
  background: var(--accent-soft); color: var(--text); place-items: center; box-shadow: var(--shadow);
}
