/* File: web/css/audioweaves_fix.css © 2026 projectemergence. All rights reserved. */
/* Site-integrated Audioweaves v2 layout. State comes from audioweaves_site_runtime.js. */

:root {
  --aw-nav-height: max(60px, calc(54px + env(safe-area-inset-bottom, 0px)));
  --aw-surface: rgba(7, 13, 24, 0.96);
  --aw-surface-raised: rgba(14, 25, 43, 0.94);
  --aw-border: rgba(129, 188, 235, 0.25);
  --aw-text-muted: rgba(207, 226, 242, 0.68);
  --aw-positive: #ff9b62;
  --aw-negative: #45d6b2;
}

#pageAudioweaves {
  height: 100%;
  min-height: 100%;
  padding: 0 !important;
  overflow: hidden;
}

#audioweaves-bottom-nav {
  position: fixed !important;
  inset: auto 0 0 !important;
  min-height: var(--aw-nav-height);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 3100 !important;
  transform: none !important;
  opacity: 1 !important;
}

body:not(.aw2-standalone) #maestro-frame {
  position: fixed !important;
  inset: var(--header-visible-height, 60px) 0 var(--aw-nav-height) !important;
  width: 100% !important;
  height: auto !important;
  min-height: 0 !important;
  margin: 0 !important;
  padding: 0.7rem !important;
  display: flex !important;
  gap: 0.7rem !important;
  overflow: hidden !important;
  z-index: 100 !important;
  background: #03070e;
  border: 0 !important;
  border-radius: 0 !important;
  box-sizing: border-box;
}

body.header-collapsed:not(.aw2-standalone):not(.audioweaves-fullscreen) #maestro-frame {
  top: var(--header-visible-height, 0px) !important;
}

body.audioweaves-fullscreen {
  overflow: hidden !important;
  --header-visible-height: 0px;
}

body.audioweaves-fullscreen header,
body.audioweaves-fullscreen .header-drag-hint,
body.audioweaves-fullscreen .footer-container {
  display: none !important;
}

body:not(.aw2-standalone).audioweaves-fullscreen #maestro-frame {
  inset: 0 0 var(--aw-nav-height) !important;
  width: 100vw !important;
  height: auto !important;
  z-index: 3000 !important;
  padding: 0 !important;
}

body.audioweaves-fullscreen #audioweaves-bottom-nav {
  display: flex !important;
  transform: none !important;
  opacity: 1 !important;
  z-index: 3100 !important;
}

#maestro-controls,
#audioweaves-panel {
  min-width: 0;
  min-height: 0;
}

#maestro-frame[data-aw-workspace="controls"] #maestro-controls {
  display: flex !important;
  flex: 1 1 100% !important;
  position: relative;
  z-index: 2;
}

#maestro-frame[data-aw-workspace="controls"] #audioweaves-panel {
  display: flex !important;
  position: absolute !important;
  inset: 0.7rem !important;
  width: auto !important;
  opacity: 0 !important;
  pointer-events: none !important;
  z-index: 0 !important;
}

#maestro-frame[data-aw-workspace="graphs"] #maestro-controls,
#maestro-frame[data-aw-workspace="visualizer"] #maestro-controls {
  display: none !important;
}

#maestro-frame[data-aw-workspace="graphs"] #audioweaves-panel,
#maestro-frame[data-aw-workspace="visualizer"] #audioweaves-panel {
  display: flex !important;
  flex: 1 1 100% !important;
  width: 100% !important;
  opacity: 1 !important;
  pointer-events: auto !important;
}

#maestro-frame[data-aw-workspace="graphs"] #audioweaves-plots {
  display: flex !important;
}

#maestro-frame[data-aw-workspace="graphs"] #audioweaves-visualizer {
  display: none !important;
}

/* The visualizer lives inside #audioweaves-plots. Keep that parent mounted and
   hide only graph-owned children; hiding the parent also hides the toolbar,
   scene selector, WebGL canvas, and legacy iframe. */
#maestro-frame[data-aw-workspace="visualizer"] #audioweaves-plots {
  display: flex !important;
  flex: 1 1 100% !important;
  width: 100% !important;
  min-width: 0 !important;
  min-height: 0 !important;
}

#maestro-frame[data-aw-workspace="visualizer"] #audioweaves-plots > #audioweaves-graph-toolbar,
#maestro-frame[data-aw-workspace="visualizer"] #audioweaves-plots > #audioweaves-graph-tabs,
#maestro-frame[data-aw-workspace="visualizer"] #audioweaves-plots > .tab-content,
#maestro-frame[data-aw-workspace="visualizer"] #audioweaves-legends {
  display: none !important;
}

