/* =========================================================================
   LAYOUT — app shell, sidebar, topbar, view scaffolding
   ========================================================================= */

.app-frame {
  height: 100vh;
  padding: 0;
  background: var(--canvas);
}

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100%;
  background: var(--surface);
  transition: grid-template-columns 0.3s var(--ease);
  border-radius: 0;
  overflow: hidden;
  position: relative;
  box-shadow: none;
}
.app.collapsed { --sidebar-w: 84px; }

/* ---------------------------------------------------------------- CLIENT VIEW BAR
   The admin's impersonation strip above the portal (body.is-client-view): who
   is being viewed + the one way out. Inverted so it reads as chrome, not content;
   the app frame gives up its height so nothing scrolls under it. */
body.is-client-view .app-frame { height: calc(100vh - var(--cv-bar-h)); }
.cv-bar {
  display: flex; align-items: center; justify-content: center; gap: var(--space-3);
  height: var(--cv-bar-h); padding: 0 var(--space-4);
  background: var(--text-strong); color: var(--surface);   /* --surface, not --text-invert: it flips with the theme */
  font-size: var(--text-sm); line-height: 1.2;
}
.cv-bar-ico { display: inline-flex; flex: 0 0 auto; opacity: 0.8; }
.cv-bar-ico svg { width: 16px; height: 16px; }
.cv-bar-msg { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cv-bar-msg b { font-weight: 600; }
.cv-bar-exit {
  display: inline-flex; align-items: center; gap: var(--space-1-5); flex: 0 0 auto;
  height: 26px; padding: 0 var(--space-3); border-radius: var(--radius-full);
  border: 1px solid color-mix(in srgb, var(--surface) 35%, transparent);
  background: transparent; color: inherit; font: inherit; font-weight: 600; cursor: pointer;
}
.cv-bar-exit svg { width: 14px; height: 14px; }
@media (hover: hover) and (pointer: fine) {
  .cv-bar-exit:hover { background: color-mix(in srgb, var(--surface) 14%, transparent); }
}
.cv-bar-exit:focus-visible { outline: 2px solid var(--surface); outline-offset: 2px; }

/* ---------------------------------------------------------------- SHELL ROWS
   Shared by sidebar + main so the two columns share identical row heights
   and their bottom borders line up exactly across every page. */
.shell-header  { height: var(--shell-header-height);  border-bottom: 1px solid var(--border); flex-shrink: 0; }
.shell-toolbar { height: var(--shell-toolbar-height); border-bottom: 1px solid var(--border); flex-shrink: 0; display: flex; align-items: center; }
/* .btn's inline-flex beats the UA [hidden] rule — pin toolbar actions down
   (e.g. the Content tab's New share while its create surface is open) */
.shell-toolbar .btn[hidden] { display: none; }

/* ---------------------------------------------------------------- SIDEBAR */
.sidebar {
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  overflow-x: hidden;
  background: var(--surface-sidebar);
  min-height: 0;
}

.brand {
  position: relative;
  display: flex; align-items: center; gap: var(--space-3);
  height: var(--shell-header-height);
  padding: 0 var(--space-5);
}
.brand-mark {
  height: 32px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
}
.brand-mark img { height: 100%; width: auto; filter: drop-shadow(var(--brand-glow)); }
.brand-mark svg { width: 100%; height: 100%; }
/* (4 Sep) the one-piece lockup replaces mark + "Magnet / CRM Platform" text.
   Inline SVG: the wordmark is currentColor → ink on light, white on dark
   (--text-strong flips); the mark keeps its own gold + ink. */
.brand-lockup { display: inline-flex; align-items: center; height: 42px; min-width: 0; color: var(--text-strong); }
.brand-lockup svg { height: 100%; width: auto; }
.app.collapsed .brand-lockup { display: none; }
.brand-text { display: flex; flex-direction: column; gap: var(--space-1); line-height: 1.15; min-width: 0; }
.brand-text .name { font-size: var(--text-base); font-weight: var(--fw-bold); color: var(--text-strong); }
.brand-text .sub  { font-size: var(--text-xs); color: var(--text-soft); }
.brand .collapse {
  margin-left: auto; color: var(--text-soft);
  width: 28px; height: 28px; border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
@media (hover: hover) and (pointer: fine) {
  .brand .collapse:hover { background: var(--gray-100); color: var(--text); }
}
.brand .collapse svg { width: 18px; height: 18px; transition: transform var(--dur) var(--ease); }
.app.collapsed .brand .collapse svg { transform: rotate(180deg); }

/* account switcher — sits inside the sidebar's shell-toolbar row,
   matched to the 40px height of the toolbar buttons (Filter/Sort/Group). */
.sidebar-toolbar { padding: 0 var(--space-4); }
.account {
  display: flex; align-items: center; gap: var(--space-2);
  width: 100%; height: var(--btn-height);
  padding: 0 var(--space-1-5);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface-field);
  box-shadow: var(--shadow-xs);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  cursor: pointer;
}
.account .avatar { width: 26px; height: 26px; }
@media (hover: hover) and (pointer: fine) {
  .account:hover { border-color: var(--border-strong); box-shadow: var(--shadow-xs); }
}
.account .email { font-size: var(--text-md); font-weight: var(--fw-medium); color: var(--text); min-width: 0; text-overflow: ellipsis; }
.account .switch {
  margin-left: auto; color: var(--text-soft);
  width: 26px; height: 26px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  transition: background var(--dur) var(--ease);
}
@media (hover: hover) and (pointer: fine) {
  .account .switch:hover { background: var(--gray-100); }
}
.account .switch svg { width: 15px; height: 15px; }

/* nav */
.nav { flex: 1; overflow-y: auto; padding: var(--space-3) var(--space-4) var(--space-4); min-height: 0; }
.nav-item {
  position: relative;
  display: flex; align-items: center; gap: var(--space-3);
  height: 38px; padding: 0 var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-muted); font-weight: var(--fw-medium);
  font-size: var(--text-md);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
  width: 100%;
}
.nav-item svg { width: 20px; height: 20px; color: var(--text-soft); transition: color var(--dur) var(--ease); }
.nav-item .label { white-space: nowrap; }
.nav-item .meta { margin-left: auto; font-size: var(--text-sm); color: var(--text-soft); font-weight: var(--fw-semibold); }
@media (hover: hover) and (pointer: fine) {
  .nav-item:hover { background: var(--nav-hover-bg); color: var(--nav-active-fg); }
  .nav-item:hover svg { color: var(--nav-active-fg); }
}
.nav-item.active { background: var(--nav-active-bg); color: var(--nav-active-fg); }
.nav-item.active svg { color: var(--nav-active-fg); }
@media (hover: hover) and (pointer: fine) {
  .nav-item.active:hover { background: var(--nav-active-bg); }
}
/* (4 Sep) no accent bar on the active item — the grey pill alone marks it,
   as in the reference sidebar; the accent is reserved for selection/links */

