/**
 * Company Mobile Shared Styles
 * Gemensamma mobila styles och utilities för alla företagssidor
 * Mobile-first approach med fokus på UX och performance
 */

/* ========== CSS VARIABLES - MOBILE SPECIFIC ========== */
:root {
  /* Spacing - Tightare för mobil */
  --spacing-mobile-xs: 0.25rem;   /* 4px */
  --spacing-mobile-sm: 0.5rem;    /* 8px */
  --spacing-mobile-md: 0.75rem;   /* 12px */
  --spacing-mobile-lg: 1rem;      /* 16px */
  --spacing-mobile-xl: 1.5rem;    /* 24px */
  --spacing-mobile-2xl: 2rem;     /* 32px */

  /* Typography - Optimerad för mobil */
  --text-mobile-xs: 0.688rem;     /* 11px */
  --text-mobile-sm: 0.813rem;     /* 13px */
  --text-mobile-base: 0.938rem;   /* 15px */
  --text-mobile-lg: 1rem;         /* 16px - MIN för att undvika iOS zoom */
  --text-mobile-xl: 1.125rem;     /* 18px */
  --text-mobile-2xl: 1.25rem;     /* 20px */
  --text-mobile-3xl: 1.5rem;      /* 24px */

  /* Touch targets */
  --touch-target-min: 44px;       /* Apple HIG minimum */
  --touch-target-comfortable: 48px; /* Material Design recommendation */

  /* Z-index layers */
  --z-mobile-nav: 1000;
  --z-mobile-modal: 1001;
  --z-mobile-toast: 1002;
  --z-mobile-max: 9999;

  /* Safe areas (iPhone notch) */
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
  --safe-left: env(safe-area-inset-left);
  --safe-right: env(safe-area-inset-right);
}

