:root {
  --mobile-header-height: 58px;
  --sheet-radius: 18px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

.mobile-menu-button,
.canvas-fullscreen-button,
.capture-launch-button,
.project-nav-toggle,
.sidebar-backdrop,
.mobile-inspector-handle {
  display: none;
}

.toolbar-actions {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-left: auto;
}

.toolbar-action {
  min-width: 34px;
  height: 34px;
  border: 1px solid #dbe3ee;
  border-radius: 9px;
  background: rgba(255,255,255,.94);
  color: #475569;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 10px;
  font-size: 11px;
  font-weight: 700;
  box-shadow: 0 1px 2px rgba(15,23,42,.03);
}

.toolbar-action:hover { background: #f8fafc; border-color: #cbd5e1; color: #0f172a; }
.toolbar-action:focus-visible { outline: 3px solid rgba(37,99,235,.14); outline-offset: 1px; }
.toolbar-action__label { white-space: nowrap; }

.project-links {
  display: grid;
  gap: 5px;
}
.project-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px;
  border-radius: 9px;
  color: #475569;
  font-size: 11px;
  text-decoration: none;
}
.project-link:hover { background: #f1f5f9; color: #0f172a; }
.project-link small { color: #94a3b8; }

.canvas-fullscreen-button { display: block; }

body.canvas-fullscreen-fallback {
  overflow: hidden;
}
body.canvas-fullscreen-fallback .workspace {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: #fff;
}
body.canvas-fullscreen-fallback .workspace .toolbar {
  position: relative;
  z-index: 4;
}
body.canvas-fullscreen-fallback .sidebar,
body.canvas-fullscreen-fallback .inspector {
  display: none !important;
}
body.canvas-fullscreen-fallback .app-shell {
  display: block;
}
body.canvas-fullscreen-fallback .workspace {
  height: 100dvh;
  display: grid;
  grid-template-rows: var(--mobile-header-height) minmax(0,1fr);
}

.workspace:fullscreen,
.workspace:-webkit-full-screen {
  background: #fff;
  display: grid;
  grid-template-rows: var(--mobile-header-height) minmax(0,1fr);
}

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 214px minmax(0,1fr); }
  .inspector {
    position: fixed;
    top: 70px;
    right: 12px;
    bottom: 12px;
    width: min(340px, calc(100vw - 250px));
    z-index: 25;
    border: 1px solid #dbe3ee;
    border-radius: 14px;
    box-shadow: 0 20px 54px rgba(15,23,42,.18);
    transform: translateX(calc(100% + 28px));
    opacity: 0;
    pointer-events: none;
    transition: transform 220ms ease, opacity 180ms ease;
  }
  body.inspector-open .inspector {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
  }
  .toolbar-action__label { display: none; }
}

@media (max-width: 840px) {
  html, body, #app { min-height: 100%; height: 100%; }
  .app-shell { display: block; }
  .workspace {
    height: 100dvh;
    display: grid;
    grid-template-rows: var(--mobile-header-height) minmax(0,1fr);
  }
  .toolbar {
    min-width: 0;
    height: var(--mobile-header-height);
    padding: 8px 9px;
    gap: 7px;
  }
  .toolbar__left { min-width: 0; flex: 1; gap: 7px; }
  .toolbar__left > div { display: none; }
  .search-box { width: auto; flex: 1; min-width: 0; }
  .search-box kbd { display: none; }
  .toolbar__stats, .canvas-style-control { display: none !important; }
  .toolbar-actions { margin-left: 0; gap: 5px; }
  .toolbar-action { width: 36px; padding: 0; }
  .mobile-menu-button { display: inline-flex; }

  .sidebar {
    display: flex;
    position: fixed;
    inset: 0 auto 0 0;
    width: min(320px, 86vw);
    z-index: 80;
    border-right: 1px solid #dbe3ee;
    box-shadow: 16px 0 48px rgba(15,23,42,.18);
    transform: translateX(-105%);
    transition: transform 220ms cubic-bezier(.2,.8,.2,1);
    padding-top: max(18px, env(safe-area-inset-top));
    padding-bottom: max(18px, var(--safe-bottom));
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 70;
    border: 0;
    background: rgba(15,23,42,.35);
    backdrop-filter: blur(3px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease;
  }
  body.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }

  .inspector {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-height: min(76dvh, 720px);
    border: 1px solid #dbe3ee;
    border-radius: var(--sheet-radius) var(--sheet-radius) 0 0;
    padding: 28px 18px calc(20px + var(--safe-bottom));
    box-shadow: 0 -20px 55px rgba(15,23,42,.2);
    transform: translateY(105%);
    opacity: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  body.inspector-open .inspector { transform: translateY(0); }
  .mobile-inspector-handle {
    display: block;
    position: sticky;
    top: -20px;
    width: 42px;
    height: 4px;
    margin: -12px auto 14px;
    border-radius: 99px;
    background: #cbd5e1;
    z-index: 2;
  }

  .canvas-hint { display: none; }
  .canvas-legend {
    left: 8px;
    right: 52px;
    bottom: max(8px, var(--safe-bottom));
    overflow-x: auto;
    justify-content: flex-start;
    white-space: nowrap;
    scrollbar-width: none;
  }
  .canvas-controls { right: 8px; bottom: max(8px, var(--safe-bottom)); }
  .canvas-controls button { width: 38px; height: 36px; }

  .focus-nav { left: 8px !important; right: 8px !important; top: 8px !important; }
  .focus-breadcrumb { max-width: calc(100vw - 150px); overflow-x: auto; }
  .focus-count { display: none; }
  .focus-realm__detail {
    left: 10px !important;
    right: 10px !important;
    width: auto !important;
    bottom: max(12px, var(--safe-bottom)) !important;
    max-height: 33dvh;
    overflow-y: auto;
  }
  .focus-realm__hint { display: none; }
}

@media (max-width: 520px) {
  .capture-launch-button { display: inline-flex; }
  .toolbar-action.docs-link { display: none; }
  .search-box input { font-size: 12px; }
  .focus-node { width: 180px !important; min-height: 92px !important; }
  .focus-node p { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .inspector, .sidebar-backdrop { transition: none !important; }
}
