/* Layout (RC1.3 QC experience): vertical sidebar on the left, everything else on the right.
   The sidebar contains the primary navigation (8 destinations) and the project summary.
   The content area: a thin topbar, optional sub-tabs, then the screen.
   Screens: canvas (Maquette › Vue 3D), plans (the plan page), document (calm cards that scroll).
   The inspector is a sheet that exists only while something is selected.
   NO rail, NO multi-bar header stack, NO permanent columns around the 3D view. */
.shell {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: var(--topbar-h) auto minmax(0, 1fr);
  grid-template-areas:
    "sidebar topbar"
    "sidebar subtabs"
    "sidebar work";
  overflow: hidden;
  background:
    radial-gradient(820px 420px at 86% 0%, #2f80ed1a, transparent 64%),
    radial-gradient(680px 360px at 4% 8%, #0fafa41a, transparent 62%),
    var(--bg-0);
}

/* ── Sidebar: the ONE navigation column ──────────────────────────────────── */
.sidebar {
  grid-area: sidebar;
  grid-row: 1 / -1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg-2) 88%, transparent);
  backdrop-filter: blur(12px);
}

/* ── Topbar: positioned at the top of the content area ───────────────────── */
.topbar { grid-area: topbar; z-index: 20; }

/* ── Sub-tabs row ────────────────────────────────────────────────────────── */
.subtabs { grid-area: subtabs; margin: 0 24px; }

/* ── Workspace: the active screen ────────────────────────────────────────── */
.workspace { grid-area: work; position: relative; min-width: 0; min-height: 0; margin: 0 24px 18px; outline: none; }

/* The screen banner (head) is inside the workspace, first child */
.screen-banner { margin-bottom: 12px; }
.screen-banner:empty { display: none; }

/* Without a model the screen is the welcome hero in the stage: nothing else shows. */
.shell[data-model="false"] .subtabs, .shell[data-model="false"] .panel, .shell[data-model="false"] .drawer { display: none; }
.shell[data-model="false"] .screen-banner { display: none; }
.shell[data-model="false"] .stage { position: relative; display: block; height: 100%; overflow-y: auto; }
.shell[data-model="false"] .viewer-host { display: none; }
.shell[data-model="false"] .stage-ui { position: relative; inset: auto; min-height: 100%; }

/* ── The screen: a scrolling stack of cards (document) ─────────────────── */
.shell[data-model="true"] .workspace { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr); overflow-y: auto; overscroll-behavior: contain; }
.panel { min-width: 0; min-height: 0; }
.panel-body { display: grid; gap: var(--s-4); align-content: start; padding: 0 0 var(--s-6); }
.stage { display: none; }
.drawer { display: none; }
/* The canvas stays mounted on every screen (it is never re-created); off the 3D screen it is only hidden. */
.shell[data-model="true"] .stage { position: absolute; display: block; width: 0; height: 0; overflow: hidden; visibility: hidden; }
.toasts { position: fixed; right: 24px; bottom: 18px; z-index: 45; display: grid; justify-items: end; gap: var(--s-2); max-width: min(420px, 80vw); pointer-events: none; }
.toasts > * { pointer-events: auto; }

/* ── Canvas screen: the viewer takes ~80% of the space, tree docks as overlay ── */
.shell[data-layout="canvas"][data-model="true"] .workspace { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); overflow: hidden; border-radius: var(--r-3); }
.shell[data-layout="canvas"][data-model="true"] .panel { position: absolute; top: 0; left: 0; z-index: 10; display: flex; flex-direction: column; width: var(--panel-w); max-height: 100%; overflow: hidden; border-right: 1px solid var(--line); border-radius: var(--r-3) 0 0 var(--r-3); background: color-mix(in srgb, var(--bg-1) 96%, transparent); backdrop-filter: blur(10px); box-shadow: var(--shadow-1); }
.shell[data-layout="canvas"][data-tree="closed"] .panel { display: none; }
.shell[data-layout="canvas"][data-model="true"] .stage { position: relative; grid-column: 1; grid-row: 1 / -1; width: auto; height: auto; overflow: hidden; visibility: visible; border: 1px solid var(--line); border-radius: var(--r-3); box-shadow: var(--shadow-1); }
.shell[data-layout="canvas"] .panel-body { display: flex; flex: 1 1 auto; flex-direction: column; min-height: 0; gap: 0; padding: 0; }
.shell[data-layout="canvas"] .capability-panel { display: none; }
.shell[data-layout="canvas"] .screen-banner { display: none; }

