/* ==========================================================================
   MODERN DESIGN SYSTEM (No Tailwind, Pure CSS)
   ========================================================================== */

/* --- CSS Reset & Variables --- */
:root {
  /* Палитра (Светлая тема) */
  --bg: #FAFAFA;
  --surface: #FFFFFF;
  --surface-hover: #F4F4F5;
  --line: #E4E4E7;
  --line-strong: #D4D4D8;
  
  --text: #09090B;
  --text-sec: #3F3F46;
  --muted: #71717A;
  
  --brand: #4F46E5;         /* Глубокий Индиго */
  --brand-hover: #4338CA;
  --brand-light: #EEF2FF;
  
  --danger: #EF4444;
  --danger-hover: #DC2626;
  --danger-light: #FEF2F2;
  
  --success: #10B981;
  --warning: #F59E0B;
  
  /* Эффекты */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.06), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --shadow-float: 0 20px 40px -8px rgba(0,0,0,0.1);
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Темная тема (опционально) */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #09090B;
    --surface: #18181B;
    --surface-hover: #27272A;
    --line: #27272A;
    --line-strong: #3F3F46;
    
    --text: #F4F4F5;
    --text-sec: #A1A1AA;
    --muted: #71717A;
    
    --brand: #6366F1;
    --brand-light: rgba(99, 102, 241, 0.15);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.2);
  }
}

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; outline: none; }

body {
  font-family: var(--font-sans);
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* Утилиты */
.w-full { width: 100%; }
.h-full { height: 100%; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }

/* --- Base Layout --- */
.layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

@media (max-width: 1024px) {
  .layout { grid-template-columns: 1fr; }
  .mobile-only { display: inline-flex !important; }
}
@media (min-width: 1025px) {
  .mobile-only { display: none !important; }
}

/* --- Sidebar --- */
.side {
  grid-column: 1; grid-row: 1 / span 2;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  z-index: 40;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.side-head {
  height: 60px;
  display: flex; align-items: center;
  padding: 0 20px;
  border-bottom: 1px solid transparent;
}

.logo {
  font-size: 18px; font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text); text-decoration: none;
}

.side-nav {
  padding: 16px 12px;
  display: flex; flex-direction: column; gap: 4px;
  flex: 1; overflow-y: auto;
}

.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-sec);
  text-decoration: none;
  font-size: 14px; font-weight: 500;
  transition: all 0.15s ease;
}
.nav-item svg { width: 18px; height: 18px; fill: currentColor; opacity: 0.7; transition: opacity 0.15s; }

.nav-item:hover { background: var(--surface-hover); color: var(--text); }
.nav-item:hover svg { opacity: 1; }

.nav-item.is-active {
  background: var(--brand-light);
  color: var(--brand);
}
.nav-item.is-active svg { fill: var(--brand); opacity: 1; }

/* Project Switcher in Sidebar */
.project-switch { padding: 0 12px 16px; position: relative; }
.project-switch-label { display: block; font-size: 11px; font-weight: 600; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; padding-left: 4px; letter-spacing: 0.05em; }
.project-btn { width: 100%; display: flex; justify-content: space-between; align-items: center; background: var(--surface-hover); border-color: transparent; }
.project-btn svg { width: 16px; height: 16px; fill: var(--muted); }

/* Sidebar Footer (Avatar) */
.side-foot {
  padding: 16px 12px;
  border-top: 1px solid var(--line);
}

.avatar-btn {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 8px;
  background: transparent; border: none;
  border-radius: var(--radius-sm); cursor: pointer;
  text-align: left; transition: background 0.15s;
}
.avatar-btn:hover { background: var(--surface-hover); }
.avatar-img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; border: 1px solid var(--line); }
.avatar-meta { flex: 1; min-width: 0; }
.avatar-name { font-size: 14px; font-weight: 600; color: var(--text); }
.avatar-sub { font-size: 12px; color: var(--muted); }
.chev { width: 16px; height: 16px; fill: var(--muted); }

/* Mobile Sidebar behavior */
@media (max-width: 1024px) {
  .side { position: fixed; left: 0; transform: translateX(-100%); width: 280px; }
  .side[data-open="true"] { transform: translateX(0); box-shadow: var(--shadow-float); }
}
.side-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  backdrop-filter: blur(2px); z-index: 30;
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.side-backdrop.show { opacity: 1; pointer-events: auto; }