/* ========== GLOBAL MOBILE RESETS ========== */
@media (max-width: 768px) {
  /* Prevent iOS text size adjustment */
  html {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  /* Prevent horizontal scroll */
  html,
  body {
    overflow-x: hidden;
    max-width: 100vw;
  }

  /* Base font size - ALDRIG under 16px för att undvika iOS zoom */
  body {
    font-size: 16px !important;
    line-height: 1.5;
  }

  /* Remove margins and padding from body */
  body {
    margin: 0 !important;
    padding: 0 !important;
  }
}

/* ========== UTILITY CLASSES ========== */

/* Display */
@media (max-width: 768px) {
  .mobile-hidden { display: none !important; }
  .mobile-block { display: block !important; }
  .mobile-flex { display: flex !important; }
  .mobile-grid { display: grid !important; }
  .mobile-inline { display: inline !important; }
  .mobile-inline-block { display: inline-block !important; }
}

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

/* Spacing */
@media (max-width: 768px) {
  .m-mobile-0 { margin: 0 !important; }
  .m-mobile-1 { margin: var(--spacing-mobile-xs) !important; }
  .m-mobile-2 { margin: var(--spacing-mobile-sm) !important; }
  .m-mobile-3 { margin: var(--spacing-mobile-md) !important; }
  .m-mobile-4 { margin: var(--spacing-mobile-lg) !important; }

  .p-mobile-0 { padding: 0 !important; }
  .p-mobile-1 { padding: var(--spacing-mobile-xs) !important; }
  .p-mobile-2 { padding: var(--spacing-mobile-sm) !important; }
  .p-mobile-3 { padding: var(--spacing-mobile-md) !important; }
  .p-mobile-4 { padding: var(--spacing-mobile-lg) !important; }

  .mt-mobile-auto { margin-top: auto !important; }
  .mb-mobile-auto { margin-bottom: auto !important; }
}

/* Typography */
@media (max-width: 768px) {
  .text-mobile-xs { font-size: var(--text-mobile-xs) !important; }
  .text-mobile-sm { font-size: var(--text-mobile-sm) !important; }
  .text-mobile-base { font-size: var(--text-mobile-base) !important; }
  .text-mobile-lg { font-size: var(--text-mobile-lg) !important; }
  .text-mobile-xl { font-size: var(--text-mobile-xl) !important; }
  .text-mobile-2xl { font-size: var(--text-mobile-2xl) !important; }
  .text-mobile-3xl { font-size: var(--text-mobile-3xl) !important; }

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

  .mobile-truncate {
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
  }

  .mobile-line-clamp-2 {
    display: -webkit-box !important;
    -webkit-line-clamp: 2 !important;
    -webkit-box-orient: vertical !important;
    overflow: hidden !important;
  }

  .mobile-line-clamp-3 {
    display: -webkit-box !important;
    -webkit-line-clamp: 3 !important;
    -webkit-box-orient: vertical !important;
    overflow: hidden !important;
  }
}

/* Layout */
@media (max-width: 768px) {
  .mobile-full-width { width: 100% !important; }
  .mobile-full-height { height: 100% !important; }
  .mobile-col-1 { grid-template-columns: 1fr !important; }
  .mobile-col-2 { grid-template-columns: repeat(2, 1fr) !important; }
  .mobile-col-3 { grid-template-columns: repeat(3, 1fr) !important; }
  .mobile-stack { flex-direction: column !important; }
  .mobile-center { 
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }
}

/* ========== TOUCH OPTIMIZATIONS ========== */
@media (max-width: 768px) {
  /* Minimum touch target size */
  .touch-target {
    min-height: var(--touch-target-min) !important;
    min-width: var(--touch-target-min) !important;
  }

  .touch-target-lg {
    min-height: var(--touch-target-comfortable) !important;
    min-width: var(--touch-target-comfortable) !important;
  }

  /* Tap highlighting */
  .tap-highlight-none {
    -webkit-tap-highlight-color: transparent !important;
  }

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

  /* Touch action */
  .touch-manipulation {
    touch-action: manipulation !important;
  }

  .touch-none {
    touch-action: none !important;
  }

  /* Active states */
  .active-scale:active {
    transform: scale(0.95) !important;
    transition: transform 0.1s ease !important;
  }

  .active-opacity:active {
    opacity: 0.7 !important;
    transition: opacity 0.1s ease !important;
  }
}

/* ========== SCROLLING ========== */
@media (max-width: 768px) {
  /* Smooth momentum scrolling */
  .scroll-smooth {
    -webkit-overflow-scrolling: touch !important;
    scroll-behavior: smooth !important;
  }

  /* Hide scrollbars */
  .scrollbar-hidden {
    scrollbar-width: none !important;
    -ms-overflow-style: none !important;
  }

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

  /* Scroll snap */
  .scroll-snap-x {
    scroll-snap-type: x mandatory !important;
    scroll-snap-stop: always !important;
  }

  .scroll-snap-y {
    scroll-snap-type: y mandatory !important;
  }

  .scroll-snap-start {
    scroll-snap-align: start !important;
  }

  .scroll-snap-center {
    scroll-snap-align: center !important;
  }
}

/* ========== SAFE AREAS (iPhone Notch) ========== */
@media (max-width: 768px) {
  .safe-top {
    padding-top: var(--safe-top) !important;
  }

  .safe-bottom {
    padding-bottom: var(--safe-bottom) !important;
  }

  .safe-left {
    padding-left: var(--safe-left) !important;
  }

  .safe-right {
    padding-right: var(--safe-right) !important;
  }

  .safe-all {
    padding-top: var(--safe-top) !important;
    padding-bottom: var(--safe-bottom) !important;
    padding-left: var(--safe-left) !important;
    padding-right: var(--safe-right) !important;
  }
}

/* ========== STICKY ELEMENTS ========== */
@media (max-width: 768px) {
  .sticky-top {
    position: sticky !important;
    top: 0 !important;
    z-index: 100 !important;
  }

  .sticky-top-nav {
    position: sticky !important;
    top: 80px !important;
    z-index: 99 !important;
  }

  .sticky-bottom {
    position: sticky !important;
    bottom: 0 !important;
    z-index: 100 !important;
  }

  .sticky-bottom-nav {
    position: sticky !important;
    bottom: calc(70px + var(--safe-bottom)) !important;
    z-index: 99 !important;
  }
}

/* ========== CARDS & CONTAINERS ========== */
@media (max-width: 768px) {
  .mobile-card {
    background: white;
    border-radius: 1rem;
    padding: 1rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    margin-bottom: 1rem;
  }

  .mobile-card-compact {
    background: white;
    border-radius: 0.75rem;
    padding: 0.75rem;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
    margin-bottom: 0.75rem;
  }
}

/* ========== BUTTONS ========== */
@media (max-width: 768px) {
  .mobile-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 0.75rem;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: var(--touch-target-min);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  .mobile-btn:active {
    transform: scale(0.98);
  }

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

  .mobile-btn-sm {
    padding: 0.625rem 1rem !important;
    font-size: 0.875rem !important;
    min-height: 40px !important;
  }

  .mobile-btn-lg {
    padding: 1rem 2rem !important;
    font-size: 1.125rem !important;
    min-height: 52px !important;
  }
}

/* ========== FORMS ========== */
@media (max-width: 768px) {
  /* Prevent iOS zoom on input focus */
  input,
  textarea,
  select {
    font-size: 16px !important; /* CRITICAL: ALDRIG under 16px */
  }

  .mobile-input {
    width: 100%;
    padding: 0.875rem 1rem;
    font-size: 16px !important;
    border: 2px solid #e2e8f0;
    border-radius: 0.75rem;
    background: white;
    transition: border-color 0.2s ease;
  }

  .mobile-input:focus {
    outline: none;
    border-color: var(--company-cta, #0f172a);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
  }

  .mobile-textarea {
    width: 100%;
    padding: 0.875rem 1rem;
    font-size: 16px !important;
    min-height: 120px;
    resize: vertical;
    border: 2px solid #e2e8f0;
    border-radius: 0.75rem;
    font-family: inherit;
    line-height: 1.5;
  }

  .mobile-select {
    width: 100%;
    padding: 0.875rem 1rem;
    font-size: 16px !important;
    border: 2px solid #e2e8f0;
    border-radius: 0.75rem;
    background: white;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    padding-right: 3rem;
  }
}

/* ========== MODALS & OVERLAYS ========== */
@media (max-width: 768px) {
  .mobile-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: var(--z-mobile-modal);
    display: flex;
    align-items: flex-end;
    padding: 0;
  }

  .mobile-modal {
    background: white;
    border-radius: 24px 24px 0 0;
    padding: 1.5rem;
    padding-bottom: calc(1.5rem + var(--safe-bottom));
    max-height: 90vh;
    overflow-y: auto;
    width: 100%;
    animation: slideUpModal 0.3s ease;
  }

  @keyframes slideUpModal {
    from {
      transform: translateY(100%);
      opacity: 0;
    }
    to {
      transform: translateY(0);
      opacity: 1;
    }
  }

  .mobile-modal-handle {
    width: 40px;
    height: 4px;
    background: #cbd5e1;
    border-radius: 2px;
    margin: 0 auto 1rem;
  }

  .mobile-modal-full {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: white;
    z-index: var(--z-mobile-modal);
    padding: 1rem;
    padding-top: calc(1rem + var(--safe-top));
    padding-bottom: calc(1rem + var(--safe-bottom));
    overflow-y: auto;
  }
}

/* ========== ANIMATIONS ========== */
@media (max-width: 768px) {
  .fade-in-up {
    animation: fadeInUp 0.3s ease !important;
  }

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

  .fade-in {
    animation: fadeIn 0.3s ease !important;
  }

  @keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
  }

  .slide-in-left {
    animation: slideInLeft 0.3s ease !important;
  }

  @keyframes slideInLeft {
    from {
      opacity: 0;
      transform: translateX(-20px);
    }
    to {
      opacity: 1;
      transform: translateX(0);
    }
  }

  .scale-in {
    animation: scaleIn 0.3s ease !important;
  }

  @keyframes scaleIn {
    from {
      opacity: 0;
      transform: scale(0.9);
    }
    to {
      opacity: 1;
      transform: scale(1);
    }
  }
}

