:root {
  --bg: #f4f6f7; --card: #ffffff; --text: #1b2428; --muted: #66757c; --line: #e2e7ea;
  --accent: #1f4e5f; --accent-2: #2f7a8f; --accent-soft: #e3eff2; --danger: #b3261e; --warn: #b26a00; --ok: #2e7d32;
  --radius: 14px; --nav-h: 64px; --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1416; --card: #182024; --text: #e6ecee; --muted: #93a3aa; --line: #263136;
          --accent: #7cc4d6; --accent-2: #9bd5e3; --accent-soft: #1d2f35; --danger: #ff8a80; --warn: #ffb74d; --ok: #81c784; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.45rem; margin: 0 0 .25rem; } h2 { font-size: 1.1rem; margin: 1.4rem 0 .6rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .danger { color: var(--danger); } .warn { color: var(--warn); }
.splash { display: grid; place-items: center; height: 100vh; font-weight: 700; color: var(--muted); }

/* Layout */
header.top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 8px;
  display: flex; align-items: center; gap: 10px; }
header.top .title { flex: 1; font-weight: 700; font-size: 1.15rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
header.top button.icon { font-size: 1.3rem; }
main { padding: 4px 16px calc(var(--nav-h) + var(--safe-b) + 90px); max-width: 860px; margin: 0 auto; }
nav.bottom { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b); background: var(--card); border-top: 1px solid var(--line); display: flex; }
nav.bottom a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: .72rem; }
nav.bottom a .i { font-size: 1.35rem; line-height: 1; }
nav.bottom a.active { color: var(--accent); font-weight: 600; }
@media (min-width: 900px) { nav.bottom { max-width: 860px; margin: 0 auto; border: 1px solid var(--line); border-radius: 16px 16px 0 0; } }

