/* ===== RESET & VARIABLES ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: var(--font-sans);
  background: #f5f6f8;
  color: #1a1a1a;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding-bottom: 70px;
}
a { text-decoration: none; color: inherit; }
button { background: none; border: none; cursor: pointer; font: inherit; }
img { display: block; max-width: 100%; }
ul { list-style: none; }

:root {
  --header-height: 56px;
  --tabbar-height: 64px;
  --sidebar-width: 250px;
  --content-max: 680px;
  --radius: 14px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --color-accent: #4684D9;
  --color-bg-card: #ffffff;
  --color-border: #e9ecf0;
  --color-text-secondary: #5e6b7a;
  --shadow-card: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.02);
  --plus-bg: rgba(70, 132, 217, 0.14);
  --plus-bg-hover: rgba(70, 132, 217, 0.24);
  --plus-border: rgba(70, 132, 217, 0.35);
  --plus-text: #0039d8;
  --plus-gradient: linear-gradient(135deg, rgba(240, 244, 255, 0.98) 0%, rgba(182, 228, 252, 0.55) 100%);
}

/* ===== HEADER ===== */
.header {
  position: sticky; top: 0; z-index: 100;
  background: #fff;
  border-bottom: 1px solid var(--color-border);
  height: var(--header-height);
  display: flex; align-items: center;
  padding: 0 16px; gap: 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.02);
}
.header__logo {
  font-weight: 700; font-size: 20px; letter-spacing: -0.3px;
  display: flex; align-items: center; gap: 6px; flex-shrink: 0; color: #1a1a1a;
}
.header__logo svg { width: 28px; height: 28px; }
.header__logo-img { width: auto; max-height: 28px; object-fit: contain; }
.header__logo-svg { width: 28px; height: 28px; flex-shrink: 0; }
.header__search {
  flex: 1; min-width: 0; background: #f2f3f5; border-radius: 24px;
  padding: 0 14px; height: 38px; display: flex; align-items: center; gap: 8px;
  color: var(--color-text-secondary); transition: 0.15s;
}
.header__search:focus-within { background: #e8ebef; }
.header__search input {
  background: transparent; border: 0; outline: none; width: 100%; font-size: 14px;
}
.header__search input::placeholder { color: #8e9aab; }
.header__actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.header__actions button, .header-dropdown__trigger {
  width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s; color: #2a2a2a; position: relative;
}
.header__actions button:hover, .header-dropdown__trigger:hover { background: #f0f2f5; }
.header__avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; }
.badge-dot {
  width: 8px; height: 8px; background: #f43f4a; border-radius: 50%;
  position: absolute; top: 6px; right: 6px; border: 2px solid #fff;
}
.plus-badge {
  background: var(--plus-bg);
  color: var(--plus-text);
  border: 1px solid var(--plus-border);
  font-weight: 600;
  font-size: 13px;
  padding: 0 14px 0 10px;
  border-radius: 30px;
  height: 34px;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, border-color 0.15s;
  backdrop-filter: blur(4px);
}
.plus-badge:hover {
  background: var(--plus-bg-hover);
  border-color: rgba(70, 132, 217, 0.5);
}
.plus-badge svg { width: 16px; height: 16px; flex-shrink: 0; }
.header__link { font-size: 14px; font-weight: 500; padding: 8px 12px; color: var(--color-text-secondary); }
.header__btn {
  font-size: 14px; font-weight: 500; padding: 8px 16px;
  background: #1a1a1a; color: #fff; border-radius: 20px;
}
.header__btn:hover { opacity: 0.85; }
.header__burger { display: none; }
.header__write-mobile { display: none; }
.header__messages-mobile { display: none; }
.header-dropdown__user {
  padding: 12px 16px; border-bottom: 1px solid #f0f2f5;
  display: flex; flex-direction: column; gap: 2px;
}
.header-dropdown__user strong { font-size: 14px; }
.header-dropdown__user span { font-size: 12px; color: var(--color-text-secondary); }
.header-dropdown__item small { display: block; font-size: 11px; color: var(--color-text-secondary); margin-top: 2px; }
.header-dropdown__badge {
  background: #f43f4a; color: #fff; font-size: 11px; padding: 1px 6px;
  border-radius: 10px; margin-left: 6px;
}
.mobile-menu__user {
  display: flex; align-items: center; gap: 10px; flex: 1;
}
.mobile-menu__user img { width: 36px; height: 36px; border-radius: 50%; }
.mobile-menu__user span { font-size: 12px; color: var(--color-text-secondary); display: block; }
.mobile-menu__auth {
  display: flex; gap: 8px; margin-bottom: 16px; padding-bottom: 16px;
  border-bottom: 1px solid var(--color-border);
}
.mobile-menu__auth a { flex: 1; text-align: center; }

/* Dropdown */
.header-dropdown,
[data-dropdown] { position: relative; }
.header-dropdown__menu {
  display: none; position: absolute; top: calc(100% + 8px); right: 0;
  background: #fff; border-radius: 12px; box-shadow: 0 8px 32px rgba(0,0,0,0.12);
  min-width: 220px; padding: 8px 0; z-index: 300;
  border: 1px solid var(--color-border);
}
.header-dropdown__menu--notifications { min-width: 320px; max-height: 400px; overflow: hidden; padding: 0; }
.header-dropdown__menu--right { right: 0; left: auto; }
.header-dropdown.is-open .header-dropdown__menu,
[data-dropdown].is-open .header-dropdown__menu { display: block; }
.header-dropdown__title { padding: 8px 16px; font-weight: 600; font-size: 14px; border-bottom: 1px solid #f0f2f5; }
.header-dropdown__item {
  display: block; width: 100%; text-align: left; padding: 10px 16px;
  font-size: 14px; transition: background 0.1s; border: none; background: none;
}
.header-dropdown__item:hover { background: #f5f6f8; }
.header-dropdown__item--unread { font-weight: 500; background: #f8fbff; }
.header-dropdown__item--danger { color: #f43f4a; }
.header-dropdown__empty { padding: 16px; color: var(--color-text-secondary); font-size: 14px; }

/* Mobile menu */
.mobile-menu { display: none; }
.mobile-menu.is-open { display: block; }
.mobile-menu__overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 300;
}
.mobile-menu__panel {
  position: fixed; top: 0; left: 0; bottom: 0; width: 280px;
  background: #fff; z-index: 301; overflow-y: auto; padding: 16px;
  transform: translateX(-100%); transition: transform 0.25s;
}
.mobile-menu.is-open .mobile-menu__panel { transform: translateX(0); }
.mobile-menu__header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px; font-weight: 600;
}
.mobile-menu .sidebar { display: block; width: 100%; }

/* ===== LAYOUT ===== */
.layout {
  display: flex; max-width: 1320px; margin: 0 auto;
  padding: 16px 16px 0; gap: 24px;
}

/* ===== SIDEBAR ===== */
.sidebar { width: var(--sidebar-width); flex-shrink: 0; display: none; }
.sidebar__section { margin-bottom: 28px; }
.sidebar__title {
  font-size: 12px; font-weight: 600; color: var(--color-text-secondary);
  text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; padding-left: 8px;
}
.sidebar-item {
  display: flex; align-items: center; gap: 12px; padding: 8px 12px;
  border-radius: 10px; transition: 0.1s; cursor: pointer;
  color: #1a1a1a; font-weight: 450; font-size: 15px;
}
.sidebar-item:hover { background: #f0f2f5; }
.sidebar-item--active { background: #eef4ff; color: var(--color-accent); font-weight: 500; }
.sidebar-item--link { color: var(--color-accent); }
.sidebar-item .icon-svg {
  width: 24px; height: 24px; flex-shrink: 0; opacity: 0.7;
  fill: none; stroke: currentColor; stroke-width: 1.8;
}
.sidebar-item--active .icon-svg { opacity: 1; }
.sidebar-item__text { flex: 1; }
.sidebar-item__tag {
  font-size: 11px; color: var(--color-text-secondary); background: #eef0f2;
  padding: 2px 10px; border-radius: 30px; font-weight: 400;
}
.sidebar-item__tag--red { background: #f43f4a; color: #fff; }
.sidebar__footer {
  font-size: 12px; color: var(--color-text-secondary);
  padding: 16px 8px 0; border-top: 1px solid var(--color-border); margin-top: 12px;
}
.sidebar__footer a { color: var(--color-accent); font-weight: 500; }
.topic-avatar {
  width: 28px; height: 28px; border-radius: 8px; flex-shrink: 0; overflow: hidden; background: #d0d4db;
  display: inline-flex; align-items: center; justify-content: center;
}
.topic-avatar--svg { color: #fff; }
.topic-avatar--svg .topic-icon-svg { width: 16px; height: 16px; }
.topic-avatar--sm { width: 24px; height: 24px; }
.topic-avatar--sm.topic-avatar--svg .topic-icon-svg { width: 14px; height: 14px; }
.topic-avatar--lg { width: 48px; height: 48px; border-radius: 12px; }
.topic-avatar--lg.topic-avatar--svg .topic-icon-svg { width: 26px; height: 26px; }
.topic-avatar img { width: 100%; height: 100%; object-fit: cover; }
.icon-svg { flex-shrink: 0; display: inline-block; vertical-align: middle; }
.sidebar-item .icon-svg { opacity: 0.85; }
.sidebar-item--active .icon-svg { opacity: 1; }
.admin-sidebar__link .icon-svg { opacity: 0.9; }
.main { flex: 1; min-width: 0; max-width: var(--content-max); padding-bottom: 20px; }

/* ===== RIGHT SIDEBAR ===== */
.right-sidebar { width: 280px; flex-shrink: 0; display: none; }
.right-sidebar__card {
  background: var(--color-bg-card); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow-card);
}
.right-sidebar__title {
  font-weight: 500; font-size: 15px; margin-bottom: 10px;
  display: flex; justify-content: space-between; align-items: center;
}
.right-sidebar__title a { font-size: 13px; color: var(--color-accent); font-weight: 400; }
.right-sidebar__item {
  display: flex; gap: 10px; padding: 10px 4px; border-bottom: 1px solid #f0f2f5;
  font-size: 14px; align-items: center; border-radius: 8px; transition: background 0.12s;
  position: relative; z-index: 1;
}
.right-sidebar__item:hover { background: #f5f8ff; }
.right-sidebar__item--active { background: #eef4ff; }
.right-sidebar__item--topic { min-height: 44px; }
.right-sidebar__item-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.right-sidebar__topic-name { font-weight: 500; line-height: 1.3; }
.right-sidebar__topic-meta { font-size: 11px; color: var(--color-text-secondary); }
.right-sidebar__all-topics {
  display: block; padding: 10px 4px 4px; font-size: 13px; color: var(--color-accent); font-weight: 500;
}
.right-sidebar__all-topics:hover { text-decoration: underline; }
.right-sidebar__item:last-child { border-bottom: 0; }
.right-sidebar__item .num { font-weight: 600; color: var(--color-text-secondary); min-width: 22px; font-size: 13px; }
.right-sidebar__ad {
  background: #fafbfc; border: 1px solid var(--color-border); border-radius: var(--radius);
  padding: 16px; text-align: center; color: var(--color-text-secondary); font-size: 13px;
}
.right-sidebar__ad .placeholder {
  height: 80px; background: #eef0f2; border-radius: 8px; margin-top: 8px;
  display: flex; align-items: center; justify-content: center;
}

/* ===== TABBAR ===== */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; height: var(--tabbar-height);
  background: rgba(255,255,255,0.96); backdrop-filter: blur(12px);
  border-top: 1px solid var(--color-border);
  display: flex; align-items: center; justify-content: space-around; z-index: 200; padding: 0 4px;
}
.tabbar__item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 10px; color: var(--color-text-secondary); padding: 4px 8px;
  border-radius: 8px; transition: 0.1s; font-weight: 450; min-width: 56px; position: relative;
}
.tabbar__item--active { color: var(--color-accent); }
.tabbar__item svg { width: 26px; height: 26px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.tabbar__item span { font-size: 10px; letter-spacing: 0.2px; }
.tabbar__item--write svg { stroke-width: 2.5; }

.floating-write {
  position: fixed; bottom: 80px; right: 20px; background: var(--color-accent); color: #fff;
  width: 56px; height: 56px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(70,132,217,0.35); z-index: 50; transition: 0.15s;
}
.floating-write:hover { transform: scale(1.04); }

/* Flash messages */
.flash {
  max-width: 680px; margin: 12px auto; padding: 12px 16px; border-radius: 10px; font-size: 14px;
}
.flash--success { background: #e8f5e9; color: #2e7d32; }
.flash--error { background: #ffebee; color: #c62828; }

/* Pagination */
.pagination { display: flex; gap: 6px; justify-content: center; margin: 24px 0; flex-wrap: wrap; }
.pagination__item {
  padding: 8px 14px; border-radius: 8px; background: #fff;
  border: 1px solid var(--color-border); font-size: 14px;
}
.pagination__item--active { background: #1a1a1a; color: #fff; border-color: #1a1a1a; }

/* Utilities */
.text-muted { color: var(--color-text-secondary); }
.fw-500 { font-weight: 500; }
.flex { display: flex; }
.items-center { align-items: center; }

/* ===== DONATION WIDGET ===== */
.donation-widget { border: 1px solid #fde8ec; background: linear-gradient(135deg, #fff 0%, #fff8fa 100%); }
.donation-widget__head { display: flex; gap: 10px; margin-bottom: 12px; }
.donation-widget__icon { font-size: 22px; line-height: 1; flex-shrink: 0; }
.donation-widget__title { font-size: 14px; font-weight: 600; line-height: 1.3; }
.donation-widget__desc { font-size: 12px; color: var(--color-text-secondary); margin-top: 4px; line-height: 1.4; }
.donation-progress__track {
  height: 8px; background: #f0e6ea; border-radius: 99px; overflow: hidden; margin-bottom: 8px;
}
.donation-progress__bar {
  height: 100%; background: linear-gradient(90deg, #f43f4a, #ff6b7a);
  border-radius: 99px; transition: width 0.4s ease;
}
.donation-progress__stats {
  display: flex; justify-content: space-between; font-size: 12px; color: var(--color-text-secondary);
}
.donation-progress__stats strong { color: #1a1a1a; font-weight: 600; }
.donation-progress__goal { font-size: 11px; color: var(--color-text-secondary); margin-top: 4px; }
.donation-widget__btn {
  display: block; width: 100%; margin-top: 12px; padding: 10px 14px;
  background: linear-gradient(135deg, #f43f4a, #e8353f); color: #fff;
  border-radius: 10px; font-size: 13px; font-weight: 600; text-align: center;
  transition: opacity 0.15s, transform 0.15s;
}
.donation-widget__btn:hover { opacity: 0.92; transform: translateY(-1px); }
.donation-widget__btn--link { text-decoration: none; }

/* Mobile card — in main feed (hidden on desktop where sidebar shows) */
.donation-widget--mobile-card {
  display: none;
  margin-bottom: 16px;
  padding: 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
}

/* Mobile bar — fixed above tabbar */
.donation-widget--mobile-bar {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: var(--tabbar-height);
  z-index: 90;
  background: linear-gradient(135deg, #fff 0%, #fff8fa 100%);
  border-top: 1px solid #fde8ec;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.06);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
}
.donation-widget__bar-inner {
  display: flex; align-items: center; gap: 10px; max-width: 680px; margin: 0 auto;
}
.donation-widget__bar-info {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px;
}
.donation-widget__bar-text { flex: 1; min-width: 0; }
.donation-widget__bar-text .donation-widget__title {
  display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.donation-progress--compact {
  display: flex; align-items: center; gap: 8px; margin-top: 4px;
}
.donation-progress--compact .donation-progress__track {
  flex: 1; height: 5px; margin-bottom: 0;
}
.donation-progress__mini {
  font-size: 11px; font-weight: 600; color: #f43f4a; flex-shrink: 0; min-width: 32px;
}
.donation-widget__bar-btn {
  flex-shrink: 0; padding: 8px 14px; border-radius: 20px;
  background: linear-gradient(135deg, #f43f4a, #e8353f); color: #fff;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.donation-widget__bar-btn--link { text-decoration: none; display: inline-flex; align-items: center; }

@media (max-width: 1023px) {
  .donation-widget--mobile-card { display: block; }
  .donation-widget--mobile-bar { display: block; }
  body.has-donation-card .donation-widget--mobile-bar { display: none; }
  body:not(.admin-page):not(.login-page-body):not(.has-donation-card) {
    padding-bottom: calc(var(--tabbar-height) + 56px);
  }
  body.has-donation-card:not(.admin-page) {
    padding-bottom: 70px;
  }
  body.article-page-body:not(.has-donation-card) {
    padding-bottom: calc(var(--tabbar-height) + 52px + 56px);
  }
  body.article-page-body.has-donation-card {
    padding-bottom: calc(var(--tabbar-height) + 52px);
  }
  body:not(.has-donation-card) .floating-write {
    bottom: calc(var(--tabbar-height) + 56px + 12px);
  }
  body.has-donation-card .floating-write {
    bottom: calc(var(--tabbar-height) + 12px);
  }
}

@media (min-width: 1024px) {
  .donation-widget--mobile-card,
  .donation-widget--mobile-bar { display: none !important; }
}
.online-widget { padding-bottom: 12px !important; }
.online-widget__head {
  display: flex; align-items: center; gap: 8px; margin-bottom: 10px;
  font-size: 14px; font-weight: 600;
}
.online-widget__dot {
  width: 8px; height: 8px; border-radius: 50%; background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2);
  animation: online-pulse 2s ease-in-out infinite;
}
@keyframes online-pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2); }
  50% { box-shadow: 0 0 0 5px rgba(34, 197, 94, 0.12); }
}
.online-widget__count {
  margin-left: auto; font-size: 12px; font-weight: 600; color: #22c55e;
  background: #ecfdf3; padding: 2px 8px; border-radius: 10px;
}
.online-widget__list { display: flex; flex-direction: column; gap: 4px; }
.online-widget__user {
  display: flex; align-items: center; gap: 8px; padding: 6px 4px;
  border-radius: 8px; font-size: 13px; transition: background 0.12s;
}
.online-widget__user:hover { background: #f5f8ff; }
.online-widget__avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.online-widget__name {
  flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-weight: 500;
}
.online-widget__badge {
  font-size: 10px; font-weight: 600; padding: 2px 6px; border-radius: 6px; flex-shrink: 0;
}
.online-widget__badge--admin { background: #fef3c7; color: #b45309; }
.online-widget__badge--editor { background: #eef4ff; color: var(--color-accent); }
.online-widget__empty { font-size: 12px; color: var(--color-text-secondary); padding: 4px 0; }

/* ===== RESPONSIVE ===== */
@media (min-width: 768px) {
  .sidebar { display: block; }
  .tabbar { display: none; }
  body { padding-bottom: 0; }
  .floating-write { display: none; }
  .header__burger { display: none !important; }
}
@media (min-width: 1024px) {
  .right-sidebar { display: block; }
  .layout { gap: 32px; }
}
@media (max-width: 767px) {
  .header__search { display: none; }
  .header__actions .plus-badge span { display: none; }
  .header__actions .plus-badge { padding: 0; width: 34px; justify-content: center; }
  .header__burger { display: flex !important; }
  .layout { padding: 12px 12px 0; }
  .header__link { display: none; }
  .header__btn { display: none; }

  /* Mobile header layout */
  .header {
    flex-wrap: wrap;
    height: auto;
    min-height: var(--header-height);
    padding: 8px 12px;
    gap: 8px;
  }
  .header__logo span { display: none; }
  .header__logo svg { width: 32px; height: 32px; }
  .header__actions {
    margin-left: auto;
    gap: 2px;
  }
  .header__actions .header-dropdown__trigger,
  .header__actions button.header__burger {
    width: 36px; height: 36px;
  }
  .header__avatar { width: 28px; height: 28px; }

  /* Mobile search bar row */
  .header__mobile-search {
    display: flex !important;
    flex: 1 1 100%;
    order: 3;
    width: 100%;
    background: #f2f3f5;
    border-radius: 12px;
    padding: 0 12px;
    height: 40px;
    align-items: center;
    gap: 8px;
  }
  .header__mobile-search input {
    flex: 1; border: 0; background: transparent; outline: none; font-size: 15px;
  }

  /* Mobile quick actions for guests */
  .header__mobile-auth {
    display: flex !important;
    gap: 6px;
    margin-left: auto;
  }
  .header__mobile-auth a {
    font-size: 13px; padding: 6px 12px; border-radius: 16px; font-weight: 500;
  }
  .header__mobile-auth .header__mobile-login { color: var(--color-text-secondary); }
  .header__mobile-auth .header__mobile-register { background: #1a1a1a; color: #fff; }
  .header__write-mobile {
    display: flex !important; width: 36px; height: 36px; align-items: center; justify-content: center;
    color: var(--color-accent);
  }
  .header__messages-mobile {
    display: flex !important; width: 36px; height: 36px; align-items: center; justify-content: center;
    position: relative; color: #2a2a2a;
  }
}

/* Hidden on desktop */
.header__mobile-search,
.header__mobile-auth { display: none; }
.header__search-btn { display: none; }

@media (max-width: 767px) {
  .news-widget__stats { flex-direction: row; gap: 8px; }
  .news-widget__num { display: none; }
}
