/* web/pages/home.css 27-03-2026 v1.8
   Home (index) only. Scoped by html[data-page="home"] to avoid leaking into other apps.
*/

@layer utilities {
  html[data-page="home"] {
    --stage-max: 1180px;
    --tile-min-h: 140px;
  }

  /* Layout width for index containers */
  html[data-page="home"] .container {
    max-width: var(--stage-max, 1180px);
    margin: 0 auto;
    padding: 12px 20px 28px;
  }

  /* Page intro + avatar */
  html[data-page="home"] .page-intro {
    margin: 18px 0 10px;
  }

  html[data-page="home"] .welcome-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 6px;
  }

  /* Use your existing avatar look but scoped */
  html[data-page="home"] .avatar {
    --size: clamp(52px, 6vw, 74px);
    width: var(--size);
    height: var(--size);
    border-radius: 999px;
    overflow: hidden;
    flex: 0 0 auto;
    background: #DDD;
    border: 3px solid rgba(70, 30, 92, .4);
    box-shadow: 0 1px 2px rgba(0, 0, 0, .08);
  }

  html[data-page="home"] .avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
  }

  @supports (color: color-mix(in srgb, white 50%, black)) {
    html[data-page="home"] .avatar {
      border-color: color-mix(in srgb, var(--accent) 40%, var(--brand-gold) 20%);
    }
  }

  html[data-page="home"] .avatar.is-empty::after {
    content: "✦";
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    font-size: calc(var(--size) * .46);
    color: var(--brand-gold);
  }

  /* Section framing */
  html[data-page="home"] .backdrop {
    border-radius: 14px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    padding: 16px;
  }

  html[data-page="home"] .section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    padding-bottom: 6px;
    margin: 10px 0 12px;
    border-bottom: 2px solid rgba(70, 30, 92, .12);
  }

  @supports (color: color-mix(in srgb, white 50%, black)) {
    html[data-page="home"] .section-head {
      border-bottom: 2px solid color-mix(in srgb, var(--accent) 12%, transparent);
    }
  }

  html[data-page="home"] .section-subtitle {
    margin: 0;
    font-size: 13px;
    color: var(--muted);
    line-height: 1.3;
  }

  /* Index grids (3 → 2 → 1) */
  html[data-page="home"] .grid-3 {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  @media (max-width: 980px) {
    html[data-page="home"] .grid-3 {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
  }

  @media (max-width: 640px) {
    html[data-page="home"] .grid-3 {
      grid-template-columns: 1fr;
    }
  }

  /* Brand tiles (scoped; keep your current scheme) */
  html[data-page="home"] .group-sales .tool {
    background: var(--c-accent);
    border-color: var(--d-accent-pressed);
    color: #fff;
    min-height: var(--tile-min-h);
  }
  html[data-page="home"] .group-sales .tool .tool-title { color: #fff; }
  html[data-page="home"] .group-sales .tool small { color: color-mix(in srgb, #fff 82%, transparent); }

  html[data-page="home"] .group-marketing .tool {
    background: var(--c-gold);
    border-color: var(--c-gold-pressed);
    color: #000;
    min-height: var(--tile-min-h);
  }
  html[data-page="home"] .group-marketing .tool .tool-title { color: #000; }
  html[data-page="home"] .group-marketing .tool small { color: color-mix(in srgb, #000 65%, transparent); }

  @media (hover:hover) and (pointer:fine) {
    html[data-page="home"] .group-sales .tool:hover {
      background: var(--d-accent-pressed);
      transform: translateY(-1px);
    }
    html[data-page="home"] .group-marketing .tool:hover {
      background: var(--c-gold-pressed);
      transform: translateY(-1px);
    }
  }

  /* Power BI card + fullscreen stays as you had it, but scoped */
  html[data-page="home"] .pbi-card {
    margin-top: 18px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 16px;
  }

  html[data-page="home"] .pbi-head {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
  }

  html[data-page="home"] .pbi-head .pbi-actions {
    margin-inline-start: auto;
  }

  /* Stage wrapper preserves responsive sizing; grows to fill flex pbi-card */
  html[data-page="home"] .pbi-stage {
    position: relative;
    width: 100%;
    flex: 1;
    min-height: 260px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--card-bg);
    box-shadow: var(--shadow);
    overflow: hidden;
  }

  html[data-page="home"] #reportContainer {
    width: 100%;
    height: 100%;
    min-height: 260px;
  }

  /* (pbi-upsell overlay removed — dual-layer panel now used) */

  /* Fullscreen behaviour unchanged */
  html[data-page="home"] .pbi-card[data-fullscreen] {
    position: fixed;
    inset: 0;
    z-index: var(--z-overlay, 1000);
    padding: 16px;
    border-radius: 0;
    background: var(--bg);
    max-width: none;
    margin: 0;
  }

  html[data-page="home"] .pbi-card[data-fullscreen] .pbi-stage,
  html[data-page="home"] .pbi-card[data-fullscreen] #reportContainer {
    min-height: calc(100dvh - 84px);
    height: calc(100dvh - 84px);
  }

  /* Ensure report never visually bleeds through upsell */
#reportContainer {
  position: relative;
  z-index: 1;
}

#pbiUpsell {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(248, 246, 242, 0.96); /* soft brand wash */
  backdrop-filter: blur(2px);
}

.pbi-upsell-inner {
  max-width: 560px;
  width: 100%;
  background: none;
  border-radius: 0;
  padding: 0 8px;
  box-shadow: none;
  border: none;
}

.pbi-card {
 margin-top: 40px;
  border-radius: 18px;
  padding: 10px 18px 18px 18px;
  overflow: hidden;
}

.pbi-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px 8px 20px;
}

.pbi-head .section-title {
  font-size: 20px;
  font-weight: 600;
}

#btnExpandPBI {
  border-radius: 999px;
  padding: 6px 16px;
  font-size: 14px;
  background: rgba(0, 0, 0, 0.05);
}

/* 2x2 grid */
.grid-2x2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 18px;
}

