:root {
  --bg: #0f172a;
  --bg-alt: #1e293b;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --accent: #38bdf8;
  --border: #334155;
  --card-bg: #162042;
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

body[data-theme="light"] {
  --bg: #f8fafc;
  --bg-alt: #ffffff;
  --text: #0f172a;
  --text-muted: #475569;
  --accent: #0ea5e9;
  --border: #e2e8f0;
  --card-bg: #ffffff;
}

* {
  box-sizing: border-box;
  scrollbar-color: var(--border) transparent;
}

*::-webkit-scrollbar {
  width: 6px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

body, button, input, select {
  font-family: inherit;
}

button {
  border: none;
  background: var(--accent);
  color: #0f172a;
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

button.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-label { display: none; }
.icon-btn-mobile {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}
#languageToggle .btn-icon {
  font-family: "Vazirmatn", "Inter", system-ui, sans-serif;
  line-height: 1;
  padding-top: 3px;
}

button:hover,
button:focus-visible {
  opacity: 0.85;
}

.app-shell {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg-alt);
  gap: 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand h1 {
  margin: 0;
  font-size: 1.2rem;
}

.brand p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.logo-flag {
  width: 70px;
  height: 47px;
  border-radius: 6px;
  object-fit: cover;
}

.text-muted {
  color: var(--text-muted);
}

.top-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.search-input {
  flex: 1;
  max-width: 280px;
  min-width: 120px;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s;
}
.search-input::placeholder {
  color: var(--text-muted);
}
.search-input:focus {
  border-color: var(--accent);
}

.status-bar {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--bg-alt);
  color: var(--text-muted);
  font-size: 0.9rem;
}

.status-bar strong {
  color: var(--text);
  margin-left: 0.25rem;
}

.layout {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 0.75rem;
  min-height: calc(100vh - 220px);
}

.map-panel {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 0;
}

.map-container {
  flex: 1;
  border-radius: 24px;
  overflow: hidden;
  border: 1px solid var(--border);
  min-height: 450px;
}

.timeline-panel {
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 0.75rem 1rem 1rem;
  background: var(--bg-alt);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 0;
  overflow: hidden;
}

.timeline-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.timeline-meta {
  font-size: 0.95rem;
  color: var(--text-muted);
}

.timeline-meta span:last-child {
  display: inline-block;
  margin-inline-start: 0.35rem;
  color: var(--text);
  font-weight: 600;
}

.timeline-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.quick-ranges {
  display: flex;
  gap: 0.25rem;
}

.quick-ranges button {
  background: rgba(128, 128, 128, 0.18);
  border: 1px solid transparent;
  color: var(--text);
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
  border-radius: 12px;
}

.timeline-track-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.timeline-play-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-alt);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  z-index: 3;
  position: relative;
  margin-bottom: 20px;
}

.timeline-play-btn:active {
  opacity: 0.7;
}

.timeline-track-wrapper {
  flex: 1;
  height: 64px;
  min-width: 0;
  position: relative;
}

.timeline-track {
  position: relative;
  width: 100%;
  height: 100%;
}

.timeline-tick {
  position: absolute;
  top: 0;
  bottom: 20px;
  width: 1px;
  background: var(--border);
  user-select: none;
}

.timeline-tick-label {
  position: absolute;
  bottom: -18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.6rem;
  color: var(--text-muted);
  white-space: nowrap;
  pointer-events: none;
}


.quick-ranges button.active {
  background: var(--accent);
  color: var(--bg);
}

.timeline-selected {
  position: absolute;
  top: 0;
  bottom: 20px;
  background: color-mix(in srgb, var(--accent) 20%, transparent);
  pointer-events: none;
  z-index: 1;
}

.timeline-handle {
  position: absolute;
  top: 0;
  width: 4px;
  height: calc(100% - 20px);
  background: var(--accent);
  cursor: col-resize;
  border-radius: 2px;
  z-index: 2;
  touch-action: none;
}

