/* Bilingual HQ V19.0.2 — unified mobile design system */
@media (max-width: 760px) {
  :root {
    --mobile-page-gutter: 18px;
    --mobile-card-padding: 18px;
    --mobile-section-gap: 16px;
    --mobile-card-radius: 16px;
    --mobile-border: #e1e5ec;
    --mobile-muted: #747b8a;
  }

  body { font-size: 14px; line-height: 1.45; background: #f6f7f9; }
  .page { padding: 22px var(--mobile-page-gutter) 48px; }

  /* Stable app header and shared page title rhythm */
  .page-header { padding: 12px var(--mobile-page-gutter); min-height: 72px; }
  .page-header-left { gap: 12px; }
  .mobile-menu { width: 40px; height: 40px; flex-basis: 40px; }
  .page-header h1 { font-size: 22px; line-height: 1.2; letter-spacing: -.02em; }
  #quickAddBtn { min-height: 40px; padding: 9px 13px; font-size: 13px; border-radius: 10px; }

  .section-title { margin: 0 0 18px; align-items: flex-start; gap: 14px; }
  .section-title h2 { margin: 0 0 5px; font-size: 22px; line-height: 1.25; letter-spacing: -.02em; }
  .section-title p { font-size: 13px; line-height: 1.5; color: var(--mobile-muted); }
  .section-title .btn { min-height: 40px; padding: 9px 12px; font-size: 13px; border-radius: 10px; }

  /* One consistent card surface across every module */
  .widget,
  .overall-progress-card,
  .phase-card,
  .board-card,
  .module-summary-card,
  .governance-health > article,
  .founder-card,
  .document-card,
  .programme,
  .strategy-card,
  .hq-panel,
  .marketing-os-card,
  .manual-group,
  .manual-category-card {
    border-color: var(--mobile-border);
    border-radius: var(--mobile-card-radius);
    box-shadow: 0 1px 2px rgba(27,31,43,.03);
  }

  /* Summary metrics: use compact balanced tiles, not tall desktop cards */
  .module-summary-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: var(--mobile-section-gap);
  }
  .module-summary-card {
    min-height: 104px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    text-align: left;
  }
  .module-summary-card span { font-size: 12px; color: var(--mobile-muted); }
  .module-summary-card strong { margin: 7px 0 4px; font-size: 26px; line-height: 1; letter-spacing: -.03em; }
  .module-summary-card small { font-size: 11px; line-height: 1.35; }

  .metric-strip {
    grid-template-columns: repeat(2, minmax(0,1fr));
    gap: 10px;
    padding: 0;
    border: 0;
    background: transparent;
  }
  .metric-strip > div {
    min-width: 0;
    min-height: 100px;
    padding: 16px;
    border: 1px solid var(--mobile-border) !important;
    border-radius: var(--mobile-card-radius);
    background: #fff;
  }
  .metric-strip strong { font-size: 24px; }

  /* Home: balanced 2x2 overview grid and aligned icon keyline */
  .home-top { margin-bottom: 18px; }
  .home-top h2 { font-size: 27px; line-height: 1.2; letter-spacing: -.03em; }
  .home-top p { font-size: 13px; }
  .home-shortcuts,
  .home-shortcuts.home-shortcuts-four {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-top: 18px;
    overflow: visible;
  }
  .home-shortcuts button {
    min-height: 112px;
    padding: 16px;
    border-radius: var(--mobile-card-radius);
    align-items: flex-start;
    justify-content: flex-start;
    flex-direction: column;
    gap: 12px;
    text-align: left;
  }
  .home-shortcuts button::after { position: absolute; right: 14px; top: 14px; }
  .home-shortcuts button > span:last-child { white-space: normal; font-size: 13px; }
  .home-shortcuts strong { font-size: 26px; line-height: 1; }
  .shortcut-icon { width: 36px; height: 36px; flex-basis: 36px; border-radius: 10px; }

  .overall-progress-card { padding: 20px; }
  .overall-progress-card strong { font-size: 42px; line-height: 1; }
  .phase-row { gap: 12px; }
  .phase-card { padding: 17px 18px; min-height: 118px; }
  .phase-card strong { font-size: 16px; }
  .phase-card small { font-size: 12px; }
  .phase-card b { font-size: 24px; }

  /* Governance: group the three small metrics into one balanced row */
  .governance-health {
    grid-template-columns: repeat(3, minmax(0,1fr));
    gap: 10px;
    margin-bottom: var(--mobile-section-gap);
  }
  .governance-health > article {
    min-height: 108px;
    padding: 16px;
    justify-content: center;
  }
  .governance-health > article:not(.governance-health-main) span { font-size: 11px; }
  .governance-health > article:not(.governance-health-main) strong { font-size: 28px; line-height: 1; }
  .governance-health > article:not(.governance-health-main) small { font-size: 10px; line-height: 1.35; }
  .governance-health-main {
    grid-column: 1 / -1;
    min-height: 132px !important;
    padding: 20px 20px 20px 22px !important;
  }
  .governance-health-main h3 { font-size: 25px; line-height: 1.15; }
  .governance-health-main p { font-size: 12px; line-height: 1.45; }
  .governance-health-main > strong { font-size: 38px !important; }

  .founder-grid { gap: 12px; }
  .founder-card { padding: 18px; min-height: 0; }
  .founder-avatar { width: 42px; height: 42px; border-radius: 11px; }
  .founder-card h3 { font-size: 17px; }
  .founder-card p { font-size: 12px; }

  /* Shared content keyline: icons and body copy never hug the viewport */
  .board-card,
  .programme,
  .document-card,
  .strategy-card,
  .marketing-info-card,
  .marketing-asset-card,
  .manual-category-card { padding: var(--mobile-card-padding); }
  .board-card-icon,
  .programme-icon,
  .manual-category-icon { width: 36px; height: 36px; border-radius: 10px; }
  .board-card h3,
  .programme h3,
  .document-card h3,
  .strategy-card h3 { font-size: 15px; }
  .board-card p,
  .programme p,
  .document-card p,
  .strategy-card p { font-size: 12px; }

  /* Dense lists keep readable internal padding */
  .task-table { border-radius: 12px; }
  .task-row,
  .check-row { padding: 13px 12px; gap: 10px; }
  .task-title,
  .check-title { font-size: 13px; line-height: 1.45; }
  .row-actions { gap: 8px; }
  .icon-action { min-height: 34px; padding: 7px 10px; }

  .details-list { padding: 0 2px; }
  .detail-row { padding: 14px 4px; gap: 12px; }
  .detail-row span { font-size: 12px; }
  .detail-row strong { font-size: 14px; line-height: 1.45; }

  /* Tables: preserve data, but give mobile cards a real inset keyline */
  .mobile-record-card,
  .mobile-file-card,
  .mobile-decision-card { padding: 18px !important; margin: 0 0 12px; border-radius: 14px !important; }

  /* Avoid oversized display typography inherited from desktop modules */
  .widget-head h3 { font-size: 17px; line-height: 1.3; }
  .widget-head span { font-size: 12px; line-height: 1.45; }
  .score { font-size: 12px; }

  /* Form controls and tabs meet mobile touch targets */
  input, select, textarea { min-height: 42px; }
  .btn, .mini-btn { min-height: 40px; }
  .marketing-os-tabs button { min-height: 42px; padding: 10px 13px; }
}

