/* =====================================================================
   Noctra - Mobile layout (No Desktop Changes)
   Text/color fixes: static/css/mobile-text.css (loaded after page CSS)
   ===================================================================== */

@media (max-width: 768px) {
  html,
  body {
    height: auto;
    overflow: auto;
  }

  body {
    overflow-x: hidden;
  }

  .app-layout {
    flex-direction: column;
    height: auto;
    min-height: 100vh;
    padding-left: 0;
  }

  .app-main {
    min-height: 0;
    min-width: 0;
    margin-left: 0;
    width: 100%;
  }

  /* Sidebar as drawer */
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    width: 240px;
    min-width: 240px;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 40;
    border-right: 1px solid rgba(124, 92, 255, 0.18);
    border-bottom-right-radius: 16px;
    overflow: hidden;
  }

  body.mobile-sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar:hover {
    width: 240px;
    transform: translateX(0);
    box-shadow: none;
  }

  .sidebar::after {
    display: none;
  }

  .sidebar-header {
    height: 64px;
    justify-content: flex-start;
    padding: 0 16px;
  }

  .sidebar-nav {
    flex-direction: column;
    overflow-y: auto;
    padding: 8px 12px 16px;
    gap: 8px;
    max-height: calc(100vh - 72px);
  }

  .nav-item {
    padding: 12px 14px;
  }

  .nav-group.has-submenu > .nav-group-head::after {
    opacity: 0.72;
  }

  .nav-group.has-submenu.is-open > .nav-group-head::after {
    opacity: 0.95;
    transform: translateY(-50%) rotate(225deg);
  }

  .nav-group .nav-submenu {
    display: none;
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
    transform: translateY(-6px);
    border-left-color: rgba(124, 92, 255, 0);
  }

  .nav-group.has-submenu.is-open .nav-submenu {
    display: flex;
    max-height: 260px;
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
    border-left-color: rgba(124, 92, 255, 0.2);
  }

  .sidebar .label {
    display: inline;
    opacity: 1;
    transform: none;
    max-width: none;
    white-space: nowrap;
  }

  /* Backdrop overlay */
  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(5, 6, 9, 0.6);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 35;
  }

  body.mobile-sidebar-open .sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
  }

  /* Topbar */
  .topbar {
    margin-left: 0;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    padding: 0 16px;
    justify-content: space-between;
    position: relative;
  }

  .hamburger-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(0, 0, 0, 0.35);
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .topbar-center {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    pointer-events: none;
  }

  .topbar-logo-link {
    pointer-events: auto;
  }

  .topbar-logo {
    height: 32px;
  }

  .topbar-right {
    margin-left: auto;
  }

  .hamburger-btn svg {
    width: 18px;
    height: 18px;
  }

  .user-name-mobile {
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(124, 92, 255, 0.12);
    border: 1px solid rgba(124, 92, 255, 0.25);
    color: #E6E8EE;
    font-size: 0.85rem;
    font-weight: 600;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .app-content {
    padding: 16px;
    overflow: visible;
    min-height: 0;
    flex: 1 0 auto;
  }

  .section-card {
    padding: 16px;
  }

  .container-header {
    max-width: 100%;
    padding: 20px;
  }

  /* Global typography safety on mobile */
  input,
  select,
  textarea {
    font-size: 16px;
  }

  /* Dashboard grid */
  .dashboard-page .dashboard-grid,
  .analytics-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .dashboard-header .dashboard-meta {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .dashboard-meta-item {
    width: 100%;
  }

  .dashboard-project-filter .select,
  .dashboard-project-filter .select select {
    width: 100%;
    min-width: 100%;
  }

  .analytics-date-range {
    width: 100%;
    margin-left: 0;
    flex-wrap: wrap;
    gap: 8px;
  }

  .analytics-date-range input[type="date"] {
    width: 100%;
  }

  .mobile-only {
    display: block !important;
  }

  .sidebar .nav-item.mobile-only {
    display: flex !important;
  }

  .desktop-only {
    display: none !important;
  }

  /* Projects, Integrations, Links */
  .projects-grid,
  .marketplace-grid,
  .link-builder-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .topbar {
    height: auto;
    padding: 10px 14px;
  }

  .dashboard-page .dashboard-grid,
  .analytics-grid {
    grid-template-columns: 1fr !important;
  }
}

@media (max-width: 600px) {
  .dashboard-page .dashboard-grid,
  .analytics-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

@media (max-width: 320px) {
  .dashboard-page .dashboard-grid,
  .analytics-grid {
    grid-template-columns: 1fr !important;
  }
}