/* ===== HOME: unified 2x2 tiles (fix contrast + tags + disabled) ===== */

.unified-tools .tool {
  position: relative;
  padding: 22px 22px 20px;
  border-radius: 14px;
  text-decoration: none;
  display: block;
  border: 1px solid rgba(0,0,0,.08);
  box-shadow: 0 8px 20px rgba(0,0,0,.06);
  transition: transform .15s ease, box-shadow .15s ease, filter .15s ease;
}

@media (hover:hover) {
  .unified-tools .tool:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 28px rgba(0,0,0,.10);
  }
}

/* Ensure title + subtitle inherit correct contrast */
.unified-tools .tool .tool-title { 
  font-weight: 650;
  letter-spacing: .1px;
  margin-bottom: 6px;
}
.unified-tools .tool small {
  display: block;
  line-height: 1.35;
  opacity: .92;
}

/* SALES = always white text */
.unified-tools .role-sales {
  background: #4b216b;
  color: #fff;
}
.unified-tools .role-sales .tool-title,
.unified-tools .role-sales small {
  color: #fff;
}

/* MARKETING = dark text */
.unified-tools .role-marketing {
  background: #f2a900;
  color: #1f1f1f;
}
.unified-tools .role-marketing .tool-title,
.unified-tools .role-marketing small {
  color: #1f1f1f;
}

/* Role tag: readable pill, top-right */
.unified-tools .role-tag {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .6px;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 999px;
  opacity: 1;
}

/* Tag colour per role */
.unified-tools .role-sales .role-tag {
  color: #fff;
  background: rgba(255,255,255,.16);
  border: 1px solid rgba(255,255,255,.22);
}
.unified-tools .role-marketing .role-tag {
  color: #1f1f1f;
  background: rgba(255,255,255,.35);
  border: 1px solid rgba(0,0,0,.10);
}

