/**
 * ═══════════════════════════════════════════════════════════
 * BRANCHEN-FINDER MOBILE DESIGN SYSTEM
 * ═══════════════════════════════════════════════════════════
 * 
 * SINGLE SOURCE OF TRUTH für alle Mobile-Styles.
 * KEINE anderen Dateien dürfen Mobile-Overrides definieren!
 * 
 * Letzte Aktualisierung: 2024-12-04
 * ═══════════════════════════════════════════════════════════
 */

/* ═══════════════════════════════════════════════════════════
   MOBILE BREAKPOINTS
   ═══════════════════════════════════════════════════════════ */

/*
 * Breakpoint-Strategie: MOBILE-FIRST
 * 
 * Default-Styles = Mobile (375px)
 * @media (min-width: 768px) = Tablet
 * @media (min-width: 1024px) = Desktop
 * 
 * NIEMALS max-width verwenden außer für spezifische Overrides!
 */


/* ═══════════════════════════════════════════════════════════
   GLOBALE MOBILE RESETS
   ═══════════════════════════════════════════════════════════ */

/* Verhindert horizontalen Scroll - KRITISCH! */
html, body {
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
}

/* Alle Container auf Mobile begrenzen - NUR Mobile! */
@media (max-width: 1023px) {
  * {
    max-width: 100vw;
  }
}

* {
  box-sizing: border-box;
}

/* iOS Input Zoom Prevention */
@media (max-width: 767px) {
  input, select, textarea {
    font-size: 16px !important;
  }
}


