/* =============================================================================
   CORE THEME VARIABLES
   ========================================================================== */
:root {
  --header-h: 64px;          /* Header height */
  --panel-w: 500px;          /* Side panels width on ≥ xl */
  --tg-radius: 16px;
  --tg-in-bg: #ffffff;
  --tg-out-bg: #e6f5ff;      /* Telegram-ish blue for outgoing */
  --tg-border: rgba(0,0,0,.06);
  --tg-shadow: 0 .35rem .8rem rgba(0,0,0,.08);
  --tg-text: #212529;
  --tg-muted: #6c757d;
}

/* =============================================================================
   GLOBAL HEADER
   ========================================================================== */
header {
  height: var(--header-h);
  box-sizing: border-box;
  transition: padding-right .3s ease; /* smooth shift when right panel opens */
  padding-right: 0;
}

/* Left header segment (burger + search) */
#headerLeft {
  width: var(--panel-w);
  height: var(--header-h);
  display: flex;
  align-items: center;
  transition: width 0.3s ease;
}
#headerLeft.collapsed { width: 60px; } /* burger only */

/* Burger icon */
.navbar-toggler-icon {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%280, 0, 0, 1%29' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
}

/* Right-header controls: link hover underline for meta links only */
.rp-meta-item a:hover { text-decoration: underline; }

/* Optional hover util */
.hover-blue:hover { background-color: #0088cc; cursor: pointer; }
.hover-blue:hover a,
.hover-blue:hover small,
.hover-blue:hover span { color: #fff !important; }

/* =============================================================================
   SEARCH BOX (in header)
   ========================================================================== */
.search-box {
  position: relative;
  flex-grow: 1;
  display: flex;
  overflow: hidden;
  transition: width 0.3s ease;
}
#headerLeft.collapsed .search-box { width: 0; }

/* Input */
#searchInput {
  flex: 1 1 auto;
  border: none;
  border-radius: 50px;
  background-color: #dee2e6;
  padding-left: 2.5rem; /* space for the icon */
}
#searchInput:focus {
  box-shadow: none;
  outline: none;
  border-color: transparent;
}

/* Inline icon (Bootstrap Icons font) */
.search-box::before {
  content: "\f52a";                 /* bi-search unicode */
  font-family: "bootstrap-icons";
  font-size: 1rem;
  color: #6c757d;
  position: absolute;
  left: 15px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

/* =============================================================================
   LEFT OVERLAY SIDE PANEL
   ========================================================================== */
#sidePanel {
  position: fixed;
  top: var(--header-h);
  left: 0;
  width: var(--panel-w);
  max-width: 100vw;
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  background: #fff;
  border-right: 1px solid #6c757d;
  box-shadow: 0 0.5rem 1rem rgba(0,0,0,.15);
  z-index: 1040;
  transform: translateX(0);
  transition: transform 0.3s ease;
}
#sidePanel.collapsed { transform: translateX(-100%); }

/* Background content shift (when left panel is present on desktop) */
#backgroundContent { transition: margin-left 0.3s ease; }

@media (min-width: 1200px) {
  #backgroundContent { margin-left: var(--panel-w); }
  #sidePanel.collapsed ~ #backgroundContent { margin-left: 0; }
}

/* =============================================================================
   RIGHT OVERLAY SIDE PANEL
   ========================================================================== */
#rightPanel {
  position: fixed;
  top: var(--header-h);
  right: 0;
  width: var(--panel-w);
  max-width: 100vw;
  height: calc(100vh - var(--header-h));
  background: #fff;
  border-left: 1px solid #6c757d;
  box-shadow: 0 0.5rem 1rem rgba(0,0,0,.15);
  z-index: 1040;
  display: flex;
  flex-direction: column;
  transition: transform .3s ease;
}
#rightPanel.collapsed { transform: translateX(100%); }

.rp-header { height: 48px; flex: 0 0 48px; background: #fff; }
.rp-body   { flex: 1 1 auto; overflow-y: auto; }

/* Right-panel hero */
.rp-hero {
  position: relative;
  width: 100%;
  height: auto;
  background: #f1f3f5;
  overflow: hidden;
}
.rp-hero-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.rp-hero-fallback {
  width: 100%; height: 100%;
  background: repeating-linear-gradient(
    45deg,
    #e9ecef, #e9ecef 12px,
    #dee2e6 12px, #dee2e6 24px
  );
}
/* Legibility gradient overlay */
.rp-hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,.55), rgba(0,0,0,0) 50%);
  pointer-events: none;
}
.rp-hero-overlay {
  position: absolute;
  left: 16px;
  bottom: 16px;
  z-index: 1;
  color: #fff;
}
.rp-hero-title {
  font-weight: 700;
  font-size: 1.1rem;
  line-height: 1.1;
  margin-bottom: 2px;
  text-shadow: 0 1px 2px rgba(0,0,0,.35);
}
.rp-hero-meta { font-size: .9rem; opacity: .9; }

