/* ============================================
   MOBILE.CSS - Responsive & Touch Optimizations
   Score Conseils Dashboard
   ============================================ */

/* ============================================
   CSS VARIABLES - MOBILE SPECIFIC
   ============================================ */
:root {
  --touch-target-min: 44px;
  --mobile-padding: 1rem;
  --mobile-gap: 0.75rem;
  --nav-height: 60px;
}

/* ============================================
   MOBILE NAVIGATION - HAMBURGER MENU
   ============================================ */

/* Hamburger button - hidden by default (shown only on mobile) */
.hamburger-btn {
  display: none !important;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
  width: var(--touch-target-min);
  height: var(--touch-target-min);
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  z-index: var(--z-hamburger, 510);
}

.hamburger-btn span {
  display: block;
  width: 24px;
  height: 2px;
  background: white;
  border-radius: 2px;
  transition: all 0.3s ease;
}

.hamburger-btn.active span:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}

.hamburger-btn.active span:nth-child(2) {
  opacity: 0;
}

.hamburger-btn.active span:nth-child(3) {
  transform: rotate(-45deg) translate(5px, -5px);
}

/* Mobile menu overlay - hidden by default */
.mobile-menu-overlay {
  display: none !important;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: var(--z-overlay, 900);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.mobile-menu-overlay.active {
  opacity: 1;
}

/* Mobile slide-in menu - hidden by default */
.mobile-nav {
  display: none !important;
  position: fixed;
  top: 0;
  right: -280px;
  width: 280px;
  height: 100vh;
  background: var(--bg-panel);
  z-index: var(--z-mobile-nav, 950);
  overflow-y: auto;
  transition: right 0.3s ease;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
  padding-top: calc(var(--nav-height) + 1rem);
}

.mobile-nav.active {
  right: 0;
}

.mobile-nav-links {
  list-style: none;
  padding: 0;
  margin: 0;
}

.mobile-nav-links li {
  border-bottom: 1px solid var(--border-color);
}

.mobile-nav-links a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  color: var(--text-primary);
  text-decoration: none;
  font-size: 1rem;
  min-height: var(--touch-target-min);
  transition: background 0.2s;
}

.mobile-nav-links a:hover,
.mobile-nav-links a:active {
  background: rgba(143, 189, 29, 0.1);
}

.mobile-nav-links .nav-icon {
  font-size: 1.25rem;
  width: 24px;
  text-align: center;
}

/* Mobile nav section headers */
.mobile-nav-section {
  padding: 0.75rem 1.25rem;
  background: var(--bg-main);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

/* Mobile accordion for dropdowns */
.mobile-accordion-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  cursor: pointer;
  min-height: var(--touch-target-min);
}

.mobile-accordion-header::after {
  content: '+';
  font-size: 1.25rem;
  font-weight: 300;
  transition: transform 0.3s;
}

.mobile-accordion-header.active::after {
  content: '-';
}

.mobile-accordion-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  background: var(--bg-main);
}

.mobile-accordion-content.active {
  max-height: 500px;
}

.mobile-accordion-content a {
  padding-left: 2.5rem;
}

/* ============================================
   RESPONSIVE BREAKPOINTS
   ============================================ */

/* Extra large (xl): 1280px+ - Default styles */

/* Large (lg): 1024px - 1279px */
@media (max-width: 1279px) {
  .container {
    padding: 0 1.5rem;
  }

  .nav-links {
    gap: 1.5rem;
  }

  .nav-links a {
    font-size: 0.875rem;
  }
}

