/* Application shell: navigation rail, top bar, pages and three-panel workspaces. */

#app { height: 100%; }
.app { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); height: 100%; background: var(--bg-0); transition: grid-template-columns var(--dur-2) var(--ease); }
.app.rail-open { grid-template-columns: var(--rail-w-open) minmax(0, 1fr); }
/* The overlay host holds only fixed-position layers; it must not take a grid row of its own. */
.app > .overlays { display: contents; }

/* ── Rail ───────────────────────────────────────────────────────────────────── */
.rail { position: relative; z-index: 20; display: flex; flex-direction: column; height: 100%; min-height: 0; background: var(--rail-grad); box-shadow: inset -1px 0 0 var(--line), 6px 0 24px -18px rgba(0, 0, 0, .7); }
.rail-brand { display: flex; align-items: center; gap: 11px; height: var(--topbar-h); padding: 0 16px; flex: none; }
.brand-mark { width: 40px; height: 40px; flex: none; border-radius: 13px; display: grid; place-items: center; color: var(--accent-hi); background: radial-gradient(120% 120% at 30% 20%, #33353d 0%, #1b1c21 60%); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .09), 0 0 0 1px var(--line-2), 0 6px 18px -6px rgba(0, 0, 0, .8), 0 0 24px -6px rgba(240, 138, 60, .45); }
:root[data-theme="light"] .brand-mark { background: radial-gradient(120% 120% at 30% 20%, #fff 0%, #ece6de 70%); }
.brand-mark svg { filter: drop-shadow(0 0 5px rgba(240, 138, 60, .7)); }
.brand-text { min-width: 0; overflow: hidden; white-space: nowrap; }
.brand-text .b-name { font-family: var(--font-display); font-size: var(--fs-15); font-weight: 700; letter-spacing: -.01em; color: var(--text-1); }
.brand-text .b-sub { font-size: var(--fs-10); font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--accent-hi); }
.app:not(.rail-open) .brand-text { display: none; }

.rail-nav { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 8px 0 12px; scrollbar-width: none; }
.rail-nav::-webkit-scrollbar { display: none; }
.rail-group { padding: 6px 0; }
.rail-group + .rail-group { border-top: 1px solid var(--line); }
.rail-group-label { padding: 8px 22px 6px; font-size: var(--fs-10); font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--text-4); white-space: nowrap; }
.app:not(.rail-open) .rail-group-label { display: none; }

.rail-item { position: relative; display: flex; align-items: center; gap: 12px; width: calc(100% - 20px); height: 42px; margin: 2px 10px; padding: 0 8px 0 10px; border-radius: 14px; color: var(--text-3); font-size: var(--fs-13); font-weight: 600; text-decoration: none; white-space: nowrap; transition: color var(--dur-1), background var(--dur-1); }
.rail-item:hover { color: var(--text-1); background: var(--accent-softer); text-decoration: none; }
.rail-item .ri-icon { width: 36px; height: 36px; flex: none; margin-left: -6px; border-radius: 12px; display: grid; place-items: center; transition: background var(--dur-2), box-shadow var(--dur-2), color var(--dur-2); }
.rail-item.is-active { color: var(--text-1); background: var(--accent-softer); }
.rail-item.is-active .ri-icon { color: var(--text-on-accent); background: var(--accent-grad); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35), 0 0 0 1px rgba(255, 170, 100, .3), 0 4px 16px -2px rgba(240, 138, 60, .65); }
.rail-item .ri-label { overflow: hidden; text-overflow: ellipsis; }
.rail-item .ri-badge { margin-left: auto; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; font-size: 10px; font-weight: 700; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-hi); }
.app:not(.rail-open) .rail-item { width: 48px; margin: 3px auto; padding: 0; justify-content: center; }
.app:not(.rail-open) .rail-item .ri-icon { margin: 0; }
.app:not(.rail-open) .rail-item .ri-label, .app:not(.rail-open) .rail-item .ri-badge { display: none; }
.app:not(.rail-open) .rail-item.has-badge::after { content: ""; position: absolute; top: 7px; right: 7px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 8px var(--accent); }

