/* ========== RESPONSIVE DESIGN - TÉLÉPHONES ========== */

/* === TRÈS PETITS ÉCRANS (320px - 480px) === */
@media (max-width: 480px) {
  :root {
    --sidebar-width: 0;
  }

  html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
  }

  /* Header adaptée */
  .web-header {
    padding: 0 12px;
    height: 50px;
    z-index: 100;
  }

  .header-logo {
    width: 20px;
    height: 20px;
  }

  .header-title {
    font-size: 0.9rem;
  }

  .header-status {
    display: none;
  }

  /* Screens */
  .screen {
    display: none;
    height: calc(100vh - 50px);
    margin-top: 50px;
    flex-direction: column;
  }

  .screen.active {
    display: flex;
  }

  /* Ensure inactive screens stay hidden */
  #auth-screen:not(.active),
  #app-screen:not(.active),
  #public-map-screen:not(.active) {
    display: none !important;
  }

  /* ===== APP LAYOUT ===== */
  body.web-version {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
  }

  body.web-version .app-screen {
    display: flex !important;
    flex-direction: column;
    width: 100%;
    height: calc(100vh - 50px);
    position: relative;
    flex: 1;
  }

  /* Sidebar → Bottom Navigation */
  .sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100vw;
    height: 60px;
    border-right: none;
    border-top: 1px solid var(--border);
    padding: 0;
    flex-direction: row;
    background: var(--bg-sidebar);
    display: flex !important;
    z-index: 1000;
    margin: 0;
  }

  /* Hide duplicate bottom-nav */
  .bottom-nav,
  .bottom-menu {
    display: none !important;
  }

  .sidebar-nav {
    flex: 1;
    flex-direction: row;
    justify-content: space-around;
    padding: 8px 0;
    gap: 0;
  }

  .nav-tab {
    flex: 1;
    padding: 8px 4px;
    font-size: 0.75rem;
    gap: 4px;
    border-radius: 0;
    justify-content: flex-start;
    flex-direction: column;
    align-items: center;
    background: none;
  }

  .nav-icon {
    font-size: 1.4rem;
    margin-bottom: 2px;
  }

  .nav-label {
    font-size: 0.65rem;
    text-align: center;
  }

  .nav-badge {
    font-size: 0.6rem;
    min-width: 18px;
  }

  .sidebar-footer {
    display: none;
  }

  /* Main content */
  .main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin-bottom: 60px;
    overflow-y: scroll;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    height: auto;
    overscroll-behavior: contain;
  }

  /* Pages */
  .page {
    display: none;
    flex-direction: column;
    overflow-y: visible;
    overflow-x: hidden;
  }

  .page.active {
    display: flex;
  }

  /* ===== MESSAGES ===== */
  .messages-layout {
    display: flex;
    flex-direction: column;
    height: 100%;
    gap: 0;
    width: 100%;
  }

  .conversations-sidebar {
    display: none;
    width: 100%;
    height: auto;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border);
  }

  .messages-layout.show-list .conversations-sidebar {
    display: flex;
    flex-direction: column;
    max-height: 60vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .messages-layout.show-list .chat-area {
    display: none;
  }

  .messages-layout:not(.show-list) .conversations-sidebar {
    display: none;
  }

  .messages-layout:not(.show-list) .chat-area {
    display: flex;
    flex: 1;
  }

  .chat-area {
    display: flex;
    flex-direction: column;
    flex: 1;
    width: 100%;
  }

  .chat-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    text-align: center;
    gap: 12px;
    color: var(--text-muted);
  }

  .chat-placeholder .placeholder-icon {
    font-size: 3rem;
  }

  .chat-panel {
    display: flex;
    flex-direction: column;
    flex: 1;
    width: 100%;
  }

  .chat-header {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .btn-back-mobile {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.9rem;
    padding: 6px 12px;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    transition: all var(--transition);
  }

  .btn-back-mobile:hover {
    background: var(--bg-hover);
  }

  /* Show back button on mobile when viewing chat */
  .messages-layout:not(.show-list) .btn-back-mobile {
    display: flex !important;
  }

  .messages-layout.show-list .btn-back-mobile {
    display: none !important;
  }

  .messages-container {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
  }

  .message-input-area {
    padding: 12px;
    gap: 8px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
  }

  .message-input-area textarea {
    font-size: 16px;
    min-height: 50px;
    resize: vertical;
    max-height: 120px;
  }

  .message-input-area .btn {
    padding: 12px 16px;
    width: 100%;
  }

  .conv-search-box {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }

  .conv-search-input {
    width: 100%;
    padding: 10px 12px;
    font-size: 16px;
  }

  .conversations-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .conversation-item {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
  }

  .conversation-item-avatar {
    width: 40px;
    height: 40px;
    min-width: 40px;
  }

  /* ===== INPUT FIELDS ===== */
  input,
  textarea,
  select {
    font-size: 16px;
    border-radius: var(--radius-md);
    min-height: 44px;
  }

  textarea {
    min-height: 60px;
  }

  /* Authentification screen */
  #auth-screen {
    height: 100%;
    overflow-y: auto;
    padding-bottom: 0;
  }

  .auth-container {
    height: 100%;
    display: flex;
    flex-direction: column;
  }

  .input-wrapper input {
    font-size: 16px !important;
  }
}