.nav-section { margin-top: var(--space-5); }
.nav-section-head {
  display: flex; align-items: center; gap: var(--space-2);
  padding: 0 var(--space-3); height: 30px;
  color: var(--text-soft); font-size: var(--text-2xs); font-weight: var(--fw-semibold);
  /* sentence-case group label (14 Sep — Attio's sidebar sections read "Records", not "RECORDS") */
}
.nav-section-head .caret { color: var(--text-soft); display: inline-flex; transition: transform var(--dur) var(--ease); }
.nav-section-head .caret svg { width: 16px; height: 16px; }
.nav-section.collapsed .caret { transform: rotate(-90deg); }
.nav-section-head .actions { margin-left: auto; display: flex; align-items: center; gap: var(--space-0-5); opacity: 0; transition: opacity var(--dur) var(--ease); }
@media (hover: hover) and (pointer: fine) {
  .nav-section:hover .actions { opacity: 1; }
}
/* keyboard users get the reveal too; no hover at all → always visible */
.nav-section:focus-within .actions { opacity: 1; }
@media (hover: none) {
  .nav-section-head .actions { opacity: 1; }
}
.nav-section-head .actions button {
  width: 24px; height: 24px; border-radius: var(--radius-xs);
  display: inline-flex; align-items: center; justify-content: center; color: var(--text-soft);
}
@media (hover: hover) and (pointer: fine) {
  .nav-section-head .actions button:hover { background: var(--gray-150); color: var(--text); }
}
.nav-section-head .actions svg { width: 16px; height: 16px; }
.nav-section-body { margin-top: var(--space-0-5); overflow: hidden; }
.nav-section.collapsed .nav-section-body { display: none; }
.nav-section .nav-item { height: 35px; }
.nav-section-head { cursor: pointer; user-select: none; }