#maestro-frame[data-aw-workspace="visualizer"] #audioweaves-visualizer {
  display: flex !important;
  flex: 1 1 auto !important;
  width: 100% !important;
  min-width: 0 !important;
  min-height: 0 !important;
}

#maestro-controls {
  overflow: hidden;
  padding: 0.2rem;
  background: radial-gradient(circle at 15% 0%, rgba(29, 82, 128, 0.18), transparent 34%), var(--aw-surface);
  border: 1px solid var(--aw-border);
  border-radius: 15px;
}

#audioweaves-tab-content {
  min-height: 0;
  padding: 0.55rem 0.65rem 1rem;
  scrollbar-gutter: stable;
}

#audioweaves-tabs {
  flex: 0 0 auto;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  border-bottom-color: var(--aw-border);
}

#audioweaves-tabs .nav-link {
  white-space: nowrap;
}

.aw-control-groups {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.55rem 0.65rem 0.35rem;
  border-bottom: 1px solid var(--aw-border);
}

.aw-control-groups .btn.active {
  background: rgba(75, 179, 255, 0.22);
  border-color: rgba(113, 204, 255, 0.75);
  color: #fff;
}

.aw-intent-panel {
  flex: 0 0 auto;
  margin: 0.2rem 0.2rem 0.65rem;
  padding: 0.7rem;
  border: 1px solid rgba(89, 212, 188, 0.32);
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(10, 43, 48, 0.72), rgba(14, 23, 42, 0.9));
}

.aw-section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.6rem;
}

.aw-section-heading strong {
  color: #e9fffb;
  letter-spacing: 0.03em;
}

.aw-section-heading span {
  color: var(--aw-text-muted);
  font-size: 0.72rem;
  text-align: right;
}

.aw-intent-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 0.55rem 0.75rem;
}

.aw-intent-control {
  display: grid;
  grid-template-columns: minmax(90px, auto) 1fr minmax(58px, auto);
  align-items: center;
  gap: 0.45rem;
  margin: 0;
  padding: 0.4rem 0.5rem;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.045);
}

.aw-intent-label {
  color: #dff8f2;
  font-size: 0.76rem;
}

.aw-intent-control output,
.aw-control-value {
  min-width: 4.8rem;
  color: #d7ecff;
  font-variant-numeric: tabular-nums;
  text-align: right;
  font-size: 0.72rem;
  white-space: nowrap;
}

.maestro-controls .control-row {
  min-height: 36px;
}

.maestro-controls .control-row > label:first-child {
  min-width: 142px;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.maestro-controls .control-owner-chip {
  margin-left: auto;
  font-size: 0.48rem;
  letter-spacing: 0.08em;
}

.maestro-controls .control-row input[type="range"] {
  min-width: 120px;
}

#audioweaves-panel {
  border-radius: 15px;
  overflow: hidden;
}

#audioweaves-plots {
  min-height: 0;
  overflow: hidden;
}

.aw-graph-toolbar {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: auto auto minmax(220px, 1fr);
  align-items: center;
  gap: 0.45rem 0.8rem;
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid var(--aw-border);
  background: rgba(7, 15, 28, 0.94);
}

.aw-data-freshness,
.aw-graph-readout,
.aw-graph-note {
  color: var(--aw-text-muted);
  font-size: 0.7rem;
}

.aw-data-freshness[data-stale="true"] {
  color: #ffba78;
}

.aw-graph-note {
  grid-column: 1 / -1;
  padding-top: 0.35rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

#graph-scroll {
  min-height: 0 !important;
  height: 100%;
  border-radius: 10px;
}

#aw-view-live,
#aw-view-fft,
#aw-view-analysis {
  min-height: 0;
  height: 100%;
}

#aw-view-live[hidden],
#aw-view-fft[hidden],
#aw-view-analysis[hidden] {
  display: none !important;
}

#fft-timeline-wrap,
#fft-timeline-scroll {
  min-height: 0;
  height: 100%;
  max-height: none;
}

#audioweaves-analysis-dashboard {
  width: 100%;
  height: 100%;
  overflow: auto;
  padding: clamp(0.8rem, 2vw, 1.5rem);
  color: #e8f4ff;
  background: radial-gradient(circle at 80% 0%, rgba(58, 120, 177, 0.15), transparent 34%), #050a13;
  box-sizing: border-box;
}

.aw-analysis-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.aw-analysis-header h3,
.aw-analysis-dashboard h4,
.aw-analysis-dashboard h5 {
  margin: 0 0 0.35rem;
  color: #f3f9ff;
}

