:root {
  --bg: #f6f7f1;
  --surface: #fffefa;
  --surface-2: #f0f4e8;
  --hover: #eaf0df;
  --selected: #e1ecc9;
  --border: #dce5d4;
  --ink: #172c25;
  --ink-2: #4f6356;
  --ink-3: #7b8a7f;
  --brand: #174e3b;
  --brand-ink: #fffdf6;
  --brand-hover: #0f3d2d;
  --lime: #d9eca9;
  --lime-ink: #174e3b;
  --danger: #b3261e;
  --danger-bg: #fbe9e7;
  --shadow: 0 1px 2px rgb(23 44 37 / 6%), 0 8px 24px rgb(23 44 37 / 8%);
  --shadow-lg: 0 24px 64px rgb(23 44 37 / 22%);
  --radius: 14px;
  --sidebar: 256px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1814; --surface: #15211b; --surface-2: #1a2922; --hover: #1f3128; --selected: #26402f;
    --border: #273a30; --ink: #e8efe6; --ink-2: #aebdb2; --ink-3: #7e9084;
    --brand: #d9eca9; --brand-ink: #10261d; --brand-hover: #e7f4c4; --lime: #2a4a2f; --lime-ink: #d9eca9;
    --danger: #ff8a80; --danger-bg: #3a1d1b;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 30%); --shadow-lg: 0 24px 64px rgb(0 0 0 / 55%);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1814; --surface: #15211b; --surface-2: #1a2922; --hover: #1f3128; --selected: #26402f;
  --border: #273a30; --ink: #e8efe6; --ink-2: #aebdb2; --ink-3: #7e9084;
  --brand: #d9eca9; --brand-ink: #10261d; --brand-hover: #e7f4c4; --lime: #2a4a2f; --lime-ink: #d9eca9;
  --danger: #ff8a80; --danger-bg: #3a1d1b;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 30%); --shadow-lg: 0 24px 64px rgb(0 0 0 / 55%);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
.mono { font-family: var(--mono); }
.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 8px; }

/* Brand */
.brand { display: flex; align-items: center; gap: 10px; font-size: 18px; letter-spacing: -.01em; color: var(--ink); }
.brand .mark { width: 32px; height: 32px; }
.brand b { font-weight: 700; color: var(--brand); }
:root[data-theme="dark"] .brand b { color: var(--lime-ink); }
.brand-lg { font-size: 24px; justify-content: center; }
.brand-lg .mark { width: 44px; height: 44px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 16px; border-radius: 999px; border: 1px solid transparent; background: none; font-weight: 600; white-space: nowrap; transition: background .15s, border-color .15s, transform .1s; }
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: var(--brand-hover); }
.btn-ghost { border-color: var(--border); background: var(--surface); color: var(--ink); }
.btn-ghost:hover { background: var(--hover); }
.btn-ghost.danger { color: var(--danger); }
.btn-ghost.danger:hover { background: var(--danger-bg); }
.btn-block { width: 100%; }
.btn:disabled { opacity: .6; cursor: default; }
.icon-btn { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 999px; border: 0; background: none; color: var(--ink-2); flex: none; }
.icon-btn:hover { background: var(--hover); color: var(--ink); }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 10% -10%, var(--lime) 0%, transparent 55%), radial-gradient(900px 500px at 110% 110%, var(--selected) 0%, transparent 50%), var(--bg); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 22px; padding: 36px 28px 28px; box-shadow: var(--shadow); display: grid; gap: 16px; }
.login-sub { text-align: center; color: var(--ink-2); margin: -4px 0 8px; }
.field { display: grid; gap: 6px; font-weight: 600; font-size: 13px; color: var(--ink-2); }
.field input, .dialog input, .dialog select { height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg); font-size: 15px; font-weight: 400; color: var(--ink); width: 100%; }
.field input:focus, .dialog input:focus, .dialog select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
.form-error { margin: 0; min-height: 1em; color: var(--danger); font-size: 13px; }

