/* Responsive shell and touch layer. Loaded last so it can adapt the other sheets.
   Window sizes follow Material 3 window size classes; touch, type and safe-area rules follow
   the Material 3 (48dp) and Apple HIG (44pt) minimums.
     compact   < 600px     phones: top app bar, bottom navigation bar, modal drawer, bottom sheets
     medium    600-1023px  tablets in portrait, phones in landscape: navigation rail, modal drawer
     expanded  >= 1024px   tablets in landscape, laptops, desktops: persistent sidebar */
:root{--touch:44px;--nav-bar-h:64px;--rail-w:80px;--ease-emph:cubic-bezier(.2,0,0,1);
  --safe-top:env(safe-area-inset-top,0px);--safe-right:env(safe-area-inset-right,0px);--safe-bottom:env(safe-area-inset-bottom,0px);--safe-left:env(safe-area-inset-left,0px);
  -webkit-text-size-adjust:100%;text-size-adjust:100%}
html{-webkit-tap-highlight-color:transparent}
/* Route changes move focus to <main> for screen readers; it is not a control, so no ring. */
#main:focus{outline:none}

/* Icons */
.nav-svg{width:24px;height:24px;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round;flex:none}
.icon-btn{gap:7px}.icon-btn .nav-svg{width:20px;height:20px}