/* === PETITS ÉCRANS (480px - 768px) === */

/* === PETITS ÉCRANS (480px - 768px) === */
@media (max-width: 768px) {
  /* Bottom navigation repositioning (keep for all pages) */
  .sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100vw;
    height: 60px;
    flex-direction: row;
    border-top: 1px solid var(--border);
    border-right: none;
    padding: 0;
    z-index: 1000;
    margin: 0;
  }

  .main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin-bottom: 60px;
    overflow-y: scroll;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  .page {
    display: none;
    flex-direction: column;
    overflow-y: visible;
  }

  .page.active {
    display: flex;
  }

  .sidebar-header {
    display: none;
  }

  .sidebar-footer {
    display: none;
  }

  .sidebar-nav {
    flex: 1;
    flex-direction: row;
    justify-content: space-around;
    padding: 8px 0;
    gap: 0;
  }

  .nav-tab {
    flex: 1;
    padding: 8px 4px;
    flex-direction: column;
    align-items: center;
    font-size: 0.7rem;
  }

  /* Messages mobile optimization */
  .messages-layout {
    height: auto;
  }

  .conversations-sidebar {
    max-height: 50vh;
  }

  .chat-area {
    min-height: 300px;
  }

  /* Back button tablet optimization */
  .btn-back-mobile {
    display: flex;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.9rem;
    padding: 6px 12px;
    cursor: pointer;
    border-radius: 4px;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    transition: all var(--transition);
  }

  .btn-back-mobile:hover {
    background: var(--bg-hover);
  }

  .messages-layout:not(.show-list) .btn-back-mobile {
    display: flex !important;
  }

  .messages-layout.show-list .btn-back-mobile {
    display: none !important;
  }
}

/* === SPONSORSHIP ET PROFILE - ADAPTÉS POUR 480-768px === */
@media (max-width: 768px) {
  #sponsorship-page,
  #profile-page {
    padding: 16px;
    padding-bottom: 120px;
  }

  .sponsorship-layout {
    gap: 16px;
  }

  .stats-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .history-list {
    max-height: 300px;
  }

  .profile-stats {
    grid-template-columns: 1fr 1fr;
  }
}