/* Desktop: shift background content when right panel opens (sibling layout) */
@media (min-width: 1200px) {
  #backgroundContent { transition: margin-right .3s ease, margin-left .3s ease; }
  #backgroundContent { margin-right: 0; }
  #rightPanel:not(.collapsed) ~ #backgroundContent { margin-right: var(--panel-w); }
}

/* Mobile: right panel spans full width */
@media (max-width: 1200px) {
  #rightPanel { width: 100vw; }
}

/* Header shift when right panel opens (works across breakpoints) */
body.right-panel-open header { padding-right: 346px; }
@media (max-width: 1200px) {
  body.right-panel-open header { padding-right: 100vw; }
}

/* =============================================================================
   HEADER RESPONSIVE BEHAVIOR (≤ 1200px)
   ========================================================================== */
@media (max-width: 1200px) {
  /* Left panel becomes full-width drawer */
  #sidePanel { width: 100vw; }

  /* HeaderLeft expands/collapses */
  #headerLeft { width: 100% !important; }
  #headerLeft.collapsed { width: 60px !important; }

  /* When LEFT drawer open: hide right header, show search full-width */
  body.drawer-left-open .headerRight { display: none !important; }
  body.drawer-left-open #rightHeaderControls,
  body.drawer-left-open .headerRight { display: none !important; }
  body.drawer-left-open #headerLeft {
    width: 100% !important;
    flex: 1 1 auto;
  }
  #headerLeft.collapsed .search-box { width: 0; }

  /* When RIGHT drawer open: show only close+label wrapper */
  body.drawer-right-open #headerLeft,
  body.drawer-right-open .headerRight,
  body.drawer-right-open #rightPanelBtn { display: none !important; }
  body.drawer-right-open #rightPanelCloseWrapper {
    display: flex !important;
    width: 100% !important;
    flex: 1 1 auto;
    height: var(--header-h);
    padding-left: 1rem;
    justify-content: flex-start;
    align-items: center;
  }

  /* Ensure search expands when left drawer active */
  body.drawer-left-open #headerLeft:not(.collapsed) .search-box {
    width: 100% !important;
    max-width: 100%;
    opacity: 1;
    transform: none;
  }
  body.drawer-left-open #headerLeft:not(.collapsed) #searchInput { opacity: 1; }
}

/* =============================================================================
   POST CARDS (Telegram-style)
   ========================================================================== */
.tg-row {
  display: flex;
  justify-content: flex-start;
  margin-bottom: 0.75rem;
}

.tg-bubble {
  width: min(560px, 100%);
  background: var(--tg-in-bg);
  box-shadow: var(--tg-shadow);
  border-radius: 16px 16px 16px 10px;
  overflow: hidden;
  color: var(--tg-text);
  text-align: left;
  position: relative;
  padding: 0;
}

/* tiny “tail” notch */
.tg-bubble::after {
  content: "";
  position: absolute;
  width: 10px; height: 10px;
  bottom: 10px; left: -5px;
  background: inherit;
  border: 1px solid var(--tg-border);
  border-top: none; border-right: none;
  transform: rotate(45deg);
  box-shadow: -2px 2px 0 rgba(0,0,0,0.02);
}

/* the media box has a fixed aspect ratio */
.tg-media {
  position: relative;
  aspect-ratio: 16 / 9;     /* adjust if you prefer 4/3, 3/2, etc. */
  overflow: hidden;
}

/* both <img> and <video> fill and crop identically */
.tg-media img,
.tg-media video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;        /* crop to fill, like your images */
}

/* Single media: image/video is a DIRECT child anchor of .tg-media */
.tg-media > .tg-media-link img,
.tg-media > .tg-media-link video {
  transition: transform .25s ease;
  will-change: transform;
}

/* both <img> and <video> fill and crop identically */
.tg-media img,
.tg-media video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;        /* crop to fill, like your images */
}

