:root {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --panel-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #16191f;
  --muted: #646b78;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #b45309;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --panel: #171a21;
    --panel-2: #1e222b;
    --border: #2a2f3a;
    --text: #e8eaee;
    --muted: #9aa1ae;
    --accent: #5b8dff;
    --accent-soft: #1d2a4a;
    --danger: #f05252;
    --ok: #34c06a;
    --warn: #e0a24a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .35);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 var(--font); background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; word-break: break-all; }
.hidden { display: none !important; }

/* Buttons & inputs */
.btn { display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 14px; border-radius: 9px; border: 1px solid var(--border); background: var(--panel); cursor: pointer; white-space: nowrap; font-weight: 500; transition: background .12s, border-color .12s; }
.btn:hover { background: var(--panel-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.icon { width: 36px; padding: 0; justify-content: center; }
.btn.lg { height: 44px; padding: 0 20px; font-size: 15px; border-radius: 11px; }
.input { width: 100%; height: 40px; padding: 0 12px; border-radius: 9px; border: 1px solid var(--border); background: var(--panel); outline: none; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label.field { display: block; margin: 0 0 14px; }
label.field > span { display: block; font-weight: 500; margin-bottom: 6px; }
.err { color: var(--danger); min-height: 20px; margin: 4px 0 0; }

.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; }
.spinner.sm { width: 16px; height: 16px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.boot { height: 100vh; display: grid; place-items: center; }

/* Auth / setup cards */
.center { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); padding: 28px; width: 100%; max-width: 440px; }
.card.wide { max-width: 560px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.brand img { width: 32px; height: 32px; }
.card h1 { font-size: 22px; margin: 18px 0 6px; letter-spacing: -.01em; }
.card p.lead { color: var(--muted); margin: 0 0 22px; }
.steps { display: flex; gap: 6px; margin-top: 18px; }
.steps i { flex: 1; height: 4px; border-radius: 4px; background: var(--border); }
.steps i.on { background: var(--accent); }
.row { display: flex; gap: 10px; align-items: center; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }

/* App layout */
.layout { display: grid; grid-template-columns: 240px 1fr; height: 100vh; }
.side { border-right: 1px solid var(--border); background: var(--panel); padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; }
.side .brand { padding: 4px 8px 16px; }
.nav { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 9px; cursor: pointer; color: var(--text); font-weight: 500; border: 0; background: none; width: 100%; text-align: left; }
.nav:hover { background: var(--panel-2); }
.nav.on { background: var(--accent-soft); color: var(--accent); }
.side .grow { flex: 1; }
.usage { padding: 12px; font-size: 12.5px; color: var(--muted); }
.bar { height: 6px; border-radius: 6px; background: var(--panel-2); overflow: hidden; margin: 6px 0; }
.bar > div { height: 100%; background: var(--accent); border-radius: 6px; }
.main { display: flex; flex-direction: column; min-width: 0; height: 100vh; }
.top { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--panel); }
.search { flex: 1; max-width: 560px; position: relative; }
.search svg { position: absolute; left: 12px; top: 11px; color: var(--muted); }
.search input { padding-left: 38px; background: var(--panel-2); border-color: transparent; }
.menu-btn { display: none; }
.content { flex: 1; overflow: auto; padding: 16px 20px 80px; position: relative; }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.crumbs { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; font-size: 18px; font-weight: 600; flex: 1; min-width: 200px; }
.crumbs button { border: 0; background: none; padding: 4px 8px; border-radius: 8px; cursor: pointer; font-weight: 600; }
.crumbs button:hover { background: var(--panel-2); }
.crumbs .sep { color: var(--muted); }
.selbar { display: flex; align-items: center; gap: 8px; background: var(--accent-soft); border-radius: 10px; padding: 6px 8px 6px 14px; margin-bottom: 12px; }
.selbar .grow { flex: 1; font-weight: 600; color: var(--accent); }

/* File list */
.list { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.list .hdr, .list .item { display: grid; grid-template-columns: 34px 1fr 110px 150px 40px; align-items: center; gap: 8px; padding: 0 10px; }
.list .hdr { height: 38px; color: var(--muted); font-size: 12.5px; font-weight: 600; border-bottom: 1px solid var(--border); }
.list.trashlist .hdr, .list.trashlist .item { grid-template-columns: 34px 1fr 110px 150px 84px; }
.list .item { height: 48px; border-bottom: 1px solid var(--border); cursor: default; user-select: none; }
.list .item:last-child { border-bottom: 0; }
.list .item:hover { background: var(--panel-2); }
.item.sel { background: var(--accent-soft) !important; }
.item .name { display: flex; align-items: center; gap: 12px; min-width: 0; }
.item .name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta { color: var(--muted); font-size: 12.5px; }
.ficon { width: 30px; height: 30px; border-radius: 7px; display: grid; place-items: center; flex: none; }
.ficon svg { width: 17px; height: 17px; }
.check { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.tile { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; position: relative; cursor: default; user-select: none; }
.tile:hover { box-shadow: var(--shadow); }
.tile .thumb { aspect-ratio: 4/3; background: var(--panel-2); display: grid; place-items: center; overflow: hidden; }
.tile .thumb img { width: 100%; height: 100%; object-fit: cover; }
.tile .thumb .ficon { width: 52px; height: 52px; border-radius: 12px; }
.tile .thumb .ficon svg { width: 26px; height: 26px; }
.tile .cap { display: flex; align-items: center; gap: 6px; padding: 8px 6px 8px 12px; }
.tile .cap span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.tile .check { position: absolute; top: 10px; left: 10px; opacity: 0; }
.tile:hover .check, .tile.sel .check, .selecting .tile .check { opacity: 1; }
.empty { text-align: center; padding: 70px 20px; color: var(--muted); }
.empty svg { width: 54px; height: 54px; stroke-width: 1.3; opacity: .6; }
.empty h3 { color: var(--text); margin: 12px 0 4px; }

/* Drop overlay */
.drop { position: fixed; inset: 0; background: rgba(37, 99, 235, .12); border: 3px dashed var(--accent); display: grid; place-items: center; z-index: 50; pointer-events: none; }
.drop div { background: var(--panel); padding: 18px 26px; border-radius: 14px; box-shadow: var(--shadow); font-weight: 600; font-size: 16px; display: flex; gap: 10px; align-items: center; }

/* Context menu */
.ctx { position: fixed; z-index: 60; background: var(--panel); border: 1px solid var(--border); border-radius: 11px; box-shadow: var(--shadow); padding: 6px; min-width: 190px; }
.ctx button { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; padding: 8px 10px; border-radius: 7px; cursor: pointer; text-align: left; }
.ctx button:hover { background: var(--panel-2); }
.ctx button.danger { color: var(--danger); }
.ctx hr { border: 0; border-top: 1px solid var(--border); margin: 5px 0; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 12, 16, .5); z-index: 70; display: grid; place-items: center; padding: 20px; animation: fade .12s; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--panel); border-radius: 16px; box-shadow: var(--shadow); width: 100%; max-width: 440px; padding: 22px; max-height: 90vh; overflow: auto; }
.modal h2 { margin: 0 0 14px; font-size: 18px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.picker { border: 1px solid var(--border); border-radius: 10px; max-height: 280px; overflow: auto; }
.picker button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; border: 0; background: none; border-bottom: 1px solid var(--border); cursor: pointer; text-align: left; }
.picker button:hover { background: var(--panel-2); }

/* Viewer */
.viewer { position: fixed; inset: 0; z-index: 80; background: rgba(8, 9, 12, .94); display: flex; flex-direction: column; color: #eee; }
.viewer .vbar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; }
.viewer .vbar .title { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer .btn { background: rgba(255, 255, 255, .08); border-color: transparent; color: #eee; }
.viewer .btn:hover { background: rgba(255, 255, 255, .16); }
.viewer .stage { flex: 1; display: grid; place-items: center; min-height: 0; padding: 0 56px 20px; position: relative; }
.viewer .stage img, .viewer .stage video { max-width: 100%; max-height: 100%; border-radius: 6px; }
.viewer .stage iframe { width: 100%; height: 100%; border: 0; background: #fff; border-radius: 6px; }
.viewer .stage pre { background: #16181d; color: #e6e6e6; width: 100%; height: 100%; margin: 0; overflow: auto; padding: 18px; border-radius: 8px; white-space: pre-wrap; word-break: break-word; font-size: 13px; }
.viewer .nav-arrow { position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 44px; border-radius: 50%; }
.viewer .nav-arrow.l { left: 8px; }
.viewer .nav-arrow.r { right: 8px; }
.viewer .nofmt { text-align: center; }

/* Upload panel */
.uploads { position: fixed; right: 20px; bottom: 20px; width: 360px; max-width: calc(100vw - 40px); background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); z-index: 40; overflow: hidden; }
.uploads .uh { display: flex; align-items: center; gap: 8px; padding: 12px 10px 12px 16px; font-weight: 600; border-bottom: 1px solid var(--border); }
.uploads .uh span { flex: 1; }
.uploads .ul { max-height: 260px; overflow: auto; }
.uploads .u { padding: 9px 16px; border-bottom: 1px solid var(--border); font-size: 13px; }
.uploads .u .row { gap: 8px; }
.uploads .u .n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uploads .bar { margin: 6px 0 0; height: 4px; }
.uploads .done .bar > div { background: var(--ok); }
.uploads .fail .bar > div { background: var(--danger); }

/* Settings */
.page { max-width: 820px; }
.page h2 { margin: 4px 0 16px; font-size: 20px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; }
.panel h3 { margin: 0 0 4px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.panel .desc { color: var(--muted); margin: 0 0 14px; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 14px; align-items: center; }
.kv .k { color: var(--muted); }
.linkbox { display: flex; align-items: center; gap: 8px; background: var(--panel-2); border-radius: 10px; padding: 8px 8px 8px 12px; margin: 6px 0; }
.linkbox .mono { flex: 1; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 99px; background: var(--panel-2); color: var(--muted); }
.pill.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.pill.warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--border); border-radius: 24px; cursor: pointer; transition: .15s; }
.switch span::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(18px); }
.notice { background: color-mix(in srgb, var(--warn) 12%, transparent); border-radius: 10px; padding: 10px 12px; margin: 10px 0; }
.share-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); }
.share-row:last-child { border-bottom: 0; }

/* Toasts */
#toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: #1f2430; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); animation: fade .15s; max-width: 90vw; }
.toast.err { background: var(--danger); }

/* Mobile */
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 65; transform: translateX(-100%); transition: transform .18s; box-shadow: var(--shadow); }
  .side.open { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 64; }
  .menu-btn { display: inline-flex; }
  .top { padding: 10px 12px; }
  .content { padding: 12px 12px 90px; }
  .list .hdr { display: none; }
  .list .item, .list.trashlist .item { grid-template-columns: 30px 1fr 36px; height: 56px; }
  .list .item .meta.size, .list .item .meta.date { display: none; }
  .item .name .sub { display: block; font-size: 12px; color: var(--muted); }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .hide-sm { display: none !important; }
  .viewer .stage { padding: 0 8px 12px; }
  .viewer .nav-arrow { display: none; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv .k { margin-top: 8px; }
  .fab { position: fixed; right: 18px; bottom: 18px; width: 56px; height: 56px; border-radius: 16px; z-index: 30; box-shadow: var(--shadow); }
}
@media (min-width: 761px) {
  .fab { display: none !important; }
  .item .name .sub { display: none; }
}
