/* ============================================================ App shell (mobile first) */
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: var(--s-2);
  height: calc(var(--topbar-h) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) var(--s-2) 0;
  background: rgba(247, 245, 242, 0.86); backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar .brand { flex: 1; justify-content: center; }
.topbar-me { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; }
.topbar-me:active .avatar { transform: scale(.94); }
@media (min-width: 1024px) { .topbar { display: none; } }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: var(--text-lg); letter-spacing: -0.02em; }
.brand-mark {
  position: relative; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(145deg, var(--amber-400), var(--amber-600)); color: var(--stone-900);
  box-shadow: 0 1px 0 rgba(255,255,255,.4) inset, 0 2px 6px rgba(217, 127, 6, .35);
}
.brand-mark .icon { width: 18px; height: 18px; stroke-width: 2.5; }

.sidebar {
  position: fixed; z-index: 60; top: 0; bottom: 0; left: 0; width: min(86vw, var(--sidebar-w));
  display: flex; flex-direction: column; padding: calc(var(--s-5) + env(safe-area-inset-top)) var(--s-3) calc(var(--s-3) + env(safe-area-inset-bottom));
  background: var(--stone-900); color: var(--stone-300);
  transform: translateX(-105%); transition: transform var(--slow) var(--ease);
}
.sidebar:focus { outline: none; box-shadow: none; }
.sidebar .brand { color: #fff; padding: 0 var(--s-3); margin-bottom: var(--s-6); }
.sidebar-close { position: absolute; top: calc(var(--s-4) + env(safe-area-inset-top)); right: var(--s-3); color: var(--stone-400); }
.sidebar-close:hover { color: #fff; }
.drawer-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
.scrim { position: fixed; inset: 0; z-index: 50; background: rgba(28, 25, 23, .5); opacity: 0; visibility: hidden; transition: opacity var(--medium) var(--ease), visibility var(--medium); }
.drawer-open .scrim { opacity: 1; visibility: visible; }
body.drawer-open { overflow: hidden; }

.btn-ghost.on-dark { --btn-hover: var(--stone-800); --btn-fg: var(--stone-300); }

.company-pill {
  display: flex; align-items: center; gap: var(--s-3); margin: 0 var(--s-1) var(--s-5); padding: var(--s-3);
  border-radius: var(--radius); background: var(--stone-800); color: #fff; font-size: var(--text-sm); font-weight: 600;
}
.company-pill .icon { color: var(--amber-400); }
.company-pill span { line-height: 1.3; }

.nav { display: grid; gap: 2px; }
.nav-label { margin: var(--s-4) var(--s-3) var(--s-2); font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--stone-500); }
.nav-link {
  position: relative; display: flex; align-items: center; gap: var(--s-3); height: 44px; padding: 0 var(--s-3);
  border-radius: var(--radius-sm); font-size: var(--text-sm); font-weight: 500; color: var(--stone-300);
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
}
.nav-link:hover { background: var(--stone-800); color: #fff; }
.nav-link.is-active { background: var(--stone-800); color: #fff; }
.nav-link.is-active::before { content: ""; position: absolute; left: -12px; top: 10px; bottom: 10px; width: 4px; border-radius: 0 4px 4px 0; background: var(--amber-500); }
.nav-link.is-active .icon { color: var(--amber-400); }
.nav-badge { margin-left: auto; min-width: 22px; height: 22px; padding: 0 7px; display: grid; place-items: center; border-radius: var(--radius-full); background: var(--amber-500); color: var(--stone-900); font-size: 11px; font-weight: 800; font-variant-numeric: tabular-nums; }

.sidebar-foot { margin-top: auto; padding-top: var(--s-4); border-top: 1px solid var(--stone-800); }
.me { position: relative; display: flex; align-items: center; gap: var(--s-3); padding: var(--s-2); border-radius: var(--radius-sm); transition: background var(--fast) var(--ease); }
.me:hover, .me.is-active { background: var(--stone-800); }
.me.is-active::before { content: ""; position: absolute; left: -12px; top: 12px; bottom: 12px; width: 4px; border-radius: 0 4px 4px 0; background: var(--amber-500); }
.me-chevron { color: var(--stone-500); transition: transform var(--fast) var(--ease), color var(--fast) var(--ease); }
.me:hover .me-chevron { color: #fff; transform: translateX(2px); }
.me-name { color: #fff; font-size: var(--text-sm); font-weight: 600; }
.me-email { font-size: var(--text-xs); color: var(--stone-500); }
.signout { display: flex; width: 100%; margin-top: var(--s-1); justify-content: flex-start; padding: 0 var(--s-3); height: 40px; }

.main { overflow-x: clip; } /* no sideways wobble on phones; clip (not hidden) keeps sticky headers working */
@media (min-width: 1024px) {
  .sidebar { transform: none; width: var(--sidebar-w); }
  .sidebar-close, .scrim { display: none; }
  .main { margin-left: var(--sidebar-w); }
}

/* ============================================================ Page */
.page { animation: rise var(--slow) var(--ease) backwards; /* not 'both': a kept transform would trap position:fixed children */ width: 100%; max-width: var(--content-max); margin: 0 auto; padding: var(--s-5) var(--s-4) calc(var(--s-16) + env(safe-area-inset-bottom)); }
@media (min-width: 640px) { .page { padding: var(--s-8) var(--s-6) var(--s-16); } }
@media (min-width: 1024px) { .page { padding: var(--s-10) var(--s-10) var(--s-16); } }
.page-narrow { max-width: 720px; }

.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--s-4); margin-bottom: var(--s-6); }
.page-title { font-size: var(--text-2xl); font-weight: 800; }
@media (min-width: 640px) { .page-title { font-size: var(--text-3xl); } }
.page-sub { margin-top: var(--s-1); color: var(--text-muted); }
.page-sub-inline { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }
.page-sub-inline .sep { color: var(--stone-300); }
.page-head .tile-icon { display: none; }
@media (min-width: 640px) { .page-head .tile-icon { display: grid; width: 56px; height: 56px; } }
.filters { margin-bottom: var(--s-2); }
.filters .toolbar + input + .chips-scroller { margin-bottom: var(--s-4); }
.filters > .search { margin-bottom: var(--s-3); } /* same gap as the Team page's toolbar */
.result-line { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); margin: 0 2px var(--s-3); font-size: var(--text-sm); color: var(--text-soft); animation: rise var(--medium) var(--ease); }
.link-sm { font-size: var(--text-sm); }
.back { display: inline-flex; align-items: center; gap: var(--s-1); margin-bottom: var(--s-3); font-size: var(--text-sm); font-weight: 600; color: var(--text-muted); transition: color var(--fast) var(--ease), gap var(--fast) var(--ease); }
.back:hover { color: var(--text); gap: var(--s-2); }

/* Floating action button for primary create actions on small screens */
.fab-wrap { display: contents; }
@media (max-width: 639px) {
  .page:has(.has-fab) { padding-bottom: 112px; }
  .page-head .btn-primary.has-fab {
    position: fixed; z-index: 25; right: var(--s-4); bottom: calc(var(--s-5) + env(safe-area-inset-bottom));
    min-height: 56px; padding: 0 var(--s-5); border-radius: var(--radius-full); box-shadow: var(--shadow-lg);
  }
}

.toolbar { display: grid; grid-template-columns: 1fr 132px; gap: var(--s-2); margin-bottom: var(--s-3); }
.toolbar .select-menu { left: auto; min-width: 180px; }
.toolbar .search input { font-size: 16px; } /* 16px stops iOS zooming on focus */
@media (min-width: 768px) { .toolbar { grid-template-columns: 1fr 200px; gap: var(--s-3); margin-bottom: var(--s-4); } }

.form-actions { display: flex; flex-direction: column-reverse; gap: var(--s-3); margin-top: var(--s-6); }
@media (min-width: 640px) { .form-actions { flex-direction: row; justify-content: flex-end; } }
.card .form-actions { margin-left: calc(var(--s-5) * -1); margin-right: calc(var(--s-5) * -1); margin-bottom: calc(var(--s-5) * -1); padding: var(--s-4) var(--s-5); border-top: 1px solid var(--border); background: var(--stone-25); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
@media (min-width: 640px) { .card .form-actions { margin-left: calc(var(--s-6) * -1); margin-right: calc(var(--s-6) * -1); margin-bottom: calc(var(--s-6) * -1); padding: var(--s-4) var(--s-6); } }
.form-section + .form-section { margin-top: var(--s-6); padding-top: var(--s-6); border-top: 1px solid var(--border); }
.form-section-head { display: block; margin-bottom: var(--s-4); padding: 0; }
.form-section-head h2 { font-size: var(--text-base); font-weight: 700; }
.form-section-head p { margin-top: 2px; font-size: var(--text-sm); color: var(--text-muted); }

.profile-hero { display: flex; flex-direction: column; align-items: center; gap: var(--s-3); padding: var(--s-6) var(--s-5); text-align: center; }
@media (min-width: 640px) { .profile-hero { flex-direction: row; text-align: left; padding: var(--s-6); } }
.profile-hero h1 { font-size: var(--text-xl); font-weight: 800; }
.hero-badges { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: var(--s-2) var(--s-3); margin-top: var(--s-2); }
@media (min-width: 640px) { .hero-badges { justify-content: flex-start; } }

.action-list { display: grid; gap: var(--s-2); padding: var(--s-4) var(--s-5); background: var(--stone-25); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
@media (min-width: 640px) { .action-list { display: flex; flex-wrap: wrap; justify-content: flex-end; padding: var(--s-4) var(--s-6); } }

/* ============================================================ Auth screens */
.auth {
  min-height: 100vh; min-height: 100dvh; display: grid; place-items: center;
  padding: calc(var(--s-6) + env(safe-area-inset-top)) var(--s-4) calc(var(--s-6) + env(safe-area-inset-bottom));
  background:
    radial-gradient(1200px 600px at 110% -10%, rgba(245, 158, 11, .16), transparent 60%),
    radial-gradient(800px 500px at -20% 110%, rgba(28, 25, 23, .07), transparent 60%),
    var(--bg);
}
.auth::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; opacity: .5;
  background-image: linear-gradient(var(--stone-200) 1px, transparent 1px), linear-gradient(90deg, var(--stone-200) 1px, transparent 1px);
  background-size: 32px 32px; mask-image: radial-gradient(ellipse at center, #000 10%, transparent 70%); -webkit-mask-image: radial-gradient(ellipse at center, #000 10%, transparent 70%);
}
.auth-card { position: relative; width: 100%; max-width: 420px; animation: rise var(--slow) var(--ease); }
.auth-card .brand { justify-content: center; margin-bottom: var(--s-8); }
.auth-panel { padding: var(--s-6) var(--s-5); }
@media (min-width: 640px) { .auth-panel { padding: var(--s-8); } }
.auth-title { font-size: var(--text-2xl); font-weight: 800; text-align: center; }
.auth-sub { margin-top: var(--s-2); text-align: center; color: var(--text-muted); }
.auth-foot { margin-top: var(--s-6); text-align: center; font-size: var(--text-sm); color: var(--text-muted); }
.auth-form { margin-top: var(--s-6); }
.auth-row { display: flex; justify-content: flex-end; margin-top: var(--s-3); }
.auth-actions { margin-top: var(--s-6); }
.back-link { display: inline-flex; align-items: center; gap: var(--s-1); }
.link { color: var(--amber-700); font-weight: 600; }
.link:hover { text-decoration: underline; text-underline-offset: 3px; }
.auth-illustration { display: grid; place-items: center; width: 64px; height: 64px; margin: 0 auto var(--s-5); border-radius: 50%; background: var(--amber-50); color: var(--amber-700); }
.auth-illustration.is-success { background: var(--green-50); color: var(--green-500); animation: pop var(--slow) var(--ease-spring); }
.auth-illustration .icon { width: 28px; height: 28px; }
.auth-illustration.is-warning { background: var(--red-50); color: var(--red-500); }


/* ============================================================ Error pages */
.error-code { margin-bottom: var(--s-2); font-size: var(--text-sm); font-weight: 700; letter-spacing: .12em; color: var(--text-muted); text-align: center; }

@media (min-width: 768px) { .hide-md { display: none; } }
