/* =====================================================================
 * V8.2 - Agentic OS shell
 *
 * Scoped to body[data-shell="modern"]. Loads alongside sharepoint.css;
 * every rule overrides a classic chrome rule by adding the data-shell
 * selector to win specificity. Classic pages are untouched.
 *
 * Palette + radii come from the CSS custom properties emitted in
 * MasterPage.xslt's AdditionalHead block; this file only references
 * them through var(). Adding a new modern theme = new color
 * vars + maybe one accent override here.
 *
 * Layout language:
 *  - Top global nav (replaces the classic ms-core-suiteBar)
 *  - Bento grid for the site home page (asymmetric)
 *  - Glassmorphism cards (backdrop-blur, semi-transparent, hairline border)
 *  - Neon accents reserved for status semantics, not chrome
 *
 * Responsiveness: 1024px down to single-column bento; 640px down
 * collapses the global nav to a horizontal scroller.
 * ===================================================================== */

body[data-shell="modern"] {
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  margin: 0;
  min-height: 100vh;
  background-image:
    radial-gradient(circle at 12% 8%, rgba(168, 85, 247, 0.08) 0%, transparent 28%),
    radial-gradient(circle at 88% 14%, rgba(59, 130, 246, 0.06) 0%, transparent 32%),
    radial-gradient(circle at 50% 92%, rgba(34, 197, 94, 0.05) 0%, transparent 30%);
  background-attachment: fixed;
}

body[data-shell="modern"] a {
  color: var(--accent-data);
  text-decoration: none;
}
body[data-shell="modern"] a:hover {
  color: #93c5fd;
}

/* =========================================================
 * Classic chrome reset - hide / restyle the SharePoint bits
 * the Agentic shell doesn't want.
 * ========================================================= */

/* The ribbon is SP-2010 furniture; modern shell doesn't need it. */
body[data-shell="modern"] #s4-ribbonrow { display: none; }

/* SuiteBar becomes the global nav skeleton; we restyle it instead
   of hiding it so the layout stays consistent with the classic shell. */
body[data-shell="modern"] .ms-core-suiteBar {
  background: rgba(10, 10, 14, 0.78);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  border-bottom: 1px solid var(--glass-border);
  height: auto;
  line-height: normal;
  padding: 10px 22px;
  position: sticky;
  top: 0;
  z-index: 50;
}
body[data-shell="modern"] .ms-core-suiteBar-wrapper {
  max-width: 1440px;
  margin: 0 auto;
  align-items: center;
  gap: 24px;
}
body[data-shell="modern"] .ms-core-branding .ms-core-suiteLink-a {
  font-weight: 700;
  letter-spacing: 0.12em;
  font-size: 13px;
  color: var(--text);
  text-transform: uppercase;
  position: relative;
  padding-left: 18px;
}
/* Status dot in the brand mark - neon green pulse signals "online". */
body[data-shell="modern"] .ms-core-branding .ms-core-suiteLink-a::before {
  content: "";
  position: absolute;
  left: 0; top: 50%;
  width: 8px; height: 8px;
  margin-top: -4px;
  border-radius: 50%;
  background: var(--accent-active);
  box-shadow: 0 0 12px var(--accent-active);
  animation: spice-pulse 2.4s ease-in-out infinite;
}
@keyframes spice-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}
body[data-shell="modern"] .ms-core-suiteBar-right {
  margin-left: auto;
}
body[data-shell="modern"] .ms-core-suiteBar-right .ms-core-menu-title {
  font-size: 12px;
  color: var(--text-dim);
  padding: 6px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  transition: border-color 120ms ease;
}
body[data-shell="modern"] .ms-core-suiteBar-right .ms-core-menu-title:hover {
  border-color: var(--glass-border);
  color: var(--text);
}