.timeline-handle::before {
  content: "";
  position: absolute;
  top: -4px;
  bottom: -4px;
  left: -20px;
  right: -20px;
}

.feed-panel {
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--bg-alt);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.feed-panel[hidden] {
  display: none !important;
}

.feed-panel:not(.open) .feed-list {
  display: none;
}

.feed-header {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.feed-header[hidden] {
  display: none !important;
}

.feed-panel .feed-header {
  flex-direction: column;
  align-items: stretch;
  gap: 0.4rem;
}

.feed-header h2 {
  margin: 0;
}

.feed-header p {
  margin: 0.2rem 0 0;
  color: var(--text-muted);
}

.feed-filter-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 36px;
}

.feed-channel-filters {
  display: flex;
  gap: 0.25rem;
}

.channel-filter-btn {
  background: transparent;
  border: 2px solid transparent;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  padding: 0;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.15s, border-color 0.15s;
}

.channel-filter-btn:hover {
  opacity: 0.8;
}

.channel-filter-btn.active {
  opacity: 1;
  border-color: var(--accent);
}

.channel-filter-btn img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.feed-filter-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 8px;
  width: 30px;
  height: 30px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  position: relative;
  flex-shrink: 0;
}

.feed-filter-btn:hover {
  border-color: var(--accent);
}

.feed-filter-btn.active {
  border-color: var(--accent);
  color: var(--accent);
}

.feed-filter-btn.has-filters::after {
  content: '';
  position: absolute;
  top: 2px;
  right: 2px;
  width: 7px;
  height: 7px;
  background: var(--accent);
  border-radius: 50%;
}

#feedPanelClose {
  margin-inline-start: auto;
  flex-shrink: 0;
}

.feed-event-types {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  overflow: hidden;
  max-height: 200px;
  transition: max-height 0.25s ease;
}

.feed-event-types[hidden],
.feed-city-filters[hidden] {
  display: none !important;
}

.feed-city-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.event-type-btn {
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.7rem;
  border: none;
  cursor: pointer;
  background: color-mix(in srgb, var(--et-color) 25%, transparent);
  color: var(--text);
  transition: background 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}

.event-type-btn:hover {
  background: color-mix(in srgb, var(--et-color) 40%, transparent);
}

.event-type-btn.active {
  background: var(--et-color);
  color: #fff;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--et-color) 40%, transparent);
}

.city-filter-btn {
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.7rem;
  border: 1px solid var(--border);
  cursor: pointer;
  background: transparent;
  color: var(--text-muted);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.city-filter-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.city-filter-btn.active {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent);
}

.feed-list {
  overflow-y: auto;
  max-height: calc(100vh - 280px);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem;
}

.feed-card {
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 0.6rem 0.75rem;
  background: var(--card-bg);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  cursor: pointer;
  transition: transform 0.2s ease;
  font-size: 0.8rem;
}

.feed-card:hover {
  transform: translateY(-2px);
}

.feed-card.expanded {
  transform: none;
  border-color: var(--accent);
}

.feed-card-detail {
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 0.3s ease, opacity 0.2s ease, margin-top 0.2s ease;
  margin-top: 0;
}

.feed-card.expanded .feed-card-detail {
  margin-top: 0.5rem;
}

