/**
 * Company Profile Mobile Optimization
 * Mobile-first responsive design för företagsprofil
 * Fokus: Sticky tabs, formoptimering, 1-kolumn grids, touch-friendly
 */

/* ========== MOBILE LAYOUT ========== */

@media (max-width: 768px) {
  /* Container */
  .profile-container {
    padding: 1rem !important;
    padding-top: 80px !important;
    padding-bottom: calc(80px + env(safe-area-inset-bottom)) !important;
    max-width: 100% !important;
  }

  /* ========== HEADER ========== */
  .profile-header {
    padding: 1rem !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 0.75rem !important;
    margin-bottom: 1rem !important;
  }

  .profile-header-left h1 {
    font-size: 1.5rem !important;
  }

  .profile-header-left p {
    font-size: 0.875rem !important;
  }

  .profile-header-actions {
    width: 100%;
    justify-content: flex-start !important;
  }

  /* ========== TAB NAVIGATION - STICKY & SCROLLABLE ========== */
  .profile-tabs {
    position: sticky !important;
    top: 80px !important;
    margin: 0 -1rem 1.5rem -1rem !important;
    padding: 0.5rem 1rem !important;
    overflow-x: auto !important;
    scroll-behavior: smooth !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
    z-index: 100 !important;
    background: white !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05) !important;
  }

  .profile-tabs::-webkit-scrollbar {
    display: none !important;
  }

  .tabs-nav {
    gap: 0.5rem !important;
    min-width: min-content !important;
  }

  .tab-button {
    padding: 0.625rem 1rem !important;
    font-size: 0.875rem !important;
    white-space: nowrap !important;
    flex-shrink: 0 !important;
    min-width: auto !important;
  }

  .tab-button i {
    font-size: 0.938rem !important;
  }

  /* Active tab indicator adjustment */
  .tab-button.active {
    font-weight: 700 !important;
  }

  /* Fixa Galleri-knapp styling */
  .tab-button {
    background: transparent !important;
    border: none !important;
  }

  .tab-button.active {
    background: rgba(14, 165, 233, 0.1) !important;
    color: #0ea5e9 !important;
  }

  /* Ta bort eventuell vit bakgrund på ikoner */
  .tab-button i {
    background: none !important;
    color: inherit !important;
  }

  /* ========== TAB CONTENT ========== */
  .tab-content {
    padding: 0 !important;
  }

  /* ========== PROFILE CARDS ========== */
  .profile-card {
    padding: 1rem !important;
    margin-bottom: 1rem !important;
    border-radius: 1rem !important;
  }

  .profile-card-header {
    margin-bottom: 1rem !important;
  }

  .profile-card-title {
    font-size: 1.125rem !important;
  }

  /* ========== ÖVERSIKT TAB ========== */

  /* Profile Hero */
  .profile-hero {
    padding: 1.5rem 1rem !important;
  }

  .hero-company {
    flex-direction: column !important;
    text-align: center !important;
    gap: 1rem !important;
  }

  .company-logo-wrapper {
    align-items: center !important;
    width: 100%;
    max-width: 8rem;
    margin-left: auto;
    margin-right: auto;
  }

  .upload-logo-btn,
  .company-logo-wrapper .btn {
    min-width: 0;
    max-width: 100%;
  }

  .company-logo {
    width: 80px !important;
    height: 80px !important;
    font-size: 2rem !important;
    margin: 0 auto !important;
  }

  .company-info {
    text-align: center !important;
  }

  .company-info h2 {
    font-size: 1.25rem !important;
  }

  .company-meta {
    font-size: 0.813rem !important;
  }

  .company-badges {
    justify-content: center !important;
    gap: 0.5rem !important;
    flex-wrap: wrap !important;
  }

  /* Stats Grid */
  .stats-grid {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 0.75rem !important;
    margin-top: 1.5rem !important;
  }

  .stat-card {
    padding: 1rem 0.5rem !important;
  }

  .stat-value {
    font-size: 1.5rem !important;
  }

  .stat-label {
    font-size: 0.75rem !important;
  }

  /* Quick Actions */
  .quick-actions {
    grid-template-columns: 1fr !important;
    gap: 0.75rem !important;
    margin-top: 1.5rem !important;
  }

  .action-button {
    padding: 1rem !important;
    text-align: left !important;
    min-height: 4.5rem !important;
  }

  .action-button i:first-of-type {
    font-size: 1.5rem !important;
  }

  /* Completeness Card */
  .progress-ring-container {
    margin: 0 auto !important;
    align-items: center !important;
  }

  .profile-card > div[style*="grid-template-columns: 200px 1fr"] {
    display: flex !important;
    flex-direction: column !important;
    gap: 1.5rem !important;
    align-items: center !important;
    text-align: center !important;
  }

  .progress-ring {
    width: 160px !important;
    height: 160px !important;
    margin: 0 auto !important;
  }

  .progress-ring svg {
    width: 160px !important;
    height: 160px !important;
    transform: rotate(-90deg) !important;
    transform-origin: 50% 50% !important;
  }

  .progress-ring-text {
    width: auto !important;
    height: auto !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
  }

  .progress-ring-percentage {
    font-size: 2.25rem !important;
  }

  .progress-ring-label {
    font-size: 0.85rem !important;
  }

  /* ========== FORM OPTIMIZATIONS ========== */

  /* Grid-2 kolumner -> 1 kolumn */
  .grid-2 {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }

  /* Form groups */
  .form-group {
    margin-bottom: 1rem !important;
  }

  .form-label {
    font-size: 0.938rem !important;
    margin-bottom: 0.5rem !important;
  }

  /* Form inputs - Prevent iOS zoom */
  .form-input,
  .form-textarea,
  .form-select,
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="url"],
  textarea,
  select {
    font-size: 16px !important; /* VIKTIGT: Förhindra iOS zoom */
    padding: 0.75rem !important;
    border-radius: 0.5rem !important;
    width: 100% !important;
  }

  .form-textarea {
    min-height: 120px !important;
  }

  .form-help {
    font-size: 0.813rem !important;
  }

  /* Character counter */
  #charCount,
  #charRecommendation {
    font-size: 0.813rem !important;
  }

  /* AI Improve button */
  #aiImproveBtn {
    padding: 0.5rem 0.875rem !important;
    font-size: 0.813rem !important;
  }

  /* Save buttons */
  .btn {
    padding: 0.875rem 1.5rem !important;
    font-size: 1rem !important;
    width: 100% !important;
    justify-content: center !important;
  }

  .btn-sm {
    padding: 0.625rem 1rem !important;
    font-size: 0.875rem !important;
    width: auto !important;
  }

  .btn i {
    margin-right: 0.5rem !important;
  }

  /* ========== STICKY SAVE BAR ========== */
  .floating-save-bar {
    bottom: calc(70px + env(safe-area-inset-bottom)) !important;
    left: 0 !important;
    right: 0 !important;
    padding: 1rem !important;
    z-index: 99 !important;
  }

  .save-bar-text {
    font-size: 0.875rem !important;
  }

  .save-bar-actions {
    gap: 0.5rem !important;
  }

  .save-bar-actions .btn {
    padding: 0.625rem 1rem !important;
    font-size: 0.875rem !important;
    width: auto !important;
  }

  /* ========== KONTAKT TAB ========== */

  /* Visibility settings */
  label[style*="display: flex; align-items: center"] {
    padding: 1rem !important;
    gap: 0.75rem !important;
  }

  label input[type="checkbox"] {
    width: 20px !important;
    height: 20px !important;
    flex-shrink: 0 !important;
  }

  /* ========== GALLERI TAB ========== */
  .gallery-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.5rem !important;
  }

  .gallery-upload {
    min-height: 150px !important;
    padding: 1rem !important;
  }

  .gallery-upload i {
    font-size: 2rem !important;
  }

  .gallery-upload div {
    font-size: 0.875rem !important;
  }

  .gallery-item {
    aspect-ratio: 1 !important;
  }

  /* ========== VERIFIERING TAB ========== */

  /* Not verified state */
  #notVerifiedState .profile-card {
    padding: 1.5rem 1rem !important;
  }

  #notVerifiedState h2 {
    font-size: 1.5rem !important;
  }

  #notVerifiedState p {
    font-size: 0.938rem !important;
  }

  /* Verification steps - Stack vertically */
  .verification-steps {
    display: flex !important;
    flex-direction: column !important;
    gap: 1rem !important;
  }

  .step-card {
    padding: 1rem !important;
    flex-direction: row !important;
    text-align: left !important;
  }

  .step-number {
    width: 40px !important;
    height: 40px !important;
    font-size: 1.25rem !important;
    flex-shrink: 0 !important;
    margin-right: 1rem !important;
  }

  .step-title {
    font-size: 1rem !important;
  }

  .step-description {
    font-size: 0.813rem !important;
  }

  /* File upload areas */
  .file-upload-area {
    padding: 1.5rem 1rem !important;
    min-height: 120px !important;
  }

  .file-upload-icon {
    font-size: 2rem !important;
  }

  .file-upload-text {
    font-size: 1rem !important;
  }

  .file-upload-hint {
    font-size: 0.813rem !important;
  }

  /* Verification status */
  .verification-status {
    flex-direction: column !important;
    text-align: center !important;
    padding: 2rem 1rem !important;
  }

  .verification-icon {
    margin: 0 auto 1rem !important;
  }

  /* ========== INSTÄLLNINGAR TAB ========== */

  /* Settings sections */
  .form-select {
    width: 100% !important;
    padding: 0.75rem !important;
  }

  /* Checkbox settings */
  label[style*="display: flex"][style*="cursor: pointer"] {
    padding: 1rem !important;
  }

  label[style*="display: flex"] input[type="checkbox"] {
    min-width: 20px !important;
  }

  /* Data security buttons */
  .btn-secondary {
    width: 100% !important;
    margin-bottom: 0.5rem !important;
  }

  /* ========== PREVIEW MODAL ========== */
  .preview-modal {
    padding: 1rem !important;
  }

  .preview-content {
    max-width: 100% !important;
    max-height: 90vh !important;
  }

  .preview-header {
    flex-direction: column !important;
    gap: 1rem !important;
  }

  .preview-header h3 {
    font-size: 1.125rem !important;
  }

  .preview-device-toggle {
    width: 100% !important;
    justify-content: space-between !important;
  }

  .preview-device-toggle .btn {
    flex: 1 !important;
    padding: 0.5rem !important;
    font-size: 0.813rem !important;
  }
}