/* Layout */
.app { display: grid; grid-template-columns: var(--sidebar) 1fr; height: 100%; }
.sidebar { display: flex; flex-direction: column; gap: 18px; padding: 20px 16px; border-right: 1px solid var(--border); background: var(--surface); overflow-y: auto; }
.sidebar .brand { padding: 2px 8px 6px; }
.side-nav { display: grid; gap: 2px; }
.side-link { display: flex; align-items: center; gap: 12px; height: 40px; padding: 0 12px; border-radius: 999px; border: 0; background: none; color: var(--ink-2); font-weight: 600; text-align: left; width: 100%; }
.side-link:hover { background: var(--hover); color: var(--ink); }
.side-link.active { background: var(--lime); color: var(--lime-ink); }
.side-foot { margin-top: auto; }
.storage { padding: 16px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); }
.storage-head { display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-weight: 600; font-size: 13px; }
.storage-num { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.storage-meta { color: var(--ink-3); font-size: 12px; overflow-wrap: anywhere; }
.storage-meta.mono { margin-top: 8px; font-size: 11px; }

.main { position: relative; display: flex; flex-direction: column; min-width: 0; height: 100%; overflow: hidden; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 14px 24px; }
.menu-btn { display: none; }
.search { flex: 1; display: flex; align-items: center; gap: 10px; height: 46px; padding: 0 16px; border-radius: 999px; background: var(--surface-2); border: 1px solid transparent; color: var(--ink-3); max-width: 720px; transition: background .15s, border-color .15s; }
.search:focus-within { background: var(--surface); border-color: var(--border); box-shadow: var(--shadow); }
.search input { flex: 1; min-width: 0; border: 0; background: none; outline: none; font-size: 15px; color: var(--ink); }
.top-upload { margin-left: auto; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 24px 12px; flex-wrap: wrap; }
.crumbs { display: flex; align-items: center; gap: 2px; font-size: 20px; font-weight: 600; letter-spacing: -.01em; min-width: 0; flex-wrap: wrap; }
.crumbs a, .crumbs span.cur { padding: 4px 10px; border-radius: 10px; white-space: nowrap; max-width: 280px; overflow: hidden; text-overflow: ellipsis; }
.crumbs a { color: var(--ink-2); }
.crumbs a:hover { background: var(--hover); color: var(--ink); }
.crumbs a.drop-hover { background: var(--selected); color: var(--ink); }
.crumbs .sep { color: var(--ink-3); width: 16px; height: 16px; }
.tools { display: flex; align-items: center; gap: 8px; }
.select { height: 38px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); font-weight: 600; }
.seg { display: flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; background: var(--surface); }
.seg-btn { display: grid; place-items: center; width: 42px; height: 36px; border: 0; background: none; color: var(--ink-2); }
.seg-btn.on { background: var(--lime); color: var(--lime-ink); }

.selbar { display: flex; align-items: center; gap: 10px; margin: 0 24px 10px; padding: 6px 8px 6px 6px; border-radius: 999px; background: var(--lime); color: var(--lime-ink); font-weight: 600; }
.selbar .icon-btn { color: var(--lime-ink); }
.selbar-actions { margin-left: auto; display: flex; gap: 6px; }
.selbar .btn { height: 34px; padding: 0 12px; }

.content { flex: 1; overflow-y: auto; padding: 0 24px 120px; }

