/* App shell, page frame, and the small shared pieces every screen uses (page header, stat tiles,
   chart classes). Logical properties only: the same rules serve RTL and LTR. */

[dir="rtl"] { --dir: 1; }
[dir="ltr"] { --dir: -1; }
body { background: var(--bg); }

.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100dvh; transition: grid-template-columns var(--d-slow) var(--ease-out); }
.app.collapsed { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }

/* ------------------------------------------------------------------ sidebar */
.sidebar { position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; background: var(--surface); border-inline-end: 1px solid var(--border); z-index: 40; overflow: hidden; }
.sb-brand { display: flex; align-items: center; gap: 12px; height: var(--topbar-h); padding-inline: 18px; flex: none; }
.logo-mark { width: 36px; height: 36px; border-radius: 11px; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; flex: none; box-shadow: inset 0 -6px 12px rgba(0,0,0,.14); }
.sb-brand-text { line-height: 1.2; min-width: 0; }
.sb-brand-text b { display: block; font-size: var(--fs-md); font-weight: 700; white-space: nowrap; }
.sb-brand-text span { font-size: var(--fs-xs); color: var(--text-3); white-space: nowrap; }
.sb-scroll { flex: 1; overflow-y: auto; padding: 4px 12px 12px; }
.sb-group { font-size: var(--fs-xs); font-weight: 700; color: var(--text-3); padding: 16px 10px 6px; letter-spacing: .03em; white-space: nowrap; }
.nav-item { display: flex; align-items: center; gap: 12px; min-height: 42px; padding-inline: 12px; border-radius: var(--r-sm); color: var(--text-2); font-weight: 500; text-decoration: none; position: relative; white-space: nowrap; transition: background var(--d-fast), color var(--d-fast); }
.nav-item:hover { background: var(--surface-3); color: var(--text); }
.nav-item[aria-current="page"] { background: var(--primary-soft); color: var(--primary-text); font-weight: 700; }
.nav-item[aria-current="page"]::before { content: ""; position: absolute; inset-block: 9px; inset-inline-start: -12px; width: 4px; background: var(--primary); border-start-end-radius: 4px; border-end-end-radius: 4px; }
.nav-item svg { flex: none; }
.nav-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.nav-count { min-width: 22px; height: 22px; padding-inline: 6px; border-radius: 11px; background: var(--attn); color: #fff; font-size: 12px; font-weight: 700; display: inline-grid; place-items: center; font-variant-numeric: tabular-nums; }
[data-theme="dark"] .nav-count { color: #1a1204; }
.sb-project { margin: 6px 0 4px; padding: 12px; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface-2); }
.sb-project-client { display: flex; align-items: center; gap: 6px; font-size: var(--fs-xs); color: var(--text-3); }
.sb-project-name { font-weight: 700; font-size: var(--fs-md); line-height: 1.35; margin: 2px 0 8px; display: block; color: var(--text); text-decoration: none; }
.sb-foot { flex: none; padding: 10px 12px; border-top: 1px solid var(--divider); display: flex; align-items: center; gap: 8px; }
.client-dot { display: inline-block; border-radius: 3px; flex: none; }

.app.collapsed .sb-brand-text, .app.collapsed .nav-label, .app.collapsed .sb-group, .app.collapsed .sb-project, .app.collapsed .sb-foot .sb-user-text { display: none; }
.app.collapsed .nav-item { justify-content: center; padding-inline: 0; }
.app.collapsed .nav-count { position: absolute; inset-block-start: 4px; inset-inline-end: 6px; min-width: 18px; height: 18px; font-size: 11px; padding-inline: 4px; }
.app.collapsed .nav-item[aria-current="page"]::before { inset-inline-start: -12px; }
.app.collapsed .sb-brand { justify-content: center; padding-inline: 0; }
.app.collapsed .sb-foot { justify-content: center; flex-direction: column; }
.app.collapsed .sb-group-sep { display: block; height: 1px; background: var(--divider); margin: 10px 8px; }
.sb-group-sep { display: none; }

/* ------------------------------------------------------------------ main + topbar */
.main { min-width: 0; display: flex; flex-direction: column; min-height: 100dvh; }
.topbar { position: sticky; top: 0; z-index: 30; height: var(--topbar-h); display: flex; align-items: center; gap: 10px; padding-inline: var(--sp-6); background: color-mix(in srgb, var(--bg) 88%, transparent); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); border-bottom: 1px solid transparent; transition: border-color var(--d-base); }
.topbar.scrolled { border-bottom-color: var(--border); }
.cmdk-trigger { display: inline-flex; align-items: center; gap: 10px; height: 40px; min-width: min(320px, 38vw); padding-inline: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); color: var(--text-3); cursor: pointer; font: inherit; font-size: var(--fs-md); transition: border-color var(--d-fast), box-shadow var(--d-fast); }
.cmdk-trigger:hover { border-color: var(--border-strong); box-shadow: var(--shadow-1); }
.cmdk-trigger .kbd { margin-inline-start: auto; }
.proto-pill { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding-inline: 10px; border-radius: 14px; background: var(--attn-soft); color: var(--attn-text); border: 1px solid var(--attn-border); font-size: var(--fs-xs); font-weight: 600; white-space: nowrap; }
.topbar .grow { min-width: 0; }
.icon-btn { position: relative; }
.icon-btn .pip { position: absolute; inset-block-start: 7px; inset-inline-end: 8px; width: 9px; height: 9px; border-radius: 50%; background: var(--attn); border: 2px solid var(--bg); }
.user-chip { display: inline-flex; align-items: center; gap: 10px; height: 44px; padding-inline: 6px 12px; border-radius: 22px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font: inherit; color: var(--text); }
.user-chip:hover { border-color: var(--border-strong); }
.user-chip .user-meta { text-align: start; line-height: 1.2; }
.user-chip .user-meta b { display: block; font-size: var(--fs-sm); }
.user-chip .user-meta span { font-size: 11px; color: var(--text-3); }

