/* file: static/css/components.css
   App-shell + design-system component layer (Decision 17, design-system-first).
   Standalone stylesheet linked globally from base.html, served directly (NOT
   processed by Tailwind). All values come from the tokens in index.css — no
   color/size literals except the documented allowlist (#fff on a colored
   surface). Reusable patterns live here, never in a per-template <style>. */

[x-cloak] { display: none !important; }

/* ════════ TOP BAR — brand + stats + user widget ════════ */
.app-topbar {
  background: hsl(var(--card));
  border-bottom: 1px solid hsl(var(--border));
  height: 58px;
  display: flex; align-items: center;
  padding: 0 22px; gap: 22px;
  position: sticky; top: 0; z-index: 40;
}
.app-brand { display: flex; align-items: center; gap: 10px; text-decoration: none; flex-shrink: 0; }
.app-brand-mark {
  height: 30px; width: auto; display: block;
}
.app-brand-name { font-size: 16px; font-weight: 700; letter-spacing: -.02em; color: hsl(var(--brand)); }

.app-stats { display: flex; align-items: center; gap: 6px; }
.app-stat {
  display: flex; align-items: baseline; gap: 6px;
  padding: 5px 12px; border-radius: 8px;
  background: hsl(var(--secondary)); text-decoration: none;
  transition: background .12s;
}
.app-stat:hover { background: hsl(var(--muted)); text-decoration: none; }
.app-stat-num {
  font-size: 16px; font-weight: 700; font-family: var(--font-mono);
  color: hsl(var(--foreground)); line-height: 1;
}
.app-stat-num.alert { color: hsl(var(--accent)); }
.app-stat-label {
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: hsl(var(--muted-foreground));
}

