:root {
  --bg: #0f1115;
  --surface: #181b22;
  --surface-2: #222631;
  --line: #2c3140;
  --text: #e9ecf2;
  --muted: #8a92a6;
  --accent: #4f8cff;
  --accent-text: #ffffff;
  --danger: #ff5a5f;
  --ok: #3ccf8e;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  overscroll-behavior-y: contain;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
[hidden] { display: none !important; }

/* ---------- шапка ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  background: rgba(15, 17, 21, 0.92);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-row { display: flex; align-items: center; gap: 8px; }
.topbar h1 { font-size: 20px; margin: 0; flex: 1; letter-spacing: -0.01em; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 0;
  background: var(--surface); display: grid; place-items: center; position: relative;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn .dot {
  position: absolute; top: 8px; right: 8px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--danger); border: 2px solid var(--surface);
}

.chips { display: flex; gap: 6px; overflow-x: auto; padding-top: 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: transparent; border-radius: 999px;
  padding: 6px 12px; font-size: 14px; color: var(--muted); white-space: nowrap;
}
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }

/* ---------- лента ---------- */
.feed { padding: 4px 12px calc(var(--safe-bottom) + 24px); max-width: 1100px; margin: 0 auto; }
.day-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 18px 4px 8px; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 960px) { .grid { grid-template-columns: repeat(4, 1fr); } }

.card {
  position: relative; border: 0; padding: 0; border-radius: var(--radius); overflow: hidden;
  background: var(--surface); aspect-ratio: 16 / 9; display: block; width: 100%;
}
.card img { width: 100%; height: 100%; object-fit: cover; display: block; background: var(--surface-2); }
.card .meta {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 8px 6px;
  background: linear-gradient(transparent, rgba(0,0,0,0.75));
  display: flex; justify-content: space-between; align-items: flex-end; gap: 6px; font-size: 12px; text-align: left;
}
.card .meta b { font-weight: 600; font-size: 13px; }
.card .meta span { color: #d0d4de; white-space: nowrap; }
.card .badge {
  position: absolute; top: 6px; left: 6px; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 999px;
  background: rgba(0,0,0,0.6); color: #fff; display: flex; align-items: center; gap: 4px;
}
.card .badge.motion { background: rgba(255, 90, 95, 0.85); }
.card.new { outline: 2px solid var(--accent); outline-offset: -2px; }

.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty svg { width: 48px; height: 48px; opacity: 0.5; }
.loader { text-align: center; color: var(--muted); padding: 20px; font-size: 14px; }
.new-pill {
  position: fixed; top: calc(var(--safe-top) + 110px); left: 50%; transform: translateX(-50%); z-index: 11;
  background: var(--accent); color: var(--accent-text); border: 0; border-radius: 999px; padding: 8px 16px;
  font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}

/* ---------- просмотр ---------- */
.viewer {
  position: fixed; inset: 0; z-index: 50; background: #000; display: flex; flex-direction: column;
  padding: var(--safe-top) 0 var(--safe-bottom);
}
.viewer-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
.viewer-head .title { flex: 1; min-width: 0; }
.viewer-head .title b { display: block; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer-head .title span { color: var(--muted); font-size: 13px; }
.viewer-stage { flex: 1; display: grid; place-items: center; position: relative; overflow: hidden; touch-action: pan-y pinch-zoom; }
.viewer-stage img, .viewer-stage video { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-stage .spinner { position: absolute; color: var(--muted); }
.nav-btn {
  position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 64px; border: 0;
  background: rgba(255,255,255,0.08); border-radius: 12px; display: grid; place-items: center;
}
.nav-btn.prev { left: 8px; } .nav-btn.next { right: 8px; }
.nav-btn svg { width: 24px; height: 24px; }
@media (hover: none) { .nav-btn { display: none; } }
.viewer-actions { display: flex; gap: 8px; padding: 10px 12px; flex-wrap: wrap; }
.viewer-actions .btn { flex: 1; }
.viewer-info { color: var(--muted); font-size: 12px; padding: 0 14px 10px; }

/* ---------- формы, настройки ---------- */
.page { padding: 12px 16px calc(var(--safe-bottom) + 30px); max-width: 640px; margin: 0 auto; }
.section { background: var(--surface); border-radius: var(--radius); padding: 14px; margin: 12px 0; }
.section h2 { font-size: 15px; margin: 0 0 10px; }
.section p { margin: 6px 0; color: var(--muted); font-size: 14px; }
.row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.row:first-of-type { border-top: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .sub { color: var(--muted); font-size: 12px; }
.btn {
  border: 0; border-radius: 12px; padding: 11px 14px; background: var(--surface-2); font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; color: var(--text);
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 7px 10px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: 0.5; }
.field { display: block; margin: 10px 0; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.input {
  width: 100%; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg);
  outline: none;
}
.input:focus { border-color: var(--accent); }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.inline-form .input { flex: 1; min-width: 120px; }
.status-ok { color: var(--ok); } .status-bad { color: var(--danger); }
.hint { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; font-size: 14px; color: var(--text); margin-top: 8px; }

.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch i { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: .2s; }
.switch i::after { content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + i { background: var(--ok); }
.switch input:checked + i::after { transform: translateX(18px); }

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login form { width: 100%; max-width: 340px; }
.login .logo { width: 72px; height: 72px; border-radius: 20px; display: block; margin: 0 auto 16px; }
.login h1 { text-align: center; margin: 0 0 20px; font-size: 24px; }
.login .btn { width: 100%; margin-top: 8px; }
.error { color: var(--danger); font-size: 14px; min-height: 20px; margin-top: 8px; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 20px); transform: translateX(-50%); z-index: 100;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 90vw;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
