/* BlueAnt Migration Dashboard — Mobile v2: Native App Experience
 * All rules scoped to <=768px — zero desktop impact.
 */

/* ================================================================
   MOBILE V2: KPI 2-COLUMN GRID
   ================================================================ */
@media (max-width: 768px) {
  .kpis {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 12px;
  }

  .kpi-hero {
    grid-column: 1 / -1;
  }

  /* Compact standard KPIs for 2-col layout */
  .kpis .kpi-std {
    padding: 12px 14px;
    min-height: 0;
  }
  .kpi-std .label {
    font-size: 7.5px;
    letter-spacing: 1.2px;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: calc(100% - 34px);
  }
  .kpi-std .value {
    font-size: 20px;
    line-height: 1.1;
  }
  .kpi-std .sub {
    font-size: 9px;
    line-height: 1.2;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .kpi-std .prev {
    font-size: 8px;
  }
  .kpi-std .icon-badge {
    width: 26px;
    height: 26px;
    top: 10px;
    right: 10px;
    font-size: 12px;
  }
}

@media (max-width: 480px) {
  .kpis {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }
  .kpis .kpi-std {
    padding: 10px 12px;
  }
  .kpi-std .value {
    font-size: 18px;
  }
  .kpi-std .icon-badge {
    width: 24px;
    height: 24px;
    top: 8px;
    right: 8px;
    font-size: 11px;
  }
}

/* ================================================================
   MOBILE V2: ENHANCED BOTTOM NAV
   ================================================================ */
@media (max-width: 768px) {
  .bottom-nav {
    height: 60px;
    background: rgba(255,255,255,0.92);
    border-top: 1px solid var(--border-2);
    box-shadow: 0 -4px 20px rgba(10,25,60,0.08);
    padding: 0 8px;
    gap: 0;
  }

  @supports (backdrop-filter: blur(12px)) {
    .bottom-nav {
      background: rgba(255,255,255,0.85);
      backdrop-filter: blur(12px);
      -webkit-backdrop-filter: blur(12px);
    }
  }

  .bottom-nav-item {
    position: relative;
    gap: 3px;
    padding: 8px 0 6px;
    min-height: 48px;
    transition: color 0.2s, transform 0.15s;
  }

  .bottom-nav-item:active {
    transform: scale(0.92);
  }

  .bottom-nav-item.active {
    color: var(--teal);
  }

  /* Active pill indicator above icon */
  .bottom-nav-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 3px;
    border-radius: 0 0 3px 3px;
    background: var(--teal);
    transition: width 0.2s;
  }

  .bottom-nav-icon {
    font-size: 22px;
    line-height: 1;
    transition: transform 0.15s;
  }

  .bottom-nav-item.active .bottom-nav-icon {
    transform: translateY(-1px);
  }

  .bottom-nav-label {
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.2px;
  }

  /* Issues badge dot */
  .bottom-nav-item[data-page="issues"] .bottom-nav-icon {
    position: relative;
  }
  .bottom-nav-item[data-page="issues"] .bottom-nav-icon::after {
    content: '';
    position: absolute;
    top: -2px;
    right: -6px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--red);
    border: 1.5px solid var(--card-bg);
  }
}

/* ================================================================
   MOBILE V2: CARD-BASED TABLE VIEWS
   ================================================================ */
@media (max-width: 768px) {
  /* Hide table element on mobile, show card list */
  .mobile-card-table {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px 12px;
  }

  .mobile-card-row {
    background: var(--surface-2);
    border: 1px solid var(--border-1);
    border-radius: 10px;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .mobile-card-row-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  .mobile-card-row-title {
    font-family: var(--font-body);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-1);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-card-row-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 10px;
    overflow: hidden;
  }

  .mobile-card-field {
    display: flex;
    flex-direction: column;
    gap: 1px;
  }

  .mobile-card-field-label {
    font-family: var(--font-body);
    font-size: 8px;
    font-weight: 600;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: var(--text-4);
  }

  .mobile-card-field-value {
    font-family: var(--font-body);
    font-size: 11px;
    color: var(--text-2);
  }

  .mobile-card-field-value .chip {
    font-size: 9px;
    padding: 2px 8px;
  }

  .mobile-card-field-value .sev-badge {
    font-size: 8px;
  }

  /* Hide real table when mobile cards present */
  .table-container.has-mobile-cards .data-table {
    display: none;
  }
  .table-container.has-mobile-cards {
    overflow-x: visible;
  }
}

