/* Postiz Mobile Responsive — v8 (week view fix + channel UX) */

@media (max-width: 768px) {

  /* === ADMIN BANNER === */
  .bg-forth { display: none !important; }

  /* === ROOT === */
  html, body { overflow-x: hidden !important; }
  body > div > div > div { padding: 0 !important; }

  /* === LEFT NAV (80px) → slide-out drawer === */
  div[class*="w-[80px]"][class*="bg-newBgColorInner"] {
    position: fixed !important;
    left: -260px !important;
    top: 0 !important; bottom: 0 !important;
    width: 240px !important; min-width: 240px !important;
    z-index: 99998 !important;
    transition: left 0.3s ease !important;
    border-radius: 0 !important;
    box-shadow: 4px 0 20px rgba(0,0,0,0.5) !important;
  }
  div[class*="w-[80px]"][class*="bg-newBgColorInner"].mobile-menu-open { left: 0 !important; }
  [id="left-menu"] { position: relative !important; width: 100% !important; inset-inline-start: 0 !important; }
  [id="left-menu"] > div { flex-direction: column !important; align-items: center !important; gap: 16px !important; padding: 12px 0 !important; }
  .flex-1.flex[class*="gap-[8px]"] { gap: 0 !important; }

  /* === TOP HEADER === */
  div[class*="h-[80px]"][class*="bg-newBgColorInner"] {
    height: 46px !important; min-height: 46px !important; padding: 0 8px !important;
  }
  div[class*="text-[24px]"] { font-size: 14px !important; }
  div[class*="gap-[20px]"][class*="text-textItemBlur"] { gap: 5px !important; }
  .bg-blockSeparator { display: none !important; }
  .text-textItemBlur svg { width: 16px !important; height: 16px !important; }

  /* === MAIN CONTENT WRAPPER === */
  .bg-newBgLineColor.blurMe { border-radius: 0 !important; overflow-x: hidden !important; }

  /* === PAGE CONTENT — vertical stack === */
  .flex.flex-1[class*="gap-[1px]"] { flex-direction: column !important; }
  .flex.flex-1[class*="gap-[1px]"] > * { min-width: 0 !important; width: 100% !important; }

  /* ============================================
     CHANNEL SIDEBAR
     Patched classes: mobile-sidebar-outer, mobile-sidebar-inner
     ============================================ */

  /* === CHANNEL SIDEBAR === */
  .mobile-sidebar-outer,
  .flex.relative.flex-col[class*="w-[260px]"],
  .flex.relative.flex-col.group.sidebar {
    width: 100% !important;
    min-width: 100% !important;
    height: auto !important;
    flex: none !important;
    order: -1 !important;
    position: relative !important;
    overflow: visible !important;
  }
  .mobile-sidebar-inner,
  .mobile-sidebar-outer > div[class*="bg-newBgColorInner"][class*="flex-col"] {
    position: relative !important;
    width: 100% !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    padding: 10px 12px !important;
  }
  /* Hide "No channels" illustration */
  img[alt="No channels"] { display: none !important; }
  img[class*="min-w-[100%]"] { display: none !important; }

  /* ============================================
     CALENDAR GRIDS
     Patched class: mobile-calendar-scroll
     ============================================ */

  /* Scroll container: absolute → relative, natural height */
  .mobile-calendar-scroll {
    position: relative !important;
    height: auto !important;
    min-height: 60vh !important;
    overflow: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  /* Calendar parent wrapper — allow natural flow */
  div[class*="flex-col"][class*="text-textColor"][class*="flex-1"] > div[class*="relative"] {
    overflow: visible !important;
    height: auto !important;
  }

  /* -----------------------------------------------
     WEEK VIEW
     Target via Tailwind arbitrary class (reliable fallback)
     ----------------------------------------------- */
  .\[grid-template-columns\:136px_repeat\(7\2c _minmax\(0\2c _1fr\)\)\] {
    position: relative !important;
    height: auto !important;
    min-height: 60vh !important;
    overflow: auto !important;
    -webkit-overflow-scrolling: touch !important;
    grid-template-columns: 56px repeat(7, 120px) !important;
    font-size: 11px !important;
    scroll-snap-type: x proximity !important;
  }

  /* Week view — day header cells */
  .\[grid-template-columns\:136px_repeat\(7\2c _minmax\(0\2c _1fr\)\)\] > .sticky {
    height: 48px !important;
    min-height: 48px !important;
    padding: 4px 2px !important;
  }
  .\[grid-template-columns\:136px_repeat\(7\2c _minmax\(0\2c _1fr\)\)\] > .sticky .text-\[14px\].font-\[500\] {
    font-size: 11px !important;
  }
  .\[grid-template-columns\:136px_repeat\(7\2c _minmax\(0\2c _1fr\)\)\] > .sticky .text-\[14px\].font-\[600\] {
    font-size: 10px !important;
  }

  /* Week time labels — compact */
  .\[grid-template-columns\:136px_repeat\(7\2c _minmax\(0\2c _1fr\)\)\] > .text-newTableText {
    font-size: 10px !important;
    padding: 4px 1px !important;
    word-break: break-all !important;
  }

  /* -----------------------------------------------
     MONTH VIEW
     ----------------------------------------------- */
  .grid-cols-7 {
    grid-template-columns: repeat(7, minmax(46px, 1fr)) !important;
    font-size: 10px !important;
    position: relative !important;
    height: auto !important;
    min-height: 50vh !important;
    overflow: auto !important;
  }

  /* Month day headers */
  .grid-cols-7 > div[class*="bg-newTableHeader"][class*="sticky"],
  .grid-cols-7 > .sticky {
    height: 36px !important;
    min-height: 36px !important;
    padding: 4px 2px !important;
    font-size: 11px !important;
  }

  /* Month day number */
  .grid-cols-7 .pt-\[6px\] {
    padding-top: 3px !important;
    font-size: 12px !important;
    font-weight: 600 !important;
  }

  /* -----------------------------------------------
     DAY VIEW
     ----------------------------------------------- */
  .mobile-calendar-scroll > .text-center.text-\[14px\] {
    font-size: 12px !important;
  }

  /* -----------------------------------------------
     LIST VIEW
     ----------------------------------------------- */
  .mobile-calendar-scroll > .text-center.text-\[14px\].min-h-\[21px\] {
    font-size: 13px !important;
    padding: 8px 4px !important;
  }

  /* -----------------------------------------------
     NAV CONTROLS (view switcher + date nav)
     ----------------------------------------------- */
  div[class*="min-h-[60px]"] {
    min-height: auto !important;
    flex-wrap: wrap !important;
    gap: 6px !important;
    padding: 8px !important;
    justify-content: center !important;
    font-size: 12px !important;
  }

  /* All nav buttons — 44px touch target */
  div[class*="min-h-[60px]"] button,
  div[class*="min-h-[60px]"] a,
  div[class*="min-h-[60px]"] select {
    min-height: 40px !important;
    min-width: 40px !important;
    font-size: 12px !important;
  }

  /* View switcher pills (Day / Week / Month) */
  div[class*="min-h-[60px]"] div[class*="rounded-full"] > * {
    padding: 6px 10px !important;
    font-size: 11px !important;
    min-height: 36px !important;
  }

  /* -----------------------------------------------
     POST CARDS (CalendarItem)
     ----------------------------------------------- */

  /* Show action icons always on touch (no hover on mobile) */
  .group .group-hover\:hidden { display: none !important; }
  .group .hidden.group-hover\:block { display: block !important; }

  /* Post card header bar — taller for touch */
  .group > div[class*="text-white"][class*="text-[11px]"][class*="max-h-[24px]"] {
    max-height: 28px !important;
    height: 28px !important;
    min-height: 28px !important;
    gap: 6px !important;
    padding: 0 6px !important;
  }

  /* Action icon SVGs — bigger touch targets */
  .group > div[class*="text-white"][class*="text-[11px]"] svg {
    width: 18px !important;
    height: 18px !important;
    padding: 2px !important;
  }

  /* Post card body — reduce padding, contain images */
  .group > div[class*="bg-newColColor"] {
    padding: 6px !important;
    gap: 4px !important;
    min-height: 44px !important;
    overflow: hidden !important;
  }
  /* Post cards in calendar — constrain entire card */
  .mobile-calendar-scroll .group,
  .grid-cols-7 .group,
  .\[grid-template-columns\:136px_repeat\(7\2c _minmax\(0\2c _1fr\)\)\] .group {
    max-height: 100px !important;
    overflow: hidden !important;
  }
  /* Post card images (not profile icons) — constrain size */
  .mobile-calendar-scroll .group img:not([class*="w-[20px]"]):not([class*="w-[12px]"]),
  .grid-cols-7 .group img:not([class*="w-[20px]"]):not([class*="w-[12px]"]) {
    max-width: 80px !important;
    max-height: 50px !important;
    object-fit: cover !important;
    border-radius: 4px !important;
  }

  /* Hide profile image in month view to save space */
  .grid-cols-7 .group > div[class*="bg-newColColor"] > div[class*="min-w-[20px]"] {
    display: none !important;
  }

  /* Post content text */
  .group > div[class*="bg-newColColor"] .line-clamp-1 {
    font-size: 11px !important;
    line-height: 1.3 !important;
  }

  /* CalendarColumn cell — bigger touch target */
  div[class*="flex flex-col w-full min-h-full relative"] {
    min-height: 50px !important;
  }

  /* "Show more" / "Show less" — bigger touch target */
  .text-center.hover\:underline {
    min-height: 40px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 12px !important;
    padding: 8px 4px !important;
  }

  /* Error indicator — larger */
  .group > div[class*="absolute"][class*="rounded-full"][class*="bg-red-500"] {
    width: 22px !important;
    height: 22px !important;
    font-size: 13px !important;
  }

  /* Main content panel padding */
  div[class*="bg-newBgColorInner"][class*="flex-1"][class*="p-[20px]"] {
    padding: 8px !important;
  }

  /* ============================================
     ANALYTICS
     ============================================ */
  div[class*="recharts"], svg[class*="recharts"] { width: 100% !important; }
  div[class*="grid-cols-4"],
  div[class*="grid-cols-3"]:not(.grid-cols-7) {
    grid-template-columns: repeat(2, 1fr) !important; gap: 8px !important;
  }

  /* ============================================
     MEDIA
     ============================================ */
  div[class*="grid-cols-5"],
  div[class*="grid-cols-4"] {
    grid-template-columns: repeat(2, 1fr) !important; gap: 8px !important;
  }

  /* ============================================
     SETTINGS — horizontal tabs
     ============================================ */
  div[class*="w-[260px]"][class*="transition-all"][class*="bg-newBgColorInner"]:not(.mobile-sidebar-outer) {
    width: 100% !important; padding: 8px !important;
  }
  div[class*="w-[260px]"][class*="transition-all"]:not(.mobile-sidebar-outer) > div:first-child {
    display: flex !important; flex-wrap: wrap !important; gap: 4px !important;
  }
  div[class*="w-[260px]"][class*="transition-all"]:not(.mobile-sidebar-outer) > div:first-child > div {
    padding: 5px 12px !important; border-radius: 20px !important;
    font-size: 12px !important; white-space: nowrap !important;
    background: rgba(255,255,255,0.05) !important;
  }

  /* ============================================
     AGENT
     ============================================ */
  .trz:not(.agent) {
    width: 100% !important; max-height: 50px !important;
    overflow: hidden !important;
    border-bottom: 1px solid rgba(255,255,255,0.08) !important;
    transition: max-height 0.3s !important;
  }
  .trz:not(.agent):focus-within { max-height: 250px !important; overflow-y: auto !important; }
  .trz:not(.agent) .absolute { position: relative !important; height: auto !important; padding: 8px 12px !important; }
  .trz:not(.agent) h2 { font-size: 14px !important; }
  .trz:not(.agent) a[class*="bg-btnPrimary"] { padding: 6px 12px !important; min-height: 34px !important; font-size: 13px !important; }

  .trz.agent { width: 100% !important; flex: 1 !important; min-height: 55vh !important; }
  .trz.agent > .absolute { position: relative !important; height: auto !important; min-height: 50vh !important; width: 100% !important; }
  .copilotKitMessage, .copilotKitUserMessage, div[class*="min-w-[300px]"] {
    min-width: 0 !important; max-width: 100% !important; word-wrap: break-word !important;
  }
  .trz.agent * { max-width: 100% !important; box-sizing: border-box !important; }

  /* ============================================
     MODALS
     ============================================ */
  [class*="mantine-Modal-content"], [class*="mantine-Modal-body"], div[role="dialog"] {
    width: 100vw !important; max-width: 100vw !important; max-height: 95vh !important;
    margin: 0 !important; border-radius: 8px 8px 0 0 !important;
    overflow-y: auto !important; -webkit-overflow-scrolling: touch !important;
  }
  [class*="mantine-Modal-inner"] { padding: 0 !important; align-items: flex-end !important; }
  div[class*="w-[500px]"], div[class*="w-[600px]"], div[class*="w-[700px]"],
  div[class*="w-[800px]"], div[class*="max-w-[1400px]"], div[class*="max-w-[48rem]"] {
    width: 100% !important; max-width: 100% !important;
  }
  [class*="min-w-[500px]"], [class*="min-w-[600px]"] { min-width: 100% !important; }
  div[role="dialog"] div[class*="grid"] { grid-template-columns: repeat(2, 1fr) !important; gap: 8px !important; }

  /* === ORG DROPDOWN === */
  #org-menu-portal { left: 10px !important; right: 10px !important; max-width: calc(100vw - 20px) !important; }
}

/* ===== SMALL PHONES (≤480px) ===== */
@media (max-width: 480px) {

  /* Month view — tighter */
  .grid-cols-7 {
    grid-template-columns: repeat(7, minmax(40px, 1fr)) !important;
    gap: 2px !important;
    font-size: 9px !important;
  }
  .grid-cols-7 > .sticky,
  .grid-cols-7 > div[class*="bg-newTableHeader"][class*="sticky"] {
    height: 30px !important;
    min-height: 30px !important;
    padding: 2px 1px !important;
    font-size: 10px !important;
  }

  /* Month post cards — colored bars only */
  .grid-cols-7 .group > div[class*="text-white"][class*="text-[11px]"][class*="max-h-[24px]"] {
    max-height: 6px !important; height: 6px !important; min-height: 6px !important;
    border-radius: 3px !important; overflow: hidden !important;
  }
  .grid-cols-7 .group > div[class*="text-white"][class*="text-[11px]"] > * { display: none !important; }
  .grid-cols-7 .group > div[class*="bg-newColColor"] { display: none !important; }
  .grid-cols-7 div[class*="flex flex-col w-full min-h-full relative"] { min-height: 40px !important; }
  .grid-cols-7 .text-center.hover\:underline { min-height: 20px !important; font-size: 9px !important; padding: 2px !important; }

  /* Week view — slightly narrower */
  .\[grid-template-columns\:136px_repeat\(7\2c _minmax\(0\2c _1fr\)\)\] {
    grid-template-columns: 48px repeat(7, 100px) !important;
    font-size: 10px !important;
  }

  /* Nav controls — tighter */
  div[class*="min-h-[60px]"] { gap: 4px !important; padding: 6px 4px !important; }
  div[class*="min-h-[60px]"] div[class*="rounded-full"] > * { padding: 4px 8px !important; font-size: 10px !important; }

  /* Channel sidebar — stack buttons vertically on tiny screens */
  .mobile-sidebar-inner > div[class*="flex-col"][class*="gap-[8px]"] > div[class*="flex"][class*="gap-[8px]"] {
    flex-direction: column !important;
  }
}

/* ===== HAMBURGER ===== */
#mobile-menu-toggle {
  display: none; position: fixed; bottom: 16px; left: 12px;
  width: 44px; height: 44px; border-radius: 50%;
  background: linear-gradient(135deg, #7c3aed, #6d28d9);
  color: white; border: 2px solid rgba(255,255,255,0.2);
  z-index: 99999; cursor: pointer;
  box-shadow: 0 4px 20px rgba(124,58,237,0.5);
  font-size: 20px; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
#mobile-menu-toggle:active { transform: scale(0.9); }
#mobile-menu-toggle.menu-open { background: linear-gradient(135deg, #dc2626, #b91c1c); box-shadow: 0 4px 20px rgba(220,38,38,0.5); }
#mobile-menu-overlay { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.6); z-index: 99997; }
@media (max-width: 768px) { #mobile-menu-toggle { display: flex !important; } }
@media (min-width: 769px) { #mobile-menu-toggle, #mobile-menu-overlay { display: none !important; } }