/* Description hidden in collapsed card, shown when expanded */
.feed-card-description {
  display: none;
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.feed-card.expanded .feed-card-description {
  display: block;
}

/* Badges row hidden when expanded (moves to bottom with sources) */
.feed-card.expanded .feed-card-badges {
  display: none;
}

/* Hide info already shown in card header */
.feed-card-detail .popup-content h3,
.feed-card-detail .popup-content .popup-time,
.feed-card-detail .popup-content .popup-description,
.feed-card-detail .popup-content .popup-location,
.feed-card-detail .popup-content > .badge {
  display: none;
}

.feed-card-detail .popup-sources {
  align-items: center;
  width: 100%;
  justify-content: space-between;
}

.feed-detail-badges,
.source-links-wrap {
  display: flex;
  gap: 0.3rem;
  align-items: center;
}

.feed-card-detail .popup-sources .popup-telegram-link {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}

body[dir="rtl"] .feed-card-detail .popup-sources .source-group {
  direction: ltr;
}

.feed-card-detail .popup-carousel-wrap {
  max-width: 320px;
  margin-inline: auto;
}

.feed-card .meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.feed-card .title {
  font-weight: 400;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.65rem;
  margin-inline-end: 0.25rem;
}

.feed-media-filters {
  display: flex;
  gap: 0.25rem;
}

.feed-media-filter {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 8px;
  width: 30px;
  height: 30px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.feed-media-filter:hover {
  border-color: var(--accent);
}

.feed-media-filter.active {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent);
}

.media-indicators {
  display: inline-flex;
  gap: 0.2rem;
  margin-inline-start: 0.35rem;
  vertical-align: middle;
}

.media-indicator {
  color: var(--text-muted);
  line-height: 1;
  display: inline-flex;
}

.source-icons {
  display: inline-flex;
  gap: 0.25rem;
  margin-inline-start: auto;
}

.source-icon {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  object-fit: cover;
}

.source-group {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}

.source-count {
  font-size: 0.65rem;
  color: var(--text-muted);
  line-height: 20px;
}

/* RTL: keep source groups in correct visual order */
body[dir="rtl"] .source-group {
  direction: ltr;
}


.feed-handle {
  display: none;
}

/* Feed mode toggle (Events ↔ Telegram) — always visible */
.feed-mode-toggle {
  display: flex;
  width: 100%;
  background: var(--bg);
  border-radius: 10px;
  padding: 3px;
  gap: 0;
}

.feed-mode-btn {
  flex: 1;
  text-align: center;
  border: none;
  border-radius: 8px;
  padding: 7px 0;
  font-weight: 600;
  font-size: 0.8rem;
  transition: background 0.2s, color 0.2s;
  cursor: pointer;
}

.feed-mode-btn.active {
  background: var(--accent);
  color: #0f172a;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.feed-mode-btn:not(.active) {
  background: transparent;
  color: var(--text-muted);
}

/* Radar ripple effect for highlighting a point */
.ripple-container {
  pointer-events: none;
  position: absolute;
  z-index: 5;
}

.ripple-dot {
  position: absolute;
  width: 16px;
  height: 16px;
  top: -8px;
  left: -8px;
  border-radius: 50%;
  animation: ripple-dot-pulse 1.5s ease-out forwards;
}

.ripple-ring {
  position: absolute;
  border: 2px solid var(--accent);
  border-radius: 50%;
  top: 0;
  left: 0;
  animation: ripple-expand 1.2s ease-out forwards;
  opacity: 0;
}

.ripple-delay {
  animation-delay: 0.35s;
}

@keyframes ripple-dot-pulse {
  0%   { transform: scale(2); opacity: 0.8; }
  50%  { transform: scale(1.4); opacity: 0.5; }
  100% { transform: scale(1); opacity: 0; }
}

@keyframes ripple-expand {
  0%   { width: 0; height: 0; top: 0; left: 0; opacity: 0.9; }
  100% { width: 80px; height: 80px; top: -40px; left: -40px; opacity: 0; }
}

/* Desktop: show toggle in feed panel header */
.feed-panel > .feed-handle {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 8px 12px 4px;
  align-items: center;
  flex-shrink: 0;
}

.feed-panel > .feed-handle > span {
  display: none;
}

/* Telegram card action buttons */
.tg-card-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.tg-events-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(56,189,248,0.08);
  border: 1px solid rgba(56,189,248,0.2);
  color: var(--accent);
  border-radius: 10px;
  padding: 5px 14px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  font-family: inherit;
}

.tg-events-btn:hover:not(:disabled) {
  background: rgba(56,189,248,0.15);
  border-color: rgba(56,189,248,0.4);
}

.tg-events-btn.disabled {
  color: var(--text-muted);
  border-color: var(--border);
  background: transparent;
  opacity: 0.5;
}

