/* ═══════════════════════════════════════════════
   MOBILE POLISH — Responsive overrides
   Breakpoints: 768px (tablet), 480px (phone)
═══════════════════════════════════════════════ */

/* ═══ TABLET (≤ 768px) ═══ */
@media (max-width: 768px) {

  /* ─── Sidebar: off-canvas overlay ─── */
  .sidebar {
    transform: translateX(-100%);
    box-shadow: none;
    transition: transform .25s cubic-bezier(.4,0,.2,1);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0,0,0,.4);
  }

  /* Overlay behind sidebar when open */
  .sidebar.open::after {
    content: '';
    position: fixed;
    top: 0; right: 0; bottom: 0;
    left: var(--sidebar-w);
    background: rgba(0,0,0,.3);
    z-index: 99;
  }

  /* ─── Main content: full width ─── */
  .main {
    margin-left: 0 !important;
  }

  .content {
    padding: 16px;
  }

  /* ─── Topbar ─── */
  .topbar {
    padding: 0 12px;
    gap: 8px;
  }

  .topbar-context {
    display: none;
  }

  .topbar-search {
    min-width: unset;
    padding: 6px 10px;
  }

  .topbar-search span {
    display: none;
  }

  .topbar-search kbd {
    display: none;
  }

  .mobile-menu-btn {
    display: flex !important;
  }

  /* ─── Temporal Bar ─── */
  .temporal-bar {
    gap: 12px;
    padding: 0 12px;
    overflow-x: auto;
    justify-content: flex-start;
    -webkit-overflow-scrolling: touch;
  }

  .tb-item {
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* ─── KPI Trio → single column ─── */
  .kpi-trio {
    grid-template-columns: 1fr !important;
    gap: 12px;
  }

  /* ─── KPI Card adjustments ─── */
  .kpi-card {
    padding: 16px;
  }

  .kpi-metrics {
    gap: 12px;
    flex-wrap: wrap;
  }

  /* ─── Headline Status ─── */
  .headline-status {
    flex-wrap: wrap;
    padding: 12px 14px;
    gap: 10px;
  }

  .hs-action {
    order: 3;
    width: 100%;
    justify-content: center;
  }

  .hs-dismiss {
    position: absolute;
    top: 8px;
    right: 8px;
  }

  /* ─── Action Items ─── */
  .action-item {
    padding: 12px 14px;
    gap: 8px;
  }

  .action-due {
    font-size: 10px;
    white-space: nowrap;
  }

  /* ─── Act Page Stats ─── */
  .act-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .act-stat {
    padding: 12px !important;
  }

  /* ─── Filter Bar ─── */
  .filter-bar {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }

  .filter-chip {
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* ─── Detail Panels → single column ─── */
  .detail-panels {
    grid-template-columns: 1fr !important;
  }

  /* ─── Velocity Chart ─── */
  .velocity-chart {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }

  /* ─── Morning Brief ─── */
  .morning-brief {
    padding: 14px 16px;
  }

  .morning-brief-lines {
    font-size: 12px;
  }

  /* ─── Gate Readiness Grid ─── */
  .gate-features-grid {
    grid-template-columns: 1fr !important;
  }

  /* ─── Watchlist Grid ─── */
  .watchlist-grid {
    grid-template-columns: 1fr;
  }

  /* ─── Command Palette ─── */
  #command-palette-dialog {
    width: 90vw !important;
    max-width: none !important;
    margin: 10vh auto !important;
  }

  /* ─── Reports page ─── */
  .report-actions {
    flex-wrap: wrap;
  }

  .report-actions button {
    flex: 1;
    min-width: 120px;
  }

  /* ─── Confidence factors ─── */
  .conf-factors {
    gap: 6px;
  }

  .cf-label {
    min-width: 80px;
    font-size: 10px;
  }

  /* ─── Risk items ─── */
  .risk-item {
    flex-wrap: wrap;
    gap: 6px;
  }

  .risk-owner {
    margin-left: auto;
  }
}

/* ═══ PHONE (≤ 480px) ═══ */
@media (max-width: 480px) {

  .content {
    padding: 12px;
  }

  /* ─── Topbar: minimal ─── */
  .topbar {
    padding: 0 10px;
    height: 44px;
  }

  .topbar-title {
    font-size: 14px;
  }

  .avatar {
    width: 24px;
    height: 24px;
    font-size: 10px;
  }

  /* ─── KPI cards: compact ─── */
  .kpi-card {
    padding: 12px;
  }

  .kpi-value {
    font-size: 20px;
  }

  .kpi-metrics {
    gap: 8px;
  }

  .kpi-metric-val {
    font-size: 14px;
  }

  .kpi-metric-label {
    font-size: 9px;
  }

  /* ─── Headline: stacked ─── */
  .headline-status {
    flex-direction: column;
    align-items: flex-start;
  }

  .hs-rag {
    margin-bottom: 4px;
  }

  /* ─── Section headers ─── */
  .section-header {
    flex-wrap: wrap;
  }

  .section-title {
    font-size: 13px;
  }

  /* ─── Action items: tighter ─── */
  .action-item {
    padding: 10px 12px;
    gap: 6px;
  }

  .action-priority {
    font-size: 9px;
    padding: 2px 5px;
  }

  .action-title {
    font-size: 12px;
  }

  .action-meta {
    font-size: 10px;
  }

  /* ─── Act stats: single column on very small ─── */
  .act-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .act-stat-value {
    font-size: 18px;
  }

  /* ─── Temporal bar: scroll ─── */
  .temporal-bar {
    font-size: 10px;
    gap: 8px;
    height: 30px;
  }

  /* ─── Watch items ─── */
  .watch-item {
    padding: 10px;
  }

  .watch-item-meta {
    font-size: 9px;
  }

  /* ─── Morning Brief ─── */
  .morning-brief {
    padding: 10px 12px;
  }

  .morning-brief h3 {
    font-size: 12px;
  }

  /* ─── Sidebar: wider on phones ─── */
  .sidebar {
    width: 260px;
  }

  /* ─── Detail panels ─── */
  .detail-header {
    padding: 10px 12px;
    font-size: 12px;
  }

  .detail-body {
    padding: 10px 12px;
  }
}

/* ═══ TOUCH ENHANCEMENTS ═══ */
@media (hover: none) and (pointer: coarse) {
  /* Larger tap targets */
  .nav-item {
    padding: 10px 12px;
    min-height: 40px;
  }

  .filter-chip {
    padding: 8px 14px;
    min-height: 36px;
  }

  .action-item {
    min-height: 48px;
  }

  .watch-unpin {
    opacity: 1;
    padding: 6px 10px;
  }

  .watch-btn {
    opacity: 1;
    padding: 6px 8px;
    font-size: 16px;
  }

  /* Remove hover effects that don't apply */
  .kpi-card:hover {
    transform: none;
  }

  .nav-item:hover {
    background: transparent;
  }

  .nav-item:active {
    background: var(--sidebar-hover);
  }

  /* Scrollbar hide on touch */
  ::-webkit-scrollbar {
    display: none;
  }
}

/* ═══ SAFE AREA (notch phones) ═══ */
@supports (padding: env(safe-area-inset-top)) {
  .topbar {
    padding-top: env(safe-area-inset-top);
  }

  .sidebar {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .content {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
}
