/**
 * OPUS — finition mobile légère pour les pages connectées.
 * Couche additive uniquement : aucune logique métier, aucun style du menu.
 * Rollback : retirer le <link> mobile-app-polish.css de index.html.
 */

@media (max-width: 768px) {
  /* Structure et hiérarchie */
  #appArea .page-area {
    padding: 12px 12px 28px;
  }

  #appArea .page-area > section.card {
    padding: 16px;
    border-radius: 14px;
    box-shadow: none;
  }

  #appArea .page-area > section.card > h2 {
    margin: 0 0 12px;
    font-size: 1.25rem;
    line-height: 1.25;
  }

  #appArea .page-area > section.card > .muted:first-of-type {
    margin-top: 0;
    font-size: .88rem;
    line-height: 1.45;
  }

  /* Formulaires : lisibilité et anti-zoom iOS */
  #appArea input:not([type="checkbox"]):not([type="radio"]),
  #appArea select,
  #appArea textarea {
    min-height: 44px;
    font-size: 16px;
    border-radius: 10px;
  }

  #appArea textarea {
    min-height: 76px;
    resize: vertical;
  }

  #appArea form .row {
    margin: 12px 0;
  }

  #appArea form .row > label:first-child {
    margin-bottom: 6px;
    font-size: .9rem;
    font-weight: 650;
  }

  #appArea .help-text {
    display: block;
    margin-top: 5px;
    font-size: .75rem;
    line-height: 1.35;
    -webkit-line-clamp: unset;
    line-clamp: unset;
    overflow: visible;
  }

  /* Actions hors navigation */
  #appArea section.card > .actions,
  #appArea section.card form > .actions,
  #appArea .match-card .actions,
  #appArea .demande-card .actions,
  #appArea .mission-summary .actions {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  #appArea section.card > .actions button,
  #appArea section.card form > .actions button,
  #appArea .match-card .actions button,
  #appArea .demande-card .actions button {
    width: 100%;
    min-height: 44px;
  }

  /* Cartes de missions, demandes et candidats */
  #appArea .cards-grid,
  #appArea .profiles-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    margin-top: 12px;
  }

  #appArea .cards-grid > .card,
  #appArea .match-card,
  #appArea .demande-card,
  #appArea .profile-card,
  #appArea .profiles-container > .card {
    padding: 14px;
    border-radius: 12px;
    box-shadow: none;
  }

  #appArea .match-card [style*="display:flex"],
  #appArea .cards-grid > .card [style*="display:flex"],
  #appArea .profiles-container > * [style*="display:flex"] {
    flex-wrap: wrap !important;
  }

  #appArea .pills-row,
  #appArea .info-strip {
    flex-wrap: wrap;
    gap: 6px;
  }

  #appArea .card.action-required:hover,
  #appArea .match-card:hover,
  #appArea .demande-card:hover {
    transform: none;
  }

  /* Dashboard : cartes moins massives, texte non tronqué */
  #dash .dashHeader {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
  }

  #dash #btnRefresh {
    min-height: 40px;
    padding: 9px 12px;
  }

  #dashSummary.cards-row {
    gap: 10px !important;
  }

  #dashSummary .metric-card {
    min-height: 126px;
    height: auto !important;
    aspect-ratio: auto !important;
    padding: 14px !important;
  }

  #dashSummary .metric-card .metric-title,
  #dashSummary .metric-card .metric-sub {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  /* Nouvelle demande : calendrier cohérent avec Mes disponibilités */
  #nouvelleDemandeSection .calendar-controls {
    display: grid;
    grid-template-columns: 44px 1fr 44px;
    align-items: center;
    gap: 8px;
  }

  #nouvelleDemandeSection .calendar-controls button {
    width: 44px;
    min-width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 10px;
  }

  #nouvelleDemandeSection .calendar-title {
    text-align: center;
    font-size: 1rem;
    font-weight: 700;
  }

  /* Messagerie : conversation lisible et saisie stable */
  #messagesSection .conversation-list {
    display: grid;
    gap: 8px;
  }

  #messagesSection .conversation-item {
    align-items: flex-start;
    gap: 10px;
    padding: 13px 12px;
    border-radius: 11px;
  }

  #messagesSection .conversation-item > div:first-child {
    min-width: 0;
    flex: 1;
  }

  #messagesSection .conversation-detail {
    max-height: none;
    padding: 12px;
    border-radius: 12px;
  }

  #messagesSection .conversation-detail h3 {
    font-size: 1rem;
    line-height: 1.35;
  }

  #messagesSection .message-list {
    min-height: 220px;
    max-height: 52dvh;
    padding: 8px 2px;
  }

  #messagesSection .chat-message {
    max-width: 90%;
    font-size: .9rem;
    line-height: 1.4;
  }

  #messagesSection .send-message-form {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin-top: 10px;
  }

  #messagesSection .send-message-form textarea {
    width: 100%;
    min-height: 72px;
    margin: 0;
  }

  #messagesSection .send-message-form button {
    width: 100%;
    min-height: 44px;
  }

  #messagesSection .conversation-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-left: 0;
  }

  #messagesSection .conversation-actions button {
    width: 100%;
    min-width: 0;
    white-space: normal;
  }

  #messagesSection .mission-summary {
    padding: 12px;
    border-radius: 10px;
  }

  /* Profil : fichiers et groupes restent dans l'écran */
  #profileSection input[type="file"] {
    width: 100%;
    max-width: 100%;
    padding: 8px;
    font-size: .82rem;
  }

  #profileSection .profile-opticien-only,
  #profileSection .profile-entreprise-only {
    max-width: 100%;
  }

  /* Zones : commandes tactiles, sans toucher à Google Maps */
  #zonesSection .map-controls {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  #zonesSection .map-controls button {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    padding: 8px 5px;
    white-space: normal;
    font-size: .82rem;
  }

  #zonesSection #zoneForm .actions button {
    width: 100%;
    min-height: 44px;
  }

  /* Tableaux : densité réduite et indication de défilement */
  #missionsPayeesSection .tableWrap,
  #zonesSection .tableWrap {
    margin: 0 -4px;
    padding: 0 4px 6px;
    border-radius: 10px;
    -webkit-overflow-scrolling: touch;
  }

  #missionsPayeesSection .tableWrap::after,
  #zonesSection .tableWrap::after {
    content: "Glissez horizontalement pour voir la suite";
    display: block;
    padding: 7px 2px 1px;
    color: #64748b;
    font-size: .7rem;
    text-align: center;
  }

  #missionsPayeesSection table,
  #zonesSection table {
    font-size: .78rem;
  }

  #missionsPayeesSection th,
  #missionsPayeesSection td,
  #zonesSection th,
  #zonesSection td {
    padding: 8px;
  }

  /* Documentation */
  #documentationSection,
  #documentationEntrepriseSection,
  #documentationOpticienSection {
    font-size: .92rem;
    line-height: 1.55;
  }

  #documentationSection h3,
  #documentationEntrepriseSection h3,
  #documentationOpticienSection h3 {
    margin-top: 20px;
    font-size: 1.05rem;
  }

  #documentationSection ul,
  #documentationEntrepriseSection ul,
  #documentationOpticienSection ul {
    padding-left: 20px;
  }

  /* Modales métier en panneau mobile */
  #appArea .modal {
    padding: 10px;
    align-items: flex-end;
  }

  #appArea .modal .modal-content {
    width: 100%;
    max-width: none !important;
    max-height: 92dvh;
    padding: 18px;
    border-radius: 16px 16px 8px 8px;
    overflow-y: auto;
  }

  #appArea .modal-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  #appArea .modal-actions button {
    width: 100%;
    min-height: 44px;
  }
}

@media (max-width: 380px) {
  #appArea .page-area {
    padding: 10px 9px 24px;
  }

  #appArea .page-area > section.card {
    padding: 13px;
  }

  #messagesSection .conversation-actions,
  #zonesSection .map-controls {
    grid-template-columns: 1fr;
  }

  #dashSummary.cards-row {
    grid-template-columns: 1fr 1fr !important;
  }
}
