:root {
  --bg: #ffffff; --panel: #f3f3f5; --line: #dcdce0; --text: #1d1d1f; --muted: #6e6e73;
  --accent: #0a6cff; --ok: #2fb551; --off: #b4b4ba; --remote: #0a6cff;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1e1e20; --panel: #28282b; --line: #3a3a3e; --text: #f2f2f4; --muted: #9a9aa1; --accent: #3b8cff; --off: #5c5c63; --remote: #3b8cff; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { font: 16px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg); }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { border: 0; border-radius: 10px; padding: 11px 16px; background: var(--accent); color: #fff; font-weight: 600; }
button.secondary { background: var(--panel); color: var(--text); }
input, select { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--bg); min-width: 0; }

/* Вход */
#login { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 24px; padding-bottom: 20vh; }
#login img { border-radius: 20px; }
#login h1 { margin: 0 0 8px; font-size: 22px; }
#login form { width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 10px; }
#login-error { min-height: 20px; margin: 0; text-align: center; font-size: 14px; color: #d9534f; }

/* Шапка */
#app { min-height: 100%; display: flex; flex-direction: column; }
header { position: sticky; top: 0; z-index: 2; padding: calc(8px + env(safe-area-inset-top)) 12px 8px; background: var(--bg); border-bottom: 1px solid var(--line); }
.bar { display: flex; align-items: center; gap: 8px; }
.bar.sub { margin-top: 8px; justify-content: space-between; }
#q { flex: 1; }
.icon-btn { flex: none; width: 42px; height: 42px; padding: 0; background: var(--panel); color: var(--text); font-size: 22px; font-weight: 400; }
#where { min-width: 0; flex: 1; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#where a { color: var(--accent); }
#sort { flex: none; padding: 6px 8px; font-size: 13px; }
.chips { display: flex; gap: 6px; margin-top: 8px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 6px 12px; border-radius: 16px; background: var(--panel); color: var(--text); font-size: 13px; font-weight: 500; }
.chip.on { background: var(--accent); color: #fff; }

/* Список */
main { flex: 1; padding-bottom: env(safe-area-inset-bottom); }
.row { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-bottom: 1px solid var(--line); }
.row:active { background: var(--panel); }
.thumb { flex: none; width: 52px; height: 40px; display: flex; align-items: center; justify-content: center; font-size: 24px; border-radius: 6px; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.txt { flex: 1; min-width: 0; }
.name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub2 { margin-top: 2px; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chev { flex: none; color: var(--off); font-size: 20px; }
.dot { display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: var(--off); vertical-align: 1px; }
.dot.on { background: var(--ok); }
.note { padding: 40px 24px; text-align: center; color: var(--muted); white-space: pre-line; }
.section { padding: 14px 12px 6px; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }

/* Карточка файла */
#sheet { position: fixed; inset: 0; z-index: 5; display: flex; flex-direction: column; background: var(--bg); overflow-y: auto; padding-bottom: env(safe-area-inset-bottom); }
.sheet-bar { position: sticky; top: 0; display: flex; align-items: center; gap: 10px; padding: calc(8px + env(safe-area-inset-top)) 12px 8px; background: var(--bg); border-bottom: 1px solid var(--line); }
#sheet-title { min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
#sheet-media { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 120px; background: #000; color: #9a9aa1; }
#sheet-media img, #sheet-media video { display: block; max-width: 100%; max-height: 62vh; }
#sheet-media audio { width: 92%; margin: 24px 0; }
#sheet-media .hint { padding: 28px 20px; text-align: center; font-size: 14px; }
#sheet-info { margin: 0; padding: 12px; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
#sheet-info dt { color: var(--muted); }
#sheet-info dd { margin: 0; overflow-wrap: anywhere; }
#sheet-actions { display: flex; flex-direction: column; gap: 8px; padding: 4px 12px 20px; }
#sheet-actions a { display: block; padding: 12px; border-radius: 10px; background: var(--accent); color: #fff; font-weight: 600; text-align: center; text-decoration: none; }
#sheet-actions .why { font-size: 13px; color: var(--muted); text-align: center; }

.text-btn { flex: none; height: 42px; padding: 0 12px; background: var(--panel); color: var(--text); font-size: 14px; font-weight: 500; }
#sort { max-width: 46%; }

#sort { max-width: none; width: 124px; }
#where { overflow-x: auto; text-overflow: clip; scrollbar-width: none; }
#where::-webkit-scrollbar { display: none; }

/* Вход по ключу устройства */
.login-extra { width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 10px; }
#enroll-form { display: flex; flex-direction: column; gap: 10px; }
#enroll-code { text-align: center; letter-spacing: .12em; }
