﻿/**
 * Unified embed + app-shell layout (SUPPIX parent + iframe children).
 * One viewport, one scroll region per surface — no nested scroll chaos.
 */

/* Logged-in SUPPIX: lock page scroll; views scroll internally */
body:not(.auth-locked) {
  overflow: hidden;
  height: 100dvh;
  max-height: 100dvh;
}

/* ── SUPPIX: main column is a flex stack ── */
.shell {
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

.content {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  height: 100%;
  max-height: 100dvh;
  overflow: hidden;
  padding: 14px 18px 16px !important;
}

.content .topbar {
  position: sticky;
  top: 0;
  left: auto;
  right: auto;
  flex-shrink: 0;
  z-index: 40;
  margin: 0 0 12px;
  border-radius: 16px;
  border: 1px solid rgba(120, 156, 255, 0.24);
}

.content.has-embed-view {
  padding-bottom: 12px !important;
}

/* Standard pages: scroll inside active view only */
.content .view {
  display: none;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.content .view.active:not(.view-embed) {
  display: block !important;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding-right: 2px;
}

/* Enterprise embeds: fill remaining height, iframe scrolls internally */
.content .view.view-embed.active {
  display: flex !important;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  height: auto !important;
  overflow: hidden;
}

.enterprise-embed-shell {
  flex: 1;
  min-height: 0;
  border-radius: 14px;
  border: 1px solid rgba(120, 156, 255, 0.18);
  background: linear-gradient(165deg, #0a1020 0%, #050816 100%);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.enterprise-embed-toolbar {
  padding: 0.55rem 0.9rem;
  gap: 0.5rem;
  flex-shrink: 0;
  background: rgba(10, 16, 30, 0.96);
  border-bottom: 1px solid rgba(120, 156, 255, 0.12);
  box-shadow: none;
}

.enterprise-embed-toolbar::after {
  display: none !important;
}

.enterprise-embed-title {
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  color: #7dd3fc;
  opacity: 1;
}

.enterprise-embed-toolbar .ghost-button,
.enterprise-embed-toolbar .primary-button {
  padding: 0.4rem 0.75rem !important;
  font-size: 0.76rem !important;
  border-radius: 10px !important;
  background: rgba(255, 255, 255, 0.05) !important;
  border: 1px solid rgba(120, 156, 255, 0.14) !important;
  color: #eaf3ff !important;
}

.enterprise-embed-toolbar .ghost-button:hover {
  background: rgba(56, 189, 248, 0.12) !important;
  border-color: rgba(56, 189, 248, 0.35) !important;
}

.enterprise-embed-frame.is-hidden {
  visibility: hidden;
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}

.embed-frame-fallback {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: radial-gradient(ellipse at 50% 0%, rgba(56, 189, 248, 0.24), transparent 70%);
}

.embed-frame-fallback.hidden {
  display: none;
}

.embed-frame-fallback-card {
  max-width: 420px;
  text-align: center;
  padding: 1.75rem 1.5rem;
  border-radius: 16px;
  border: 1px solid rgba(120, 156, 255, 0.18);
  background: rgba(10, 16, 30, 0.92);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.embed-frame-fallback-eyebrow {
  margin: 0 0 0.35rem;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(125, 211, 252, 0.9);
}

.embed-frame-fallback-title {
  margin: 0 0 0.65rem;
  font-size: 1.15rem;
  color: #eef6ff;
}

.embed-frame-fallback-msg {
  margin: 0 0 1.1rem;
  font-size: 0.88rem;
  line-height: 1.45;
  color: #8ea4c0;
}

.embed-frame-fallback-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

.enterprise-embed-frame {
  flex: 1;
  min-height: 0;
  width: 100%;
  height: 100%;
  border: none;
  background: #050816;
}

/* ── Iframe children (enterprise-hub, ai-command-center, admin-v2) ── */
html.embed-document,
html.embed-document body {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

body.embed-mode {
  height: 100%;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 14% 12%, rgba(56, 189, 248, 0.14), transparent 26%),
    radial-gradient(circle at 88% 10%, rgba(99, 102, 241, 0.12), transparent 24%),
    linear-gradient(145deg, #050816 0%, #081124 42%, #050816 100%);
}

body.embed-mode .embed-scroll-main {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(56, 189, 248, 0.35) rgba(5, 8, 22, 0.8);
}

body.embed-mode .embed-scroll-main::-webkit-scrollbar {
  width: 6px;
}

body.embed-mode .embed-scroll-main::-webkit-scrollbar-track {
  background: rgba(5, 8, 22, 0.85);
  border-radius: 6px;
}

body.embed-mode .embed-scroll-main::-webkit-scrollbar-thumb {
  background: rgba(56, 189, 248, 0.32);
  border-radius: 6px;
}

body.embed-mode .embed-scroll-main::-webkit-scrollbar-thumb:hover {
  background: rgba(56, 189, 248, 0.5);
}

/* Custom scrollbars on main content column (SUPPIX views) */
.content .view.active:not(.view-embed) {
  scrollbar-width: thin;
  scrollbar-color: rgba(56, 189, 248, 0.45) rgba(5, 8, 22, 0.55);
}

.content .view.active:not(.view-embed)::-webkit-scrollbar {
  width: 8px;
}

.content .view.active:not(.view-embed)::-webkit-scrollbar-track {
  background: rgba(5, 8, 22, 0.45);
  border-radius: 8px;
}

.content .view.active:not(.view-embed)::-webkit-scrollbar-thumb {
  background: rgba(56, 189, 248, 0.4);
  border-radius: 8px;
}

body.embed-mode .embed-panel-fixed {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

body.embed-mode .embed-panel-fixed .embed-scroll-main {
  flex: 1;
}

body.embed-mode .embed-panel-footer {
  flex-shrink: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

/* Enterprise Hub inside SUPPIX iframe — 100vh bug fix */
html.embed-document body.embed-mode #mainLayout.embed-layout-split {
  height: 100%;
  min-height: 0;
}

html.embed-document body.embed-mode .hub-main-col.embed-scroll-main {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: none;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

html.embed-document body.embed-mode #mainLayout.layout {
  display: flex !important;
  flex-direction: column !important;
  grid-template-columns: unset !important;
  width: 100% !important;
  max-width: none !important;
}

html.embed-document body.embed-mode .ai-panel.embed-panel-fixed {
  max-height: none !important;
  height: 100% !important;
}

html.embed-document body.embed-mode #aiLog.embed-scroll-main {
  min-height: 0 !important;
}

body.embed-mode .embed-panel-fixed > h2,
body.embed-mode .embed-panel-fixed > #aiStatus,
body.embed-mode .embed-panel-fixed > .ai-toolbar,
body.embed-mode .embed-panel-fixed > #aiPrompts {
  flex-shrink: 0;
}

body.embed-mode .embed-panel-fixed #aiLog {
  flex: 1;
  min-height: 0;
}

/* Admin v2 inside SUPPIX iframe */
html.embed-document body.embed-mode.admin-v2-embed {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

html.embed-document body.embed-mode.admin-v2-embed #dashboardView {
  flex: 1;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
}

html.embed-document body.embed-mode.admin-v2-embed .app-shell {
  flex: 1;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  max-height: 100%;
}

html.embed-document body.embed-mode.admin-v2-embed .app-sidebar,
html.embed-document body.embed-mode.admin-v2-embed .mobile-bottom-nav {
  display: none !important;
}

html.embed-document body.embed-mode.admin-v2-embed .app-main {
  flex: 1;
  min-height: 0;
  max-height: none;
  overflow: hidden;
}

html.embed-document body.embed-mode.admin-v2-embed .app-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

html.embed-document body.ops-app.embed-mode {
  height: 100%;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

html.embed-document body.ops-app.embed-mode .ops-header {
  flex-shrink: 0;
  position: relative;
  top: auto;
}

html.embed-document body.ops-app.embed-mode main {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 1100px) {
  body.embed-mode .embed-layout-split {
    grid-template-columns: 1fr !important;
    grid-template-rows: minmax(0, 1fr) auto !important;
  }

  body.embed-mode .embed-panel-fixed {
    max-height: 42vh;
  }
}

@media (max-width: 960px) {
  body:not(.auth-locked) {
    overflow: hidden;
    height: 100dvh;
    max-height: 100dvh;
  }

  .shell {
    grid-template-columns: 1fr !important;
    grid-template-rows: auto minmax(0, 1fr);
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
  }

  .sidebar {
    height: auto !important;
    max-height: min(42vh, 320px);
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .content {
    min-height: 0;
    height: auto;
    max-height: none;
    overflow: hidden;
    padding-bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px)) !important;
  }

  .content .view.active:not(.view-embed) {
    padding-bottom: 0.5rem;
  }

  .content .view.view-embed.active {
    min-height: 0;
    flex: 1;
  }

  .enterprise-embed-shell {
    min-height: 0;
    flex: 1;
  }
}

/* Shared tenant / platform logo chip (ops, hub, foreman) */
[data-tenant-logo],
.tenant-logo-chip {
  width: 40px;
  height: 40px;
  object-fit: contain;
  border-radius: 10px;
  padding: 4px;
  background: linear-gradient(145deg, rgba(15, 23, 42, 0.88), rgba(5, 8, 22, 0.95));
  border: 1px solid rgba(103, 232, 249, 0.22);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28), 0 0 16px rgba(168, 85, 247, 0.12);
}

[data-tenant-logo]:not(.hidden),
.tenant-logo-chip:not(.hidden) {
  display: inline-block;
}