/* Shell */
.rail,.bottom-nav,.scrim,.top-logo{display:none}
.page{min-width:0}
.shell{grid-template-columns:248px minmax(0,1fr)}
.top-title{display:flex;align-items:center;gap:10px;min-width:0}
.top-title strong{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.top-actions{flex-wrap:nowrap}

/* Sidebar: six destinations, Discover, and the remaining tools behind one disclosure */
.sidebar .group a{min-height:36px}
.sidebar .nav-indicator{display:inline-grid;place-items:center;color:#c5b9ff}
.sidebar .nav-svg{width:19px;height:19px}
.sidebar .tools summary{list-style:none;cursor:pointer;display:flex;align-items:center;justify-content:space-between;border-radius:7px}
.sidebar .tools summary::-webkit-details-marker{display:none}
.sidebar .tools summary h2{padding-bottom:0}
.sidebar .tools summary::after{content:"";width:7px;height:7px;border-right:2px solid #bdb7d9;border-bottom:2px solid #bdb7d9;transform:rotate(45deg);margin:0 12px 3px 0;transition:transform .2s var(--ease-emph)}
.sidebar .tools[open] summary::after{transform:rotate(-135deg);margin-bottom:-3px}
.sidebar .tools[open] summary{margin-bottom:4px}
.sidebar .tools summary:hover h2{color:#fff}

/* Rail and bottom bar items share the Material 3 active indicator (pill behind the icon) */
.rail-item,.bottom-item{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:4px;border:0;background:none;color:var(--muted);font-size:.75rem;line-height:1.2;font-weight:600;letter-spacing:.01em;min-width:0;text-align:center}
.nav-indicator{display:grid;place-items:center;width:56px;height:32px;border-radius:16px;transition:background-color .2s var(--ease-emph)}
.rail-item[aria-current=page],.bottom-item[aria-current=page]{color:var(--ink)}
.rail-item[aria-current=page] .nav-label,.bottom-item[aria-current=page] .nav-label{font-weight:750}
.rail-item[aria-current=page] .nav-indicator,.bottom-item[aria-current=page] .nav-indicator{background:var(--tint);color:var(--accent)}
.rail-item:hover .nav-indicator,.bottom-item:active .nav-indicator,.rail-item:active .nav-indicator{background:color-mix(in srgb,var(--accent) 12%,transparent)}
.rail-item:focus-visible,.bottom-item:focus-visible{outline:0}
.rail-item:focus-visible .nav-indicator,.bottom-item:focus-visible .nav-indicator{outline:2px solid var(--accent);outline-offset:2px}

/* Graph node: two-line titles fit the 74px node instead of being clipped at the top */
.graph-node .node{padding-block:2px}
.graph-node .node strong{font-size:.84rem;line-height:1.18}
.graph-node .node small{display:block;font-size:.72rem;line-height:1.25;margin-top:2px}
.graph-node .node br{display:none}

@media (min-width:1024px) and (max-width:1199px){.shell{grid-template-columns:224px minmax(0,1fr)}}

/* Medium and compact: the sidebar becomes a modal navigation drawer */
@media (max-width:1023px){
  .sidebar{display:flex;position:fixed;top:0;bottom:0;left:0;z-index:11;width:min(320px,86vw);height:100dvh;
    padding:calc(19px + var(--safe-top)) 13px calc(19px + var(--safe-bottom)) max(13px,var(--safe-left));
    border-radius:0 16px 16px 0;box-shadow:0 16px 48px #0007;overscroll-behavior:contain;
    transform:translateX(-105%);visibility:hidden;transition:transform .3s var(--ease-emph),visibility 0s linear .3s}
  .nav-open .sidebar{transform:none;visibility:visible;transition:transform .35s var(--ease-emph)}
  .scrim{display:block;position:fixed;inset:0;z-index:10;border:0;padding:0;margin:0;background:#0d0c1f;opacity:0;pointer-events:none;transition:opacity .3s}
  .nav-open .scrim{opacity:.45;pointer-events:auto}
  body:has(.nav-open){overflow:hidden}
  .sidebar .group a,.sidebar .tools summary{min-height:48px;font-size:.94rem}
  .sidebar .group{gap:2px}
  .top{position:sticky;top:0;z-index:6}
}

/* Editor below expanded: canvas full width first, action library underneath as a wrapping grid */
@media (max-width:1023px){
  .context-layout .unified,.unified{grid-template-columns:minmax(0,1fr)}
  .context-layout .unified>*,.unified>*{grid-column:1/-1}
  .unified .editor-core{order:-1}
  .unified .palette{grid-template-columns:repeat(auto-fill,minmax(min(100%,220px),1fr));max-height:340px}
  .editor-toolbar label:last-child{margin-left:0}
}

/* Medium: navigation rail */
@media (min-width:600px) and (max-width:1023px){
  .shell{grid-template-columns:calc(var(--rail-w) + var(--safe-left)) minmax(0,1fr)}
  .rail{display:flex;flex-direction:column;align-items:center;gap:6px;position:sticky;top:0;height:100dvh;overflow-y:auto;z-index:7;
    padding:calc(12px + var(--safe-top)) 0 calc(12px + var(--safe-bottom)) var(--safe-left);background:var(--paper);border-right:1px solid var(--line)}
  .rail-item{width:var(--rail-w);min-height:56px;padding:0 0 4px}
  .rail-more{margin-bottom:14px}
  .top{padding-right:max(clamp(16px,3vw,36px),var(--safe-right))}
  .main{padding-right:max(clamp(14px,3vw,36px),var(--safe-right))}
}
@media (min-width:600px) and (max-width:1023px) and (max-height:520px){.rail{gap:0}.rail-item{min-height:48px}.rail-item .nav-indicator{height:28px}}

/* Compact: top app bar, bottom navigation bar, snackbar above it, bottom sheet for the context panel */
@media (max-width:599px){
  .shell{display:block;padding-bottom:calc(var(--nav-bar-h) + var(--safe-bottom))}
  .top{height:auto;min-height:calc(56px + var(--safe-top));gap:8px;padding:var(--safe-top) max(8px,var(--safe-right)) 0 max(16px,var(--safe-left));
    background:color-mix(in srgb,var(--paper) 90%,transparent);-webkit-backdrop-filter:blur(16px) saturate(1.5);backdrop-filter:blur(16px) saturate(1.5)}
  .top-logo{display:inline-grid;place-items:center;width:30px;height:30px;border-radius:9px;flex:none;color:#fff;background:linear-gradient(135deg,#8869f5,#4e3ac8)}
  .top-logo .flow-icon{width:18px;height:18px}
  .top-title strong{font-size:1.06rem}
  .top .pill{display:none}
  .top-actions{gap:0}
  .icon-btn .label{display:none}
  .icon-btn,.icon-btn:hover{width:var(--touch);min-height:var(--touch);padding:0;border-color:transparent;background:transparent;color:var(--ink);border-radius:50%}
  .icon-btn .nav-svg{width:22px;height:22px}
  .top .avatar{margin-left:4px}
  .bottom-nav{display:grid;grid-template-columns:repeat(5,minmax(0,1fr));position:fixed;left:0;right:0;bottom:0;z-index:7;
    height:calc(var(--nav-bar-h) + var(--safe-bottom));padding:0 var(--safe-right) var(--safe-bottom) var(--safe-left);
    background:color-mix(in srgb,var(--paper) 92%,transparent);-webkit-backdrop-filter:blur(16px) saturate(1.5);backdrop-filter:blur(16px) saturate(1.5);border-top:1px solid var(--line)}
  .bottom-item{padding:6px 0 8px}
  #notice{left:max(16px,var(--safe-left));right:max(16px,var(--safe-right));bottom:calc(var(--nav-bar-h) + var(--safe-bottom) + 12px);max-width:none;border-radius:8px;padding:14px 16px;box-shadow:0 6px 20px #0003}

  .main{padding:14px max(16px,var(--safe-right)) 28px max(16px,var(--safe-left))}
  .head{margin:8px 0 18px;gap:14px}
  .head>div:first-child{min-width:0}
  .head .actions{width:100%}
  .head .actions>.btn{flex:1 1 auto}
  .grid{gap:12px}
  .tabs{flex-wrap:nowrap;overflow-x:auto;scrollbar-width:none;margin-inline:-16px;padding-inline:16px;gap:0}
  .tabs::-webkit-scrollbar{display:none}
  .tabs a{flex:1 0 auto;justify-content:center}
  .chart-row{grid-template-columns:minmax(80px,1fr) 1.4fr 32px}

  /* Editor: one-row picker, no split-layout control on a phone, a taller canvas */
  .editor-toolbar>label:first-child{flex:1 1 100%}
  .editor-toolbar>label:first-child select{max-width:none;flex:1}
  .editor-toolbar label:has(#editor-layout){display:none}
  .graph{padding:10px}
  .viewport{min-height:min(56vh,440px);max-height:64vh;overscroll-behavior:contain}

  /* Context panel docks as a Material bottom sheet */
  #right-context[data-mode=drawer],#right-context[data-mode=floating]{left:0;right:0;top:auto;bottom:0;width:100%;height:min(86dvh,760px);max-height:none;border-radius:28px 28px 0 0;padding-bottom:var(--safe-bottom)}
  #right-context[data-mode=drawer]::before,#right-context[data-mode=floating]::before{content:"";display:block;flex:none;width:32px;height:4px;border-radius:2px;background:color-mix(in srgb,var(--muted) 45%,transparent);margin:10px auto 0}
}

/* Touch: 44px minimum targets, 16px form text (stops iOS zoom on focus) */
@media (pointer:coarse),(max-width:1023px){
  .btn{min-height:var(--touch);padding-inline:14px}
  .icon-btn{padding-inline:12px}
  input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]),select{min-height:var(--touch)}
  input,select,textarea{font-size:16px}
  input[type=checkbox],input[type=radio]{width:22px;height:22px;flex:none}
  .tabs a{display:inline-flex;align-items:center;min-height:48px;padding-inline:14px}
  .pick{min-height:52px}
  .context-icon{min-width:40px;min-height:40px}
  summary{min-height:var(--touch);display:list-item;padding-block:10px}
  .sidebar .tools summary{display:flex;padding-block:0}
}
@media (max-width:599px){.icon-btn{padding-inline:0}}

/* No sticky hover colours on touch screens; press feedback instead */
@media (hover:none){
  .btn:not(.primary):hover{border-color:var(--line);color:var(--ink)}
  .btn:not(.primary):active{background:color-mix(in srgb,var(--accent) 10%,var(--paper))}
  .primary:active{filter:brightness(1.12)}
  .group a:not([aria-current]):hover{background:none}
  .group a:active{background:#38315f}
  .graph-node:hover,.app-card:hover{box-shadow:var(--visual-shadow,var(--shadow))}
}

@media (prefers-reduced-motion:reduce){
  *,*::before,*::after{animation-duration:.01ms!important;animation-iteration-count:1!important;transition-duration:.01ms!important;scroll-behavior:auto!important}
}