.aw-analysis-header p,
.aw-analysis-effects > p {
  margin: 0;
  color: var(--aw-text-muted);
  font-size: 0.8rem;
}

.aw-analysis-version {
  flex: 0 0 auto;
  padding: 0.5rem 0.7rem;
  text-align: right;
  border: 1px solid var(--aw-border);
  border-radius: 10px;
  background: var(--aw-surface-raised);
  font-variant-numeric: tabular-nums;
}

.aw-analysis-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 0.65rem;
  margin-bottom: 0.8rem;
}

.aw-metric-card,
.aw-analysis-health,
.aw-analysis-effects,
.aw-curve-panel,
.aw-analysis-interactions {
  border: 1px solid var(--aw-border);
  border-radius: 13px;
  background: var(--aw-surface-raised);
}

.aw-metric-card {
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
  padding: 0.7rem 0.8rem;
}

.aw-metric-card span,
.aw-metric-card small {
  color: var(--aw-text-muted);
  font-size: 0.68rem;
}

.aw-metric-card strong {
  font-size: 1.35rem;
  font-variant-numeric: tabular-nums;
}

.aw-analysis-health,
.aw-analysis-effects,
.aw-curve-panel,
.aw-analysis-interactions {
  padding: 0.85rem;
  margin-bottom: 0.8rem;
}

.aw-analysis-health ul {
  margin: 0;
  padding-left: 1.1rem;
  color: var(--aw-text-muted);
  font-size: 0.75rem;
}

.aw-effect-list {
  display: grid;
  gap: 0.26rem;
  margin-top: 0.7rem;
}

.aw-effect-row {
  display: grid;
  grid-template-columns: minmax(150px, 230px) minmax(120px, 1fr) minmax(210px, auto);
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.42rem 0.5rem;
  color: #deeffd;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
}

.aw-effect-row:hover,
.aw-effect-row:focus-visible {
  background: rgba(255, 255, 255, 0.06);
  outline: 1px solid rgba(128, 207, 255, 0.35);
}

.aw-effect-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.76rem;
}

.aw-effect-bar {
  display: block;
  height: 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

.aw-effect-bar i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--aw-positive);
}

.aw-effect-bar i[data-sign="negative"] {
  background: var(--aw-negative);
}

.aw-effect-value {
  text-align: right;
  font-size: 0.73rem;
  font-variant-numeric: tabular-nums;
}

.aw-effect-value small {
  color: var(--aw-text-muted);
}

.aw-response-curve {
  width: min(100%, 760px);
  height: auto;
  margin-top: 0.5rem;
}

.aw-response-curve line {
  stroke: rgba(177, 208, 233, 0.35);
  stroke-width: 1;
}

.aw-response-curve polyline {
  fill: none;
  stroke: #6ed8ff;
  stroke-width: 3;
}

.aw-response-curve text {
  fill: rgba(211, 231, 247, 0.72);
  font-size: 13px;
}

.aw-analysis-interactions table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.73rem;
}

.aw-analysis-interactions th,
.aw-analysis-interactions td {
  padding: 0.42rem 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  text-align: left;
}

.aw-analysis-interactions th {
  color: var(--aw-text-muted);
  font-weight: 600;
}

.aw-analysis-error,
.aw-analysis-empty {
  padding: 1rem;
  border: 1px solid var(--aw-border);
  border-radius: 12px;
  color: var(--aw-text-muted);
  background: var(--aw-surface-raised);
}

.aw-analysis-error {
  color: #ffb4ad;
  border-color: rgba(255, 100, 89, 0.35);
}

.audioweaves-visualizer-toolbar {
  flex-wrap: wrap;
  gap: 0.45rem;
}

.aw-visual-policy {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-left: auto;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--aw-border);
  border-radius: 10px;
  color: var(--aw-text-muted);
  font-size: 0.7rem;
}

.aw-visual-policy strong {
  color: #edf7ff;
}

.aw-visual-policy label {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  margin: 0;
}

.aw-visual-policy select {
  min-height: 30px;
  color: #eef8ff;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 7px;
  background: rgba(0, 0, 0, 0.32);
}

@media (max-width: 1050px) {
  .aw-intent-grid {
    grid-template-columns: repeat(2, minmax(150px, 1fr));
  }

  .aw-analysis-metrics {
    grid-template-columns: repeat(2, minmax(130px, 1fr));
  }
}

