:root {
  --bg: #ffffff; --side: #fafafa; --hover: #f0f0f2; --active: #ececef; --line: #e6e6ea;
  --text: #24262b; --muted: #6d7078; --accent: #f6b73c; --accent-strong: #ffd84d; --on-accent: #24262b;
  --folder: #fde9a6; --folder-back: #fbd872; --danger: #c8372d; --shadow: 0 8px 30px rgba(0,0,0,.16);
  --chip: #eeeef1;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1e22; --side: #17181b; --hover: #2a2c31; --active: #303238; --line: #33353b;
    --text: #e9e9ec; --muted: #9b9ea6; --accent: #f6b73c; --accent-strong: #f6c343;
    --folder: #d9b75a; --folder-back: #b8963f; --danger: #ff7a6e; --shadow: 0 8px 30px rgba(0,0,0,.5);
    --chip: #2c2e33;
  }
}
* { box-sizing: border-box; }
html, body, #app { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; -webkit-tap-highlight-color: transparent; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
a { color: inherit; }
svg { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; background: var(--side); }
.login form { width: 100%; max-width: 380px; background: var(--bg); border: 1px solid var(--line); border-radius: 22px; padding: 32px 26px; display: grid; gap: 14px; }
.login img { width: 56px; height: 56px; }
.login h1 { margin: 0; font-size: 24px; font-weight: 600; }
.login .err { color: var(--danger); font-size: 14px; min-height: 20px; margin: 0; }
.field { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); }
.field:focus { outline: 2px solid var(--accent); border-color: transparent; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 18px; border-radius: 14px; background: var(--chip); font-weight: 500; text-decoration: none; }
.btn:hover { background: var(--active); }
.btn.primary { background: var(--accent-strong); color: #24262b; }
.btn.primary:hover { background: var(--accent); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .55; cursor: default; }

/* Layout */
.shell { display: flex; height: 100%; }
.side { width: 300px; flex: none; background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 18px 16px; overflow-y: auto; }
.brand { font-size: 22px; font-weight: 500; text-decoration: none; }
.brand b { font-weight: 700; }
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 16px; }
.side .btn { width: 100%; margin-bottom: 10px; }
nav { margin-top: 6px; display: grid; gap: 2px; }
nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; text-decoration: none; }
nav a:hover { background: var(--hover); }
nav a.on { background: var(--active); }
.side-bottom { margin-top: auto; padding-top: 16px; display: grid; gap: 8px; }
.space { background: var(--chip); border-radius: 14px; padding: 12px 14px; font-size: 14px; }
.bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-bottom: 8px; }
.bar i { display: block; height: 100%; background: var(--accent); min-width: 2px; }
.acct { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 14px; color: var(--muted); padding: 0 4px; }
.acct span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link { color: var(--muted); text-decoration: underline; padding: 2px; font-size: 14px; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.top { display: flex; align-items: center; gap: 10px; padding: 18px 28px 10px; min-height: 68px; }
.top h1 { margin: 0; font-size: 24px; font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumbs { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 2px; font-size: 22px; font-weight: 600; }
.crumbs a { text-decoration: none; padding: 2px 6px; border-radius: 8px; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumbs a:hover { background: var(--hover); }
.crumbs .sep { color: var(--muted); font-weight: 400; }
.iconbtn { width: 42px; height: 42px; display: inline-grid; place-items: center; border-radius: 12px; flex: none; }
.iconbtn:hover { background: var(--hover); }
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 9px 14px; border-radius: 14px; background: var(--chip); font-size: 15px; flex: none; }
.chip:hover { background: var(--active); }
.burger { display: none; }
.searchbox { flex: 1; max-width: 420px; }
.content { flex: 1; overflow-y: auto; padding: 8px 28px 90px; }
.empty { text-align: center; color: var(--muted); padding: 70px 16px; }
.empty svg { width: 54px; height: 54px; margin-bottom: 10px; stroke-width: 1.2; }

/* Selection */
.selbar { display: flex; align-items: center; gap: 6px; padding: 6px 28px; background: var(--chip); flex-wrap: wrap; }
.selbar span { margin-right: auto; font-size: 15px; }

/* Grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 10px; }
.tile { position: relative; border-radius: 14px; padding: 8px 8px 10px; text-align: center; cursor: pointer; user-select: none; min-width: 0; }
.tile:hover { background: var(--hover); }
.tile.sel { background: var(--active); }
.tile .pic { height: 104px; display: grid; place-items: center; margin-bottom: 6px; position: relative; }
.tile .pic img { max-width: 100%; max-height: 100%; border-radius: 10px; object-fit: cover; }
.tile .nm { font-size: 14px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-word; }
.tile .meta { display: none; }
.check, .more { position: absolute; top: 6px; width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; opacity: 0; background: var(--bg); box-shadow: 0 1px 4px rgba(0,0,0,.2); }
.check { left: 6px; }
.more { right: 6px; }
.check svg, .more svg { width: 18px; height: 18px; }
.tile:hover .check, .tile:hover .more, .tile.sel .check, .selecting .check { opacity: 1; }
.tile.sel .check { background: var(--accent); color: #24262b; }
@media (hover: none) { .more { opacity: 1; background: transparent; box-shadow: none; } }
.linkmark { position: absolute; right: 10px; bottom: 4px; width: 26px; height: 26px; border-radius: 50%; background: #3c3f46; color: #fff; display: grid; place-items: center; }
.linkmark svg { width: 15px; height: 15px; }

.ficon { width: 74px; height: 92px; border-radius: 10px 22px 10px 10px; background: var(--chip); display: grid; place-items: center; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .4px; }
.folder { width: 100px; height: 78px; position: relative; }
.folder::before { content: ""; position: absolute; left: 0; top: 0; width: 46px; height: 24px; border-radius: 12px 14px 0 0; background: var(--folder-back); }
.folder::after { content: ""; position: absolute; inset: 11px 0 0; border-radius: 12px; background: var(--folder); }

/* List */
.grid.list { grid-template-columns: 1fr; gap: 0; }
.list .tile { display: flex; align-items: center; gap: 12px; text-align: left; padding: 7px 44px 7px 10px; }
.list .tile .pic { height: 40px; width: 44px; flex: none; margin: 0; }
.list .folder { width: 38px; height: 30px; transform: none; }
.list .folder::before { width: 18px; height: 10px; border-radius: 5px 6px 0 0; }
.list .folder::after { inset: 4px 0 0; border-radius: 5px; }
.list .ficon { width: 32px; height: 38px; font-size: 8px; border-radius: 5px 10px 5px 5px; }
.list .tile .nm { flex: 1; -webkit-line-clamp: 1; }
.list .tile .meta { display: block; color: var(--muted); font-size: 14px; white-space: nowrap; }
.list .check { position: static; opacity: 1; background: none; box-shadow: none; border: 1.5px solid var(--line); width: 22px; height: 22px; border-radius: 6px; flex: none; }
.list .check svg { opacity: 0; width: 14px; height: 14px; }
.list .tile.sel .check svg { opacity: 1; }
.list .more { top: 50%; margin-top: -15px; right: 8px; }
.grid:not(.list) .check svg { opacity: 1; }

/* Photos */
.month { font-size: 16px; font-weight: 600; margin: 18px 0 8px; text-transform: capitalize; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px; }
.ph { position: relative; aspect-ratio: 1; overflow: hidden; border-radius: 8px; background: var(--chip); cursor: pointer; padding: 0; display: block; width: 100%; }
.ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph .play { position: absolute; left: 8px; bottom: 8px; color: #fff; filter: drop-shadow(0 1px 3px rgba(0,0,0,.7)); }

/* Plain rows */
.rows { display: grid; gap: 2px; }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; flex-wrap: wrap; }
.row:hover { background: var(--hover); }
.row .grow { flex: 1; min-width: 180px; }
.row .sub { color: var(--muted); font-size: 14px; word-break: break-word; }
.row b { font-weight: 500; word-break: break-word; }

/* FAB, menus, dialogs */
.fab { display: none; position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); width: 58px; height: 58px; border-radius: 18px; background: var(--accent-strong); color: #24262b; box-shadow: var(--shadow); z-index: 20; place-items: center; }
.menu { position: fixed; z-index: 60; min-width: 220px; background: var(--bg); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 6px; }
.menu button { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 12px; border-radius: 10px; text-align: left; }
.menu button:hover { background: var(--hover); }
.menu button.danger { color: var(--danger); }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: grid; place-items: center; padding: 16px; }
.dialog { width: 100%; max-width: 440px; max-height: 86vh; overflow-y: auto; background: var(--bg); border-radius: 20px; padding: 22px; display: grid; gap: 14px; box-shadow: var(--shadow); }
.dialog h2 { margin: 0; font-size: 20px; font-weight: 600; word-break: break-word; }
.dialog p { margin: 0; color: var(--muted); word-break: break-word; }
.dialog .actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.dialog label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
.pick { max-height: 280px; overflow-y: auto; border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.pick button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border-radius: 8px; text-align: left; }
.pick button:hover { background: var(--hover); }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(22px + env(safe-area-inset-bottom)); background: #24262b; color: #fff; padding: 11px 18px; border-radius: 12px; z-index: 80; max-width: calc(100% - 32px); box-shadow: var(--shadow); font-size: 15px; }
.drop { position: absolute; inset: 10px; border: 2.5px dashed var(--accent); border-radius: 18px; background: color-mix(in srgb, var(--accent) 12%, transparent); display: grid; place-items: center; font-size: 20px; font-weight: 600; z-index: 15; pointer-events: none; }

/* Upload panel */
.uploads { position: fixed; right: 20px; bottom: 20px; width: 360px; max-width: calc(100% - 32px); background: var(--bg); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); z-index: 40; overflow: hidden; }
.uploads header { display: flex; align-items: center; justify-content: space-between; padding: 10px 8px 10px 16px; font-weight: 600; font-size: 15px; }
.uploads ul { list-style: none; margin: 0; padding: 0 12px 10px; max-height: 240px; overflow-y: auto; display: grid; gap: 8px; }
.uploads li { font-size: 14px; display: grid; gap: 4px; }
.uploads .u-name { display: flex; justify-content: space-between; gap: 8px; }
.uploads .u-name span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uploads .u-state { color: var(--muted); white-space: nowrap; }
.uploads .failed { color: var(--danger); }
.uploads .bar { margin: 0; height: 4px; }