/* Single media: image/video is a DIRECT child anchor of .tg-media */
.tg-media > .tg-media-link img,
.tg-media > .tg-media-link video {
  transition: transform .25s ease;
  will-change: transform;
}

/* Play icon badge like Telegram */
.tg-play-badge {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  display: flex; align-items: center; justify-content: center;

  width: 48px; height: 48px;              /* adjust size */
  background: rgba(0,0,0,.6);             /* dark translucent circle */
  border-radius: 50%;

  pointer-events: none;                   /* allow click-through */
}

/* White triangle */
.tg-play-badge::before {
  content: "";
  display: block;
  margin-left: 2px;                       /* optical centering */
  width: 0; height: 0;
  border-left: 14px solid #fff;           /* triangle */
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
}

.tg-body { position: relative; padding: 12px 14px 10px; }
.tg-text p:last-child { margin-bottom: .25rem; }

.tg-meta {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 28px;
  padding-right: 52px; /* room for time */
}
.tg-meta .time {
  position: absolute;
  right: 0; bottom: 0;
  font-size: .8rem;
  color: var(--tg-muted);
  line-height: 1;
}

.tg-divider {
  margin: .6rem 0 .4rem;
  border: 0;
  border-top: 1px solid #898989;
  width: 100%;
}

.tg-comments {
  font-weight: 600;
  color: #0c63e4;
  padding: 0 14px 10px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.tg-comments .bi { font-size: 1em; line-height: 1; }

/* Reactions row (Telegram-like pills) */
.tg-reactions { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.tg-reaction {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  font-size: .9rem; line-height: 1.1;
  border-radius: 999px;
  background: #e6f3ff; color: #0c63e4; font-weight: 500;
}
.tg-reaction b { font-weight: 600; }

/* Telegram-ish inline link look */
.tg-readmore,
.tg-readless {
  color: #3390ec;               /* Telegram link blue */
  text-decoration: none;
  cursor: pointer;
  font-weight: 500;
}

.tg-readmore::after {
  content: " ▾";                /* small chevron */
  font-size: 0.95em;
}
.tg-readless::after {
  content: " ▴";
  font-size: 0.95em;
}

/* Optional: subtle fade at the end of the collapsed text (Telegram vibe) */
.tg-text[data-collapsed="true"] .tg-text-collapsed {
  position: relative;
  display: inline;
}
.tg-text[data-collapsed="true"] .tg-text-collapsed::after {
  content: "";
  display: inline-block;
  width: 48px;
  height: 1em;
  margin-left: 4px;
  vertical-align: middle;
  background: linear-gradient(to right, transparent, rgba(255,255,255,0.2));
  border-radius: 8px;
}

/* Smooth expand/collapse for the full text block */
.tg-text-full {
  overflow: hidden;
  height: 0;                 /* collapsed */
  opacity: 0;                /* subtle fade */
  transition: height 240ms ease, opacity 180ms ease;
}

/* Optional: preview fade during expand */
.tg-text[data-collapsed="true"] .tg-text-collapsed {
  transition: opacity 160ms ease;
}

/* When expanded, don't show the truncated preview at all */
.tg-text[data-collapsed="false"] .tg-text-collapsed { display: none; }

/* Hover lift on pointers (no effect on touch) */
@media (hover: hover) {
  .tg-bubble { transition: transform .15s ease, box-shadow .15s ease; }
  .tg-bubble:hover { transform: translateY(-1px); box-shadow: 0 .5rem 1.1rem rgba(0,0,0,.10); }
  /* Hover the anchor, not the whole .tg-media wrapper */
  .tg-media > .tg-media-link:hover img,
  .tg-media > .tg-media-link:hover video {
    transform: scale(1.03);
  }
  .tg-collage-tile:hover img {
    transform: scale(1.03);
  }
}

@media (prefers-reduced-motion: reduce) {
  .tg-media > .tg-media-link img,
  .tg-media > .tg-media-link video,
  .tg-collage-tile img {
    transition: none;
  }
}

/* =============================================================================
   IMAGE LIGHTBOX MODAL
   ========================================================================== */
.tg-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.85);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000; /* above side panels */
}
.tg-modal.open { display: flex; }
.tg-modal-img {
  max-width: 90vw; max-height: 90vh;
  object-fit: contain;
  box-shadow: 0 .5rem 1.25rem rgba(0,0,0,.5);
  border-radius: 8px;
}
.tg-modal-close {
  position: absolute; top: 14px; right: 16px;
  font-size: 2rem; line-height: 1; color: #fff;
  background: transparent; border: 0; cursor: pointer; padding: 6px 10px;
}