.page { width: 100%; max-width: var(--content-max); margin-inline: auto; padding: var(--sp-4) var(--sp-6) var(--sp-16); animation: fade-up var(--d-slow) var(--ease-out) both; }
.page-wide { max-width: none; }

/* ------------------------------------------------------------------ page header */
.page-header { margin-bottom: var(--sp-6); }
.page-header-row { display: flex; gap: var(--sp-4); align-items: flex-start; flex-wrap: wrap; }
.page-header-row > .grow { min-width: min(100%, 320px); }
.page-title { font-size: var(--fs-2xl); font-weight: 700; line-height: 1.3; letter-spacing: -.005em; }
.page-sub { color: var(--text-2); margin-top: 4px; max-width: 70ch; }
.page-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: center; }
.page-eyebrow { font-size: var(--fs-xs); font-weight: 700; color: var(--primary-text); letter-spacing: .04em; margin-bottom: 4px; display: flex; gap: 6px; align-items: center; }
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--text-3); font-size: var(--fs-sm); text-decoration: none; margin-bottom: 10px; padding: 4px 0; }
.back-link:hover { color: var(--text); }

/* ------------------------------------------------------------------ stat tiles */
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; box-shadow: var(--shadow-1); position: relative; overflow: hidden; --tone: var(--primary); --tone-soft: var(--primary-soft); --tone-text: var(--primary-text); }
.stat-attn { --tone: var(--attn); --tone-soft: var(--attn-soft); --tone-text: var(--attn-text); }
.stat-success { --tone: var(--success); --tone-soft: var(--success-soft); --tone-text: var(--success-text); }
.stat-danger { --tone: var(--danger); --tone-soft: var(--danger-soft); --tone-text: var(--danger-text); }
.stat-info { --tone: var(--info); --tone-soft: var(--info-soft); --tone-text: var(--info-text); }
.stat-link { cursor: pointer; transition: transform var(--d-base) var(--ease-out), box-shadow var(--d-base), border-color var(--d-base); }
.stat-link:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); border-color: var(--border-strong); }
.stat-top { display: flex; align-items: center; gap: 10px; }
.stat-ico { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; background: var(--tone-soft); color: var(--tone-text); flex: none; }
.stat-label { color: var(--text-2); font-size: var(--fs-sm); font-weight: 500; flex: 1; }
.stat-value { font-size: var(--fs-3xl); font-weight: 700; line-height: 1.1; letter-spacing: -.01em; }
.stat-sub { color: var(--text-3); font-size: var(--fs-sm); }
.delta { display: inline-flex; align-items: center; gap: 3px; font-size: var(--fs-xs); font-weight: 600; padding: 2px 7px; border-radius: 10px; }
.delta.up { background: var(--success-soft); color: var(--success-text); }
.delta.down { background: var(--danger-soft); color: var(--danger-text); }

