/* Postiz mobil használhatósági javítás — Cognitudo
   Injektálva: nginx sub_filter (/etc/nginx/nginx.conf a postiz konténerben)
   Forrás a hoston: /opt/postiz/mobile/postiz-mobile.css
   A Postiz saját osztályai Tailwind "arbitrary value" nevek, ezért
   [class*="..."] attribútum-szelektorral célozzuk őket. */

@media (max-width: 900px) {

  html,
  body {
    overflow-x: hidden !important;
    max-width: 100vw;
  }

  /* ---------- Gyökér keret ---------- */
  div[class*="min-h-screen"][class*="min-w-screen"] {
    min-width: 0 !important;
    padding: 6px 6px 60px 6px !important;
  }

  /* ---------- 1. Bal oldali menü -> alsó navigációs sáv ---------- */
  div:has(> #left-menu) {
    width: 0 !important;
    min-width: 0 !important;
    background: transparent !important;
  }

  #left-menu {
    position: fixed !important;
    top: auto !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    inset-inline-start: 0 !important;
    width: 100% !important;
    height: auto !important;
    max-height: none !important;
    padding-top: 0 !important;
    z-index: 9000;
    background: var(--new-bgColorInner, #fff);
    border-top: 1px solid var(--new-border, rgba(0, 0, 0, .1));
    box-shadow: 0 -4px 16px rgba(0, 0, 0, .18);
  }

  #left-menu > div {
    flex-direction: row !important;
    align-items: center !important;
    height: auto !important;
    gap: 0 !important;
    padding: 2px 2px calc(2px + env(safe-area-inset-bottom)) !important;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
  }

  #left-menu img {
    display: none !important;
  }

  #left-menu > div > div {
    flex-direction: row !important;
    gap: 0 !important;
    flex: 1 1 auto !important;
  }

  #left-menu a,
  #left-menu button {
    flex-direction: column !important;
    justify-content: center !important;
    height: 46px !important;
    min-width: 0 !important;
    width: auto !important;
    flex: 1 1 0 !important;
    padding: 4px 1px !important;
    gap: 2px !important;
  }

  /* az ikon max-height:800px alatt el van rejtve (custom:hidden) — mobilon kell */
  #left-menu a > div:first-child,
  #left-menu button > div:first-child {
    display: block !important;
  }

  #left-menu svg {
    width: 18px;
    height: 18px;
  }

  #left-menu a > div:last-child,
  #left-menu button > div:last-child {
    font-size: 8.5px !important;
    line-height: 1.1;
    text-align: center;
    white-space: nowrap;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* ---------- 2. Felső sáv ---------- */
  div[class*="h-[80px]"][class*="bg-newBgColorInner"][class*="items-center"] {
    height: auto !important;
    min-height: 52px;
    padding-inline: 10px !important;
    gap: 8px;
  }

  div[class*="h-[80px]"] > div[class*="text-[24px]"] {
    font-size: 16px !important;
    flex: 0 1 auto !important;
    min-width: 0;
    overflow: hidden;
  }

  div[class*="gap-[20px]"][class*="text-textItemBlur"] {
    gap: 12px !important;
    flex: 0 0 auto !important;
    max-width: 62vw;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }

  div[class*="gap-[20px]"][class*="text-textItemBlur"] > * {
    flex: 0 0 auto !important;
  }

  /* ---------- 3. Fő panel: oszlopos elrendezés ---------- */
  div[class*="bg-newBgLineColor"] {
    overflow: visible !important;
  }

  div[class*="bg-newBgLineColor"] > div[class*="flex-1"][class*="gap-[1px]"] {
    flex-direction: column !important;
    min-width: 0 !important;
  }

  /* csatorna-oszlop -> teljes szélesség, normál folyamban
     (nyitott w-[260px] és összecsukott .sidebar állapotban egyaránt) */
  div[class*="relative"][class*="flex-col"]:has(> div[class*="absolute"][class*="bg-newBgColorInner"]) {
    width: 100% !important;
    min-width: 0 !important;
    flex: 0 0 auto !important;
    height: auto !important;
  }

  div[class*="relative"][class*="flex-col"]:has(> div[class*="absolute"][class*="bg-newBgColorInner"]) > div[class*="absolute"] {
    position: static !important;
    width: 100% !important;
    height: auto !important;
    max-height: 38vh;
    padding: 12px !important;
  }

  /* Elemzések oldal keskeny csatorna-oszlopa -> teljes szélességű, tördelt sor */
  div[class*="sidebar"][class*="w-[100px]"][class*="bg-newBgColorInner"] {
    width: 100% !important;
    flex: 0 0 auto !important;
    padding: 12px !important;
  }

  div[class*="sidebar"][class*="w-[100px]"][class*="bg-newBgColorInner"] > div[class*="flex-col"] {
    flex-direction: row !important;
    flex-wrap: wrap !important;
    gap: 10px !important;
  }

  div[class*="sidebar"][class*="w-[100px]"][class*="bg-newBgColorInner"] div[class*="group/profile"] {
    width: auto !important;
    justify-content: flex-start !important;
  }

  /* mobilon az összecsukott mód is teljes értékű listaként jelenjen meg */
  div[class*="sidebar"] div[class*="group-[.sidebar]:mx-auto"] {
    margin-inline: 0 !important;
    width: 100% !important;
  }

  div[class*="sidebar"] div[class*="group-[.sidebar]:flex-col"] {
    flex-direction: row !important;
    flex-wrap: wrap !important;
  }

  div[class*="sidebar"] div[class*="group-[.sidebar]:hidden"] {
    display: block !important;
  }

  /* gombok teljes szélességben */
  div[class*="relative"][class*="flex-col"]:has(> div[class*="absolute"][class*="bg-newBgColorInner"]) div[class*="group-[.sidebar]:block"] {
    flex-direction: column !important;
    width: 100%;
  }

  div[class*="relative"][class*="flex-col"]:has(> div[class*="absolute"][class*="bg-newBgColorInner"]) button {
    width: 100% !important;
  }

  /* ---------- 4. Naptár ---------- */
  div[class*="bg-newBgColorInner"][class*="p-[20px]"][class*="gap-[12px]"] {
    padding: 10px !important;
    min-width: 0 !important;
  }

  /* eszköztár sor törhessen */
  div[class*="flex-grow"][class*="flex-row"][class*="gap-[10px]"] {
    flex-wrap: wrap !important;
    row-gap: 8px;
    justify-content: center;
  }

  /* heti nézet rácsa: olvasható oszlopszélesség + vízszintes görgetés */
  div[class*="grid-template-columns:136px"] {
    grid-template-columns: 52px repeat(7, minmax(92px, 1fr)) !important;
    min-width: max-content;
  }

  /* havi nézet: a napnevek ne csússzanak egymásra a keskeny oszlopokban */
  div[class*="grid-cols-7"] > div[class*="bg-newTableHeader"] {
    height: 40px !important;
    padding: 2px !important;
    overflow: hidden;
  }

  div[class*="grid-cols-7"] > div[class*="bg-newTableHeader"] * {
    font-size: 9px !important;
    line-height: 1.15 !important;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* az abszolút pozicionált rács szülője kapjon magasságot */
  div[class*="flex-1"][class*="relative"]:has(> div[class*="grid-template-columns"]) {
    min-height: 62vh;
  }

  /* ---------- 4b. Legördülő menük (a JS inline left-et számol, kifutna) ---------- */
  div[class*="shadow-menu"][class*="fixed"] {
    left: auto !important;
    inset-inline-start: auto !important;
    right: 8px !important;
    max-width: calc(100vw - 16px) !important;
    max-height: 60vh !important;
    overflow-y: auto !important;
    white-space: normal !important;
  }

  /* ---------- 5. Modálok (bejegyzés szerkesztő) ---------- */
  /* a modál az alsó navigációs sáv fölött érjen véget */
  div[class*="bg-popup"] {
    height: calc(100% - 54px) !important;
  }

  div[class*="bg-popup"] div[class*="p-[40px]"] {
    padding: 6px !important;
  }

  div[class*="bg-popup"] div[class*="w-[580px]"] {
    width: 100% !important;
    min-width: 0 !important;
  }

  /* kétoszlopos szerkesztő -> egymás alá */
  div[class*="bg-popup"] div[class*="flex-1"]:has(> div[class*="w-[580px]"]) {
    flex-direction: column !important;
  }

  div[class*="bg-popup"] div[class*="border-e"] {
    border-inline-end: 0 !important;
    border-bottom: 1px solid var(--new-border, rgba(0, 0, 0, .1));
  }

  /* görgethető belső panelek ne essenek 0 magasságba */
  div[class*="bg-popup"] div[class*="flex-1"][class*="relative"]:has(> div[class*="absolute"][class*="overflow-y-scroll"]) {
    min-height: 340px;
  }

  /* modál fejlécek kerekítése/magassága */
  div[class*="bg-popup"] div[class*="h-[65px]"] {
    height: auto !important;
    min-height: 48px;
    font-size: 16px !important;
    padding-inline: 12px !important;
  }

  /* alsó gombsor törhessen, ne csússzon ki */
  div[class*="h-[84px]"][class*="border-t"] {
    height: auto !important;
    flex-wrap: wrap !important;
    gap: 8px;
    padding: 10px !important;
  }

  div[class*="h-[84px]"][class*="border-t"] > div {
    padding-inline: 0 !important;
    flex-wrap: wrap !important;
    justify-content: flex-start !important;
    flex: 1 1 100% !important;
    gap: 8px !important;
  }

  /* minden vezérlő teljes szélességben, könnyen nyomhatóan */
  div[class*="h-[84px]"][class*="border-t"] > div > * {
    flex: 1 1 100% !important;
    width: 100% !important;
    min-width: 0 !important;
    margin-inline: 0 !important;
  }

  /* ---------- 6. AI segéd buborék ne takarja a gombokat ---------- */
  .copilotKitPopup {
    z-index: 8000 !important;
    bottom: 62px !important;
    top: auto !important;
  }

  /* szerkesztő modál közben ne takarja a Közzététel gombot */
  div[class*="bg-popup"] .copilotKitPopup {
    display: none !important;
  }

  .copilotKitWindow {
    max-width: 96vw !important;
    max-height: 66vh !important;
    bottom: 122px !important;
  }

  /* ---------- 7. Általános túlcsordulás-védelem ---------- */
  div[class*="bg-newBgLineColor"] img,
  div[class*="bg-popup"] img {
    max-width: 100%;
  }
}
