:root {
  --bg: #f6f5f2; --panel: #ffffff; --text: #1d1f23; --muted: #6b7078; --line: #e4e2dc;
  --accent: #2f6f5e; --accent-ink: #ffffff; --accent-soft: #e3efe9; --hover: #f0eee9;
  --danger: #b4412f; --danger-soft: #f8e5e1; --warn: #c58a1a; --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a; --panel: #1d2024; --text: #e8e6e1; --muted: #9a9ea6; --line: #2e3238;
    --accent: #5fb39a; --accent-ink: #0f1a16; --accent-soft: #1f3530; --hover: #262a2f;
    --danger: #e0715f; --danger-soft: #3a2420; --warn: #e2ac45;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font: 13px Consolas, "Cascadia Mono", monospace; background: var(--hover); padding: 1px 5px; border-radius: 4px; }
h1, h2 { margin: 0 0 12px; font-weight: 600; }
h1 { font-size: 22px; } h2 { font-size: 17px; }
.muted { color: var(--muted); } .small { font-size: 13px; }

/* верхняя панель */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px;
  height: 56px; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; color: var(--text); white-space: nowrap; }
.brand img, .card-brand img { width: 26px; height: 26px; }
.search { flex: 1; max-width: 520px; }
.search input { width: 100%; }
.user-menu { margin-left: auto; display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.user-menu form { margin: 0; }

.layout { display: flex; min-height: calc(100vh - 56px); }
.sidebar { width: 240px; flex-shrink: 0; padding: 14px 10px; border-right: 1px solid var(--line); background: var(--panel); }
.nav-title { margin: 18px 10px 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text); }
.nav-item:hover { background: var(--hover); text-decoration: none; }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .ico { width: 20px; text-align: center; }
.content { flex: 1; min-width: 0; padding: 20px 24px 120px; }
.page-title { margin-bottom: 14px; }

/* элементы форм */
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; min-height: 38px; width: 100%; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=checkbox] { width: 17px; height: 17px; min-height: 0; accent-color: var(--accent); margin: 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 6px 14px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text); font: inherit;
  cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--hover); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.wide { width: 100%; }
.link-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; padding: 0; }
.link-btn:hover { color: var(--text); }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px;
  border-radius: 8px; border: 0; background: none; color: var(--text); cursor: pointer; font-size: 15px; }
.icon-btn:hover { background: var(--hover); text-decoration: none; }
.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.form label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
.row { display: flex; gap: 8px; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; align-items: end; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; grid-column: 1 / -1; }
.inline-form { flex-direction: row; flex-wrap: wrap; align-items: flex-end; gap: 8px; margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--line); }
.inline-form label { flex: 1; min-width: 200px; }
.narrow-form { max-width: 380px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.badge { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--hover); color: var(--muted); font-weight: 500; vertical-align: middle; }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; background: var(--accent-soft); color: var(--text); border-left: 4px solid var(--accent); }
.flash.error { background: var(--danger-soft); border-left-color: var(--danger); }

/* карточка входа */
.center-card { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; }
.center-card .flash { width: 100%; max-width: 520px; }
.card { width: 100%; max-width: 520px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.card.narrow { max-width: 380px; }
.card-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--accent); margin-bottom: 18px; }