/* Disabled tile: obvious + friendly */
.unified-tools .tool.disabled,
.unified-tools .tool[aria-disabled="true"] {
  opacity: .62;
  filter: grayscale(.15);
  cursor: not-allowed;
}
@media (hover:hover) {
  .unified-tools .tool.disabled:hover,
  .unified-tools .tool[aria-disabled="true"]:hover {
    transform: none;
    box-shadow: 0 8px 20px rgba(0,0,0,.06);
  }
}

/* ===== PBI upsell: stronger mask + better centring ===== */

.pbi-stage {
  position: relative;
}

#reportContainer {
  position: relative;
  z-index: 1;
  border-radius: 12px;
  overflow: hidden;
}

/* Overlay mask (stops 'Cannot load model' bleed) */
#pbiUpsell {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(248, 246, 242, 0.97);
  backdrop-filter: blur(2px);
}

#pbiUpsell.hide { display: none; }

.pbi-upsell-inner {
  max-width: 560px;
  width: 100%;
  background: none;
  border-radius: 0;
  padding: 0 8px;
  border: none;
  box-shadow: none;
}

/* ===== 9.5 POLISH PASS (HOME) ===== */

/* 1) Improve section header rhythm + alignment */
.home .section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 10px;
  margin-bottom: 14px;
}

.home .section-head .section-title {
  font-size: 18px;
  letter-spacing: .2px;
}

.home .section-head .section-subtitle {
  font-size: 12.5px;
  opacity: .82;
  max-width: 540px;
  text-align: right;
  line-height: 1.25;
}

/* 2) Card hierarchy: clearer title, calmer copy */
.unified-tools .tool .tool-title {
  font-size: 16px;
  line-height: 1.15;
  margin-top: 2px;
}

.unified-tools .tool small {
  font-size: 12.75px;
  opacity: .88;
}

/* 3) Badge refinement: less dominant, more premium */
.unified-tools .role-tag {
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .7px;
  padding: 4px 9px;
  transform: translateY(0);
}

/* Make badges slightly quieter */
.unified-tools .role-sales .role-tag {
  background: rgba(255,255,255,.12);
  border-color: rgba(255,255,255,.18);
}

.unified-tools .role-marketing .role-tag {
  background: rgba(255,255,255,.28);
  border-color: rgba(0,0,0,.08);
}

/* 4) Click affordance only for enabled tiles */
.unified-tools a.tool:not(.disabled) {
  cursor: pointer;
}

@media (hover:hover) {
  .unified-tools a.tool:not(.disabled):hover {
    filter: saturate(1.02);
  }

  /* Add a subtle edge highlight on hover */
  .unified-tools a.tool:not(.disabled):hover::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 14px;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.14);
    pointer-events: none;
  }
}

/* 5) Disabled tile: clearer “not active” without looking broken */
.unified-tools .tool.disabled,
.unified-tools .tool[aria-disabled="true"] {
  opacity: .55;
  filter: grayscale(.2);
}

/* 6) Make “Intelligence” feel like connective tissue */
.pbi-card {
  position: relative;
}

/* Subtle top “connector” line motif */
.pbi-card::before {
  content: "";
  position: absolute;
  top: -10px;
  left: 22px;
  right: 22px;
  height: 1px;
  background: rgba(70,30,92,.10);
}

/* Better header alignment and weight */
.pbi-head {
  align-items: baseline;
  gap: 14px;
}

.pbi-head .section-title {
  font-size: 18px;
}

.pbi-head .fineprint,
.pbi-head .section-subtitle {
  opacity: .82;
}

/* 7) Upsell modal: more premium, better spacing */
#pbiUpsell {
  background: rgba(248, 246, 242, 0.985);
}