/* ========== SMALL SCREENS (< 360px) ========== */
@media (max-width: 360px) {
  .profile-container {
    padding: 0.75rem !important;
  }

  .profile-header {
    padding: 0.75rem !important;
  }

  .profile-header-left h1 {
    font-size: 1.25rem !important;
  }

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

  .tab-button {
    padding: 0.5rem 0.875rem !important;
    font-size: 0.813rem !important;
  }

  .profile-card {
    padding: 0.875rem !important;
  }

  .gallery-grid {
    grid-template-columns: 1fr !important;
  }

  .verification-steps {
    gap: 0.75rem !important;
  }

  .step-card {
    flex-direction: column !important;
    text-align: center !important;
  }

  .step-number {
    margin: 0 auto 0.5rem !important;
  }
}

/* ========== LANDSCAPE MODE ========== */
@media (max-width: 768px) and (orientation: landscape) {
  .profile-tabs {
    top: 60px !important;
  }

  .profile-container {
    padding-top: 70px !important;
  }

  .profile-hero {
    padding: 1rem !important;
  }

  .company-logo {
    width: 60px !important;
    height: 60px !important;
  }

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

  .progress-ring {
    width: 120px !important;
    height: 120px !important;
  }

  .form-textarea {
    min-height: 100px !important;
  }
}

