/* Drive UI. Tokens mirror DESIGN.md. */
:root {
  --overlay: rgb(0 0 0 / .6); --stage: #0b0d10; --stage-ink: #f2f4f7; --stage-muted: #a8b0ba; --stage-hover: rgb(255 255 255 / .1);
  --bg: #ffffff; --panel: #f3f5f8; --panel-2: #e9edf2; --line: #e1e5eb; --text: #1b1f24; --muted: #5b6470;
  --accent: #2357d8; --accent-hover: #1c48b8; --accent-ink: #ffffff; --accent-soft: #e6edfc; --danger: #c42b1c;
  --scrim: rgb(10 14 20 / .55); --shadow: 0 8px 24px rgb(16 24 40 / .14), 0 2px 6px rgb(16 24 40 / .06);
  --r-bar: 999px; --r-control: 8px; --r-tile: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171b; --panel: #1c2026; --panel-2: #252a32; --line: #2c323a; --text: #e8ebef; --muted: #a0a8b3;
    --accent: #7fa2ff; --accent-hover: #9db8ff; --accent-ink: #0d1424; --accent-soft: #1f2a44; --danger: #ff7a6b;
    --scrim: rgb(0 0 0 / .7); --shadow: 0 8px 24px rgb(0 0 0 / .45), 0 2px 6px rgb(0 0 0 / .3);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 400 0.9375rem/1.45 var(--font); }
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.ic { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.ic-sm { width: 16px; height: 16px; }
.ic-lg { width: 28px; height: 28px; }
.ic-xl { width: 48px; height: 48px; stroke-width: 1.5; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: var(--r-control); background: var(--bg); cursor: pointer; white-space: nowrap;
  text-decoration: none; font-weight: 500; transition: background-color .15s, border-color .15s, color .15s; }
.btn:hover { background: var(--panel); }
.btn:active { background: var(--panel-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-primary:active { background: var(--accent-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.95); background: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--panel); }
.btn-icon { width: 40px; padding: 0; }
.btn-sm { height: 32px; padding: 0 10px; font-size: .8125rem; }
.btn-sm.btn-icon { width: 32px; }
.btn.is-loading { pointer-events: none; opacity: .7; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-control); overflow: hidden; }
.seg button { height: 38px; width: 40px; border: 0; background: transparent; display: grid; place-items: center; cursor: pointer; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.seg button:hover { color: var(--text); }

/* Inputs */
.field { display: grid; gap: 6px; }
.field label { font-size: .8125rem; font-weight: 500; color: var(--muted); }
.input { height: 42px; width: 100%; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--r-control);
  background: var(--bg); transition: border-color .15s, box-shadow .15s; }
.input::placeholder { color: var(--muted); }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.error { color: var(--danger); font-size: .8125rem; margin: 0; }
.with-btn { position: relative; }
.with-btn .input { padding-right: 44px; }
.with-btn .btn { position: absolute; right: 1px; top: 1px; height: 40px; border: 0; }

/* App frame */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; height: 60px;
  padding: 0 max(16px, env(safe-area-inset-left)); background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 650; font-size: 1.125rem; text-decoration: none; }
.brand .ic { color: var(--accent); width: 24px; height: 24px; }
.tabs { display: flex; gap: 4px; margin-left: 8px; }
.tab { height: 36px; padding: 0 12px; display: inline-flex; align-items: center; border-radius: var(--r-control);
  text-decoration: none; color: var(--muted); font-weight: 500; }
.tab:hover { background: var(--panel-2); color: var(--text); }
.tab[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.spacer { flex: 1; }
.user { display: inline-flex; align-items: center; gap: 8px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink);
  font-weight: 600; font-size: .875rem; text-transform: uppercase; }
.main { max-width: 1280px; margin: 0 auto; padding: 16px max(16px, env(safe-area-inset-right)) 120px; }

.toolbar { display: flex; align-items: center; gap: 8px; min-height: 56px; flex-wrap: wrap; margin-bottom: 8px; }
.crumbs { display: flex; align-items: center; gap: 2px; min-width: 0; flex: 1 1 260px; font-size: 1.125rem; }
.crumbs a, .crumbs span { padding: 4px 8px; border-radius: var(--r-control); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 28ch; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { background: var(--panel); color: var(--text); }
.crumbs span[aria-current] { font-weight: 600; }
.crumbs .ic { color: var(--muted); }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: 12px; }
.section-label { font-size: .8125rem; font-weight: 600; color: var(--muted); margin: 20px 0 10px; }
.tile { position: relative; display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--r-tile);
  background: var(--bg); overflow: hidden; cursor: pointer; transition: border-color .15s, box-shadow .15s; }