.tg-events-count {
  background: var(--accent);
  color: #0f172a;
  font-size: 0.6rem;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 700;
}

.tg-open-embed-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  font-family: inherit;
  white-space: nowrap;
}

.tg-open-embed-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Telegram embed wrapper with events button */
.tg-embed-wrapper {
  flex-shrink: 0;
}

.tg-embed-wrapper .tg-events-btn {
  margin-top: 6px;
  margin-bottom: 8px;
  float: inline-start;
}

/* Events modal */
.events-modal-backdrop[hidden],
.events-modal[hidden] {
  display: none !important;
}

.events-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1000;
}

.events-modal {
  position: fixed;
  z-index: 1001;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 85vh;
  border-radius: 18px 18px 0 0;
}

@media (min-width: 1025px) {
  .events-modal {
    top: 50%;
    left: 50%;
    bottom: auto;
    right: auto;
    transform: translate(-50%, -50%);
    width: 420px;
    max-height: 75vh;
    border-radius: 18px;
  }
}

.events-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.events-modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: color 0.15s;
  font-family: inherit;
}

.events-modal-close:hover {
  color: var(--text);
}

.events-modal-body {
  overflow-y: auto;
  flex: 1;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Map view toggle (clusters vs points) — stacks below nav controls */
.map-view-toggle {
  display: flex;
  flex-direction: column;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: none;
  float: right;
  clear: both;
  margin: 10px 10px 0 0;
  pointer-events: auto;
}

.map-view-btn {
  border: none;
  border-radius: 0;
  width: 36px;
  height: 36px;
  padding: 0;
  cursor: pointer;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.map-view-btn + .map-view-btn {
  border-top: 1px solid var(--border);
}

.map-view-btn:not(.active):hover {
  color: var(--text);
}

.map-view-btn.active,
.map-view-btn.active:hover,
.map-view-btn.active:focus-visible {
  background: var(--accent);
  color: #0f172a;
  opacity: 1 !important;
  cursor: default;
}

/* Map status chip — hidden on desktop, shown on mobile */
.map-status-chip { display: none; }

/* --- Mobile header --- */
.mobile-header { display: none; }
/* --- Mobile search bar --- */
.mobile-search-bar { display: none; }
/* --- Mobile tab bar --- */
.mobile-tab-bar { display: none; }
/* --- Map toggle button --- */
.map-toggle-btn { display: none; }

@media (max-width: 1024px) {
  .map-status-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    position: absolute;
    top: 8px;
    left: 8px;
    right: auto;
    background: color-mix(in srgb, var(--bg-alt) 88%, transparent);
    backdrop-filter: blur(12px);
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.72rem;
    color: var(--text-muted);
    z-index: 5;
    border: 1px solid rgba(255,255,255,0.06);
  }
  .map-status-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: #22c55e;
    animation: pulse-dot 2s ease-in-out infinite;
  }
  @keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
  }
}

