:root {
  --bg: #111317; --panel: #181b21; --panel2: #20242c; --line: #2a2f39;
  --text: #e7e9ee; --muted: #8b93a3; --accent: #5aa2ff; --accent2: #2f6fd1;
  --thumb: 180px; --radius: 8px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, select, input { font: inherit; color: inherit; }
code { background: var(--panel2); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }

/* header */
.top { position: sticky; top: 0; z-index: 10; height: 52px; display: flex; align-items: center; gap: 12px;
  padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.top h1 { font-size: 17px; margin: 0; white-space: nowrap; }
.spacer { flex: 1; }
.crumbs { display: flex; gap: 4px; align-items: center; overflow: hidden; white-space: nowrap; color: var(--muted); min-width: 0; }
.crumbs a { color: var(--text); text-decoration: none; cursor: pointer; }
.crumbs a:hover { color: var(--accent); }
.crumbs span.sep { opacity: .5; }
select { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; }
.chk { display: flex; align-items: center; gap: 5px; color: var(--muted); white-space: nowrap; cursor: pointer; }
.status { font-size: 12px; color: var(--muted); white-space: nowrap; }
.status.busy::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%;
  background: var(--accent); animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: .3 } to { opacity: 1 } }
.icon-btn { background: none; border: 0; font-size: 22px; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--panel2); }
#menuBtn { display: none; }

/* layout */
.layout { display: flex; height: calc(100% - 52px); }
.sidebar { width: 280px; flex: none; overflow-y: auto; background: var(--panel); border-right: 1px solid var(--line); padding: 12px 8px 40px; }
.sidebar h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
  margin: 8px 8px 6px; display: flex; align-items: center; justify-content: space-between; }
.sidebar section + section { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 10px; }
main { flex: 1; overflow-y: auto; padding: 16px; }

