/* Agency identity is shared across every workspace without altering LeadFlow's existing themes. */
#agencySidebarIdentity.agency-sidebar-identity {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0 16px;
  padding: 12px 10px;
  min-height: 88px;
  border: 1px solid rgba(211, 172, 93, .65);
  border-radius: 14px;
  color: #f8f5ed;
  background: linear-gradient(135deg, #102d44, #071b2e);
  box-shadow: 0 8px 20px rgba(0,0,0,.12), inset 0 1px rgba(255,255,255,.07);
}
#agencySidebarIdentity.hidden { display: none !important; }
#agencySidebarIdentity .agency-sidebar-logo-wrap {
  flex: 0 0 64px; width: 64px; height: 64px; display: grid; place-items: center;
  background: transparent; overflow: hidden;
}
#agencySidebarIdentity img { width: 100%; height: 100%; object-fit: contain; padding: 0; }
#agencySidebarIdentity #agencySidebarFallback { display: grid; place-items: center; color: #a56d21; }
#agencySidebarIdentity #agencySidebarFallback svg { height: 24px; width: 24px; }
#appScreen #agencySidebarIdentity #agencySidebarName {
  min-width: 0; flex: 1; color: #fff !important; -webkit-text-fill-color: #fff !important;
  font-size: 14px; font-family: Georgia, "Times New Roman", serif;
  font-weight: 700; line-height: 1.35; overflow-wrap: anywhere; opacity: 1;
}
#agencyLeaderboardMark.agency-leaderboard-mark { display: none; }
body.leaderboard-page-active.has-agency-brand #agencyLeaderboardMark.agency-leaderboard-mark {
  display: grid; place-items: center; position: static; z-index: 1;
  width: 120px; height: 120px; transform: none;
  overflow: hidden; background: transparent;
  color: #b98938;
}
#agencyLeaderboardMark img { width:100%; height:100%; object-fit:contain; }
#agencyLeaderboardMark svg { width: 55px; height: 55px; stroke-width: 1.5; }
body.leaderboard-page-active.has-agency-brand #appScreen .top-header {
  position: relative; display: grid; grid-template-columns: 120px minmax(0,1fr) auto;
  gap: 20px; padding: 12px 0 22px !important;
  min-height: 154px; align-items: center; margin-bottom: 20px;
}
body.leaderboard-page-active.has-agency-brand #appScreen .top-header .page-heading-copy { min-width: 0; }
html[data-leadflow-theme] body.leaderboard-page-active.has-agency-brand #appScreen .top-header #pageEyebrow {
  letter-spacing: .2em !important; font-weight: 700; margin: 0 0 6px;
  font-size: 12px; color: #a67320 !important; -webkit-text-fill-color: #a67320 !important;
}
body.leaderboard-page-active.has-agency-brand #appScreen .top-header #pageEyebrow::after {
  content: "✦"; display: inline-block; margin-left: 12px; color: #d5a653; font-size: 17px;
}
body.leaderboard-page-active.has-agency-brand #appScreen .top-header #pageTitle {
  max-width: none; margin: 0; font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(32px, 3.25vw, 54px); font-weight: 600;
  letter-spacing: -.035em; line-height: 1.12;
  overflow-wrap: anywhere;
}
body.leaderboard-page-active.has-agency-brand #appScreen .top-header #pageTitle::after { display: none; }
html[data-leadflow-theme="dark"] body.leaderboard-page-active.has-agency-brand #appScreen .top-header #pageEyebrow,
html[data-leadflow-theme="gold"] body.leaderboard-page-active.has-agency-brand #appScreen .top-header #pageEyebrow {
  color: #e3bd79 !important; -webkit-text-fill-color: #e3bd79 !important;
}
body.leaderboard-page-active .top-header #pageSubtitle { display: none !important; }
/* Preserve the existing podium and cards. No separate agency banner is added. */
body.leaderboard-page-active .leaderboard-page-header { display: none !important; }

