/* v203: iPhone layouts. Load after the component and design-system sheets.
   Wide data tables and the seven-day calendar scroll inside their own frame. */
#app .ic-mobile-scroll-hint { display: none; }
@media (max-width: 800px) {
  #app.shell, #app.shell.sidebar-collapsed { overflow-x: visible; }
  #app main, #app #content, #app .heading > div,
  #app .panel, #app .card, #app .field,
  #app .dash-card, #app .insv2-section { min-width: 0; }
  #app main {
    padding: 18px max(12px, env(safe-area-inset-right))
      max(24px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }
  #app .top {
    padding-top: max(10px, env(safe-area-inset-top)) !important;
    padding-left: max(12px, env(safe-area-inset-left)) !important;
    padding-right: max(12px, env(safe-area-inset-right)) !important;
  }
  #app .sidebar {
    padding-top: max(18px, env(safe-area-inset-top)) !important;
    padding-bottom: max(18px, env(safe-area-inset-bottom)) !important;
  }
  #app button, #auth button, #dialog button, .social-cal-drawer button {
    min-height: 44px;
    touch-action: manipulation;
  }
  #app #toggleSidebar {
    flex-basis: 44px !important; width: 44px !important;
    min-width: 44px !important; height: 44px !important;
  }
  #app .topcontrols {
    flex-basis: 44px !important; width: 44px !important; min-width: 44px !important;
  }
  #app #profileAvatar {
    flex-basis: 44px !important; width: 44px !important;
    height: 44px !important; max-width: 44px !important;
  }
  #app .artist-picker { min-height: 44px; }
  /* 16px prevents Safari's automatic focus zoom on editable controls. */
  #app input, #app select, #app textarea,
  #auth input, #auth select, #auth textarea,
  #dialog input, #dialog select, #dialog textarea,
  .social-cal-drawer input, .social-cal-drawer select, .social-cal-drawer textarea {
    font-size: 16px !important; min-width: 0; max-width: 100%;
  }
  #app input:not([type=checkbox]):not([type=radio]), #app select,
  #auth input:not([type=checkbox]):not([type=radio]),
  #dialog input:not([type=checkbox]):not([type=radio]), #dialog select,
  .social-cal-drawer select { min-height: 44px; }
  #app input[type=file], #dialog input[type=file] { width: 100%; }
  #app textarea, #dialog textarea { width: 100%; resize: vertical; }
  #app summary, #dialog summary {
    min-height: 44px; padding-top: 11px; padding-bottom: 11px;
  }
  #app .tablewrap, #app .curator-table-scroll,
  #app .social-cal-scroll, #app .kpi-viewport, #app .gig-carousel,
  #dialog .tablewrap {
    min-width: 0; max-width: 100%; overflow-x: auto;
    overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch;
  }
  /* Compact tables fit naturally; dense matrices retain their component sizing. */
  #app .tablewrap td, #dialog .tablewrap td { overflow-wrap: anywhere; }
  #app .ic-mobile-scroll-hint { display: block; margin: 0 0 10px; }
  #app .budget-tabs, #app .insv2-tabs, #app .insv8-drill-tabs,
  #app .social-performance-tabs, #app .ic-tabs,
  #app .social-cal-view-switch, #dialog .row:has(> [data-builder-step]) {
    max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch; flex-wrap: nowrap;
  }
  #app .budget-tabs > button, #app .insv2-tabs > button,
  #app .insv8-drill-tabs > button, #app .social-performance-tabs > button,
  #app .ic-tabs > button, #app .social-cal-view-switch > button,
  #dialog .row:has(> [data-builder-step]) > button { flex: 0 0 auto; }
  #app .heading h1 { font-size: clamp(23px, 6vw, 29px); overflow-wrap: anywhere; }
  #app .heading > .actions { width: 100%; justify-content: flex-start; }
  #app .heading > .actions button { flex: 1 1 120px; }
  #app main > .ic-workspace-header { gap: 14px; padding-bottom: 18px; margin-bottom: 20px; }
  #app #workspaceDescription { font-size: 13px; line-height: 1.6; margin-top: 8px; }
  #app .row > *, #app .toolbar > *, #app .filters > * { min-width: 0; }
  #app .row, #app .toolbar, #app .filters { gap: 10px; }
  #app .panel p, #app .taskname, #app .taskdetails,
  #app .dash-show-detail, #app .social-sync-platform p,
  #dialog p, #dialog h2 { overflow-wrap: anywhere; }
  #app .task-campaign-filters select, #app .today-owner-wrap select {
    width: 100%; max-width: 100%;
  }
  #app .insight-history-chart { max-width: 100%; }
  #app .insight-history-chart svg { max-width: 100%; height: auto; }
  #app .social-nav-bar .social-toolbar { margin-left: 0; }
  #app .social-cal-redesign .social-cal-card {
    min-height: 44px; padding-top: 9px; padding-bottom: 9px;
  }
  #app .social-cal-redesign .social-cal-title { font-size: 12px; }
  #app .social-cal-redesign .social-cal-time { font-size: 11px; }
  #app .social-cal-filter-group { min-width: 0; width: 100%; }
  #app .social-cal-filter-group label { flex: 1 1 180px; min-width: 0; }
  #app .social-cal-filter-group label select { flex: 1; min-width: 0; }
  #app .social-cal-navigation, #app .social-cal-view-switch { flex-wrap: wrap; }
  .social-cal-drawer {
    width: min(480px, 100%); padding: max(16px, env(safe-area-inset-top))
      max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom))
      max(16px, env(safe-area-inset-left));
    overscroll-behavior: contain;
  }
  .social-cal-drawer-top > button { min-width: 44px; flex-shrink: 0; }
  .social-cal-drawer-meta, .social-cal-drawer-actions { flex-wrap: wrap; }
  .social-cal-drawer-actions > button { flex: 1 1 140px; }
  #dialog.modal {
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    overscroll-behavior: contain;
  }
  #dialog .dialog {
    min-width: 0; width: 100%; max-width: 100%; padding: 18px;
    max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px);
    overflow: auto; overscroll-behavior: contain;
  }
  #dialog .modal-top-close { min-width: 44px; width: 44px; height: 44px; }
  #dialog .grid, #dialog .curator-form-grid { grid-template-columns: minmax(0, 1fr); }
  #dialog .grid > .full { grid-column: 1; }
  #dialog .actions { gap: 10px; }
  #dialog .actions > button { flex: 1 1 120px; white-space: normal; }
  /* Smart Link font/size controls use a legacy inline two-column grid. */
  #dialogBody div[style*="grid-template-columns:minmax(0,2fr)"] {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  #auth.auth { margin: 24px 12px; max-width: 470px; padding: 20px; }
  #auth .brand-logo { max-width: 100%; height: auto; }
  #auth .actions { gap: 10px; }
  #auth .actions > button { flex: 1 1 130px; }
  #app .legal-footer a, #auth .legal-footer a {
    display: inline-flex; align-items: center; min-height: 44px;
  }
  #message { top: max(12px, env(safe-area-inset-top)); right: 12px; max-width: calc(100vw - 24px); }
  /* Keep the desktop workspace rhythm without spending phone width on nested padding. */
  #app[data-workspace="insights"] .insv2-section { padding: 16px; }
  #app[data-workspace="insights"] :is(.insv2-kpis, .insv2-drivers, .insv4-recs) { gap: 12px; }
  #app[data-workspace="insights"] :is(.insv2-driver, .insv4-rec) { padding: 16px; }
  #app[data-workspace="curators"] .curator-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  #app[data-workspace="curators"] .curator-stats > div { padding: 16px; }
  #app[data-workspace="social"] :is(.social-library-section, .social-composer-section) { padding: 16px; }
  #app[data-workspace="social"] .social-library-section .cards { grid-template-columns: repeat(auto-fill, minmax(min(100%, 235px), 1fr)); }
  #app[data-workspace="social"] .social-composer-section .grid { gap: 16px; }
  /* Native table roles and data-labels keep one directory DOM accessible while
     each phone row becomes a readable card with full-width actions. */
  #app[data-workspace="smartlinks"] #smartLinkRows .smart-link-table { border: 0; overflow: visible; }
  #app[data-workspace="smartlinks"] #smartLinkRows .smart-link-table table {
    display: block; width: 100%; min-width: 0; table-layout: auto;
  }
  #app[data-workspace="smartlinks"] #smartLinkRows .smart-link-table thead {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    clip-path: inset(50%); overflow: hidden; white-space: nowrap;
  }
  #app[data-workspace="smartlinks"] #smartLinkRows .smart-link-table tbody { display: grid; gap: 14px; }
  #app[data-workspace="smartlinks"] #smartLinkRows .smart-link-table tr {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(70px, .45fr);
    padding: 5px; border: 1px solid var(--ic-border); border-radius: 12px; background: var(--ic-input);
  }
  #app[data-workspace="smartlinks"] #smartLinkRows .smart-link-table td {
    display: block; min-width: 0; width: auto; padding: 12px; border-bottom: 0;
  }
  #app[data-workspace="smartlinks"] #smartLinkRows .smart-link-table td::before {
    content: attr(data-label); display: block; margin-bottom: 7px;
    color: var(--ic-muted); font-size: 11px; font-weight: 650; letter-spacing: .025em;
  }
  #app[data-workspace="smartlinks"] #smartLinkRows .smart-link-table td:first-child {
    grid-column: 1 / -1; border-bottom: 1px solid var(--ic-border);
  }
  #app[data-workspace="smartlinks"] #smartLinkRows .smart-link-table .smart-link-actions {
    grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px;
    border-top: 1px solid var(--ic-border); margin-top: 4px;
  }
  #app[data-workspace="smartlinks"] #smartLinkRows .smart-link-table .smart-link-actions::before { width: 100%; margin-bottom: 0; }
  #app[data-workspace="smartlinks"] #smartLinkRows .smart-link-table .smart-link-actions button {
    flex: 1 1 100px; margin: 0; padding: 10px; white-space: normal;
  }
}