/* --- Header & Content --- */
.app-head {
  grid-column: 2; grid-row: 1;
  height: 60px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  background: rgba(var(--bg), 0.8);
  backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 20;
}
.content {
  grid-column: 2; grid-row: 2;
  padding: 24px;
  min-width: 0;
}
@media (max-width: 1024px) {
  .app-head { grid-column: 1; border-bottom: 1px solid var(--line); background: var(--surface); }
  .content { grid-column: 1; padding: 16px; }
}


/* --- Dropdowns --- */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; top: calc(100% + 4px); right: 0;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  opacity: 0; visibility: hidden; transform: translateY(-4px);
  transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 100;
  height: inherit;
}
.dropdown.open > .dropdown-menu { opacity: 1; visibility: visible; transform: translateY(0); }
.dropdown-menu--up { top: auto; bottom: calc(100% + 4px); transform: translateY(4px); }
.dropdown.open > .dropdown-menu--up { transform: translateY(0); }

.menu-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 8px 12px;
  background: transparent; border: none; border-radius: var(--radius-sm);
  color: var(--text-sec); font-size: 13px; font-weight: 500;
  text-align: left; text-decoration: none; cursor: pointer;
  transition: background 0.1s;
}
.menu-item svg { width: 16px; height: 16px; fill: currentColor; opacity: 0.7; }
.menu-item:hover { background: var(--surface-hover); color: var(--text); }
.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover { background: var(--danger-light); color: var(--danger-hover); }
.menu-sep { height: 1px; background: var(--line); margin: 4px 6px; }


/* --- UI Elements: Buttons & Inputs --- */
.btn, .btn-ghost, .btn-icon, .btn-primary, .btn-secondary, .btn-success {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: inherit; font-size: 14px; font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer; transition: all 0.15s ease;
  text-decoration: none; white-space: nowrap;
}

.btn { padding: 8px 16px; background: var(--surface); border: 1px solid var(--line-strong); color: var(--text); box-shadow: var(--shadow-sm); }
.btn:hover { background: var(--surface-hover); border-color: var(--muted); }
.btn:active { transform: scale(0.98); }

.btn-primary { padding: 8px 16px; background: var(--brand); border: 1px solid var(--brand); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }

.btn-success { padding: 8px 16px; background: var(--success); border: 1px solid var(--success); color: #fff; }
.btn-success:hover { background: #059669; }

.btn-ghost { padding: 8px 16px; background: transparent; border: 1px solid transparent; color: var(--text-sec); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }

.btn-icon { width: 36px; height: 36px; padding: 0; background: transparent; border: 1px solid transparent; color: var(--text-sec); }
.btn-icon:hover { background: var(--surface-hover); color: var(--text); }
.btn-icon svg { width: 20px; height: 20px; fill: currentColor; }

.input, .select, textarea {
  width: 100%; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); font-size: 14px; color: var(--text);
  transition: border 0.15s, box-shadow 0.15s; font-family: inherit;
}
.input:focus, .select:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-light);
}

.badge {
  display: inline-flex; align-items: center; padding: 2px 8px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em;
  border-radius: 99px; background: var(--surface-hover); color: var(--text-sec); border: 1px solid var(--line);
}


/* --- Dashboard / Feed specific (Day.html) --- */
.feed-container { max-width: 860px; margin: 0 auto; padding-bottom: 60px; }
.feed-header { margin-bottom: 32px; }
.feed-header h1 { font-size: 32px; font-weight: 700; letter-spacing: -0.03em; color: var(--text); margin-bottom: 6px; }
.feed-header .subtitle { font-size: 15px; color: var(--muted); }

/* Theme Chips */
#theme-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 24px; }
.chip-btn {
  padding: 6px 16px; background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 99px; font-size: 13px; font-weight: 500; color: var(--text-sec);
  cursor: pointer; transition: all 0.15s;
}
.chip-btn:hover { background: var(--surface-hover); color: var(--text); border-color: var(--muted); }
.chip-btn.active { background: var(--text); border-color: var(--text); color: var(--surface); }

.chip-btn--ad { border-style: dashed; color: var(--warning); border-color: var(--warning); }
.chip-btn--ad:hover { background: #FEF3C7; }
.chip-btn--ad.active { background: var(--warning); border-color: var(--warning); color: #fff; }

/* Cluster Cards */
#clusters-list { display: flex; flex-direction: column; gap: 16px; }
.cluster-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 20px;
  cursor: pointer; transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: var(--shadow-sm); position: relative;
}
.cluster-card:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.cluster-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 12px; }
.cluster-title { font-size: 18px; font-weight: 600; line-height: 1.4; letter-spacing: -0.01em; color: var(--text); margin: 0; }
.cluster-time { text-align: right; flex-shrink: 0; }
.cluster-date { display: block; font-size: 12px; font-weight: 500; color: var(--muted); }
.cluster-lifespan { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }

