:root {
  --bg: #f4f5f8; --card: #fff; --ink: #1d2433; --muted: #6b7385; --line: #dde1ea;
  --brand: #1f2a44; --accent: #2f6fed; --accent-ink: #fff; --danger: #c93636; --chip: #e7eefc; --chip-ink: #1f3f8f;
  --sel: #2f6fed;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151c; --card: #1b2029; --ink: #e8ebf2; --muted: #98a0b3; --line: #2b3240;
    --brand: #0d1220; --chip: #24324f; --chip-ink: #cfdcff;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }
button, .btn, select, input { font: inherit; color: inherit; }
button, .btn {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px;
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
}
button:hover, .btn:hover { filter: brightness(0.97); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { color: var(--danger); }
button.icon { border: none; background: transparent; font-size: 20px; padding: 6px 10px; }
input, select { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; min-width: 0; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.gap { gap: 10px; margin: 12px 0; flex-wrap: wrap; }
.row.end { justify-content: flex-end; margin-top: 14px; }
.spacer { flex: 1; }
.error { color: var(--danger); min-height: 1.4em; }
.hint { color: var(--muted); font-size: 13px; }

/* login */
.login-box { max-width: 320px; margin: 18vh auto 0; display: flex; flex-direction: column; gap: 12px; padding: 24px; text-align: center; }
.login-logo { width: 72px; height: 72px; margin: 0 auto; }
.login-box h1 { margin: 0 0 8px; }
.login-box input { text-align: center; font-size: 18px; }

/* header */
.top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 10px 12px 8px; border-bottom: 1px solid var(--line); padding-top: max(10px, env(safe-area-inset-top)); }
.brand { font-size: 19px; margin: 0; cursor: pointer; }
.search { position: relative; margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px 6px; }
.search input { border: none; flex: 1; min-width: 140px; padding: 7px 6px; background: transparent; }
.search input:focus { outline: none; }
.filters { margin-top: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: none; border-radius: 0; padding: 7px 10px; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.note { margin-top: 8px; padding: 6px 10px; background: var(--chip); color: var(--chip-ink); border-radius: 8px; display: flex; justify-content: space-between; align-items: center; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--chip); color: var(--chip-ink); border-radius: 999px; padding: 3px 10px; font-size: 13px; display: inline-flex; align-items: center; gap: 4px; border: none; cursor: pointer; }
.chip .x { opacity: .7; font-weight: bold; padding-left: 2px; }
.chip .n { opacity: .6; font-size: 12px; }

.suggest { position: absolute; left: 0; right: 0; top: 100%; margin-top: 4px; z-index: 20; background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.18); max-height: 280px; overflow: auto; }
.suggest.up { top: auto; bottom: 100%; margin: 0 0 4px; }
.suggest div { padding: 9px 12px; cursor: pointer; display: flex; justify-content: space-between; }
.suggest div.on, .suggest div:hover { background: var(--chip); }
.suggest .n { color: var(--muted); font-size: 12px; }

/* grid */
main { padding: 8px 8px 90px; }
.count { color: var(--muted); font-size: 13px; padding: 2px 4px 8px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 4px; }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); } }
.tile { position: relative; aspect-ratio: 1; background: var(--card); border-radius: 6px; overflow: hidden; cursor: pointer; user-select: none; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .badge { position: absolute; right: 5px; bottom: 5px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 6px; }
.tile .doc { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 8px; text-align: center; gap: 6px; }
.tile .doc .ext { font-weight: 700; font-size: 16px; background: var(--chip); color: var(--chip-ink); padding: 8px 10px; border-radius: 8px; }
.tile .doc .nm { font-size: 12px; color: var(--muted); word-break: break-word; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.tile .tick { position: absolute; left: 6px; top: 6px; width: 24px; height: 24px; border-radius: 50%; border: 2px solid #fff; background: rgba(0,0,0,.25); display: none; }
.selecting .tile .tick { display: block; }
.tile.sel .tick { background: var(--sel); }
.tile.sel .tick::after { content: "✓"; color: #fff; font-size: 14px; position: absolute; inset: 0; display: grid; place-items: center; }
.tile.sel img, .tile.sel .doc { transform: scale(.9); border-radius: 6px; }
.more { height: 40px; }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }

.selbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--card); border-top: 1px solid var(--line);
  padding: 10px 12px max(10px, env(safe-area-inset-bottom)); display: flex; gap: 6px; align-items: center; overflow-x: auto; }
.selbar span { margin-right: auto; white-space: nowrap; }

/* menu */
.menu { position: fixed; right: 10px; top: 54px; z-index: 30; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.2); display: flex; flex-direction: column; min-width: 210px; overflow: hidden; }
.menu button { border: none; border-radius: 0; padding: 12px 16px; justify-content: flex-start; }
.menu .who { padding: 10px 16px; color: var(--muted); font-size: 13px; border-bottom: 1px solid var(--line); }

