/*
 * Layout: a one-screen sandbox.
 *   header (48px)
 *   app = [controls rail 300px] [views]
 *   sandbox view = [workspace 1fr] [insight rail 340px]
 * Above 1100px the app fills the viewport and each column scrolls on its own,
 * so controls, chart and guide stay visible together. Below that it stacks.
 */
.frame {
  max-width: 1680px;
  margin: 0 auto;
  padding: 18px var(--frame-pad) var(--frame-pad);
}

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 48px;
}

.header-chrome {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ---------- App shell ---------- */
.app {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: var(--grid-gap);
  margin-top: 16px;
  height: calc(100dvh - 18px - 48px - 16px - var(--frame-pad));
  min-height: 640px;
}

#views {
  min-width: 0;
  min-height: 0;
  transition: opacity 0.2s ease;
}

.view {
  height: 100%;
  min-height: 0;
}

/* ---------- Controls rail ---------- */
.rail {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0;
  overflow: hidden;
}

.rail-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 18px 8px;
  scrollbar-width: thin;
}

.rail-section {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px dashed var(--ink-14);
}

.rail-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-top: 1px dashed var(--ink-14);
}

.rail-foot .pill-btn {
  flex: 1;
  justify-content: center;
}

/* ---------- Sandbox view ---------- */
.view-sandbox:not([hidden]) {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: var(--grid-gap);
}

.workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.scene-head {
  padding: 2px 4px 0;
}

.kpi-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 28px;
  margin: 14px 4px 14px;
}

.chart-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 340px;
}

.chart-card .chart-wrap {
  flex: 1;
  min-height: 200px;
}

.insight {
  display: flex;
  flex-direction: column;
  gap: var(--grid-gap);
  min-height: 0;
  overflow-y: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
}

.insight > * {
  flex: none;
}

/* ---------- Panel views (records, events, log) ---------- */
.view-panel:not([hidden]) {
  display: flex;
  flex-direction: column;
}

.panel-card {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-card .table-scroll,
.panel-card .event-stream {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.panel-card.dark-card-lg {
  overflow-y: auto;
}

body[data-busy="true"] .workspace,
body[data-busy="true"] .insight,
body[data-busy="true"] .panel-card {
  opacity: 0.6;
}

/* ---------- Responsive ---------- */
@media (max-width: 1360px) {
  .view-sandbox:not([hidden]) {
    grid-template-columns: minmax(0, 1fr) 300px;
  }

  .app {
    grid-template-columns: 270px minmax(0, 1fr);
  }
}

@media (max-width: 1100px) {
  .app {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 0;
  }

  .rail-scroll,
  .insight {
    overflow: visible;
  }

  .view-sandbox:not([hidden]) {
    display: flex;
    flex-direction: column;
  }

  .chart-card {
    min-height: 0;
  }

  .chart-card .chart-wrap {
    flex: none;
    height: 300px;
  }

  .panel-card {
    max-height: none;
  }

  .panel-card .table-scroll {
    max-height: 75vh;
  }

  .brand-product {
    display: none;
  }

  .rail-foot {
    position: sticky;
    bottom: 0;
    z-index: 4;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 0 0 var(--r-card) var(--r-card);
  }

  .rail {
    overflow: visible;
  }
}

@media (max-width: 760px) {
  :root {
    --frame-pad: 16px;
  }

  .app-header {
    flex-wrap: wrap;
  }

  .nav-group {
    order: 3;
    width: 100%;
  }

  .scene-title {
    font-size: 30px;
  }

  .kpi-row {
    gap: 14px 24px;
  }

  .kpi .t-kpi {
    font-size: 38px;
  }

  .event-row {
    grid-template-columns: 44px 1fr;
  }

  .event-dates,
  .event-detail {
    grid-column: 2;
  }
}
