/* Convergent Layout & Responsive Breakpoints */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
}

/* App Header */
.app-header {
  background-color: var(--md-sys-color-surface-container);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  z-index: 100;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-logo {
  width: 32px;
  height: 32px;
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--md-sys-color-primary);
}

.brand-subtitle {
  font-size: 0.75rem;
  color: var(--md-sys-color-on-surface-variant);
}

/* Main Dashboard Body & Convergent Navigation */
.app-body {
  display: flex;
  flex: 1;
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  min-height: 0;
  /* Allows flex children to shrink/grow properly */
  overflow: hidden;
}

/* Desktop Navigation Rail */
.nav-rail {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1.5rem 1rem;
  background-color: var(--md-sys-color-surface);
  border-right: 1px solid var(--md-sys-color-outline-variant);
  width: 220px;
  flex-shrink: 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: var(--md-shape-corner-full);
  color: var(--md-sys-color-on-surface-variant);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  transition: background-color 0.2s, color 0.2s;
}

.nav-item:hover {
  background-color: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
}

.nav-item.active {
  background-color: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

/* Main Content Area */
.main-content {
  flex: 1;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  overflow-y: auto;
  min-height: 0;
}

/* View Sections (Tab Switching) */
.view-section {
  display: none;
  flex-direction: column;
  gap: 1.5rem;
}

.view-section.active {
  display: flex;
}

/* Dashboard Grid Layout */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 1.5rem;
  align-items: stretch;
}

.dashboard-grid .md-card {
  display: flex;
  flex-direction: column;
}

.dashboard-grid .md-console {
  flex: 1;
  min-height: 260px;
  max-height: 380px;
}

/* Flasher Area */
.flasher-dropzone {
  border: 2px dashed var(--md-sys-color-outline);
  border-radius: var(--md-shape-corner-md);
  padding: 2rem 1.5rem;
  text-align: center;
  background-color: var(--md-sys-color-surface-container);
  transition: border-color 0.2s, background-color 0.2s;
  cursor: pointer;
}

.flasher-dropzone.dragover {
  border-color: var(--md-sys-color-primary);
  background-color: var(--md-sys-color-surface-container-high);
}

.flasher-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 1.5rem;
}

/* WASM Synth Curve Visualizer Canvas */
.synth-curve-canvas {
  width: 100%;
  height: auto;
  aspect-ratio: 720 / 180;
  border-radius: var(--md-shape-corner-md);
  border: 1px solid var(--md-sys-color-outline-variant);
  background-color: #16161E;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.4);
  display: block;
  image-rendering: auto;
}

/* Instrument Test Keyboard */
.virtual-keyboard {
  display: flex;
  position: relative;
  height: 180px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.5rem 0.25rem 1rem 0.25rem;
  user-select: none;
  -webkit-user-select: none;
  background-color: var(--md-sys-color-surface-container-low);
  border-radius: var(--md-shape-corner-md);
  border: 1px solid var(--md-sys-color-outline-variant);
}

.piano-key {
  position: relative;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transition: background-color 0.08s, color 0.08s, transform 0.05s;
  box-sizing: border-box;
}

.piano-key-white {
  flex: 1 0 42px;
  min-width: 42px;
  max-width: 52px;
  height: 100%;
  background-color: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 0 0 6px 6px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding-bottom: 0.5rem;
  gap: 0.15rem;
  z-index: 1;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12);
}

.piano-key-black {
  position: absolute;
  right: -13px;
  top: 0;
  width: 26px;
  height: 60%;
  background-color: var(--md-sys-color-surface-container-lowest);
  color: var(--md-sys-color-outline);
  border: 1px solid var(--md-sys-color-outline);
  border-top: none;
  border-radius: 0 0 4px 4px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding-bottom: 0.35rem;
  gap: 0.15rem;
  z-index: 2;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.35);
}

.key-note-name {
  font-size: 0.6875rem;
  font-weight: 700;
  font-family: var(--md-sys-font-mono);
  pointer-events: none;
}

.key-shortcut {
  font-size: 0.5625rem;
  font-weight: 600;
  opacity: 0.65;
  background-color: rgba(0, 0, 0, 0.08);
  border-radius: 3px;
  padding: 0.05rem 0.25rem;
  font-family: var(--md-sys-font-mono);
  pointer-events: none;
}

.piano-key-black .key-shortcut {
  background-color: rgba(255, 255, 255, 0.15);
}

.piano-key-white:hover {
  background-color: var(--md-sys-color-surface-container-high);
}

.piano-key-black:hover {
  background-color: #1a1a1a;
}

.piano-key-white.active {
  background-color: var(--md-sys-color-primary) !important;
  color: var(--md-sys-color-on-primary) !important;
  transform: translateY(2px);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.piano-key-black.active {
  background-color: var(--md-sys-color-primary) !important;
  color: var(--md-sys-color-on-primary) !important;
  transform: translateY(2px);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.piano-key.active .key-shortcut {
  background-color: rgba(255, 255, 255, 0.25);
  color: var(--md-sys-color-on-primary);
}

/* Responsive Mobile Bottom Navigation */
.mobile-nav-bar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: var(--md-sys-color-surface-container);
  border-top: 1px solid var(--md-sys-color-outline-variant);
  justify-content: space-around;
  padding: 0.5rem 0.25rem;
  z-index: 100;
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--md-sys-color-on-surface-variant);
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0.25rem 0.75rem;
  border-radius: var(--md-shape-corner-md);
}

.mobile-nav-item.active {
  color: var(--md-sys-color-primary);
  background-color: var(--md-sys-color-primary-container);
}

/* Responsive Breakpoints (Convergent Styling) */
@media (max-width: 768px) {
  .app-container {
    height: 100vh;
    overflow: auto;
  }

  .nav-rail {
    display: none;
  }

  .mobile-nav-bar {
    display: flex;
  }

  .main-content {
    padding: 1rem;
    padding-bottom: 5.5rem;
    /* spacing for mobile nav */
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  #view-monitor.view-section.active {
    min-height: calc(100vh - 12rem);
  }
}