/* faint separator above a sidebar group (e.g. the one under Leads) */
.nav-sep { height: 1px; background: var(--border); margin: var(--space-3) var(--space-2); }
.nav-sep + .nav-section { margin-top: var(--space-2); }   /* the sep already adds the gap */

/* collapsed sidebar tweaks */
/* text labels animate (fade + collapse width) instead of snapping */
.brand-text,
.account .email,
.nav-item .label,
.nav-section-head .label,
.footer-item span {
  white-space: nowrap; overflow: hidden;
  max-width: 200px; opacity: 1;
  transition: max-width 0.28s var(--ease), opacity 0.18s var(--ease);
}
.app.collapsed .brand-text,
.app.collapsed .account .email,
.app.collapsed .nav-item .label,
.app.collapsed .nav-section-head .label,
.app.collapsed .footer-item span {
  max-width: 0; opacity: 0;
}
/* icon rail: a group label has nothing to say without its text, so the head
   goes away and the .nav-sep hairline above the group stands in for it; the
   group's items always show (a user-collapsed group can't be re-expanded
   from the rail, so don't hide its icons there) */
.app.collapsed .nav-section-head { display: none; }
.app.collapsed .nav-section { margin-top: var(--space-2); }
.app.collapsed .nav-section.collapsed .nav-section-body { display: block; }
.app.collapsed .account .switch,
.app.collapsed .nav-item .meta,
.app.collapsed .nav-section-head .actions,
.app.collapsed .nav-section-head .caret,
.app.collapsed .footer-item .chev { display: none; }
.app.collapsed .nav-item,
.app.collapsed .footer-item { justify-content: center; gap: 0; }
.app.collapsed .nav-item .meta { display: none; }
.app.collapsed .account { justify-content: center; padding: var(--space-2); gap: 0; }
.app.collapsed .brand { justify-content: center; padding: 0; gap: 0; }
.app.collapsed .brand-mark { display: none; }
.app.collapsed .brand .collapse { position: static; margin: 0; }

