/**
 * SmartPresence — Global responsive utilities
 * Covers tenant app, superadmin, public pages, and shared components.
 */

/* ─── Base & overflow ─────────────────────────────────────────────── */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  overflow-x: hidden;
}

img,
video,
canvas,
svg {
  max-width: 100%;
  height: auto;
}

/* ─── Sidebar overlay (mobile) ────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 999;
  opacity: 0;
  transition: opacity 0.3s ease;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

body.sidebar-open-mobile .sidebar-overlay {
  display: block;
  opacity: 1;
}

body.sidebar-open-mobile {
  overflow: hidden;
}

/* ─── Content area spacing ────────────────────────────────────────── */
@media (max-width: 991.98px) {
  #content {
    padding: 16px 12px 0 !important;
    margin-left: 0 !important;
    width: 100% !important;
  }

  #sidebar {
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25);
  }

  #sidebar.active ~ #content {
    margin-left: 0 !important;
    width: 100% !important;
  }

  .content {
    padding: 1rem !important;
    margin-left: 0 !important;
  }

  .content.active {
    margin-left: 0 !important;
  }

  .navbar .container-fluid {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .navbar .flex-grow-1.justify-content-center {
    order: 3;
    width: 100%;
    margin: 0.25rem 0 0 !important;
    flex-grow: 1 !important;
  }

  .navbar h5 {
    font-size: 0.95rem !important;
  }
}

@media (max-width: 575.98px) {
  .navbar .container-fluid > .d-flex.align-items-center.flex-grow-1 {
    display: none !important;
  }

  .navbar .container-fluid {
    flex-wrap: nowrap !important;
    justify-content: space-between;
  }

  .navbar .container-fluid > .d-flex.align-items-center:first-child {
    flex: 1;
    min-width: 0;
  }

  .navbar .dropdown {
    flex-shrink: 0;
  }
}

@media (max-width: 575.98px) {
  #content {
    padding: 12px 8px 0 !important;
  }

  .card-body {
    padding: 1rem !important;
  }

  .card-header {
    padding: 0.85rem 1rem !important;
  }

  .btn {
    padding: 0.45rem 0.85rem;
    font-size: 0.875rem;
  }

  h1, .h1 { font-size: 1.65rem; }
  h2, .h2 { font-size: 1.4rem; }
  h3, .h3 { font-size: 1.2rem; }
  h4, .h4 { font-size: 1.05rem; }

  .display-1 { font-size: 3.5rem; }
  .display-2 { font-size: 2.75rem; }
  .display-3 { font-size: 2.25rem; }
  .display-4 { font-size: 1.85rem; }
}

/* ─── Tables ──────────────────────────────────────────────────────── */
.table-responsive,
.table-responsive-auto {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
}

