/* =========================================================================
   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 cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 0;
  overflow: hidden;
  position: relative;
  box-shadow: none;
}
.app.collapsed { --sidebar-w: 84px; }

/* ---------------------------------------------------------------- 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(0 1px 2px rgba(0, 0, 0, 0.12)); }
.brand-mark svg { width: 100%; height: 100%; }
.brand-text { display: flex; flex-direction: column; gap: 4px; 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 6px;
  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); }
.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); }
}
.nav-item.active::before {
  content: ""; position: absolute; left: calc(-1 * var(--space-4)); top: 50%;
  transform: translateY(-50%); width: 3px; height: 22px;
  background: var(--primary-600); border-radius: 0 3px 3px 0;
}

.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-muted); font-size: var(--text-sm); font-weight: var(--fw-semibold);
}
.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: 2px; opacity: 0; transition: opacity var(--dur) var(--ease); }
@media (hover: hover) and (pointer: fine) {
  .nav-section:hover .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: 2px; 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 cubic-bezier(0.4, 0, 0.2, 1), 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;
}
.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,
.app.collapsed .storage-card { 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; }

/* storage card */
.sidebar-bottom { padding: var(--space-4); }
.storage-card {
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: var(--space-4); background: var(--surface);
}
.storage-card .row-between { margin-bottom: 2px; }
.storage-card .title { font-size: var(--text-md); font-weight: var(--fw-semibold); color: var(--text-strong); }
.storage-card .pct { font-size: var(--text-sm); font-weight: var(--fw-semibold); color: var(--text-muted); }
.storage-card .used { font-size: var(--text-xs); color: var(--text-soft); }
.storage-bar {
  height: 8px; border-radius: var(--radius-full);
  background: repeating-linear-gradient(90deg, var(--gray-200) 0 3px, transparent 3px 6px);
  margin: var(--space-3) 0; position: relative; overflow: hidden;
}
.storage-bar i {
  position: absolute; inset: 0; width: 90%;
  background: repeating-linear-gradient(90deg, #ff8a3d 0 3px, #ffb070 3px 6px);
  border-radius: var(--radius-full);
}
.storage-upgrade {
  width: 100%; height: 38px; margin-top: var(--space-1);
  display: flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface); font-size: var(--text-sm); font-weight: var(--fw-medium); color: var(--text);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.storage-upgrade .muted { color: var(--text-soft); font-weight: var(--fw-regular); }
@media (hover: hover) and (pointer: fine) {
  .storage-upgrade:hover { background: var(--gray-50); border-color: var(--border-strong); }
}
.storage-upgrade svg { width: 18px; height: 18px; color: var(--text); }

/* 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)); }
.settings-back {
  width: 30px; height: 30px; border-radius: var(--radius-sm); flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-muted); border: 1px solid var(--border); background: var(--surface);
  box-shadow: var(--btn-shadow);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
@media (hover: hover) and (pointer: fine) {
  .settings-back:hover { background: var(--gray-50); color: var(--text-strong); }
}
.settings-back svg { width: 17px; height: 17px; }
.settings-title { font-size: var(--text-lg); font-weight: var(--fw-semibold); color: var(--text-strong); }

.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(--border); box-shadow: none; }
.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 {
  font-size: var(--text-2xs); font-weight: var(--fw-bold); letter-spacing: 0.07em;
  text-transform: uppercase; 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: 18px; height: 18px; 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);
}
.topbar .crumb { display: flex; align-items: center; gap: var(--space-3); font-size: 16px; }
.topbar .crumb .ico { color: var(--text-strong); display: inline-flex; }
.topbar .crumb .ico svg { width: 19px; height: 19px; }
.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); }
.topbar .crumb .sep { color: var(--text-soft); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: var(--space-3); }
.topbar-sep { width: 1px; height: 26px; background: var(--border); }

.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; }