@media (max-width: 430px) {
  .module-summary-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .module-summary-card:last-child:nth-child(odd) { grid-column: 1 / -1; min-height: 88px; }
  .governance-health { grid-template-columns: repeat(3, minmax(0,1fr)); }
}

@media (max-width: 360px) {
  :root { --mobile-page-gutter: 14px; --mobile-card-padding: 15px; }
  .page-header h1 { font-size: 20px; }
  .home-shortcuts, .home-shortcuts.home-shortcuts-four { gap: 8px; }
  .home-shortcuts button { min-height: 104px; padding: 14px; }
  .governance-health > article:not(.governance-health-main) { padding: 12px 10px; }
}

/* V19.0.1 — remove horizontal scrolling and compact mobile action rows */
@media (max-width: 760px) {
  html, body, .main, .page { max-width: 100%; overflow-x: hidden; }
  .page > *, .widget, .hq-panel, .timeline-control-bar { min-width: 0; max-width: 100%; }

  /* Checklist rows: title/meta on the left, actions fixed at the far right */
  .checklist { width: 100%; }
  .check-row {
    grid-template-columns: 22px minmax(0, 1fr) auto;
    grid-template-areas:
      "check title actions"
      ". meta1 actions"
      ". meta2 actions";
    align-items: start;
    min-height: 0;
    padding: 13px 12px;
    column-gap: 10px;
    row-gap: 3px;
  }
  .check-row > input { grid-area: check; margin-top: 2px; }
  .check-row > .check-title { grid-area: title; padding-right: 4px; }
  .check-row > .check-meta:nth-of-type(2) { grid-area: meta1; }
  .check-row > .check-meta:nth-of-type(3) { grid-area: meta2; }
  .check-row > .check-meta:empty { display: none; }
  .check-row > .row-actions {
    grid-area: actions;
    grid-column: auto;
    align-self: center;
    justify-self: end;
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0;
  }
  .check-row .icon-action {
    min-width: 48px;
    min-height: 32px;
    padding: 5px 8px;
    white-space: nowrap;
  }

  /* Brand & marketing: every control wraps inside the viewport */
  .marketing-os-title { display: grid; grid-template-columns: 1fr; gap: 14px; }
  .marketing-title-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    overflow: visible;
  }
  .marketing-title-actions .btn { width: 100%; min-width: 0; white-space: normal; }
  .marketing-os-tabs {
    position: static;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
    overflow: visible;
    padding: 7px;
  }
  .marketing-os-tabs button {
    width: 100%;
    min-width: 0;
    padding: 9px 6px;
    white-space: normal;
    line-height: 1.25;
  }
  .asset-filter-row,
  .approval-stage-strip { flex-wrap: wrap; overflow: visible; }

  /* Franchise CRM: pipeline becomes a vertical stage list */
  .crm-pipeline-panel { overflow: hidden; }
  .pipeline-board {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    width: 100%;
    max-width: 100%;
    overflow: visible;
    padding-bottom: 0;
  }
  .pipeline-column {
    width: 100%;
    min-width: 0;
    min-height: 0;
    padding: 11px;
  }
  .pipeline-column > header { margin-bottom: 8px; }
  .pipeline-card { width: 100%; max-width: 100%; }

  /* Timeline: tabs, filters and phase cards wrap instead of scrolling */
  .timeline-header-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }
  .timeline-header-actions .btn { width: 100%; min-width: 0; white-space: normal; }
  .timeline-control-bar { padding: 10px; }
  .timeline-view-tabs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    gap: 7px;
    overflow: visible;
  }
  .timeline-view-tabs button {
    width: 100%;
    min-width: 0;
    padding: 9px 6px;
    white-space: normal;
    line-height: 1.25;
  }
  .timeline-controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    gap: 9px;
  }
  .timeline-controls input { grid-column: 1 / -1; }
  .timeline-controls input,
  .timeline-controls select { width: 100%; min-width: 0; }
  .timeline-quick-filters {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    width: 100%;
    overflow: visible;
  }
  .timeline-quick-filters button {
    min-width: 0;
    padding: 8px 4px;
    white-space: normal;
    line-height: 1.2;
  }
  .timeline-phase-strip {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
    width: 100%;
    overflow: visible;
    padding-bottom: 0;
  }
  .timeline-phase-strip .timeline-phase-card,
  .timeline-phase-strip article {
    width: 100%;
    min-width: 0;
  }
}