/* sidebar footer */
.sidebar-footer { border-top: 1px solid var(--border); padding: var(--space-3) var(--space-4); }
.footer-item {
  display: flex; align-items: center; gap: var(--space-3);
  height: 38px; padding: 0 var(--space-3); border-radius: var(--radius-md);
  color: var(--text-muted); font-weight: var(--fw-medium); width: 100%;
  font-size: var(--text-md);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.footer-item svg { width: 20px; height: 20px; color: var(--text-soft); }
.footer-item .chev { margin-left: auto; color: var(--text-soft); }
.footer-item .chev svg { width: 16px; height: 16px; }
@media (hover: hover) and (pointer: fine) {
  .footer-item:hover { background: var(--nav-hover-bg); color: var(--nav-active-fg); }
  .footer-item:hover svg { color: var(--nav-active-fg); }
}
.footer-item.active { background: var(--nav-active-bg); color: var(--nav-active-fg); }
.footer-item.active svg { color: var(--nav-active-fg); }
@media (hover: hover) and (pointer: fine) {
  .footer-item.active:hover { background: var(--nav-active-bg); }
}

/* ----------------------------------------------------------- SETTINGS MODE */
/* +--safe-top so the header clears the iPhone notch when the settings panel is
   a full-height fixed drawer (top:0). --safe-top is 0 off-notch, so no change
   on desktop. */
.settings-sidebar .settings-head { gap: var(--space-2); padding: var(--safe-top) var(--space-4) 0; height: calc(var(--shell-header-height) + var(--safe-top)); }
/* the rail expand toggle only exists on tablet (responsive.css shows it) */
.settings-head .collapse { display: none; }
/* Linear-style labelled exit — "‹ Back to app" as the sidebar's top row */
.settings-back {
  display: inline-flex; align-items: center; gap: 7px; flex-shrink: 0;
  height: 32px; padding: 0 var(--space-2-5) 0 var(--space-1-5); margin-left: -6px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: var(--text-sm); font-weight: var(--fw-semibold);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
@media (hover: hover) and (pointer: fine) {
  .settings-back:hover { background: var(--gray-100); color: var(--text-strong); }
}
.settings-back svg { width: 16px; height: 16px; position: relative; top: 1px; }   /* optical: the chevron reads high against Figtree's x-height */

.settings-body { flex: 1; overflow-y: auto; overflow-x: hidden; padding: var(--space-4); min-height: 0; }
.settings-version {
  flex-shrink: 0; padding: var(--space-3) var(--space-4) var(--space-4);
  font-size: var(--text-xs); color: var(--text-soft); letter-spacing: 0.01em;
}
.settings-search {
  display: flex; align-items: center; gap: var(--space-2);
  height: 38px; padding: 0 var(--space-3); margin-bottom: var(--space-5);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface); color: var(--text-soft);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.settings-search:focus-within { border-color: var(--primary-400); box-shadow: var(--ring-primary); }
.settings-search svg { width: 17px; height: 17px; color: var(--primary-500); }
.settings-search input { border: none; outline: none; background: none; font-size: var(--text-md); color: var(--text); width: 100%; }
.settings-search input:focus, .settings-search input:focus-visible { outline: none; box-shadow: none; border: none; }
.settings-search input::placeholder { color: var(--text-soft); }

.settings-group { margin-bottom: var(--space-5); }
.settings-group-label {
  /* same recipe as the app sidebar's .nav-section-head, so both navs read as one system */
  font-size: var(--text-2xs); font-weight: var(--fw-semibold); color: var(--text-soft);
  padding: 0 var(--space-3); margin-bottom: var(--space-2);
}
.settings-item {
  display: flex; align-items: center; gap: var(--space-3); width: 100%;
  height: 38px; padding: 0 var(--space-3); border-radius: var(--radius-md);
  color: var(--text-muted); font-weight: var(--fw-medium); font-size: var(--text-md);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.settings-item svg { width: 20px; height: 20px; color: var(--text-soft); transition: color var(--dur) var(--ease); }
@media (hover: hover) and (pointer: fine) {
  .settings-item:hover { background: var(--nav-hover-bg); color: var(--nav-active-fg); }
  .settings-item:hover svg { color: var(--nav-active-fg); }
}
.settings-item.active { background: var(--nav-active-bg); color: var(--nav-active-fg); }
.settings-item.active svg { color: var(--nav-active-fg); }
@media (hover: hover) and (pointer: fine) {
  .settings-item.active:hover { background: var(--nav-active-bg); }
}
/* container: toolbars inside the main column re-lay-out on the COLUMN's width,
   not the viewport's — with the sidebar open the column is ~260px narrower than
   the window, so viewport breakpoints fire too late and bars overlap first. */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--surface); position: relative; container-type: inline-size; container-name: main-col; }

.topbar {
  display: flex; align-items: center; gap: var(--space-4);
  padding: 0 var(--space-6);
}
/* page title (4 Sep): 16px semibold title, no route icon on desktop — the
   reference's plain "Bookings" header. */
.topbar .crumb { display: flex; align-items: center; gap: var(--space-3); font-size: 16px; }
.topbar .crumb .ico { display: none; }
.topbar .crumb .seg { color: var(--text-soft); font-weight: var(--fw-medium); }
.topbar .crumb .seg.cur { color: var(--text-strong); font-weight: var(--fw-semibold); letter-spacing: -0.01em; }
.topbar .crumb .sep { color: var(--text-soft); }
/* dashboard greeting: muted question, strong name, wave */
.topbar .crumb .crumb-greet { color: var(--text-soft); font-weight: var(--fw-medium); white-space: nowrap; }
.topbar .crumb .crumb-greet-name { color: var(--text-strong); font-weight: var(--fw-semibold); letter-spacing: -0.01em; margin-left: calc(-1 * var(--space-1)); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .crumb .crumb-greet-wave { margin-left: calc(-1 * var(--space-1)); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: var(--space-1); }

.view-scroll { flex: 1; overflow-y: auto; min-height: 0; scrollbar-gutter: stable; overscroll-behavior: contain; }

/* page toolbar row — a real shell row outside the scroll area so its bottom
   border lines up with the sidebar account row's border on every page. */
.main-toolbar {
  padding: 0 var(--space-6);
  gap: var(--space-3);
}
.main-toolbar .spacer { flex: 1; }
/* routes with no toolbar content (e.g. the portal's My Plan) collapse the
   row entirely — no dead strip between the header and the page. */
.main-toolbar.is-empty { display: none; }