@media (max-width: 480px) {
  #app .panel { padding: 14px; }
  #app:is([data-workspace="today"], [data-workspace="tasks"], [data-workspace="upcoming"]) .task:not(.subtask) { padding: 13px; gap: 9px; }
  #app:is([data-workspace="today"], [data-workspace="tasks"], [data-workspace="upcoming"]) .task-actions { padding-left: 0; }
  #app:is([data-workspace="today"], [data-workspace="tasks"], [data-workspace="upcoming"]) .subtask-group { margin-left: 16px; padding-left: 12px; }
  #app[data-workspace="tasks"] #content > .filters { padding: 13px; }
  #app .stats { gap: 10px; }
  #app .stat { padding: 12px; }
  #app .stat b { font-size: 26px; }
  #app .filters > * { flex-basis: 100%; }
  #app .task-campaign-filters label { flex-basis: 100%; }
  #app .today-owner-wrap, #app #todayCampaignFilters { width: 100%; }
  #app .task { flex-wrap: wrap; gap: 9px; }
  #app .taskbody { flex-basis: calc(100% - 42px); }
  #app .task-actions {
    flex-direction: row; flex-wrap: wrap; margin-left: 30px;
    width: calc(100% - 30px); max-width: calc(100% - 30px); min-width: 0;
  }
  #app .task-actions button { white-space: normal; }
  #app .task-menu-popover { left: 0; right: auto; }
  #app .task-default-row { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  #app .task-default-row select { width: 100%; }
  #app .release-tile { flex-basis: 100%; max-width: 100%; }
  #app .release-tile-main { gap: 12px; }
  #app .release-tile-art { width: 80px; height: 80px; }
  #app[data-workspace="releases"] :is(.release-tile, .gig-tile) { padding: 16px; gap: 16px; }
  #app[data-workspace="releases"] .release-tile-main { gap: 12px; }
  #app[data-workspace="releases"] .release-tile-art { width: 80px; height: 80px; }
  #app[data-workspace="releases"] .release-tile-copy h3 { font-size: 20px; }
  #app .release-tile-actions button { white-space: normal; }
  #app .dash-release-topline { flex-wrap: wrap; }
  /* Keep the release overview useful before a long page of milestones. */
  #app .dash-release-art {
    display: grid; grid-template-columns: 104px minmax(0, 1fr); align-items: center;
    gap: 12px; max-width: none; width: 100%; margin: 0;
  }
  #app .dash-release-art > img, #app .dash-release-art > .dash-no-art {
    width: 104px; height: 104px; min-height: 0;
  }
  #app .dash-release-art > .dash-no-art { padding: 10px; font-size: 12px; }
  #app .dash-release-art .dash-countdown { min-width: 0; margin: 0; padding: 12px 8px; }
  #app .dash-release-name { max-width: 100%; text-align: left; }
  #app .dash-card-heading { flex-wrap: wrap; gap: 10px; }
  #app .dash-card-heading > button { max-width: 100%; white-space: normal; }
  #app .budget-toolbar .budget-add-expense { margin-left: 0 !important; width: 100%; }
  #app .social-toolbar > .primary { width: 100%; white-space: normal; }
  #app .social-performance-grid { grid-template-columns: minmax(0, 1fr); }
  #app .social-cal-redesign .social-cal-hero { padding: 16px; }
  #app .social-cal-redesign .social-cal-metrics > div { padding: 13px; }
  #app .social-cal-redesign .social-cal-filter-group label {
    flex-basis: 100%; flex-direction: column; align-items: stretch;
  }
  #app .social-cal-redesign .social-cal-filters select { width: 100%; }
  #app .curator-stats { grid-template-columns: minmax(0, 1fr); }
  #app[data-workspace="curators"] .curator-stats { grid-template-columns: minmax(0, 1fr); gap: 9px; }
  #app[data-workspace="curators"] .curator-stats > div { padding: 13px 15px; }
  #app[data-workspace="curators"] :is(.curator-hero, .curator-toolbar, .curator-footer) { padding: 15px; }
  #app .curator-stats > div { flex-direction: row; align-items: center; justify-content: space-between; }
  #app .curator-toolbar { padding: 14px; }
  #app .curator-toolbar input { width: 100%; }
  #app .ai-preview-media-content { flex-wrap: wrap; }
  #app .ai-preview-post { padding: 13px; }
  #app .account-settings-grid p > button { margin-bottom: 8px; }
  #app[data-workspace="settings"] .account-settings-grid > .panel,
  #app[data-workspace="settings"] :is(.settings-team, .settings-integrations, .settings-backups, .settings-ai) { padding: 16px; }
  #app[data-workspace="settings"] .settings-team > .card { padding: 14px; }
  #app[data-workspace="dashboard"] .dash-card { padding: 16px; }
  #app[data-workspace="social"] :is(.social-library-section, .social-composer-section) { padding: 13px; }
  #app[data-workspace="social"] .social-library-section > .row > label { flex-basis: 100%; min-width: 0; }
  #app[data-workspace="budget"] .budget-expense-details > summary { padding: 15px; }
  #app[data-workspace="budget"] .budget-expense-details > :not(summary) { margin-left: 13px; margin-right: 13px; }
  #dialog .milestone-task { align-items: flex-start; flex-wrap: wrap; }
  #dialog .milestone-task small { margin-left: 30px; }
  #dialog .gig-summary { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 360px) {
  #app .stats, #app .social-cal-metrics, #app .insv2-platforms {
    grid-template-columns: minmax(0, 1fr);
  }
  #app .artist-picker-name { font-size: 12px !important; }
  #app .release-tile-main { flex-direction: column; }
  #dialog .dialog { padding: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  #app .sidebar { transition: none !important; }
}