/* Medium (md): 768px - 1023px - Tablet */
@media (max-width: 1023px) {
  .container {
    padding: 0 1.25rem;
  }

  .nav-links {
    gap: 1rem;
  }

  /* Hide some nav items on tablet */
  .nav-links > li:not(.user-menu):not(.groupements-menu):nth-child(n+7) {
    display: none;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .charts-grid {
    grid-template-columns: 1fr;
  }

  .chart-card {
    min-height: 280px;
  }
}

/* Small (sm): 640px - 767px - Large phone / Small tablet */
@media (max-width: 767px) {
  /* Show hamburger, hide desktop nav */
  .hamburger-btn {
    display: flex !important;
  }

  .mobile-nav,
  .mobile-menu-overlay {
    display: block !important;
  }

  .nav-links {
    display: none !important;
  }

  /* Body padding - only safe area for notched devices */
  body {
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  main {
    padding: 1.5rem 0;
  }

  .container {
    padding: 0 var(--mobile-padding);
  }

  /* Page header mobile */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
  }

  .page-header h1 {
    font-size: 1.5rem;
  }

  /* Hero section mobile */
  .hero {
    padding: 2rem 1rem;
    margin-bottom: 1.5rem;
  }

  .hero h1 {
    font-size: 1.75rem;
    line-height: 1.2;
  }

  .hero p {
    font-size: 1rem;
  }

  /* Stats grid - 2 columns on tablet, 1 on phone */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }

  .stat-card {
    padding: 1.25rem;
  }

  .stat-card h3,
  .stat-number {
    font-size: 2rem;
  }

  /* Filters responsive */
  .filters-form {
    flex-direction: column;
    gap: var(--mobile-gap);
    padding: 1rem;
  }

  .search-group {
    min-width: 100%;
  }

  .search-input {
    font-size: 16px; /* Prevents zoom on iOS */
    padding: 0.75rem 1rem;
  }

  .filter-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .filter-select,
  .limit-select {
    flex: 1;
    min-width: calc(50% - 0.375rem);
  }

  /* Cards and details */
  .details-grid,
  .detail-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .details-card,
  .detail-section {
    padding: 1.25rem;
  }

  .details-card h2,
  .detail-section h2 {
    font-size: 1.2rem;
  }

  /* Buttons - larger touch targets */
  .btn {
    min-height: var(--touch-target-min);
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
  }

  .btn-sm {
    min-height: 36px;
    padding: 0.5rem 1rem;
  }

  /* Pagination mobile */
  .pagination {
    flex-direction: column;
    gap: 1rem;
  }

  .pagination .btn {
    width: 100%;
    text-align: center;
  }

  /* Action buttons row - smaller gap on mobile */
  .btn-outline-score {
    font-size: 0.8rem;
    padding: 0.4rem 0.65rem;
  }

  /* Data tables - horizontal scroll on mobile */
  .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Dashboard header card */
  .dashboard-header-card {
    flex-direction: column;
    gap: 1rem;
    padding: 1.25rem;
  }

  /* Charts smaller on mobile */
  .chart-card {
    min-height: 220px;
  }

  /* Footer mobile */
  .footer {
    padding: 1.5rem 0;
    margin-top: 2rem;
  }

  .footer p {
    font-size: 0.875rem;
  }
}

/* Extra small (xs): < 640px - Mobile phones */
@media (max-width: 639px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .navbar .container {
    padding: 0 0.75rem;
  }

  .nav-brand img {
    height: 36px;
  }

  .nav-brand h1 {
    font-size: 1rem;
    display: none; /* Show only logo on very small screens */
  }

  /* Filter selects full width */
  .filter-select,
  .limit-select {
    width: 100%;
    min-width: 100%;
  }
}

/* ============================================
   TABLES - RESPONSIVE CARDS MODE
   ============================================ */
@media (max-width: 767px) {
  /* Table horizontal scroll indicator */
  .table-container {
    position: relative;
  }

  .table-container::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 30px;
    background: linear-gradient(to right, transparent, rgba(0, 0, 0, 0.05));
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
  }

  .table-container.scrollable::after {
    opacity: 1;
  }

  /* Card view for tables - opt-in via class */
  .data-table.mobile-cards {
    display: block;
  }

  .data-table.mobile-cards thead {
    display: none;
  }

  .data-table.mobile-cards tbody {
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }

  .data-table.mobile-cards tr {
    display: block;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    box-shadow: var(--shadow-sm);
  }

  .data-table.mobile-cards td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 0.5rem 0;
    border: none;
    border-bottom: 1px solid var(--border-color);
  }

  .data-table.mobile-cards td:last-child {
    border-bottom: none;
  }

  .data-table.mobile-cards td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    flex-shrink: 0;
    margin-right: 1rem;
  }

  /* Standard table - responsive tweaks */
  .data-table:not(.mobile-cards) th,
  .data-table:not(.mobile-cards) td {
    padding: 0.75rem 0.5rem;
    font-size: 0.875rem;
  }

  /* Hide less important columns on mobile */
  .data-table .hide-mobile {
    display: none;
  }
}

/* ============================================
   FORMS - MOBILE OPTIMIZATIONS
   ============================================ */