/* ------------------------------------------------------------------ charts */
.donut { position: relative; display: inline-block; flex: none; }
.donut-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; line-height: 1.25; }
.stackbar { display: flex; gap: 2px; border-radius: 99px; overflow: hidden; background: var(--surface-3); }
.stackbar > span { display: block; min-width: 3px; }
.legend { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 10px; }
.legend li { display: flex; align-items: center; gap: 7px; font-size: var(--fs-sm); color: var(--text-2); }
.legend i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend b { color: var(--text); font-weight: 600; }
.bars { display: flex; align-items: flex-end; gap: 8px; }
.bar-col { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; }
.bar { display: block; width: 100%; max-width: 30px; border-radius: 6px 6px 2px 2px; transition: height var(--d-slow) var(--ease-out); }
.bar-val { font-size: 11px; color: var(--text-3); }
.bar-label { font-size: 11px; color: var(--text-3); white-space: nowrap; }
.funnel { display: flex; flex-direction: column; gap: 10px; }
.funnel-row { display: grid; grid-template-columns: minmax(96px, 150px) 1fr 70px; gap: 12px; align-items: center; }
.funnel-label { font-size: var(--fs-sm); color: var(--text-2); display: flex; flex-direction: column; line-height: 1.3; }
.funnel-track { height: 14px; background: var(--surface-3); border-radius: 7px; overflow: hidden; }
.funnel-track span { display: block; height: 100%; border-radius: 7px; transition: width var(--d-slow) var(--ease-out); }
.funnel-val { text-align: end; font-weight: 600; font-size: var(--fs-sm); }
.spark { display: block; }

/* ------------------------------------------------------------------ command palette */
.cmdk-wrap { position: fixed; inset: 0; z-index: 90; background: var(--overlay); display: grid; justify-items: center; align-content: start; padding: 12vh 16px 16px; animation: fade-in var(--d-base) both; }
.cmdk { width: min(640px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl); box-shadow: var(--shadow-3); overflow: hidden; animation: pop-in var(--d-base) var(--ease-out) both; }
.cmdk-input { display: flex; align-items: center; gap: 12px; padding: 0 18px; height: 60px; border-bottom: 1px solid var(--divider); color: var(--text-3); }
.cmdk-input input { flex: 1; border: 0; outline: 0; background: transparent; font: inherit; font-size: var(--fs-lg); color: var(--text); min-width: 0; }
.cmdk-list { max-height: min(56vh, 420px); overflow-y: auto; padding: 8px; }
.cmdk-sec { font-size: var(--fs-xs); font-weight: 700; color: var(--text-3); padding: 10px 10px 4px; }
.cmdk-item { display: flex; align-items: center; gap: 12px; min-height: 46px; padding: 6px 10px; border-radius: var(--r-sm); cursor: pointer; color: var(--text); text-decoration: none; }
.cmdk-item[aria-selected="true"] { background: var(--primary-soft); color: var(--primary-text); }
.cmdk-item small { color: var(--text-3); display: block; font-size: var(--fs-xs); }
.cmdk-foot { display: flex; gap: 16px; padding: 10px 16px; border-top: 1px solid var(--divider); font-size: var(--fs-xs); color: var(--text-3); }

