/**
 * InnoLab portal � tablet & phone layout fixes.
 * Loaded after styles.css; complements the 860px block in styles.css.
 */

@media (max-width: 900px) {
  html {
    -webkit-text-size-adjust: 100%;
  }

  /* Sidebar collapsed reserves 72px — use flex shell so workspace is always full width */
  body.portal-authenticated .portal-shell .app,
  body.portal-authenticated .portal-shell .app.sidebar-collapsed {
    display: flex;
    flex-direction: column;
    grid-template-columns: unset;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
  }

  body.portal-authenticated .portal-shell .app > .workspace {
    flex: 1 1 auto;
    order: 1;
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  body.portal-authenticated .portal-shell .sidebar {
    position: fixed;
    z-index: 130;
    width: min(280px, 88vw);
    transform: translateX(-105%);
  }

  body.portal-authenticated .portal-shell .workspace {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  body.portal-authenticated .workspace-panels,
  body.portal-authenticated .panel.studio-portal-panel.is-active {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  body:not(.portal-authenticated) .login-screen {
    padding: 0;
  }

  .login-panel {
    width: min(370px, 100%);
  }

  body.portal-authenticated,
  body.portal-authenticated .portal-shell,
  body.portal-authenticated .portal-shell .app {
    height: 100dvh;
    min-height: 100dvh;
    max-height: 100dvh;
  }

  body.portal-authenticated .portal-shell .workspace {
    min-width: 0;
    overflow-x: hidden;
  }

  body.portal-authenticated .topbar--with-site-nav {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  body.portal-authenticated .topbar--with-site-nav .topbar-main {
    width: 100%;
  }

  body.portal-authenticated .topbar--with-site-nav .site-header-nav {
    order: 3;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    justify-content: flex-start;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }

  body.portal-authenticated .topbar--with-site-nav .site-header-nav::-webkit-scrollbar {
    display: none;
  }

  body.portal-authenticated .topbar--with-site-nav .topbar-actions {
    order: 2;
    width: 100%;
    max-width: 100%;
    justify-content: flex-start;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  body.portal-authenticated .topbar--with-site-nav .topbar-actions::-webkit-scrollbar {
    display: none;
  }

  body.portal-authenticated .workspace-chrome .topbar {
    padding: 8px 10px;
    margin-bottom: 0;
  }

  body.portal-authenticated .panel:not(.immersive-panel).is-active {
    padding: 12px 14px max(28px, env(safe-area-inset-bottom));
  }

  .topbar h1 {
    font-size: clamp(1.2rem, 5vw, 1.65rem);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: min(72vw, 20rem);
  }

  .topbar .eyebrow {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: min(72vw, 20rem);
  }

  .mobile-nav-toggle {
    flex-shrink: 0;
    min-width: 40px;
    min-height: 40px;
    align-items: center;
    justify-content: center;
  }

  .sync-pill,
  .session-pill {
    flex-shrink: 0;
  }

  .hero-card {
    padding: 18px 16px;
  }

  .hero-card h2 {
    font-size: clamp(1.35rem, 5vw, 2rem);
  }

  .section-head {
    gap: 10px;
  }

  .section-head .ghost,
  .section-head .primary,
  .section-head button {
    flex-shrink: 0;
  }

  /* DAM hub */
  .dam-hub-shell {
    padding: 14px 12px 20px;
    gap: 14px;
  }

  .dam-hub-title {
    font-size: 1.35rem;
  }

  .dam-hub-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .dam-hub-toolbar-actions {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .dam-hub-search {
    min-width: 0;
    width: 100%;
  }

  .dam-btn-new-library {
    width: 100%;
    text-align: center;
    justify-content: center;
  }

  .dam-hub-grid {
    grid-template-columns: repeat(1, minmax(0, 1fr));
    gap: var(--space-4);
  }

  .dam-hub-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .dam-hub-search {
    max-width: none;
  }

  .dam-hub-controls-end {
    margin-left: 0;
    width: 100%;
  }

  .dam-hub-sort {
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
  }

  .dam-hub-sort-chips {
    flex-wrap: wrap;
  }

  /* DAM browse */
  .dam-workspace-header,
  .studio-workspace-header {
    flex-direction: column;
    align-items: stretch;
  }

  .dam-workspace-nav {
    flex: 1 1 auto;
    width: 100%;
  }

  .dam-workspace-breadcrumb {
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }

  .dam-workspace-tabs {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    width: 100%;
    -webkit-overflow-scrolling: touch;
  }

  .dam-workspace-tab {
    flex-shrink: 0;
  }

  .dam-toolbar-primary,
  .dam-toolbar-secondary {
    flex-direction: column;
    align-items: stretch;
  }

  .dam-toolbar-primary .studio-toolbar-search,
  .studio-toolbar-search {
    min-width: 0;
    max-width: none;
    width: 100%;
    flex: 1 1 100%;
  }

  .dam-content-subtabs {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
  }

  .dam-content-subtab {
    flex-shrink: 0;
  }

  .dam-toolbar-actions {
    flex-wrap: wrap;
    width: 100%;
    justify-content: flex-start;
  }

  .dam-browse-panel-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .dam-folder-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 148px), 1fr));
    gap: 10px;
  }

  .dam-folder-card {
    min-height: 160px;
  }

  .studio-toolbar {
    padding: 8px 10px;
  }

  .studio-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding: 0 10px;
    -webkit-overflow-scrolling: touch;
  }

  .studio-tab {
    flex-shrink: 0;
    padding: 10px 12px;
    font-size: 0.8rem;
  }

  .studio-tab-panel {
    padding: 10px 12px 14px;
  }

  .dam-workspace.studio-workspace:not(.dam-workspace--hub) .studio-context-sidebar {
    max-height: 38vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .dam-workspace.studio-workspace:not(.dam-workspace--hub) {
    grid-template-rows: auto minmax(0, 1fr);
  }

  /* Asset detail overlay */
  .dam-asset-detail {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(38vh, 1fr) minmax(0, 52vh);
    height: 100dvh;
    min-height: 100dvh;
  }

  .dam-asset-detail-sidebar {
    border-left: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    overflow: auto;
  }

  .dam-asset-detail-preview {
    padding: 44px 12px 12px;
  }

  .dam-asset-detail-media img,
  .dam-asset-detail-media iframe,
  .dam-asset-detail-video {
    max-height: calc(42vh - 48px);
  }

  /* Guidelines / brand portal � horizontal mode rail */
  .guidelines-workspace.studio-workspace,
  .brand-portal-workspace.studio-workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .guidelines-mode-rail,
  .brand-portal-mode-rail,
  .studio-mode-rail {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 8px 10px;
    min-height: auto;
    max-height: none;
    -webkit-overflow-scrolling: touch;
  }

  .guidelines-mode-rail button,
  .brand-portal-mode-rail button,
  .studio-mode-rail button {
    flex-shrink: 0;
  }

  .guidelines-publish-bar-inner {
    flex-direction: column;
    align-items: flex-start;
  }

  .guidelines-publish-bar-link {
    margin-left: 0;
  }

  .guidelines-tools-grid {
    grid-template-columns: 1fr;
  }

  .brand-portal-workspace-top {
    padding: 12px 14px 0;
  }

  .brand-portal-workspace-scroll {
    padding: 12px 14px 20px;
  }

  /* Access hub & wide tables */
  .access-hub-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .access-hub-toolbar-l,
  .access-hub-toolbar-r {
    width: 100%;
  }

  .access-hub-search {
    min-width: 0;
    width: 100%;
  }

  .access-hub-split.is-preview-open {
    grid-template-columns: 1fr;
  }

  .access-hub-preview {
    width: 100%;
    max-width: none;
    position: relative;
    inset: auto;
  }

  /* Modals & drawers (anchored menus only — sheets use dam-p8-overlays.css) */
  .studio-popover:not(.dam-overlay-sheet),
  .dam-popover:not(.dam-overlay-sheet) {
    left: max(12px, env(safe-area-inset-left)) !important;
    right: max(12px, env(safe-area-inset-right)) !important;
    width: auto !important;
    max-width: none;
  }

  .activity-drawer {
    left: 8px;
    right: 8px;
    top: auto;
    bottom: max(8px, env(safe-area-inset-bottom));
    max-width: none;
    width: auto;
  }

  .commercial-actions-panel,
  .approval-filter-row {
    width: 100%;
  }

  .two-col > *,
  .form-grid > * {
    min-width: 0;
  }
}

@media (max-width: 480px) {
  .dam-hub-grid {
    grid-template-columns: 1fr;
  }

  .dam-asset-grid,
  .dam-virtual-window {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dam-folder-grid {
    grid-template-columns: 1fr 1fr;
  }

  .guidelines-hub-chapter-grid {
    grid-template-columns: 1fr;
  }

  .profile-groups {
    grid-template-columns: 1fr;
  }

  .topbar-actions .sync-pill#liveToggle {
    padding-left: 8px;
    padding-right: 8px;
  }

  .action-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .brand-preview-surface {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .brand-preview-logo {
    margin: 0 auto;
  }

  .brand-preview-promise {
    flex-direction: column;
    align-items: flex-start;
  }

  .dam-upload-meta-grid {
    grid-template-columns: 1fr;
  }

  .dam-upload-meta-grid .span-2 {
    grid-column: auto;
  }

  .dam-upload-modal .portal-modal-panel.dam-upload-modal-panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    transform: none;
    width: 100%;
    max-width: 100%;
    max-height: min(92dvh, 760px);
    border-radius: 18px 18px 0 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
  }

  .dam-upload-modal .portal-modal-backdrop {
    background: rgba(27, 24, 20, 0.56);
  }
}
