/*
 * PRESS PLAY — MOBILE RESPONSIVE
 * JarganApiDemo Smartphone Adaptation
 *
 * Layered on top of styles-instrument-paper.css
 * Breakpoints:
 *   - <= 768px  : Phone layout (single column, bottom tabs)
 *   - <= 1024px : Tablet (narrower sidebar)
 *
 * Design Principles (preserved from Instrument Paper):
 *   - No border-radius, no shadows, no smooth transitions
 *   - Monochrome palette, color is signal
 *   - Lines over surfaces
 *   - Touch targets >= 44px
 */

/* ============================================================
   MOBILE VIEWPORT TOKENS
   ============================================================ */

@media (max-width: 768px) {
  :root {
    /* Scale up typography for mobile readability */
    --text-xs: 11px;
    --text-sm: 13px;
    --text-base: 15px;
    --text-md: 17px;
    --text-lg: 20px;
    --text-xl: 26px;

    /* Wider touch spacing */
    --space-touch: 44px;  /* Minimum touch target */
    --mobile-nav-height: 56px;
    --mobile-header-height: 52px;
  }
}

/* ============================================================
   TABLET ADJUSTMENTS (769px - 1024px)
   ============================================================ */

@media (min-width: 769px) and (max-width: 1024px) {
  .app {
    width: 340px !important;
    min-width: 340px !important;
    max-width: 340px !important;
  }

  .devtools-drawer {
    width: 340px !important;
  }
}

/* ============================================================
   PHONE LAYOUT (<= 768px)
   ============================================================ */