/* Navigation shell regression guard: desktop header/sidebar geometry.
   Keep the navigation independent of dashboard and workspace content. */
@media (min-width: 801px) {
  #app.shell:not(.sidebar-collapsed):where(:not([hidden])) {
    display:grid !important;
    grid-template-columns:245px minmax(0,1fr) !important;
    grid-template-rows:auto minmax(0,1fr) !important;
  }
  #app.shell.sidebar-collapsed:where(:not([hidden])) {
    display:grid !important;
    grid-template-columns:72px minmax(0,1fr) !important;
    grid-template-rows:auto minmax(0,1fr) !important;
  }
  #app .layout { display:contents !important; }
  #app .sidebar {
    grid-column:1 !important;grid-row:1 / 3 !important;
    position:sticky !important;top:0 !important;
    width:100% !important;height:100vh !important;
    display:flex !important;flex-direction:column !important;
    align-items:stretch !important;gap:6px !important;
    overflow-x:hidden !important;overflow-y:auto !important;
    padding:18px 12px !important;
  }
  #app .sidebar .nav {width:100% !important;justify-content:flex-start !important;}
  #app.sidebar-collapsed .sidebar {padding:12px 7px !important;}
  #app.sidebar-collapsed .sidebar .nav {justify-content:center !important;}
  #app.sidebar-collapsed .sidebar .nav-label {display:none !important;}
  #app .top {
    grid-column:2 !important;grid-row:1 !important;
    display:flex !important;flex-direction:row !important;
    align-items:center !important;justify-content:space-between !important;
    flex-wrap:nowrap !important;min-height:72px !important;
    padding:12px 24px !important;margin:0 !important;
  }
  #app main {grid-column:2 !important;grid-row:2 !important;min-width:0 !important;}
  #app .top-left {display:flex !important;flex-direction:row !important;align-items:center !important;gap:14px !important;min-width:0 !important;}
  #app .topcontrols {display:flex !important;flex-direction:row !important;align-items:center !important;justify-content:flex-end !important;width:auto !important;margin-left:auto !important;}
}
#app .sidebar-brand {display:flex !important;align-items:center !important;justify-content:center !important;flex:0 0 auto !important;width:100% !important;max-height:84px !important;overflow:hidden !important;margin:0 0 20px !important;}
#app .sidebar-brand img {display:block !important;width:auto !important;max-width:100% !important;max-height:64px !important;height:auto !important;object-fit:contain !important;}
#app .artist-picker {display:flex !important;flex-direction:row !important;align-items:center !important;gap:9px !important;min-width:0 !important;min-height:44px !important;}
#app .artist-picker-name {display:block !important;flex:1 1 auto !important;min-width:0 !important;white-space:nowrap !important;overflow:hidden !important;text-overflow:ellipsis !important;}
#app #globalArtistHeadshot {flex:0 0 37px !important;width:37px !important;height:37px !important;object-fit:cover !important;}
#app .artist-chevron {flex:0 0 auto !important;}
#app .menu-frame-toggle {flex:0 0 44px !important;width:44px !important;height:44px !important;display:inline-flex !important;align-items:center !important;justify-content:center !important;}
@media (max-width:800px) {
  #app .sidebar-brand {max-height:76px !important;margin-bottom:12px !important;}
  #app .sidebar-brand img {max-height:54px !important;}
  #app .top-left {display:flex !important;align-items:center !important;min-width:0 !important;}
}
