:root {
  --bg: #f6f5f2; --surface: #ffffff; --fg: #1b1c1e; --dim: #6c6e73; --line: #e3e1dc;
  --accent: #c47c12; --accent-fg: #fff; --tile: #e7e5e0; --err: #c0392b;
  --header-h: 57px; /* реальная высота шапки, обновляется из JS */
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111214; --surface: #1b1c1f; --fg: #ecebe8; --dim: #8d8f95; --line: #2a2b2f;
          --accent: #e8a33d; --accent-fg: #111; --tile: #1f2023; --err: #ff6b5e; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body { font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
button, select, input { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }

/* --- вход --- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(340px, 100%); display: grid; gap: 14px; background: var(--surface);
  padding: 28px 24px; border-radius: 14px; border: 1px solid var(--line); }
.login-card label { display: grid; gap: 6px; font-size: 13px; color: var(--dim); }
.login-card input { padding: 11px 12px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--bg); font-size: 16px; }
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.login-card button { padding: 11px; border: 0; border-radius: 9px; background: var(--accent);
  color: var(--accent-fg); font-weight: 600; cursor: pointer; }
.login-card button:disabled { opacity: .6; cursor: default; }
.err { color: var(--err); min-height: 1.2em; margin: 0; font-size: 14px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 19px; }
.brand.small { font-size: 16px; flex: none; }
.logo { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); position: relative; flex: none; }
.logo::after { content: ""; position: absolute; inset: 5px; border: 2.5px solid var(--bg); border-radius: 50%; }

/* --- шапка --- */
.top { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top); }
.row { display: flex; align-items: center; gap: 12px; padding: 8px 16px; min-height: 56px; flex-wrap: wrap; }
.crumbs { flex: 1 1 200px; min-width: 0; display: flex; gap: 4px; align-items: center; overflow-x: auto;
  white-space: nowrap; scrollbar-width: none; color: var(--dim); }
.crumbs::-webkit-scrollbar { display: none; }
.crumbs a { padding: 3px 6px; border-radius: 6px; }
.crumbs a:hover { background: var(--tile); }
.crumbs a:last-child { color: var(--fg); font-weight: 600; }
.tools { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.tools select { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); }
.icon { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: 18px; line-height: 1; }
.icon:hover, .txt:hover { border-color: var(--dim); }
.txt { height: 36px; padding: 0 12px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: 14px; }
.banner { display: flex; gap: 12px; align-items: center; padding: 8px 16px; font-size: 14px;
  background: color-mix(in srgb, var(--accent) 16%, var(--bg)); border-top: 1px solid var(--line); }
.banner button { padding: 4px 10px; border-radius: 7px; border: 1px solid var(--accent);
  background: transparent; cursor: pointer; }
.banner.bad { background: color-mix(in srgb, var(--err) 14%, var(--bg)); }

