/*
 * 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: 44px;
    --mobile-header-height: 52px;
  }
}

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

@media (min-width: 769px) and (max-width: 1024px) {
  .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-3);
    margin-bottom: 0;
    border-bottom: var(--line-hairline) solid var(--border-default);
    flex-shrink: 0;
    min-height: 36px;
    align-items: center;
    overflow: visible; /* SP-082: allow dropdown to escape header bounds */
  }

  /* SP-082: Remove transform containing block from .right-panel so that
     position:fixed elements inside it (auth modal) can escape to viewport.
     .right-panel has 0 height on mobile, so removing its animation has no
     visual effect. Without this, will-change:transform and transform:translate(0,0)
     from page-load-transitions.css trap position:fixed descendants. */
  .right-panel {
    transform: none !important;
    will-change: auto !important;
  }

  /* SP-082: Increase tap target to 44px minimum on mobile */
  .user-dropdown-item {
    padding: 14px 16px;
    font-size: 15px;
    min-height: 44px;
  }

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

  .jargan-lockup {
    height: 16px;
    width: auto;
    flex-shrink: 0;
    overflow: visible;
  }

  .logo {
    flex-shrink: 0;
    overflow: visible;
    margin-right: 4px;
  }

  .domain-select {
    font-size: var(--text-sm);
    flex-shrink: 1;
    min-width: 0;
  }

  .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: var(--mobile-nav-height);
    scroll-padding-bottom: 160px; /* Account for sticky generate-controls overlay */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain; /* Prevent browser pull-to-refresh */
  }

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

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

  .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 + diamond 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: 18px;
    height: 18px;
    background: var(--text-primary);
    cursor: pointer;
    border: none;
    margin-top: -8px; /* Center: -(18/2 - 2/2) = -8 */
    transform: rotate(45deg);
  }

  .slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    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;
    gap: 4px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
  }

  /* When a goal is elected, fade the grid so the throne dominates */
  .objective-grid.has-elected {
    opacity: 0.45;
  }

  /* ---- Goal Throne: prevent truncation on narrow screens ---- */
  .goal-throne {
    margin-bottom: 4px;
  }

  .throne-name {
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
    font-size: 12px;
  }

  .throne-desc {
    -webkit-line-clamp: 2;
    font-size: 10px;
  }

  .throne-card {
    padding: 6px 8px;
    gap: 6px;
  }

  .throne-icon {
    width: 28px;
    height: 28px;
    min-width: 28px;
    font-size: 14px;
  }

  /* 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)
     ============================================================ */

  /* Hide the old standalone preview section on mobile */
  #previewSection {
    display: none !important;
  }

  /* 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;
  }

  .objective-preview-drawer .preview-section-row {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    margin-bottom: 4px;
  }

  .objective-preview-drawer .preview-section-row:last-child {
    margin-bottom: 0;
  }

  .objective-preview-drawer .preview-section-icon {
    flex-shrink: 0;
    width: 14px;
    height: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    margin-top: 1px;
  }

  .objective-preview-drawer .preview-section-icon svg {
    width: 12px;
    height: 12px;
  }

  .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);
  }

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

  /* SP-058: No-partner message in mobile drawer */
  .preview-no-partner {
    padding: var(--space-1);
    font-size: var(--text-xs);
  }

  /* 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 */
  /* SP-062: Mobile layout only applies when workflow-ready (controls are visible) */
  .generate-controls.workflow-ready {
    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;
    overflow: visible;  /* SP-076: override desktop overflow:hidden that clips date field border */
  }

  .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);
    align-items: stretch;
    max-width: 100%;       /* SP-076: prevent children from overflowing parent padding */
    box-sizing: border-box;
  }

  .generate-controls .form-col,
  .generate-controls .form-col-wide {
    display: flex;
    flex-direction: column;
  }

  .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 {
    -webkit-appearance: none;
    appearance: none;
    flex: 1;
    min-height: 0;
    min-width: 0;          /* SP-076: override desktop min-width:130px that clips right border */
    font-size: 12px;
    padding: 4px 4px;      /* SP-076: tighter horizontal padding for mobile */
    box-sizing: border-box;
    text-align: center;
  }

  /* Strip WebKit shadow DOM padding inside date inputs */
  .generate-controls .date-input::-webkit-datetime-edit,
  .generate-controls .date-input::-webkit-datetime-edit-fields-wrapper,
  .generate-controls .date-input::-webkit-datetime-edit-text {
    padding: 0;
  }

  .generate-controls .date-input::-webkit-calendar-picker-indicator {
    display: none;
  }

  .generate-controls .slider {
    margin: 8px 0 16px;
  }

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

  /* Spacing between Generate button and mobile nav bar */
  .generate-controls.workflow-ready {
    padding-bottom: 16px;
  }

  .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);
    position: relative;
  }

  .results-header-top {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: var(--space-1);
  }

  /* Left: goal name + partner + dates */
  .results-header-left {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    gap: 2px;
  }

  .schedule-name-input-compact {
    font-size: var(--text-sm);
    font-weight: 700;
    width: 100%;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Hide deliverable count on mobile */
  #resultsCount {
    display: none;
  }

  .results-meta-compact {
    font-size: var(--text-xs);
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
    color: var(--text-muted);
  }

  /* Right: buttons in a single row on mobile */
  .results-header-right {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    flex-wrap: nowrap;
  }

  /* Hide redundant elements on mobile results header */
  #copyBtn,
  #showJgnBtn {
    display: none !important;
  }

  /* View tabs (list/calendar) stay in results header on mobile */
  .results-header-right .view-tabs-compact {
    display: flex;
    gap: 2px;
  }

  /* Hide connection status in results header — already in main header */
  .results-header-right .desktop-connection-status {
    display: none !important;
  }

  .view-tab-compact {
    min-width: 28px;
    min-height: 28px;
    font-size: var(--text-xs);
    padding: 2px 4px;
  }

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

  .icon-btn svg {
    width: 14px;
    height: 14px;
  }

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

  /* ---- Results Content: remove gray container ---- */

  .results-panel-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    padding: 0;
    padding-bottom: var(--mobile-nav-height);
    background: var(--bg-primary);
  }

  .results-details {
    padding: 0;
    gap: 0;
  }

  .results-layout {
    gap: 0;
  }

  /* ============================================================
     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 {
    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 */
  .deliverable-date-row {
    display: flex;
    align-items: center;
    padding: var(--space-2);
    border: 1px solid var(--border-default);
    background: var(--bg-primary);
    cursor: pointer;
    gap: var(--space-2);
  }

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

  .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;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
  }

  .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 {
    padding: var(--space-2);
    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);
  }

  .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;
  }

  /* 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, zero waste ---- */

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

  .calendar-main {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  .calendar-grid {
    border: none;
    grid-template-columns: repeat(7, 1fr) !important;
    min-width: 0 !important;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  /* Calendar navigation: two rows on mobile */
  .calendar-nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 4px 8px;
    padding: 6px 12px;
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--bg-primary);
    border: none;
    border-bottom: var(--line-hairline) solid var(--border-default);
    min-width: 0 !important;
    min-height: 44px;
    max-width: 100%;
    box-sizing: border-box;
  }

  .cal-nav-btn {
    min-width: 40px;
    min-height: 40px;
    padding: 0;
    font-size: 16px;
    background: var(--bg-tertiary, #f0f0f0);
    border: none;
    border-radius: 8px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }
  .cal-month {
    font-size: 14px;
    font-weight: var(--weight-bold);
    letter-spacing: 0.02em;
    white-space: nowrap;
    text-align: center;
    flex: 1;
    min-width: 0;
  }
  /* Month nav row: prev < Month Year > next — centered, full width */
  .cal-nav-left {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 100%;
  }
  /* Hide desktop-only center/right sections on mobile */
  .cal-nav-center,
  .cal-nav-right {
    display: none;
  }

  /* Row 2: Month/Week + Today */
  .calendar-nav .mobile-cal-mode-toggle {
    order: 20;
    flex-basis: auto;
    display: flex;
    justify-content: center;
    gap: 0;
    margin: 0 auto;
  }
  .calendar-nav #calTodayBtn {
    order: 21;
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 10px;
    padding: 2px 8px;
  }

  /* Calendar grid: compact icon-only cells */
  .calendar-grid {
    grid-template-columns: repeat(7, 1fr) !important;
  }
  /* Shrink empty day-of-week columns */
  .calendar-grid.has-empty-cols {
    grid-template-columns: var(--cal-col-template, repeat(7, 1fr)) !important;
  }

  .cal-header {
    font-size: 9px;
    padding: 4px 1px;
    text-align: center;
    letter-spacing: 0;
  }
  /* Single-letter day headers on mobile */
  .cal-header { font-size: 0; }
  .cal-header::after { font-size: 9px; }
  .cal-header:nth-child(1)::after { content: 'S'; }
  .cal-header:nth-child(2)::after { content: 'M'; }
  .cal-header:nth-child(3)::after { content: 'T'; }
  .cal-header:nth-child(4)::after { content: 'W'; }
  .cal-header:nth-child(5)::after { content: 'T'; }
  .cal-header:nth-child(6)::after { content: 'F'; }
  .cal-header:nth-child(7)::after { content: 'S'; }

  .cal-day {
    min-height: 44px;
    padding: 2px;
    font-size: 10px;
    box-sizing: border-box;
  }

  .cal-day-num {
    font-size: 10px;
    margin-bottom: 1px;
  }

  /* Icon-only events: hide text labels, show platform icon as dot */
  .cal-event {
    padding: 2px;
    margin-bottom: 1px;
    gap: 0;
    justify-content: center;
    border-left-width: 0;
    border-radius: 3px;
    /* SP-425/426: SP-424 added .cal-event class to mobile pills; suppress selection + scroll hijack */
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    touch-action: none;
  }
  .cal-event-label {
    display: none;
  }
  .cal-event-icon {
    width: 14px;
    height: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .cal-event-icon svg {
    width: 12px;
    height: 12px;
  }

  .cal-event-more {
    font-size: 8px;
    padding: 1px 2px;
    text-align: center;
  }

  .cal-event-collapse {
    font-size: 9px;
    text-align: center;
    color: #888;
    padding: 1px 0;
    cursor: pointer;
    line-height: 1;
    user-select: none;
    -webkit-user-select: none;
  }
  .cal-event-collapse:active {
    color: #DD5100;
  }

  /* Empty columns shrink */
  .cal-header.col-empty,
  .cal-day.col-empty {
    max-width: 20px;
    min-height: 32px;
    overflow: hidden;
  }
  .cal-header.col-empty {
    min-height: unset;
  }

  /* ---- 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;
  }

  /* ── Calendar Detail: Compact card layout ── */

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

  .detail-header {
    padding: 10px 14px;
    min-height: unset;
    background: var(--bg-tertiary, #f0f0f0);
  }

  .detail-date {
    font-size: 13px;
  }

  .detail-content {
    padding: 8px 14px 6px;
  }

  /* Pill-style metadata row — all three fields on one line */
  .detail-field {
    display: inline-flex;
    align-items: baseline;
    gap: 4px;
    padding: 0;
    margin-bottom: 0;
    margin-right: 12px;
  }

  .detail-label {
    font-size: 9px;
    margin-bottom: 0;
    opacity: 0.6;
  }

  .detail-value {
    font-size: 13px;
    font-weight: 500;
  }

  /* Brief section — compact with fade */
  .detail-brief {
    padding: 8px 0 4px;
    margin-top: 6px;
    border-top: 1px solid var(--border-default, #e8e8e8);
  }

  .detail-brief .detail-label {
    display: none; /* "Content Brief" label is redundant in context */
  }

  .detail-brief-content {
    font-size: 12px;
    line-height: 1.5;
    max-height: 72px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    color: var(--text-secondary, #666);
  }

  /* Actions — compact row */
  .detail-actions {
    padding: 6px 0;
    margin-top: 4px;
    border-top: none;
  }

  .btn-copy-prompt {
    min-height: 34px;
    font-size: 11px;
    padding: 6px 10px;
  }

  .detail-fiverr-footer {
    padding: 4px 14px 8px;
  }

  .btn-fiverr-cta {
    min-height: 34px;
    font-size: 11px;
    padding: 5px 10px;
  }

  .fiverr-banner-btn {
    min-height: 34px;
  }

  /* ============================================================
     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: 8px 12px;
    background: var(--bg-tertiary);
    border-bottom: var(--line-hairline) solid var(--border-default);
    font-weight: var(--weight-bold);
    color: var(--text-primary);
    gap: 6px;
  }

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

  .viz-toggle-text {
    font-size: 12px;
  }

  .viz-metrics-inline {
    font-size: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

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

  /* Workbench panels — tighter on mobile */
  .wb-stats-row {
    gap: 4px;
    margin-bottom: 6px;
  }

  .wb-stat-card {
    padding: 6px 4px;
  }

  .wb-stat-value {
    font-size: 16px;
  }

  .wb-stat-label {
    font-size: 8px;
  }

  .wb-panel-header {
    padding: 5px 8px;
    min-height: 24px;
  }

  .wb-panel-title {
    font-size: 9px;
  }

  .wb-panel-body {
    padding: 6px;
  }

  /* Sankey: reduce min-height for mobile */
  #wbSankeyBody {
    min-height: 160px;
  }

  /* Bubble matrix: allow horizontal scroll */
  .wb-bubble-matrix {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .wb-bubble-cell {
    min-width: 36px;
    min-height: 36px;
  }

  .wb-bubble-corner,
  .wb-bubble-stage {
    min-width: 56px;
    flex: 0 0 56px;
    font-size: 9px;
  }

  /* Stacked bar labels: narrower */
  .wb-stacked-label {
    width: 60px;
    font-size: 9px;
  }

  .wb-stacked-row {
    gap: 4px;
    height: 20px;
  }

  .wb-stacked-bar-container {
    height: 16px;
  }

  /* ── Workbench expanded panels: full-viewport on mobile ── */
  .wb-expanded {
    position: fixed !important;
    inset: 0 !important;
    z-index: 1000 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--wb-surface, #F7F5F0);
    margin: 0 !important;
  }

  .wb-expanded .wb-panel-header {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--wb-surface-alt, #F1EFE8);
    padding: 10px 12px;
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  .wb-expanded .wb-panel-body {
    height: auto;
    min-height: calc(100vh - 56px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px;
  }

  /* Siblings hidden when one panel is expanded */
  .wb-panel.wb-hidden-by-expand,
  .wb-panel-full.wb-hidden-by-expand,
  .wb-grid-half.wb-hidden-by-expand,
  .wb-stats-row.wb-hidden-by-expand {
    display: none !important;
  }

  /* Allow the analytics drawer to grow when a panel is expanded inside it */
  .viz-drawer.open .viz-drawer-content:has(.wb-expanded) {
    max-height: none;
    overflow: visible;
  }

  /* 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;
    /* HEADER ships at z-index 200 with position:relative; a 150 panel sat
       behind it and the brand bar poked through the full-screen modal on
       mobile. 300 reliably covers the header AND the workflow stagger
       layers (z-index 5/10/100). */
    z-index: 300;
    overflow: visible;
    /* Ensure the inner header isn't constrained by the desktop min-width:
       340px (set in styles-instrument-paper-v2.css) which can push content
       wider than narrow viewports. */
    background: var(--bg-primary);
  }

  .pack-detail-panel.open .pack-detail-header,
  .pack-detail-panel.open .pack-detail-body {
    min-width: 0 !important;
  }

  .pack-detail-header {
    min-height: var(--space-touch);
    padding: var(--space-2);
    /* Sticky inside the panel so the title + close stay visible while the
       body scrolls. Background prevents bleed-through. */
    position: sticky;
    top: 0;
    background: var(--bg-primary);
    z-index: 1;
  }

  .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 ---- */
  /* SP-418: iOS-banner style — anchored at top:0, drops over the app header.
     Never overlaps calendar/workbench content. Clears translateX(-50%) from
     desktop base. Slides DOWN from top of screen, slides UP to dismiss. */

  .toast {
    bottom: auto !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    border-radius: 0 0 12px 12px !important;
    transform: translateX(0) translateY(-110%) !important;
    font-size: var(--text-sm);
    z-index: 9999 !important;
    /* SP-436: Use the app's elevated-surface token as a fully opaque base so the
       panel header never bleeds through. Desktop base already uses --bg-tertiary
       but success/error types override it with rgba(…0.1) — transparent on mobile. */
    background: var(--bg-tertiary) !important;
    border: 1px solid var(--border-default) !important;
    box-shadow: 0 2px 12px rgba(0,0,0,0.12) !important;
    padding: 12px 16px !important;
  }
  .toast.show {
    transform: translateX(0) translateY(0) !important;
  }
  /* Left-border accent keeps type visible without transparent tints */
  .toast.success { border-left: 3px solid var(--success) !important; }
  .toast.error   { border-left: 3px solid var(--error) !important; }
  .toast.info    { border-left: 3px solid var(--accent-jargan, #DD5100) !important; }

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

  /* ============================================================
     SP-065 FIX #1: Collapse dead space below Analytics on mobile

     Root cause: .results-layout has flex:1 + overflow:hidden from
     desktop CSS, forcing it to fill the full panel height even when
     the viz-drawer is collapsed. The space between the collapsed
     drawer toggle and the layout bottom becomes dead whitespace.

     Fix: Let results-layout shrink to content height on mobile.
     The parent (.results-panel-content) already handles scrolling.

     SP-084: re-fix with !important to survive later stylesheet overrides
     ============================================================ */

  .results-layout {
    flex: 0 1 auto !important;
    overflow: visible !important;
  }

  .results-details {
    flex: 0 1 auto !important;
    overflow: visible !important;
  }

  /* ============================================================
     SP-065 FIX #2: CTA ticker readable on mobile

     The marquee scroll is hard to read on narrow viewports — text
     is wider than the screen so users only see a clipped fragment.
     On mobile, stop the animation and show a single static message
     that wraps within the viewport width. The second buildStrip()
     copy (for seamless looping) and extra messages are hidden so
     only the first message is visible.
     ============================================================ */

  .upsell-ticker {
    height: auto;
    min-height: 24px;
    padding: 6px 12px;
  }

  .upsell-ticker .upsell-ticker-track {
    animation: none !important;
    white-space: normal;
    flex-wrap: wrap;
    padding-left: 0;
    overflow: hidden;
  }

  /* Show only the first message; hide separators and subsequent messages */
  .upsell-ticker-msg {
    white-space: normal;
    line-height: 1.4;
    font-size: 11px;
  }

  .upsell-ticker-sep {
    display: none;
  }

  .upsell-ticker-msg ~ .upsell-ticker-msg {
    display: none;
  }

  /* ============================================================
     SP-069: Tighten spacing between CTA ticker, Analytics drawer,
     and upsell prompt card on mobile.

     Root cause: .results-details has gap:16px (--space-2) from
     base CSS, and .upsell-prompt has margin-top:12px.  Combined
     with flex layout these create generous whitespace between the
     three elements that should feel like one cohesive bottom
     section on mobile.

     Fix: Collapse the gap in results-details, remove margin above
     the upsell-prompt, and zero out any extra margin on the
     viz-drawer so the three items stack tightly.

     SP-084: re-fix with !important to survive later stylesheet overrides
     ============================================================ */

  .results-details {
    gap: 0 !important;
  }

  .viz-drawer {
    margin-top: 0 !important;
  }

  .upsell-prompt {
    margin-top: 4px !important;
  }

  /* Remove any bottom margin on ticker so it butts up against drawer */
  .upsell-ticker {
    margin-bottom: 0 !important;
  }

}

/* ============================================================
   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: 15px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
  }

  .mobile-nav-label {
    line-height: 1;
    font-size: 8px;
  }

  .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 view: hide old month nav row (week headers replace it) */
  .calendar-main.infinite-week-active > .calendar-nav .cal-nav-left {
    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;
    /* SP-425: suppress iOS long-press text selection + copy/paste callout during drag hold */
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    /* SP-426: tell the browser NOT to claim this touch for scrolling before pointerdown fires.
       Without this, the browser fires pointercancel before our 150ms hold timer completes.
       touch-action must be set in CSS — dynamically setting it after pointerdown is too late. */
    touch-action: none;
  }

  .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;
  }
}

/* ============================================================
   SP-073: INFINITE MONTH SCROLL (MOBILE ONLY)
   ============================================================ */

@media (max-width: 768px) {

  /* Container: hidden by default, shown when active */
  .mobile-month-scroll {
    display: none;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    position: relative;
  }

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

  /* Sticky header: month indicator + day-of-week headers */
  .month-scroll-sticky-header {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--bg-primary);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-bottom: var(--line-hairline) solid var(--border-default);
    flex-shrink: 0;
  }

  /* Header row: month indicator + Today button */
  .month-scroll-header-row {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 2px 12px;
  }

  /* Sticky month indicator */
  .month-scroll-indicator {
    padding: 4px 0;
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: var(--weight-bold);
    letter-spacing: 0.02em;
    color: var(--text-primary);
    text-align: center;
    white-space: nowrap;
    flex: 1;
    background: var(--bg-primary, #fff);
    background: color-mix(in srgb, var(--bg-primary, #fff) 85%, transparent);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }

  /* SP-434: Today button in infinite month scroll header */
  .month-scroll-today-btn {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 10px;
    font-family: var(--font-mono);
    font-weight: var(--weight-bold);
    padding: 2px 8px;
    border: 1px solid var(--accent-jargan, #DD5100);
    border-radius: 4px;
    background: transparent;
    color: var(--accent-jargan, #DD5100);
    cursor: pointer;
    letter-spacing: 0.02em;
    text-transform: uppercase;
  }
  .month-scroll-today-btn:active {
    background: var(--accent-jargan, #DD5100);
    color: #fff;
  }

  /* SP-435: Undo/redo/revert bar under month indicator */
  .month-scroll-undo-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px 2px;
  }

  .month-undo-btn {
    background: transparent;
    border: 1px solid #444;
    border-radius: 12px;
    color: #bbb;
    font-size: 11px;
    padding: 3px 10px;
    cursor: pointer;
    font-family: monospace;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.15s, border-color 0.15s;
  }
  .month-undo-btn:disabled {
    opacity: 0.35;
    cursor: default;
  }
  .month-undo-btn:not(:disabled):active {
    color: #DD5100;
    border-color: #DD5100;
  }

  .month-revert-btn {
    margin-left: auto;
    color: #aaa;
    border-color: #555;
  }
  .month-revert-btn:not(:disabled):active {
    color: #e55;
    border-color: #e55;
  }

  /* Day-of-week headers (render once, sticky) */
  .month-scroll-day-headers {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    text-align: center;
  }

  .month-scroll-day-headers .cal-header {
    font-size: 9px;
    padding: 3px 1px;
    text-align: center;
    letter-spacing: 0;
    font-family: var(--font-mono);
    font-weight: var(--weight-bold);
    text-transform: uppercase;
    color: var(--text-muted);
  }

  /* Override the paginated-grid trick that hides text and uses ::after */
  .month-scroll-day-headers .cal-header::after {
    content: none;
  }

  /* Scrollable body containing all month sections */
  .month-scroll-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: auto;
  }

  /* Individual month section */
  .month-scroll-section {
    position: relative;
  }

  /* Subtle month transition: thin divider + inline label */
  .month-scroll-section + .month-scroll-section {
    border-top: 1px solid var(--border-default, #e0e0e0);
    padding-top: 4px;
  }

  /* Inline month label between grid sections */
  .month-scroll-label {
    font-size: 11px;
    font-family: var(--font-mono);
    font-weight: var(--weight-bold);
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted, #999);
    padding: 8px 12px 4px;
  }

  /* First month section: no top border, hide label (indicator shows it) */
  .month-scroll-section:first-of-type {
    border-top: none;
    padding-top: 0;
  }

  /* 7-column grid matching existing calendar layout */
  .month-scroll-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    width: 100%;
    box-sizing: border-box;
  }

  /* Reuse existing .cal-day styles — they're already defined above */
  /* The month-scroll-grid .cal-day inherits from the existing rules */

  /* Empty overlay within infinite scroll sections */
  .month-scroll-empty {
    position: relative;
    grid-column: 1 / -1;
    padding: 8px 12px;
  }

  .month-scroll-empty .cal-empty-text {
    font-size: 10px;
    padding: 4px 0;
  }

  /* Sentinel for infinite scroll */
  .month-scroll-sentinel {
    height: 1px;
    width: 100%;
    flex-shrink: 0;
  }

  /* SP-073 fix: Hide old paginated calendar when infinite month scroll is active.
     Uses a class on .calendar-main instead of sibling selectors (which can't
     target preceding siblings) or inline style.display hacks (which race
     with renderCalendar()). Hide the entire .calendar-nav container — its
     children (.cal-nav-left, month/week toggle, Today btn) are already hidden
     or irrelevant, but the container itself still occupies ~60px via padding
     and flex layout. */
  .calendar-main.infinite-month-active > .calendar-nav {
    display: none !important;
  }
  .calendar-main.infinite-month-active > .calendar-grid {
    display: none !important;
  }
}

/* ============================================================
   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,
    .objective-card:hover,
    .domain-tab:hover {
      background: inherit;
      color: inherit;
      border-color: inherit;
    }
    /* duration-btn excluded — active class handles its state cleanly */
  }

  .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;
  }
}