@media (max-width: 1024px) {
  /* Hide desktop elements */
  .top-bar { display: none; }
  .status-bar { display: none; }
  .feed-mode-toggle { display: none; }
  .feed-handle { display: none !important; }
  .timeline-panel { display: none; }

  /* Mobile header — single row: flag + title + actions */
  .mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 20;
    height: 44px;
    padding: 0 12px;
    background: var(--bg-alt);
    border-bottom: 1px solid var(--border);
  }
  .mobile-header-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
  }
  .mobile-logo-flag {
    width: 22px;
    height: 15px;
    border-radius: 2px;
    object-fit: cover;
    flex-shrink: 0;
  }
  .mobile-brand-title {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .mobile-header-actions {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-shrink: 0;
  }
  .mobile-search-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 10px;
    width: 32px;
    height: 32px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
  }
  .mobile-search-btn.has-text::after {
    content: '';
    position: absolute;
    top: 2px;
    right: 2px;
    width: 7px;
    height: 7px;
    background: var(--accent);
    border-radius: 50%;
  }

  /* Mobile search bar */
  .mobile-search-bar:not([hidden]) {
    display: block;
    padding: 0 12px 8px;
    background: var(--bg-alt);
  }
  .mobile-search-bar input {
    width: 100%;
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg);
    color: var(--text);
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
  }
  .mobile-search-bar input::placeholder {
    color: var(--text-muted);
  }
  .mobile-search-bar input:focus {
    border-color: var(--accent);
  }

  /* Layout restructure */
  .app-shell {
    padding: 0;
    gap: 0;
    padding-bottom: 52px;
    height: calc(100vh - 52px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .layout {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  /* Map panel: optional, sticky 25vh */
  .map-panel {
    height: 25vh;
    flex-shrink: 0;
    display: none;
  }
  .map-panel.mobile-visible {
    display: flex;
  }
  .map-container {
    border-radius: 0;
    border: none;
    border-bottom: 1px solid var(--border);
    min-height: 0;
  }

  /* Feed panel: scrolls independently below map */
  .feed-panel {
    position: static;
    flex: 1;
    min-height: 0;
    border-radius: 0;
    border: none;
    transform: none !important;
    z-index: auto;
    overflow-y: auto;
  }
  .feed-panel.open .feed-list,
  .feed-panel:not(.open) .feed-list {
    display: flex;
  }

  .feed-list {
    max-height: none;
    flex: 1;
  }

  /* Map toggle button */
  .map-toggle-btn {
    display: flex;
  }
  .map-toggle-btn.active {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(56,189,248,0.15);
  }

  /* Bottom tab bar */
  .mobile-tab-bar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 52px;
    background: var(--bg-alt);
    border-top: 1px solid var(--border);
    z-index: 20;
  }
  .mobile-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 600;
    padding: 4px 0;
    cursor: pointer;
  }
  .mobile-tab.active {
    color: var(--accent);
  }
  .mobile-tab svg {
    width: 22px;
    height: 22px;
  }

  /* Hide close button on mobile */
  #feedPanelClose { display: none; }

  /* Compact map controls for short map */
  .maplibregl-ctrl-group button {
    width: 28px !important;
    height: 28px !important;
  }
  .maplibregl-ctrl-group {
    border-radius: 8px !important;
  }
  /* Move map view toggle to bottom-left so it doesn't overlap nav controls */
  .map-view-toggle {
    float: none;
    position: absolute;
    bottom: 8px;
    left: 8px;
    right: auto;
    margin: 0;
    z-index: 5;
    flex-direction: row;
  }
  .map-view-btn {
    width: 28px;
    height: 28px;
  }
  .map-view-btn + .map-view-btn {
    border-top: none;
    border-inline-start: 1px solid var(--border);
  }
}

/* Landscape: map on right side */
@media (max-width: 1024px) and (orientation: landscape) {
  .layout {
    flex-direction: row;
  }
  .map-panel.mobile-visible {
    height: auto;
    width: 50%;
    order: 2;
  }
  .feed-panel {
    width: 50%;
    order: 1;
  }
}

body[dir="rtl"] {
  font-family: "Vazirmatn", "Inter", system-ui, sans-serif;
}

body[dir="rtl"] .status-bar {
  flex-direction: row-reverse;
}

body[dir="rtl"] .brand {
  flex-direction: row;
}

body[dir="rtl"] .brand > div:last-child {
  text-align: right;
}

body[dir="rtl"] .feed-event-types {
  direction: rtl;
}

.maplibregl-ctrl-group {
  background: var(--bg-alt) !important;
  border: 1px solid var(--border) !important;
  border-radius: 12px !important;
  box-shadow: none !important;
  overflow: hidden;
}

.maplibregl-ctrl-group button {
  width: 36px !important;
  height: 36px !important;
  border: none !important;
  border-bottom: 1px solid var(--border) !important;
  background: transparent !important;
}

.maplibregl-ctrl-group button:last-child {
  border-bottom: none !important;
}

body[data-theme="dark"] .maplibregl-ctrl-group button .maplibregl-ctrl-icon,
:root .maplibregl-ctrl-group button .maplibregl-ctrl-icon {
  filter: invert(1);
}