@media (max-width: 768px) {
  :root {
    --aw-nav-height: max(64px, calc(58px + env(safe-area-inset-bottom, 0px)));
  }

  body:not(.aw2-standalone) #maestro-frame {
    padding: 0.35rem !important;
  }

  #maestro-frame[data-aw-workspace="controls"] #audioweaves-panel {
    inset: 0.35rem !important;
  }

  .audioweaves-vertical-label {
    display: none !important;
  }

  .aw-section-heading {
    display: block;
  }

  .aw-section-heading span {
    display: block;
    margin-top: 0.2rem;
    text-align: left;
  }

  .aw-intent-grid,
  .aw-analysis-metrics {
    grid-template-columns: 1fr;
  }

  .aw-intent-control {
    grid-template-columns: 1fr minmax(110px, 2fr) minmax(62px, auto);
  }

  .maestro-controls .control-row > label:first-child {
    min-width: 100%;
    width: 100%;
  }

  .aw-graph-toolbar {
    grid-template-columns: auto 1fr;
  }

  .aw-graph-readout {
    grid-column: 1 / -1;
  }

  .aw-analysis-header {
    display: block;
  }

  .aw-analysis-version {
    margin-top: 0.6rem;
    text-align: left;
  }

  .aw-effect-row {
    grid-template-columns: minmax(110px, 1fr) minmax(90px, 1fr);
  }

  .aw-effect-value {
    grid-column: 1 / -1;
    text-align: left;
  }

  .aw-analysis-interactions {
    overflow-x: auto;
  }

  .audioweaves-visualizer-toolbar,
  #audioweaves-visualizer-status,
  #audioweaves-visualizer-file-controls,
  #audioweaves-visualizer-source,
  #audioweaves-visualizer-scene {
    display: flex !important;
  }

  .aw-visual-policy {
    width: 100%;
    margin-left: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  #maestro-frame,
  #audioweaves-bottom-nav,
  #audioweaves-panel *,
  #maestro-controls * {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* Parameter history is the authoritative live graph/legend surface. Keep the
   complete flex-height chain measurable and do not let the older outer legend
   collapse wrapper hide the parameter-history legend. */
#maestro-frame[data-aw-workspace="graphs"] #audioweaves-panel,
#maestro-frame[data-aw-workspace="graphs"] #audioweaves-plots,
#maestro-frame[data-aw-workspace="graphs"] #audioweaves-plots > .tab-content,
#maestro-frame[data-aw-workspace="graphs"] #aw-view-live {
  min-width: 0 !important;
  min-height: 0 !important;
  width: 100% !important;
}

#maestro-frame[data-aw-workspace="graphs"] #audioweaves-plots {
  flex: 1 1 0 !important;
  height: 100% !important;
  flex-direction: column !important;
}

#maestro-frame[data-aw-workspace="graphs"] #audioweaves-plots > .tab-content,
#maestro-frame[data-aw-workspace="graphs"] #aw-view-live {
  display: flex !important;
  flex: 1 1 0 !important;
  height: auto !important;
  flex-direction: column !important;
  overflow: hidden !important;
}

#maestro-frame[data-aw-workspace="graphs"] #graph-scroll {
  position: relative !important;
  display: block !important;
  flex: 1 1 0 !important;
  width: 100% !important;
  height: auto !important;
  min-height: 180px !important;
  overflow: hidden !important;
  background: #050915 !important;
}

#maestro-frame[data-aw-workspace="graphs"] #audioweaves-graph,
#maestro-frame[data-aw-workspace="graphs"] #audioweaves-parameter-timeline {
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  width: 100% !important;
  height: 100% !important;
}

#maestro-frame[data-aw-workspace="graphs"] #audioweaves-parameter-timeline {
  position: absolute !important;
  inset: 0 !important;
  z-index: 3 !important;
  pointer-events: none !important;
}

#maestro-frame[data-aw-workspace="graphs"] #audioweaves-legends {
  display: flex !important;
  flex: 0 1 auto !important;
  flex-direction: column !important;
  width: 100% !important;
  min-height: 38px !important;
  max-height: 240px !important;
  overflow: hidden !important;
}

#maestro-frame[data-aw-workspace="graphs"] #audioweaves-legend {
  display: block !important;
  flex: 0 1 auto !important;
  width: 100% !important;
  min-height: 38px !important;
  max-height: 220px !important;
  overflow: auto !important;
}

/* audioweaves_parameter_history.js already owns the whole-legend disclosure.
   The continuity-level disclosure was a second controller for the same DOM. */
#maestro-frame[data-aw-workspace="graphs"] #audioweaves-legends > .aw-legend-collapse-toggle {
  display: none !important;
}

#maestro-frame[data-aw-workspace="graphs"] #audioweaves-legends.aw-legend-collapsed > #audioweaves-legend {
  display: block !important;
}