.rail-foot { flex: none; padding: 10px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; }
.app:not(.rail-open) .rail-foot { align-items: center; }
.rail-toggle { color: var(--text-4); }

/* ── Main column ────────────────────────────────────────────────────────────── */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100%; }

.topbar { position: relative; z-index: 15; flex: none; display: flex; align-items: center; gap: 12px; height: var(--topbar-h); padding: 0 18px 0 22px; background: var(--bg-1); box-shadow: inset 0 -1px 0 var(--line); }
/* Out of sight until it takes keyboard focus, as the first stop on every page. */
.skip-link { position: fixed; z-index: 100; left: 12px; top: -60px; padding: 10px 16px; border-radius: var(--r-sm); background: var(--accent-grad); color: var(--text-on-accent); font-weight: 650; box-shadow: var(--shadow-3); }
.skip-link:focus { top: 12px; }
.tb-title { min-width: 0; display: flex; flex-direction: column; justify-content: center; }
.crumbs { display: flex; align-items: center; gap: 4px; font-size: var(--fs-11); color: var(--text-4); white-space: nowrap; overflow: hidden; }
.crumbs a { color: var(--text-3); }
.crumbs a:hover { color: var(--accent-hi); text-decoration: none; }
.crumbs .icon { color: var(--text-4); }
/* A long trail gives way part by part, each part ending in an ellipsis; the chevrons keep their size. */
.crumbs > a, .crumbs > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.crumbs > .icon { flex: none; }
.tb-title h1, .tb-title .tb-h1 { font-size: var(--fs-16); font-weight: 650; color: var(--text-1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.25; }
.tb-search { display: flex; align-items: center; gap: 9px; height: 36px; width: clamp(220px, 22vw, 340px); padding: 0 8px 0 12px; margin-left: auto; border-radius: var(--r-md); color: var(--text-4); background: var(--sunken); box-shadow: var(--well); font-size: var(--fs-13); transition: box-shadow var(--dur-1); }
.tb-search:hover { color: var(--text-2); box-shadow: var(--well), 0 0 0 1px var(--line-2); }
.tb-search .kbd { margin-left: auto; }
.tb-actions { display: flex; align-items: center; gap: 6px; }

/* Company logo (app.config.json › logo). Both theme variants are in the page; CSS shows one. */
.company-logo { display: inline-flex; align-items: center; }
.company-logo img { display: block; height: 100%; width: auto; max-width: none; }
:root[data-theme="dark"] .company-logo .logo-on-light,
:root[data-theme="light"] .company-logo .logo-on-dark { display: none; }
/* Top-right of the top bar, after a hairline divider: on every screen, never dominant. */
.tb-logo { flex: none; display: flex; align-items: center; height: 34px; margin-left: 4px; padding-left: 16px; box-shadow: inset 1px 0 0 var(--line-2); }
.tb-logo .company-logo { height: 34px; }
/* Narrow windows: the logo moves to the bottom of the navigation instead. */
.rail-logo { display: none; padding: 8px 12px 12px; }
.rail-logo .company-logo { height: 30px; }
@media (max-width: 1279px) {
  .tb-logo { display: none; }
  .app.rail-open .rail-logo, .app.mobile-nav .rail-logo { display: block; }
}
.tb-btn { position: relative; width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; color: var(--text-3); transition: color var(--dur-1), background var(--dur-1); }
.tb-btn:hover { color: var(--text-1); background: var(--surface-hi); }
.tb-btn.has-dot::after { content: ""; position: absolute; top: 8px; right: 8px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 2px var(--bg-1), 0 0 8px var(--accent); }
.tb-project { display: flex; align-items: center; gap: 8px; height: 36px; max-width: 240px; padding: 0 10px 0 8px; border-radius: var(--r-md); background: var(--raised-grad); box-shadow: var(--shadow-1), 0 0 0 1px var(--line); font-size: var(--fs-12); font-weight: 600; color: var(--text-2); }
.tb-project:hover { color: var(--text-1); }
.tb-project .p-dot { width: 22px; height: 22px; border-radius: 7px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-hi); flex: none; }
.tb-user { display: flex; align-items: center; gap: 9px; padding: 3px 4px 3px 3px; border-radius: var(--r-pill); }
.tb-user:hover { background: var(--surface-hi); }
.tb-menu-btn { display: none; }