.cluster-meta {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  align-items: center;
  overflow: hidden;
}
.meta-tag { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 6px; background: var(--brand-light); color: var(--brand); }
.meta-tag--ad { background: #FEF3C7; color: var(--warning); }
.meta-count { font-size: 12px; font-weight: 500; color: var(--text-sec); }

.cluster-preview { font-size: 14px; line-height: 1.6; color: var(--text-sec); margin-bottom: 16px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* Sources Avatars inside Card */
/* Sources — compact overlap row with fade */
.cluster-sources {
  display: flex;
  align-items: center;
  overflow: hidden;
  position: relative;
  height: 28px;
  gap: 4px;
  flex: 1;
  min-width: 0;
}
.cluster-sources::after {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 32px;
  background: linear-gradient(to right, transparent, var(--surface));
  pointer-events: none;
  z-index: 1;
}
.source-btn {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  padding: 0;
  cursor: pointer;
  background: transparent;
  flex-shrink: 0;
  /* margin-left: -4px; */
  transition: transform 0.15s;
  position: relative;
}
.source-btn:first-child { margin-left: 0; }
.source-btn:hover { transform: scale(1.2); z-index: 3; }
.source-avatar-wrap { width: 100%; height: 100%; position: relative; }
.source-avatar-wrap > div:first-child {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  overflow: hidden;
  border: 1.5px solid var(--surface);
  box-shadow: 0 0 0 0.5px var(--line);
}
.source-avatar { width: 100%; height: 100%; object-fit: cover; }
.source-avatar.text {
  background: var(--line-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  color: #fff;
}
.more-sources {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  margin-left: 6px;
  white-space: nowrap;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}

/* Rank Badges */
.rank-badge {
  position: absolute; top: -12px; left: -12px;
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: #fff;
  box-shadow: 0 0 0 4px var(--bg); z-index: 10;
}
.rank-1 { background: linear-gradient(135deg, #F43F5E, #E11D48); }
.rank-2 { background: linear-gradient(135deg, #F59E0B, #D97706); }
.rank-3 { background: linear-gradient(135deg, #10B981, #059669); }
.rank-norm { background: var(--surface); color: var(--muted); border: 1px solid var(--line-strong); box-shadow: none; width: 28px; height: 28px; top: -10px; left: -10px; font-size: 11px; }

/* --- Drawer / Inspector Modal --- */
.drawer {
  position: fixed; inset: 0; z-index: 100;
  pointer-events: none;
}
.drawer[aria-hidden="false"] { pointer-events: auto; }

/* Фон затемнения */
.drawer::before {
  content: ''; position: absolute; inset: 0;
  background: rgba(0,0,0,0.4); backdrop-filter: blur(2px);
  opacity: 0; transition: opacity 0.3s ease;
}
.drawer[aria-hidden="false"]::before { opacity: 1; }

.drawer .panel {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: min(600px, 100vw);
  background: var(--bg);
  box-shadow: var(--shadow-float);
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.drawer[aria-hidden="false"] .panel { transform: translateX(0); }

.drawer-head {
  padding: 20px 24px; background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: flex-start;
}
.drawer-title { font-size: 20px; font-weight: 700; line-height: 1.3; color: var(--text); margin-bottom: 4px; }
.drawer-subtitle { font-size: 13px; color: var(--muted); }
.drawer-body { flex: 1; overflow-y: auto; padding: 24px; }

/* Posts inside Modal */
.post-list { display: flex; flex-direction: column; gap: 12px; }
.post-item { width:100%; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md); overflow: hidden; }
.post-head {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  background: var(--surface-hover); cursor: pointer; user-select: none;
}
.post-time { font-size: 12px; font-weight: 500; color: var(--muted); width: 44px; flex-shrink: 0; }
.post-author-name { font-weight: 600; font-size: 14px; color: var(--text); }
.post-snippet { flex: 1; min-width: 0; font-size: 13px; color: var(--text-sec); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.post-toggle-icon { font-size: 10px; color: var(--muted); transition: transform 0.2s; }
.post-item.open .post-toggle-icon { transform: rotate(180deg); }
.post-item.open .post-snippet { opacity: 0; }

.post-full-text {
  display: none; flex-direction: column; gap: 12px;
  padding: 16px; border-top: 1px solid var(--line);
  font-size: 14px; line-height: 1.6; color: var(--text);
}
.post-item.open .post-full-text { display: flex; }
.collapse-toggle svg {
  width: 40px;
}
/* Modern Details / Collapsible */
.modern-details { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md); margin-bottom: 16px; overflow: hidden; }
.modern-details > summary { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; font-size: 14px; font-weight: 600; cursor: pointer; user-select: none; background: var(--surface-hover); }
.modern-details > summary::-webkit-details-marker { display: none; }
.modern-details > summary svg { width: 16px; height: 16px; fill: var(--muted); transition: transform 0.2s; }
.modern-details[open] > summary svg { transform: rotate(180deg); }
.modern-details[open] > summary { border-bottom: 1px solid var(--line); }
.modern-details > *:not(summary) { padding: 16px; }

/* WYSIWYG & Compose */
.wysiwyg-toolbar {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 8px; background: var(--surface-hover);
  border: 1px solid var(--line-strong); border-bottom: none;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}
.toolbar-btn {
  padding: 6px 10px; background: transparent; border: none; border-radius: 6px;
  font-size: 14px; font-weight: 500; color: var(--text-sec); cursor: pointer; transition: background 0.1s;
}
.toolbar-btn:hover { background: var(--line-strong); color: var(--text); }
.wysiwyg-editor {
  min-height: 200px; padding: 16px;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  font-size: 15px; line-height: 1.6; outline: none;
}
.wysiwyg-editor:focus { border-color: var(--brand); }
.wysiwyg-editor p { margin-bottom: 12px; }
.wysiwyg-editor p:last-child { margin-bottom: 0; }

/* General helpers */
.field { margin-bottom: 16px; }
.field > label { display: block; font-size: 13px; font-weight: 500; color: var(--text-sec); margin-bottom: 6px; }

/* Media items */
.media-item { position: relative; border-radius: 8px; overflow: hidden; box-shadow: var(--shadow-sm); }
.media-item img { display: block; width: 100%; height: auto; }
.media-preview--video::after {
  content: '▶'; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.3); color: white; font-size: 24px; pointer-events: none;
}

/* AI Skeleton */
.skeleton {
  background: linear-gradient(90deg, var(--surface-hover) 25%, var(--line) 50%, var(--surface-hover) 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: 4px;
}
@keyframes skeleton-loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Modals (Posts modal legacy support) */
#posts-modal { position: fixed; inset: 0; z-index: 1000; display: none; align-items: center; justify-content: center; }
#posts-modal[aria-hidden="false"] { display: flex; }
/* #posts-modal::before { content: ''; position: absolute; inset: 0; background: rgba(0,0,0,0.5); backdrop-filter: blur(2px); } */
.modal-window { position: relative; background: var(--bg); width: 100%; max-width: 800px; max-height: 90vh; border-radius: var(--radius-xl); box-shadow: var(--shadow-float); display: flex; flex-direction: column; overflow: hidden; margin: 16px; z-index: 10; }
.modal-header { padding: 20px 24px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; background: var(--surface); }
.modal-title { font-size: 20px; font-weight: 700; color: var(--text); }
.modal-close { background: transparent; border: none; font-size: 24px; color: var(--muted); cursor: pointer; line-height: 1; transition: color 0.15s; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 24px; overflow-y: auto; }



/* ==========================================================================
   ФИКСЫ: Выпадающие меню, Иконки и страница "Источники"
   ========================================================================== */

/* 1. Исправление выпадающего меню аккаунта и проектов */
.dropdown-menu.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* 2. Глобальный фикс размеров SVG для всех кнопок */
.btn svg, .btn-ghost svg, .btn-primary svg, .btn-success svg, .btn-icon svg {
  width: 18px; height: 18px;
  fill: currentColor; flex-shrink: 0;
}

/* 3. Вкладки (Табы) на странице источников */
.tabs {
  display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 24px;
}
.tabs .tab {
  padding: 8px 16px; border-radius: 99px;
  font-size: 14px; font-weight: 500; color: var(--text-sec);
  background: var(--surface); border: 1px solid var(--line-strong);
  cursor: pointer; transition: all 0.15s; text-decoration: none;
}
.tabs .tab:hover {
  background: var(--surface-hover); color: var(--text);
}
.tabs .tab.active {
  background: var(--text); color: var(--surface); border-color: var(--text);
}

/* 4. Сетка источников (Sources List) */
.source-list { display: grid; gap: 12px; }
.source-row {
  display: grid; grid-template-columns: 1fr auto auto;
  align-items: center; gap: 16px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-md); padding: 16px;
  box-shadow: var(--shadow-sm); transition: transform 0.15s, box-shadow 0.15s;
}
.source-row:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--line-strong);
}
.src-main { display: flex; align-items: center; gap: 16px; min-width: 0; }
.src-avatar { 
  width: 44px; height: 44px; border-radius: 50%; 
  border: 1px solid var(--line); object-fit: cover; flex-shrink: 0; 
}
.src-avatar.ph { 
  background: var(--surface-hover); display: flex; align-items: center; 
  justify-content: center; font-size: 12px; color: var(--muted); 
}
.src-texts { min-width: 0; }
.src-name { font-weight: 600; font-size: 15px; color: var(--text); margin-bottom: 2px; }
.src-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.src-controls { display: flex; align-items: center; gap: 8px; }

/* Цветные бейджи статусов для источников */
.badge.ok { background: var(--brand-light); color: var(--brand); border-color: transparent; }
.badge.warn { background: #FEF3C7; color: var(--warning); border-color: transparent; }
.badge.err { background: var(--danger-light); color: var(--danger); border-color: transparent; }

/* Адаптивность источников для телефонов */
@media (max-width: 640px) {
  .source-row { grid-template-columns: 1fr; gap: 12px; }
  .src-controls { justify-content: flex-start; flex-wrap: wrap; }
}


/* ==========================================================================
   MODERN DESIGN SYSTEM (Pure CSS, No Tailwind)
   ========================================================================== */

/* --- 1. Variables & Base --- */
:root {
  --bg: #FAFAFA;
  --surface: #FFFFFF;
  --surface-hover: #F4F4F5;
  --line: #E4E4E7;
  --line-strong: #D4D4D8;
  
  --text: #09090B;
  --text-sec: #3F3F46;
  --muted: #71717A;
  
  --brand: #4F46E5;
  --brand-hover: #4338CA;
  --brand-light: #EEF2FF;
  
  --danger: #EF4444;
  --danger-light: #FEF2F2;
  --success: #10B981;
  --warning: #F59E0B;
  
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.06);
  --shadow-float: 0 20px 40px -8px rgba(0,0,0,0.1);
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* Сброс SVG (ЧТОБЫ НЕ БЫЛИ ОГРОМНЫМИ) */
svg {
  display: block;
  vertical-align: middle;
  max-width: 100%;
  height: auto;
}

/* Глобальные скроллбары */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* Утилиты */
.w-full { width: 100%; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }

/* --- 2. Layout & Sidebar --- */
.layout {
  display: grid; grid-template-columns: 260px 1fr; grid-template-rows: auto 1fr; min-height: 100vh;
}
@media (max-width: 1024px) {
  .layout { grid-template-columns: 1fr; }
  .mobile-only { display: inline-flex !important; }
}
@media (min-width: 1025px) { .mobile-only { display: none !important; } }


.side-head { height: 60px; display: flex; align-items: center; padding: 0 20px; }
.logo { font-size: 18px; font-weight: 700; letter-spacing: -0.03em; color: var(--text); text-decoration: none; }
.side-nav { padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; overflow-y: auto; }

.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  border-radius: var(--radius-sm); color: var(--text-sec); text-decoration: none;
  font-size: 14px; font-weight: 500; transition: all 0.15s;
}
.nav-item svg { width: 20px; height: 20px; fill: currentColor; opacity: 0.7; flex-shrink: 0; }
.nav-item:hover { background: var(--surface-hover); color: var(--text); }
.nav-item:hover svg { opacity: 1; }
.nav-item.is-active { background: var(--brand-light); color: var(--brand); }
.nav-item.is-active svg { fill: var(--brand); opacity: 1; }

.side-foot { padding: 16px 12px; border-top: 1px solid var(--line); }
.avatar-btn {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 8px;
  background: transparent; border: none; border-radius: var(--radius-sm);
  cursor: pointer; text-align: left; transition: background 0.15s;
}
.avatar-btn:hover { background: var(--surface-hover); }
.avatar-img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; border: 1px solid var(--line); }
.avatar-meta { flex: 1; min-width: 0; }
.avatar-name { font-size: 14px; font-weight: 600; color: var(--text); }
.avatar-sub { font-size: 12px; color: var(--muted); }

/* Мобильный сайдбар */
@media (max-width: 1024px) {
  .side { position: fixed; left: 0; transform: translateX(-100%); width: 280px; }
  .side[data-open="true"] { transform: translateX(0); box-shadow: var(--shadow-float); }
}
.side-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); backdrop-filter: blur(2px);
  z-index: 30; opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.side-backdrop.show { opacity: 1; pointer-events: auto; }

.app-head {
  grid-column: 2; grid-row: 1; height: 60px; display: flex; align-items: center;
  padding: 0 24px; background: rgba(var(--bg), 0.8); backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 20;
}
.content { grid-column: 2; grid-row: 2; padding: 0; min-width: 0;}
@media (max-width: 1024px) {
  .app-head { grid-column: 1; border-bottom: 1px solid var(--line); background: var(--surface); }
  .content { grid-column: 1; }
}

/* --- 3. Выпадающие меню (ФИКС АККАУНТА) --- */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; top: calc(100% + 4px); right: 0; min-width: 220px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg); padding: 6px; z-index: 100;
  opacity: 0; visibility: hidden; transform: translateY(-4px); transition: all 0.15s;
}
.dropdown-menu.open { opacity: 1; visibility: visible; transform: translateY(0); }
.dropdown-menu--up { top: auto; bottom: calc(100% + 4px); transform: translateY(4px); }

.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 12px;
  background: transparent; border: none; border-radius: var(--radius-sm);
  color: var(--text-sec); font-size: 13px; font-weight: 500; cursor: pointer; text-decoration: none;
}
.menu-item svg { width: 16px; height: 16px; fill: currentColor; flex-shrink: 0; opacity: 0.7; }
.menu-item:hover { background: var(--surface-hover); color: var(--text); }
.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover { background: var(--danger-light); color: var(--danger); }
.menu-sep { height: 1px; background: var(--line); margin: 4px 6px; }

/* Project Switcher */
.project-switch { padding: 0 12px 16px; position: relative; }
.project-switch-label { display: block; font-size: 11px; font-weight: 600; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; padding-left: 4px; }
.project-btn { width: 100%; justify-content: space-between; }

/* --- 4. Каркас страниц (ФИКС КОНТЕЙНЕРОВ) --- */
.container { max-width: 1100px; margin: 0 auto; padding: 32px 24px 64px; }
@media (max-width: 768px) { .container { padding: 24px 16px 64px; } }

.page-head {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end;
  margin-bottom: 24px; gap: 16px;
}
.page-head .title h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
.page-head .title .sub { font-size: 14px; color: var(--muted); margin-top: 4px; }
.page-head .status { display: flex; align-items: center; gap: 12px; }

/* Карточки (ФИКС ОШИБКИ ИСЧЕЗНОВЕНИЯ) */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); margin-bottom: 24px;
}
.card-head {
  padding: 16px 20px; border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center; background: rgba(0,0,0,0.01);
}
.card-title { display: flex; align-items: center; gap: 10px; font-size: 16px; font-weight: 600; }
/* ФИКС ОГРОМНЫХ SVG В ЗАГОЛОВКАХ */
.card-title svg { width: 22px; height: 22px; fill: currentColor; flex-shrink: 0; opacity: 0.8; }
.card-tools { display: flex; align-items: center; gap: 8px; }
.card-body { padding: 20px; }