/* TitleRow turns into a slim site-header card under the global nav. */
body[data-shell="modern"] #s4-titlerow {
  background: linear-gradient(135deg, rgba(255,255,255,0.04), rgba(255,255,255,0.02));
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-card);
  margin: 20px 24px 0 24px;
  padding: 18px 24px;
  box-shadow: none;
  color: var(--text);
}
body[data-shell="modern"] #titleAreaBox { max-width: 1440px; margin: 0 auto; }
body[data-shell="modern"] .ms-core-pageTitle a {
  color: var(--text);
  font-weight: 600;
  letter-spacing: -0.01em;
}
body[data-shell="modern"] .ms-siteicon-a .ms-siteicon-img {
  filter: grayscale(1) brightness(1.4);
  opacity: 0.7;
}

/* Top-nav links live in TitleRow's TopNavigation. */
body[data-shell="modern"] .ms-core-navigation .ms-core-listMenu-horizontalBox { gap: 4px; }
body[data-shell="modern"] .ms-core-listMenu-root { gap: 4px; padding: 0; }
body[data-shell="modern"] .ms-core-listMenu-item {
  color: var(--text-dim);
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  font-size: 13px;
  transition: all 120ms ease;
}
body[data-shell="modern"] .ms-core-listMenu-item:hover {
  color: var(--text);
  border-color: var(--glass-border);
  background: var(--surface-hover);
}

/* Workspace + content area. Every classic wrapper that defaults to a
   white background gets reset to transparent so the dark body bg
   shows through. Missing any one of these makes the page render a
   white band; that was the first thing wrong in the V8.2 smoke. */
body[data-shell="modern"] #s4-workspace,
body[data-shell="modern"] #s4-bodyContainer,
body[data-shell="modern"] #contentBox,
body[data-shell="modern"] #mainContent,
body[data-shell="modern"] .ms-pub-contentLayout,
body[data-shell="modern"] .ms-core-content,
body[data-shell="modern"] .ms-webpart-page-content {
  background: transparent !important;
  background-color: transparent !important;
}
body[data-shell="modern"] #s4-bodyContainer { max-width: 1440px; margin: 0 auto; padding: 0; }

/* Hide the classic vertical Quick Launch sidebar; modern shell relies on the
   global nav + breadcrumb. Lists are bento cards on the home page. */
body[data-shell="modern"] #sideNavBox { display: none; }

/* Re-claim the full width since Quick Launch is gone. */
body[data-shell="modern"] #contentRow { display: block; padding: 0 24px; background: transparent; }
body[data-shell="modern"] #contentBox { width: 100%; max-width: none; padding: 0; }
body[data-shell="modern"] #mainContent { padding: 0; }

/* Breadcrumb -> hairline strip. */
body[data-shell="modern"] .ms-breadcrumb-top { background: transparent; padding: 18px 0 12px 0; }
body[data-shell="modern"] .ms-breadcrumb { font-size: 12px; color: var(--text-faint); }
body[data-shell="modern"] .ms-breadcrumbNode .ms-core-listMenu-item {
  background: transparent;
  border: none;
  padding: 0;
  color: var(--text-faint);
}
body[data-shell="modern"] .ms-breadcrumbNode .ms-core-listMenu-item:hover { color: var(--text); }
body[data-shell="modern"] .ms-breadcrumbSeparator { color: var(--text-faint); padding: 0 8px; }

/* Footer -> tiny. */
body[data-shell="modern"] .ms-core-footer {
  background: transparent;
  border-top: 1px solid var(--glass-border);
  margin-top: 32px;
  padding: 14px 24px;
  text-align: center;
  color: var(--text-faint);
  font-size: 11px;
}

/* =========================================================
 * Bento grid - the site home page layout
 * =========================================================
 * The classic Site template emits .ms-webpart-zone-layout
 * containing welcome content, optional Theme card, the
 * ProvisionedLists grid, and WebPartZones. Under Modern shell
 * we re-flow the same DOM into an asymmetric bento grid by
 * targeting the welcome + lists containers directly.
 */

body[data-shell="modern"] .ms-webpart-zone-layout {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  grid-auto-rows: minmax(120px, auto);
  gap: 16px;
  padding: 8px 0 32px 0;
}

