/* ============================================================
   mobile.css — Responsive & mobile-first styles
   Broadpeak CRM Design System
   Applied only on screens <= 768px
   ============================================================ */

/* ── CSS variables mobile ── */
:root {
  --bottom-nav-height: 60px;
  --mobile-padding: 1rem;
}

/* ══════════════════════════════════════════════════════════════
   BOTTOM NAVIGATION BAR (mobile only)
══════════════════════════════════════════════════════════════ */
.bottom-nav {
  display: none; /* hidden on desktop */
}

@media (max-width: 768px) {
  /* Safe area for notch phones */
  body { padding-bottom: env(safe-area-inset-bottom); }

  /* Bottom nav visible on mobile */
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: var(--bottom-nav-height);
    background: var(--color-navy);
    border-top: 1px solid var(--border-dark);
    z-index: 150;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .2rem;
    background: none;
    border: none;
    cursor: pointer;
    color: rgba(255,255,255,.45);
    font-size: .625rem;
    font-weight: 600;
    font-family: var(--font-body);
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: .5rem .25rem;
    transition: color .15s;
    position: relative;
  }

  .bottom-nav-item:hover,
  .bottom-nav-item.active {
    color: var(--color-cyan);
  }

  .bottom-nav-item.active::before {
    content: '';
    position: absolute;
    top: 0; left: 20%; right: 20%;
    height: 2px;
    background: var(--color-cyan);
    border-radius: 0 0 2px 2px;
  }

  .bottom-nav-item svg {
    width: 22px; height: 22px;
  }

  .bottom-nav-badge {
    position: absolute;
    top: 6px; right: calc(50% - 18px);
    background: var(--color-blue);
    color: white;
    font-size: .5rem;
    font-weight: 700;
    padding: .05rem .3rem;
    border-radius: 10px;
    min-width: 14px;
    text-align: center;
    line-height: 1.4;
  }
}

/* ══════════════════════════════════════════════════════════════
   LAYOUT ADJUSTMENTS
══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* Hide desktop sidebar */
  .sidebar { display: none !important; }

  /* Hide desktop topbar nav links & user info */
  .nav-links { display: none; }
  .nav-user .user-info,
  .nav-user .btn-logout { display: none; }
  .nav-user { gap: .5rem; }

  /* Topbar compact */
  .topbar { padding: 0 1rem; height: 50px; }

  /* Add bottom padding so content isn't hidden behind bottom nav */
  .main,
  #app > div:last-child {
    padding-bottom: var(--bottom-nav-height);
  }

  /* Page header compact */
  .page-header {
    padding: .875rem var(--mobile-padding);
    flex-wrap: wrap;
    gap: .5rem;
  }
  .page-title { font-size: 1.125rem; }
  .page-subtitle { font-size: .75rem; }

  /* Stats row — 2 columns on mobile */
  .stats-row {
    grid-template-columns: repeat(2, 1fr);
    gap: .625rem;
    padding: .875rem var(--mobile-padding) 0;
  }
  .stat-card { padding: .875rem 1rem; }
  .stat-value { font-size: 1.5rem; }

  /* Content padding */
  .content { padding: .875rem var(--mobile-padding) calc(var(--bottom-nav-height) + 1rem); }
}

/* ══════════════════════════════════════════════════════════════
   TABLES → CARD LIST ON MOBILE
══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* Hide table header */
  .table-card thead { display: none; }

  /* Each row becomes a card */
  .table-card tbody tr {
    display: flex;
    flex-direction: column;
    padding: .875rem var(--mobile-padding);
    border-bottom: 1px solid var(--border-light);
    background: white;
    gap: .3rem;
    position: relative;
  }
  .table-card tbody tr:hover { background: var(--color-gray50); }

  /* Reset td display */
  .table-card td {
    display: block;
    padding: 0;
    border: none;
    font-size: .875rem;
  }

  /* Hide less important columns on mobile */
  .table-card td:nth-child(3),
  .table-card td:nth-child(5) {
    font-size: .75rem;
    color: var(--color-gray400);
  }

  /* Row actions always visible on mobile */
  .row-actions {
    opacity: 1;
    position: absolute;
    top: .875rem; right: var(--mobile-padding);
  }

  /* View hint hidden on mobile (replaced by tap) */
  .view-hint { display: none; }

  /* Table toolbar stacks */
  .table-toolbar {
    padding: .75rem var(--mobile-padding);
    gap: .5rem;
  }
  .search-box { min-width: 0; }
  .filter-select { font-size: .8125rem; }
}