/* === MEGA PETITS ÉCRANS (< 320px - fallback) === */
@media (max-width: 320px) {
  body.web-version {
    height: 100vh;
  }

  .web-header {
    height: 45px;
    padding: 0 8px;
  }

  .app-screen {
    height: calc(100vh - 45px);
  }

  .screen {
    height: calc(100vh - 45px);
    margin-top: 45px;
  }

  .main-content {
    margin-bottom: 55px;
    overflow-y: scroll;
    -webkit-overflow-scrolling: touch;
  }

  .page {
    padding: 8px;
    padding-bottom: 100px;
    overflow-y: visible;
  }

  .user-card {
    padding: 12px;
  }

  .btn,
  input,
  textarea {
    font-size: 16px;
  }

  .sidebar-nav {
    padding: 6px 0;
  }

  .nav-tab {
    padding: 6px 2px;
  }

  /* Ultra-petit écran messages */
  .conversation-item {
    padding: 10px;
  }

  .match-card {
    padding: 8px;
  }

  .match-actions {
    flex-direction: row;
    gap: 4px;
  }

  .match-actions .btn {
    padding: 8px 10px;
    font-size: 0.75rem;
  }

  .sponsor-code {
    font-size: 0.9rem;
    letter-spacing: 0.5px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* === MODE PAYSAGE (LANDSCAPE) === */
@media (max-height: 600px) and (orientation: landscape) {
  body.web-version {
    height: 100vh;
  }

  .web-header {
    height: 40px;
  }

  .app-screen {
    height: calc(100vh - 40px);
  }

  .screen {
    height: calc(100vh - 40px);
    margin-top: 40px;
  }

  .main-content {
    margin-bottom: 50px;
    overflow-y: scroll;
    -webkit-overflow-scrolling: touch;
  }

  .page {
    padding: 10px;
    padding-bottom: 100px;
    overflow-y: visible;
  }

  .page-header {
    margin-bottom: 8px;
  }

  .users-grid {
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  }

  .btn {
    padding: 8px 12px;
    min-height: 36px;
    font-size: 0.85rem;
  }

  input,
  textarea {
    min-height: 36px;
    font-size: 14px;
  }

  .sidebar-nav {
    padding: 6px 0;
  }

  .messages-container {
    max-height: 250px;
  }

  /* Landscape optimization for messages, matches, sponsorship */
  .messages-layout {
    height: auto;
  }

  .matches-grid {
    gap: 12px;
  }

  .match-card {
    flex-direction: row;
    padding: 8px 12px;
    gap: 10px;
  }

  .match-actions {
    flex-direction: row;
    gap: 4px;
  }

  .match-actions .btn {
    padding: 6px 8px;
    font-size: 0.75rem;
    flex: 1;
  }

  .sponsorship-layout {
    gap: 12px;
  }

  .stats-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
  }

  .history-list {
    max-height: 200px;
  }
}

/* === ÉCRANS LARGES (>768px - DESKTOP) === */
@media (min-width: 769px) {
  /* Restaurer sidebar latérale */
  :root {
    --sidebar-width: 280px;
  }

  .sidebar {
    position: static;
    bottom: auto;
    width: var(--sidebar-width);
    height: auto;
    border-right: 1px solid var(--border);
    border-top: none;
    flex-direction: column;
    padding: 20px 0;
    z-index: auto;
  }

  .sidebar-header {
    display: flex;
    padding: 20px;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-nav {
    flex-direction: column;
    justify-content: flex-start;
    padding: 10px 0;
    gap: 4px;
  }

  .nav-tab {
    padding: 12px 16px;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    font-size: 0.9rem;
  }

  .sidebar-footer {
    display: flex;
  }

  .main-content {
    margin-bottom: 0;
    padding-bottom: 0;
    margin-left: 0;
  }

  .page {
    padding: 24px 32px;
    padding-bottom: 24px;
  }

  .users-grid {
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  }

  .houses-grid {
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  }

  /* Desktop layout restoration for messages, matches, sponsorship */
  .messages-layout {
    display: flex;
    flex-direction: row;
    height: calc(100vh - var(--titlebar-height) - 80px);
    gap: 0;
  }

  .conversations-sidebar {
    display: flex !important;
    width: 320px;
    height: auto;
    border-right: 1px solid var(--border);
    border-bottom: none;
    max-height: none;
    flex-direction: column;
  }

  .messages-layout.show-list .chat-area {
    display: flex !important;
  }

  .chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
  }

  .matches-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 32px;
  }

  .match-card {
    flex-direction: row;
    align-items: center;
    padding: 16px 20px;
    gap: 16px;
  }

  .match-actions {
    flex-direction: row;
    gap: 8px;
    flex-shrink: 0;
  }

  .sponsorship-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    padding: 20px 0;
  }

  .history-section {
    grid-column: span 2;
  }

  .stats-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
  }
}

/* === TACTILE (TOUCH DEVICES) === */
@media (hover: none) and (pointer: coarse) {
  /* Désactiver les effets hover */
  button:hover,
  a:hover,
  .btn:hover {
    transform: none;
  }

  /* Augmenter les zones cliquables */
  button,
  .btn,
  a {
    min-height: 44px;
    min-width: 44px;
  }

  /* Meilleur feedback tactile */
  button:active,
  .btn:active {
    opacity: 0.8;
  }
}
