/* ═══════════════════════════════════
   RESPONSIVE SYSTEM
   ═══════════════════════════════════ */

/* ── TABLET LANDSCAPE (901px - 1024px) ── */
@media (max-width: 1024px) {
  .sidebar { width: 180px; min-width: 180px; }
  .detail-panel { width: 260px; min-width: 260px; }
}

/* ── TABLET PORTRAIT (601px - 900px) ── */
@media (max-width: 900px) {
  .sidebar { width: 56px; min-width: 56px; }
  .sidebar .sb-label, .sidebar .sb-text, .sidebar .sb-badge,
  .sidebar .ai-badge, .sidebar .sb-section-title,
  .sidebar .sb-bottom-text, .sidebar .logo-text { display: none; }
  .sidebar .sb-item { justify-content: center; padding: 10px; }
  .detail-panel { width: 260px; min-width: 260px; }
}

/* ── PHONE (max 600px) ── */
@media (max-width: 600px) {

  body { font-size: 15px; }

  /* Hide sidebar — bottom nav takes over */
  .sidebar { display: none; }

  /* Full-width layout */
  .app { flex-direction: column; }
  .main { padding-bottom: max(68px, calc(60px + env(safe-area-inset-bottom))); }

  /* Compact top bar */
  .topbar { padding: 0 12px; gap: 8px; height: 50px; }
  .topbar-toggle { display: none; }
  .page-title { font-size: 16px; font-weight: 600; }
  .search-box { max-width: 120px; }
  .search-box .kbd { display: none; }
  .topbar-actions .btn span { display: none; }
  .topbar-actions .btn { padding: 7px 10px; }

  /* Task list */
  .task-panel { padding: 12px; }
  .task-item { padding: 13px 12px; min-height: 52px; }
  .task-check { width: 22px; height: 22px; }

  /* Detail panel — full-screen slide-up overlay */
  .detail-panel {
    position: fixed !important;
    inset: 0 !important;
    width: 100% !important;
    min-width: 100% !important;
    max-width: 100% !important;
    z-index: 700;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(.4,0,.2,1);
    border-left: none !important;
    padding-bottom: 80px;
    display: block !important;
    overflow-y: auto;
    background: var(--surface);
  }
  .detail-panel.mobile-open {
    transform: translateY(0) !important;
  }

  /* Modals — bottom sheet */
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal {
    border-radius: 20px 20px 0 0;
    max-width: 100%;
    width: 100%;
    padding: 24px 20px 32px;
    max-height: 92vh;
    overflow-y: auto;
  }

  /* Auth card */
  .auth-card { padding: 28px 20px; margin: 0 8px; }

  /* Kanban — horizontal scroll with snap */
  .kanban-board {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    padding-bottom: 12px;
  }
  .kanban-col {
    min-width: 280px;
    scroll-snap-align: start;
    flex-shrink: 0;
  }

  /* AI tabs — horizontal scroll without wrapping */
  .ai-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-wrap: nowrap;
    -ms-overflow-style: none;
  }
  .ai-tabs::-webkit-scrollbar { display: none; }
  .ai-tab { flex-shrink: 0; }

  /* Settings */
  .settings-wrap { padding: 16px !important; }

  /* Toast — above bottom nav */
  .toast { bottom: 76px; right: 12px; left: 12px; max-width: 100%; }

  /* Habits — bigger tap circles */
  .habit-day { width: 34px; height: 34px; font-size: 11px; }

  /* Touch targets minimum 44px */
  .btn, .modal-btn, .sb-item, .focus-btn,
  .ai-submit-btn, .apply-btn { min-height: 44px; }

  /* View padding */
  .ai-view { padding: 12px; }
  .focus-view { padding: 12px; }
  .focus-card { padding: 24px 16px; }

  /* Bottom nav */
  .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 60px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 500;
    align-items: center;
    justify-content: space-around;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
  .mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 10px;
    color: var(--muted);
    min-height: 44px;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
  }
  .mobile-nav-item.active { color: var(--sky); }
  .mobile-nav-item i { font-size: 22px; }

  /* Middle Add button — circular, sky blue */
  .mobile-nav-add {
    background: var(--sky);
    border-radius: 50%;
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(56, 189, 248, .4);
    margin-bottom: 2px;
  }
  .mobile-nav-add i { font-size: 26px; color: white; }

  /* Sticky mobile back button in detail panel */
  .mobile-back-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    font-weight: 600;
    color: var(--sky);
    cursor: pointer;
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 10;
    flex-shrink: 0;
    user-select: none;
    -webkit-user-select: none;
  }
}

/* ── SMALL PHONE (max 380px) ── */
@media (max-width: 380px) {
  .task-title { font-size: 13px; }
  .prio-badge { display: none; }
  .page-title { font-size: 14px; }
  .auth-card { padding: 24px 16px; }
  .kanban-col { min-width: 240px; }
}

/* ── CROSS DEVICE ── */

/* Momentum scrolling on iOS */
.sb-scroll, .task-panel, .detail-panel, .ai-view, .focus-view {
  -webkit-overflow-scrolling: touch;
}

/* Prevent accidental text selection on interactive UI elements */
.sb-item, .btn, .task-check, .habit-day, .modal-btn,
.topbar-toggle, .ai-tab { user-select: none; -webkit-user-select: none; }

/* Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* Cap width on ultra-wide displays */
@media (min-width: 1800px) {
  .app { max-width: 1800px; margin: 0 auto; }
}