/* Desktop: hide mobile card tables */
@media (min-width: 769px) {
  .mobile-card-table {
    display: none !important;
  }
}

/* ================================================================
   MOBILE V2: SWIPE PAGE TRANSITION
   ================================================================ */
@media (max-width: 768px) {
  .scroll-area {
    touch-action: pan-y;
    overscroll-behavior: contain;
  }

  /* Swipe transition classes */
  .page.active.swipe-out-left {
    animation: swipeOutLeft 0.25s ease forwards;
  }
  .page.active.swipe-out-right {
    animation: swipeOutRight 0.25s ease forwards;
  }
  .page.swipe-in-left {
    animation: swipeInLeft 0.25s ease forwards;
  }
  .page.swipe-in-right {
    animation: swipeInRight 0.25s ease forwards;
  }

  @keyframes swipeOutLeft {
    to { opacity: 0; transform: translateX(-30px); }
  }
  @keyframes swipeOutRight {
    to { opacity: 0; transform: translateX(30px); }
  }
  @keyframes swipeInLeft {
    from { opacity: 0; transform: translateX(30px); }
    to { opacity: 1; transform: translateX(0); }
  }
  @keyframes swipeInRight {
    from { opacity: 0; transform: translateX(-30px); }
    to { opacity: 1; transform: translateX(0); }
  }
}

/* ================================================================
   MOBILE V2: PULL-TO-REFRESH
   ================================================================ */
@media (max-width: 768px) {
  .ptr-indicator {
    display: none;
    position: fixed;
    top: 48px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 150;
    background: var(--card-bg);
    border: 1px solid var(--border-2);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(10,25,60,0.12);
    transition: transform 0.2s, opacity 0.2s;
  }

  .ptr-indicator.visible {
    display: flex;
  }

  .ptr-indicator.refreshing {
    display: flex;
  }

  .ptr-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--surface-3);
    border-top-color: var(--teal);
    border-radius: 50%;
  }

  .ptr-indicator.refreshing .ptr-spinner {
    animation: ptrSpin 0.6s linear infinite;
  }

  @keyframes ptrSpin {
    to { transform: rotate(360deg); }
  }

  .ptr-arrow {
    font-size: 16px;
    color: var(--teal);
    transition: transform 0.2s;
  }

  .ptr-indicator.ready .ptr-arrow {
    transform: rotate(180deg);
  }
}

/* ================================================================
   MOBILE V2: CONDENSED CARDS
   ================================================================ */
@media (max-width: 768px) {
  /* Tighter card headers */
  .card-header {
    padding: 8px 12px;
    gap: 6px;
  }
  .card-accent {
    width: 2.5px;
    height: 14px;
  }
  .card-title {
    font-size: 11.5px;
    line-height: 1.3;
  }
  .card-subtitle {
    font-size: 8.5px;
    line-height: 1.2;
  }

  /* Comparison strip: 2-col grid instead of vertical stack */
  .compare-strip {
    display: grid;
    grid-template-columns: 1fr 1fr;
    border-radius: 12px;
    margin-bottom: 10px;
  }
  .compare-cell {
    border-right: none;
    border-bottom: 1px solid var(--border-1);
    padding: 10px 12px;
  }
  .compare-cell:nth-child(odd) {
    border-right: 1px solid var(--border-1);
  }
  .compare-cell:nth-last-child(-n+2) {
    border-bottom: none;
  }
  .compare-value { font-size: 16px; }
  .compare-label { font-size: 7.5px; margin-bottom: 4px; }
  .compare-prev { font-size: 8px; }
  .delta-badge { font-size: 7.5px; padding: 1px 5px; }

  /* Charts: full width, better touch target */
  .chart-wrap {
    margin: 0 -4px;
  }
  canvas {
    touch-action: pan-y;
  }

  /* Donut: centered, proper sizing */
  .card-body canvas[width="170"] {
    width: 130px !important;
    height: 130px !important;
  }

  /* Gauge rows: more compact */
  .gauge-row {
    padding: 7px 12px;
    gap: 8px;
    flex-wrap: wrap;
  }
  .gauge-label {
    font-size: 10px;
    min-width: 0;
    flex: 1 1 auto;
  }
  .gauge-track {
    width: 50px;
    flex-shrink: 0;
  }
  .gauge-value {
    font-size: 9.5px;
    min-width: 36px;
    flex-shrink: 0;
    text-align: right;
    overflow: visible;
    white-space: nowrap;
  }

  /* RAG grid: 2-col on mobile */
  .rag-grid {
    grid-template-columns: 1fr 1fr;
    padding: 8px 10px;
    gap: 5px;
  }
  .rag-cell {
    padding: 7px 10px;
    border-radius: 8px;
  }
  .rag-name { font-size: 9.5px; }
  .rag-inline { font-size: 9px; }
  .rag-dot { width: 6px; height: 6px; }

  /* Alerts: condensed */
  .alert-row {
    padding: 8px 12px;
    gap: 6px;
    border-left-width: 2.5px;
  }
  .alert-text { font-size: 10px; line-height: 1.4; }

  /* Stat strip: 2-col maintained */
  .stat-strip {
    grid-template-columns: 1fr 1fr;
  }
  .stat-cell {
    padding: 10px 12px;
  }
  .stat-value { font-size: 16px; }
  .stat-label { font-size: 7.5px; }

  /* Milestone timeline: horizontal scroll with snap */
  .milestone-timeline {
    scroll-snap-type: x mandatory;
    padding: 12px 8px;
  }
  .milestone-item {
    scroll-snap-align: center;
  }
  .milestone-dot {
    width: 11px;
    height: 11px;
  }
  .milestone-label {
    font-size: 7.5px;
    max-width: 46px;
  }
  .milestone-date {
    font-size: 7px;
  }
}