.pbi-upsell-inner {
  border: none;
  box-shadow: none;
  padding: 0 8px;
}

.pbi-upsell-title {
  font-size: 18px;
  line-height: 1.2;
  margin-bottom: 8px;
}

.pbi-upsell-copy {
  line-height: 1.45;
  opacity: .9;
}

.pbi-upsell-bullets {
  margin: 12px 0 16px;
  padding-left: 18px;
  opacity: .92;
}

/* 8) Expand button: slightly less “floating pill” */
#btnExpandPBI.btn {
  border-radius: 999px;
  padding: 8px 14px;
}

/* ===== HOME: micro layout polish (reduces "stacked sections" feel) ===== */
html[data-page="home"] #dashboard .backdrop {
  padding: 18px;
}

/* Tighten the gap between tools card and intelligence row */
html[data-page="home"] #dashboard .backdrop + .intel-row {
  margin-top: 14px;
}

/* ===== Intelligence row: two-column layout ===== */
html[data-page="home"] .intel-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  align-items: stretch;
}

@media (max-width: 760px) {
  html[data-page="home"] .intel-row {
    grid-template-columns: 1fr;
  }
}

/* pbi-card inside the row: suppress inherited top margin; height fills row */
html[data-page="home"] .intel-row .pbi-card {
  margin-top: 0;
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-self: stretch;
}

/* Tighten pbi-head within intel-row — removes extra inner padding from unscoped rule */
html[data-page="home"] .intel-row .pbi-head {
  padding: 0;
  margin-bottom: 10px;
}

/* ===== DUAL-LAYER PANEL: top upsell + bottom access ===== */

/* Hero tagline (always visible) */
html[data-page="home"] .intel-row .pbi-card .pbi-hero {
  font-size: 14px;
  font-weight: 600;
  color: var(--heading);
  margin: 4px 0 10px;
  line-height: 1.3;
}

/* CTA zone (shown when not subscribed) */
html[data-page="home"] .intel-row .pbi-card .pbi-cta-zone {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 8px;
}

html[data-page="home"] .intel-row .pbi-card .pbi-cta-zone.hide {
  display: none;
}

html[data-page="home"] .intel-row .pbi-card .pbi-note {
  font-size: 11.5px;
  color: var(--muted);
  margin: 0;
  opacity: 0.8;
}

/* Divider between top value and bottom access layer */
html[data-page="home"] .intel-row .pbi-card .pbi-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 10px 0;
}

/* Bottom: preview placeholder (not subscribed) */
html[data-page="home"] .intel-row .pbi-card .pbi-preview {
  background: color-mix(in srgb, var(--accent) 4%, var(--card-bg));
  border-radius: 10px;
  padding: 16px;
  text-align: center;
}

html[data-page="home"] .intel-row .pbi-card .pbi-preview.hide {
  display: none;
}

html[data-page="home"] .intel-row .pbi-card .pbi-preview-msg {
  font-size: 13px;
  color: var(--muted);
  margin: 0;
}

/* Bottom: PBI stage (subscribed) — clean, no heavy borders */
html[data-page="home"] .intel-row .pbi-card #pbiStage {
  border: none;
  box-shadow: none;
  background: transparent;
  min-height: 200px;
}

html[data-page="home"] .intel-row .pbi-card #pbiStage.hide {
  display: none;
}

html[data-page="home"] .intel-row .pbi-card #pbiStage #reportContainer {
  min-height: 200px;
}

/* ===== Recent activity card ===== */
html[data-page="home"] .activity-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-self: stretch;
}

html[data-page="home"] .activity-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

html[data-page="home"] .activity-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
}

html[data-page="home"] .activity-item {
  display: grid;
  grid-template-columns: 20px auto 1fr auto;
  gap: 3px 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  align-items: baseline;
}

html[data-page="home"] .activity-item:last-child {
  border-bottom: none;
}