/* Формы и сетки (ФИКС РАЗМЕТКИ monitoring.html) */
.row { display: flex; align-items: flex-end; }
.row-center { display: flex; align-items: center; }
.gap { gap: 16px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.grow { flex: 1 1 250px; }
.field > label { font-size: 13px; font-weight: 500; color: var(--text-sec); }
.input-wrap { position: relative; }

/* --- 5. Элементы управления (Кнопки, Инпуты, Табы) --- */
.input, .select, textarea {
  width: 100%; padding: 10px 12px; background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); font-size: 14px; font-family: inherit; transition: all 0.15s;
}
.input:focus, .select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-light); }

.btn, .btn-ghost, .btn-icon, .btn-primary, .btn-secondary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: inherit; font-size: 14px; font-weight: 500; border-radius: var(--radius-sm);
  cursor: pointer; transition: all 0.15s; text-decoration: none; border: 1px solid transparent;
}
.btn svg, .btn-ghost svg, .btn-icon svg, .btn-primary svg { width: 18px; height: 18px; fill: currentColor; flex-shrink: 0; }

.btn { padding: 8px 16px; background: var(--surface); border-color: var(--line-strong); color: var(--text); box-shadow: var(--shadow-sm); }
.btn:hover { background: var(--surface-hover); }
.btn-primary { padding: 8px 16px; background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--brand-hover); }
.btn-ghost { padding: 8px 16px; background: transparent; color: var(--text-sec); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-icon { width: 36px; height: 36px; padding: 0; background: transparent; color: var(--text-sec); }
.btn-icon:hover { background: var(--surface-hover); color: var(--text); }

/* Табы (ФИКС ВКЛАДОК "Новости", "Сообщения") */
.tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.tabs .tab {
  padding: 8px 18px; border-radius: 99px; font-size: 14px; font-weight: 500;
  color: var(--text-sec); background: var(--surface); border: 1px solid var(--line-strong);
  cursor: pointer; transition: all 0.15s;
}
.tabs .tab:hover { background: var(--surface-hover); color: var(--text); }
.tabs .tab.active { background: var(--text); color: var(--surface); border-color: var(--text); }

/* Тумблер (Switch) */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; margin: 0; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--line-strong); transition: .3s cubic-bezier(0.4, 0.0, 0.2, 1); border-radius: 22px; }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 2px; bottom: 2px; background-color: white; transition: .3s cubic-bezier(0.4, 0.0, 0.2, 1); border-radius: 50%; box-shadow: 0 2px 4px rgba(0,0,0,0.15); }
input:checked + .slider { background-color: var(--success); }
input:checked + .slider:before { transform: translateX(18px); }