/* ------------------------------------------------------------------ prototype panel (clearly not security) */
.sim-note { font-size: var(--fs-xs); color: var(--attn-text); background: var(--attn-soft); border: 1px solid var(--attn-border); border-radius: var(--r-sm); padding: 8px 10px; line-height: 1.5; margin: 4px 8px 8px; }
.persona-item { display: flex; gap: 10px; align-items: flex-start; }
.persona-item small { display: block; color: var(--text-3); font-size: 11.5px; line-height: 1.4; font-weight: 400; }

/* ------------------------------------------------------------------ mobile bottom nav */
.bottom-nav { display: none; }
.scrim { display: none; }
.menu-btn { display: none; }

/* ------------------------------------------------------------------ responsive */
@media (max-width: 1099px) and (min-width: 760px) {
  .app { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }
  .app .sb-brand-text, .app .nav-label, .app .sb-group, .app .sb-project, .app .sb-foot .sb-user-text { display: none; }
  .app .nav-item { justify-content: center; padding-inline: 0; }
  .app .nav-count { position: absolute; inset-block-start: 4px; inset-inline-end: 6px; min-width: 18px; height: 18px; font-size: 11px; padding-inline: 4px; }
  .app .sb-brand { justify-content: center; padding-inline: 0; }
  .app .sb-foot { justify-content: center; flex-direction: column; }
  .app .sb-group-sep { display: block; height: 1px; background: var(--divider); margin: 10px 8px; }
  .collapse-toggle { display: none !important; }
  .user-chip .user-meta { display: none; }
  .user-chip { padding-inline: 4px; }
}
@media (max-width: 759px) {
  .app, .app.collapsed { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; width: min(310px, 86vw); transform: translateX(calc(var(--dir) * 100%)); transition: transform var(--d-slow) var(--ease-out); box-shadow: var(--shadow-3); }
  .app.drawer-open .sidebar { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 35; background: var(--overlay); opacity: 0; pointer-events: none; transition: opacity var(--d-base); }
  .app.drawer-open .scrim { opacity: 1; pointer-events: auto; }
  .menu-btn { display: inline-flex; }
  .collapse-toggle { display: none !important; }
  .topbar { padding-inline: var(--sp-4); gap: 6px; }
  .cmdk-trigger { min-width: 0; width: 40px; padding: 0; justify-content: center; }
  .cmdk-trigger span, .cmdk-trigger .kbd { display: none; }
  .proto-pill span { display: none; }
  .user-chip .user-meta { display: none; }
  .user-chip { padding-inline: 4px; }
  .page { padding: var(--sp-2) var(--sp-4) calc(var(--bottom-nav-h) + var(--sp-8)); }
  .page-title { font-size: var(--fs-xl); }
  .bottom-nav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; inset-inline: 0; bottom: 0; z-index: 30; height: var(--bottom-nav-h); background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
  .bn-item { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; color: var(--text-3); text-decoration: none; background: none; border: 0; font-family: inherit; position: relative; min-height: 48px; cursor: pointer; }
  .bn-item[aria-current="page"] { color: var(--primary-text); font-weight: 700; }
  .bn-item[aria-current="page"]::before { content: ""; position: absolute; inset-block-start: 0; width: 28px; height: 3px; border-radius: 0 0 3px 3px; background: var(--primary); }
  .bn-item .nav-count { position: absolute; inset-block-start: 5px; inset-inline-start: calc(50% + 6px); min-width: 17px; height: 17px; font-size: 10.5px; padding-inline: 4px; }
  .funnel-row { grid-template-columns: 96px 1fr 44px; gap: 8px; }
}

@media (max-width: 1099px) {
  .proto-pill span { display: none; }
  .proto-pill { padding-inline: 7px; }
  .cmdk-trigger { min-width: 0; flex: 0 1 240px; }
  .topbar { padding-inline: var(--sp-4); gap: 6px; }
}