/* ═══════════════════════════════════════════════════════════
   TOUCH TARGETS - MINIMUM 44px
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  button,
  .btn,
  .clickable,
  [role="button"] {
    min-height: 44px;
  }

  input[type="checkbox"],
  input[type="radio"] {
    width: 22px;
    height: 22px;
    margin: 0;
  }
  
  .checkbox-wrapper,
  .radio-wrapper {
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 10px;
  }
}


/* ═══════════════════════════════════════════════════════════
   PAGE LAYOUT - MOBILE
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  .page-content,
  .main-content,
  main,
  .app-content {
    padding: 16px;
    padding-bottom: 100px;
  }

  .container {
    padding: 16px;
    padding-bottom: 100px;
  }

  h1, .page-title {
    font-size: 1.5rem;
    line-height: 1.3;
    margin-bottom: 16px;
  }
  
  h2 {
    font-size: 1.25rem;
    margin-bottom: 12px;
  }
}


/* ═══════════════════════════════════════════════════════════
   BOTTOM NAVIGATION
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  .bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: white;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding-bottom: env(safe-area-inset-bottom, 0);
    z-index: 1000;
  }

  .bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 60px;
    min-height: 56px;
    padding: 8px 12px;
    color: var(--neutral-500, #6b7280);
    text-decoration: none;
    font-size: 11px;
    position: relative;
    -webkit-tap-highlight-color: transparent;
  }

  .bottom-nav-item.active {
    color: var(--color-brand);
  }

  .bottom-nav-icon {
    font-size: 22px;
    margin-bottom: 2px;
  }
  
  .bottom-nav-label {
    font-size: 11px;
    font-weight: 500;
  }
  
  .bottom-nav-badge {
    position: absolute;
    top: 4px;
    right: 8px;
    background: var(--danger, #ef4444);
    color: white;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
  }
}

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


/* ═══════════════════════════════════════════════════════════
   CARDS - MOBILE OPTIMIERT
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  .card,
  .ds-card {
    width: 100%;
    padding: 16px;
    border-radius: 12px;
    background: white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-bottom: 12px;
  }

  .stats-grid,
  .admin-quick-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }

  .stat-card {
    text-align: center;
    padding: 16px 12px;
  }

  .stat-card .stat-number,
  .stat-card .stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary-500, #0D9488);
  }

  .stat-card .stat-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--neutral-500, #6b7280);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 4px;
  }
}


/* ═══════════════════════════════════════════════════════════
   BUTTONS - MOBILE
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  .btn,
  button.btn-primary,
  button.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    font-size: 15px;
    font-weight: 600;
    border-radius: 8px;
    min-height: 44px;
    width: 100%;
    cursor: pointer;
    transition: all 0.2s ease;
  }

  .button-grid,
  .btn-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .button-grid .btn,
  .btn-group .btn {
    width: 100%;
  }
}


/* ═══════════════════════════════════════════════════════════
   FORMS - MOBILE
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  .form-group {
    margin-bottom: 16px;
  }

  .form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--neutral-700, #374151);
    margin-bottom: 6px;
  }

  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="tel"],
  select,
  textarea {
    width: 100%;
    padding: 12px 16px;
    font-size: 16px;
    border: 1px solid var(--neutral-200, #e5e7eb);
    border-radius: 8px;
    background: white;
    color: var(--neutral-900, #111827);
  }

  select {
    padding-right: 40px;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
  }
  
  select option {
    padding: 12px;
    font-size: 14px;
  }
}


/* ═══════════════════════════════════════════════════════════
   USER HEADER - NAME + EMAIL GETRENNT
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  .user-header,
  .user-info,
  .user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
  }

  .user-avatar {
    width: 44px;
    height: 44px;
    min-width: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 600;
    flex-shrink: 0;
  }

  .user-details,
  .user-info-block,
  .sidebar-user-info-block {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
  }

  .user-name,
  .sidebar-user-name-text {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
  }

  .user-email,
  .sidebar-user-email-text {
    font-size: 12px;
    opacity: 0.8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
  }
}


/* ═══════════════════════════════════════════════════════════
   MODALS - MOBILE FULLSCREEN
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  .modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 9999;
    padding: 0;
  }

  .modal-content,
  .modal {
    background: white;
    width: 100%;
    max-height: 90vh;
    border-radius: 16px 16px 0 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .modal-header {
    position: sticky;
    top: 0;
    background: white;
    padding: 16px 20px;
    border-bottom: 1px solid var(--neutral-100, #f3f4f6);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 1;
  }

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

  .modal-footer {
    position: sticky;
    bottom: 0;
    background: white;
    padding: 16px 20px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0));
    border-top: 1px solid var(--neutral-100, #f3f4f6);
  }

  .modal-close {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    background: none;
    border: none;
    cursor: pointer;
  }
}


/* ═══════════════════════════════════════════════════════════
   LEAD CARDS - MOBILE
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  .lead-card {
    padding: 16px;
    width: 100%;
  }

  .lead-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
  }

  .lead-card-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--neutral-900, #111827);
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .lead-card-address {
    font-size: 14px;
    color: var(--neutral-500, #6b7280);
    margin-top: 8px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .lead-card-score {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 28px;
    padding: 0 10px;
    border-radius: 14px;
    font-size: 14px;
    font-weight: 700;
  }
}


/* ═══════════════════════════════════════════════════════════
   BULK ACTIONS - MOBILE
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  .bulk-actions {
    background: white;
    border-radius: 12px;
    padding: 12px 16px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  }

  .bulk-actions .selection-count {
    font-size: 14px;
    color: var(--neutral-600, #4b5563);
    margin-bottom: 8px;
  }

  .bulk-actions .bulk-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .bulk-actions .btn {
    padding: 10px 12px;
    font-size: 13px;
  }
}


/* ═══════════════════════════════════════════════════════════
   BADGES - MOBILE
   ═══════════════════════════════════════════════════════════ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}

.badge-success {
  background: var(--success-light, #d1fae5);
  color: var(--success, #059669);
}

.badge-warning {
  background: var(--warning-light, #fef3c7);
  color: var(--warning, #d97706);
}

.badge-error {
  background: var(--danger-light, #fee2e2);
  color: var(--danger, #dc2626);
}

.badge-neutral {
  background: var(--neutral-100, #f3f4f6);
  color: var(--neutral-600, #4b5563);
}


/* ═══════════════════════════════════════════════════════════
   SEARCH HISTORY CARDS - MOBILE
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  .search-history-card {
    display: flex;
    flex-direction: column;
    padding: 16px;
    gap: 12px;
  }

  .search-history-card .card-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 4px;
  }
}


/* ═══════════════════════════════════════════════════════════
   INFO BOXES - MOBILE
   ═══════════════════════════════════════════════════════════ */