/* --- папки --- */
.folders { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; padding: 14px 16px 4px; }
.folder { display: grid; grid-template-rows: auto auto; background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; overflow: hidden; cursor: pointer; }
.folder .cover { aspect-ratio: 16/10; background: var(--tile); background-size: cover; background-position: center; }
.folder .cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.folder .fname { padding: 7px 10px 8px; font-size: 14px; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.folder .fname small { display: block; color: var(--dim); font-weight: 400; font-size: 12px; }
.folder:hover { border-color: var(--dim); }
.summary { padding: 10px 16px 0; color: var(--dim); font-size: 13px; }

/* --- сетка (виртуальная: в DOM только строки около экрана) --- */
.vgrid { position: relative; margin: 6px 3px 0; contain: layout; }
@media (min-width: 700px) { .vgrid { margin: 6px 16px 0; } }
.mhead, .trow { position: absolute; left: 0; right: 0; top: 0; will-change: transform; }
.mhead { height: 46px; padding: 16px 0 0 4px; font-size: 15px; font-weight: 650; }
.mhead span { color: var(--dim); font-weight: 400; margin-left: 6px; font-size: 13px; }
.trow { display: grid; grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr)); }
.tile { position: relative; background: var(--tile); overflow: hidden; cursor: pointer; border: 0; padding: 0; display: block; width: 100%; height: 100%; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .15s; }
.tile img.ok { opacity: 1; }
.tile.broken::after { content: "⚠"; position: absolute; inset: 0; display: grid; place-items: center; color: var(--dim); }
.tile:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }
.vbadge { position: absolute; left: 6px; bottom: 5px; color: #fff; font-size: 13px; text-shadow: 0 1px 3px #000a; pointer-events: none; }
.empty { text-align: center; color: var(--dim); padding: 60px 16px; }
.pill { position: fixed; top: calc(var(--header-h, 57px) + 10px); left: 50%; transform: translateX(-50%); z-index: 9;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 5px 14px; font-size: 13px;
  font-weight: 600; box-shadow: 0 2px 10px #0002; pointer-events: none; }
.scrub { position: fixed; top: 0; right: 0; bottom: 0; width: 0; z-index: 8; }
.scrub-handle { position: absolute; right: 2px; top: 0; width: 34px; height: 44px; border-radius: 22px 6px 6px 22px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: 0 2px 8px #0003; touch-action: none; cursor: grab;
  display: grid; place-items: center; }
.scrub-handle::before { content: "⇕"; color: var(--dim); font-size: 16px; }
.scrub-handle.drag { cursor: grabbing; background: var(--accent); }
.scrub-handle span { position: absolute; right: 44px; white-space: nowrap; background: var(--accent); color: var(--accent-fg);
  border-radius: 8px; padding: 4px 10px; font-weight: 600; font-size: 14px; }
.scrub-handle span:empty { display: none; }

/* --- меню --- */
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: 42px; min-width: 240px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 8px 24px #0003; padding: 6px; z-index: 20; display: grid; }
.mi { display: flex; gap: 8px; align-items: center; padding: 9px 10px; border-radius: 7px; font-size: 14px; background: none;
  border: 0; text-align: left; cursor: pointer; width: 100%; }
.mi:hover { background: var(--tile); }
.mi input { accent-color: var(--accent); }
.mi small { color: var(--dim); }

/* --- Google --- */
.google-btn { display: flex; justify-content: center; align-items: center; gap: 10px; padding: 10px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--bg); font-weight: 550; }
.google-btn .g { font-weight: 800; color: #4285f4; font-size: 17px; }
.google-btn:hover { border-color: var(--dim); }

/* --- просмотр --- */
.viewer { position: fixed; inset: 0; z-index: 50; background: #000; color: #eee; display: grid;
  grid-template-rows: auto 1fr; touch-action: pan-y; }
.v-top { display: flex; align-items: center; gap: 10px; padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top));
  background: linear-gradient(#000c, #0000); position: absolute; inset: 0 0 auto 0; z-index: 2; }
.v-top .icon { background: #ffffff14; border-color: #ffffff22; color: #eee; }
.v-meta { flex: 1; min-width: 0; font-size: 14px; text-align: right; }
.v-meta div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dim { color: #aaa; font-size: 12px; }
.v-stage { grid-row: 1 / -1; position: relative; overflow: hidden; touch-action: none; }
.v-zoom { position: absolute; inset: 0; transform-origin: 0 0; will-change: transform; }
.v-zoom.anim { transition: transform .22s ease-out; }
.v-stage.zoomed { cursor: grab; } .v-stage.zoomed.drag { cursor: grabbing; }
.v-stage img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none; }
#v-low { filter: blur(6px); transform: scale(1.01); }
#v-img { opacity: 0; transition: opacity .15s; }
#v-video { position: absolute; inset: 0; width: 100%; height: 100%; background: #000; z-index: 1; }
#v-img.ok { opacity: 1; }
.v-nav { position: absolute; top: 50%; transform: translateY(-50%); z-index: 2; width: 48px; height: 72px; border: 0;
  background: #ffffff10; color: #fff; font-size: 34px; cursor: pointer; border-radius: 10px; }
.v-nav.prev { left: 8px; } .v-nav.next { right: 8px; }
@media (hover: none) { .v-nav { display: none; } }
.spin { position: absolute; left: 50%; top: 50%; width: 34px; height: 34px; margin: -17px; border-radius: 50%;
  border: 3px solid #ffffff33; border-top-color: #fff; animation: rot .8s linear infinite; z-index: 1; }
@keyframes rot { to { transform: rotate(360deg); } }

@media (max-width: 560px) {
  .row { gap: 8px; padding: 6px 10px; }
  .brand.small .brand-name { display: none; }
  .crumbs { order: 3; flex-basis: 100%; }
  .folders { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); padding: 10px 10px 2px; gap: 8px; }
}

/* щипок на сетке обрабатываем сами, браузерный зум страницы не нужен */
#main { touch-action: pan-x pan-y; }
.zoom { display: inline-flex; gap: 4px; }
@media (hover: none) { .zoom { display: none; } }

/* --- админка --- */
.adm .tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.adm .tabs button { border: 0; background: none; padding: 8px 12px; border-radius: 8px; cursor: pointer; color: var(--dim); white-space: nowrap; }
.adm .tabs button.on { background: var(--tile); color: var(--fg); font-weight: 600; }
.adm-body { padding: 16px; max-width: 1100px; margin: 0 auto; }
.adm h3 { font-size: 15px; margin: 24px 0 10px; }
.btn { display: inline-flex; align-items: center; justify-content: center; padding: 8px 14px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: 14px; }
.btn:hover { border-color: var(--dim); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }
.btn.small { padding: 4px 9px; font-size: 13px; border-radius: 7px; }
.btn.danger { color: var(--err); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.card .k { color: var(--dim); font-size: 12px; } .card .v { font-size: 16px; font-weight: 600; margin-top: 3px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
table.kv, table.list { width: 100%; border-collapse: collapse; font-size: 14px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
table.kv th { text-align: left; color: var(--dim); font-weight: 500; width: 35%; }
table.kv th, table.kv td, table.list td, table.list th { padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list th { text-align: left; color: var(--dim); font-weight: 500; font-size: 12px; }
table.list tr:last-child td { border-bottom: 0; }
tr.warn td, tr.warn th { color: var(--err); }
.ops { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
td .gmail { margin-right: 8px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; word-break: break-all; }
.nowrap { white-space: nowrap; }
.dim2 { color: var(--dim); font-size: 13px; }
.inline { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inline input, .inline select, .form input, .form textarea, table select {
  padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); font-size: 14px; }
.form { display: grid; gap: 14px; max-width: 640px; }
.form label { display: grid; gap: 5px; font-size: 13px; color: var(--dim); }
.form fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.form legend { font-size: 13px; color: var(--dim); padding: 0 4px; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px; }
.chkline { display: flex !important; gap: 6px; align-items: center; color: var(--fg) !important; font-size: 14px !important; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.logs td { font-size: 13px; }
tr.lvl-warning td { color: #b8860b; } tr.lvl-error td, tr.lvl-critical td { color: var(--err); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 30; background: var(--fg); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; margin: 0; box-shadow: 0 4px 16px #0004; }
.toast.bad { background: var(--err); color: #fff; }
@media (max-width: 640px) {
  table.list thead { display: none; }
  table.list tr { display: grid; grid-template-columns: 1fr auto; padding: 6px 0; border-bottom: 1px solid var(--line); }
  table.list td { border: 0; padding: 4px 12px; }
  .ops { justify-content: flex-start; }
}

.v-origchk { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 10px; border-radius: 9px;
  background: #ffffff14; border: 1px solid #ffffff22; font-size: 13px; cursor: pointer; user-select: none; white-space: nowrap; }
.v-origchk input { accent-color: var(--accent); margin: 0; }
/* живое фото: ролик лежит поверх снимка, ведёт себя как картинка (масштаб, свайпы) */
#v-live { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; pointer-events: none;
  opacity: 0; transition: opacity .25s; background: transparent; }
#v-live.on { opacity: 1; }
.live-ico { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid currentColor;
  box-shadow: inset 0 0 0 2px transparent; position: relative; }
.live-ico::after { content: ""; position: absolute; inset: 2.5px; border-radius: 50%; background: currentColor; }
.lbadge { position: absolute; left: 6px; top: 5px; width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid #fff;
  box-shadow: 0 0 3px #0008; pointer-events: none; }
.lbadge::after { content: ""; position: absolute; inset: 3px; border-radius: 50%; background: #fff; }
.v-note { position: absolute; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 2;
  background: #000b; color: #fff; padding: 8px 14px; border-radius: 10px; font-size: 14px; text-align: center; max-width: 90%; }