/* Бейджи и подсказки */
.badge {
  display: inline-flex; align-items: center; padding: 4px 10px; border-radius: 99px;
  font-size: 12px; font-weight: 600; background: var(--surface-hover); color: var(--text-sec); border: 1px solid var(--line);
}
.hint { font-size: 13px; color: var(--muted); margin-top: 6px; }

/* Таблицы (ФИКС monitoring.html) */
.table-wrap { border: 1px solid var(--line); border-radius: var(--radius-md); overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; text-align: left; }
.table th, .table td { padding: 14px 16px; border-bottom: 1px solid var(--line); font-size: 14px; }
.table th { background: var(--surface-hover); font-weight: 600; color: var(--text-sec); }
.table tr:last-child td { border-bottom: none; }
.table .w-min { width: 1%; white-space: nowrap; }

/* --- 6. Кастомные компоненты из ваших шаблонов --- */

/* Всплывающие подсказки (kw-help) */
.kw-help-btn {
  width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface-hover); color: var(--text-sec); font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; font-size: 12px;
}
.kw-help-btn:hover { background: var(--line); color: var(--text); }
.kw-help-pop {
  position: absolute; top: 40px; left: 0; z-index: 80; width: 320px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg); padding: 16px;
}
.kw-help-text { font-size: 13px; color: var(--muted); line-height: 1.5; }
.kw-help-text code { display: inline-block; margin-top: 6px; background: var(--surface-hover); padding: 2px 6px; border-radius: 4px; color: var(--text); }

