/* Rbuzzer Global Responsive Layer
 * Applied after page styles to normalize layouts on phones, tablets,
 * laptops, desktop monitors, landscape screens and safe-area devices.
 */
:root {
  --rbz-safe-top: env(safe-area-inset-top, 0px);
  --rbz-safe-right: env(safe-area-inset-right, 0px);
  --rbz-safe-bottom: env(safe-area-inset-bottom, 0px);
  --rbz-safe-left: env(safe-area-inset-left, 0px);
  --rbz-bottom-nav-h: 72px;
}

html {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: hidden;
  margin-left: 0;
  margin-right: 0;
}

*, *::before, *::after { box-sizing: border-box; }

/* Prevent flex/grid children from forcing horizontal overflow. */
.flex > *, .inline-flex > *, .grid > *, main, section, article, aside, nav, header, footer {
  min-width: 0;
}

img, picture, video, canvas, svg, iframe {
  max-width: 100%;
}
img, video { height: auto; }
iframe { width: 100%; }

pre, code, .break-responsive {
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
select,
textarea {
  max-width: 100%;
}

button, a, input, select, textarea {
  -webkit-tap-highlight-color: transparent;
}

/* Tables remain usable without breaking the entire page width. */
.overflow-x-auto {
  max-width: 100%;
  overflow-x: auto !important;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}
.overflow-x-auto > table { width: 100%; }
table { max-width: 100%; }
th, td { vertical-align: middle; }

/* Modal/dialog safety on short and narrow screens. */
[role="dialog"],
.modal-box,
[id*="modal" i] > .bg-white,
[id*="modal" i] .modal-box {
  max-width: calc(100vw - 24px) !important;
}
[id*="modal" i] {
  overscroll-behavior: contain;
}

/* Pagination should never collide with floating/bottom navigation. */
.pagination,
.rbz-pagination {
  max-width: 100%;
  padding-left: 4px;
  padding-right: 4px;
}
.pagination a,
.pagination span,
.rbz-pagination a,
.rbz-pagination span {
  flex: 0 0 auto;
}

/* Fixed bottom navigation: safe-area aware and stable on notched devices. */
.bottom-nav {
  padding-bottom: max(8px, var(--rbz-safe-bottom)) !important;
  padding-left: var(--rbz-safe-left) !important;
  padding-right: var(--rbz-safe-right) !important;
}
body.rbz-has-bottom-nav .content-padding {
  padding-bottom: calc(var(--rbz-bottom-nav-h) + 28px + var(--rbz-safe-bottom)) !important;
}

/* Toasts should not overflow narrow phones. */
.toast-container {
  max-width: min(380px, calc(100vw - 24px)) !important;
}

/* Keep floating support buttons above mobile navigation. */
body.rbz-has-bottom-nav .floating-buttons {
  bottom: calc(var(--rbz-bottom-nav-h) + 26px + var(--rbz-safe-bottom)) !important;
}

/* Small phones: 320–479px */
@media (max-width: 479px) {
  :root { --rbz-bottom-nav-h: 70px; }

  body { font-size: 14px; }

  /* 16px prevents unwanted iOS form zoom while preserving layout. */
  input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
  select,
  textarea { font-size: 16px !important; }

  h1 { font-size: clamp(1.35rem, 7vw, 1.85rem) !important; line-height: 1.2 !important; }
  h2 { font-size: clamp(1.15rem, 6vw, 1.55rem) !important; line-height: 1.25 !important; }
  h3 { line-height: 1.3 !important; }

  .content-padding {
    padding-left: 12px !important;
    padding-right: 12px !important;
  }

  .bottom-nav {
    gap: 0 !important;
  }
  .bottom-nav a {
    flex: 1 1 0 !important;
    min-width: 0 !important;
    padding: 5px 2px !important;
    font-size: 8px !important;
    line-height: 1.1 !important;
    white-space: nowrap;
  }
  .bottom-nav a i {
    font-size: 17px !important;
    margin-bottom: 2px !important;
  }

  .pagination {
    gap: 6px !important;
    margin-bottom: 18px !important;
  }
  .pagination a,
  .pagination span {
    min-width: 38px !important;
    height: 38px !important;
    padding-left: 9px !important;
    padding-right: 9px !important;
    font-size: 12px !important;
  }

  /* Tailwind-style pagination rows used by advertiser/admin. */
  .justify-center.gap-2:has(> a[href*="page="]),
  .justify-center.gap-2:has(> a[href*="_page="]) {
    max-width: 100%;
    overflow-x: auto;
    justify-content: flex-start !important;
    padding: 4px 2px 16px;
    scrollbar-width: none;
  }

  .toast-container {
    left: 12px !important;
    right: 12px !important;
    top: calc(68px + var(--rbz-safe-top)) !important;
    width: auto !important;
  }

  /* Support buttons: compact enough not to cover cards/pagination. */
  body.rbz-has-bottom-nav .fixed.bottom-24.right-3 {
    bottom: calc(var(--rbz-bottom-nav-h) + 26px + var(--rbz-safe-bottom)) !important;
    right: 10px !important;
  }

  table th, table td {
    padding-left: 10px;
    padding-right: 10px;
  }
}

/* Phones and small tablets */
@media (max-width: 767px) {
  body.rbz-has-bottom-nav {
    padding-bottom: calc(var(--rbz-bottom-nav-h) + var(--rbz-safe-bottom));
  }

  .content-padding {
    padding-top: 16px !important;
  }

  .overflow-x-auto > table:not(.rbz-mobile-native-table) {
    min-width: 620px;
  }

  /* Actions and filter bars can wrap instead of overflowing. */
  form.flex,
  .filter-bar,
  .action-bar,
  .toolbar {
    flex-wrap: wrap;
  }

  .stat-card {
    min-width: 0 !important;
  }

  /* Full-screen overlays respect safe areas and mobile browser UI. */
  .fixed.inset-0 {
    padding-top: max(12px, var(--rbz-safe-top));
    padding-bottom: max(12px, var(--rbz-safe-bottom));
  }
}

/* Tablet portrait/landscape: use the roomy mobile drawer until 1024px.
   This prevents a 220–260px desktop sidebar from squeezing the main content. */
@media (min-width: 768px) and (max-width: 1023px) {
  #mobile-menu-btn { display: inline-flex !important; }
  #mobile-sidebar { display: flex !important; }
  #menu-backdrop { display: block !important; }
  .bottom-nav { display: flex !important; }

  /* Only direct desktop sidebar blocks in dashboard shells. */
  .content-padding > .flex > .hidden.md\:block,
  .content-padding > .hidden.md\:block,
  .max-w-7xl > .flex > .hidden.md\:block {
    display: none !important;
  }

  body.rbz-has-bottom-nav .content-padding {
    padding-bottom: calc(var(--rbz-bottom-nav-h) + 30px + var(--rbz-safe-bottom)) !important;
  }
}

/* Medium laptop sizes */
@media (min-width: 1024px) and (max-width: 1279px) {
  .content-padding { gap: 20px !important; }
  .stat-card { padding: 0.9rem !important; }
}

/* Very wide displays: keep readable line lengths, no stretching. */
@media (min-width: 1536px) {
  .max-w-7xl { max-width: 1400px !important; }
}

/* Landscape phones / low-height screens. */
@media (max-height: 560px) and (orientation: landscape) {
  #mobile-sidebar { overflow-y: auto; }
  .bottom-nav a { min-height: 46px !important; }
  [id*="modal" i] > .bg-white,
  .modal-box { max-height: calc(100vh - 24px) !important; overflow-y: auto !important; }
}

/* Reduced motion preference. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Rbuzzer dashboard-specific final overrides */
@media (max-width: 1023px) {
  body.rbz-has-bottom-nav .pagination:last-child,
  body.rbz-has-bottom-nav .pagination-info:last-child {
    margin-bottom: 20px !important;
  }
}

/* Keep long page ranges compact; JS retains first/current/last navigation. */
.pagination { display: flex !important; flex-wrap: nowrap !important; align-items: center; justify-content: center; gap: 5px; max-width: 100%; overflow-x: auto; padding: 3px 2px; }
.pagination > a, .pagination > span { flex: 0 0 auto; min-width: 36px; min-height: 36px; display: inline-flex; align-items: center; justify-content: center; padding: 0 10px; }
.pagination .page-ellipsis { min-width: 22px; padding: 0 2px; color: #94a3b8; pointer-events: none; }
@media (max-width: 640px) { .pagination { gap: 3px; } .pagination > a, .pagination > span { min-width: 32px; min-height: 32px; padding: 0 7px; font-size: .78rem; } }

/* Compact history category tabs for Komentator. */
.history-filter-tabs { scrollbar-width: none; }
.history-filter-tabs::-webkit-scrollbar { display: none; }
.history-filter-tab { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 7px; padding: 9px 13px; border-radius: 999px; background: rgba(255,255,255,.76); border: 1px solid rgba(23,21,37,.1); color: #68647a; font-size: .82rem; font-weight: 700; text-decoration: none; transition: all .18s ease; }
.history-filter-tab:hover { color: #7c3aed; border-color: rgba(124,58,237,.28); transform: translateY(-1px); }
.history-filter-tab.active { color: #fff; background: linear-gradient(135deg,#7c3aed,#ec4899); border-color: transparent; box-shadow: 0 8px 18px rgba(124,58,237,.2); }
.history-filter-count { min-width: 21px; height: 21px; display: inline-flex; align-items: center; justify-content: center; padding: 0 6px; border-radius: 999px; background: rgba(124,58,237,.1); color: #7c3aed; font-size: .7rem; }
.history-filter-tab.active .history-filter-count { background: rgba(255,255,255,.22); color: #fff; }
@media (max-width: 640px) { .history-filter-tab { padding: 8px 11px; font-size: .76rem; } }