/* folder tree */
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul { padding-left: 14px; }
.tree li > .row { display: flex; align-items: center; gap: 4px; padding: 4px 6px; border-radius: 6px; cursor: pointer; user-select: none; }
.tree li > .row:hover { background: var(--panel2); }
.tree li.active > .row { background: var(--accent2); color: #fff; }
.tree .tw { width: 16px; text-align: center; color: var(--muted); flex: none; font-size: 10px; }
.tree li.active > .row .tw, .tree li.active > .row .cnt { color: #dfe9ff; }
.tree .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree .cnt { font-size: 11px; color: var(--muted); }
.tree li.collapsed > ul { display: none; }

/* people */
.small-btn { text-transform: none; letter-spacing: 0; font-size: 12px; background: var(--panel2); border: 1px solid var(--line);
  border-radius: 6px; padding: 3px 8px; cursor: pointer; color: var(--text); }
.small-btn:hover { border-color: var(--accent); }
.face-status { font-size: 12px; color: var(--muted); margin: 0 8px 8px; min-height: 1em; }
.people { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; padding: 0 6px; }
.person { text-align: center; cursor: pointer; border-radius: 8px; padding: 4px; }
.person:hover, .person.active { background: var(--panel2); }
.person.active { outline: 2px solid var(--accent); }
.person img { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; display: block; margin: 0 auto 4px; background: var(--panel2); }
.person .pn { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person .pc { font-size: 11px; color: var(--muted); }

/* grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--thumb), 1fr)); gap: 6px; }
.tile { position: relative; aspect-ratio: 1; overflow: hidden; border-radius: 6px; background: var(--panel2); cursor: zoom-in; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .25s; }
.tile:hover img { transform: scale(1.04); }
.tile .cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 8px 6px; font-size: 12px; opacity: 0;
  background: linear-gradient(transparent, rgba(0,0,0,.7)); transition: opacity .2s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile:hover .cap { opacity: 1; }
.tile.new { animation: pop .5s; }
@keyframes pop { from { opacity: 0; transform: scale(.9) } }
.subfolders { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; margin-bottom: 16px; }
.subfolder { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); cursor: pointer; }
.subfolder:hover { border-color: var(--accent); }
.subfolder .fi { font-size: 22px; }
.subfolder .fn { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.subfolder .fc { font-size: 12px; color: var(--muted); }
.empty { text-align: center; padding: 60px 20px; font-size: 16px; }
.more { text-align: center; padding: 20px; }
.more button { background: var(--panel2); border: 1px solid var(--line); padding: 8px 18px; border-radius: 6px; cursor: pointer; }

/* viewer */
.viewer { position: fixed; inset: 0; z-index: 50; background: rgba(8,9,12,.97); display: flex; flex-direction: column; }
.viewer[hidden] { display: none; }
.viewer-top { display: flex; align-items: center; padding: 8px 16px; gap: 12px; }
.v-info { flex: 1; font-size: 13px; color: var(--muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.v-info b { color: var(--text); font-weight: 600; }
.v-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; position: relative; padding: 0 56px; }
.v-imgwrap { position: relative; max-width: 100%; max-height: 100%; display: flex; }
.v-imgwrap img { max-width: 100%; max-height: calc(100vh - 290px); object-fit: contain; display: block; user-select: none;
  -webkit-user-drag: none; border-radius: 4px; transition: opacity .2s; }
.v-imgwrap img.loading { opacity: .3; }
.v-boxes { position: absolute; inset: 0; pointer-events: none; }
.v-boxes div { position: absolute; border: 2px solid rgba(90,162,255,.9); border-radius: 4px; opacity: 0; transition: opacity .15s; }
.v-boxes div.show { opacity: 1; }
.v-boxes div span { position: absolute; top: 100%; left: -2px; background: var(--accent2); color: #fff; font-size: 11px; padding: 1px 5px; white-space: nowrap; border-radius: 0 0 4px 4px; }
.nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255,255,255,.06); border: 0; color: #fff;
  width: 44px; height: 64px; font-size: 36px; border-radius: 8px; cursor: pointer; }
.nav:hover { background: rgba(255,255,255,.15); }
.nav.prev { left: 6px; } .nav.next { right: 6px; }
.v-faces { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; padding: 8px 16px 0; min-height: 34px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--panel2); border: 1px solid var(--line);
  border-radius: 999px; padding: 3px 10px; font-size: 12px; cursor: pointer; }
.chip:hover { border-color: var(--accent); }
.chip .x { color: var(--muted); padding-left: 2px; }
.chip .x:hover { color: #ff7a7a; }
.v-related { padding: 6px 16px 14px; }
.v-related h3 { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin: 6px 0 8px; text-align: center; }
.related { display: grid; grid-template-columns: repeat(15, minmax(0, 76px)); gap: 6px; justify-content: center; }
.related .tile { cursor: pointer; }
.related .tile img { border-radius: 4px; }

/* selection */
.hdr-btn { font-size: 13px; padding: 5px 10px; }
.hdr-btn.on { background: var(--accent2); border-color: var(--accent2); color: #fff; }
body.selecting .tile { cursor: pointer; }
.tile .tick { position: absolute; top: 6px; left: 6px; width: 24px; height: 24px; border-radius: 50%; border: 2px solid #fff;
  background: rgba(0,0,0,.35); display: none; align-items: center; justify-content: center; font-size: 14px; color: #fff; }
body.selecting #grid .tile .tick { display: flex; }
.tile.sel { outline: 3px solid var(--accent); outline-offset: -3px; }
.tile.sel img { transform: scale(.92); }
.tile.sel .tick { background: var(--accent); border-color: var(--accent); }
.sel-bar { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 30; display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; box-shadow: 0 8px 30px rgba(0,0,0,.5);
  width: min(760px, calc(100% - 32px)); flex-wrap: wrap; }
.sel-bar[hidden] { display: none; }
#selCount { font-weight: 600; padding: 0 6px; }
.btn { background: var(--accent2); color: #fff; border: 0; border-radius: 8px; padding: 7px 14px; cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn:hover { filter: brightness(1.1); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.insta { background: linear-gradient(45deg, #f09433, #dc2743 50%, #bc1888); }
.viewer-top .small-btn { padding: 5px 10px; font-size: 13px; }

/* dialogs */
.dlg { width: min(560px, calc(100% - 32px)); max-height: calc(100% - 32px); background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.dlg::backdrop { background: rgba(0,0,0,.6); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; margin: -4px 0 10px; }
.dlg-head h3 { margin: 0; font-size: 16px; }
.dlg-thumbs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.dlg-thumbs .th { position: relative; width: 64px; height: 64px; border-radius: 6px; overflow: hidden; background: var(--panel2); }
.dlg-thumbs .th img { width: 100%; height: 100%; object-fit: cover; display: block; }
.dlg-thumbs .th .num { position: absolute; top: 2px; left: 2px; background: rgba(0,0,0,.65); font-size: 11px; padding: 0 5px; border-radius: 4px; }
.dlg-thumbs .th .rm { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(0,0,0,.65); color: #fff; font-size: 14px; line-height: 20px; padding: 0; }
.dlg-thumbs .more { align-self: center; color: var(--muted); font-size: 13px; }
.share-icons { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 10px; margin: 4px 0 14px; }
.share-icons a, .share-icons button { display: flex; flex-direction: column; align-items: center; gap: 5px; font-size: 12px; color: var(--text);
  text-decoration: none; background: none; border: 0; cursor: pointer; padding: 4px; border-radius: 8px; }
.share-icons a:hover, .share-icons button:hover { background: var(--panel2); }
.share-icons svg { width: 42px; height: 42px; display: block; }
.link-row { display: flex; gap: 8px; }
.link-row input, .fld input, .fld textarea, .fld select { flex: 1; width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; color: var(--text); }
.fld { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.fld input, .fld textarea, .fld select { margin-top: 4px; font-size: 14px; resize: vertical; }
.warn { background: #3a2c12; border: 1px solid #6b5220; color: #f3d28b; border-radius: 8px; padding: 8px 10px; font-size: 13px; margin-bottom: 12px; }
.small { font-size: 12px; }
.ig-msg { min-height: 1.2em; font-size: 13px; margin-bottom: 10px; }
.ig-msg.err { color: #ff8a8a; } .ig-msg.ok { color: #7ddc8f; } .ig-msg a { color: var(--accent); }
.dlg-actions { display: flex; align-items: center; gap: 8px; }

/* admin */
body:not(.admin) .admin-only { display: none !important; }
.admin-section #adminIn, .admin-section #adminOut { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 8px; }
.admin-section #adminIn[hidden], .admin-section #adminOut[hidden] { display: none; }
.admin-acct { width: 100%; }
.dlg.narrow { width: min(400px, calc(100% - 32px)); }

@media (max-width: 1250px) { .related { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); max-width: 640px; margin: 0 auto; } }
@media (max-width: 800px) {
  :root { --thumb: 110px; }
  #menuBtn { display: block; }
  .sidebar { position: fixed; top: 52px; bottom: 0; left: 0; z-index: 20; transform: translateX(-100%); transition: transform .2s; box-shadow: 4px 0 20px rgba(0,0,0,.5); }
  .sidebar.open { transform: none; }
  .chk, .crumbs { display: none; }
  .v-stage { padding: 0 8px; }
  .nav { width: 34px; height: 50px; font-size: 28px; background: rgba(0,0,0,.4); }
  .v-imgwrap img { max-height: calc(100vh - 330px); }
}