/* Статистика источников (sources.html) */
.sources-stats {
  display: flex; align-items: center; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 16px 20px; margin-bottom: 24px; box-shadow: var(--shadow-sm);
}
.sources-stats__item { display: flex; flex-direction: column; align-items: center; flex: 1; gap: 4px; }
.sources-stats__value { font-size: 24px; font-weight: 700; color: var(--text); }
.sources-stats__value--muted { color: var(--muted); }
.sources-stats__value--queue { color: var(--warning); }
.sources-stats__label { font-size: 11px; color: var(--muted); text-transform: uppercase; font-weight: 600; letter-spacing: 0.05em; }
.sources-stats__sep { width: 1px; height: 32px; background: var(--line); }

/* Сетка источников (sources.html) */
.source-list { display: grid; gap: 12px; }
.source-row {
  display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md);
  padding: 16px; transition: box-shadow 0.15s;
}
.source-row:hover { border-color: var(--line-strong); box-shadow: var(--shadow-sm); }
.src-main { display: flex; align-items: center; gap: 16px; min-width: 0; }
.src-avatar { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); object-fit: cover; }
.src-texts { min-width: 0; }
.src-name { font-weight: 600; font-size: 15px; margin-bottom: 2px; }
.src-sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.src-controls { display: flex; align-items: center; gap: 8px; }