.demo-banner { flex: none; display: flex; align-items: center; justify-content: center; gap: 8px; height: 26px; font-size: var(--fs-11); color: var(--warn); background: var(--warn-soft); box-shadow: inset 0 -1px 0 rgba(233, 177, 76, .2); }
.demo-banner button { color: var(--text-2); text-decoration: underline; font-size: var(--fs-11); }
/* A newer build is ready: more room, and a 24 px button. */
.demo-banner.update-banner { height: auto; min-height: 34px; padding: 4px 12px; flex-wrap: wrap; color: var(--info); background: var(--info-soft); box-shadow: inset 0 -1px 0 var(--line); }
.demo-banner.update-banner button { min-height: 24px; padding: 0 10px; border-radius: var(--r-pill); color: var(--text-1); text-decoration: none; font-weight: 650; background: var(--raised-grad); box-shadow: var(--shadow-1), 0 0 0 1px var(--line); }

/* ── Pages ──────────────────────────────────────────────────────────────────── */
.page { flex: 1 1 auto; min-height: 0; overflow: auto; position: relative; }
.page-inner { max-width: 1480px; margin: 0 auto; padding: 24px 28px 56px; animation: fade-in var(--dur-2) var(--ease); }
.page-inner.narrow { max-width: 1080px; }
.page.fill { overflow: hidden; display: flex; flex-direction: column; }
.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .ph-text { min-width: 0; }
.page-head h2 { font-size: var(--fs-24); font-weight: 650; letter-spacing: -.02em; }
.page-head p { color: var(--text-3); margin-top: 4px; max-width: 760px; }
.page-head .ph-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Three-panel workspace ──────────────────────────────────────────────────── */
.ws { display: grid; grid-template-columns: var(--ws-left, 316px) minmax(0, 1fr) var(--ws-right, 348px); flex: 1 1 auto; min-height: 0; transition: grid-template-columns var(--dur-2) var(--ease); }
.ws.left-closed { --ws-left: 0px; }
.ws.right-closed { --ws-right: 0px; }
.ws-panel { min-width: 0; min-height: 0; overflow: hidden; display: flex; flex-direction: column; background: var(--bg-1); }
.ws-panel.left { box-shadow: inset -1px 0 0 var(--line); }
.ws-panel.right { box-shadow: inset 1px 0 0 var(--line); }
.ws-panel .ws-scroll { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 14px; display: flex; flex-direction: column; gap: 14px; }
.ws-panel .ws-head { flex: none; display: flex; align-items: center; gap: 8px; height: 46px; padding: 0 12px 0 16px; box-shadow: inset 0 -1px 0 var(--line); }
.ws-panel .ws-head h3 { font-size: var(--fs-13); font-weight: 650; }
.ws-center { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--bg-0); }
.ws-toolbar { flex: none; display: flex; align-items: center; gap: 8px; height: 50px; padding: 0 14px; box-shadow: inset 0 -1px 0 var(--line); background: var(--bg-1); overflow-x: auto; scrollbar-width: none; }
.ws-toolbar::-webkit-scrollbar { display: none; }
/* A refused save's held copy: the choice sits above the toolbar, on top of the work. */
.ws-held { flex: none; padding: 10px 14px; background: var(--bg-1); box-shadow: inset 0 -1px 0 var(--line); }
.ws-held .alert { flex-wrap: wrap; }
.ws-held .alert > .grow { flex: 1 1 320px; }
.ws-held .alert-actions { flex-wrap: wrap; }
/* Tools keep their size and the bar scrolls; only the document title gives way. */
.ws-toolbar > * { flex-shrink: 0; }
.ws-toolbar > .col { flex-shrink: 1; min-width: 64px; }
.ws-toolbar .tb-sep { width: 1px; height: 22px; background: var(--line-2); margin: 0 4px; flex: none; }
.ws-mobile-tabs { display: none; }