/* ── Plans screen: levels left, the sheet right ────────────────────────── */
.shell[data-layout="plans"][data-model="true"] .workspace { overflow: hidden; border: 1px solid var(--line); border-radius: var(--r-3); background: var(--bg-1); box-shadow: var(--shadow-1); }
.shell[data-layout="plans"] .panel { overflow: hidden; display: flex; flex-direction: column; }
.shell[data-layout="plans"] .panel-body { display: flex; flex: 1 1 auto; flex-direction: column; min-height: 0; padding: 0; gap: 0; }
.shell[data-layout="plans"] .capability-panel { display: none; }
.shell[data-layout="plans"] .screen-banner { display: none; }

/* ── Table pages: the list IS the screen (Éléments, Qualité IFC) ─────── */
.shell[data-table="page"][data-model="true"] .workspace { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr); overflow: hidden; gap: var(--s-3); }
.shell[data-table="page"][data-view="explore"][data-model="true"] .workspace { grid-template-columns: 300px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
.shell[data-table="page"] .panel { overflow-y: auto; }
.shell[data-table="page"] .drawer { display: flex; flex-direction: column; min-height: 0; overflow: hidden; border: 1px solid var(--line); border-radius: var(--r-3); background: var(--bg-1); box-shadow: var(--shadow-1); }
.shell[data-table="page"][data-view="explore"] .drawer { grid-column: 2; grid-row: 1; }
.shell[data-table="page"] .drawer-toggle { display: none; }
.shell[data-table="page"] .screen-banner { display: none; }

/* ── Inspector: a sheet that exists only while something is selected ────── */
.inspector { grid-area: work; z-index: 30; justify-self: end; display: none; flex-direction: column; width: min(380px, 100%); min-height: 0; margin: 0 24px 18px 0; overflow: hidden; border: 1px solid var(--line); border-radius: var(--r-3); background: var(--bg-1); box-shadow: var(--shadow-2); }
.inspector[data-open="true"] { display: flex; animation: sheet-in var(--dur-2) var(--ease); }
.shell:has(.inspector[data-open="true"]) .workspace { margin-right: calc(24px + 380px + 12px); }
@keyframes sheet-in { from { transform: translateX(12px); opacity: 0; } to { transform: none; opacity: 1; } }

/* The viewer host: the canvas paints the studio itself; this is only its first-frame backdrop. */
.viewer-host { position: absolute; inset: 0; background: var(--stage-bg); border-radius: inherit; }
.viewer-host .viewer-canvas { display: block; width: 100%; height: 100%; }
.stage-ui { position: absolute; inset: 0; z-index: 31; pointer-events: none; }
.stage-ui > * { pointer-events: auto; }

/* ── Medium widths: the sidebar becomes a slide-over ─────────────────────── */
@media (max-width: 1180px) {
  .shell { grid-template-columns: 0 minmax(0, 1fr); }
  .shell .sidebar { position: fixed; top: 0; bottom: 0; left: 0; z-index: 35; width: min(280px, 88vw); box-shadow: var(--shadow-2); }
  .shell .sidebar { display: none; }
  .shell[data-side-pref="open"] .sidebar { display: flex; }
  .shell .workspace, .shell .subtabs { margin-left: 18px; margin-right: 18px; }
}

/* ── Narrow: one column, bottom sheet inspector ──────────────────────────── */
@media (max-width: 760px) {
  .shell { grid-template-rows: auto auto minmax(0, 1fr); }
  .shell .workspace, .shell .subtabs { margin-left: 8px; margin-right: 8px; }
  .shell[data-layout="canvas"][data-model="true"] .panel { width: 100%; max-height: 240px; position: relative; border-radius: var(--r-3) var(--r-3) 0 0; border-right: 0; border-bottom: 1px solid var(--line); }
  .shell[data-layout="canvas"][data-model="true"] .workspace { grid-template-rows: auto minmax(0, 1fr); }
  .shell[data-table="page"][data-view="explore"][data-model="true"] .workspace { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .shell[data-table="page"][data-view="explore"] .drawer { grid-column: 1; grid-row: 2; }
  .shell .inspector { position: fixed; top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 72dvh; margin: 0; border-radius: var(--r-3) var(--r-3) 0 0; }
  .shell:has(.inspector[data-open="true"]) .workspace { margin-right: 8px; }
}
