/* ============================================================
   SOCOM Overview Dashboard — Mobile Responsive
   All responsive rules live here, never in styles.css
   Breakpoints: 1024px (tablet), 640px (phone), 480px (small)
   ============================================================ */

/* ============================================================
   TABLET — max-width 1024px
   Sidebar collapses, 2-col grid
   ============================================================ */
@media (max-width: 1024px) {
  /* Sidebar hidden on mobile, replaced by bottom nav */
  .sidebar {
    display: none;
  }

  .content-area {
    margin-left: 0 !important;
  }

  /* Bottom navigation */
  .bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(56px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--bg-surface);
    border-top: 1px solid var(--border-default);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 90;
    display: flex;
    align-items: center;
    justify-content: space-evenly;
    transform: translateZ(0);
  }

  .bottom-nav__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: var(--space-2) var(--space-1);
    min-width: 48px;
    min-height: 48px;
    justify-content: center;
    color: var(--text-tertiary);
    font-size: var(--font-xs);
    text-decoration: none;
    position: relative;
    cursor: pointer;
    transition: color var(--transition-fast);
  }

  .bottom-nav__item:hover {
    color: var(--text-secondary);
    text-decoration: none;
  }

  .bottom-nav__item.active {
    color: var(--color-action);
  }

  .bottom-nav__item.active::after {
    content: '';
    position: absolute;
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 4px;
    border-radius: var(--radius-full);
    background: var(--color-action);
  }

  .bottom-nav__icon {
    width: 20px;
    height: 20px;
  }

  .bottom-nav__label {
    font-size: var(--font-xs);
    line-height: 1;
    white-space: nowrap;
  }

  /* More drawer */
  .more-drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 200;
    animation: fadeIn 200ms ease;
  }

  .more-drawer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 60vh;
    background: var(--bg-elevated);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    z-index: 201;
    overflow-y: auto;
    animation: slideUp 300ms ease;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .more-drawer__handle {
    width: 40px;
    height: 4px;
    background: var(--border-strong);
    border-radius: var(--radius-full);
    margin: var(--space-3) auto;
  }

  .more-drawer__item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    height: 48px;
    padding: 0 var(--space-6);
    color: var(--text-primary);
    font-size: var(--font-body);
    cursor: pointer;
    transition: background var(--transition-fast);
  }

  .more-drawer__item:hover {
    background: var(--bg-hover);
  }

  .more-drawer__item.active {
    color: var(--color-action);
  }

  /* Page adjustments */
  .page {
    padding: var(--space-4);
    padding-bottom: calc(56px + var(--space-6) + env(safe-area-inset-bottom, 0px));
  }

  /* Grid: 2 columns */
  .grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-4);
  }

  .grid--3,
  .grid--4 {
    grid-template-columns: repeat(2, 1fr);
  }

  .grid__span-3 {
    grid-column: 1 / -1;
  }

  /* Metric cards always 2x2 */
  .metric-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: var(--space-3);
  }

  /* Card padding reduction */
  .card {
    padding: var(--space-4);
  }

  .card__header {
    margin-bottom: var(--space-3);
  }

  /* Filter bar stacks vertical */
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-3);
  }

  .filter-bar__group {
    flex-wrap: wrap;
  }

  .filter-bar__separator {
    display: none;
  }

  .filter-bar--collapsed .filter-bar__group {
    display: none;
  }

  .filter-bar__toggle-btn {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    height: 40px;
    padding: 0 var(--space-4);
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    font-size: var(--font-body);
    color: var(--text-secondary);
    cursor: pointer;
  }

  .filter-bar__toggle-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 var(--space-1);
    border-radius: var(--radius-full);
    background: var(--color-action);
    color: var(--text-on-action);
    font-size: var(--font-xs);
    font-weight: 600;
  }

  /* Table horizontal scroll */
  .data-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .fin-table th,
  .fin-table td {
    padding: var(--space-2) var(--space-3);
    font-size: var(--font-small);
  }

  /* Mobile card system activation */
  .mob-cards-page .data-table-wrap {
    display: none;
  }

  .mob-cards-page .mob-cards {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
  }

  /* Page header scaling */
  .page-header__title {
    font-size: var(--font-h1);
  }

  /* Typography scaling */
  .t-display { font-size: var(--font-h1); }
  .metric-card__value { font-size: var(--font-metric); }
  .metric-card--hero .metric-card__value { font-size: var(--font-metric); }

  /* Utility: hide/show on mobile */
  .mob-hide { display: none !important; }
  .desk-only { display: none !important; }
  .mob-only { display: flex !important; }

  /* Breadcrumb: show parent + current only */
  .breadcrumb__item.middle {
    display: none;
  }
}