body[data-theme="light"] .maplibregl-ctrl-group button .maplibregl-ctrl-icon {
  filter: none;
}

.maplibregl-popup-content {
  background: var(--bg-alt);
  color: var(--text);
  border-radius: 18px;
  border: 1px solid var(--border);
  box-shadow: none;
  min-width: 220px;
  max-width: 320px;
}

body[dir="rtl"] .maplibregl-popup-content {
  font-family: "Vazirmatn", "Inter", system-ui, sans-serif;
}

.city-tooltip .maplibregl-popup-content {
  min-width: auto;
  max-width: none;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  line-height: 1.2;
}
.city-tooltip .maplibregl-popup-tip { border-width: 5px; }

body[dir="rtl"] .popup-sources {
  direction: rtl;
}

body[dir="rtl"] .carousel-dots {
  direction: rtl;
}

body[dir="rtl"] .carousel-label {
  direction: rtl;
}

body[dir="rtl"] .maplibregl-popup-close-button {
  right: auto;
  left: 0;
}

.popup-content h3 {
  margin-top: 0;
  margin-bottom: 0.15rem;
}

.popup-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 0 0 0.4rem;
}

.popup-content > .badge {
  margin-bottom: 0.5rem;
}

.popup-content p {
  margin: 0 0 0.5rem;
  color: var(--text-muted);
}

.popup-content a {
  color: var(--accent);
  font-weight: 600;
}

.inline-link {
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
}

.inline-link:hover {
  text-decoration: underline;
}

.popup-sources {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.4rem;
}

.popup-telegram-link {
  cursor: pointer;
  line-height: 0;
}

/* Popup thumbnail carousel */
.popup-carousel-wrap {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

body[dir="rtl"] .popup-carousel-wrap {
  direction: rtl;
}

.carousel-prev,
.carousel-next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.carousel-prev { left: 4px; }
.carousel-next { right: 4px; }


.carousel-prev:hover,
.carousel-next:hover {
  background: rgba(0, 0, 0, 0.8);
}

.popup-carousel {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.popup-carousel::-webkit-scrollbar {
  display: none;
}

.carousel-slide {
  flex: 0 0 100%;
  scroll-snap-align: start;
  position: relative;
  cursor: pointer;
}

.carousel-slide img {
  width: 100%;
  height: 140px;
  object-fit: contain;
  display: block;
}

.carousel-slide .play-badge {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0;
  color: #fff;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 50%;
  width: 48px;
  height: 48px;
  pointer-events: none;
}

.carousel-slide .play-badge::after {
  content: '';
  display: block;
  position: absolute;
  top: 50%;
  left: 54%;
  transform: translate(-50%, -50%);
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 8px 0 8px 14px;
  border-color: transparent transparent transparent #fff;
}

.carousel-label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.4rem;
  font-size: 0.65rem;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.45);
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1;
}

.carousel-label img {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  object-fit: cover;
}

.carousel-dots {
  display: flex;
  justify-content: center;
  gap: 0.25rem;
  margin-bottom: 0.5rem;
  direction: ltr;
}

.carousel-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.2s;
  cursor: pointer;
}

.carousel-dot.active {
  background: var(--accent);
}

.carousel-dot.group-gap {
  margin-left: 0.35rem;
}

/* Telegram post modal */
.tg-modal-backdrop[hidden],
.tg-modal[hidden] {
  display: none !important;
}

.tg-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1010;
}

.tg-modal {
  position: fixed;
  z-index: 1011;
  background: transparent;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  /* Mobile: bottom sheet */
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 90vh;
  border-radius: 12px 12px 0 0;
}

@media (min-width: 1025px) {
  .tg-modal {
    top: 50%;
    left: 50%;
    bottom: auto;
    right: auto;
    transform: translate(-50%, -50%);
    width: 420px;
    max-height: 80vh;
  }
}

.tg-modal-header {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  flex-shrink: 0;
}

