/* ═══════════════════════════════════════════════════════════════
   Orion — Mobile / Responsive CSS + PWA iOS/Android
   Breakpoints: 1024px (tablet), 768px (phone/small tablet), 480px (phone)
   ═══════════════════════════════════════════════════════════════ */

/* ── Safe area (iPhone notch / Dynamic Island) ────────────────── */
:root {
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --mobile-nav-h: calc(58px + var(--sab));
  --topbar-h: 56px;
}

/* ── Tap highlight removal ────────────────────────────────────── */
*, *::before, *::after {
  -webkit-tap-highlight-color: transparent;
}
input, textarea, select, button, a {
  -webkit-tap-highlight-color: transparent;
}

/* ── Touch scrolling ─────────────────────────────────────────── */
.nav, .nav-scroll, .content, main, .modal, .kanban-cards,
.kanban-board, .notif-list, .pd-due-list, .pd-team-list,
.gal-grid {
  -webkit-overflow-scrolling: touch;
}

/* ── Momentum scroll for horizontal kanban ───────────────────── */
.kanban-board {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x mandatory;
}
.kanban-col {
  scroll-snap-align: start;
}

/* ── PWA back button (injected by pwa.js in standalone) ─────── */
#pwa-back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface2, rgba(255,255,255,.06));
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
  margin-right: 4px;
  transition: background .15s;
  -webkit-tap-highlight-color: transparent;
}
#pwa-back-btn:active {
  background: var(--surface3);
  transform: scale(0.92);
}