.panel-block { border-radius: var(--r-lg); background: var(--surface-grad); box-shadow: var(--shadow-2), 0 0 0 1px var(--line); }
.panel-block > .pb-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px 8px; }
.panel-block > .pb-head h4 { font-size: var(--fs-12); font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--text-3); }
.panel-block > .pb-head .actions { margin-left: auto; display: flex; gap: 4px; }
.panel-block > .pb-body { padding: 4px 14px 14px; display: flex; flex-direction: column; gap: 10px; }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 1360px) {
  .ws { --ws-left: 292px; --ws-right: 320px; }
}
@media (max-width: 1180px) {
  .ws { grid-template-columns: var(--ws-left, 292px) minmax(0, 1fr); }
  /* Closed panels are hidden as well as moved aside, so keyboard focus cannot land in them;
     the visibility change waits for the slide to finish. */
  .ws-panel.right { position: absolute; right: 0; top: 0; bottom: 0; width: min(360px, 92vw); z-index: 30; box-shadow: var(--shadow-3), inset 1px 0 0 var(--line); transform: translateX(105%); visibility: hidden; transition: transform var(--dur-2) var(--ease), visibility 0s linear var(--dur-2); }
  .ws.right-open .ws-panel.right { transform: none; visibility: visible; transition: transform var(--dur-2) var(--ease), visibility 0s; }
  .ws.right-closed .ws-panel.right { transform: translateX(105%); visibility: hidden; }
  .page.fill { position: relative; }
  .tb-search { width: 44px; padding: 0; justify-content: center; } .tb-search .label-text, .tb-search .kbd { display: none; }
}
@media (max-width: 860px) {
  .app, .app.rail-open { grid-template-columns: minmax(0, 1fr); }
  .rail { position: fixed; left: 0; top: 0; bottom: 0; width: var(--rail-w-open); transform: translateX(-102%); transition: transform var(--dur-2) var(--ease); }
  .app.mobile-nav .rail { transform: none; box-shadow: var(--shadow-3); }
  .app .brand-text { display: block !important; }
  .app .rail-group-label { display: block !important; }
  .app .rail-item { width: calc(100% - 20px) !important; margin: 2px 10px !important; padding: 0 8px 0 10px !important; justify-content: flex-start !important; }
  .app .rail-item .ri-label { display: block !important; }
  .rail-toggle { display: none; }
  .tb-menu-btn { display: grid; }
  .topbar { padding: 0 10px; gap: 6px; }
  .tb-project, .tb-hide-sm { display: none !important; }
  .page-inner { padding: 16px 16px 48px; }
  .page-head h2 { font-size: var(--fs-20); }
  .ws { grid-template-columns: minmax(0, 1fr); }
  .ws-panel.left { position: absolute; left: 0; top: 0; bottom: 0; width: min(360px, 94vw); z-index: 30; transform: translateX(-105%); visibility: hidden; transition: transform var(--dur-2) var(--ease), visibility 0s linear var(--dur-2); box-shadow: var(--shadow-3); }
  .ws.left-open .ws-panel.left { transform: none; visibility: visible; transition: transform var(--dur-2) var(--ease), visibility 0s; }
  .ws-mobile-tabs { display: flex; flex: none; gap: 4px; padding: 8px 10px; background: var(--bg-1); box-shadow: inset 0 -1px 0 var(--line); }
  .ws-mobile-tabs button { flex: 1; height: 40px; border-radius: var(--r-sm); font-weight: 600; color: var(--text-3); display: flex; align-items: center; justify-content: center; gap: 6px; }
  .ws-mobile-tabs button.is-active { color: var(--text-1); background: var(--raised-grad); box-shadow: var(--shadow-1), 0 0 0 1px var(--line); }
  /* The tool bar scrolls sideways here; fade its right edge so that is discoverable. */
  .ws-toolbar { padding-right: 28px; -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent); }
  :root { --control-h: 40px; --control-h-sm: 34px; }
}
.mobile-scrim { display: none; }
@media (max-width: 860px) { .app.mobile-nav .mobile-scrim { display: block; position: fixed; inset: 0; z-index: 19; background: var(--scrim); } }
