/* ════════════════════════════════════════════════
   PIANO SUITE — MOBILE UI OVERRIDES
   Only active on screens ≤ 768px.
   Zero changes to desktop layout.
   ════════════════════════════════════════════════ */

@media (max-width: 768px) {

  body {
    overflow: auto;
    height: auto;
    min-height: 100vh;
  }

  /* ── TOP BAR ── */
  .topbar {
    padding: 0 12px;
    height: 50px;
  }
  .topbar-nav { display: none !important; }
  .topbar-logo-name { font-size: 13px; }
  .topbar-logo-icon { width: 26px; height: 26px; font-size: 13px; }
  .topbar-logo { padding-right: 10px; margin-right: 0; gap: 7px; }
  .topbar-right { margin-left: auto; gap: 5px; }
  .theme-btn { width: 30px; height: 30px; font-size: 13px; flex-shrink: 0; }

  /* Mobile nav dropdown button */
  #mobile-nav-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 32px;
    border-radius: var(--r);
    border: 1px solid var(--border2);
    background: transparent;
    color: var(--text);
    cursor: pointer;
    font-family: var(--mono);
    gap: 5px;
    padding: 0 9px;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background .15s;
    font-size: 11px;
  }
  #mobile-nav-btn:active { background: var(--surface2); }
  #mobile-nav-btn .nav-chevron {
    font-size: 8px;
    color: var(--text3);
    transition: transform .2s;
  }
  #mobile-nav-btn.open .nav-chevron { transform: rotate(180deg); }

  /* Hamburger button */
  #mobile-sidebar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--r);
    border: 1px solid var(--border2);
    background: transparent;
    color: var(--text2);
    cursor: pointer;
    font-size: 15px;
    flex-shrink: 0;
    transition: background .15s;
  }
  #mobile-sidebar-btn:active { background: var(--surface2); }
  #mobile-sidebar-btn.hidden { display: none !important; }

  /* Nav dropdown */
  #mobile-nav-dropdown {
    display: none;
    position: fixed;
    top: 50px;
    left: 0;
    right: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    z-index: 300;
    box-shadow: 0 8px 24px rgba(0,0,0,0.18);
    animation: fadeIn .15s ease;
  }
  #mobile-nav-dropdown.open { display: block; }

  .mobile-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    font-size: 14px;
    color: var(--text2);
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background .1s;
    user-select: none;
  }
  .mobile-nav-item:last-child { border-bottom: none; }
  .mobile-nav-item:active { background: var(--surface2); }
  .mobile-nav-item.active {
    color: var(--accent-text);
    background: var(--accent-soft);
    font-weight: 500;
  }
  .mobile-nav-item-icon { font-size: 16px; width: 22px; text-align: center; }
  .mobile-nav-item-check {
    margin-left: auto;
    color: var(--accent);
    font-size: 13px;
    opacity: 0;
  }
  .mobile-nav-item.active .mobile-nav-item-check { opacity: 1; }

  #mobile-nav-overlay {
    display: none;
    position: fixed;
    inset: 0;
    top: 50px;
    z-index: 290;
  }
  #mobile-nav-overlay.open { display: block; }

  /* ── APP BODY ── */
  .app-body {
    padding-top: 50px;
    height: auto;
    min-height: calc(100vh - 50px);
    display: block;
  }

  .view {
    display: none;
    flex-direction: column;
    height: auto;
    overflow: visible;
  }
  .view.active { display: flex; }

  /* ── SIDEBAR DRAWER ── */
  .sidebar {
    position: fixed;
    top: 50px;
    left: 0;
    bottom: 0;
    width: 220px;
    z-index: 400;
    transform: translateX(-100%);
    transition: transform .25s cubic-bezier(0.4,0,0.2,1);
    box-shadow: 4px 0 20px rgba(0,0,0,0.25);
    overflow-y: auto;
    padding-top: 4px;
  }
  .sidebar.open { transform: translateX(0); }

  #mobile-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    top: 50px;
    z-index: 390;
    background: rgba(0,0,0,0.4);
  }
  #mobile-sidebar-overlay.open { display: block; }

  /* ── MAIN CONTENT ── */
  .main-content {
    flex: none;
    width: 100%;
    padding: 12px 12px 28px;
    height: auto;
    overflow: visible;
    display: block;
    align-items: stretch;
  }

  /* ── LANDING ── */
  #view-landing {
    height: auto;
    overflow-y: auto;
  }
  #view-landing[style*="flex"] {
    min-height: calc(100vh - 50px);
  }
  .landing {
    padding: 20px 16px 32px;
    min-height: calc(100vh - 50px);
  }
  .landing-logo { width: 58px; height: 58px; font-size: 28px; margin-bottom: 14px; }
  .landing-title { font-size: 24px; }
  .landing-sub { font-size: 13px; margin-bottom: 20px; }
  .landing-cards { grid-template-columns: 1fr; gap: 10px; max-width: 100%; }
  .landing-card { padding: 14px; }
  .landing-card-icon { font-size: 20px; margin-bottom: 8px; }
  .landing-card-title { font-size: 13px; }
  .landing-card-desc { font-size: 11.5px; }

  /* ── SUB-PANELS ── */
  .sub-panel,
  .sub-panel#sp-3 {
    max-width: 100% !important;
    width: 100% !important;
  }

  /* ── GRIDS ── */
  .grid2 { grid-template-columns: 1fr !important; gap: 10px; }
  .grid3 { grid-template-columns: 1fr !important; gap: 10px; }
  .grid4 { grid-template-columns: 1fr 1fr !important; gap: 8px; }

  /* ── CARDS ── */
  .card { padding: 12px; margin-bottom: 10px; }
  .page-title { font-size: 16px; }
  .page-sub { font-size: 11.5px; margin-bottom: 12px; }

  /* ── CHARTS ── */
  .chart-wrap { margin-bottom: 10px; padding: 10px; }
  canvas { width: 100% !important; max-width: 100% !important; }

  #fft-canvas            { height: 120px !important; }
  #inh-B-canvas          { height: 110px !important; }
  #inh-dev-canvas        { height: 110px !important; }
  #inh-B-log-canvas      { height: 110px !important; }
  #inh-stretch-canvas    { height: 110px !important; }
  #inh-cent-dev-canvas   { height: 100px !important; }
  #inh-partial-dev-canvas  { height: 100px !important; }
  #inh-partial-count-canvas{ height: 90px  !important; }
  #inh-fit-rms-canvas    { height: 90px  !important; }
  #partial-fft-canvas    { height: 140px !important; }
  #partial-bar-canvas    { height: 130px !important; }
  #partial-cent-dev-canvas { height: 150px !important; }
  #dial-canvas           { height: 88px  !important; }
  #fork-wave-canvas      { height: 48px  !important; }
  #tension-chart         { height: 130px !important; }
  #diameter-chart        { height: 110px !important; }
  #b-target-chart        { height: 130px !important; }
  #b-achieved-chart      { height: 130px !important; }
  #b-d1-chart            { height: 110px !important; }
  #b-tension-chart       { height: 110px !important; }
  #b-compare-B-chart     { height: 130px !important; }
  #b-compare-d1-chart    { height: 110px !important; }
  #b-compare-T-chart     { height: 110px !important; }
  #b-delta-chart         { height: 90px  !important; }
  #ss-sigma-chart        { height: 130px !important; }
  #ss-d1-chart           { height: 110px !important; }
  #uc-tension            { height: 120px !important; }
  #uc-rtf                { height: 100px !important; }
  #uc-harmonicity        { height: 100px !important; }
  #uc-harm-length        { height: 100px !important; }
  #uc-elongation         { height: 90px  !important; }
  #uc-attack             { height: 90px  !important; }
  #uc-impedance          { height: 90px  !important; }
  #uc-stress             { height: 90px  !important; }
  #uc-b                  { height: 90px  !important; }
  #uc-d1                 { height: 90px  !important; }
  #uc-mu                 { height: 90px  !important; }
  #uc-length             { height: 90px  !important; }
  #uc-inh-stretch        { height: 100px !important; }

  /* ── BUTTONS ── */
  .btn-row { flex-wrap: wrap; gap: 6px; margin-top: 8px; }
  .btn { font-size: 11px; padding: 6px 10px; gap: 4px; }

  /* ── TUNER ── */
  .big-note { font-size: 40px; }
  .cents-display { font-size: 20px; padding: 5px 0; }
  .dial-wrap { padding: 10px; margin-bottom: 10px; }
  .note-chips { gap: 4px; }
  .note-chip { font-size: 9.5px; padding: 2px 7px; min-width: 32px; }
  .status-bar { font-size: 10.5px; padding: 7px 10px; }
  .alert { font-size: 11px; padding: 8px 12px; }
  .range-row { gap: 6px; }
  .range-val { font-size: 11px; min-width: 48px; }

  /* Partial view */
  #view-partial .main-content > div { width: 100%; max-width: 100%; }
  .btab-row { flex-wrap: wrap; }
  .btab { font-size: 10px; padding: 6px 10px; }

  /* Metric grid in partial */
  #view-partial .card .grid3 { grid-template-columns: repeat(3, 1fr) !important; }
  .metric .val { font-size: 16px; }
  .metric .lbl { font-size: 9px; }

  /* ── SCALE DESIGNER ── */
  /* Unified panel: stack editor below table */
  #sp-3 > div[style*="grid-template-columns"] {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
  }
  #unified-editor-panel { position: static !important; }
  #unified-scale-table { min-width: 680px; }

  /* Setup table */
  #setup-table { min-width: 500px; }
  .cell-input { width: 50px; font-size: 10px; }

  /* Tension model 2-col grid for law card */
  #sp-1 .card:last-child .grid3 { grid-template-columns: 1fr 1fr !important; }
  #transition-analysis { grid-template-columns: 1fr 1fr !important; }

  /* Scroll wraps */
  .scroll-wrap { overflow-x: auto; }
  #tp-tune .card .scroll-wrap { max-height: 220px; }

  /* B-break */
  #b-break-display { grid-template-columns: 1fr 1fr !important; }

  /* Fork */
  .fork-display { padding: 12px 0; }
  .freq-big { font-size: 36px; }
  .freq-unit { font-size: 13px; }

  /* Tables */
  table { font-size: 10px; }
  thead th { font-size: 8.5px; padding: 5px 6px; }
  tbody td { padding: 4px 6px; }

  /* Forms */
  input[type=text], input[type=number], select, textarea {
    font-size: 13px;
    padding: 7px 9px;
  }
  label { font-size: 11px; }

} /* end @media (max-width: 768px) */

/* Hide mobile-only elements on desktop */
@media (min-width: 769px) {
  #mobile-nav-btn,
  #mobile-sidebar-btn,
  #mobile-nav-dropdown,
  #mobile-nav-overlay,
  #mobile-sidebar-overlay {
    display: none !important;
  }
}