/* Controls */
button, .btn { font: inherit; border: 0; border-radius: 12px; padding: 12px 16px; background: var(--accent); color: #fff;
  font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
@media (prefers-color-scheme: dark) { button, .btn { color: #0f1416; } }
button.secondary, .btn.secondary { background: var(--accent-soft); color: var(--accent); }
button.ghost { background: transparent; color: var(--accent); padding: 8px 10px; }
button.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
button.icon { background: transparent; color: var(--text); padding: 6px 8px; }
button.block { width: 100%; } button:disabled { opacity: .5; }
.row { display: flex; gap: 10px; align-items: center; } .row > * { flex: 1; } .row.wrap { flex-wrap: wrap; }
.stack > * + * { margin-top: 12px; }
label.field { display: block; } label.field > span { display: block; font-size: .82rem; color: var(--muted); margin: 0 0 4px 2px; }
input, select, textarea { width: 100%; font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-2); outline-offset: -1px; }
textarea { min-height: 90px; resize: vertical; }
.switch { display: flex; align-items: center; gap: 10px; padding: 6px 2px; } .switch input { width: 22px; height: 22px; }
.search { position: relative; } .search input { padding-left: 40px; } .search::before { content: "🔍"; position: absolute; left: 13px; top: 11px; opacity: .6; }

.fab { position: fixed; right: 18px; bottom: calc(var(--nav-h) + var(--safe-b) + 18px); z-index: 9; width: 60px; height: 60px;
  border-radius: 20px; font-size: 1.8rem; box-shadow: 0 6px 18px rgba(0,0,0,.22); padding: 0; }

/* Cards & lists */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; gap: 12px; align-items: center; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 12px; color: var(--text); }
.item .thumb { width: 52px; height: 52px; border-radius: 10px; background: var(--accent-soft); display: grid; place-items: center;
  font-size: 1.5rem; flex: none; overflow: hidden; } .item .thumb img { width: 100%; height: 100%; object-fit: cover; }
.item .body { flex: 1; min-width: 0; } .item .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .s { font-size: .83rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 999px; padding: 7px 12px;
  font-weight: 500; font-size: .9rem; }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .chip.active { color: #0f1416; } }
.tag { display: inline-block; background: var(--accent-soft); color: var(--accent); border-radius: 8px; padding: 2px 8px; font-size: .78rem; margin: 2px 4px 2px 0; }
.badge { font-size: .75rem; font-weight: 700; border-radius: 8px; padding: 2px 8px; white-space: nowrap; }
.badge.over { background: var(--danger); color: #fff; } .badge.soon { background: var(--warn); color: #fff; } .badge.ok { background: var(--accent-soft); color: var(--accent); }

.grid-cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.cat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; color: var(--text); }
.cat .i { font-size: 1.6rem; } .cat .n { font-weight: 600; margin-top: 4px; } .cat .c { font-size: .8rem; color: var(--muted); }
.catpick { display: grid; grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); gap: 8px; }
.catpick button { flex-direction: column; background: var(--card); color: var(--text); border: 1px solid var(--line); padding: 10px 6px;
  font-weight: 500; font-size: .82rem; gap: 2px; } .catpick button .i { font-size: 1.4rem; }
.catpick button.active { border: 2px solid var(--accent); background: var(--accent-soft); }

/* Dropzone */
.dropzone { border: 2px dashed var(--line); border-radius: var(--radius); padding: 18px; text-align: center; background: var(--card);
  transition: .15s; } .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .hint { color: var(--muted); margin-bottom: 12px; }
.previews { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; margin-top: 12px; }
.previews .p { position: relative; aspect-ratio: 3/4; border-radius: 10px; overflow: hidden; background: var(--accent-soft);
  display: grid; place-items: center; font-size: .72rem; text-align: center; padding: 4px; word-break: break-all; }
.previews .p img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.previews .p button { position: absolute; top: 4px; right: 4px; padding: 2px 7px; border-radius: 8px; background: rgba(0,0,0,.6); color: #fff; font-size: .8rem; }
.global-drop { position: fixed; inset: 0; z-index: 50; background: rgba(31,78,95,.85); color: #fff; display: none; place-items: center;
  font-size: 1.4rem; font-weight: 700; } .global-drop.show { display: grid; }

/* Files in detail */
.files { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.file { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; color: var(--text); }
.file .pv { aspect-ratio: 3/4; background: var(--accent-soft); display: grid; place-items: center; font-size: 2rem; }
.file .pv img { width: 100%; height: 100%; object-fit: cover; }
.file .fn { font-size: .75rem; padding: 6px 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Sheet / modal */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 640px; max-height: 92vh; overflow: auto; border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(18px + var(--safe-b)); animation: up .18s ease-out; }
@media (min-width: 700px) { .sheet-bg { align-items: center; } .sheet { border-radius: 20px; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet h3 { margin: 0 0 12px; }
.viewer { position: fixed; inset: 0; z-index: 60; background: #000; display: flex; flex-direction: column; }
.viewer .bar { display: flex; gap: 8px; padding: calc(env(safe-area-inset-top, 0px) + 8px) 10px 8px; background: #111; }
.viewer .bar button { background: #222; color: #fff; padding: 8px 12px; }
.viewer .content { flex: 1; overflow: auto; display: grid; place-items: center; }
.viewer img { max-width: 100%; max-height: 100%; } .viewer iframe { width: 100%; height: 100%; border: 0; background: #fff; }

#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + var(--safe-b) + 90px); z-index: 70;
  background: #222; color: #fff; padding: 10px 16px; border-radius: 12px; opacity: 0; transition: .2s; pointer-events: none; max-width: 90vw; }
#toast.show { opacity: 1; } #toast.err { background: var(--danger); color: #fff; }

/* Login */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth .box { width: 100%; max-width: 380px; text-align: center; }
.auth .logo { font-size: 3.2rem; } .auth h1 { margin: 8px 0 4px; }
.secret { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.15rem; letter-spacing: .04em; word-break: break-all;
  background: var(--accent-soft); padding: 10px 12px; border-radius: 10px; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; } .empty .i { font-size: 2.5rem; }

.auth label.field { text-align: left; }