/* Glass card surface shared by every bento tile. */
body[data-shell="modern"] .ms-webpart-chrome,
body[data-shell="modern"] .welcome-content,
body[data-shell="modern"] .site-theme {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-card);
  padding: 18px 22px;
  color: var(--text);
  position: relative;
  overflow: hidden;
}
body[data-shell="modern"] .ms-webpart-chrome::before,
body[data-shell="modern"] .welcome-content::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(135deg, rgba(255,255,255,0.06) 0%, transparent 40%);
  opacity: 0.6;
}

/* Welcome tile - spans full width, top of the bento. */
body[data-shell="modern"] .welcome-content {
  grid-column: 1 / -1;
  padding: 28px 28px;
  background:
    linear-gradient(135deg, rgba(168, 85, 247, 0.18), rgba(59, 130, 246, 0.10)),
    rgba(20,20,28,0.85);
}
body[data-shell="modern"] .welcome-content .ms-webpart-titleText span {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #ffffff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}
body[data-shell="modern"] .welcome-content h2 { color: #ffffff; }

/* Theme summary card - small, AI-accent (purple) since theming is an
   AI-platform thing. Tucked to the side under the welcome tile. */
body[data-shell="modern"] .ms-webpart-chrome-fullWidth:has(.site-theme) {
  grid-column: 1 / 5;
}
body[data-shell="modern"] .site-theme {
  padding: 14px 18px;
  border-left: 3px solid var(--accent-ai);
}
body[data-shell="modern"] .site-theme strong { color: var(--text-dim); font-weight: 500; }

/* Site Lists & Recent Activity - the big tile under the bento. */
body[data-shell="modern"] .ms-webpart-chrome-fullWidth:has(.ms-webpart-content > div[style*="grid"]) {
  grid-column: 5 / -1;
}
body[data-shell="modern"] .ms-webpart-chrome-fullWidth:has(.ms-webpart-content > div[style*="grid"]) .ms-webpart-content {
  padding: 0;
}
/* Fallback for browsers without :has() support: don't break, just stack. */
@supports not selector(:has(*)) {
  body[data-shell="modern"] .ms-webpart-chrome-fullWidth { grid-column: 1 / -1; }
}

/* The card grid inside Site Lists - override the inline grid style
   from MasterPage.xslt to use our glass tiles. */
body[data-shell="modern"] .ms-webpart-content > div[style*="grid"] {
  background: transparent;
  padding: 6px;
  gap: 12px !important;
}
body[data-shell="modern"] .ms-webpart-content > div[style*="grid"] > div {
  background: var(--surface) !important;
  border: 1px solid var(--glass-border) !important;
  border-radius: var(--radius-card);
  transition: border-color 140ms ease, transform 140ms ease;
}
body[data-shell="modern"] .ms-webpart-content > div[style*="grid"] > div:hover {
  border-color: var(--glass-border-strong) !important;
  transform: translateY(-1px);
}
body[data-shell="modern"] .ms-webpart-content > div[style*="grid"] a[style*="color:#0072c6"] {
  color: var(--accent-data) !important;
}
body[data-shell="modern"] .ms-webpart-content > div[style*="grid"] code {
  background: var(--surface);
  color: var(--accent-ai) !important;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
}
/* Override the inline #333 / #999 / #888 colors on RecentItem rows so
   titles and metadata are readable on the dark glass card. */
body[data-shell="modern"] .ms-webpart-content > div[style*="grid"] li a[style*="color:#333"] {
  color: var(--text) !important;
}
body[data-shell="modern"] .ms-webpart-content > div[style*="grid"] li span[style*="color:#999"],
body[data-shell="modern"] .ms-webpart-content > div[style*="grid"] span[style*="color:#888"] {
  color: var(--text-faint) !important;
}
body[data-shell="modern"] .ms-webpart-content > div[style*="grid"] li {
  border-top-color: var(--glass-border) !important;
}
body[data-shell="modern"] .ms-webpart-content > div[style*="grid"] > div div[style*="color:#666"] {
  color: var(--text-dim) !important;
}
body[data-shell="modern"] .ms-webpart-content > div[style*="grid"] > div div[style*="color:#aaa"] {
  color: var(--text-faint) !important;
}

/* Web part chrome header bars. */
body[data-shell="modern"] .ms-webpart-header {
  background: transparent;
  border-bottom: 1px solid var(--glass-border);
  padding: 8px 0 12px 0;
  margin-bottom: 14px;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Default Web Part Zones (when nothing custom) - reflow into bento halves. */
body[data-shell="modern"] .ms-webpart-page-content {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 16px;
}
body[data-shell="modern"] .ms-webpart-zone-column { width: auto !important; }
body[data-shell="modern"] .ms-webpart-zone-column:nth-child(1) { grid-column: 1 / 9; }
body[data-shell="modern"] .ms-webpart-zone-column:nth-child(2) { grid-column: 9 / -1; }

/* "View all lists" CTA. */
body[data-shell="modern"] .ms-commandLink {
  grid-column: 1 / -1;
  text-align: center;
  margin-top: 4px;
}
body[data-shell="modern"] .ms-heroCommandLink {
  display: inline-block;
  padding: 10px 22px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  transition: all 140ms ease;
}
body[data-shell="modern"] .ms-heroCommandLink:hover {
  border-color: var(--accent-data);
  background: var(--surface-hover);
  color: var(--text);
}

/* =========================================================
 * Generic surface restyling - lists, tables, forms - so any
 * page in modern mode picks up the dark-glass look.
 * ========================================================= */

body[data-shell="modern"] .ms-listview,
body[data-shell="modern"] table.ms-listview-table {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-card);
  overflow: hidden;
  color: var(--text);
}
body[data-shell="modern"] table.ms-listview-table th {
  background: rgba(255,255,255,0.04);
  color: var(--text-dim);
  border-bottom: 1px solid var(--glass-border);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 11px;
}
body[data-shell="modern"] table.ms-listview-table td {
  border-bottom: 1px solid var(--glass-border);
  color: var(--text);
}
body[data-shell="modern"] table.ms-listview-table tr:hover td {
  background: var(--surface-hover);
}

body[data-shell="modern"] .ms-toolbar {
  border-bottom: 1px solid var(--glass-border);
}
body[data-shell="modern"] .ms-btn-primary {
  background: var(--accent-data);
  color: white;
  border: none;
  border-radius: var(--radius-pill);
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.08), 0 6px 20px -10px rgba(59,130,246,0.6);
}
body[data-shell="modern"] .ms-btn-primary:hover { filter: brightness(1.1); }
body[data-shell="modern"] .ms-btn-folder,
body[data-shell="modern"] .ms-btn-secondary {
  background: var(--surface);
  border: 1px solid var(--glass-border);
  color: var(--text);
  border-radius: var(--radius-pill);
  padding: 7px 14px;
}

/* =========================================================
 * Responsive breakpoints
 * ========================================================= */

@media (max-width: 1024px) {
  body[data-shell="modern"] .ms-webpart-zone-layout {
    grid-template-columns: 1fr;
  }
  body[data-shell="modern"] .welcome-content,
  body[data-shell="modern"] .ms-webpart-chrome-fullWidth:has(.site-theme),
  body[data-shell="modern"] .ms-webpart-chrome-fullWidth:has(.ms-webpart-content > div[style*="grid"]) {
    grid-column: 1 / -1;
  }
  body[data-shell="modern"] .ms-webpart-page-content { grid-template-columns: 1fr; }
  body[data-shell="modern"] .ms-webpart-zone-column:nth-child(1),
  body[data-shell="modern"] .ms-webpart-zone-column:nth-child(2) { grid-column: 1 / -1; }
}

@media (max-width: 640px) {
  body[data-shell="modern"] #s4-titlerow { margin: 12px 12px 0 12px; padding: 14px 16px; }
  body[data-shell="modern"] #contentRow { padding: 0 12px; }
  body[data-shell="modern"] .ms-core-suiteBar-wrapper {
    flex-wrap: wrap;
    gap: 8px;
  }
  body[data-shell="modern"] .ms-core-navigation .ms-core-listMenu-horizontalBox {
    overflow-x: auto;
    flex-wrap: nowrap;
    white-space: nowrap;
  }
}
