/* ==========================================================================
   Responsive layer — loaded LAST so it can override the desktop rules in
   components.css without fighting specificity.

   Breakpoints:
     <= 1024px  narrow laptops / large tablets
     <=  860px  tablets — sidebar becomes an off-canvas drawer
     <=  640px  phones
   ========================================================================== */

/* --------------------------------------------------------------------------
   Shared: never let a horizontal overflow escape the viewport
   -------------------------------------------------------------------------- */
html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

/* Long ticket names, emails and URLs are the usual cause of sideways scroll. */
.ticket-card-title,
.project-nav-label,
.md-comment,
.attachment-row a {
  overflow-wrap: anywhere;
}

/* --------------------------------------------------------------------------
   <= 1024px
   -------------------------------------------------------------------------- */
@media (max-width: 1024px) {
  .search-container {
    max-width: 260px;
  }

  .brand-subtitle-text {
    display: none;
  }
}

/* --------------------------------------------------------------------------
   <= 860px — sidebar turns into a drawer
   -------------------------------------------------------------------------- */
.sidebar-toggle-btn {
  display: none;
}

.sidebar-backdrop {
  display: none;
}

@media (max-width: 860px) {
  .sidebar-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--surface-card);
    color: var(--ink);
    font-size: 17px;
    cursor: pointer;
  }

  .app-layout {
    display: block !important;
    height: auto !important;
    min-height: calc(100vh - 65px);
    overflow: visible !important;
  }

  /* Off-canvas: slid out of view rather than hidden, so it animates and stays
     in the accessibility tree only while open (see [hidden] handling in JS). */
  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 70;
    width: min(300px, 84vw);
    max-height: none;
    overflow-y: auto;
    transform: translateX(-105%);
    transition: transform var(--transition-normal);
    border-radius: 0;
    padding-top: 18px;
  }

  .app-sidebar.drawer-open {
    transform: translateX(0);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.28);
  }

  /* The collapse affordance is meaningless once it's a drawer. */
  .sidebar-collapse-btn {
    display: none;
  }

  .app-sidebar.collapsed {
    width: min(300px, 84vw);
    max-height: none;
    padding-left: 14px;
    padding-right: 14px;
  }

  .app-sidebar.collapsed .sidebar-title-text,
  .app-sidebar.collapsed .project-nav-label,
  .app-sidebar.collapsed .project-nav-count {
    display: revert;
  }

  .app-sidebar.collapsed .project-nav-item {
    justify-content: flex-start;
    padding: 10px 12px;
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 65;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-normal);
  }

  .sidebar-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
  }

  .board-main {
    width: 100%;
    padding-left: 0;
    padding-right: 0;
  }
}

/* --------------------------------------------------------------------------
   <= 640px — phones
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
  .glass-topbar {
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 12px;
    position: sticky;
    top: 0;
    z-index: 60;
  }

  /* Brand shrinks; search drops to its own full-width row underneath. */
  .glass-topbar > div:first-of-type {
    min-width: 0;
    flex: 1 1 auto;
  }

  .search-container {
    order: 10;
    flex: 1 0 100%;
    max-width: none;
  }

  /* Text buttons in the topbar become icon-sized to stop the row wrapping
     three times deep on a 360px screen. */
  .glass-topbar .btn-outline,
  .glass-topbar .btn-primary {
    padding: 8px 10px;
    font-size: 12px;
  }

  /* Dropdowns must never be wider than the screen. */
  .dropdown-menu {
    width: min(320px, calc(100vw - 24px)) !important;
    right: 0;
    left: auto;
    max-width: calc(100vw - 24px);
  }

  /* Every tap target gets a comfortable minimum. */
  .btn,
  .btn-icon,
  .avatar,
  .sidebar-toggle-btn,
  .project-nav-item {
    min-height: 40px;
  }

  .btn-sm {
    min-height: 32px;
  }

  /* Filters scroll sideways instead of stacking into a tall wall of selects. */
  .filter-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    padding-bottom: 6px;
  }

  .filter-bar select,
  .filter-bar .btn {
    flex: 0 0 auto;
  }

  .column {
    min-width: 88vw;
  }

  .board-columns {
    /* Let cards breathe right up to the screen edge while keeping snap points. */
    margin-inline: -12px;
    padding-inline: 12px;
  }

  #boardProjectTitle {
    font-size: 16px;
  }

  /* Bottom-sheet modal: give the body its own scroll so the header and footer
     stay put while a long description scrolls. */
  .modal-dialog {
    max-height: 92vh;
    display: flex;
    flex-direction: column;
  }

  .modal-body {
    overflow-y: auto;
    flex: 1 1 auto;
    -webkit-overflow-scrolling: touch;
  }

  .modal-footer {
    flex-wrap: wrap;
    gap: 8px;
    /* Clear of the iOS home indicator. */
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }

  .modal-footer .btn {
    flex: 1 1 auto;
  }

  /* Two-column form grids collapse to one. */
  .form-grid,
  .form-row {
    grid-template-columns: 1fr !important;
  }

  /* iOS zooms the page when a focused input's font-size is under 16px. */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="date"],
  input[type="number"],
  select,
  textarea {
    font-size: 16px;
  }

  .bulk-bar {
    flex-wrap: wrap;
    gap: 8px;
  }

  .toast-container {
    left: 12px;
    right: 12px;
    bottom: 12px;
  }

  .toast {
    max-width: none;
  }

  /* Tables and Data grids horizontal touch scroll */
  .table-wrap,
  .responsive-table {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    max-width: 100% !important;
  }

  .data-table {
    min-width: 580px;
  }

  /* SuperAdmin panels on mobile */
  .super-main {
    padding: 14px 10px 40px !important;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
  }

  .stat-card {
    padding: 14px 12px !important;
  }

  .stat-num {
    font-size: 22px !important;
  }

  .stat-label {
    font-size: 11px !important;
  }

  /* Auth / Login cards on mobile */
  .auth-container {
    padding: 16px 12px !important;
  }

  .auth-card,
  .platform-card {
    padding: 24px 18px !important;
    border-radius: var(--radius-lg) !important;
    width: 100% !important;
    max-width: 100% !important;
  }
}

/* --------------------------------------------------------------------------
   Very small phones
   -------------------------------------------------------------------------- */
@media (max-width: 380px) {
  .column {
    min-width: 92vw;
  }

  .glass-topbar .btn-outline {
    display: none;
  }
}

/* --------------------------------------------------------------------------
   Print — an occasionally useful way to hand a board to someone
   -------------------------------------------------------------------------- */
@media print {
  .glass-topbar,
  .app-sidebar,
  .filter-bar,
  .bulk-bar,
  .sidebar-backdrop,
  .toast-container {
    display: none !important;
  }

  .board-columns {
    display: block;
  }

  .column {
    break-inside: avoid;
    page-break-inside: avoid;
  }
}