#agencyBrandSettings.agency-brand-settings { border-radius: 16px; }
#agencyBrandSettings.hidden { display: none !important; }
.agency-brand-settings-layout { display: flex; align-items: flex-start; gap: 24px; padding: 6px 0 0; }
.agency-brand-preview {
  width: 135px; height: 135px; flex: 0 0 135px; display: grid; place-items: center;
  overflow: hidden; border-radius: 17px; border: 1px solid rgba(160,162,177,.3);
  background: repeating-conic-gradient(#e7eaf0 0% 25%, #fff 0% 50%) 50% / 16px 16px; color: #a77831;
}
.agency-brand-preview img { width: 100%; height: 100%; object-fit: contain; padding: 10px; }
.agency-brand-preview svg { width: 48px; height: 48px; }
.agency-brand-settings-fields { display:flex; flex-direction:column; gap: 8px; min-width:0; flex:1; }
.agency-brand-settings-fields label { font-size: 12px; font-weight: 700; }
.agency-brand-settings-fields input[type=text] {
  width:100%; min-height:43px; padding:8px 12px; border:1px solid #aeb9c9;
  border-radius: 10px; background: var(--surface, #fff); color: inherit;
}
.agency-brand-settings-fields input[type=file] { max-width:100%; font-size:12px; }
.agency-brand-settings-fields small { color: var(--muted, #64748b); font-size: 12px; }
.agency-brand-actions { display: flex; flex-wrap:wrap; gap: 9px; margin-top: 5px; }
#agencyBrandMessage { margin: 0; min-height:18px; font-size:12px; }
.agency-co-owner-editor {
  margin: 12px 0 17px; padding: 15px;
  border: 1px solid rgba(160,162,177,.32);
  border-radius: 14px; background: rgba(124,139,166,.05);
}
.agency-co-owner-heading { display:flex; flex-direction:column; gap:5px; margin-bottom: 13px; }
.agency-co-owner-heading strong { font-size: 15px; }
.agency-co-owner-heading small { font-size: 12px; opacity: .78; }
.agency-co-owner-editor > label { display:flex; flex-direction:column; gap:6px; }
.agency-co-owner-editor select,
.agency-co-owner-editor input {
  min-height: 40px; padding: 8px 12px; border-radius:9px;
  border: 1px solid #aab6c9; background: var(--surface, #fff); color: inherit; width:100%;
}
.agency-co-owner-create { margin-top: 12px; }
.agency-co-owner-create.hidden { display: none !important; }
.agency-co-owner-actions { display:flex; align-items:center; gap:10px; margin-top:12px; flex-wrap:wrap; }
#agencyCoOwnerMessage { font-size: 12px; }
#appScreen.sidebar-collapsed #agencySidebarIdentity:not(.hidden) { display:flex !important; padding:7px; margin:8px 0 12px; min-height:54px; justify-content:center; }
#appScreen.sidebar-collapsed #agencySidebarIdentity .agency-sidebar-logo-wrap { width:40px; height:40px; flex-basis:40px; }
#appScreen.sidebar-collapsed #agencySidebarIdentity #agencySidebarName { display:none; }
@media (max-width: 1250px) and (min-width: 761px) {
  body.leaderboard-page-active.has-agency-brand #appScreen .top-header { grid-template-columns:100px minmax(0,1fr); gap:10px 18px; }
  body.leaderboard-page-active.has-agency-brand #agencyLeaderboardMark.agency-leaderboard-mark { width:100px; height:100px; grid-row:1 / 3; }
  body.leaderboard-page-active.has-agency-brand #appScreen .top-header .top-header-actions { grid-column:2; justify-content:flex-start; }
}
@media (max-width: 760px) {
  body.leaderboard-page-active.has-agency-brand #appScreen .top-header { grid-template-columns:74px minmax(0,1fr); gap:12px; min-height:100px; padding:8px 0 18px !important; }
  body.leaderboard-page-active.has-agency-brand #agencyLeaderboardMark.agency-leaderboard-mark {
    width:74px; height:80px;
  }
  body.leaderboard-page-active.has-agency-brand #appScreen .top-header #pageTitle {
    max-width: none; font-size: clamp(25px, 6vw, 34px);
  }
  body.leaderboard-page-active.has-agency-brand #appScreen .top-header #pageEyebrow { font-size:10px; letter-spacing:.12em !important; }
  body.leaderboard-page-active.has-agency-brand #appScreen .top-header .top-header-actions { grid-column:1 / -1; display:grid; grid-template-columns:40px minmax(0,1fr) minmax(0,1.2fr); gap:8px; align-items:stretch; width:100%; overflow:visible; }
  body.leaderboard-page-active.has-agency-brand #appScreen .top-header-actions > * { min-width:0; width:auto; }
  body.leaderboard-page-active.has-agency-brand #appScreen .top-header-actions :is(.top-pill,.profile-pill) { height:auto; min-height:44px; padding:6px 8px; gap:7px; }
  body.leaderboard-page-active.has-agency-brand #appScreen .top-header-actions .notification-pill { width:40px; height:44px; }
  body.leaderboard-page-active.has-agency-brand #appScreen .profile-pill > div:last-child { min-width:0; overflow-wrap:anywhere; }
  body.leaderboard-page-active.has-agency-brand #appScreen #topProfileName { white-space:normal; }
  .agency-brand-settings-layout { flex-direction: column; gap: 13px; }
  .agency-brand-preview { width: 105px; height: 105px; flex-basis:105px; }
}

/* Inputs inherit each luxury theme's surface and foreground together. */
html[data-leadflow-theme="dark"] body:not(.app-login-mode) :is(
  .agency-brand-settings-fields input[type=text], .agency-co-owner-editor input, .agency-co-owner-editor select
) {
  background: #25203d; border-color: rgba(183,167,236,.42); color: #f8f3ff;
}
html[data-leadflow-theme="gold"] body:not(.app-login-mode) :is(
  .agency-brand-settings-fields input[type=text], .agency-co-owner-editor input, .agency-co-owner-editor select
) {
  background: #181b20; border-color: rgba(219,180,106,.4); color: #faf1dc;
}
html[data-leadflow-theme="light"] body:not(.app-login-mode) :is(
  .agency-brand-settings-fields input[type=text], .agency-co-owner-editor input, .agency-co-owner-editor select
) { background: #fff; color: #0f2744; }

/* Four metrics, followed immediately by the existing period/view controls. */
#appScreen #leaderboardPage .leaderboard-hero-row { display:grid; grid-template-columns:minmax(0,1fr); gap:18px; margin-bottom:16px; }
#appScreen #leaderboardPage .leaderboard-summary-grid { grid-template-columns:repeat(4,minmax(0,1fr)) !important; gap:16px; }
#appScreen #leaderboardPage .leaderboard-summary-card { min-height:112px; padding:18px 16px; gap:14px; }
#appScreen #leaderboardPage .leaderboard-summary-copy small { font-size:13px; line-height:1.35; }
#appScreen #leaderboardPage .leaderboard-summary-copy strong { font-size:clamp(23px,2vw,30px); line-height:1.25; }
#appScreen #leaderboardPage .leaderboard-summary-delta { line-height:1.45; font-size:12px; }
#appScreen #leaderboardPage .leaderboard-filters-row { display:flex; flex-direction:row; flex-wrap:wrap; align-items:flex-end; justify-content:flex-start; gap:14px; margin-top:0; }
#appScreen #leaderboardPage .leaderboard-period-control { padding:0; justify-content:flex-start; flex-wrap:wrap; }
#appScreen #leaderboardPage .leaderboard-scope-control { display:flex; align-items:center; gap:8px; }
#appScreen #leaderboardPage .leaderboard-scope-control > label { font-size:12px; font-weight:700; text-transform:none; letter-spacing:0; margin:0; }
#appScreen #leaderboardPage .leaderboard-period-select-wrap { min-width:142px; }
#appScreen #leaderboardPage .leaderboard-period-select-wrap select { height:44px; border-radius:10px; }
#appScreen #leaderboardPage .leaderboard-podium-stage { min-height:350px !important; height:auto !important; padding:22px 22px 38px !important; border-radius:18px; }
#appScreen #leaderboardPage .leaderboard-podium { max-width:1040px !important; padding:0 30px !important; gap:22px !important; }
#appScreen #leaderboardPage .leaderboard-podium-card { height:auto !important; min-height:242px !important; padding:24px 18px 22px !important; gap:9px !important; border-radius:20px 20px 12px 12px; }
#appScreen #leaderboardPage .leaderboard-podium-card.rank-1 { min-height:286px !important; padding-top:32px !important; }
#appScreen #leaderboardPage .leaderboard-podium-card.rank-3 { min-height:242px !important; }
#appScreen #leaderboardPage .leaderboard-agent-heading { min-width:0; width:100%; }
#appScreen #leaderboardPage .leaderboard-agent-heading strong { font-size:22px; line-height:1.15; overflow-wrap:anywhere; }
#appScreen #leaderboardPage .rank-1 .leaderboard-agent-heading strong { font-size:26px; }
#appScreen #leaderboardPage .leaderboard-agent-metrics { width:100%; margin-top:auto; padding-top:13px; gap:8px; }
#appScreen #leaderboardPage .leaderboard-agent-metrics span { font-size:12px; line-height:1.35; }
html[data-leadflow-theme] body[data-leadflow-theme]:not(.app-login-mode) #appScreen #leaderboardPage .leaderboard-celebration { z-index:0 !important; background:transparent !important; box-shadow:none !important; }
#appScreen #leaderboardPage .leaderboard-confetti-rain { opacity:.65; }
#appScreen #leaderboardPage .leaderboard-confetti-piece { filter:none; }
html[data-leadflow-theme] body[data-leadflow-theme]:not(.app-login-mode) #appScreen #leaderboardPage .leaderboard-celebration .leaderboard-confetti-piece { color:var(--crm-primary,#183e67) !important; }
html[data-leadflow-theme] body[data-leadflow-theme]:not(.app-login-mode) #appScreen #leaderboardPage .leaderboard-celebration .leaderboard-confetti-piece:nth-child(3n+1) { color:#d7a33d !important; }
html[data-leadflow-theme] body[data-leadflow-theme]:not(.app-login-mode) #appScreen #leaderboardPage .leaderboard-celebration .leaderboard-confetti-piece:nth-child(3n+2) { color:var(--crm-trim,#b88a38) !important; }
#appScreen #leaderboardPage .leaderboard-panel { border-radius:16px; overflow:hidden; }
#appScreen #leaderboardPage .leaderboard-table th { padding:14px 18px; font-size:13px; }
#appScreen #leaderboardPage .leaderboard-table td { padding:13px 18px; }
#appScreen .organization-agency-owners { white-space:normal; overflow-wrap:anywhere; }
@media (min-width: 961px) and (max-width: 1200px) {
  #appScreen #leaderboardPage .leaderboard-summary-card { gap:10px; padding:14px 12px; }
  #appScreen #leaderboardPage .leaderboard-summary-icon { width:38px; height:38px; flex-basis:38px; }
  #appScreen #leaderboardPage .leaderboard-summary-copy small { font-size:12px; }
}
@media (max-width: 960px) {
  #appScreen #leaderboardPage .leaderboard-summary-grid { grid-template-columns:repeat(2,minmax(0,1fr)) !important; gap:12px; }
  #appScreen #leaderboardPage .leaderboard-podium-stage { padding:30px 18px !important; }
  #appScreen #leaderboardPage .leaderboard-podium { padding:10px 4px 16px !important; gap:44px !important; max-width:520px !important; }
  #appScreen #leaderboardPage .leaderboard-podium-card.rank-1 { order:-1; }
  #appScreen #leaderboardPage .leaderboard-reference-platform { display:block !important; left:-6px !important; right:-6px !important; bottom:-24px !important; height:30px !important; }
  #appScreen #leaderboardPage .leaderboard-reference-platform-rank-1 { left:-10px !important; right:-10px !important; height:36px !important; }
}
@media (max-width: 540px) {
  #appScreen #leaderboardPage .leaderboard-summary-card { padding:14px 12px; gap:9px; flex-wrap:wrap; align-content:flex-start; }
  #appScreen #leaderboardPage .leaderboard-summary-icon { width:34px; height:34px; flex-basis:34px; }
  #appScreen #leaderboardPage .leaderboard-summary-icon svg { width:20px; height:20px; }
  #appScreen #leaderboardPage .leaderboard-summary-copy { flex-basis:100%; }
  #appScreen #leaderboardPage .leaderboard-summary-copy small { min-height:34px; }
  #appScreen #leaderboardPage .leaderboard-summary-delta { font-size:11px; white-space:normal; }
  #appScreen #leaderboardPage .leaderboard-mini-bars { display:none; }
  #appScreen #leaderboardPage .leaderboard-filters-row { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); align-items:start; gap:12px; }
  #appScreen #leaderboardPage .leaderboard-filters-row:has(#leaderboardCustomDateWrap:not(.hidden)) { grid-template-columns:minmax(0,1fr); }
  #appScreen #leaderboardPage .leaderboard-period-control,
  #appScreen #leaderboardPage .leaderboard-scope-control { align-items:flex-start; flex-direction:column; gap:6px; }
  #appScreen #leaderboardPage .leaderboard-period-select-wrap { min-width:0; width:100%; }
  #appScreen #leaderboardPage .leaderboard-table { min-width:0; width:100%; }
  #appScreen #leaderboardPage .leaderboard-table th,
  #appScreen #leaderboardPage .leaderboard-table td { padding:12px 8px; font-size:12px; white-space:normal; overflow-wrap:anywhere; }
  #appScreen #leaderboardPage .leaderboard-table th:first-child { width:14%; white-space:nowrap; }
  #appScreen #leaderboardPage .leaderboard-table th:nth-child(2) { width:35%; }
  #appScreen #leaderboardPage .leaderboard-table th:nth-child(3) { width:29%; }
  #appScreen #leaderboardPage .leaderboard-table th:nth-child(4) { width:22%; }
  #appScreen #leaderboardPage .leaderboard-table-agent { gap:6px; }
  #appScreen #leaderboardPage .leaderboard-table-agent strong { font-size:13px; overflow-wrap:anywhere; }
  #appScreen #leaderboardPage .leaderboard-table-avatar { display:none; }
}
@media (prefers-reduced-motion:reduce) { #appScreen #leaderboardPage .leaderboard-confetti-piece { animation:none !important; } }

/* Keyboard-accessible crop editor with the same two placements as the saved logo. */
#agencyLogoEditor { box-sizing:border-box; width:min(920px,calc(100% - 24px)); max-height:calc(100dvh - 28px); padding:24px; border:1px solid var(--crm-trim-line,#cbb88c); border-radius:20px; background:var(--crm-surface,#fff); color:var(--crm-text,#102b43); box-shadow:0 24px 90px #0006; overflow:auto; }
#agencyLogoEditor::backdrop { background:rgba(5,16,30,.65); backdrop-filter:blur(3px); }
#agencyLogoEditor * { box-sizing:border-box; }
#agencyLogoEditor :is(h2,h3,p) { margin:0; color:inherit; }
#agencyLogoEditor h2 { font:600 24px/1.2 Georgia,serif; }
#agencyLogoEditor h3 { font-size:15px; }
#agencyLogoEditor p { font-size:13px; line-height:1.5; }
#agencyLogoEditor .agency-logo-editor-heading { display:flex; align-items:flex-start; justify-content:space-between; gap:16px; margin-bottom:20px; }
#agencyLogoEditor .agency-logo-editor-heading p { margin-top:8px; max-width:570px; }
#agencyLogoEditor .agency-logo-editor-layout { display:grid; grid-template-columns:minmax(0,1.2fr) minmax(0,1fr); gap:24px; }
#agencyLogoCropCanvas { display:block; max-width:100%; width:auto; height:auto; max-height:340px; margin:0 auto; touch-action:none; cursor:crosshair; background:repeating-conic-gradient(#e7eaf0 0% 25%,#fff 0% 50%) 50% / 16px 16px; }
#agencyLogoEditor .agency-logo-editor-hint { color:var(--crm-muted,#526279); margin:10px 0; font-size:12px; }
#agencyLogoEditor .agency-logo-crop-controls { display:grid; grid-template-columns:1fr 1fr; gap:12px 16px; margin:16px 0; }
#agencyLogoEditor .agency-logo-crop-controls label,
#agencyLogoEditor .agency-logo-tolerance { display:grid; grid-template-columns:1fr auto; gap:6px; font-size:12px; font-weight:600; }
#agencyLogoEditor input[type=range] { width:100%; grid-column:1 / -1; accent-color:var(--crm-accent,#9b742a); min-height:24px; }
#agencyLogoEditor .agency-logo-placement { display:flex; align-items:center; gap:14px; padding:16px 14px; border-radius:14px; margin:14px 0; min-height:102px; }
#agencyLogoEditor .agency-logo-placement canvas { width:80px; height:80px; object-fit:contain; flex:none; }
#agencyLogoEditor .agency-logo-placement-header { background:#faf9f5; color:#102b43; border:1px solid #dce1e8; }
#agencyLogoEditor .agency-logo-placement-header div { min-width:0; }
#agencyLogoEditor .agency-logo-placement-header small { color:#946515; letter-spacing:.1em; font-size:9px; }
#agencyLogoEditor .agency-logo-placement-header strong { display:block; color:#102b43; -webkit-text-fill-color:#102b43; font:600 22px/1.15 Georgia,serif; margin-top:4px; overflow-wrap:anywhere; }
#agencyLogoEditor .agency-logo-placement-sidebar { background:linear-gradient(135deg,#102d44,#071b2e); border:1px solid #b29559; }
#agencyLogoEditor .agency-logo-placement-sidebar canvas { width:64px; height:64px; }
#agencyLogoEditor .agency-logo-placement-sidebar strong { color:#fff; -webkit-text-fill-color:#fff; font:700 16px/1.3 Georgia,serif; overflow-wrap:anywhere; }
#agencyLogoEditor .agency-logo-background-option { display:flex; align-items:center; gap:9px; margin-top:20px; font-size:14px; }
#agencyLogoEditor input[type=checkbox] { width:18px; height:18px; accent-color:var(--crm-accent,#9b742a); }
#agencyLogoEditorStatus { margin-top:14px !important; min-height:38px; font-size:12px !important; }
#agencyLogoEditor .agency-logo-editor-footer { display:flex; justify-content:space-between; align-items:center; gap:18px; padding-top:20px; margin-top:20px; border-top:1px solid var(--crm-line,#dce1e8); }
#agencyLogoEditor .agency-logo-editor-footer span { font-size:12px; max-width:350px; color:var(--crm-muted,#526279); }
#agencyLogoEditor button { white-space:normal; }
#agencyLogoEditor :focus-visible { outline:2px solid var(--crm-accent,#9b742a); outline-offset:3px; }
@media (max-width:640px) {
  #agencyLogoEditor { padding:18px; }
  #agencyLogoEditor .agency-logo-editor-layout { grid-template-columns:1fr; gap:20px; }
  #agencyLogoEditor .agency-logo-editor-footer { flex-direction:column; align-items:stretch; }
  #agencyLogoEditor .agency-logo-editor-footer button { width:100%; }
  #agencyLogoEditor h2 { font-size:21px; }
}