.info-box {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 12px;
}

.info-box-info {
  background: var(--info-light, #dbeafe);
  border: 1px solid var(--info, #3b82f6);
  color: #1e40af;
}

.info-box-warning {
  background: var(--warning-light, #fef3c7);
  border: 1px solid var(--warning, #f59e0b);
  color: #92400e;
}

.info-box-error {
  background: var(--danger-light, #fee2e2);
  border: 1px solid var(--danger, #ef4444);
  color: #b91c1c;
}

.info-box-success {
  background: var(--success-light, #d1fae5);
  border: 1px solid var(--success, #10b981);
  color: #065f46;
}


/* ═══════════════════════════════════════════════════════════
   FLOATING ELEMENTS (FAB, Credits)
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  .feedback-fab {
    position: fixed;
    bottom: calc(64px + 24px);
    left: 16px;
    right: auto;
    z-index: 990;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .feedback-fab-text {
    display: none;
  }
}


/* ═══════════════════════════════════════════════════════════
   SCROLL LOCK FÜR MODALS
   ═══════════════════════════════════════════════════════════ */

body.modal-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
}


/* ═══════════════════════════════════════════════════════════
   ADMIN BEREICH - MOBILE OVERRIDES
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  .admin-page .stat-card .stat-number,
  .admin-page .stat-card .stat-value {
    color: var(--admin-primary, #e74c3c);
  }

  .admin-header {
    padding: 16px;
  }
  
  .admin-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }
  
  .admin-nav .btn,
  .admin-nav a {
    flex: 1 1 auto;
    min-width: calc(50% - 4px);
    text-align: center;
    padding: 10px 12px;
    font-size: 13px;
    border-radius: 20px;
  }
}


/* ═══════════════════════════════════════════════════════════
   SIDEBAR - MOBILE HIDDEN
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  .app-sidebar,
  .sidebar {
    display: none !important;
  }
  
  .app-content {
    margin-left: 0 !important;
  }
}


/* ═══════════════════════════════════════════════════════════
   TABLET BREAKPOINT (768px+)
   ═══════════════════════════════════════════════════════════ */

@media (min-width: 768px) {
  /* FIX #1: Sidebar Layout - Content muss Platz für Sidebar lassen */
  .app-content {
    margin-left: var(--sidebar-width, 260px);
    transition: margin-left 0.3s ease;
  }
  
  .stats-grid,
  .admin-quick-stats {
    grid-template-columns: repeat(4, 1fr);
  }
  
  .btn {
    width: auto;
  }
  
  .button-grid {
    grid-template-columns: repeat(4, auto);
    justify-content: flex-start;
  }
  
  .modal-overlay {
    align-items: center;
    padding: 20px;
  }
  
  .modal-content,
  .modal {
    max-width: 500px;
    max-height: 80vh;
    border-radius: 16px;
  }
}


/* ═══════════════════════════════════════════════════════════
   DESKTOP BREAKPOINT (1024px+) - KONSISTENTES LAYOUT
   SINGLE SOURCE OF TRUTH für Sidebar-Offset!
   ═══════════════════════════════════════════════════════════ */

@media (min-width: 1024px) {
  /* Sidebar bleibt fixed links */
  .app-sidebar,
  .sidebar {
    position: fixed !important;
    left: 0 !important;
    top: 0 !important;
    width: var(--sidebar-width, 260px) !important;
    height: 100vh !important;
    z-index: 1000 !important;
  }
  
  /* 
   * ROBUSTER ANSATZ: Alle bekannten Content-Wrapper mit Offset
   * Deckt alle Template-Varianten ab
   */
  main,
  main.app-content,
  div.app-content,
  main.main-content,
  div.main-content,
  .page-layout,
  body > div:not(.app-sidebar):not(.sidebar):not(.modal-overlay):not(.toast-container):not(.ds-toast-container) {
    margin-left: var(--sidebar-width, 260px) !important;
  }
  
  /* Konsistente Container-Breite */
  .container,
  .page-container,
  .profile-container {
    max-width: 960px !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }
  
  /* Layout-Shim-Applied Klasse */
  .layout-shim-applied {
    transition: margin-left 0.2s ease;
  }
}