@media (max-width: 768px) {

  /* ---- Remove Electron-specific chrome ---- */

  .app-container::before {
    display: none !important;
  }

  .header {
    -webkit-app-region: unset;
  }

  .results-panel-header {
    -webkit-app-region: unset;
    padding-top: var(--space-1) !important;
  }

  /* ---- App Container: Stacked, not side-by-side ---- */

  .app-container {
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  /* ---- Main App Panel: Full width, scrollable ---- */

  .app {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    flex-shrink: 0;
    height: 100%;
    padding: 0;
    padding-top: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  /* ---- Header: Mobile optimized ---- */

  .header {
    padding: var(--space-1) var(--space-2);
    margin-bottom: 0;
    border-bottom: var(--line-hairline) solid var(--border-default);
    flex-shrink: 0;
    min-height: var(--mobile-header-height);
    align-items: center;
  }

  .header-title {
    font-size: 15px;
    gap: 6px;
  }

  .jargan-mark {
    width: 20px;
    height: 20px;
  }

  .connection-status {
    font-size: var(--text-xs);
  }

  /* ---- Main Content: Scrollable form area ---- */

  .main-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    border-right: none;
    padding-bottom: calc(var(--mobile-nav-height) + 16px);
    -webkit-overflow-scrolling: touch;
  }

  /* ---- Form Sections: Mobile spacing ---- */

  .form-section {
    padding: var(--space-2);
  }

  .section-label {
    font-size: var(--text-xs);
    margin-bottom: var(--space-1);
  }

  /* ---- Form Row: Stack vertically on phone ---- */

  .form-row {
    flex-direction: column;
    gap: 0;
  }

  .form-col,
  .form-col-wide {
    flex: none;
    width: 100%;
  }

  /* ---- Select Input: Touch-friendly ---- */

  .select-input {
    min-height: var(--space-touch);
    font-size: var(--text-base);
    padding: var(--space-1) var(--space-2);
  }

  /* ---- Date Input: Touch-friendly ---- */

  .date-input {
    min-height: var(--space-touch);
    font-size: var(--text-base);
    padding: var(--space-1) var(--space-2);
  }

  /* ---- Duration Toggle: Wider buttons ---- */

  .duration-toggle {
    display: flex;
  }

  .duration-btn {
    min-height: var(--space-touch);
    font-size: var(--text-sm);
    padding: var(--space-1) 0;
    flex: 1;
  }

  /* ============================================================
     FIX #4: Intensity Slider — thin line + rectangular handle
     Matches desktop instrument-paper aesthetic
     ============================================================ */

  .slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 2px;
    background: var(--border-default);
    outline: none;
    margin: 20px 0;
    cursor: pointer;
  }

  .slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    background: var(--text-primary);
    cursor: pointer;
    border: none;
    transform: rotate(45deg);
    margin-top: -6px; /* Center on 2px track: -(14/2 - 2/2) = -6 */
  }

  .slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: var(--text-primary);
    cursor: pointer;
    border: none;
    transform: rotate(45deg);
  }

  .slider::-webkit-slider-runnable-track {
    height: 2px;
    background: var(--border-default);
  }

  .slider::-moz-range-track {
    height: 2px;
    background: var(--border-default);
  }

  /* ============================================================
     FIX #2: Objective Section — ensure visible on mobile
     Was collapsing due to flex:1 + min-height:0 in parent
     ============================================================ */

  #objectiveSection {
    flex: 1 1 auto !important;
    min-height: 80px !important;
    display: flex !important;
    flex-direction: column;
    overflow: hidden;
  }

  .objective-grid {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
  }

  /* Inline preview drawer spans full grid width */
  .objective-preview-drawer {
    grid-column: 1 / -1;
  }

  .objective-card {
    min-height: 40px;
    padding: 6px var(--space-1);
    font-size: var(--text-sm);
    gap: 4px;
  }

  /* Compact card contents for 2-col grid */
  .objective-card .objective-icon {
    width: 16px;
    height: 16px;
    font-size: 12px;
  }

  .objective-card .objective-name {
    font-size: 11px;
    line-height: 1.2;
  }

  .objective-card .objective-desc {
    display: none;
  }

  .objective-card .objective-dev-toggle {
    display: none;
  }

  .objective-card .objective-detail-btn {
    display: none;
  }

  /* ============================================================
     FIX #9: Inline preview per goal (replaces separate preview section)
     ============================================================ */

  /* Inline preview drawer below each goal card */
  .objective-preview-drawer {
    display: none;
    border: 1px solid var(--border-default);
    border-top: none;
    background: var(--bg-secondary);
    padding: var(--space-1);
    font-size: var(--text-xs);
  }

  .objective-preview-drawer.open {
    display: block;
  }

  /* Two-column layout: channels left, voices right */
  .objective-preview-drawer .preview-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .objective-preview-drawer .preview-column {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .objective-preview-drawer .preview-column-label {
    font-size: 9px;
    font-family: var(--font-mono);
    font-weight: var(--weight-bold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
    border-bottom: 1px solid var(--border-default);
    padding-bottom: 3px;
    margin-bottom: 2px;
  }

  .objective-preview-drawer .preview-column-label svg {
    width: 10px;
    height: 10px;
  }

  .objective-preview-drawer .preview-packs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    flex: 1;
  }

  .objective-preview-drawer .preview-pack {
    font-size: 10px;
    padding: 2px 6px;
    border: 1px solid var(--border-default);
    background: var(--bg-primary);
  }

  .objective-preview-drawer .preview-adjustments {
    font-size: 10px;
    margin-top: 4px;
    color: var(--text-secondary);
    grid-column: 1 / -1;
  }

  .objective-preview-drawer .preview-loading {
    padding: var(--space-1);
    font-size: var(--text-xs);
    color: var(--text-muted);
  }

  /* Chevron on objective card */
  .objective-chevron {
    margin-left: auto;
    font-size: 10px;
    color: var(--text-muted);
    transition: transform 0.15s;
    flex-shrink: 0;
  }

  .objective-card.active .objective-chevron {
    color: var(--text-primary);
  }

  .objective-card.preview-open .objective-chevron {
    transform: rotate(90deg);
  }

  /* ============================================================
     FIX #5: Hide DevTools button from Create pane on mobile
     Settings is accessed via bottom nav instead
     ============================================================ */

  .btn-devtools {
    display: none !important;
  }

  /* #10: Unified generate controls group */
  .generate-controls {
    position: sticky;
    bottom: 0;
    z-index: 10;
    background: var(--bg-primary);
    border-top: 2px solid var(--border-default);
    padding: var(--space-1) var(--space-2);
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .generate-controls .form-section {
    padding: 0;
    margin: 0;
  }

  .generate-controls .section-label {
    font-size: 9px;
    margin-bottom: 2px;
  }

  .generate-controls .form-row {
    flex-direction: row;
    gap: var(--space-1);
  }

  .generate-controls .form-col {
    flex: 1;
  }

  .generate-controls .form-col-wide {
    flex: 2;
  }

  .generate-controls .duration-btn {
    min-height: 32px;
    padding: 4px 0;
    font-size: 11px;
  }

  .generate-controls .date-input {
    min-height: 32px;
    font-size: 13px;
  }

  .generate-controls .slider {
    margin: 12px 0 24px;
  }

  .sticky-buttons {
    padding: 0;
    background: none;
    border-top: none;
    display: flex;
    gap: var(--space-1);
    flex-direction: row;
  }

  /* Reduce bottom gap between Generate button and nav bar */
  .generate-controls {
    padding-bottom: 6px;
  }

  .btn-primary {
    min-height: var(--space-touch);
    font-size: var(--text-base);
    flex: 1;
  }

  /* ---- Results Panel: Full-screen overlay on mobile ---- */

  .results-panel {
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100% !important;
    height: 100% !important;
    z-index: 100;
    border-left: none;
    flex-direction: column;
  }

  .results-panel.visible {
    display: flex;
  }

  .results-panel-header {
    padding: var(--space-1) var(--space-2);
    padding-top: var(--space-1);
  }

  .results-header-top {
    flex-wrap: wrap;
    gap: var(--space-1);
  }

  .results-header-left {
    flex: 1;
    min-width: 0;
  }

  .schedule-name-input-compact {
    font-size: var(--text-base);
    width: 100%;
  }

  .results-meta-compact {
    font-size: var(--text-xs);
  }

  .results-header-right {
    display: flex;
    gap: var(--space-1);
    align-items: center;
  }

  .view-tab-compact {
    min-width: var(--space-touch);
    min-height: 36px;
  }

  .icon-btn {
    min-width: 36px;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .close-btn {
    min-width: 36px;
    min-height: 36px;
  }

  /* ---- Results Content ---- */

  .results-panel-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: var(--mobile-nav-height);
  }

  /* ============================================================
     FIX #6: Table View — card layout instead of horizontal table
     Each deliverable is a card, not a table row
     ============================================================ */

  .table-scroll {
    overflow-x: visible;
    -webkit-overflow-scrolling: touch;
  }

  .results-table {
    display: block;
    font-size: var(--text-sm);
    min-width: 0;
    width: 100%;
  }

  .results-table thead {
    display: none;
  }

  .results-table tbody {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    padding: var(--space-1);
  }

  .results-table tr.deliverable-row {
    display: flex;
    flex-wrap: wrap;
    gap: 4px var(--space-2);
    padding: var(--space-2);
    border: 1px solid var(--border-default);
    background: var(--bg-primary);
    align-items: baseline;
  }

  .results-table td {
    display: block;
    padding: 0;
    border: none;
    white-space: normal;
  }

  /* Date column: full width, bold */
  .results-table td:first-child {
    position: static;
    background: none;
    border-right: none;
    width: 100%;
    font-weight: var(--weight-bold);
    font-size: var(--text-xs);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-family: var(--font-mono);
  }

  /* Channel + Voice + Stage: inline tags */
  .results-table td:nth-child(2),
  .results-table td:nth-child(3),
  .results-table td:nth-child(4) {
    font-size: var(--text-sm);
    padding: 2px 6px;
    border: 1px solid var(--border-default);
    background: var(--bg-secondary);
  }

  /* ============================================================
     TABLE VIEW: Grouped by date with collapsible drawers
     ============================================================ */

  /* Hide desktop-style flat rows on mobile (desktop uses .deliverable-row) */
  .deliverable-detail-row {
    display: none;
  }

  /* Date row: collapsible header — uniform fixed height (mirrors week view day rows) */
  .deliverable-date-row {
    display: flex;
    align-items: center;
    height: var(--space-touch); /* Fixed 44px — same as week view day rows */
    padding: 0 var(--space-2);
    border-bottom: var(--line-hairline) solid var(--border-default);
    background: var(--bg-primary);
    cursor: pointer;
    gap: var(--space-1);
    flex-shrink: 0;
  }

  .deliverable-date-row.expanded {
    background: var(--bg-secondary);
    border-bottom-color: var(--border-heavy);
  }

  .date-row-date {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    font-weight: var(--weight-bold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-primary);
    white-space: nowrap;
    flex-shrink: 0;
    width: 56px;
  }

  .date-row-summary {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    overflow: hidden;
  }

  .date-row-count {
    font-size: 11px;
    font-weight: var(--weight-bold);
    background: var(--bg-tertiary);
    padding: 1px 6px;
    flex-shrink: 0;
  }

  .date-row-channels {
    font-size: 11px;
    display: flex;
    flex-wrap: nowrap; /* Single line — clip overflow */
    gap: 3px;
    flex: 1;
    overflow: hidden;
  }

  .date-row-channel-pill {
    font-size: 9px;
    padding: 1px 5px;
    font-family: var(--font-mono);
    letter-spacing: 0.03em;
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* Subtle color coding for channel pills (border-left accent) */
  .date-row-channel-pill.color-0 { border-left: 3px solid var(--ip-gray-900); color: var(--text-secondary); }
  .date-row-channel-pill.color-1 { border-left: 3px solid var(--ip-gray-600); color: var(--text-secondary); }
  .date-row-channel-pill.color-2 { border-left: 3px solid var(--ip-gray-400); color: var(--text-secondary); }
  .date-row-channel-pill.color-3 { border-left: 3px solid var(--ip-signal-active); color: var(--text-secondary); }
  .date-row-channel-pill.color-4 { border-left: 3px solid var(--ip-signal-success); color: var(--text-secondary); }

  .date-row-divider {
    color: var(--text-muted);
    font-size: 9px;
    flex-shrink: 0;
  }

  .date-row-voices {
    display: flex;
    gap: 3px;
    flex-wrap: nowrap;
    overflow: hidden;
  }

  .date-row-voice-pill {
    font-size: 9px;
    font-style: italic;
    color: var(--text-secondary);
    border-left: 2px solid var(--ip-gray-400);
    padding: 1px 4px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  .date-row-stages {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
  }

  .date-row-stage-badge {
    font-size: 8px;
    font-family: var(--font-mono);
    font-weight: var(--weight-bold);
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 0 3px;
    border: var(--line-hairline) solid var(--border-default);
  }

  .date-row-arrow {
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
    margin-left: auto;
  }

  /* Date item rows: deliverable details, hidden by default */
  .deliverable-date-item {
    display: none;
  }

  .deliverable-date-item.visible {
    display: block;
    border: 1px solid var(--border-default);
    border-top: none;
    background: var(--bg-primary);
  }

  .deliverable-date-item.visible td {
    display: block;
    padding: 0;
    border: none;
  }

  .date-item-content {
    position: relative;
    padding: var(--space-2);
    padding-bottom: 28px;
    border-bottom: 1px dashed var(--border-default);
  }

  .deliverable-date-item:last-of-type .date-item-content,
  .deliverable-date-item.visible:has(+ :not(.deliverable-date-item.visible)) .date-item-content {
    border-bottom: none;
  }

  .date-item-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 6px;
  }

  .date-item-channel,
  .date-item-voice,
  .date-item-stage {
    font-size: var(--text-xs);
    padding: 2px 6px;
    border: 1px solid var(--border-default);
    background: var(--bg-secondary);
    display: inline-flex;
    align-items: center;
    gap: 3px;
  }

  .date-item-channel svg,
  .date-item-voice svg,
  .date-item-stage svg {
    width: 10px;
    height: 10px;
    flex-shrink: 0;
    color: var(--text-muted);
  }

  /* Color-coded channel tags match summary pills */
  .date-item-channel.color-0 { border-left: 3px solid var(--ip-gray-900); }
  .date-item-channel.color-1 { border-left: 3px solid var(--ip-gray-600); }
  .date-item-channel.color-2 { border-left: 3px solid var(--ip-gray-400); }
  .date-item-channel.color-3 { border-left: 3px solid var(--ip-signal-active); }
  .date-item-channel.color-4 { border-left: 3px solid var(--ip-signal-success); }

  .date-item-platform {
    font-size: 10px;
    padding: 2px 6px;
    border: 1px solid var(--border-default);
    font-family: var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
  }

  .date-item-brief {
    font-size: var(--text-sm);
    line-height: var(--leading-relaxed);
    color: var(--text-secondary);
    margin-top: 4px;
  }

  .date-item-copy-btn {
    position: absolute;
    bottom: 6px;
    right: 6px;
    padding: 3px 10px;
    font-size: 10px;
    font-family: var(--font-mono);
    font-weight: var(--weight-bold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border: 1px solid var(--border-default);
    background: var(--bg-primary);
    color: var(--text-muted);
    cursor: pointer;
  }

  .date-item-copy-btn:active {
    background: var(--bg-active);
    color: var(--bg-primary);
  }

  /* ============================================================
     TABLE FILTER/SORT DRAWER — slides from right
     ============================================================ */

  .table-filter-drawer {
    position: fixed;
    top: 0;
    right: -280px;
    width: 260px;
    height: 100%;
    background: var(--bg-primary);
    border-left: var(--line-normal) solid var(--border-heavy);
    z-index: 200;
    display: flex;
    flex-direction: column;
    transition: right 0.15s linear !important;
  }

  .table-filter-drawer.open {
    right: 0;
  }

  .table-filter-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2);
    border-bottom: var(--line-hairline) solid var(--border-default);
    min-height: var(--space-touch);
  }

  .table-filter-title {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    font-weight: var(--weight-bold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  .table-filter-close {
    background: none;
    border: none;
    font-size: 18px;
    color: var(--text-muted);
    cursor: pointer;
    min-width: var(--space-touch);
    min-height: var(--space-touch);
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .table-filter-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-2);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
  }

  .table-filter-section {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .table-filter-label {
    font-family: var(--font-mono);
    font-size: 9px;
    font-weight: var(--weight-bold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: var(--line-hairline) solid var(--border-default);
    padding-bottom: 4px;
  }

  .table-filter-select {
    min-height: 36px;
    font-size: var(--text-sm);
    font-family: var(--font-mono);
    padding: 4px 8px;
    border: 1px solid var(--border-default);
    background: var(--bg-primary);
    color: var(--text-primary);
  }

  .table-filter-checks {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 120px;
    overflow-y: auto;
  }

  .table-filter-check {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
    font-size: var(--text-sm);
    cursor: pointer;
  }

  .table-filter-check input[type="checkbox"] {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
  }

  .table-filter-check span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .table-filter-actions {
    display: flex;
    gap: var(--space-1);
    margin-top: auto;
    padding-top: var(--space-2);
    border-top: var(--line-hairline) solid var(--border-default);
  }

  .table-filter-apply {
    flex: 1;
    min-height: 36px;
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    font-weight: var(--weight-bold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border: var(--line-normal) solid var(--text-primary);
    background: var(--text-primary);
    color: var(--bg-primary);
    cursor: pointer;
  }

  .table-filter-reset {
    min-height: 36px;
    padding: 0 var(--space-2);
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border: 1px solid var(--border-default);
    background: none;
    color: var(--text-muted);
    cursor: pointer;
  }

  /* Platform badge (desktop fallback) */
  .deliverable-platform-badge {
    display: inline-block;
    margin-top: 6px;
    padding: 2px 6px;
    border: 1px solid var(--border-default);
    font-size: var(--text-xs);
    font-family: var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
  }

  /* ---- Calendar View: Stack vertically ---- */

  .calendar-layout {
    flex-direction: column;
    gap: 0;
  }

  .calendar-main {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Calendar navigation: sleek minimal bar */
  .calendar-nav {
    min-height: 28px;
    padding: 2px var(--space-1);
    gap: 2px;
    display: flex;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--bg-primary);
    border-bottom: var(--line-hairline) solid var(--border-default);
  }

  .cal-nav-btn {
    min-width: 28px;
    min-height: 28px;
    padding: 0;
    font-size: 12px;
    background: none;
    border: none;
  }

  .cal-month {
    font-size: 11px;
    font-weight: var(--weight-bold);
    letter-spacing: 0.03em;
    white-space: nowrap;
  }

  /* Calendar grid: larger cells */
  .cal-header {
    font-size: var(--text-xs);
    padding: 4px 2px;
  }

  .cal-day {
    min-height: 48px;
    font-size: var(--text-xs);
  }

  .cal-event {
    font-size: 9px;
    padding: 1px 3px;
  }

  /* ---- Calendar Detail: Bottom sheet ---- */

  .calendar-detail {
    width: 100% !important;
    max-height: 0;
    overflow: hidden;
    border-top: var(--line-normal) solid var(--border-heavy);
    border-left: none;
    flex-shrink: 0;
  }

  .calendar-detail.visible {
    width: 100% !important;
    max-height: 50vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .detail-header {
    padding: var(--space-2);
    min-height: var(--space-touch);
  }

  .detail-field {
    padding: var(--space-1) var(--space-2);
  }

  .detail-label {
    font-size: var(--text-xs);
  }

  .detail-value {
    font-size: var(--text-base);
  }

  .detail-brief {
    padding: var(--space-1) var(--space-2);
  }

  .detail-brief-content {
    font-size: var(--text-sm);
    line-height: var(--leading-relaxed);
    max-height: 120px;
    overflow-y: auto;
  }

  .detail-actions {
    padding: var(--space-1) var(--space-2);
    padding-bottom: var(--space-2);
  }

  .btn-copy-prompt {
    min-height: var(--space-touch);
    font-size: var(--text-sm);
  }

  /* ============================================================
     FIX #1: Analytics Drawer — tinted header + no clip
     ============================================================ */

  .viz-drawer {
    border-top: var(--line-normal) solid var(--border-heavy);
  }

  .viz-drawer-toggle {
    min-height: var(--space-touch);
    padding: var(--space-1) var(--space-2);
    background: var(--bg-tertiary);
    border-bottom: var(--line-hairline) solid var(--border-default);
    font-weight: var(--weight-bold);
    color: var(--text-primary);
  }

  .viz-toggle-icon {
    color: var(--accent-primary);
  }

  .viz-metrics-inline {
    font-size: var(--text-xs);
  }

  /* Allow voice/channel analytics to scroll */
  .viz-drawer.open .viz-drawer-content {
    max-height: 50vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Analytics grid: Single column on phone */
  .analytics-grid {
    grid-template-columns: 1fr !important;
    gap: var(--space-1);
  }

  .analytics-panel {
    min-height: auto;
  }

  .heatmap-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* ---- DevTools Drawer: Full-width bottom sheet overlay ---- */

  .devtools-drawer {
    position: fixed !important;
    width: 100% !important;
    max-height: calc(80vh - var(--mobile-nav-height));
    left: 0;
    right: 0;
    bottom: var(--mobile-nav-height);
    z-index: 500;
    overflow-y: auto;
  }

  /* Hide branding on mobile to save space */
  .devtools-branding {
    display: none;
  }

  .devtools-header {
    min-height: var(--space-touch);
    padding: var(--space-2);
  }

  .devtools-close {
    min-width: var(--space-touch);
    min-height: var(--space-touch);
  }

  .devtools-content {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: var(--space-2);
  }

  .domain-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-1);
  }

  .domain-tab {
    min-height: var(--space-touch);
    padding: var(--space-1);
    font-size: var(--text-sm);
    justify-content: center;
  }

  .devtools-section .form-group input {
    min-height: var(--space-touch);
    font-size: var(--text-base);
  }

  .devtools-item {
    min-height: var(--space-touch);
  }

  .devtools-footer {
    padding: var(--space-1) var(--space-2);
    gap: var(--space-1);
  }

  .devtools-footer-btn {
    min-height: var(--space-touch);
    font-size: var(--text-base);
  }

  .devtools-select {
    min-height: 36px;
    font-size: var(--text-base);
  }

  .devtools-toggle-item {
    min-height: var(--space-touch);
    display: flex;
    align-items: center;
  }

  .devtools-checkbox {
    width: 20px;
    height: 20px;
  }

  /* ---- Pack Detail Panel ---- */

  .pack-detail-panel {
    display: none !important;
    width: 0 !important;
  }

  .pack-detail-panel.open {
    display: flex !important;
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100% !important;
    height: 100% !important;
    z-index: 150;
    overflow: visible;
  }

  .pack-detail-header {
    min-height: var(--space-touch);
    padding: var(--space-2);
  }

  .pack-detail-close {
    min-width: var(--space-touch);
    min-height: var(--space-touch);
  }

  .pack-detail-panel.open .pack-detail-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* #6: Voice cards stack vertically as full-width cards */
  .pack-voice-list .expandable-item {
    width: 100%;
  }

  .pack-voice-list .expandable-header {
    flex-wrap: wrap;
    gap: 4px;
    padding: var(--space-2);
  }

  .pack-voice-name {
    flex: 1;
    min-width: 0;
  }

  .voice-expandable {
    padding: var(--space-2);
  }

  .voice-viz-container {
    flex-direction: column;
  }

  .voice-viz-diagram {
    width: 100%;
    max-width: 200px;
    margin: 0 auto;
  }

  /* #6: Voice viz panels — all stacked, collapsed by default */
  .voice-viz-tabs {
    display: none !important;
  }

  .voice-viz-panel {
    display: block !important;
    border-bottom: 1px solid var(--border-default);
  }

  .voice-viz-panel:last-child {
    border-bottom: none;
  }

  /* Collapsed by default: only show header */
  .voice-viz-panel .voice-viz-header {
    padding: var(--space-2);
    cursor: pointer;
  }

  .voice-viz-panel .voice-viz-header::after {
    content: '▸';
    float: right;
    color: var(--text-muted);
    font-size: 12px;
  }

  .voice-viz-panel.expanded .voice-viz-header::after {
    content: '▾';
  }

  .voice-viz-panel .voice-viz-diagram,
  .voice-viz-panel .voice-viz-attr-detail,
  .voice-viz-panel .viz-attr-hint {
    display: none;
  }

  .voice-viz-panel.expanded .voice-viz-diagram {
    display: block;
    max-width: 240px;
    margin: 0 auto;
  }

  .voice-viz-panel.expanded .voice-viz-attr-detail,
  .voice-viz-panel.expanded .viz-attr-hint {
    display: block;
  }

  /* ---- API Viewer ---- */

  .api-viewer {
    width: 100% !important;
    left: 0 !important;
    right: 0 !important;
    max-height: 70vh;
  }

  .api-viewer-header {
    min-height: var(--space-touch);
  }

  .api-call-header {
    min-height: 36px;
    padding: var(--space-1);
    font-size: var(--text-sm);
  }

  /* ---- JGN Modal ---- */

  .jgn-modal {
    padding: 0;
  }

  .jgn-modal-content {
    width: 100% !important;
    height: 100% !important;
    max-width: none;
    max-height: none;
  }

  .jgn-modal-header {
    min-height: var(--space-touch);
    padding: var(--space-2);
  }

  #jgnContent {
    font-size: var(--text-xs);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* ---- Overlay ---- */

  .app-container.overlay::before {
    z-index: 140;
  }

  /* ---- Funnel ---- */

  .funnel-section {
    padding: var(--space-1);
  }

  .funnel-bar {
    height: 28px;
    font-size: var(--text-xs);
  }

  .funnel-legend {
    font-size: var(--text-xs);
    flex-wrap: wrap;
    gap: var(--space-1);
  }

  /* ---- Toast ---- */

  .toast {
    bottom: calc(var(--mobile-nav-height) + 16px) !important;
    left: var(--space-2) !important;
    right: var(--space-2) !important;
    font-size: var(--text-sm);
  }

  #healthScoreCard {
    padding: var(--space-1);
  }

}

/* ============================================================
   BOTTOM NAVIGATION BAR
   ============================================================ */

.mobile-nav {
  display: none;
}

@media (max-width: 768px) {
  .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--mobile-nav-height);
    background: var(--bg-primary);
    border-top: var(--line-normal) solid var(--border-heavy);
    z-index: 300;
    align-items: stretch;
    justify-content: space-around;
    padding: 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .mobile-nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 9px;
    font-weight: var(--weight-bold);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    cursor: pointer;
    padding: 4px 0;
    min-width: 0;
    position: relative;
  }

  .mobile-nav-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 25%;
    right: 25%;
    height: 2px;
    background: transparent;
  }

  .mobile-nav-btn.active {
    color: var(--text-primary);
  }

  .mobile-nav-btn.active::before {
    background: var(--text-primary);
  }

  .mobile-nav-icon {
    font-size: 18px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
  }

  .mobile-nav-label {
    line-height: 1;
  }

  .mobile-nav-btn[data-tab="results"].has-results {
    color: var(--accent-primary);
  }

  .mobile-nav-btn[data-tab="results"].has-results::before {
    background: var(--accent-primary);
  }
}

/* ============================================================
   MOBILE VIEW STATES
   ============================================================ */

@media (max-width: 768px) {

  .results-panel {
    display: none !important;
  }

  [data-mobile-view="results"] .results-panel.visible,
  [data-mobile-view="results"] .results-panel.has-results {
    display: flex !important;
  }

  [data-mobile-view="form"] .app {
    display: flex;
  }

  .devtools-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom, 0px));
    background: rgba(0, 0, 0, 0.4);
    z-index: 499;
  }

  .devtools-backdrop.visible {
    display: block;
  }
}