/* ========== TOUCH OPTIMIZATIONS ========== */
@media (max-width: 768px) {
  /* Större touch targets (utom översikt-CTA – egen min-height ovan) */
  .tab-button,
  .btn,
  input[type="checkbox"],
  input[type="radio"],
  .file-upload-area {
    min-height: 44px !important;
  }

  /* Tap highlight */
  * {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.05) !important;
  }

  /* Prevent double-tap zoom on buttons */
  button,
  .btn,
  a[role="button"] {
    touch-action: manipulation !important;
  }

  /* Form focus states - larger for mobile */
  input:focus,
  textarea:focus,
  select:focus {
    outline: 3px solid #0ea5e9 !important;
    outline-offset: 2px !important;
  }
}

/* ========== ANIMATIONS ========== */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.tab-content.active {
  animation: fadeInUp 0.3s ease !important;
}

/* Smooth tab scrolling */
.profile-tabs {
  scroll-padding: 0 1rem !important;
}

/* Scroll indicator for tabs */
@media (max-width: 768px) {
  .profile-tabs::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 40px;
    background: linear-gradient(to left, white, transparent);
    pointer-events: none;
  }

  .profile-tabs::-webkit-scrollbar {
    display: none !important;
  }
}

/* ========== ACCESSIBILITY ========== */
@media (max-width: 768px) {
  /* Skip to content */
  .skip-to-content {
    position: absolute;
    top: -100px;
    left: 0;
    background: #0f172a;
    color: white;
    padding: 1rem;
    z-index: 9999;
    text-decoration: none;
  }

  .skip-to-content:focus {
    top: 0;
  }

  /* Focus visible improvements */
  *:focus-visible {
    outline: 3px solid #0ea5e9 !important;
    outline-offset: 2px !important;
  }

  /* Screen reader only text */
  .sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border-width: 0 !important;
  }
}

/* ========== PRINT MEDIA ========== */
@media print {
  .profile-tabs,
  .floating-save-bar,
  .company-mobile-bottom-nav,
  .btn {
    display: none !important;
  }

  .profile-container {
    padding: 0 !important;
  }

  .tab-content {
    display: block !important;
  }
}