/* ================================================================
   MOBILE V2: TOPBAR REFINEMENTS
   ================================================================ */
@media (max-width: 768px) {
  .topbar {
    height: 48px;
    min-height: 48px;
    padding: 0 12px;
    gap: 8px;
  }

  .sidebar-toggle {
    font-size: 20px;
    padding: 4px 6px;
    margin-right: 4px;
    border-radius: 8px;
    transition: background 0.15s;
  }
  .sidebar-toggle:active {
    background: var(--surface-3);
  }

  .topbar-title {
    font-size: 14px;
    font-weight: 700;
  }
  .topbar-eyebrow {
    font-size: 8px;
    letter-spacing: 0.5px;
  }

  .btn-refresh {
    padding: 6px 12px;
    font-size: 10px;
    border-radius: 6px;
  }
  .btn-refresh:active {
    transform: scale(0.95);
  }

  /* Scroll area: accommodate enhanced bottom nav */
  .scroll-area {
    padding-bottom: 64px;
  }

  /* Edge-to-edge content */
  .content {
    padding: 10px 8px 24px;
    max-width: 100%;
  }
}

@media (max-width: 480px) {
  .topbar-eyebrow { display: none; }
  .topbar-title { font-size: 13px; }
  .content { padding: 8px 6px 20px; }
  .scroll-area { padding-bottom: 68px; }
}

/* ================================================================
   MOBILE V2: SWIPE PAGE INDICATOR DOTS
   ================================================================ */
@media (max-width: 768px) {
  .page-dots {
    display: flex;
    justify-content: center;
    gap: 5px;
    padding: 4px 0 2px;
    position: fixed;
    bottom: 60px;
    left: 0;
    right: 0;
    z-index: 200;
    background: linear-gradient(to top, var(--card-bg) 60%, transparent);
  }

  .page-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--surface-4);
    transition: all 0.2s;
  }

  .page-dot.active {
    width: 16px;
    border-radius: 3px;
    background: var(--teal);
  }
}

@media (min-width: 769px) {
  .page-dots {
    display: none;
  }
  .ptr-indicator {
    display: none !important;
  }
}

/* ================================================================
   REDUCED MOTION
   ================================================================ */
@media (prefers-reduced-motion: reduce) {
  .page.active { animation: none !important; }
  .page.swipe-out-left,
  .page.swipe-out-right,
  .page.swipe-in-left,
  .page.swipe-in-right { animation: none !important; }
  .bottom-nav-item { transition: none !important; }
  .ptr-spinner { animation: none !important; }
  .pulse-dot { animation: none !important; }
  .btn-refresh:active { transform: none !important; }
  .bottom-nav-item:active { transform: none !important; }
}