/* ===== Collapsible per-app activity groups ===== */
html[data-page="home"] .activity-empty {
  font-size: 13px;
  color: var(--muted);
  padding: 10px 0;
  margin: 0;
}

html[data-page="home"] .activity-group {
  border-bottom: 1px solid var(--border);
}

html[data-page="home"] .activity-group:last-child {
  border-bottom: none;
}

html[data-page="home"] .activity-group-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 2px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

html[data-page="home"] .activity-group-summary::-webkit-details-marker {
  display: none;
}

html[data-page="home"] .activity-group-icon {
  font-size: 9px;
  color: var(--accent);
  opacity: 0.6;
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

html[data-page="home"] .activity-group[open] .activity-group-icon {
  transform: rotate(90deg);
}

html[data-page="home"] .activity-group-name {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--accent);
  flex: 1;
}

html[data-page="home"] .activity-group-count {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

html[data-page="home"] .activity-runs {
  list-style: none;
  margin: 0;
  padding: 0 0 6px 0;
}

html[data-page="home"] .activity-run {
  border-top: 1px solid var(--border);
}

html[data-page="home"] .activity-run-link {
  display: block;
  padding: 7px 6px;
  text-decoration: none;
  color: inherit;
  border-radius: 6px;
  transition: background 0.1s;
}

html[data-page="home"] .activity-run-link:hover {
  background: rgba(0, 0, 0, 0.04);
}

html[data-page="home"] .activity-run-company {
  display: block;
  font-size: 13px;
  color: var(--text-1);
  font-weight: 500;
  line-height: 1.3;
}

html[data-page="home"] .activity-run-meta {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

html[data-page="home"] .activity-icon {
  grid-column: 1;
  grid-row: 1 / 3;
  align-self: center;
  font-size: 9px;
  color: var(--accent);
  opacity: 0.6;
  line-height: 1;
}

html[data-page="home"] .activity-tool {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--accent);
  white-space: nowrap;
  grid-column: 2;
  grid-row: 1;
}

html[data-page="home"] .activity-desc {
  font-size: 13px;
  color: var(--text-1);
  line-height: 1.3;
  grid-column: 2 / 5;
  grid-row: 2;
}

html[data-page="home"] .activity-time {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  grid-column: 4;
  grid-row: 1;
  text-align: right;
}

/* ===== WELCOME HERO: two-column product-led layout ===== */
html[data-page="home"] #welcome.welcome-hero {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 48px;
  align-items: center;
  padding: 52px 0 56px;
  margin: 0;
}

@media (max-width: 720px) {
  html[data-page="home"] #welcome.welcome-hero {
    grid-template-columns: 1fr;
    padding: 36px 0 40px;
    gap: 32px;
  }
  html[data-page="home"] .welcome-hero-right {
    order: -1;
  }
}

html[data-page="home"] .welcome-headline {
  font-size: clamp(22px, 2.8vw, 36px);
  font-weight: 750;
  line-height: 1.15;
  color: var(--heading);
  letter-spacing: -.3px;
  margin: 0 0 18px;
}

html[data-page="home"] .welcome-copy {
  font-size: clamp(14px, 1.25vw, 16px);
  color: var(--text-2);
  line-height: 1.65;
  margin: 0 0 28px;
  max-width: 44ch;
}

html[data-page="home"] .welcome-cta-group {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

html[data-page="home"] .welcome-secure {
  font-size: 12.5px;
  color: var(--muted);
}

html[data-page="home"] .welcome-credibility {
  font-size: 11.5px;
  color: var(--muted);
  margin: 0;
  opacity: 0.7;
  letter-spacing: .25px;
}

html[data-page="home"] .welcome-hero-right {
  display: flex;
  align-items: center;
  justify-content: center;
}

html[data-page="home"] .welcome-illustration {
  width: 100%;
  max-width: 340px;
  height: auto;
  display: block;
  border-radius: 16px;
  padding: 20px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
}