/* файлы */
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 18px; font-weight: 600; margin-bottom: 10px; }
.crumbs a { color: var(--text); }
.crumbs .sep { color: var(--muted); }
.usage { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.usage .bar { width: 160px; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.usage .bar div { height: 100%; background: var(--accent); }
.usage .bar div.warn { background: var(--danger); }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.toolbar .spacer { flex: 1; }
.sel-actions { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.sel-count { color: var(--muted); font-size: 14px; margin-right: 4px; }
.files { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.files th { text-align: left; font-weight: 500; font-size: 13px; color: var(--muted); padding: 9px 10px; border-bottom: 1px solid var(--line); }
.files th a { color: var(--muted); }
.files td { padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.files tr:last-child td { border-bottom: 0; }
.files tbody tr:hover { background: var(--hover); }
.files tr.selected { background: var(--accent-soft) !important; }
.files .chk { width: 36px; text-align: center; }
.files .num { text-align: right; white-space: nowrap; }
.files td.muted { white-space: nowrap; }
.files .act { width: 80px; text-align: right; white-space: nowrap; }
.files .name { word-break: break-word; }
.files .name a { color: var(--text); display: inline-flex; align-items: center; gap: 10px; }
.meta-sm { font-size: 12px; color: var(--muted); margin-left: 32px; }
.fi { width: 22px; height: 22px; flex-shrink: 0; border-radius: 5px; background: var(--muted); position: relative; display: inline-block; }
.fi::after { content: ""; position: absolute; inset: 0; }
.fi.dir { background: #d9a43a; border-radius: 3px 6px 5px 5px; }
.fi.image { background: #8d6bd1; } .fi.video { background: #c64f6d; } .fi.audio { background: #d4782f; }
.fi.pdf { background: #c8432f; } .fi.text { background: #5b7f9e; } .fi.archive { background: #8a7a5c; }
.fi.doc { background: #3a6fc4; } .fi.sheet { background: #2f8a55; } .fi.slides { background: #d2632b; }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty .big { font-size: 46px; }
.dropzone { position: fixed; inset: 0; z-index: 50; background: rgba(47,111,94,.18); display: flex; align-items: center; justify-content: center; pointer-events: none; }
.dropzone div { padding: 28px 40px; border: 3px dashed var(--accent); border-radius: 16px; background: var(--panel); font-size: 18px; font-weight: 600; color: var(--accent); }
[hidden] { display: none !important; }

/* загрузки */
.uploads { position: fixed; right: 16px; bottom: 16px; z-index: 40; width: min(420px, calc(100vw - 32px)); max-height: 50vh; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.uploads-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.uploads-head span { flex: 1; color: var(--muted); font-size: 13px; }
.uploads-list { overflow: auto; padding: 6px 12px 10px; }
.up-item { padding: 6px 0; font-size: 13px; }
.up-item .up-row { display: flex; justify-content: space-between; gap: 8px; }
.up-item .up-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-item .up-bar { height: 4px; background: var(--line); border-radius: 2px; margin-top: 4px; overflow: hidden; }
.up-item .up-bar div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.up-item.err .up-bar div { background: var(--danger); }
.up-item.err .up-state { color: var(--danger); }

/* диалоги */
.dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; background: var(--panel); color: var(--text); width: min(480px, calc(100vw - 32px)); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(0,0,0,.4); }
.dialog-body { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.dialog-body label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.picker { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.picker-path { padding: 8px 10px; background: var(--hover); font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px; }
.picker-path a { cursor: pointer; }
.picker ul { list-style: none; margin: 0; padding: 4px; max-height: 260px; overflow: auto; }
.picker li { padding: 7px 10px; border-radius: 6px; cursor: pointer; display: flex; align-items: center; gap: 8px; }
.picker li:hover { background: var(--hover); }
.picker li.none { color: var(--muted); cursor: default; }
.preview { width: min(1100px, calc(100vw - 24px)); height: calc(100vh - 40px); max-height: none; }
.preview[open] { display: flex; flex-direction: column; }
.preview-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.preview-head span { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-body { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.preview-body img, .preview-body video { max-width: 100%; max-height: 100%; object-fit: contain; }
.preview-body iframe { width: 100%; height: 100%; border: 0; background: #fff; }

/* админка */
.stats { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.stat { flex: 1; min-width: 150px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; }
.stat span { display: block; font-size: 13px; color: var(--muted); }
.stat b { font-size: 20px; }
.user-row { padding: 0; }
.user-row summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 12px; padding: 12px 16px; flex-wrap: wrap; }
.user-row summary::-webkit-details-marker { display: none; }
.user-row[open] summary { border-bottom: 1px solid var(--line); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; }
.u-main { flex: 1; min-width: 180px; }
.u-side { font-size: 13px; }
.user-edit { padding: 16px; }
.log { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; font: 12.5px/1.55 Consolas, "Cascadia Mono", monospace; overflow: auto; white-space: pre; max-height: 75vh; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
.toast.error { background: var(--danger); color: #fff; }

.only-mobile { display: none; }
@media (max-width: 760px) {
  .only-mobile { display: block; }
  .icon-btn.only-mobile { display: inline-flex; }
  .hide-sm { display: none; }
  .topbar { gap: 8px; padding: 0 8px; }
  .brand { font-size: 0; gap: 0; }
  .user-menu a { display: none; }
  .sidebar { position: fixed; top: 56px; bottom: 0; left: 0; z-index: 30; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); overflow: auto; }
  .sidebar.open { transform: none; }
  .content { padding: 14px 12px 120px; }
  .crumbs { font-size: 16px; }
  .toolbar .btn { padding: 6px 10px; }
}

/* ── вид: переключатель ── */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--panel); color: var(--muted); width: 38px; height: 34px; font-size: 16px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent-soft); color: var(--accent); }

/* ── плитка ── */
.grid-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.check-all-label { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); cursor: pointer; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tile { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.tile:hover { border-color: var(--muted); }
.tile.selected { outline: 3px solid var(--accent); outline-offset: -1px; }
.tile-media { display: flex; align-items: center; justify-content: center; aspect-ratio: 1 / 1; background: var(--hover); overflow: hidden; }
.tile-media:hover { text-decoration: none; }
.tile-media img, .tile-media .tile-video { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .25s; }
.tile:hover .tile-media img { transform: scale(1.03); }
.tile-name { padding: 6px 9px; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: default; }
.tile-check { position: absolute; top: 8px; left: 8px; z-index: 2; width: 20px !important; height: 20px !important; opacity: 0; transition: opacity .15s;
  filter: drop-shadow(0 0 2px rgba(0,0,0,.5)); }
.tile:hover .tile-check, .tile.selected .tile-check, .selecting .tile-check { opacity: 1; }
@media (hover: none) { .tile-check { opacity: .85; } }
.play-badge { position: absolute; left: 50%; top: calc(50% - 16px); transform: translate(-50%, -50%); width: 44px; height: 44px; border-radius: 50%;
  background: rgba(0,0,0,.55); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 17px; padding-left: 3px; pointer-events: none; }
.fi.big { width: 56px; height: 56px; border-radius: 10px; }
.fi.dir.big { border-radius: 6px 12px 10px 10px; }
.fi-thumb { width: 22px; height: 22px; border-radius: 5px; object-fit: cover; flex-shrink: 0; background: var(--hover); }

/* ── полноэкранный просмотр ── */
.viewer { width: 100vw; height: 100vh; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0;
  background: #0b0c0e; color: #eee; }
.viewer[open] { display: block; }
.viewer::backdrop { background: #0b0c0e; }
.v-top { position: absolute; top: 0; left: 0; right: 0; z-index: 3; display: flex; align-items: center; gap: 6px; padding: 8px 10px;
  background: linear-gradient(rgba(0,0,0,.65), rgba(0,0,0,0)); }
.v-title { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 12px; }
.v-title #v-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.v-title #v-meta { color: #aaa; font-size: 13px; white-space: nowrap; }
.v-btn { width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(255,255,255,.08); color: #fff; font-size: 17px;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; }
.v-btn:hover { background: rgba(255,255,255,.2); text-decoration: none; }
.v-stage:focus { outline: none; }
.v-stage { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; touch-action: pan-y pinch-zoom; }
.v-stage > img { max-width: 100%; max-height: 100%; object-fit: contain; cursor: zoom-in; user-select: none; -webkit-user-drag: none; }
.v-stage > video { max-width: 100%; max-height: calc(100% - 60px); outline: none; }
.v-stage > audio { width: min(600px, 90vw); }
.v-stage > .v-doc { width: min(1100px, 100%); height: calc(100% - 60px); margin-top: 56px; border: 0; background: #fff; }
.v-stage.zoom { display: block; overflow: auto; touch-action: auto; }
.v-stage.zoom > img { max-width: none; max-height: none; cursor: zoom-out; }
.v-stage.loading::after { content: ""; position: absolute; left: 50%; top: 50%; width: 34px; height: 34px; margin: -17px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.2); border-top-color: #fff; animation: vspin .8s linear infinite; }
@keyframes vspin { to { transform: rotate(360deg); } }
.v-nav { position: absolute; top: 50%; z-index: 2; transform: translateY(-50%); width: 52px; height: 52px; border-radius: 50%; border: 0;
  background: rgba(255,255,255,.1); color: #fff; font-size: 34px; line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center; padding-bottom: 4px; }
.v-nav:hover { background: rgba(255,255,255,.25); }
.v-prev { left: 14px; } .v-next { right: 14px; }
.v-error { text-align: center; color: #ccc; }
.v-error .btn { margin-top: 10px; }
@media (max-width: 760px) {
  .grid { grid-template-columns: repeat(3, 1fr); gap: 4px; }
  .tile { border-radius: 4px; border: 0; }
  .tile-name { display: none; }
  .tile.is-dir .tile-name, .tile:not([data-kind="image"]):not([data-kind="video"]) .tile-name {
    display: block; position: absolute; left: 0; right: 0; bottom: 0; font-size: 12px; padding: 3px 6px;
    background: var(--panel); opacity: .92; }
  .fi.big { width: 42px; height: 42px; }
  .v-nav { display: none; }
  .seg button { width: 34px; }
}

/* ── вход по коду, пароли ── */
.code-input { font-size: 26px; letter-spacing: .35em; text-align: center; font-variant-numeric: tabular-nums; }
.resend { margin-top: 14px; font-size: 14px; color: var(--muted); }
.resend .link-btn { color: var(--accent); }
.resend .link-btn:disabled { color: var(--muted); cursor: default; }
.pw-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--line); }
.pw-value.shown { background: var(--accent-soft); color: var(--accent); font-size: 14px; user-select: all; }
.row.wrap { flex-wrap: wrap; }
.stat small { font-size: 13px; }

/* ── веб-приложение: вырезы экрана iPhone, баннер установки ── */
.topbar { padding-top: env(safe-area-inset-top); height: calc(56px + env(safe-area-inset-top));
  padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
.layout { min-height: calc(100vh - 56px - env(safe-area-inset-top)); }
.content { padding-bottom: calc(120px + env(safe-area-inset-bottom)); }
.uploads { bottom: calc(16px + env(safe-area-inset-bottom)); }
.toast { bottom: calc(24px + env(safe-area-inset-bottom)); }
.center-card { padding-top: calc(24px + env(safe-area-inset-top)); padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
.v-top { padding-top: calc(8px + env(safe-area-inset-top)); padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
html.standalone body { overscroll-behavior-y: none; -webkit-tap-highlight-color: transparent; }
html.standalone .topbar { -webkit-user-select: none; user-select: none; }
.install-banner { display: flex; align-items: center; gap: 10px; padding: 10px 12px; margin-bottom: 14px; border-radius: 12px;
  background: var(--accent-soft); border: 1px solid var(--line); }
.install-banner img { width: 40px; height: 40px; border-radius: 10px; }
.install-banner div { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 14px; }
.install-banner span { color: var(--muted); font-size: 13px; }
.dav-grid { display: grid; grid-template-columns: max-content 1fr; gap: 8px 14px; align-items: center; margin: 10px 0; }
.dav-grid code { word-break: break-all; }
code.copy { cursor: pointer; }
code.copy:hover { outline: 1px solid var(--accent); }
code.secret.shown { background: var(--accent-soft); color: var(--accent); }
.howto { margin-top: 8px; }
.howto summary { cursor: pointer; color: var(--accent); }
.howto ol { padding-left: 20px; line-height: 1.6; }
@media (max-width: 760px) {
  .sidebar { top: calc(56px + env(safe-area-inset-top)); padding-bottom: env(safe-area-inset-bottom); }
  .topbar { padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }
  .dav-grid { grid-template-columns: 1fr; gap: 2px; }
  .dav-grid .muted { margin-top: 8px; }
}