@media (max-width: 991.98px) {
  .card-body:not(.p-0):not(.no-scroll) {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .table {
    font-size: 0.85rem;
  }

  .table th,
  .table td {
    padding: 0.55rem 0.65rem;
    white-space: nowrap;
  }

  .table td.allow-wrap,
  .table th.allow-wrap {
    white-space: normal;
    min-width: 120px;
  }
}

/* ─── Forms & filters ─────────────────────────────────────────────── */
@media (max-width: 767.98px) {
  .row.g-3 > [class*="col"],
  .row.g-2 > [class*="col"],
  .row > [class*="col-md"],
  .row > [class*="col-lg"] {
    margin-bottom: 0.25rem;
  }

  .input-group,
  .form-control,
  .form-select {
    font-size: 16px; /* prevents iOS zoom on focus */
  }

  .d-flex.flex-wrap.gap-2,
  .d-flex.flex-wrap.gap-3,
  .btn-toolbar,
  .page-actions {
    gap: 0.5rem !important;
  }

  .page-actions .btn,
  .d-flex.gap-2 .btn {
    flex: 1 1 auto;
    min-width: 0;
  }
}

/* ─── Modals ──────────────────────────────────────────────────────── */
@media (max-width: 575.98px) {
  .modal-dialog {
    margin: 0.5rem;
    max-width: calc(100% - 1rem);
  }

  .modal-body {
    padding: 1rem;
  }
}

/* ─── Stats / KPI grids ───────────────────────────────────────────── */
@media (max-width: 767.98px) {
  .stats-bar {
    flex-direction: column;
  }

  .stats-bar-item {
    width: 100%;
  }

  .row-cols-md-2 > *,
  .row-cols-md-3 > *,
  .row-cols-md-4 > *,
  .row-cols-lg-3 > *,
  .row-cols-lg-4 > * {
    flex: 0 0 100%;
    max-width: 100%;
  }
}

/* ─── Chat interface ──────────────────────────────────────────────── */
@media (max-width: 767.98px) {
  .chat-container {
    height: calc(100vh - 180px);
    max-height: none;
  }

  .message-wrapper {
    max-width: 88%;
  }

  .chat-header,
  .chat-input-area {
    padding: 1rem;
  }
}

/* ─── Footer ──────────────────────────────────────────────────────── */
@media (max-width: 575.98px) {
  .footer-links {
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem;
  }

  .footer-container .d-flex.align-items-center {
    flex-direction: column;
    text-align: center;
  }

  .footer-logo {
    margin-right: 0 !important;
    margin-bottom: 0.35rem;
  }
}

/* ─── Public / landing pages ──────────────────────────────────────── */
@media (max-width: 767.98px) {
  .d-flex.justify-content-between.align-items-center.mb-4,
  .d-flex.justify-content-between.align-items-center.mb-3 {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 0.75rem;
  }

  .d-flex.justify-content-between.align-items-center.mb-4 .btn,
  .d-flex.justify-content-between.align-items-center.mb-3 .btn {
    width: 100%;
  }
}
  section[class*="py-24"],
  section[class*="py-20"] {
    padding-top: 5rem !important;
    padding-bottom: 3rem !important;
  }

  .text-5xl,
  .text-6xl,
  .text-7xl {
    font-size: 2rem !important;
    line-height: 1.2 !important;
  }

  .text-4xl {
    font-size: 1.75rem !important;
  }

  .text-3xl {
    font-size: 1.5rem !important;
  }
}

/* ─── Video / camera feeds ────────────────────────────────────────── */
.video-container,
.camera-feed,
.detect-video-wrap,
#videoElement,
#webcam,
.live-feed-container {
  max-width: 100%;
  width: 100%;
}

video {
  width: 100%;
  object-fit: contain;
}

/* ─── Utility helpers ─────────────────────────────────────────────── */
@media (max-width: 767.98px) {
  .hide-mobile {
    display: none !important;
  }

  .stack-mobile {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  .stack-mobile > * {
    width: 100% !important;
    max-width: 100% !important;
  }

  .text-truncate-mobile {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
  }
}

@media (min-width: 768px) {
  .hide-desktop {
    display: none !important;
  }
}

/* ─── Touch targets ───────────────────────────────────────────────── */
@media (pointer: coarse) {
  .btn:not(.btn-sm):not(.btn-link),
  .navbar .nav-link,
  .dropdown-item,
  #sidebarToggle,
  #sidebarCollapse {
    min-height: 44px;
  }

  #sidebar ul li a,
  .sidebar .nav-link {
    min-height: 44px;
    display: flex;
    align-items: center;
  }
}

/* ─── Print ───────────────────────────────────────────────────────── */
@media print {
  #sidebar,
  .sidebar,
  .navbar,
  .sidebar-overlay,
  .footer,
  .btn,
  #sidebarToggle,
  #sidebarCollapse {
    display: none !important;
  }

  #content,
  .content {
    margin-left: 0 !important;
    width: 100% !important;
    padding: 0 !important;
  }
}