/* ── View dots indicator ─────────────────────────────────────── */
.view-dots {
  display: none;
  position: fixed;
  bottom: calc(var(--mobile-nav-h) + 6px);
  left: 50%;
  transform: translateX(-50%);
  gap: 5px;
  z-index: 79;
  pointer-events: auto;
  align-items: center;
}
.view-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--border);
  transition: background .2s, width .2s;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.view-dot.active {
  background: var(--accent, #3b82f6);
  width: 18px;
  border-radius: 3px;
}

/* ── Swipe hint flash ────────────────────────────────────────── */
.swipe-hint {
  position: fixed;
  top: 0; bottom: 0;
  width: 4px;
  background: linear-gradient(180deg, transparent, var(--accent,#3b82f6), transparent);
  opacity: .6;
  animation: swipe-hint-fade .4s ease forwards;
  pointer-events: none;
  z-index: 9998;
}
.swipe-hint-right { right: 0; }
.swipe-hint-left  { left: 0; }
@keyframes swipe-hint-fade {
  from { opacity: .6; }
  to   { opacity: 0; }
}

/* ── Mobile view picker (bottom sheet) ──────────────────────── */
.mobile-view-picker {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9000;
}
.mobile-view-picker.open { display: block; }
.mvp-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.mvp-sheet {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: var(--surface, #1c1c1e);
  border-radius: 24px 24px 0 0;
  padding: 16px 20px calc(16px + var(--sab));
  font-family: 'Inter', -apple-system, sans-serif;
  animation: pwa-slide-up .3s cubic-bezier(.4,0,.2,1);
  max-height: 80vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.mvp-handle {
  width: 40px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 18px;
}
.mvp-section-label {
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
  padding: 0 2px;
}
.mvp-views-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}
.mvp-view-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 8px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  font-size: .7rem;
  font-weight: 500;
  transition: background .15s, border-color .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}
.mvp-view-btn:active { transform: scale(0.93); background: var(--surface3); }
.mvp-view-btn svg { color: var(--accent); }
.mvp-divider {
  height: 1px;
  background: var(--border);
  margin: 12px -2px 16px;
}
.mvp-nav-links {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 4px;
}
.mvp-nav-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface2);
  color: var(--text);
  text-decoration: none;
  font-size: .82rem;
  font-weight: 500;
  transition: background .15s;
  -webkit-tap-highlight-color: transparent;
}
.mvp-nav-link:active { background: var(--surface3); transform: scale(0.97); }
.mvp-nav-link svg { flex-shrink: 0; color: var(--muted); }

body[data-theme="pastel"] .mvp-sheet { background: #fff; }
body[data-theme="pastel"] .mvp-view-btn { background: #f8faff; border-color: rgba(59,130,246,.12); }
body[data-theme="pastel"] .mvp-nav-link { background: #f8faff; border-color: rgba(59,130,246,.12); color: #1e3a5f; }
body[data-theme="pastel"] .mvp-backdrop { background: rgba(30,58,95,.35); }

/* ── Bottom navigation bar ───────────────────────────────────── */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--mobile-nav-h);
  padding-bottom: var(--sab);
  background: var(--surface, #111113);
  border-top: 1px solid var(--border, rgba(255,255,255,.06));
  z-index: 80;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
/* Both class variants for compatibility */
.mobile-nav-inner,
.mobile-nav > * {
  display: flex;
  height: 58px;
  align-items: stretch;
}
/* Support both naming conventions used across pages */
.mobile-nav-btn,
.mobile-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--muted, #a1a1aa);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: .6rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: color .15s, transform .15s;
  padding: 0 2px;
  -webkit-tap-highlight-color: transparent;
}
.mobile-nav-btn .mn-icon,
.mobile-nav-item > :first-child { font-size: 1.3rem; line-height: 1; }
.mobile-nav-btn span,
.mobile-nav-item span { font-size: .6rem; }
.mobile-nav-btn.active,
.mobile-nav-item.active { color: var(--accent, #3b82f6); }
.mobile-nav-btn.active .mn-icon,
.mobile-nav-btn.active > :first-child,
.mobile-nav-item.active > :first-child { transform: scale(1.15); }
.mobile-nav-btn:active,
.mobile-nav-item:active { transform: scale(0.9); }
body[data-theme="pastel"] .mobile-nav {
  background: rgba(255,255,255,.92);
  border-top-color: rgba(59,130,246,.12);
}

/* ── FAB center button ──────────────────────────────────────── */
.mobile-nav-btn.mn-fab {
  position: relative;
  background: linear-gradient(135deg, #3b82f6, #0ea5e9) !important;
  color: #fff !important;
  width: 52px;
  height: 52px;
  border-radius: 50% !important;
  flex: 0 0 52px !important;
  align-self: center;
  box-shadow: 0 4px 16px rgba(59,130,246,.45);
  margin: 0 4px;
  padding: 0;
  transform: translateY(-8px);
  min-height: unset;
  transition: transform .2s cubic-bezier(.4,0,.2,1), box-shadow .2s !important;
}
.mobile-nav-btn.mn-fab:active {
  transform: translateY(-8px) scale(0.9);
  box-shadow: 0 2px 8px rgba(59,130,246,.3);
}

/* ── Hamburger / sidebar toggle ──────────────────────────────── */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: calc(12px + var(--sat));
  left: 12px;
  z-index: 200;
  width: 40px; height: 40px;
  background: var(--surface, #111113);
  border: 1px solid var(--border, rgba(255,255,255,.06));
  border-radius: 10px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
  -webkit-tap-highlight-color: transparent;
  transition: background .15s;
}
.sidebar-toggle:active { background: var(--surface2); }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 149;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
/* Support both 'show' and 'active' classes */
.sidebar-overlay.show,
.sidebar-overlay.active { display: block; }

/* ── Touch minimum targets (44px per Apple HIG) ──────────────── */
button, a, [role="button"], [onclick] { min-height: 44px; }
.btn-sm, .tag, .badge, .etiq-pill, .view-tab,
.kcol-add, .notif-close, .goal-action-btn,
.sc-row kbd, .prio-badge { min-height: unset; }

/* ═══════════════════════════════════════════════════════════════
   LARGE TABLET (≤ 1024px)
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
  .pd-grid { grid-template-columns: 1fr 1fr !important; }
  .pd-kpi-row { grid-template-columns: repeat(3, 1fr) !important; }
  .mt-kpi-row { grid-template-columns: repeat(2, 1fr) !important; }
}

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

  /* ── Layout ── */
  .layout, .app-layout {
    grid-template-columns: 1fr !important;
  }
  .sidebar {
    position: fixed !important;
    left: 0; top: 0; bottom: 0;
    width: min(300px, 80vw) !important;
    z-index: 150;
    transform: translateX(-100%);
    transition: transform .3s cubic-bezier(.4,0,.2,1);
    box-shadow: 4px 0 32px rgba(0,0,0,.35);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: flex; }
  .mobile-nav { display: block; }

  /* ── Main content padding ── */
  main, .main {
    padding: 16px 16px calc(var(--mobile-nav-h) + 8px) !important;
    padding-top: calc(var(--topbar-h) + var(--sat) + 8px) !important;
  }

  /* ── Topbar ── */
  .topbar {
    position: fixed !important;
    top: 0; left: 0; right: 0;
    z-index: 50;
    padding: calc(10px + var(--sat)) 16px 10px 60px !important;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    height: calc(var(--topbar-h) + var(--sat));
  }
  .topbar .page-title { font-size: .95rem !important; }
  .topbar-left .proj-badge { display: none; }
  .topbar-left .topbar-tags { display: none; }

  /* ── View tabs: hidden on mobile (bottom nav used instead) ── */
  .view-tabs { display: none !important; }
  /* Show dots indicator instead */
  .view-dots { display: flex; }

  /* ── Topbar actions ── */
  .topbar-actions .btn-ghost { display: none !important; }
  #btn-export-csv { display: none !important; }
  #notif-btn { display: flex !important; }
  /* Back btn visible only in topbar in standalone via pwa.js */
  #pwa-back-btn { display: flex; }

  /* ── Modals → bottom sheets ── */
  .overlay { padding: 0 !important; align-items: flex-end !important; }
  .modal {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 24px 24px 0 0 !important;
    max-height: 92vh !important;
    overflow-y: auto;
    /* Drag handle visual */
    padding-top: 8px !important;
  }
  .modal::before {
    content: '';
    display: block;
    width: 40px; height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 0 auto 16px;
  }
  .modal-wide { width: 100% !important; }
  .modal-tache-layout { flex-direction: column !important; }
  .modal-subtasks { width: 100% !important; max-height: 60vh !important; }
  .mt-props-row { gap: 5px !important; }
  .mt-prop { padding: 5px 8px !important; }

  /* ── Stats bar ── */
  .stats-bar {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 8px !important;
  }
  .stat-card { padding: 10px 12px !important; }
  .stat-value { font-size: 1.3rem !important; }
  .stats-bar .stat-card:nth-child(n+4) { display: none; }

  /* ── KPI grids ── */
  .kpi-grid, .pd-kpi-row, .mt-kpi-row { grid-template-columns: repeat(2, 1fr) !important; gap: 8px !important; }

  /* ── Dashboard ── */
  .pd-grid { grid-template-columns: 1fr !important; }
  .pd-velocity { grid-column: 1 !important; }

  /* ── Kanban ── */
  .kanban-col { min-width: 240px; flex-shrink: 0; }
  .kcol-quick-add { display: none !important; }

  /* ── Gallery ── */
  .gal-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .gal-grid.compact { grid-template-columns: repeat(2, 1fr) !important; }

  /* ── Goal cards ── */
  .goal-progress-wrap { min-width: 80px !important; }
  .goal-meta { flex-wrap: wrap; gap: 6px !important; }

  /* ── Grids ── */
  .grid-2, .grid-3-1, .form-row-2 { grid-template-columns: 1fr !important; }

  /* ── Notifications panel ── */
  .notif-panel {
    position: fixed !important;
    bottom: var(--mobile-nav-h) !important;
    top: auto !important;
    right: 0 !important;
    left: 0 !important;
    width: 100% !important;
    border-radius: 20px 20px 0 0 !important;
    max-height: 60vh !important;
  }

  /* ── Shortcuts overlay ── */
  .shortcuts-grid .sc-row { padding: 5px 4px; font-size: .82rem; }
  .sc-key { min-width: 100px !important; }

  /* ── My tasks page ── */
  .mt-row { grid-template-columns: 12px 1fr 90px 60px !important; gap: 6px !important; }
  .mt-row-head { grid-template-columns: 12px 1fr 90px 60px !important; }
  .mt-row > :nth-child(n+5),
  .mt-row-head > :nth-child(n+5) { display: none !important; }

  /* ── Espaces / Goals pages ── */
  .kr-row { grid-template-columns: 1fr 32px !important; }
  .kr-progress, .kr-values { display: none !important; }

  /* ── Misc ── */
  .proj-panel { display: none; }
  .proj-main { grid-column: 1 / -1 !important; }
  .page-header { flex-direction: column !important; gap: 10px !important; align-items: flex-start !important; }
  .topbar-left { max-width: calc(100vw - 200px); overflow: hidden; }

}

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

  /* KPI grids: 2 columns */
  .kpi-grid, .pd-kpi-row, .mt-kpi-row {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 6px !important;
  }
  .kpi-card, .pd-kpi, .mt-kpi { padding: 11px 12px !important; }
  .kpi-value, .pd-kpi-val, .mt-kpi-val { font-size: 1.3rem !important; }

  /* Table: minimal columns */
  .task-table .tthead span:nth-child(n+4),
  .task-table .ttrow > *:nth-child(n+4) { display: none; }

  /* Stats: 3 → 2 */
  .stats-bar { grid-template-columns: repeat(2, 1fr) !important; }
  .stats-bar .stat-card:nth-child(n+3) { display: none; }

  /* Page title */
  .page-title { font-size: 1.2rem !important; }
  .stat-value { font-size: 1.2rem !important; }

  /* Filters: horizontal scroll */
  .quick-filters {
    overflow-x: auto;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }
  .quick-filters::-webkit-scrollbar { display: none; }

  /* Gallery: 1 column on small phones */
  .gal-grid { grid-template-columns: 1fr !important; }

  /* Task title bigger on phone editor */
  .mt-big-title { font-size: 1.1rem !important; }

  /* Notif panel: full screen */
  .notif-panel { max-height: 70vh !important; }

  /* Goal cards: compact */
  .goal-actions { display: none !important; }
  .goal-header { padding: 12px !important; }

}

/* ═══════════════════════════════════════════════════════════════
   PWA Standalone mode (added to home screen)
   ═══════════════════════════════════════════════════════════════ */
@media (display-mode: standalone) {

  /* Push content below status bar */
  .topbar, header { padding-top: calc(10px + var(--sat)) !important; height: calc(var(--topbar-h) + var(--sat)) !important; }
  main, .main { padding-top: calc(var(--topbar-h) + var(--sat) + 8px) !important; }

  /* iOS: prevent text selection except inputs */
  body { -webkit-user-select: none; user-select: none; }
  input, textarea, [contenteditable] { -webkit-user-select: text; user-select: text; }

  /* Remove browser chrome artifacts */
  * { -webkit-touch-callout: none; }
  input, textarea, a { -webkit-touch-callout: default; }

  /* Status bar area — match app bg color */
  body::before {
    content: '';
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--sat);
    background: var(--bg);
    z-index: 9999;
    pointer-events: none;
  }
}

/* ═══════════════════════════════════════════════════════════════
   iOS-specific fixes
   ═══════════════════════════════════════════════════════════════ */

/* Prevent 300ms tap delay on iOS < 13 */
* { touch-action: manipulation; }
/* But keep scroll/zoom working on scroll areas */
.kanban-board, .nav, .content, main, .modal, .notif-list { touch-action: pan-y; }
.kanban-board { touch-action: pan-x pan-y; }

/* Fix iOS Safari viewport height (100vh issue) */
@supports (-webkit-touch-callout: none) {
  .overlay {
    min-height: -webkit-fill-available;
  }
  main, .main {
    min-height: -webkit-fill-available;
  }
}

/* ═══════════════════════════════════════════════════════════════
   Active/focus states (touch-friendly)
   ═══════════════════════════════════════════════════════════════ */
@media (hover: none) and (pointer: coarse) {
  /* Touch devices: more pronounced active states */
  .card:active, .gal-card:active { transform: scale(0.97) !important; opacity: .85; }
  .view-tab:active, .nav-item:active, .mt-filter:active { opacity: .7; }
  .btn-new:active, .btn-primary:active { transform: scale(0.96); filter: brightness(.9); }
  .kanban-col:active { border-color: var(--border-hover); }

  /* Disable hover effects that don't work well on touch */
  .card:hover { transform: none !important; box-shadow: none !important; }
  .gal-card:hover { transform: none !important; }
  .nav-item:hover { transform: none !important; }
  .pd-kpi:hover, .mt-kpi:hover { box-shadow: none !important; }
}

/* ═══════════════════════════════════════════════════════════════
   Auth page: full screen on mobile
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 540px) {
  .auth-container, .login-container {
    flex-direction: column !important;
    min-height: 100dvh !important;
  }
  .auth-promo, .login-promo { display: none !important; }
  .auth-form-side, .login-form-side {
    width: 100% !important;
    padding: calc(32px + var(--sat)) 24px calc(24px + var(--sab)) !important;
    border-radius: 0 !important;
  }
}