/* viewer */
.viewer { position: fixed; inset: 0; z-index: 40; background: #000; color: #fff; display: flex; flex-direction: column; }
.v-top { display: flex; align-items: center; gap: 8px; padding: 6px 8px; padding-top: max(6px, env(safe-area-inset-top)); background: rgba(0,0,0,.6); }
.v-top button { color: #fff; }
.v-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.v-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; touch-action: pan-y; }
.v-stage img, .v-stage video { max-width: 100%; max-height: 100%; object-fit: contain; }
.v-stage .docbig { text-align: center; }
.v-stage .docbig .ext { font-size: 34px; font-weight: 700; background: #24324f; padding: 22px 26px; border-radius: 14px; display: inline-block; margin-bottom: 14px; }
.v-nav { position: absolute; top: 45%; background: rgba(0,0,0,.35); color: #fff; border: none; font-size: 34px; padding: 6px 14px; border-radius: 10px; }
.v-nav.prev { left: 6px; } .v-nav.next { right: 6px; }
@media (hover: none) { .v-nav { display: none; } }
.v-info { background: #141821; color: #e8ebf2; padding: 10px 12px max(12px, env(safe-area-inset-bottom)); max-height: 45vh; overflow: auto; }
.v-info.collapsed { display: none; }
.v-tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.v-tags .chip { background: #24324f; color: #cfdcff; }
.tag-add { position: relative; flex: 1; min-width: 150px; }
.tag-add input { width: 100%; }
.v-info input { background: #1f2530; border-color: #333b4a; color: #fff; }
.v-meta { color: #a8b0c2; font-size: 13px; margin: 8px 0; }
.v-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.v-actions button, .v-actions .btn { background: #232a36; border-color: #333b4a; color: #fff; }
.v-actions .danger { color: #ff8080; }

/* dialogs */
dialog { border: none; border-radius: 16px; padding: 0; width: min(520px, 94vw); background: var(--card); color: var(--ink); box-shadow: 0 20px 50px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(0,0,0,.45); }
.dlg { padding: 18px; display: flex; flex-direction: column; }
.dlg h2 { margin: 0 0 12px; font-size: 19px; }
.dlg label { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.dlg label.check { color: var(--ink); font-size: 14px; display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.tag-input-wrap { position: relative; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; border: 1px solid var(--line); border-radius: 10px; padding: 5px 6px; }
.tag-input-wrap input { border: none; flex: 1; min-width: 140px; padding: 6px; }
.tag-input-wrap input:focus { outline: none; }
.up-progress { margin-top: 6px; }
.bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.bar div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
#upStatus { font-size: 13px; margin: 6px 0; }
#upList { list-style: none; padding: 0; margin: 0; max-height: 220px; overflow: auto; font-size: 13px; }
#upList li { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; border-bottom: 1px solid var(--line); }
#upList li span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#upList .ok { color: #2a9d55; } #upList .dup { color: var(--muted); } #upList .bad { color: var(--danger); }
.tag-cloud { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; max-height: 50vh; overflow: auto; }
.tag-cloud .tg { display: inline-flex; }
.tag-cloud .tg .chip { border-radius: 999px 0 0 999px; }
.tag-cloud .tg .ed { border-radius: 0 999px 999px 0; background: var(--chip); color: var(--chip-ink); border: none; padding: 3px 8px; font-size: 12px; border-left: 1px solid var(--line); }
#tagFilter { width: 100%; }

.toast { position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%); z-index: 60; background: #222a; backdrop-filter: blur(6px);
  background: rgba(20,24,33,.92); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: 90vw; }