/* Лента упоминаний (monitoring.html) */
#feed-container { display: flex; flex-direction: column; gap: 16px; }
.mention-item {
  display: flex; gap: 16px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-md); padding: 16px; transition: box-shadow 0.15s;
}
.mention-item:hover { border-color: var(--line-strong); box-shadow: var(--shadow-sm); }
.mention-avatar { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; }
.mention-content { flex: 1; min-width: 0; }
.mention-header { display: flex; justify-content: space-between; margin-bottom: 8px; }
.mention-channel { font-weight: 600; font-size: 15px; color: var(--text); }
.mention-time { font-size: 12px; color: var(--muted); }
.mention-text { font-size: 14px; line-height: 1.5; color: var(--text-sec); margin-bottom: 12px; }
.mention-actions { display: flex; gap: 8px; }

/* Модалки и Инспектор */
#posts-modal { position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,0.5); backdrop-filter: blur(2px); }
.drawer { position: fixed; inset: 0; z-index: 100; pointer-events: none; }
.drawer[aria-hidden="false"] { pointer-events: auto; }
.drawer::before { content: ''; position: absolute; inset: 0; background: rgba(0,0,0,0.4); backdrop-filter: blur(2px); opacity: 0; transition: opacity 0.3s; }
.drawer[aria-hidden="false"]::before { opacity: 1; }
.drawer .panel { position: absolute; top: 0; right: 0; bottom: 0; width: min(600px, 100vw); background: var(--bg); box-shadow: var(--shadow-float); display: flex; flex-direction: column; transform: translateX(100%); transition: transform 0.3s; }
.drawer[aria-hidden="false"] .panel { transform: translateX(0); }
.drawer-head { padding: 20px 24px; background: var(--surface); border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; }
.drawer-title { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.drawer-subtitle { font-size: 13px; color: var(--muted); }
.drawer-body { flex: 1; overflow-y: auto; padding: 24px; }

/* AI и Compose Panel */
.wysiwyg-toolbar { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px; background: var(--surface-hover); border: 1px solid var(--line-strong); border-bottom: none; border-radius: var(--radius-md) var(--radius-md) 0 0; }
.toolbar-btn { padding: 6px 10px; background: transparent; border: none; border-radius: 6px; font-size: 14px; font-weight: 500; cursor: pointer; }
.toolbar-btn:hover { background: var(--line-strong); }
.wysiwyg-editor { min-height: 200px; padding: 16px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 0 0 var(--radius-md) var(--radius-md); font-size: 15px; outline: none; }
.wysiwyg-editor:focus { border-color: var(--brand); }



/* ==========================================================================
   СТИЛИ ДЛЯ ВКЛАДКИ "НАСТРОЙКИ" (settings.html)
   ========================================================================== */
.settings-container {
    max-width: 780px;
    margin: 0 auto;
    padding: 32px 24px 80px;
}
/* Заголовок страницы */
h2 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 24px;
  color: var(--text);
}