/* Viewer */
.viewer { position: fixed; inset: 0; background: #0c0c0e; z-index: 70; display: flex; flex-direction: column; color: #fff; }
.viewer header { display: flex; align-items: center; gap: 6px; padding: 8px 10px; }
.viewer header .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-left: 8px; }
.viewer .iconbtn:hover { background: rgba(255,255,255,.14); }
.viewer .stage { flex: 1; min-height: 0; display: grid; place-items: center; position: relative; touch-action: pan-y; }
.viewer img, .viewer video { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.viewer .stage > * { grid-area: 1 / 1; }
.nav-prev, .nav-next { position: absolute; top: 50%; margin-top: -26px; width: 52px; height: 52px; border-radius: 50%; background: rgba(255,255,255,.12); color: #fff; display: grid; place-items: center; }
.nav-prev { left: 12px; } .nav-next { right: 12px; }
.viewer .nofile { display: grid; gap: 12px; text-align: center; color: #bbb; }

/* Mobile */
@media (max-width: 820px) {
  .side { position: fixed; inset: 0 auto 0 0; z-index: 45; width: 84%; max-width: 320px; transform: translateX(-102%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: var(--shadow); }
  .veil { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 44; }
  .burger { display: inline-grid; }
  .top { padding: 10px 10px 6px; min-height: 58px; gap: 4px; }
  .top h1, .crumbs { font-size: 19px; }
  .crumbs a { max-width: 150px; }
  .chip .chip-label { display: none; }
  .chip { padding: 10px; }
  .content { padding: 4px 10px 100px; }
  .selbar { padding: 6px 10px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 4px; }
  .tile .pic { height: 86px; }
  .folder { width: 84px; height: 66px; }
  .ficon { width: 62px; height: 78px; }
  .list .folder { width: 38px; height: 30px; }
  .list .ficon { width: 32px; height: 38px; }
  .list .tile .meta { display: none; }
  .photos { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 2px; }
  .ph { border-radius: 2px; }
  .fab { display: grid; }
  .menu.sheet { left: 8px !important; right: 8px; top: auto !important; bottom: calc(8px + env(safe-area-inset-bottom)); }
  .nav-prev, .nav-next { display: none; }
  .uploads { right: 16px; bottom: 90px; }
  .check { opacity: 1; background: transparent; box-shadow: none; }
  .grid:not(.list) .tile:not(.sel) .check { opacity: 0; }
  .selecting .grid:not(.list) .tile .check { opacity: 1; background: var(--bg); }
}

/* Public share page */
body.share { background: var(--side); min-height: 100%; }
.share-head { padding: 16px 20px; }
.share-main { max-width: 760px; margin: 0 auto; padding: 8px 16px 40px; }
.share-main h1 { font-size: 22px; font-weight: 600; margin: 8px 0; word-break: break-word; }
.share-img { display: block; max-width: 100%; max-height: 70vh; border-radius: 14px; margin: 14px 0; }
.share-meta { color: var(--muted); font-size: 14px; white-space: nowrap; }
.share-msg { color: var(--muted); padding: 40px 0; text-align: center; }
.share-list { list-style: none; padding: 0; display: grid; gap: 2px; }
.share-list a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; text-decoration: none; }
.share-list a:hover { background: var(--hover); }
.share-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