@media (max-width: 390px) {
  .marketing-os-tabs,
  .timeline-view-tabs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .timeline-quick-filters { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* V19.0.2 — verified mobile compactness and header flow fix */
@media (max-width: 760px) {
  /* Keep the fixed black utility bar, but remove the duplicate blank offset.
     The sticky page header now begins immediately below it. */
  .main {
    padding-top: 0 !important;
    min-width: 0;
  }
  .page-header {
    position: sticky !important;
    top: 44px !important;
    z-index: 40 !important;
    min-height: 64px !important;
    padding: 10px 16px !important;
    margin: 0 !important;
    background: #fff;
  }
  .page.active {
    padding-top: 16px !important;
  }

  /* Prevent section content and action buttons from slipping beneath the header. */
  .section-title {
    position: relative;
    z-index: 1;
    width: 100%;
    min-width: 0;
  }
  .section-title > div { min-width: 0; }

  /* Launch / finance / shared checklist rows: compact mobile list rows. */
  .checklist {
    gap: 8px !important;
  }
  .check-row {
    position: relative;
    display: grid !important;
    grid-template-columns: 26px minmax(0, 1fr) auto !important;
    grid-template-areas:
      "check title actions"
      ". meta actions" !important;
    align-items: center !important;
    min-height: 72px !important;
    height: auto !important;
    padding: 11px 12px !important;
    column-gap: 10px !important;
    row-gap: 3px !important;
    border-radius: 12px !important;
  }
  .check-row > input[type="checkbox"] {
    grid-area: check !important;
    width: 24px !important;
    height: 24px !important;
    margin: 0 !important;
    align-self: center !important;
  }
  .check-row > .check-title {
    grid-area: title !important;
    align-self: center !important;
    padding: 0 !important;
    font-size: 14px !important;
    line-height: 1.4 !important;
    overflow-wrap: anywhere;
  }
  .check-row > .check-meta {
    display: none !important;
  }
  .check-row > .row-actions {
    grid-area: actions !important;
    grid-column: auto !important;
    align-self: center !important;
    justify-self: end !important;
    display: flex !important;
    flex-direction: row !important;
    gap: 6px !important;
    margin: 0 !important;
  }
  .check-row .icon-action {
    min-width: 46px !important;
    min-height: 32px !important;
    padding: 5px 8px !important;
    border-radius: 8px !important;
    font-size: 11px !important;
  }

  /* Readiness card itself should not add excessive internal whitespace. */
  #launch .widget,
  #finance .widget {
    padding: 12px !important;
  }
  #launch .widget-head,
  #finance .widget-head {
    margin-bottom: 10px !important;
  }

  /* Major decisions: actions sit at the top-right, not in a full bottom row. */
  #decisions tr {
    position: relative;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 9px 14px !important;
    padding: 14px !important;
    padding-top: 50px !important;
    min-height: 0 !important;
  }
  #decisions td:nth-child(1) {
    padding-right: 0 !important;
  }
  #decisions td:last-child {
    position: absolute !important;
    top: 12px !important;
    right: 12px !important;
    display: flex !important;
    gap: 6px !important;
    width: auto !important;
    padding: 0 !important;
    border: 0 !important;
  }
  #decisions td:last-child .icon-action {
    min-height: 32px !important;
    padding: 5px 9px !important;
    border-radius: 8px !important;
  }

  /* No horizontal scrolling anywhere in the main mobile workspace. */
  .table-wrap,
  .marketing-os-tabs,
  .pipeline-board,
  .timeline-view-tabs,
  .timeline-quick-filters,
  .timeline-phase-strip,
  .approval-stage-strip,
  .marketing-title-actions {
    overflow-x: visible !important;
    max-width: 100% !important;
  }
  .timeline-phase-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
  .timeline-phase-strip article {
    min-width: 0 !important;
  }
}