.tile:hover { border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); box-shadow: 0 2px 8px rgb(16 24 40 / .08); }
.tile:focus-within { border-color: var(--accent); }
.tile-open { all: unset; display: flex; flex-direction: column; cursor: pointer; }
.tile-open:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: var(--r-tile); }
.thumb { position: relative; aspect-ratio: 16 / 10; background: var(--panel); display: grid; place-items: center; color: var(--muted); overflow: hidden; }
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.thumb .ic { width: 40px; height: 40px; stroke-width: 1.5; }
.play { position: absolute; left: 10px; bottom: 10px; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--overlay); color: #fff; }
.play .ic { width: 16px; height: 16px; }
.tile-more { position: absolute; right: 4px; bottom: 8px; }
.tile .tile-body { padding-right: 40px; }
.tile-body { display: flex; align-items: center; gap: 8px; padding: 10px 6px 10px 12px; min-width: 0; }
.tile-text { min-width: 0; flex: 1; }
.name { display: block; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-open .name { white-space: normal; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.3; }
.folder-tile .name { -webkit-line-clamp: 1; }
.meta { display: block; font-size: .8125rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.folder-tile { flex-direction: row; align-items: center; }
.folder-tile .tile-open { flex-direction: row; align-items: center; gap: 12px; padding: 12px 0 12px 14px; flex: 1; min-width: 0; }
.folder-tile .ic-folder { color: var(--accent); width: 24px; height: 24px; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: .75rem; color: var(--muted); }

/* List */
.list { width: 100%; border-collapse: collapse; }
.list th { text-align: left; font-size: .8125rem; font-weight: 600; color: var(--muted); padding: 8px 12px; border-bottom: 1px solid var(--line); }
.list td { padding: 0 12px; height: 52px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.list tr.row { cursor: pointer; }
.list tr.row:hover td { background: var(--panel); }
.list .c-name { width: 100%; max-width: 0; }
.list .c-name > div { display: flex; align-items: center; gap: 12px; min-width: 0; }
.list .c-name .name { flex: 1; }
.list .c-num { white-space: nowrap; color: var(--muted); font-size: .875rem; }
.list .c-act { width: 1%; padding-right: 4px; }
.list .ic-type { color: var(--muted); }
.list .ic-folder { color: var(--accent); }
.row-open { all: unset; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.row-open:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* Empty + skeleton */
.empty { display: grid; justify-items: center; gap: 10px; text-align: center; padding: 64px 16px; border: 1.5px dashed var(--line); border-radius: var(--r-tile); color: var(--muted); }
.empty h2 { margin: 0; font-size: 1.125rem; color: var(--text); }
.empty p { margin: 0; max-width: 46ch; }
.empty .ic-xl { color: var(--accent); }
.skel { border-radius: var(--r-tile); background: linear-gradient(90deg, var(--panel) 0%, var(--panel-2) 50%, var(--panel) 100%);
  background-size: 200% 100%; animation: shimmer 1.4s ease-in-out infinite; aspect-ratio: 16 / 13; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* Menu */
.menu { position: fixed; z-index: 60; min-width: 200px; padding: 6px; background: var(--bg); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow); }
.menu button, .menu a { display: flex; align-items: center; gap: 10px; width: 100%; height: 38px; padding: 0 10px; border: 0;
  background: transparent; border-radius: 6px; cursor: pointer; text-align: left; text-decoration: none; }
.menu button:hover, .menu a:hover, .menu button:focus-visible, .menu a:focus-visible { background: var(--panel); outline: none; }
.menu .danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }

/* Dialog */
dialog { border: 0; padding: 0; color: var(--text); background: var(--bg); }
#dlg { width: min(520px, calc(100vw - 32px)); border-radius: 12px; box-shadow: var(--shadow); }
dialog::backdrop { background: var(--scrim); }
.dlg-head { display: flex; align-items: center; gap: 12px; padding: 18px 20px 6px; }
.dlg-head h2 { margin: 0; font-size: 1.125rem; font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dlg-body { padding: 10px 20px 4px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
#dlg form { min-width: 0; }
.dlg-body p { margin: 0; color: var(--muted); }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 20px 20px; }
.choice { display: grid; gap: 8px; }
.opt { display: flex; gap: 12px; align-items: flex-start; padding: 12px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; }
.opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.opt input { margin: 3px 0 0; accent-color: var(--accent); }
.opt strong { display: block; font-weight: 600; }
.opt span { color: var(--muted); font-size: .875rem; }
.links { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.link-row { display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 12px; background: var(--panel); border-radius: 12px; }
.link-row .ic { color: var(--muted); }
.link-text { min-width: 0; flex: 1; }
.link-text .url { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .875rem; }
.link-text .meta { font-size: .75rem; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
select.input { padding-right: 8px; }

/* Upload tray */
.tray { position: fixed; z-index: 40; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); width: min(400px, calc(100vw - 32px));
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
.tray-head { display: flex; align-items: center; gap: 8px; padding: 10px 8px 10px 16px; background: var(--panel); }
.tray-head strong { flex: 1; font-weight: 600; }
.tray-bar { height: 3px; background: var(--panel-2); }
.tray-bar i { display: block; height: 100%; background: var(--accent); transform-origin: left; transition: transform .2s; }
.tray-list { max-height: 320px; overflow: auto; }
.tray-list.collapsed { display: none; }
.up { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 10px; align-items: center; padding: 10px 16px; border-top: 1px solid var(--line); }
.up .name { font-size: .875rem; }
.up .meta { grid-column: 2 / 4; font-size: .75rem; }
.up .bar { grid-column: 2 / 4; height: 4px; border-radius: var(--r-bar); background: var(--panel-2); overflow: hidden; }
.up .bar i { display: block; height: 100%; background: var(--accent); transform-origin: left; transform: scaleX(0); transition: transform .2s; }
.up .ic { color: var(--muted); }
.up.done .ic-status { color: var(--accent); }
.up.failed .meta { color: var(--danger); }

/* Drop overlay */
.drop { position: fixed; inset: 0; z-index: 70; background: color-mix(in srgb, var(--accent) 14%, transparent); display: grid; place-items: center; pointer-events: none; }
.drop-card { display: grid; justify-items: center; gap: 8px; padding: 28px 36px; background: var(--bg); border: 2px dashed var(--accent); border-radius: 12px; box-shadow: var(--shadow); color: var(--accent); }
.drop-card p { margin: 0; font-weight: 600; color: var(--text); }

/* Toast */
.toast { position: fixed; z-index: 80; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%); padding: 10px 16px;
  background: var(--text); color: var(--bg); border-radius: 12px; box-shadow: var(--shadow); font-weight: 500; max-width: calc(100vw - 32px); }

/* Viewer */
.viewer { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; background: var(--stage); color: var(--stage-ink); }
.viewer::backdrop { background: var(--stage); }
.viewer[open] { display: grid; grid-template-rows: auto 1fr; }
.v-head { display: flex; align-items: center; gap: 8px; padding: 10px max(12px, env(safe-area-inset-left)); }
.v-head .name { flex: 1; min-width: 0; font-weight: 500; }
.v-head .meta { color: var(--stage-muted); }
.viewer .btn { color: var(--stage-ink); border-color: transparent; background: transparent; }
.viewer .btn:hover { background: var(--stage-hover); }
.viewer .btn-primary { background: var(--accent); color: var(--accent-ink); }
.viewer .btn-primary:hover { background: var(--accent-hover); }
.v-stage { position: relative; min-height: 0; display: grid; place-items: center; padding: 0 56px 16px; }
.v-stage video, .v-stage img { max-width: 100%; max-height: 100%; border-radius: 6px; background: #000; }
.v-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 44px; border-radius: 50%; }
.v-prev { left: 8px; } .v-next { right: 8px; }
.v-file { display: grid; justify-items: center; gap: 12px; color: var(--stage-muted); }

/* Login + share gate */
.center { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background: var(--panel); }
.card { width: min(400px, 100%); background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 28px; display: grid; gap: 18px; box-shadow: 0 1px 2px rgb(16 24 40 / .05); }
.card h1 { margin: 0; font-size: 1.375rem; font-weight: 650; }
.card p { margin: -8px 0 0; color: var(--muted); }
.card .brand { font-size: 1rem; }
.lock { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }

/* Share page */
.share-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 24px 0 20px; border-bottom: 1px solid var(--line); margin-bottom: 20px; }
.share-head h1 { margin: 0 0 4px; font-size: 1.5rem; font-weight: 650; overflow-wrap: anywhere; }
.share-head p { margin: 0; color: var(--muted); font-variant-numeric: tabular-nums; }
.share-head .btn-primary { height: 44px; padding: 0 18px; }
.share-top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; height: 56px; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.gallery .thumb { aspect-ratio: 16 / 9; }
.foot { margin-top: 40px; color: var(--muted); font-size: .8125rem; text-align: center; }

/* Shared links page */
.table-wrap { overflow-x: auto; }
.pill { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.pill.lockd { background: var(--accent-soft); color: var(--accent); }

@media (max-width: 640px) {
  .topbar { gap: 8px; }
  .tabs { margin-left: 0; }
  .tab { padding: 0 8px; }
  .topbar .brand span { display: none; }
  .user .uname { display: none; }
  .crumbs { font-size: 1rem; flex-basis: 100%; }
  .actions { width: 100%; }
  .actions .grow { flex: 1; }
  .btn .label-wide { display: none; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .list .c-hide { display: none; }
  .v-stage { padding: 0 0 12px; }
  .v-nav { display: none; }
  .row2 { grid-template-columns: 1fr; }
  .share-head .btn-primary { width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