.app-user { margin-left: auto; position: relative; flex-shrink: 0; }
.app-user-btn {
  display: flex; align-items: center; gap: 9px;
  padding: 5px 8px 5px 5px; border-radius: 10px;
  background: hsl(var(--secondary)); border: 1px solid hsl(var(--border));
  cursor: pointer; transition: background .12s;
}
.app-user-btn:hover { background: hsl(var(--muted)); }
.app-user-av {
  width: 32px; height: 32px; border-radius: 50%;
  background: hsl(var(--primary)); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 11.5px; font-weight: 700; flex-shrink: 0;
}
.app-user-meta { text-align: left; line-height: 1.25; max-width: 200px; }
.app-user-name {
  font-size: 12.5px; font-weight: 600; color: hsl(var(--foreground));
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.app-user-email {
  font-size: 10.5px; color: hsl(var(--muted-foreground));
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.app-user-plan {
  font-size: 9.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: hsl(var(--accent));
}
.app-user-caret { width: 14px; height: 14px; color: hsl(var(--muted-foreground)); stroke-width: 2.5; }
.app-user-menu {
  position: absolute; right: 0; top: calc(100% + 8px);
  width: 220px; background: hsl(var(--card));
  border: 1px solid hsl(var(--border)); border-radius: 11px;
  padding: 6px; z-index: 50;
}
.app-user-menu-head { padding: 9px 10px 10px; border-bottom: 1px solid hsl(var(--border)); margin-bottom: 5px; }
.app-user-menu-head .n { font-size: 13px; font-weight: 600; color: hsl(var(--foreground)); }
.app-user-menu-head .e { font-size: 11px; color: hsl(var(--muted-foreground)); margin-top: 1px; }
.app-user-menu a, .app-user-menu button {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 8px 10px; border-radius: 7px; font-size: 13px;
  color: hsl(var(--foreground)); text-decoration: none;
  background: transparent; border: 0; cursor: pointer; text-align: left;
  font-family: var(--font-sans);
}
.app-user-menu a:hover { background: hsl(var(--secondary)); text-decoration: none; }
.app-user-menu button:hover { background: hsl(var(--destructive) / .08); color: hsl(var(--destructive)); }
.app-user-menu svg { width: 15px; height: 15px; stroke-width: 2; }
.app-user-menu .ti { font-size: 16px; }

/* ════════ BODY = SIDEBAR + CONTENT ════════ */
.app-body { display: flex; min-height: calc(100vh - 58px); }

/* ── Sidebar — dark-slate surface (Decision 17 / idea #68): activates the
   --sidebar token family. Single active indicator = orange left rail +
   orange-tinted icon. ── */
.app-sidebar {
  width: 218px; flex-shrink: 0;
  background: hsl(var(--sidebar));
  border-right: 1px solid hsl(var(--sidebar-border));
  padding: 14px 10px;
  position: sticky; top: var(--ld-topbar-h, 58px); height: calc(100vh - var(--ld-topbar-h, 58px));
  overflow-y: auto;
  display: flex; flex-direction: column;
}
.app-side-label {
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .08em; color: hsl(var(--sidebar-foreground) / .42);
  margin: 12px 10px 4px;
}
.app-side-label:first-child { margin-top: 2px; }

/* collapsible section headers — render as muted group labels with a chevron */
.app-side-section { margin-bottom: 2px; }
.app-side-section-btn {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; padding: 9px 10px 5px; border-radius: 8px;
  background: transparent; border: 0; cursor: pointer; text-align: left;
  font-family: var(--font-sans);
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .07em; color: hsl(var(--sidebar-foreground) / .5);
  transition: color .12s;
}
.app-side-section-btn:hover { color: hsl(var(--sidebar-foreground) / .85); }
.app-side-section-btn.open { color: hsl(var(--sidebar-foreground) / .85); }
.app-side-section-btn .sec-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-side-section-chev {
  width: 13px; height: 13px; flex-shrink: 0; opacity: .55;
  transition: transform .15s ease;
}
.app-side-section-btn.open .app-side-section-chev { transform: rotate(180deg); opacity: .85; }
.app-side-section-body { padding: 1px 0 8px; }

/* nav links (top-level + section sub-links share one look) */
.app-side-link, .app-side-sublink {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 9px;
  color: hsl(var(--sidebar-foreground) / .78); text-decoration: none;
  transition: background .12s, color .12s; margin-bottom: 1px;
}
.app-side-link { font-size: 13px; }
.app-side-sublink { font-size: 12.5px; padding-left: 12px; }
.app-side-link:hover, .app-side-sublink:hover {
  background: hsl(var(--sidebar-accent) / .6);
  color: hsl(var(--sidebar-foreground)); text-decoration: none;
}
.app-side-link.active, .app-side-sublink.active {
  background: hsl(var(--sidebar-accent));
  color: hsl(var(--sidebar-foreground)); font-weight: 500;
}
.app-side-link-disabled {
  opacity: .45; cursor: default; pointer-events: none;
}
.app-side-link-disabled:hover { background: transparent; }
.app-side-link-disabled .app-side-badge {
  background: hsl(var(--muted-foreground) / .5);
}
.app-side-link .ti, .app-side-sublink .ti {
  font-size: 18px; width: 18px; text-align: center; line-height: 1;
  opacity: .82; flex-shrink: 0;
}
.app-side-sublink .ti { font-size: 16px; }
.app-side-link.active .ti, .app-side-sublink.active .ti {
  color: hsl(var(--sidebar-primary)); opacity: 1;
}
.app-side-link.active::before, .app-side-sublink.active::before {
  content: ""; position: absolute; left: -10px; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 18px; border-radius: 0 3px 3px 0;
  background: hsl(var(--sidebar-primary));
}
.app-side-badge {
  margin-left: auto; min-width: 18px; height: 17px; padding: 0 6px;
  border-radius: 999px; background: hsl(var(--sidebar-primary)); color: #fff;
  font-size: 10px; font-weight: 600; font-family: var(--font-mono);
  display: flex; align-items: center; justify-content: center;
}
.app-side-divider { height: 1px; background: hsl(var(--sidebar-border)); margin: 12px 8px; }

/* ── Sidebar foot (pinned bottom: back to all firms/companies) ── */
.app-side-foot { margin-top: auto; padding-top: 12px; }
.app-side-foot a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 9px; font-size: 12px;
  color: hsl(var(--sidebar-foreground) / .55); text-decoration: none;
}
.app-side-foot a:hover { background: hsl(var(--sidebar-accent) / .6); color: hsl(var(--sidebar-foreground)); text-decoration: none; }
.app-side-foot .ti { font-size: 16px; width: 18px; text-align: center; flex-shrink: 0; }

/* ── Icon rail — used on reports (a second, report-specific sidebar is present).
   Same menu, condensed to icons only. ── */
.app-sidebar--rail { width: 58px; padding: 12px 7px; }
.app-sidebar--rail .app-side-section-btn,
.app-sidebar--rail .app-side-label { display: none; }
.app-sidebar--rail .app-side-section { margin-bottom: 4px; }
.app-sidebar--rail .app-side-section-body { padding: 0; }
.app-sidebar--rail .app-side-link,
.app-sidebar--rail .app-side-sublink,
.app-sidebar--rail .app-side-foot a { justify-content: center; padding-left: 0; padding-right: 0; }
.app-sidebar--rail .app-side-link span,
.app-sidebar--rail .app-side-sublink span,
.app-sidebar--rail .app-side-foot span { display: none; }
.app-sidebar--rail .app-side-link.active::before,
.app-sidebar--rail .app-side-sublink.active::before { left: -7px; }

/* ── Content ── */
.app-content { flex: 1; min-width: 0; }
.app-content-wrap { max-width: 1000px; margin: 0 auto; padding: 32px 40px 60px; }

/* ── Active-scope chip (idea #68) — replaces the old inline-styled breadcrumb ── */
.app-scope-chip { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.app-scope-chip .pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 4px 11px; border: 1px solid hsl(var(--border));
  border-radius: 999px; background: hsl(var(--muted) / .4);
}
.app-scope-chip .dot { width: 6px; height: 6px; border-radius: 999px; background: hsl(var(--primary)); }
.app-scope-chip .kind {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .04em; color: hsl(var(--muted-foreground));
}
.app-scope-chip .name { color: hsl(var(--foreground)); font-family: var(--font-mono); font-size: 11.5px; }

/* ── Page heading ── */
.app-page-eyebrow {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .14em; color: hsl(var(--accent));
}
.app-page-headline {
  font-size: 26px; font-weight: 700; letter-spacing: -.03em;
  margin-top: 3px; color: hsl(var(--foreground));
}
.app-page-dateline { font-size: 13px; color: hsl(var(--muted-foreground)); margin-top: 4px; }

/* ════════ TOP-BAR COMPANY SWITCHER ════════ */
.app-co-sw { position: relative; flex-shrink: 0; }
.app-co-sw-btn {
  display: flex; align-items: center; gap: 10px;
  padding: 5px 10px 5px 5px; border-radius: 9px;
  background: hsl(var(--secondary)); border: 1px solid hsl(var(--border));
  cursor: pointer; transition: background .12s;
  min-width: 220px; max-width: 320px; color: hsl(var(--foreground));
  font-family: var(--font-sans); text-align: left;
}
.app-co-sw-btn:hover { background: hsl(var(--muted)); }
.app-co-sw-logo {
  width: 30px; height: 30px; border-radius: 7px; flex-shrink: 0;
  background: hsl(var(--primary)); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 11px;
}
.app-co-sw-id { flex: 1; min-width: 0; }
.app-co-sw-nm {
  font-size: 12.5px; font-weight: 600; line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.app-co-sw-meta {
  font-family: var(--font-mono); font-size: 10px;
  color: hsl(var(--muted-foreground)); margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.app-co-sw-chev { width: 14px; height: 14px; flex-shrink: 0; color: hsl(var(--muted-foreground)); }
.app-co-sw-menu {
  position: absolute; top: calc(100% + 8px); left: 0;
  min-width: 300px; max-width: 360px;
  background: hsl(var(--card)); border: 1px solid hsl(var(--border));
  border-radius: 10px; padding: 6px; z-index: 50;
  max-height: 70vh; overflow-y: auto;
}
.app-co-sw-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 7px;
  text-decoration: none; color: hsl(var(--foreground));
}
.app-co-sw-row:hover { background: hsl(var(--secondary)); text-decoration: none; }
.app-co-sw-row.active { background: hsl(var(--secondary)); }
.app-co-sw-row-lg {
  width: 28px; height: 28px; border-radius: 6px; flex-shrink: 0;
  background: hsl(var(--primary)); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 10.5px;
}
.app-co-sw-row-body { flex: 1; min-width: 0; }
.app-co-sw-row-nm { font-size: 13px; font-weight: 600; line-height: 1.25; }
.app-co-sw-row-st { font-family: var(--font-mono); font-size: 10.5px; color: hsl(var(--muted-foreground)); }
.app-co-sw-foot { border-top: 1px solid hsl(var(--border)); margin-top: 4px; padding-top: 2px; }

/* ════════ REUSABLE SETTINGS / CARD PRIMITIVES ════════
   Used by the settings pages (profile, company/firm preferences) and anywhere
   a stat row, titled card, key/value row, form grid, or icon mini-card repeats.
   These replace the copy-pasted markup the audit flagged. */
.ld-stat-tiles {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px; margin-bottom: 16px;
}
.ld-stat-tile {
  background: hsl(var(--card)); border: 1px solid hsl(var(--card-border));
  border-radius: 10px; padding: 13px 15px;
}
.ld-stat-label { font-size: 11px; color: hsl(var(--muted-foreground)); margin-bottom: 4px; }
.ld-stat-value { font-family: var(--font-mono); font-size: 21px; font-weight: 600; color: hsl(var(--foreground)); line-height: 1.1; }

.ld-scard {
  background: hsl(var(--card)); border: 1px solid hsl(var(--card-border));
  border-radius: 12px; padding: 16px 18px; margin-bottom: 14px;
}
.ld-scard-head { display: flex; align-items: center; gap: 9px; margin-bottom: 12px; }
.ld-scard-head .ti { font-size: 18px; color: hsl(var(--primary)); }
.ld-scard-title { font-size: 13.5px; font-weight: 600; color: hsl(var(--foreground)); }

.ld-row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 9px 0; border-top: 1px solid hsl(var(--card-border)); font-size: 12.5px;
}
.ld-row .k { color: hsl(var(--muted-foreground)); }
.ld-row .v { color: hsl(var(--foreground)); font-weight: 500; }
.ld-row .v.mono { font-family: var(--font-mono); font-size: 11.5px; font-weight: 400; }

.ld-fgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ld-field { min-width: 0; }
.ld-field > label { display: block; font-size: 11.5px; font-weight: 500; color: hsl(var(--foreground)); margin-bottom: 5px; }

.ld-minis { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.ld-mini {
  display: flex; gap: 11px; align-items: flex-start;
  background: hsl(var(--card)); border: 1px solid hsl(var(--card-border));
  border-radius: 11px; padding: 13px 15px; text-decoration: none;
  transition: background .12s;
}
.ld-mini:hover { background: hsl(var(--secondary)); text-decoration: none; }
.ld-mini .ic {
  width: 34px; height: 34px; flex-shrink: 0; border-radius: 9px;
  background: hsl(var(--primary) / .08); color: hsl(var(--primary));
  display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.ld-mini .t { font-size: 12.5px; font-weight: 600; color: hsl(var(--foreground)); margin: 0 0 2px; }
.ld-mini .d { font-size: 11px; color: hsl(var(--muted-foreground)); margin: 0; line-height: 1.4; }

@media (max-width: 720px) {
  .ld-fgrid { grid-template-columns: 1fr; }
}