/* Desktop: hide mobile-only elements */
@media (min-width: 1025px) {
  .bottom-nav { display: none; }
  .mob-only { display: none !important; }
  .mob-cards { display: none; }
  .filter-bar__toggle-btn { display: none; }
}

/* ============================================================
   MOBILE CARD COMPONENTS
   ============================================================ */
.mob-cards {
  display: none;
  flex-direction: column;
  gap: var(--space-3);
}

.mob-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}

.mob-card__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.mob-card__title {
  font-size: var(--font-body);
  font-weight: 600;
  color: var(--text-primary);
}

.mob-card__value {
  font-family: 'Geist Mono', ui-monospace, monospace;
  font-size: var(--font-data);
  font-weight: 500;
  text-align: right;
}

.mob-card__body {
  padding-top: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.mob-card__kv {
  display: flex;
  justify-content: space-between;
}

.mob-card__kv-key {
  font-size: var(--font-small);
  color: var(--text-secondary);
}

.mob-card__kv-value {
  font-size: var(--font-small);
  color: var(--text-primary);
}

.mob-card__progress {
  height: 6px;
  background: var(--bg-inset);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.mob-card__progress-fill {
  height: 100%;
  border-radius: var(--radius-full);
}

.mob-card__tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.mob-card__actions {
  border-top: 1px solid var(--border-subtle);
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  display: flex;
  gap: var(--space-2);
}

.mob-card__action-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.mob-card__action-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Collapsible groups */
.mob-cards__group {
  margin-bottom: var(--space-2);
}

.mob-cards__group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-3) var(--space-4);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  cursor: pointer;
  user-select: none;
  transition: background var(--transition-fast);
}

.mob-cards__group-header:hover {
  background: var(--bg-hover);
}

.mob-cards__group-title {
  font-size: var(--font-body);
  font-weight: 600;
  color: var(--text-primary);
}

.mob-cards__group-summary {
  font-size: var(--font-small);
  color: var(--text-secondary);
}

.mob-cards__group-chevron {
  width: 16px;
  height: 16px;
  color: var(--text-tertiary);
  transition: transform 200ms ease;
  flex-shrink: 0;
}

.mob-cards__group.expanded .mob-cards__group-chevron {
  transform: rotate(180deg);
}

.mob-cards__group-body {
  display: none;
  padding-top: var(--space-2);
}

.mob-cards__group.expanded .mob-cards__group-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

/* ============================================================
   PHONE — max-width 640px
   Single column, compact spacing
   ============================================================ */
@media (max-width: 640px) {
  .page {
    padding: var(--space-3);
    padding-bottom: calc(56px + var(--space-4) + env(safe-area-inset-bottom, 0px));
  }

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

  /* Metric cards still 2x2 */
  .metric-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: var(--space-3);
  }

  .metric-card {
    padding: var(--space-3) var(--space-4);
  }

  .metric-card__value {
    font-size: var(--font-h2);
  }

  .metric-card__label {
    font-size: var(--font-xs);
  }

  .metric-card__trend {
    font-size: var(--font-xs);
  }

  /* Typography scaling */
  .page-header__title {
    font-size: var(--font-h2);
  }

  .t-display { font-size: var(--font-h2); }
  .t-h1 { font-size: var(--font-h2); }
  .card__title { font-size: var(--font-h3); }

  /* Card compact */
  .card {
    padding: var(--space-4);
  }

  /* Filter bar: full width inputs */
  .filter-bar__date-range {
    flex-direction: column;
    width: 100%;
  }

  .filter-bar__date-range .input,
  .filter-bar__date-range .select {
    width: 100%;
    min-width: 0;
  }

  .filter-bar__arrow {
    display: none;
  }

  .select,
  .input {
    width: 100%;
  }

  /* Table smaller font */
  .fin-table th {
    font-size: var(--font-xs);
    padding: var(--space-2);
  }

  .fin-table td {
    font-size: var(--font-small);
    padding: var(--space-2);
  }

  /* Charts: horizontal scroll */
  .chart-wrap {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
  }

  .chart-wrap .apexcharts-canvas {
    min-width: 500px;
  }

  /* Breadcrumb: compact */
  .breadcrumb {
    font-size: var(--font-xs);
    gap: var(--space-1);
  }

  /* Modal mobile sizing */
  .modal {
    max-width: calc(100vw - 32px);
    max-height: 85dvh;
  }

  .modal__header,
  .modal__body,
  .modal__footer {
    padding: var(--space-4);
  }

  /* Hide sparklines on phone */
  .mob-hide-sm { display: none !important; }
}