/* ========== LOADING STATES ========== */
@media (max-width: 768px) {
  .mobile-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    color: #64748b;
  }

  .mobile-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #f1f5f9;
    border-top-color: var(--company-cta, #0f172a);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
  }

  @keyframes spin {
    to { transform: rotate(360deg); }
  }

  .mobile-skeleton {
    background: linear-gradient(
      90deg,
      #f0f0f0 25%,
      #e0e0e0 50%,
      #f0f0f0 75%
    );
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border-radius: 0.5rem;
  }

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

/* ========== ACCESSIBILITY ========== */
@media (max-width: 768px) {
  /* Focus states */
  *:focus-visible {
    outline: 3px solid var(--company-cta, #0f172a) !important;
    outline-offset: 2px !important;
  }

  /* Screen reader only */
  .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;
  }

  /* Skip to content */
  .skip-link {
    position: absolute;
    top: -100px;
    left: 0;
    background: #0f172a;
    color: white;
    padding: 1rem;
    z-index: var(--z-mobile-max);
    text-decoration: none;
    font-weight: 600;
  }

  .skip-link:focus {
    top: 0;
  }
}

/* ========== PERFORMANCE OPTIMIZATIONS ========== */
@media (max-width: 768px) {
  /* Hardware acceleration */
  .gpu-accelerate {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
  }

  /* Reduce motion for users who prefer it */
  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
      scroll-behavior: auto !important;
    }
  }
}