/* Утилиты отступов (замена Tailwind) */
.mb-4 { margin-bottom: 24px; }
.mt-2 { margin-top: 12px; }
.text-sm { font-size: 13px; color: var(--text); font-weight: 500; }

/* Списки внутри карточек */
ul.list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
}

.list-item {
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}
.list-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}
.list-item:first-child {
  padding-top: 0;
}

/* Строка проекта */
.projects-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.projects-row > div:first-child {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Красная кнопка (Завершить сессию) */
.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-danger:hover {
  background: #DC2626; /* Более темный красный */
  border-color: #DC2626;
}

/* Выделение текущего проекта / сессии */
#projects-list .hint {
  background: var(--brand-light);
  color: var(--brand);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  margin-top: 0;
}

.tg-suggest__item--added {
  opacity: 0.5;
  cursor: default;
}
.tg-suggest__badge {
  font-size: 11px;
  color: #10b981;
  margin-left: 6px;
}



/* Autopublish settings */
.ap-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.ap-field {
  margin-bottom: 16px;
}
.ap-field > label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-sec);
  margin-bottom: 6px;
}
.ap-channel-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.ap-channel-row .input {
  flex: 1;
  max-width: 280px;
}
.ap-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
@media (max-width: 640px) {
  .ap-grid { grid-template-columns: 1fr; }
}
.ap-input-unit {
  display: flex;
  align-items: center;
  gap: 8px;
}
.ap-input-unit .input {
  width: 80px;
}
.ap-input-unit span {
  font-size: 13px;
  color: var(--muted);
}
#ap-verify-status {
  font-size: 13px;
  font-weight: 500;
}

.meta-count {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
}

.meta-item {
  display: inline-flex;
  align-items: center;
  white-space: nowrap; 
}

.meta-divider {
  opacity: 0.5;
}