:root {
  --bg: #0b1220;
  --panel: #10192d;
  --panel-2: #0c1425;
  --line: rgba(255,255,255,0.08);
  --text: #e7eefc;
  --muted: #97a7c0;
  --accent: #2563eb;
  --accent-2: #60a5fa;
  --danger: #7f1d1d;
  --ok: #22c55e;
  --warn: #eab308;
  --radius: 20px;
  --shadow: 0 16px 40px rgba(0,0,0,0.22);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, Segoe UI, Arial, sans-serif;
  background: radial-gradient(circle at top, #12203b 0%, var(--bg) 42%);
  color: var(--text);
}

a { color: #9ac7ff; text-decoration: none; }
a:hover { color: #c0dcff; }
code { background: rgba(255,255,255,0.08); padding: 2px 6px; border-radius: 8px; }
h1, h2, h3, p { margin-top: 0; }
.page-title { margin-bottom: 8px; }
.hidden { display: none !important; }
.mobile-wrap { word-break: break-word; }
.wrap { flex-wrap: wrap; }
.gap8 { gap: 8px; }

.layout {
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 26px 20px;
  border-right: 1px solid var(--line);
  background: rgba(10,16,31,0.82);
  backdrop-filter: blur(14px);
}

.brand-wrap { display: flex; gap: 14px; align-items: center; margin-bottom: 24px; }
.brand-mark {
  width: 46px; height: 46px; border-radius: 16px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #1d4ed8);
  font-weight: 900; font-size: 22px;
  box-shadow: 0 10px 24px rgba(37,99,235,.35);
}
.brand { font-size: 22px; font-weight: 900; }
.brand-sub { color: var(--muted); font-size: 13px; margin-top: 3px; }

.side-nav { display: grid; gap: 10px; }
.nav-link {
  display: block;
  padding: 14px 16px;
  border-radius: 16px;
  background: rgba(255,255,255,0.04);
  color: var(--text);
  border: 1px solid transparent;
}
.nav-link.active {
  background: rgba(37,99,235,0.18);
  border-color: rgba(96,165,250,.4);
  color: #fff;
}
.nav-link:hover { background: rgba(255,255,255,0.08); }

.card-like,
.card {
  background: rgba(16,25,45,0.92);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card { padding: 18px; margin-bottom: 16px; }
.hint { margin-top: 18px; padding: 16px; color: var(--muted); line-height: 1.5; font-size: 14px; }

.main-wrap { min-width: 0; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(11,18,32,0.72);
  backdrop-filter: blur(14px);
}
.topbar-title { font-size: 18px; font-weight: 800; }
.topbar-sub { color: var(--muted); font-size: 13px; }
.content {
  padding: 22px 24px 110px;
  max-width: 1320px;
}

.flash {
  margin-bottom: 16px;
  padding: 14px 16px;
  border-radius: 16px;
  background: rgba(37,99,235,0.16);
  border: 1px solid rgba(96,165,250,.35);
}

.hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.hero-status { display: flex; align-items: center; }
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}
.row { display: flex; gap: 12px; }
.center { align-items: center; }
.between { justify-content: space-between; }

.cards { display: grid; gap: 14px; margin-bottom: 16px; }
.cards-compact { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.category-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stack-grid { display: grid; grid-template-columns: 1.08fr .92fr; gap: 16px; }
.stat .label { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.stat .value { font-size: clamp(28px, 3vw, 34px); font-weight: 900; }

.quick-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.quick-actions.two-up { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.quick-actions.slim { max-width: 420px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  width: auto;
  padding: 0 16px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.05);
  color: #fff;
  border-radius: 16px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 700;
}
.btn:hover { background: rgba(255,255,255,0.10); }
.btn.primary { background: linear-gradient(135deg, var(--accent), #1d4ed8); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { background: rgba(127,29,29,.92); border-color: rgba(248,113,113,.25); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 40px; font-size: 14px; }
.btn.wide { width: 100%; }
.mobile-strong { min-height: 56px; font-size: 16px; }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}
.badge.green { background: rgba(34,197,94,0.16); color: #86efac; }
.badge.red { background: rgba(239,68,68,0.16); color: #fca5a5; }
.badge.yellow { background: rgba(234,179,8,0.16); color: #fde68a; }
.badge.blue { background: rgba(59,130,246,0.16); color: #93c5fd; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.event-list { display: grid; gap: 12px; }
.event-item {
  padding: 14px;
  border-radius: 18px;
  background: rgba(7,12,24,.8);
  border: 1px solid rgba(255,255,255,0.06);
}
.event-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.event-title { font-weight: 800; margin: 6px 0 4px; font-size: 16px; }
.event-text { white-space: pre-wrap; margin: 8px 0 0; color: #dbe8f8; word-break: break-word; }
.inline-link { display: inline-block; margin-top: 10px; }
.log-box {
  white-space: pre-wrap;
  background: #090f1c;
  padding: 14px;
  border-radius: 16px;
  max-height: 720px;
  overflow: auto;
  border: 1px solid rgba(255,255,255,0.08);
  font-size: 13px;
  line-height: 1.45;
}

.form-stack { display: grid; gap: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 14px;
  color: #d2deee;
}
input, textarea, select {
  width: 100%;
  min-height: 48px;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.12);
  background: #09101d;
  color: #fff;
  padding: 12px 14px;
  font-size: 15px;
}
textarea { min-height: 130px; resize: vertical; }
.checkboxes { display: grid; gap: 12px; }
.toggle-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.checkboxes label {
  flex-direction: row;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border-radius: 16px;
  background: rgba(255,255,255,0.04);
}
.checkboxes input { width: 20px; height: 20px; margin: 0; }
.mobile-form-add { display: grid; grid-template-columns: 1fr 1.5fr auto; gap: 12px; }

.category-card { display: grid; gap: 16px; }
.category-head { display: flex; justify-content: space-between; gap: 12px; }
.category-title { margin: 0; font-size: 20px; }
.meta-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.meta-chip {
  padding: 12px;
  border-radius: 16px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.05);
}
.meta-chip span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.meta-chip strong { font-size: 15px; }

.sticky-submit-bar {
  position: sticky;
  bottom: calc(76px + env(safe-area-inset-bottom));
  z-index: 8;
  display: grid;
  gap: 10px;
  padding: 12px;
  border-radius: 22px;
  background: rgba(11,18,32,0.9);
  border: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.danger-zone { margin-bottom: 4px; }
.warning { background: rgba(245,158,11,0.12); border-color: rgba(245,158,11,0.3); }
.page-actions { margin-bottom: 16px; }

.mobile-nav {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: rgba(9,14,27,0.92);
  backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
}
.mobile-nav {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.mobile-nav-link {
  display: grid;
  gap: 4px;
  justify-items: center;
  padding: 10px 8px;
  border-radius: 16px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.mobile-nav-link.active {
  color: white;
  background: rgba(37,99,235,0.18);
}
.mobile-nav-ico { font-size: 18px; line-height: 1; }

@media (max-width: 1220px) {
  .cards-compact { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stack-grid { grid-template-columns: 1fr; }
}

@media (max-width: 920px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    display: none;
  }
  .content { padding: 16px 16px 106px; }
  .topbar { padding: 14px 16px; }
  .mobile-nav { display: grid; }
  .cards-compact,
  .category-cards,
  .quick-actions,
  .quick-actions.two-up,
  .form-grid,
  .toggle-grid,
  .mobile-form-add,
  .meta-grid {
    grid-template-columns: 1fr 1fr;
  }
  .hero,
  .mobile-stack,
  .section-head {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 640px) {
  .cards-compact,
  .category-cards,
  .quick-actions,
  .quick-actions.two-up,
  .form-grid,
  .toggle-grid,
  .mobile-form-add,
  .meta-grid {
    grid-template-columns: 1fr;
  }
  .content { padding-left: 12px; padding-right: 12px; }
  .topbar-title { font-size: 17px; }
  .card { padding: 16px; border-radius: 18px; }
  .category-title { font-size: 18px; }
  .sticky-submit-bar { bottom: calc(74px + env(safe-area-inset-bottom)); }
}

.category-card,
.category-head,
.category-head > div,
.row,
.meta-chip,
.meta-chip strong {
  min-width: 0;
}

.category-title,
.category-card .muted.small,
.meta-chip strong {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.category-card .muted.small {
  line-height: 1.4;
}

.content {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  overflow-x: hidden;
}

@media (max-width: 640px) {
  .category-head {
    display: block;
  }

  .category-card .muted.small {
    font-size: 11px;
  }

  .meta-chip strong {
    font-size: 14px;
  }
}
/* ===== User app ===== */
.user-app-body {
  background: radial-gradient(circle at top, #132242 0%, var(--bg) 42%);
}

.user-shell {
  max-width: 980px;
  margin: 0 auto;
  min-height: 100vh;
}

.user-topbar {
  position: sticky;
  top: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 16px 10px;
  background: rgba(11,18,32,0.78);
  backdrop-filter: blur(14px);
}

.brand-wrap-mobile { margin-bottom: 0; }

.user-content {
  padding: 10px 16px 108px;
  max-width: 100%;
  min-width: 0;
}

.user-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.live-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.live-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.22);
  box-shadow: 0 0 0 6px rgba(255,255,255,0.05);
}

.live-dot.is-live {
  background: var(--ok);
  box-shadow: 0 0 0 6px rgba(34,197,94,0.15);
}

.user-stats-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.app-filter-head {
  align-items: flex-start;
}

.topic-chip-row {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
}

.topic-chip {
  flex: 0 0 auto;
  min-height: 42px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.04);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.topic-chip.active {
  background: rgba(37,99,235,0.22);
  border-color: rgba(96,165,250,.4);
}

.user-feed-card,
.user-feed-card .section-head,
.user-feed-card .event-list,
.user-event-item,
.user-event-text {
  min-width: 0;
  max-width: 100%;
}

.user-event-item {
  display: grid;
  gap: 10px;
}

.user-event-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.topic-pill {
  display: inline-flex;
  width: fit-content;
  max-width: 100%;
  padding: 8px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  color: #bfdbfe;
  background: rgba(59,130,246,0.16);
  overflow-wrap: anywhere;
}

.topic-preferences {
  display: grid;
  gap: 12px;
}

.topic-pref-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 14px;
  border-radius: 18px;
  background: rgba(7,12,24,.8);
  border: 1px solid rgba(255,255,255,0.06);
}

.topic-pref-title {
  font-size: 17px;
  font-weight: 800;
  margin-bottom: 6px;
}

.topic-pref-tags {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.topic-tag {
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
  background: rgba(255,255,255,0.05);
}

.switch {
  position: relative;
  display: inline-flex;
  width: 58px;
  height: 34px;
}

.switch input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.slider {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.12);
  border-radius: 999px;
  transition: .2s ease;
}

.slider::before {
  content: '';
  position: absolute;
  width: 26px;
  height: 26px;
  left: 4px;
  top: 4px;
  border-radius: 999px;
  background: #fff;
  transition: .2s ease;
}

.switch input:checked + .slider {
  background: rgba(37,99,235,0.8);
}

.switch input:checked + .slider::before {
  transform: translateX(24px);
}

.user-mobile-nav {
  display: flex;
}

@media (max-width: 900px) {
  .user-stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .user-topbar {
    padding: 16px 14px 8px;
  }

  .user-content {
    padding: 8px 14px 104px;
  }

  .user-hero,
  .topic-pref-card {
    grid-template-columns: 1fr;
    display: grid;
  }

  .topic-pref-card {
    gap: 12px;
  }

  .live-inline {
    justify-content: flex-start;
  }

  .user-stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.login-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 420px;
}

.login-brand {
  margin-bottom: 16px;
}

.stack-form {
  display: grid;
  gap: 14px;
}

.form-block {
  display: grid;
  gap: 8px;
}

.topbar-actions {
  align-items: center;
  gap: 8px;
}

.compact-list {
  margin: 8px 0 0;
  padding-left: 18px;
}

.compact-list li + li {
  margin-top: 6px;
}

.push-check-chip.good strong {
  color: #16a34a;
}

.push-check-chip.bad strong {
  color: #dc2626;
}


.admin-member-tools-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

@media (max-width: 900px) {
  .admin-member-tools-grid {
    grid-template-columns: 1fr;
  }
}


/* Multi-program cards + fixed log tail */
.program-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.program-cards .card,
.program-cards .quick-actions,
.program-cards .quick-actions form,
.stack-grid > .card,
.section-head,
.hero,
#dashboardRoot,
#logTailBox,
#lastLogLine {
  min-width: 0;
  max-width: 100%;
}

.program-quick-actions {
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}

.program-quick-actions .btn {
  width: 100%;
  min-width: 0;
  white-space: nowrap;
}

.stack-grid {
  grid-template-columns: minmax(0, 1.08fr) minmax(0, 0.92fr);
}

.log-box,
#logTailBox {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  overflow-y: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  box-sizing: border-box;
}

#lastLogLine {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.4;
  max-height: calc(1.4em * 2);
}

.source-pill {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.small-source {
  align-self: center;
}

@media (max-width: 1220px) {
  .program-cards {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  }
}

@media (max-width: 900px) {
  .program-cards {
    grid-template-columns: 1fr;
  }
}

.event-top-title {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.event-title-inline {
  min-width: 0;
  font-size: 16px;
  line-height: 1.35;
}

.event-title-inline strong {
  font-weight: 800;
}

.event-price-line {
  font-size: 15px;
  line-height: 1.45;
}

.event-price-line strong {
  font-weight: 800;
}

.price-old {
  text-decoration: line-through;
  opacity: 0.72;
}

@media (max-width: 640px) {
  .event-top-title {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* Admin dashboard: source program and mobile log tail fix */
.admin-event-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

@media (max-width: 1220px) {
  .stack-grid {
    grid-template-columns: 1fr !important;
  }

  .stack-grid > .card {
    width: 100%;
    max-width: 100%;
  }
}

:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* Общий контейнер приложения */
body {
  padding-top: var(--safe-top);
}

/* Если у тебя верхняя панель фиксированная или липкая */
.topbar,
.app-header,
.mobile-header {
  padding-top: calc(var(--safe-top) + 8px);
}

/* Чтобы нижняя навигация тоже не прилипала к краю */
.bottom-nav,
.mobile-nav {
  padding-bottom: calc(var(--safe-bottom) + 8px);
}

.topbar,
.app-header,
.mobile-header {
  left: 0;
  right: 0;
  top: 0;
}