@media (max-width: 767px) {
  /* Form layout */
  .form-group {
    margin-bottom: 1rem;
  }

  .form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    font-size: 0.875rem;
  }

  /* Input styling for touch */
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="number"],
  input[type="password"],
  input[type="search"],
  input[type="date"],
  select,
  textarea {
    width: 100%;
    min-height: var(--touch-target-min);
    padding: 0.75rem 1rem;
    font-size: 16px; /* Prevents iOS zoom */
    border-radius: 8px;
    border: 2px solid var(--border-color);
    background: var(--bg-panel);
    color: var(--text-primary);
    -webkit-appearance: none;
    appearance: none;
  }

  input:focus,
  select:focus,
  textarea:focus {
    outline: none;
    border-color: var(--score-green-light);
    box-shadow: 0 0 0 3px rgba(143, 189, 29, 0.15);
  }

  /* Select arrow */
  select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%234a5568' viewBox='0 0 12 12'%3E%3Cpath d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    padding-right: 2.5rem;
  }

  /* Textarea */
  textarea {
    min-height: 120px;
    resize: vertical;
  }

  /* Checkbox and radio - larger touch targets */
  input[type="checkbox"],
  input[type="radio"] {
    width: 24px;
    height: 24px;
    margin-right: 0.75rem;
  }

  /* Submit button sticky on mobile */
  .form-actions {
    position: sticky;
    bottom: 1rem;
    background: var(--bg-panel);
    padding: 1rem;
    margin: 0 -1rem;
    border-top: 1px solid var(--border-color);
    z-index: 10;
  }

  .form-actions .btn {
    width: 100%;
  }
}

/* ============================================
   TOUCH OPTIMIZATIONS
   ============================================ */

/* Improve touch responsiveness - disable double-tap zoom on interactive elements */
.hamburger-btn,
.user-trigger,
.nav-item,
.nav-dropdown-item,
.mobile-nav-links a,
.mobile-accordion-header,
.btn,
.stat-card,
.details-card {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* ============================================
   TOUCH FEEDBACK
   ============================================ */
@media (hover: none) and (pointer: coarse) {
  /* Touch devices - remove hover effects, add active states */
  .btn:hover {
    transform: none;
  }

  .btn:active {
    transform: scale(0.98);
    opacity: 0.9;
  }

  .stat-card:hover {
    transform: none;
  }

  .stat-card:active {
    transform: scale(0.98);
  }

  /* Touch ripple effect */
  .touch-ripple {
    position: relative;
    overflow: hidden;
  }

  .touch-ripple::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(143, 189, 29, 0.3);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.3s, height 0.3s;
  }

  .touch-ripple:active::after {
    width: 200%;
    height: 200%;
  }
}

/* ============================================
   TYPOGRAPHY - MOBILE SCALING
   ============================================ */
@media (max-width: 767px) {
  body {
    font-size: 16px;
    line-height: 1.6;
  }

  h1 {
    font-size: clamp(1.5rem, 5vw, 2.5rem);
    line-height: 1.2;
  }

  h2 {
    font-size: clamp(1.25rem, 4vw, 1.75rem);
    line-height: 1.3;
  }

  h3 {
    font-size: clamp(1.1rem, 3.5vw, 1.5rem);
  }

  p, li {
    font-size: 1rem;
    line-height: 1.7;
  }

  /* Improve readability */
  .detail-value,
  .pappers-value {
    font-size: 1rem;
    line-height: 1.5;
  }

  .detail-label,
  .pappers-label {
    font-size: 0.8125rem;
  }
}

/* ============================================
   IMAGES & MEDIA - RESPONSIVE
   ============================================ */
img {
  max-width: 100%;
  height: auto;
}

/* Lazy loading placeholder */
img[loading="lazy"] {
  background: var(--bg-main);
}

/* ============================================
   CHARTS - MOBILE RESPONSIVE
   ============================================ */
@media (max-width: 767px) {
  .chart-card {
    height: auto;
    min-height: 280px;
    padding: 1rem;
  }

  .chart-card h2 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
  }

  .chart-card canvas {
    max-height: 200px !important;
    height: 200px !important;
  }

  .chart-controls {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .chart-controls label {
    font-size: 0.8rem;
    flex: 1;
    min-width: calc(50% - 0.25rem);
  }

  .chart-controls select {
    width: 100%;
    min-height: 36px;
  }
}

/* ============================================
   MODALS - MOBILE FULL SCREEN
   ============================================ */