/* ══════════════════════════════════════════════════════════════
   MODALS → BOTTOM SHEETS ON MOBILE
══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* Overlay aligns to bottom */
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  /* Modal slides up from bottom */
  .modal,
  .modal-sm {
    width: 100%;
    max-width: 100%;
    max-height: 92vh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    animation: slideUp .25s ease;
  }

  /* Handle bar indicator */
  .modal::before {
    content: '';
    display: block;
    width: 40px; height: 4px;
    background: var(--color-gray200);
    border-radius: 2px;
    margin: .75rem auto -.25rem;
  }

  .modal-header { padding: 1rem 1.25rem; }
  .modal-body   { padding: 1rem 1.25rem; }
  .modal-footer {
    padding: .875rem 1.25rem;
    padding-bottom: calc(.875rem + env(safe-area-inset-bottom));
  }

  /* Tabs scroll horizontally */
  .modal-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; padding: 0 1rem; }
  .modal-tab  { padding: .625rem .75rem; font-size: .8125rem; }

  /* Form grid → single column */
  .form-grid { grid-template-columns: 1fr; }
  .field.span-2 { grid-column: span 1; }

  /* Inputs larger touch targets */
  input[type=text],
  input[type=email],
  input[type=date],
  input[type=password],
  select,
  textarea {
    padding: .625rem .875rem;
    font-size: 1rem; /* prevents iOS zoom */
    min-height: 44px;
  }
  textarea { min-height: 80px; }
}

/* ══════════════════════════════════════════════════════════════
   PORTAL-SPECIFIC MOBILE STYLES
══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* Main views take full height */
  .main-view { overflow-y: auto; }

  /* Detail header compact */
  .detail-header {
    padding: .875rem var(--mobile-padding);
    flex-wrap: wrap;
    gap: .5rem;
  }
  .detail-name { font-size: 1.125rem; }

  /* Detail body */
  .detail-body {
    padding: .875rem var(--mobile-padding);
    padding-bottom: calc(var(--bottom-nav-height) + 1rem);
  }

  /* Info grid → 2 columns on mobile */
  .info-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: .625rem;
  }
  .info-card { padding: .75rem .875rem; }
  .info-card-value { font-size: .875rem; }

  /* Section cards full width */
  .section-card { border-radius: var(--radius-md); }

  /* Solutions grid → 1 column */
  .detail-body [style*="grid-template-columns:repeat(3,1fr)"] {
    display: grid !important;
    grid-template-columns: 1fr !important;
  }

  /* Partner pills wrap nicely */
  .checkbox-group { gap: .375rem; }
  .checkbox-pill  { font-size: .75rem; padding: .3rem .5rem; }

  /* Type filter pills scrollable */
  #partner-type-pills {
    display: flex !important;
    flex-wrap: wrap;
  }

  /* Back button */
  .back-btn { padding: .375rem .625rem; font-size: .8125rem; }
  .back-btn svg { width: 12px; height: 12px; }

  /* Detail action buttons */
  .detail-header .btn-sm { padding: .375rem .625rem; font-size: .8125rem; }

  /* Ref content */
  .ref-content { overflow-y: auto; padding-bottom: calc(var(--bottom-nav-height) + 1rem); }

  /* Toast position above bottom nav */
  .toast-container {
    bottom: calc(var(--bottom-nav-height) + .75rem);
    right: .75rem;
    left: .75rem;
  }
  .toast { max-width: 100%; }

  /* Loading overlay full screen */
  .loading-overlay { z-index: 600; }

  /* Buttons full width in some contexts */
  .modal-footer .btn { flex: 1; justify-content: center; }

  /* Icon buttons always visible on mobile */
  .icon-btn { width: 34px; height: 34px; }

  /* Liaison add row stacks */
  .liaison-add {
    flex-wrap: wrap;
    padding: .625rem 1rem;
  }
  .liaison-add select { min-width: 100%; }

  /* Liaison rows compact */
  .liaison-row { padding: .625rem 1rem; }
  .liaison-name { font-size: .8125rem; }
}

/* ══════════════════════════════════════════════════════════════
   HOMEPAGE RESPONSIVE
══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .hero { padding: 1rem; }
  .hero-title { font-size: 1.25rem; }
  .hero-status-row { flex-wrap: wrap; gap: .75rem; }

  .grid-wrap { padding: .875rem 1rem; }

  .tiles-2,
  .tiles-3,
  .tiles-4 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
  .tiles-2,
  .tiles-3,
  .tiles-4 { grid-template-columns: 1fr; }

  .info-grid { grid-template-columns: 1fr !important; }
}

/* ══════════════════════════════════════════════════════════════
   TOUCH IMPROVEMENTS
══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  /* Larger tap targets */
  .sidebar-item,
  .nav-link,
  .btn { min-height: 44px; }

  .btn-sm { min-height: 36px; }

  /* Prevent double-tap zoom on buttons */
  button, a { touch-action: manipulation; }

  /* Smooth scrolling */
  .main-view,
  .detail-body,
  .ref-content,
  .modal { -webkit-overflow-scrolling: touch; }

  /* Remove hover effects that don't work on touch */
  .tile:hover .tile-arrow { opacity: 0; }
  tr:hover .row-actions { opacity: 1; } /* always show on mobile */
}

/* ══════════════════════════════════════════════════════════════
   MOBILE MENU ITEMS
══════════════════════════════════════════════════════════════ */
.mobile-menu-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  width: 100%;
  padding: .75rem .5rem;
  background: none;
  border: none;
  color: rgba(255,255,255,.8);
  font-size: .9375rem;
  font-family: var(--font-body);
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background .15s;
  text-align: left;
  min-height: 44px;
}
.mobile-menu-item:hover,
.mobile-menu-item:active {
  background: rgba(255,255,255,.07);
}