/* ============================================================
   FIX #7 & #8: MOBILE WEEK VIEW + INFINITE SCROLL
   ============================================================ */

@media (max-width: 768px) {

  /* Week view switcher (Month / Week toggle in calendar nav) */
  .mobile-cal-mode-toggle {
    display: flex;
    gap: 0;
    border: 1px solid var(--border-default);
    margin-left: auto;
  }

  .mobile-cal-mode-btn {
    padding: 2px 8px;
    font-size: 10px;
    font-family: var(--font-mono);
    font-weight: var(--weight-bold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1.4;
  }

  .mobile-cal-mode-btn.active {
    background: var(--text-primary);
    color: var(--bg-primary);
  }

  /* Today button in calendar nav */
  .cal-today-btn {
    padding: 2px 6px;
    font-size: 9px;
    font-family: var(--font-mono);
    font-weight: var(--weight-bold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border: 1px solid var(--border-default);
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1.4;
    margin-left: 4px;
  }

  .cal-today-btn:active {
    background: var(--text-primary);
    color: var(--bg-primary);
  }

  /* Week view container */
  .mobile-week-view {
    display: none;
    flex-direction: column;
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .mobile-week-view.active {
    display: flex;
  }

  /* Hide month grid when week view is active */
  .calendar-grid.hidden-by-week {
    display: none !important;
  }

  /* Week row */
  .mobile-week-row {
    border-bottom: var(--line-hairline) solid var(--border-default);
  }

  .mobile-week-header {
    display: flex;
    align-items: center;
    padding: 6px var(--space-2);
    background: var(--bg-secondary);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    font-weight: var(--weight-bold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    position: sticky;
    top: 0;
    z-index: 3;
  }

  /* Day row within a week */
  .mobile-day-row {
    display: flex;
    align-items: stretch;
    min-height: var(--space-touch);
    border-bottom: var(--line-hairline) solid var(--border-default);
  }

  .mobile-day-label {
    width: 56px;
    flex-shrink: 0;
    padding: var(--space-1);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-right: var(--line-hairline) solid var(--border-default);
    font-family: var(--font-mono);
  }

  .mobile-day-name {
    font-size: 9px;
    font-weight: var(--weight-bold);
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.05em;
  }

  .mobile-day-num {
    font-size: var(--text-md);
    font-weight: var(--weight-bold);
    color: var(--text-primary);
    line-height: 1;
  }

  .mobile-day-row.today .mobile-day-num {
    color: var(--accent-primary);
  }

  .mobile-day-row.other-month .mobile-day-num {
    color: var(--text-muted);
  }

  .mobile-day-events {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 6px var(--space-1);
  }

  .mobile-day-event {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 4px 8px;
    background: var(--bg-primary);
    border: 1px solid var(--border-default);
    cursor: pointer;
    flex: 1;
    min-width: 0;
  }

  .mobile-day-event:active {
    background: var(--bg-tertiary);
    border-color: var(--text-primary);
  }

  .day-event-channel {
    font-size: var(--text-xs);
    font-weight: var(--weight-bold);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .day-event-voice {
    font-size: 10px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .day-event-stage {
    font-size: 9px;
    font-family: var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
  }

  .mobile-day-empty {
    color: var(--text-muted);
    font-size: var(--text-xs);
    padding: 6px;
  }

  /* Infinite scroll sentinel */
  .infinite-scroll-sentinel {
    height: 1px;
    width: 100%;
  }

  /* Loading indicator at bottom */
  .infinite-scroll-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-2);
    font-size: var(--text-xs);
    color: var(--text-muted);
    font-family: var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  /* ============================================================
     MONTH SCROLL VIEW — Multiple months stacked vertically
     Uses the same cal-day/cal-event classes as desktop grid
     ============================================================ */

  .mobile-month-scroll {
    display: none;
    flex-direction: column;
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .mobile-month-scroll.active {
    display: flex;
  }

  .mobile-month-section {
    flex-shrink: 0;
  }

  .mobile-month-header {
    position: sticky;
    top: 0;
    z-index: 3;
    padding: 6px var(--space-2);
    background: var(--bg-secondary);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    font-weight: var(--weight-bold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    border-bottom: var(--line-hairline) solid var(--border-default);
  }

  /* Expand/collapse toggle in month scroll cells */
  .mobile-month-scroll .cal-event-collapse {
    font-style: italic;
    color: var(--text-muted);
  }

  /* Instance grids inside scroll container inherit all .calendar-grid
     and .cal-day styles from the base stylesheet. Only override border. */
  .mobile-month-grid-instance {
    border-top: none;
  }
}

/* ============================================================
   PWA / STANDALONE MODE
   ============================================================ */

@media (display-mode: standalone) {
  .header {
    padding-top: env(safe-area-inset-top, 0px);
  }

  .mobile-nav {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}

/* ============================================================
   TOUCH INTERACTION HELPERS
   ============================================================ */

@media (max-width: 768px) {
  .btn-primary:active,
  .duration-btn:active,
  .objective-card:active,
  .domain-tab:active,
  .mobile-nav-btn:active {
    opacity: 0.7;
  }

  @media (hover: none) {
    .btn-primary:hover,
    .duration-btn:hover,
    .objective-card:hover,
    .domain-tab:hover {
      background: inherit;
      color: inherit;
      border-color: inherit;
    }
  }

  .mobile-nav-btn,
  .btn-primary,
  .duration-btn,
  .objective-card,
  .view-tab-compact,
  .icon-btn {
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }

  .main-content,
  .results-panel-content,
  .devtools-content,
  .pack-detail-body {
    scroll-behavior: smooth;
  }
}

/* ============================================================
   LANDSCAPE PHONE
   ============================================================ */

@media (max-width: 768px) and (max-height: 500px) and (orientation: landscape) {
  :root {
    --mobile-nav-height: 44px;
    --mobile-header-height: 40px;
  }

  .header {
    min-height: 40px;
    padding: 4px var(--space-2);
  }

  .form-section {
    padding: var(--space-1) var(--space-2);
  }

  .mobile-nav {
    height: 44px;
  }

  .mobile-nav-label {
    display: none;
  }

  .mobile-nav-icon {
    font-size: 20px;
  }

  .calendar-detail.visible {
    max-height: 40vh;
  }
}
