/* ==========================================================================
   ThinkNCollab - Universal Responsive Design System (Unified & Safe)
   Breakpoints: Mobile (<= 576px), Tablet (<= 992px), Laptop (<= 1200px), Desktop (> 1200px)
   ========================================================================== */

/* ── Universal Smooth Box-Sizing & Viewport Guards ── */
*, *::before, *::after {
  box-sizing: border-box;
}

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

/* ── Universal Media Guards (Safe, Non-Destructive to IFrames & Canvases) ── */
img {
  max-width: 100%;
}
img:not([height]) {
  height: auto;
}
video, svg {
  max-width: 100%;
}

/* ── Universal Logo 5:8 Aspect Ratio Standard (612x373 Natural Ratio) ── */
.logo img,
.nav-logo img,
.sb-logo img,
.brand-title img,
.gh-logo img,
.brand img,
.brand-icon img,
.footer-logo img,
.fb-logo img {
  height: 28px !important;
  width: auto !important;
  max-height: 28px !important;
  aspect-ratio: 612 / 373 !important;
  object-fit: contain !important;
  border-radius: 4px !important;
  flex-shrink: 0 !important;
  display: inline-block !important;
}

/* ── Universal Mobile Sidebar Drawer & Backdrop ── */
.mob-sidebar-toggle {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 8px;
  background: var(--surface2, #1e1e2f);
  border: 1px solid var(--border, rgba(255, 255, 255, 0.1));
  color: var(--text, #ffffff);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  z-index: 100;
  margin-bottom: 12px;
  transition: all 0.2s ease;
}
.mob-sidebar-toggle:hover {
  background: var(--greens, rgba(0, 255, 136, 0.1));
  color: var(--green, #00ff88);
}

.mob-sidebar-overlay, .nav-overlay, .sb-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 10000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.mob-sidebar-overlay.active, .mob-sidebar-overlay.show,
.nav-overlay.active, .nav-overlay.show,
.sb-overlay.active, .sb-overlay.show {
  display: block !important;
  opacity: 1 !important;
  pointer-events: auto !important;
}

/* ── Responsive Data Tables Wrapper ── */
.table-responsive, .table-wrap, .table-container, .inv-table-wrap, .data-table-wrap, .table-box, .custom-table-wrap {
  width: 100% !important;
  max-width: 100% !important;
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch !important;
  margin-bottom: 1rem;
}
.table-responsive table, .inv-table-wrap table, .data-table-wrap table {
  min-width: 600px;
}

/* ── Global Adaptive Grid Layouts ── */
.grid-auto-fit {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}
.grid-auto-fill {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

/* ==========================================================================
   LAPTOP & SMALL DESKTOP BREAKPOINT (max-width: 1200px)
   ========================================================================== */
@media (max-width: 1200px) {
  .room-grid {
    grid-template-columns: 280px 1fr !important;
    gap: 16px !important;
  }
  .dash-grid {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 14px !important;
  }
  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)) !important;
    gap: 14px !important;
  }
  .devops-grid, .server-grid, .pipeline-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 14px !important;
  }
  .branch-drawer-panel {
    width: 340px !important;
    max-width: 48% !important;
  }
}

/* ==========================================================================
   TABLET LANDSCAPE & COMPACT LAPTOPS (max-width: 1024px)
   ========================================================================== */