/* Explicit stacking so controls are always above the media */
.tg-counter { z-index: 2; }     /* counter above media */
.tg-nav-btn { z-index: 2; }     /* arrows above media */
.tg-modal-close { z-index: 3; } /* close above everything */

/* Counter (Telegram-like) */
.tg-counter {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 10px;
  font-size: .92rem;
  font-weight: 600;
  color: #fff;
  background: rgba(0,0,0,.5);
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 999px;
  backdrop-filter: blur(3px);
  box-shadow: 0 .35rem 1rem rgba(0,0,0,.35);
  user-select: none;
  pointer-events: none;
}

/* Arrows (Telegram-like) */
.tg-nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.24);
  background: rgba(0,0,0,.55);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  backdrop-filter: blur(4px);
  box-shadow: 0 .6rem 1.25rem rgba(0,0,0,.45);
  transition: background .15s ease, transform .12s ease, opacity .2s ease, border-color .15s ease;
  opacity: .95;
  z-index: 1;
}
.tg-nav-btn:focus { outline: none; }
.tg-nav-btn:focus-visible { box-shadow: 0 0 0 3px rgba(255,255,255,.35); }
.tg-nav-btn:hover { background: rgba(255,255,255,.18); border-color: rgba(255,255,255,.32); }
.tg-nav-btn:active { transform: translateY(-50%) scale(.96); }
.tg-prev { left: 16px; }
.tg-next { right: 16px; }

.tg-modal[data-single="true"] .tg-nav-btn,
.tg-modal[data-single="true"] .tg-counter { display: none; }

.tg-modal:not(:hover) .tg-nav-btn { opacity: .75; }
.tg-modal:not(:hover) .tg-counter { opacity: .85; }

/* Modal video only */
.tg-modal .tg-modal-body > video {
  display: block;
  margin: 0 auto;
  width: auto;            /* keep natural aspect */
  height: auto;
  max-width: 100%;
  max-height: 90vh;

  /* desktop minimum */
  min-width: 768px;
  min-height: 432px;

  background: #000;       /* avoids white flash before load */
}

/* Optional: if you also show images in the modal */
.tg-modal .tg-modal-body > img {
  display: block;
  margin: 0 auto;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 90vh;
  object-fit: contain;     /* show full image, no crop */

  /* desktop minimums */
  min-width: 768px;
  min-height: 432px;

  background: #000; 
}

/* Relax minimums on small screens */
@media (max-width: 768px) {
  .tg-modal .tg-modal-body > video,
  .tg-modal .tg-modal-body > img {
    min-width: auto;
    min-height: auto;
  }
}

/* =============================================================================
   COLLAGE STYLES
   ========================================================================== */
.tg-collage {
  position: relative;
  display: grid;
  gap: 6px;
  width: 100%;
}
.tg-collage-tile {
  position: relative;
  overflow: hidden;
  border-radius: 10px;
  display: block;
  background: #111;
}
.tg-collage-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .25s ease;
  will-change: transform;
}
.tg-collage-tile:hover img { transform: scale(1.03); }

/* 3-tile layout: A large left, B top-right, C bottom-right */
.tg-collage-3 {
  grid-template-columns: 2fr 1fr;
  grid-template-rows: 1fr 1fr;
  grid-template-areas:
    "a b"
    "a c";
  aspect-ratio: 16 / 9;
}
.tg-collage-3 .tile-a { grid-area: a; }
.tg-collage-3 .tile-b { grid-area: b; }
.tg-collage-3 .tile-c { grid-area: c; }

/* 2-tile layout: split */
.tg-collage-2 {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr;
  grid-template-areas: "a b";
  aspect-ratio: 16 / 9;
}
.tg-collage-2 .tile-a { grid-area: a; }
.tg-collage-2 .tile-b { grid-area: b; }

/* Reuse gallery count badge */
.tg-gallery-count {
  position: absolute;
  right: 8px;
  bottom: 8px;
  padding: 4px 8px;
  font-size: .85rem;
  font-weight: 600;
  color: #fff;
  background: rgba(0,0,0,.55);
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.22);
  backdrop-filter: blur(2px);
  pointer-events: none;
}

/* Small screens tweaks */
@media (max-width: 480px) {
  .tg-prev { left: 10px; }
  .tg-next { right: 10px; }
  .tg-nav-btn { width: 44px; height: 44px; }
}