/* ========== DARK MODE SUPPORT ========== */
@media (prefers-color-scheme: dark) and (max-width: 768px) {
  .mobile-card,
  .mobile-card-compact {
    background: #1e293b;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  }

  .mobile-input,
  .mobile-textarea,
  .mobile-select {
    background: #1e293b;
    border-color: #334155;
    color: white;
  }

  .mobile-modal {
    background: #1e293b;
  }

  .mobile-modal-full {
    background: #1e293b;
  }
}

/* ========== PRINT MEDIA ========== */
@media print {
  .mobile-hidden-print,
  .company-mobile-bottom-nav,
  .company-standalone-fab,
  .mobile-modal,
  .mobile-overlay {
    display: none !important;
  }
}

/* Dark mode — company mobile shared (klassbaserat, inte prefers-color-scheme) */
body.dark-mode .mobile-card,
body.dark-mode .mobile-card-compact {
  background: #1e293b;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  color: #f8fafc;
}

body.dark-mode .mobile-input,
body.dark-mode .mobile-textarea,
body.dark-mode .mobile-select {
  background: #0f172a;
  border-color: #334155;
  color: #f8fafc;
}

body.dark-mode .mobile-modal,
body.dark-mode .mobile-modal-full {
  background: #1e293b;
  color: #f8fafc;
}

body.dark-mode .mobile-overlay {
  background: rgba(0, 0, 0, 0.65);
}

/* Anställd botten-nav (Mina jobb | Min tid) */
.emp-bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  background: #fff;
  border-top: 1px solid #e2e8f0;
  padding: 0.35rem 0 calc(0.35rem + env(safe-area-inset-bottom));
  box-shadow: 0 -4px 16px rgba(22, 35, 30, 0.06);
}
.emp-bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.45rem 0.25rem;
  text-decoration: none;
  color: #5c6b64;
  font-size: 0.72rem;
  font-weight: 600;
  min-height: 52px;
  justify-content: center;
}
.emp-bottom-nav a.is-active {
  color: #2f5d50;
}
.emp-bottom-nav a i,
.emp-bottom-nav a svg {
  width: 22px;
  height: 22px;
}
body.has-emp-bottom-nav {
  padding-bottom: calc(4.25rem + env(safe-area-inset-bottom));
}
body.dark-mode .emp-bottom-nav {
  background: #1e293b;
  border-top-color: #334155;
}
body.dark-mode .emp-bottom-nav a {
  color: #94a3b8;
}
body.dark-mode .emp-bottom-nav a.is-active {
  color: #86efac;
}
@media (min-width: 768px) {
  .emp-bottom-nav {
    display: none;
  }
  body.has-emp-bottom-nav {
    padding-bottom: 0;
  }
}