@media (max-width: 767px) {
  .modal-content {
    width: 100% !important;
    max-width: 100% !important;
    height: 100vh !important;
    max-height: 100vh !important;
    margin: 0 !important;
    border-radius: 0 !important;
  }

  .modal-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg-panel);
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
  }

  .modal-body {
    padding: 1rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .modal-footer {
    position: sticky;
    bottom: 0;
    background: var(--bg-panel);
    padding: 1rem;
    border-top: 1px solid var(--border-color);
  }
}

/* ============================================
   PAPPERS SECTION - MOBILE
   ============================================ */
@media (max-width: 767px) {
  .pappers-collapsible-header {
    padding: 0.875rem 1rem;
    gap: 0.75rem;
  }

  .pappers-section-title {
    font-size: 0.9375rem;
  }

  .pappers-count {
    font-size: 0.6875rem;
    padding: 0.2rem 0.5rem;
  }

  .pappers-collapsible-content.show {
    padding: 1rem;
  }

  .pappers-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .pappers-field {
    gap: 0.375rem;
  }

  .pappers-list-item {
    padding: 0.625rem;
    font-size: 0.8125rem;
  }
}

/* ============================================
   SEARCH - MOBILE STICKY
   ============================================ */
@media (max-width: 767px) {
  .search-sticky {
    position: sticky;
    top: var(--nav-height);
    z-index: 50;
    background: var(--bg-main);
    padding: 0.75rem 0;
    margin: -0.75rem 0 1rem 0;
  }

  .search-sticky .search-input {
    border-radius: 24px;
    padding-left: 1.25rem;
  }

  /* Clear button */
  .search-clear {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    border: none;
    background: var(--text-muted);
    color: white;
    border-radius: 50%;
    font-size: 1rem;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
  }

  .search-input:not(:placeholder-shown) + .search-clear {
    display: flex;
  }
}

/* ============================================
   LOADING STATES - SKELETON
   ============================================ */
.skeleton {
  background: linear-gradient(90deg, var(--border-color) 25%, var(--bg-main) 50%, var(--border-color) 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: 4px;
}

@keyframes skeleton-loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.skeleton-text {
  height: 1rem;
  margin-bottom: 0.5rem;
}

.skeleton-text:last-child {
  width: 60%;
}

.skeleton-card {
  height: 120px;
}

/* ============================================
   PULL TO REFRESH INDICATOR
   ============================================ */
.pull-to-refresh {
  display: none;
  justify-content: center;
  align-items: center;
  padding: 1rem;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.pull-to-refresh.visible {
  display: flex;
}

.pull-to-refresh .spinner {
  width: 20px;
  height: 20px;
  margin-right: 0.5rem;
}

/* ============================================
   SAFE AREA - iOS NOTCH SUPPORT
   ============================================ */
@supports (padding: env(safe-area-inset-top)) {
  .navbar {
    padding-top: env(safe-area-inset-top);
  }

  body {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ============================================
   UTILITY CLASSES - MOBILE
   ============================================ */
@media (max-width: 767px) {
  .hide-mobile {
    display: none !important;
  }

  .show-mobile {
    display: block !important;
  }

  .mobile-full-width {
    width: 100% !important;
  }

  .mobile-center {
    text-align: center !important;
  }

  .mobile-stack {
    flex-direction: column !important;
  }

  .mobile-gap-sm {
    gap: 0.5rem !important;
  }

  .mobile-p-0 {
    padding: 0 !important;
  }

  .mobile-mt-1 {
    margin-top: 1rem !important;
  }
}

@media (min-width: 768px) {
  .hide-desktop {
    display: none !important;
  }

  .show-desktop {
    display: block !important;
  }

  /* Ensure mobile elements are hidden on desktop */
  .mobile-nav,
  .mobile-menu-overlay,
  .hamburger-btn {
    display: none !important;
  }
}

/* ============================================
   DARK MODE - MOBILE ADJUSTMENTS
   ============================================ */
@media (max-width: 767px) {
  [data-theme="dark"] .mobile-nav {
    background: var(--bg-panel);
    border-left: 1px solid var(--border-color);
  }

  [data-theme="dark"] .mobile-nav-links a:hover {
    background: rgba(143, 189, 29, 0.15);
  }
}

/* ============================================
   PRINT - HIDE MOBILE ELEMENTS
   ============================================ */
@media print {
  .hamburger-btn,
  .mobile-nav,
  .mobile-menu-overlay {
    display: none !important;
  }

  .nav-links {
    display: flex !important;
  }
}