.tg-modal-counter {
  color: #fff;
  font-size: 0.85rem;
  opacity: 0.8;
}

.tg-modal-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  z-index: 1;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.tg-modal-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1012;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
}

.tg-modal-nav[hidden] {
  display: none !important;
}

.tg-modal-nav:disabled {
  opacity: 0.3;
  cursor: default;
}

.tg-modal-prev {
  left: 4px;
}

.tg-modal-next {
  right: 4px;
}

body[dir="rtl"] .tg-modal-header {
  direction: rtl;
}

body[dir="rtl"] .tg-modal-prev {
  left: auto;
  right: 4px;
}

body[dir="rtl"] .tg-modal-next {
  right: auto;
  left: 4px;
}

.tg-modal-body {
  overflow-y: auto;
  flex: 1;
}

.tg-modal-body iframe {
  width: 100% !important;
  border: none;
  min-height: 300px;
  display: block;
}

/* Telegram channel filter buttons */
.tg-channel-filters {
  display: flex;
  gap: 0.4rem;
  flex: 1;
  justify-content: center;
}

.tg-channel-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: none;
  cursor: pointer;
  overflow: hidden;
  transition: filter 0.2s, opacity 0.2s, border-color 0.2s;
}

.tg-channel-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tg-channel-btn.disabled {
  filter: grayscale(1);
  opacity: 0.35;
  border-color: var(--border);
}

/* Telegram widget wrappers */
.tg-widget-wrapper {
  min-height: 80px;
  flex-shrink: 0;
}

.tg-widget-wrapper iframe {
  border-radius: 12px !important;
  width: 100% !important;
  display: block;
}

@keyframes highlight-new {
  0% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 50%, transparent); }
  100% { box-shadow: 0 0 0 3px transparent; }
}

.tg-widget-wrapper.new-item,
.tg-widget-wrapper.cross-link-highlight,
.tg-native-card.new-item,
.tg-native-card.cross-link-highlight {
  animation: highlight-new 2s ease-out;
}

/* Telegram feed mode toggle */
.tg-mode-toggle {
  display: inline-flex;
  background: var(--bg);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
  flex-shrink: 0;
}

.tg-mode-btn {
  border: none;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: var(--text-muted);
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}

.tg-mode-btn.active {
  background: var(--accent);
  color: #0f172a;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* Native Telegram card */
.tg-native-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.2s;
  flex-shrink: 0;
}

.tg-native-card:hover {
  transform: translateY(-1px);
}


.tg-native-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.tg-native-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  overflow: hidden;
  flex-shrink: 0;
  cursor: pointer;
}

.tg-native-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tg-native-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.tg-native-channel {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tg-native-time {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.tg-native-text {
  font-size: 0.85rem;
  line-height: 1.45;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

/* Tile grid */
.tg-native-tiles {
  display: grid;
  gap: 3px;
  border-radius: 10px;
  overflow: hidden;
  margin-top: 8px;
}

.tg-native-tiles[data-count="1"] {
  grid-template-columns: 1fr;
}

.tg-native-tiles[data-count="2"],
.tg-native-tiles[data-count="3"],
.tg-native-tiles[data-count="4"] {
  grid-template-columns: 1fr 1fr;
}

.tg-native-tile {
  position: relative;
  overflow: hidden;
  cursor: pointer;
}

.tg-native-tiles[data-count="1"] .tg-native-tile {
  aspect-ratio: 16 / 9;
}

.tg-native-tiles:not([data-count="1"]) .tg-native-tile {
  aspect-ratio: 4 / 3;
}

.tg-native-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tg-native-tile .play-badge {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0;
  color: #fff;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  pointer-events: none;
}

.tg-native-tile .play-badge::after {
  content: '';
  display: block;
  position: absolute;
  top: 50%;
  left: 54%;
  transform: translate(-50%, -50%);
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 7px 0 7px 12px;
  border-color: transparent transparent transparent #fff;
}



/* Loading skeleton for async detail fetch */
.detail-loading {
  height: 60px;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--border) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