/* ============================================================
   SMALL PHONE — max-width 480px
   Compact density, minimal spacing
   ============================================================ */
@media (max-width: 480px) {
  .page {
    padding: var(--space-2);
    padding-bottom: calc(56px + var(--space-3) + env(safe-area-inset-bottom, 0px));
  }

  /* Metric cards compact */
  .metric-grid {
    gap: var(--space-2);
  }

  .metric-card {
    padding: var(--space-2) var(--space-3);
  }

  .metric-card__value {
    font-size: 1.125rem;
  }

  .metric-card__label {
    font-size: 10px;
  }

  .metric-card__trend {
    font-size: 10px;
  }

  /* Hide sparklines */
  .metric-card__sparkline {
    display: none;
  }

  /* Page title */
  .page-header__title {
    font-size: 1.25rem;
  }

  /* Typography */
  .t-display { font-size: 1.375rem; }
  .t-h1 { font-size: var(--font-h3); }
  .t-body { font-size: 13px; }
  .t-data { font-size: var(--font-small); }

  /* Cards */
  .card {
    padding: var(--space-3);
  }

  .mob-card {
    padding: var(--space-3);
  }

  /* Table font */
  .fin-table th {
    font-size: 10px;
  }

  .fin-table td {
    font-size: var(--font-xs);
  }

  /* Badge compact */
  .badge {
    height: 20px;
    font-size: 10px;
    padding: 0 var(--space-1);
  }

  /* Chart axis */
  .apexcharts-xaxis-label,
  .apexcharts-yaxis-label {
    font-size: 10px !important;
  }
}

/* ============================================================
   TOUCH TARGETS
   ============================================================ */
@media (max-width: 1024px) {
  .btn--sm {
    min-height: 44px;
  }

  .btn--md {
    min-height: 44px;
  }

  .input,
  .select {
    min-height: 44px;
  }

  .input--sm,
  .select--sm {
    min-height: 44px;
  }

  .context-menu__item {
    min-height: 44px;
  }
}

/* ============================================================
   SCROLL NAVIGATION
   ============================================================ */
@media (max-width: 1024px) {
  .scroll-nav {
    position: fixed;
    bottom: calc(56px + 12px + env(safe-area-inset-bottom, 0px));
    right: var(--space-3);
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    z-index: 80;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    background: rgba(var(--bg-surface), 0.8);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-default);
    overflow: hidden;
  }

  .scroll-nav__btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
  }

  .scroll-nav__btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
  }
}

@media (min-width: 1025px) {
  .scroll-nav {
    display: none;
  }
}

/* ============================================================
   FLOATING ACTION BUTTON
   ============================================================ */
@media (max-width: 1024px) {
  .fab {
    position: fixed;
    bottom: calc(56px + 52px + env(safe-area-inset-bottom, 0px));
    right: var(--space-4);
    width: 56px;
    height: 56px;
    border-radius: var(--radius-full);
    background: var(--color-action);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg);
    z-index: 85;
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
  }

  .fab:hover {
    background: var(--color-action-hover);
    transform: scale(1.05);
  }

  .fab__icon {
    width: 24px;
    height: 24px;
  }
}

@media (min-width: 1025px) {
  .fab {
    display: none;
  }
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .bottom-nav,
  .more-drawer,
  .mob-cards__group-chevron {
    transition: none !important;
  }
}
