/* ============================================
   WHITE OAK MEDIA — Client Portal Styles
   09-mobile.css — Mobile-first rework
   "Excellent for working on the go"
   ============================================
   Loads LAST in the cascade so it overrides everything above.
   Target devices: iPhone SE (375px) → iPhone 14 Pro Max (430px) → tablets.
   ============================================ */

/* ─────────────────────────────────────────────
   BREAKPOINT: ≤ 768px (mobile/tablet)
   ───────────────────────────────────────────── */
@media (max-width: 768px) {

  /* ─── Global tap behavior ─── */
  html { -webkit-text-size-adjust: 100%; }
  body {
    /* Native momentum scroll, prevent iOS zoom on form focus, prevent rubber-band */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
  }
  /* Prevent text auto-zoom when tapping form fields on iOS */
  input, select, textarea {
    font-size: 16px !important;
  }
  /* Generous tap targets everywhere */
  .btn { min-height: 44px; padding: 0.7rem 1.1rem; }
  .btn-sm { min-height: 38px; padding: 0.55rem 0.9rem; font-size: 0.85rem; }
  .btn-xs { min-height: 32px; padding: 0.4rem 0.75rem; font-size: 0.78rem; }
  a, button { touch-action: manipulation; } /* removes 300ms tap delay */

  /* ─── Topbar — slimmer, single-row ─── */
  .topbar {
    height: calc(56px + env(safe-area-inset-top, 0px));
    padding-top: env(safe-area-inset-top, 0px);
    padding-left: max(0.85rem, env(safe-area-inset-left));
    padding-right: max(0.85rem, env(safe-area-inset-right));
    background: #fff;
    border-bottom: 1px solid var(--wom-stone, #e0d4c1);
  }
  .nav-logo { height: 26px; }
  .nav-avatar { width: 36px; height: 36px; font-size: 0.78rem; }
  /* Hide user details on mobile — they're in the "more" drawer */
  .nav-user-details { display: none !important; }
  .nav-user { padding-left: 0.5rem; gap: 0.4rem; border-left-color: var(--wom-cream-dark); }
  #btn-change-password, #btn-logout { display: none !important; }

  /* ─── Sidebar — proper full-height slide-out drawer ─── */
  .sidebar {
    width: 280px !important;
    top: calc(56px + env(safe-area-inset-top, 0px));
    bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.32, 0.72, 0.2, 1);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.2);
    display: flex;
  }
  .sidebar.mobile-open {
    transform: translateX(0);
  }
  .sidebar-overlay {
    background: rgba(20, 28, 36, 0.6);
    backdrop-filter: blur(2px);
    top: calc(56px + env(safe-area-inset-top, 0px));
  }
  .sidebar-nav {
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  }
  /* Larger nav items in dark sidebar on mobile */
  .nav-tab {
    padding: 0.85rem 1rem;
    font-size: 0.95rem;
    min-height: 48px;
  }
  .nav-section-label {
    font-size: 0.7rem;
    padding-top: 1.25rem;
  }

  /* ─── Main content ─── */
  .main-content {
    margin-left: 0 !important;
    margin-top: calc(56px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)); /* room for bottom nav */
  }
  .page {
    padding: 1rem 1rem 1.5rem;
    max-width: 100%;
  }

  /* ─── Page Header — compact greeting ─── */
  .page-header {
    margin-bottom: 1.25rem;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.85rem;
  }
  .page-header > div:first-child { width: 100%; }
  .page-header h1 {
    font-size: 1.45rem !important;
    letter-spacing: -0.02em;
    line-height: 1.2;
  }
  .page-header .label-upper {
    font-size: 0.62rem;
    letter-spacing: 0.12em;
  }
  /* Primary action button on page header goes full-width */
  .page-header > button.btn-primary,
  .page-header > .btn-primary {
    width: 100%;
    justify-content: center;
  }

  /* ─── Donna's Brief — smaller, still hero ─── */
  .donna-brief-card {
    padding: 1rem 1.1rem 1.15rem;
    margin-bottom: 1.1rem;
  }
  .donna-brief-header { gap: 0.6rem; margin-bottom: 0.5rem; }
  .donna-brief-avatar { width: 28px; height: 28px; font-size: 0.78rem; }
  .donna-brief-title { font-size: 0.65rem; letter-spacing: 0.12em; }
  .donna-brief-sub { font-size: 0.72rem; }
  .donna-brief-refresh { padding: 0.4rem 0.55rem; font-size: 0.72rem; }
  .donna-brief-refresh span { display: none; } /* icon-only on mobile */
  .donna-brief-body { font-size: 0.9rem; line-height: 1.6; }

  /* ─── Stat cards — 2-col grid, compact ─── */
  .stats-row,
  .stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.6rem !important;
  }
  .stat-card {
    padding: 0.85rem 0.95rem 0.95rem !important;
    border-radius: 10px !important;
  }
  .stat-card:hover { transform: none !important; box-shadow: none !important; }
  .stat-card .label-upper { font-size: 0.58rem; letter-spacing: 0.1em; }
  .stat-card .stat-value,
  .stat-card .stat-number {
    font-size: 1.35rem !important;
    margin-top: 0.3rem;
  }
  .stat-card .stat-sub,
  .stat-card .stat-label {
    font-size: 0.7rem;
    margin-top: 0.25rem;
  }

  /* ─── TODAY list — bigger touch targets ─── */
  .today-item {
    padding: 0.95rem 1rem;
    gap: 0.7rem;
  }
  .today-item-icon { width: 36px; height: 36px; }
  .today-item-title { font-size: 0.9rem; line-height: 1.35; }
  .today-item-sub {
    font-size: 0.75rem;
    /* Truncate at 2 lines on mobile */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .today-item-meta { font-size: 0.72rem; }
  .today-item-arrow { display: none; } /* free up space */
  .today-item-resolve { width: 36px; height: 36px; }

  /* ─── Recent Activity ─── */
  .activity-item { padding: 0.75rem 1rem; }
  .activity-text { font-size: 0.85rem; }
  .activity-time { font-size: 0.7rem; }

  /* ─── Section cards — less padding, more breathing ─── */
  .section-card {
    border-radius: 12px;
  }
  .section-card-header {
    padding: 0.95rem 1.1rem !important;
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  .section-card-header .label-upper { font-size: 0.65rem; }

  /* Section grids stack on mobile */
  .section-grid,
  .section-grid-2,
  .section-grid-3 {
    grid-template-columns: 1fr !important;
    gap: 1.1rem;
  }

  /* ─── Clients page — toolbar + cards ─── */
  .clients-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.6rem;
    padding: 0.85rem;
  }
  .clients-search-wrap { width: 100%; }
  .clients-view-toggle { align-self: flex-end; }
  /* Hide table view on mobile entirely — cards are the way */
  .clients-table-wrap { display: none !important; }
  .clients-card-grid {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 0.75rem;
    padding: 0;
  }
  .client-card {
    padding: 1.1rem;
    border-radius: 12px;
  }

  /* ─── Client Detail page ─── */
  /* Compact header with avatar + name + actions stacked */
  #page-admin-client-detail .page-header {
    flex-direction: column;
    align-items: stretch;
  }
  #client-detail-header h1 {
    font-size: 1.3rem !important;
    margin: 0;
  }
  #client-detail-header .client-cell-avatar {
    width: 40px !important;
    height: 40px !important;
    font-size: 0.95rem !important;
  }
  /* Action buttons wrap into a tight row, key actions stay primary */
  #client-detail-actions {
    flex-wrap: wrap;
    gap: 0.4rem !important;
    width: 100%;
  }
  #client-detail-actions > * {
    flex: 1 1 calc(50% - 0.2rem);
    min-width: 0;
  }
  #client-detail-actions > div {
    flex: 1 1 100% !important;
    margin-right: 0 !important;
  }
  #client-detail-actions .btn {
    font-size: 0.8rem;
    padding: 0.55rem 0.6rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Tab bar — horizontal scroll if needed, larger touch */
  .client-detail-tabs {
    top: calc(56px + env(safe-area-inset-top, 0px));
    margin-left: -1rem;
    margin-right: -1rem;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    border-radius: 0;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    background: var(--wom-cream, #f2f1ec);
    box-shadow: 0 6px 12px -8px rgba(20, 28, 36, 0.08);
  }
  .client-detail-tabs::-webkit-scrollbar { display: none; }
  .client-detail-tab {
    padding: 0.85rem 1rem;
    font-size: 0.85rem;
    min-height: 46px;
  }
  .tab-count { font-size: 0.65rem; padding: 0.08rem 0.4rem; }

  /* Compact stats inside Overview tab */
  .stats-grid.stats-grid-compact {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.5rem !important;
  }
  .stats-grid.stats-grid-compact .stat-card {
    padding: 0.7rem 0.85rem 0.8rem !important;
  }
  .stats-grid.stats-grid-compact .stat-card .stat-value {
    font-size: 1.1rem !important;
  }

  /* Client info grid → stack */
  .project-info-grid {
    grid-template-columns: 1fr !important;
    gap: 0.5rem;
  }
  .project-info-row { padding: 0.45rem 0; }
  .project-info-row.full-width { grid-column: 1 !important; }

  /* Project row inside client detail */
  .project-row {
    flex-direction: column;
    align-items: stretch !important;
    gap: 0.75rem;
  }

  /* ─── Drawer (Edit Client, etc.) — already bottom-sheets via Phase 5 CSS,
        but tweak for excellent mobile experience ─── */
  .modal-overlay.modal-drawer .drawer-content,
  .modal-overlay.modal-drawer .modal-content.drawer-content {
    height: 92vh !important;
    max-height: 92vh !important;
    border-radius: 20px 20px 0 0 !important;
  }
  .drawer-header { padding: 1.2rem 1.25rem 0.85rem !important; }
  .drawer-header h3 { font-size: 1.05rem !important; }
  .drawer-body { padding: 1.1rem 1.25rem !important; }
  .drawer-section { padding-bottom: 1.1rem; margin-bottom: 1.1rem; }
  .drawer-footer {
    padding: 0.8rem 1.25rem calc(0.8rem + env(safe-area-inset-bottom, 0px));
    margin-left: -1.25rem !important;
    margin-right: -1.25rem !important;
    margin-bottom: 0 !important;
  }
  .drawer-footer .btn { flex: 1; }

  /* ─── Modal sheet enhancements ─── */
  .modal-overlay {
    align-items: flex-end !important;
    padding: 0 !important;
  }
  .modal, .modal-content {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 20px 20px 0 0 !important;
    max-height: 92vh !important;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .modal-header {
    padding: 1.1rem 1.25rem 0.85rem !important;
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--wom-warm-white, #faf7f2);
  }
  .modal-header h3 { font-size: 1.05rem; }
  /* Add a visual drag handle to all bottom sheets */
  .modal-overlay.open .modal::before,
  .modal-overlay.open .modal-content::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 38px;
    height: 4px;
    border-radius: 2px;
    background: var(--wom-stone, #e0d4c1);
    z-index: 10;
  }
  .modal form, .modal-content form,
  .modal > div[style*="padding"],
  .modal-content > div[style*="padding"] {
    padding: 1rem 1.25rem 1.5rem !important;
  }
  .modal-actions, .form-actions {
    flex-direction: column-reverse;
    gap: 0.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--wom-cream-dark, #e8e2d6);
    margin-top: 1.25rem;
  }
  .modal-actions .btn, .form-actions .btn {
    width: 100%;
    justify-content: center;
  }

  /* ─── Form fields ─── */
  .form-group label { font-size: 0.82rem; margin-bottom: 0.4rem; }
  .form-group input,
  .form-group textarea,
  .form-select,
  textarea {
    padding: 0.85rem 0.9rem !important;
    border-radius: 8px !important;
  }
  .form-row {
    flex-direction: column !important;
    gap: 0 !important;
  }

  /* ─── Action Needed card (Client + Contracts) ─── */
  .client-action-needed-card {
    flex-direction: column;
    gap: 0.85rem;
    padding: 1.1rem 1.15rem 1.25rem;
  }
  .client-action-needed-icon { width: 40px; height: 40px; }
  .client-action-needed-body h3 { font-size: 1rem; }
  .client-action-needed-body p { font-size: 0.85rem; }
  .client-action-needed-cta {
    width: 100%;
    justify-content: center;
    padding: 0.7rem 1rem;
    font-size: 0.9rem;
  }
  .client-action-items { gap: 0.3rem; }
  .client-action-item-chip { font-size: 0.74rem; padding: 0.25rem 0.6rem; }

  /* ─── Asset request items — give the modal room ─── */
  #asset-req-items > div {
    flex-wrap: wrap;
  }
  #asset-req-items input[type="text"] {
    flex: 1 1 100% !important;
    min-width: 0;
  }
  #asset-req-items select {
    flex: 1 1 calc(100% - 40px);
  }

  /* ─── Contract send modal — bigger drop zone ─── */
  #contract-drop-zone {
    padding: 1.75rem 1rem !important;
  }

  /* ─── Client dashboard — quick actions and stats ─── */
  .client-quick-actions {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.5rem;
  }
  .client-quick-stats {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.5rem;
  }
  .quick-stat { padding: 0.8rem; }

  /* ─── Project detail ─── */
  .project-detail-grid {
    grid-template-columns: 1fr !important;
    gap: 1rem;
  }
  .project-detail-header h1 { font-size: 1.3rem; }
  /* Phase tracker — horizontal scroll */
  .phase-tracker {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 0.5rem;
  }
  .phase-tracker::-webkit-scrollbar { display: none; }

  /* ─── Pipeline / Kanban — horizontal scroll ─── */
  .pipeline-board,
  .kanban-board {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    padding-bottom: 1rem;
  }
  .pipeline-column,
  .kanban-column {
    min-width: 80vw;
    scroll-snap-align: start;
    flex-shrink: 0;
  }

  /* ─── Tables → mobile card view (where practical) ─── */
  /* Tables remain in horizontal scroll mode for billing/invoices,
     but we hide non-essential columns and shrink padding */
  .invoice-table th,
  .invoice-table td,
  .clients-table th,
  .clients-table td {
    padding: 0.55rem 0.7rem !important;
    font-size: 0.78rem;
  }

  /* ─── Notification panel — full screen on mobile ─── */
  .notification-panel {
    width: 100% !important;
    top: calc(56px + env(safe-area-inset-top, 0px)) !important;
    max-height: calc(100vh - 56px - env(safe-area-inset-top, 0px));
  }

  /* ─── Toasts — above mobile bottom nav ─── */
  .toast-container,
  .toast {
    bottom: calc(78px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* ─── Mobile bottom nav — bigger touch + safe area ─── */
  .mobile-nav {
    padding: 0.4rem 0 calc(0.4rem + env(safe-area-inset-bottom, 0px));
    background: #fff;
    border-top: 1px solid var(--wom-stone, #e0d4c1);
    box-shadow: 0 -4px 16px rgba(20, 28, 36, 0.05);
  }
  .mobile-nav .nav-tab {
    min-height: 56px;
    padding: 0.55rem 0.25rem;
    font-size: 0.66rem;
    font-weight: 600;
    gap: 0.25rem;
  }
  .mobile-nav .nav-tab svg { width: 22px; height: 22px; }
  .mobile-nav .nav-tab.active {
    color: var(--wom-oak, #b45143) !important;
  }
  .mobile-nav .nav-tab.active::before {
    content: '';
    position: absolute;
    top: 4px;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 3px;
    border-radius: 2px;
    background: var(--wom-oak, #b45143);
  }

  /* ─── Search bars — full width with icon ─── */
  .clients-search,
  #clients-search,
  #projects-search {
    width: 100% !important;
    padding: 0.75rem 0.85rem 0.75rem 2.5rem !important;
    font-size: 16px !important;
    border-radius: 10px !important;
  }

  /* ─── Asset requests / Contracts list cards ─── */
  #admin-assets-content > div,
  #admin-contracts-content > div {
    padding: 1rem !important;
  }

  /* ─── Buttons in cards stack cleanly ─── */
  .btn-xs {
    min-height: 36px;
    padding: 0.45rem 0.75rem;
  }

  /* ─── Redesign tour — fit small screens ─── */
  .redesign-tour-card { width: 95%; max-width: none; }
  .redesign-tour-step { padding: 2.25rem 1.5rem 1.25rem; min-height: 280px; }
  .redesign-tour-step h2 { font-size: 1.3rem !important; }
  .redesign-tour-step p { font-size: 0.92rem; }
  .redesign-tour-nav { padding: 1rem 1.5rem calc(1rem + env(safe-area-inset-bottom, 0px)); }
  .redesign-tour-nav .btn { flex: 1; }
  .redesign-tour-nav-right { flex: 1; gap: 0.5rem; }
  .redesign-tour-nav-right .btn { flex: 1; }

  /* ─── Inline action button groups everywhere — wrap ─── */
  .section-card-header > div[style*="display:flex"],
  .section-card-header > div[style*="display: flex"] {
    flex-wrap: wrap !important;
    gap: 0.4rem !important;
  }

  /* ─── Float-y elements — keep above bottom nav ─── */
  .notif-overlay { z-index: 199; }
  .modal-overlay { z-index: 500; }

  /* ─── Auto-hide hover-only UI ─── */
  .hover-only { display: none !important; }
}

/* ─────────────────────────────────────────────
   BREAKPOINT: ≤ 480px (small phones)
   ───────────────────────────────────────────── */
@media (max-width: 480px) {
  /* Even tighter spacing */
  .page { padding: 0.85rem 0.85rem 1.25rem; }
  .page-header h1 { font-size: 1.3rem !important; }
  .donna-brief-card { padding: 0.9rem 1rem; }
  .donna-brief-body { font-size: 0.88rem; }

  /* Stats: still 2-col but tighter */
  .stats-row, .stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.5rem !important;
  }

  /* Tab bar: shrink padding slightly */
  .client-detail-tab {
    padding: 0.75rem 0.8rem;
    font-size: 0.82rem;
  }

  /* Action card chips wrap nicely */
  .client-action-item-chip {
    font-size: 0.72rem;
    padding: 0.22rem 0.55rem;
  }

  /* Section cards header */
  .section-card-header { padding: 0.85rem 1rem !important; }

  /* Client cards full width with comfortable padding */
  .client-card { padding: 0.95rem; }
}

/* ─────────────────────────────────────────────
   BREAKPOINT: ≤ 360px (Galaxy S, very small)
   ───────────────────────────────────────────── */
@media (max-width: 360px) {
  /* Stats fall back to single column on very narrow */
  .stats-row, .stats-grid {
    grid-template-columns: 1fr !important;
  }
  .stats-grid.stats-grid-compact {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  .page-header h1 { font-size: 1.2rem !important; }
}

/* ─────────────────────────────────────────────
   LANDSCAPE on phones — collapse top padding
   ───────────────────────────────────────────── */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  .topbar { height: calc(48px + env(safe-area-inset-top, 0px)); }
  .main-content { margin-top: calc(48px + env(safe-area-inset-top, 0px)); }
  .sidebar { top: calc(48px + env(safe-area-inset-top, 0px)); }
  .donna-brief-card { padding: 0.75rem 1rem; }
  .page-header h1 { font-size: 1.2rem !important; }
}

/* ─────────────────────────────────────────────
   TABLET (768px–1024px) — middle ground
   ───────────────────────────────────────────── */
@media (min-width: 769px) and (max-width: 1024px) {
  .sidebar { width: 200px; }
  .main-content { margin-left: 200px; }
  .stats-row, .stats-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .section-grid-2 { grid-template-columns: 1fr; }
}