@media (max-width: 1024px) {
  .dash-grid, .stats-grid, .grid-4, .grid-3 {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px !important;
  }
  .devops-summary-cards {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  .board-canvas {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  .terminal-wrap {
    height: calc(100vh - 120px) !important;
    min-height: 480px !important;
  }
  .status-page .status-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ==========================================================================
   TABLET PORTRAIT & MOBILE (max-width: 992px)
   ========================================================================== */
@media (max-width: 992px) {
  .mob-toggle, .sb-toggle, .mob-sidebar-toggle {
    display: inline-flex !important;
  }

  /* ── Unified Mobile Sidebar Drawer ── */
  body {
    grid-template-columns: 1fr !important;
  }
  body.with-sidebar {
    padding-left: 0 !important;
  }
  .sidebar, aside.sidebar, .workspace-sidebar {
    position: fixed !important;
    top: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 280px !important;
    max-width: 85vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    z-index: 10001 !important;
    background: var(--bg2, #0a0b12) !important;
    border-right: 1px solid var(--border2, rgba(255, 255, 255, 0.15)) !important;
    box-shadow: 10px 0 40px rgba(0, 0, 0, 0.7) !important;
    transform: translateX(-100%) !important;
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1) !important;
    display: flex !important;
    flex-direction: column !important;
  }
  .sidebar.mobile-open, .sidebar.open, .sidebar.mob-open, .sidebar.show, .sidebar.active,
  aside.sidebar.mobile-open, aside.sidebar.open, aside.sidebar.mob-open, aside.sidebar.show, aside.sidebar.active,
  .workspace-sidebar.mobile-open, .workspace-sidebar.open, .workspace-sidebar.mob-open {
    transform: translateX(0) !important;
  }

  /* ── Main Workspace Containers ── */
  .workspace, .dash, .app-layout {
    display: flex !important;
    flex-direction: column !important;
    min-height: auto !important;
    padding: 0 !important;
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden !important;
  }
  .main, main, .main-content, .content {
    width: 100% !important;
    max-width: 100vw !important;
    padding: 14px 12px !important;
    margin-left: 0 !important;
    overflow-x: hidden !important;
  }

  /* ── Page Header & Action Toolbars ── */
  .page-header {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 12px !important;
    margin-bottom: 16px !important;
  }
  .page-header .ph-actions, .header-actions, .toolbar-actions {
    width: 100% !important;
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
    justify-content: flex-start !important;
  }
  .page-header .ph-btn {
    flex: 1 1 auto;
    min-width: 0;
  }

  /* ── Chat & Team Rooms ── */
  .chat-wrap {
    height: calc(100vh - 120px);
    height: calc(100dvh - 120px);
    min-height: 460px;
    position: relative !important;
    border-radius: 10px !important;
  }
  .chat-head {
    padding: 8px 12px !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
  }
  .chat-head-r {
    width: 100% !important;
    justify-content: space-between !important;
    gap: 6px !important;
  }
  .chat-online-pill {
    display: none !important;
  }
  .chat-msgs {
    padding: 12px 10px !important;
  }
  .chat-msg-row {
    gap: 8px !important;
  }
  .msg-avatar {
    width: 30px !important;
    height: 30px !important;
  }
  .chat-input-wrap {
    padding: 6px 8px !important;
  }
  .chat-input-container {
    padding: 6px 8px !important;
  }

  /* ── Fullscreen Thread Drawer on Mobile ── */
  .branch-drawer-panel {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    z-index: 99999 !important;
    border-left: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }

  /* ── DevOps Wall, CI/CD & Active Servers ── */
  .devops-grid, .server-grid, .pipeline-grid, .devops-summary-cards {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  .pipeline-stage-row {
    flex-direction: column !important;
    align-items: stretch !important;
  }
  .stage-connector {
    width: 2px !important;
    height: 20px !important;
    margin: 4px auto !important;
  }
  .server-telemetry-row {
    flex-direction: column !important;
    gap: 8px !important;
  }

  /* ── Terminal & Shell Users ── */
  .terminal-wrap, .cli-window {
    height: calc(100vh - 120px) !important;
    min-height: 420px !important;
    border-radius: 8px !important;
  }
  .terminal-head {
    padding: 8px 12px !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
  }
  .shell-users-grid {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }
  .shell-user-card {
    padding: 12px !important;
  }

  /* ── Kanban Board & Timelines ── */
  .board-header {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
  }
  .board-filter-bar {
    flex-wrap: wrap !important;
    gap: 6px !important;
  }
  .board-scroll, .board-columns-wrap, .board-columns {
    display: flex !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    gap: 12px !important;
    padding-bottom: 12px !important;
  }
  .board-scroll .col, .board-col, .board-column {
    min-width: 80vw !important;
    max-width: 85vw !important;
    scroll-snap-align: start;
    flex-shrink: 0 !important;
  }

  /* ── Status & Notification Center ── */
  .status-header {
    flex-direction: column !important;
    text-align: center !important;
    gap: 10px !important;
  }
  .uptime-pill-row {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px !important;
  }
  .notif-center-wrap {
    grid-template-columns: 1fr !important;
  }

  /* ── Grids & Card Metrics ── */
  .stats-grid, .dash-grid, .grid-2, .grid-3, .grid-4, .cards-grid {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }
}

/* ==========================================================================
   SMALL SMARTPHONES (max-width: 480px)
   ========================================================================== */
@media (max-width: 480px) {
  .ph-title {
    font-size: 1.25rem !important;
  }
  .card-body, .card {
    padding: 12px !important;
  }
  .chat-wrap {
    height: calc(100vh - 120px) !important;
    height: calc(100dvh - 120px) !important;
    min-height: 400px !important;
    border-radius: 8px !important;
  }
  .chat-head-sub {
    display: none !important;
  }
  .chat-input-tools {
    gap: 4px !important;
  }
  .chat-tool-icon-btn {
    width: 26px !important;
    height: 26px !important;
    font-size: 0.72rem !important;
  }
  .auth-card, .login-box, .signup-box {
    width: 100% !important;
    padding: 20px 14px !important;
    border-radius: 12px !important;
  }
}