/* List view */
.list-head, .items.list .row { display: grid; grid-template-columns: 36px minmax(0, 1fr) 170px 100px 44px; align-items: center; gap: 8px; }
.list-head { position: sticky; top: 0; z-index: 2; height: 40px; padding: 0 8px; background: var(--bg); border-bottom: 1px solid var(--border); color: var(--ink-3); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.items.list .row { height: 52px; padding: 0 8px; border-bottom: 1px solid var(--border); border-radius: 0; cursor: default; user-select: none; }
.items.list .row:hover { background: var(--hover); }
.row.sel, .items.list .row.sel:hover { background: var(--selected); }
.row.drop-hover { outline: 2px dashed var(--brand); outline-offset: -2px; background: var(--selected); }
.name { display: flex; align-items: center; gap: 12px; min-width: 0; }
.name-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.name-sub { display: block; color: var(--ink-3); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-mod, .col-size { color: var(--ink-2); font-size: 13px; font-variant-numeric: tabular-nums; }
.col-size { text-align: right; }
.list-head .col-size { text-align: right; }
.row .more { opacity: 0; }
.row:hover .more, .row.sel .more, .row .more:focus-visible { opacity: 1; }

.ft { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; flex: none; font-size: 9px; font-weight: 800; letter-spacing: .03em; color: #fff; background: #7b8a7f; }
.ft .i { width: 18px; height: 18px; }
.ft.folder { background: none; color: var(--brand); }
.ft.folder svg { width: 30px; height: 30px; }
.ft.img { background: #3f8f5f; } .ft.vid { background: #9b4dca; } .ft.aud { background: #d9822b; }
.ft.pdf { background: #d9443b; } .ft.doc { background: #2f6fd6; } .ft.xls { background: #1f8f4e; } .ft.ppt { background: #d0612f; }
.ft.zip { background: #8a6d3b; } .ft.code { background: #37474f; } .ft.txt { background: #6b7c72; }

.check { position: relative; display: grid; place-items: center; width: 36px; height: 36px; cursor: pointer; }
.check input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.check span { width: 18px; height: 18px; border-radius: 6px; border: 1.8px solid var(--ink-3); background: var(--surface); transition: all .12s; }
.check input:checked + span { background: var(--brand); border-color: var(--brand); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fffdf6' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 12 5 5 9-10'/%3E%3C/svg%3E"); background-size: 14px; background-position: center; background-repeat: no-repeat; }
:root[data-theme="dark"] .check input:checked + span { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2310261d' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 12 5 5 9-10'/%3E%3C/svg%3E"); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .check input:checked + span { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2310261d' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 12 5 5 9-10'/%3E%3C/svg%3E"); } }
.check input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }

/* Grid view */
.content.grid-mode .list-head { display: none; }
.items.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; padding-top: 6px; }
.items.grid .row { position: relative; display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; user-select: none; transition: box-shadow .15s, border-color .15s; }
.items.grid .row:hover { box-shadow: var(--shadow); }
.items.grid .row.sel { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); background: var(--surface); }
.items.grid .thumb { aspect-ratio: 4/3; display: grid; place-items: center; background: var(--surface-2); overflow: hidden; }
.items.grid .thumb img { width: 100%; height: 100%; object-fit: cover; }
.items.grid .thumb .ft { width: 56px; height: 56px; border-radius: 14px; font-size: 13px; }
.items.grid .thumb .ft .i { width: 26px; height: 26px; }
.items.grid .thumb .ft.folder svg { width: 64px; height: 64px; }
.items.grid .meta { display: flex; align-items: center; gap: 4px; padding: 8px 4px 8px 12px; min-width: 0; }
.items.grid .meta .name-text { flex: 1; font-size: 13px; }
.items.grid .check { position: absolute; top: 6px; left: 6px; opacity: 0; }
.items.grid .row:hover .check, .items.grid .row.sel .check, .items.grid.selecting .check { opacity: 1; }
.items.grid .col-mod, .items.grid .col-size, .items.grid .name > .ft { display: none; }
.items.grid.grid-folders { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }

.empty { display: grid; justify-items: center; text-align: center; padding: 80px 16px; color: var(--ink-2); }
.empty-art { width: 96px; height: 96px; border-radius: 30px; display: grid; place-items: center; background: var(--lime); color: var(--lime-ink); margin-bottom: 16px; }
.empty-art .i { width: 46px; height: 46px; }
.empty h2 { margin: 0 0 4px; font-size: 18px; color: var(--ink); }
.empty p { margin: 0; }
.loading { display: grid; place-items: center; padding: 60px; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--brand); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.load-more { display: flex; margin: 16px auto; }

.drop { position: absolute; inset: 8px; z-index: 20; display: grid; place-items: center; border-radius: 20px; border: 2px dashed var(--brand); background: color-mix(in srgb, var(--lime) 55%, transparent); backdrop-filter: blur(2px); pointer-events: none; }
.drop-inner { display: grid; justify-items: center; gap: 6px; padding: 28px 36px; border-radius: 20px; background: var(--surface); box-shadow: var(--shadow-lg); color: var(--ink); }
.drop-inner .i { width: 44px; height: 44px; color: var(--brand); }
.drop-inner span { color: var(--ink-2); font-size: 13px; }

/* Upload tray */
.tray { position: fixed; right: 20px; bottom: 20px; z-index: 40; width: 380px; max-width: calc(100vw - 32px); background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow-lg); overflow: hidden; }
.tray-head { display: flex; align-items: center; gap: 2px; padding: 8px 8px 8px 18px; background: var(--surface-2); }
.tray-head strong { flex: 1; }
.tray.collapsed .tray-list { display: none; }
.tray.collapsed #tray-toggle { transform: rotate(180deg); }
.tray-list { list-style: none; margin: 0; padding: 4px 0; max-height: 320px; overflow-y: auto; }
.tray-item { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 12px; padding: 8px 12px 8px 16px; }
.tray-item .ft { width: 30px; height: 30px; }
.tray-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.tray-sub { color: var(--ink-3); font-size: 12px; }
.bar { height: 4px; border-radius: 4px; background: var(--border); overflow: hidden; margin-top: 5px; }
.bar i { display: block; height: 100%; width: 0; background: var(--brand); transition: width .2s; }
.tray-item.done .bar, .tray-item.err .bar { display: none; }
.tray-state .i { width: 20px; height: 20px; }
.tray-item.done .tray-state { color: #3f8f5f; }
.tray-item.err .tray-state, .tray-item.err .tray-sub { color: var(--danger); }

/* Menu */
.menu { position: fixed; z-index: 60; min-width: 210px; padding: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg); }
.menu button { display: flex; align-items: center; gap: 12px; width: 100%; height: 38px; padding: 0 12px; border: 0; border-radius: 9px; background: none; text-align: left; }
.menu button:hover, .menu button:focus-visible { background: var(--hover); outline: none; }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 5px 4px; }

