/* Shared small-screen shell. Keep actions reachable instead of clipping overflow. */
@media (max-width: 1200px) {
  body .app {grid-template-columns:76px minmax(0,1fr)}
  body .sidebar {padding:18px 8px}
  body .sidebar .logo>div:nth-child(2), body .sidebar .nav-title,
  body .sidebar .nav button span, body .sidebar .side-card {display:none}
  body .sidebar .nav button {justify-content:center}
  body .sidebar .fd-help-entry{justify-content:center}
  body .sidebar .fd-help-entry span{display:none}
  body .main {min-width:0;padding:18px}
  #products .product-list-head, .fd-directory-head,
  .main .hero-actions, .main .top-actions {flex-wrap:wrap;min-width:0;gap:8px}
  #products .product-list-head>* {max-width:100%;min-width:0}
  #productCollectionTools {flex-shrink:1}
  #productCollectionTools .fd-collection-controls>div {flex-wrap:wrap}
  #productGrid.fd-collection-list>.catalog-card {grid-template-columns:110px minmax(0,1fr)}
  #productGrid.fd-collection-list .catalog-meta {grid-column:1/-1;justify-self:stretch;display:flex;flex-wrap:wrap;justify-content:flex-end}
  #customerList.fd-collection-list {max-width:100%;overflow-x:auto}
  #customerList.fd-collection-list>.crm-grid {min-width:700px}
}
@media (max-width: 700px) {
  body .app, body.merchant-rail-collapsed .app {display:block}
  body .sidebar {display:grid;grid-template-columns:repeat(4,minmax(0,1fr));position:relative;top:auto;height:auto;padding:8px 12px;gap:4px;border-bottom:1px solid var(--fd-line,#dfe5f3)}
  body .sidebar>.merchant-only {display:contents}
  body .sidebar .v1-rail-header {display:none}
  body .sidebar .nav {display:contents}
  body .sidebar .nav button {flex:0 0 auto;flex-direction:column;gap:4px;min-width:58px;min-height:48px;padding:6px;font-size:12px}
  body .sidebar .nav button span {display:block;font-size:11px}
  body .main {padding:12px;max-width:100%;min-width:0}
  .main .topbar {height:auto;flex-wrap:wrap}
  .main .hero {gap:12px}
  .main .hero-actions {width:100%;justify-content:flex-start}
  .main .page-quota {flex:1 1 160px;min-width:160px;max-width:100%}
  .main .page-quota>span {white-space:nowrap}
  .main :is(.btn,.mini-btn), .fd-directory-head :is(button,select),
  #products .product-list-head :is(.btn,.mini-btn) {min-height:40px;height:auto}
  #products .product-list-head, .fd-directory-head {padding:12px;gap:10px;align-items:center}
  #products .product-list-head h1 {flex:1 0 100%;white-space:normal}
  #productNameSearch {width:100%;flex:1 0 100%;min-height:40px}
  .product-status-counts {flex-wrap:wrap;white-space:normal}
  #productCollectionTools {max-width:100%;flex:1 1 100%}
  #productCollectionTools .fd-collection-controls {flex-wrap:wrap}
  #products #productGrid.fd-collection-cards, #customerList.fd-collection-cards,
  #materialGrid.fd-collection-cards {grid-template-columns:minmax(0,1fr);padding:10px}
  #productGrid.fd-collection-list>.catalog-card {grid-template-columns:minmax(0,1fr);padding:12px;gap:10px}
  #productGrid.fd-collection-list .catalog-meta {grid-column:auto;justify-content:flex-start;gap:8px}
  #productGrid.fd-collection-list .actions {display:flex;flex-wrap:wrap;gap:6px}
  #productGrid .catalog-card :is(h3,p), #materialGrid .catalog-card h3 {min-width:0;overflow-wrap:anywhere}
  html #customerList.fd-collection-list>.crm-grid {min-width:0;grid-template-columns:minmax(0,1fr)!important;gap:10px;padding:14px}
  html #customerList.fd-collection-list>.customer-table-head {display:none!important}
  html #customerList.fd-collection-list>.customer-row>* {display:flex!important;grid-column:auto;grid-row:auto;justify-content:flex-start!important;text-align:left!important;max-width:100%;min-width:0}
  html #customerList.fd-collection-list .crm-card-details {flex-direction:column;gap:8px}
  html #customerList.fd-collection-list .crm-card-details>.crm-cell {display:flex;gap:8px;text-align:left;max-height:none;white-space:normal}
  #customerList.fd-collection-list .crm-cell {white-space:normal;max-height:none;overflow-wrap:anywhere}
  #customerList.fd-collection-list .crm-card-label {display:block;margin-right:8px}
  #customerList.fd-collection-list>.crm-grid>:last-child {position:static;box-shadow:none}
  #customerList.fd-collection-list .crm-status, #customerList.fd-collection-list .customer-project-picker {margin-inline:0}
  .fd-compact-directory .customer-stats {flex-wrap:wrap;gap:8px}
  .main .directory-toolbar, .main .directory-tools {flex-wrap:wrap;min-width:0}
  .main .directory-toolbar input, #materialSearchForm {width:100%;min-width:0}
  #materialSearchForm input {flex:1;min-width:0;width:auto}
  .fd-collection-pager {flex-wrap:wrap;gap:10px;padding:10px}
  .fd-collection-pager>div {max-width:100%;flex-wrap:wrap}
  .fd-collection-pager button {min-height:36px;height:auto}
  .main :is(.catalog-grid,.settings-grid,.dashboard,.client-shell) {grid-template-columns:minmax(0,1fr)}
  .main .customer-project-card {grid-template-columns:minmax(0,1fr)}
  .modal-mask {padding:10px}
  .modal-mask .modal {width:100%;max-width:100%;max-height:calc(100dvh - 20px)}
  .modal-mask .modal-body {max-height:calc(100dvh - 150px);overflow:auto}
  .modal-mask .form-grid {grid-template-columns:minmax(0,1fr)}
  .fd-ambient {display:none}
  html .route-node-dialog .action-tabs {flex-wrap:wrap!important;overflow:visible}
  html .route-node-dialog .action-tabs button {min-height:40px;padding:8px 10px}
}
/* AI becomes an overlay on compact screens; never squeeze the editor into 45vw. */
@media (max-width: 1000px) {
  html:root {--fd-ai-dock-width:min(420px,100vw)}
  html body.fd-ai-layout-host>#root {width:100%}
  html body:has(#platformGuidePanel.show) .main, html body:has(#tutorPanel.show) .c-main,
  html body.fd-ai-layout-host .c-main {margin-right:0}
  html body:has(#tutorPanel.show) #client iframe, html body.fd-ai-layout-host #client iframe {width:100%!important}
  html dialog.fd-ai-layout-host {width:100%!important;margin-right:0!important}
  html dialog.fd-ai-drawer {width:var(--fd-ai-dock-width);max-width:100vw;box-shadow:-12px 0 36px #20234726}
}
@media (max-width: 600px) {
  html:root {--fd-ai-dock-width:100vw}
  dialog.fd-ai-drawer, #platformGuidePanel.guide-panel, #tutorPanel.tutor-panel {height:100dvh;max-height:100dvh}
  .fd-ai-panel :is(.fd-ai-compose,.fd-ai-composer), .guide-compose {padding-bottom:max(12px,env(safe-area-inset-bottom))}
  .fd-ai-panel textarea, .guide-compose textarea {font-size:16px;min-height:80px;max-height:25dvh}
  .fd-ai-panel pre, .fd-ai-panel table {max-width:100%;overflow-x:auto}
  .fd-ai-panel, .fd-ai-scroll, .guide-messages {min-width:0;min-height:0}
}