@media (max-width: 390px) {
  .page-header { padding-inline: 14px !important; }
  .check-row {
    grid-template-columns: 24px minmax(0, 1fr) auto !important;
    padding: 10px !important;
  }
  .check-row > .check-title { font-size: 13px !important; }
  .check-row .icon-action {
    min-width: 42px !important;
    padding-inline: 7px !important;
  }
}

/* V19.0.3 — mobile header must remain in normal document flow */
@media (max-width: 760px) {
  /* The black brand bar is fixed. Reserve exactly its height in the main flow. */
  .main {
    padding-top: 44px !important;
  }

  /* Do not keep a second sticky header on mobile. A sticky page header was
     covering the first lines of every page while Safari restored scroll. */
  .page-header {
    position: relative !important;
    top: auto !important;
    inset: auto !important;
    z-index: 20 !important;
    width: 100% !important;
    min-height: 64px !important;
    margin: 0 !important;
  }

  /* Ensure every page begins visibly below its own title bar. */
  .page.active {
    padding-top: 20px !important;
    scroll-margin-top: 0 !important;
  }

  .page.active > :first-child {
    margin-top: 0 !important;
  }

  #overview .home-top,
  .section-title,
  .timeline-hero,
  .marketing-title-row,
  .franchise-title-row {
    position: relative !important;
    top: auto !important;
    transform: none !important;
  }
}