/* Viewer */
.viewer { position: fixed; inset: 0; z-index: 50; display: grid; grid-template-rows: auto 1fr; background: rgb(8 14 11 / 94%); color: #eef3ec; }
.viewer .icon-btn { color: #d9e3d6; }
.viewer .icon-btn:hover { background: rgb(255 255 255 / 12%); color: #fff; }
.viewer-bar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; }
.viewer-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.viewer-body { display: grid; place-items: center; min-height: 0; padding: 8px 72px 28px; overflow: auto; }
.viewer-body img, .viewer-body video { max-width: 100%; max-height: calc(100vh - 110px); border-radius: 8px; }
.viewer-body audio { width: min(520px, 90vw); }
.viewer-body iframe { width: min(1100px, 100%); height: calc(100vh - 110px); border: 0; border-radius: 8px; background: #fff; }
.viewer-body pre { width: min(1100px, 100%); max-height: calc(100vh - 110px); margin: 0; overflow: auto; padding: 20px; border-radius: 10px; background: #111c16; color: #dfe8dc; font: 13px/1.55 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }
.viewer-nav { position: absolute; top: 50%; width: 48px; height: 48px; margin-top: -24px; border-radius: 50%; border: 0; display: grid; place-items: center; background: rgb(255 255 255 / 10%); color: #fff; }
.viewer-nav:hover { background: rgb(255 255 255 / 20%); }
.viewer-nav.prev { left: 14px; } .viewer-nav.next { right: 14px; }
.viewer-nav .i { width: 24px; height: 24px; }
.no-preview { display: grid; justify-items: center; gap: 14px; text-align: center; }
.no-preview .ft { width: 84px; height: 84px; border-radius: 22px; font-size: 16px; }
.no-preview .ft .i { width: 36px; height: 36px; }

/* Dialog */
.dialog { width: min(440px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--border); border-radius: 20px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg); }
.dialog::backdrop { background: rgb(15 24 20 / 45%); backdrop-filter: blur(2px); }
.dialog form { display: grid; gap: 14px; padding: 22px; }
.dialog h3 { margin: 0; font-size: 18px; }
.dialog p { margin: 0; color: var(--ink-2); }
#dialog-body { display: grid; gap: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.dialog .danger-btn { background: var(--danger); color: #fff; }
.share-out { display: flex; gap: 8px; }
.share-out input { font-family: var(--mono); font-size: 12px; }

/* Toasts */
.toasts { position: fixed; left: 50%; bottom: 24px; z-index: 70; transform: translateX(-50%); display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-radius: 12px; background: var(--ink); color: var(--bg); font-weight: 500; box-shadow: var(--shadow-lg); animation: rise .2s ease-out; max-width: calc(100vw - 32px); }
.toast.err { background: var(--danger); color: #fff; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.scrim { position: fixed; inset: 0; z-index: 29; background: rgb(15 24 20 / 40%); }

/* Responsive */
@media (max-width: 900px) {
  .list-head, .items.list .row { grid-template-columns: 36px minmax(0, 1fr) 90px 44px; }
  .col-mod { display: none; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 30; width: min(var(--sidebar), 85vw); transform: translateX(-100%); visibility: hidden; transition: transform .2s, visibility .2s; }
  .sidebar.open { transform: none; visibility: visible; box-shadow: var(--shadow-lg); }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 10px 16px; gap: 6px; }
  .top-upload span, .tools .btn span, .selbar .btn span { display: none; }
  .top-upload, .tools .btn { width: 42px; padding: 0; flex: none; }
  .search { height: 42px; }
  .toolbar { padding: 2px 16px 10px; }
  .crumbs { font-size: 17px; }
  .selbar { margin: 0 16px 8px; }
  .selbar .btn { width: 36px; padding: 0; }
  .content { padding: 0 16px 120px; }
  .list-head, .items.list .row { grid-template-columns: 36px minmax(0, 1fr) 44px; }
  .col-size, .list-head span.col-size { display: none; }
  .row .more { opacity: 1; }
  .items.grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .items.grid .check { opacity: 1; }
  .viewer-body { padding: 8px 8px 20px; }
  .viewer-nav { display: none; }
  .tray { right: 16px; bottom: 16px; }
}
@media (max-width: 380px) { .tools .select { display: none; } }
