/* =============================================================================
   MOBILE.CSS - Responsiv mobilanpassning för EsyTech
   =============================================================================
   
   STRUKTUR:
   1. CSS Custom Properties (rad ~8)
   2. PWA Standalone Mode (rad ~17)
   3. Dölj Scrollbar (rad ~64)
   4. Global Mobile Detection (rad ~93)
   5. Tabell -> Kort-layout (rad ~157)
   6. Tabell-header & Filter (rad ~299)
   7. Formulär på mobil (rad ~460)
   8. Header & Sidpanel (rad ~720)
   9. Stat-kort (rad ~769)
   10. Modaler (rad ~820)
   11. Kalender (rad ~840)
   12. Utility Classes (rad ~870)
   13. Touch-förbättringar (rad ~900)
   14. Edit-sidor (rad ~970)
   15. Print (rad ~1165)
   16. Filter-bar & Table Controls (rad ~1175)
   17. Login/Auth (rad ~1620)
   
   NOTERA:
   - filter-toggle-btn: 36x36px (definieras i filter-bar sektionen)
   - icon-btn: 36x36px
   - footer-knappar (pg-btn, search-toggle): 32x32px
   
   ============================================================================= */

/* =============================================================================
   CSS Custom Properties för mobil
   ============================================================================= */
:root {
  --mobile-breakpoint: 768px;
  --mobile-padding: 12px;
  --mobile-gap: 8px;
}

/* =============================================================================
   PWA STANDALONE MODE - Safe Area för notch/statusbar
   ============================================================================= */
@media all and (display-mode: standalone) {
  /* I standalone-läge - header börjar vid toppen (ingen webbläsar-UI) */
  .header {
    top: 0 !important;
    padding-top: env(safe-area-inset-top, 0) !important;
    height: calc(56px + env(safe-area-inset-top, 0)) !important;
  }
  
  /* Justera body/main-content för headern */
  body {
    padding-top: 0 !important;
  }
  
  .main-content {
    margin-top: calc(56px + env(safe-area-inset-top, 0)) !important;
  }
  
  /* Sidebar direkt under header */
  .sidebar {
    top: calc(56px + env(safe-area-inset-top, 0)) !important;
    height: calc(100vh - 56px - env(safe-area-inset-top, 0)) !important;
  }
}

/* Fallback för äldre enheter utan env() stöd */
@media all and (display-mode: standalone) {
  @supports not (top: env(safe-area-inset-top)) {
    .header {
      top: 0 !important;
      height: 56px !important;
    }
    body {
      padding-top: 0 !important;
    }
    .main-content {
      margin-top: 56px !important;
    }
    .sidebar {
      top: 56px !important;
      height: calc(100vh - 56px) !important;
    }
  }
}

/* =============================================================================
   DÖLJ SCROLLBAR PÅ MOBIL
   ============================================================================= */
@media (max-width: 768px) {
  /* Dölj scrollbar men behåll scroll-funktionalitet */
  body,
  .main-content,
  .tbl-scroller,
  .card-body {
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
  }
  
  body::-webkit-scrollbar,
  .main-content::-webkit-scrollbar,
  .tbl-scroller::-webkit-scrollbar,
  .card-body::-webkit-scrollbar {
    display: none; /* Chrome/Safari/Opera */
    width: 0;
    height: 0;
  }
  
  /* Förhindra horisontell scroll */
  html, body {
    overflow-x: hidden;
    max-width: 100vw;
  }
}

/* =============================================================================
   GLOBAL MOBILE DETECTION
   ============================================================================= */
@media (max-width: 768px) {
  /* Flagga för JS-detektering */
  body::before {
    content: 'mobile';
    display: none;
  }
  
  /* Grundläggande mobilanpassningar */
  body {
    font-size: 15px;
    line-height: 1.5;
  }
  
  /* FULL BREDD - behåll bakgrundsfärg men ta bort kanter */
  .main-content {
    padding: 0 !important;
    margin: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
  }
  
  /* Cards - full bredd med inre padding */
  .card {
    margin: 0 0 16px 0 !important;
    padding: 0 12px !important;
    width: 100% !important;
    border-radius: 0 !important;
    border-left: none !important;
    border-right: none !important;
    box-shadow: none !important;
  }
  
  .card-body {
    padding: 16px 0 !important;
  }
  
  /* Form-sections med padding */
  .form-section,
  .form-row,
  .edit-tabs,
  .stat-cards {
    padding-left: 12px !important;
    padding-right: 12px !important;
  }

  /* Card header */
  .card-header {
    padding: 14px 16px !important;
    font-size: 16px;
  }
  
  /* Section titles */
  .form-section-title {
    font-size: 15px !important;
    font-weight: 600 !important;
    margin-bottom: 16px !important;
  }
}

/* =============================================================================
   TABELL -> KORT-LAYOUT PÅ MOBIL
   ============================================================================= */
@media (max-width: 768px) {
  /* Göm tabellheader på mobil */
  .tbl-table thead {
    display: none;
  }
  
  /* Varje rad blir ett kort - modern design */
  .tbl-table tbody tr {
    display: block;
    background: linear-gradient(145deg, #ffffff 0%, #f8fafc 100%);
    border: none;
    border-radius: 16px;
    margin-bottom: 16px;
    padding: 20px;
    box-shadow: 
      0 1px 3px rgba(0,0,0,0.04),
      0 4px 12px rgba(0,0,0,0.06),
      inset 0 1px 0 rgba(255,255,255,0.8);
    position: relative;
    border-left: 4px solid #3b82f6;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
  }
  
  .tbl-table tbody tr:hover {
    background: linear-gradient(145deg, #ffffff 0%, #f1f5f9 100%);
  }
  
  .tbl-table tbody tr:active {
    transform: scale(0.99);
    box-shadow: 
      0 1px 2px rgba(0,0,0,0.04),
      0 2px 6px rgba(0,0,0,0.06);
  }
  
  /* Varje cell blir en rad - VERTIKAL layout (label ovanför värde) */
  .tbl-table tbody td {
    display: block !important;
    padding: 8px 0 !important;
    border-bottom: 1px solid #f3f4f6;
    font-size: 15px;
    line-height: 1.4;
    text-align: left !important;
    width: 100% !important;
  }
  
  .tbl-table tbody td:last-child {
    border-bottom: none;
  }
  
  /* Label som rubrik ovanför värdet */
  .tbl-table tbody td::before {
    content: attr(data-label);
    display: block !important;
    font-weight: 600;
    color: #6b7280;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
  }
  
  /* Göm tom label */
  .tbl-table tbody td[data-label=""]::before,
  .tbl-table tbody td.td-actions::before {
    display: none !important;
  }
  
  /* Actions - snyggt footer-fält över hela kortet */
  .tbl-table tbody td.td-actions {
    display: flex !important;
    justify-content: flex-end !important;
    align-items: center !important;
    gap: 12px !important;
    border-top: 1px solid #e5e7eb;
    border-bottom: none !important;
    background: linear-gradient(180deg, #f1f5f9 0%, #e2e8f0 100%);
    margin: 16px -20px -20px -20px;
    padding: 14px 20px !important;
    border-radius: 0 0 16px 16px;
    width: calc(100% + 40px) !important;
    box-sizing: border-box !important;
  }
  
  /* Checkbox-cell - flytta till actions-raden (td som innehåller row-select-checkbox) */
  .tbl-table tbody td:has(.row-select-checkbox) {
    position: absolute !important;
    bottom: 14px !important;
    left: 20px !important;
    top: auto !important;
    right: auto !important;
    padding: 0 !important;
    border: none !important;
    background: transparent !important;
    width: auto !important;
    z-index: 10 !important;
  }
  
  .tbl-table tbody td:has(.row-select-checkbox)::before {
    display: none !important;
  }
  
  /* Alternativ för äldre browsers utan :has() */
  .tbl-table tbody td.td-select {
    position: absolute !important;
    bottom: 14px !important;
    left: 20px !important;
    top: auto !important;
    right: auto !important;
    padding: 0 !important;
    border: none !important;
    background: transparent !important;
    width: auto !important;
    z-index: 10 !important;
  }
  
  .tbl-table tbody td.td-select::before {
    display: none !important;
  }
  
  /* ID-fältet - visa som badge uppe till höger */
  .tbl-table tbody td[data-label="ID"] {
    position: absolute !important;
    top: 12px;
    right: 12px;
    padding: 4px 10px !important;
    background: #f3f4f6;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    color: #6b7280;
    border: none !important;
    width: auto !important;
  }
  
  .tbl-table tbody td[data-label="ID"]::before {
    display: inline !important;
    content: '#';
    margin-right: 2px;
    margin-bottom: 0;
  }
  
  /* Scroller behöver inte overflow på mobil */
  .tbl-scroller {
    overflow: visible !important;
    min-height: auto !important;
    max-height: none !important;
    height: auto !important;
    padding: 0 !important;
  }
  
  /* Tabell tar full bredd */
  .tbl-table {
    display: block;
  }
  
  .tbl-table tbody {
    display: block;
  }
  
  /* Ta bort onödig padding/margin i wrap men behåll inre padding */
  .tbl-wrap {
    padding: 0 12px !important;
    margin: 0 !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }
}

/* =============================================================================
   TABELL-HEADER & FILTER PÅ MOBIL
   ============================================================================= */
@media (max-width: 768px) {
  .tbl-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding-bottom: 12px;
  }
  
  .tbl-header strong {
    font-size: 18px;
  }
  
  .tbl-filters {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  
  .tbl-filter-right {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 12px;
  }
  
  /* Sökfält - normalt stort, inte överdrivet */
  .tbl-search {
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
    height: 44px !important;
    min-height: 44px !important;
    max-height: 44px !important;
    padding: 0 14px !important;
    font-size: 16px !important;
    border-radius: 10px !important;
    border: 1.5px solid #d1d5db !important;
    order: 1;
    box-sizing: border-box !important;
  }
  
  .tbl-search:focus {
    border-color: #3b82f6 !important;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15) !important;
    outline: none !important;
  }
  
  /* Pagination - egen rad, VÄNSTERJUSTERAD */
  .tbl-pagination {
    display: flex;
    justify-content: flex-start !important;
    gap: 6px;
    order: 2;
    width: 100%;
  }
  
  /* ALLA knappar i pagination - samma storlek */
  .tbl-pagination .pg-btn,
  .tbl-pagination button {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
    max-width: 44px !important;
    max-height: 44px !important;
    padding: 0 !important;
    border-radius: 10px !important;
    font-size: 14px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex-shrink: 0 !important;
  }
  
  .pg-info {
    display: none !important;
  }
  
  .pg-rows {
    width: 70px !important;
    height: 44px !important;
    min-height: 44px !important;
    font-size: 15px !important;
    border-radius: 10px !important;
    padding: 0 10px !important;
  }
  
  /* Action-knappar (Ny, Export, Print) - VÄNSTERJUSTERADE */
  .tbl-btns {
    display: flex !important;
    justify-content: flex-start !important;
    gap: 10px !important;
    order: 3;
    width: 100%;
  }
  
  /* ALLA icon-knappar - samma storlek (36x36px) */
  .tbl-btns .icon-btn,
  .icon-btn {
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    min-height: 36px !important;
    max-width: 36px !important;
    max-height: 36px !important;
    padding: 0 !important;
    border-radius: 8px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex-shrink: 0 !important;
  }
  
  /* filter-toggle-btn storlek sätts via inline style i app.js */
  
  .icon-btn i {
    font-size: 14px !important;
  }
  
  /* Extra filter (dropdown etc) */
  .tbl-extra-filter {
    width: 100%;
    order: 0;
  }
  
  .tbl-extra-filter select {
    width: 100% !important;
    height: 48px !important;
    min-height: 48px !important;
    font-size: 16px !important;
    padding: 12px 44px 12px 14px !important;
    border-radius: 10px !important;
    border: 1.5px solid #d1d5db !important;
  }
  
  /* Filter chips */
  .tbl-chip {
    min-height: 44px;
    padding: 10px 16px;
    font-size: 14px;
    border-radius: 20px;
  }
  
  /* Footer med "Visar X av Y" */
  .tbl-footer,
  .tbl-summary {
    text-align: center;
    padding: 12px 0;
    font-size: 14px;
    color: #6b7280;
  }
}

/* =============================================================================
   FORMULÄR PÅ MOBIL
   ============================================================================= */
@media (max-width: 768px) {
  /* Form sections blir vertikala */
  .form-sections {
    display: flex !important;
    flex-direction: column !important;
    gap: 16px !important;
  }
  
  .form-section {
    width: 100% !important;
    min-width: 0 !important;
  }
  
  /* Form rows blir vertikala */
  .form-row {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
  }
  
  .form-row .form-group,
  .form-group,
  .form-section .form-group {
    width: 100% !important;
    max-width: 100% !important;
    flex: 1 1 100% !important;
  }
  
  /* =========================================================================
     INPUTFÄLT - Större och tydligare
     ========================================================================= */
  .form-input,
  .form-select,
  .form-textarea,
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="number"],
  input[type="password"],
  input[type="date"],
  input[type="time"],
  input[type="datetime-local"],
  input[type="search"],
  input[type="url"],
  select,
  textarea {
    width: 100% !important;
    max-width: 100% !important;
    min-height: 48px !important;
    height: auto !important;
    padding: 12px 14px !important;
    font-size: 16px !important; /* Förhindrar zoom på iOS */
    line-height: 1.4 !important;
    border-radius: 10px !important;
    border: 1.5px solid #d1d5db !important;
    background-color: #fff !important;
    color: #1f2937 !important;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05) !important;
    box-sizing: border-box !important;
    -webkit-appearance: none;
    appearance: none;
  }
  
  /* Fokusläge - tydlig blå ram */
  .form-input:focus,
  .form-select:focus,
  .form-textarea:focus,
  input:focus,
  select:focus,
  textarea:focus {
    outline: none !important;
    border-color: #3b82f6 !important;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15) !important;
  }
  
  /* Placeholder - tydligare */
  input::placeholder,
  textarea::placeholder {
    color: #F8F9FA !important;
    opacity: 1 !important;
  }
  
  /* Datumfält - fixa iOS styling */
  input[type="date"],
  input[type="time"],
  input[type="datetime-local"] {
    min-height: 48px !important;
    padding-right: 12px !important;
  }
  
  /* Select-pilar */
  select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%236b7280'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 12px center !important;
    background-size: 20px !important;
    padding-right: 44px !important;
  }
  
  /* Textarea */
  textarea {
    min-height: 100px !important;
    resize: vertical;
  }
  
  /* Labels */
  .form-label,
  label {
    display: block;
    font-size: 14px !important;
    font-weight: 600 !important;
    color: #374151 !important;
    margin-bottom: 6px !important;
  }
  
  /* Form group spacing */
  .form-group {
    margin-bottom: 16px !important;
  }

  /* =========================================================================
     KNAPPAR - Större och mer touch-vänliga
     ========================================================================= */
  .btn,
  button[type="submit"],
  button[type="button"]:not(.icon-btn):not(.filter-toggle-btn):not(.pg-btn):not(.search-toggle-btn):not(.btn-icon):not(.btn-nav),
  input[type="submit"],
  input[type="button"] {
    min-height: 48px !important;
    padding: 12px 20px !important;
    font-size: 15px !important;
    font-weight: 600 !important;
    border-radius: 10px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }
  
  /* Små ikonknappar - behåll storlek */
  .icon-btn,
  .filter-toggle-btn,
  .pg-btn,
  .search-toggle-btn,
  .btn-icon,
  .btn-nav {
    min-height: auto !important;
    padding: 0 !important;
  }
  
  /* Primär knapp */
  .btn:not(.secondary):not(.btn-secondary):not(.btn-danger):not(.btn-outline) {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%) !important;
    color: #fff !important;
    border: none !important;
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.25) !important;
  }
  
  .btn:not(.secondary):not(.btn-secondary):not(.btn-danger):not(.btn-outline):active {
    transform: scale(0.98);
    box-shadow: 0 1px 2px rgba(37, 99, 235, 0.2) !important;
  }
  
  /* Sekundär knapp */
  .btn.secondary,
  .btn-secondary {
    background: #f3f4f6 !important;
    color: #374151 !important;
    border: 1.5px solid #d1d5db !important;
  }
  
  .btn.secondary:active,
  .btn-secondary:active {
    background: #e5e7eb !important;
  }
  
  /* Danger knapp */
  .btn-danger,
  .btn.danger {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%) !important;
    color: #fff !important;
    border: none !important;
  }
  
  /* Outline knapp */
  .btn-outline {
    background: transparent !important;
    border: 1.5px solid #3b82f6 !important;
    color: #3b82f6 !important;
  }
  
  /* Knappar i rad */
  .form-actions,
  .btn-group {
    display: flex !important;
    flex-direction: column !important;
    gap: 10px !important;
    margin-top: 20px !important;
  }
  
  .form-actions .btn,
  .btn-group .btn {
    width: 100% !important;
  }
  
  /* Full-width knapp variant */
  .btn-block {
    width: 100% !important;
  }

  /* Icon buttons i grupp - storlek definieras i tbl-btns sektionen ovan */
  .btn-icons {
    display: flex !important;
    gap: 8px !important;
  }

  /* =========================================================================
     CHECKBOXAR & RADIO - Större klickyta
     ========================================================================= */
  input[type="checkbox"],
  input[type="radio"] {
    width: 22px !important;
    height: 22px !important;
    margin-right: 10px !important;
  }
  
  /* Switch/toggle styling */
  .switch {
    width: 48px !important;
    height: 28px !important;
  }
  
  .switch .slider:before {
    width: 22px !important;
    height: 22px !important;
  }
  
  .switch-label {
    min-height: 44px;
    display: flex;
    align-items: center;
    padding: 8px 0;
  }
}

/* =============================================================================
   HEADER & SIDPANEL PÅ MOBIL
   ============================================================================= */
@media (max-width: 768px) {
  /* Header kompakt */
  .header {
    padding: 0.75rem 1rem;
    height: 56px;
    box-shadow: none !important;
    z-index: 1003 !important;
  }
  
  /* Justera main-content för kortare header */
  .main-content {
    margin-top: 56px !important;
  }
  
  .logo {
    font-size: 1.5rem;
  }
  
  .header-org-name {
    display: none;
  }
  
  /* Sidebar som overlay - direkt under header */
  .sidebar {
    position: fixed !important;
    z-index: 1002 !important;
    width: 280px !important;
    max-width: 85vw !important;
    top: 56px !important;
    margin-top: 0 !important;
    border-top: none !important;
    padding-top: 0 !important;
    height: calc(100vh - 56px) !important;
    background: var(--primary-blue) !important;
  }
  
  .nav-menu {
    padding-top: 0 !important;
  }
  
  /* Första menyitem direkt vid toppen */
  .nav-menu .nav-item:first-child {
    margin-top: 0 !important;
  }
  
  .nav-menu .nav-item:first-child .nav-link {
    padding-top: 0.75rem !important;
  }
  
  /* Profilmeny kompakt */
  .user-dropdown {
    min-width: auto;
  }
}

/* =============================================================================
   STAT-KORT PÅ MOBIL
   ============================================================================= */
@media (max-width: 768px) {
  /* Dashboard stats grid */
  .stats-grid,
  .stat-cards,
  div[style*="display:grid"][style*="repeat(4"] {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
    padding: 8px 12px !important;
    margin-bottom: 16px !important;
  }
  
  .stat-card {
    padding: 10px 12px !important;
    min-height: auto !important;
    border-radius: 8px !important;
    gap: 4px !important;
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    align-items: center !important;
  }
  
  /* Stat ikoner - mindre, på samma rad som värde */
  .stat-icon {
    width: 28px !important;
    height: 28px !important;
    font-size: 12px !important;
    margin-bottom: 0 !important;
    margin-right: 8px !important;
    border-radius: 6px !important;
    flex-shrink: 0 !important;
  }
  
  /* Stat värden - på samma rad som ikon */
  .stat-value {
    font-size: 18px !important;
    line-height: 1.1 !important;
    flex: 1 !important;
  }
  
  /* Stat etiketter - på ny rad under */
  .stat-label {
    font-size: 10px !important;
    line-height: 1.2 !important;
    width: 100% !important;
    margin-top: 2px !important;
  }
}

/* =============================================================================
   MODALER PÅ MOBIL
   ============================================================================= */
@media (max-width: 768px) {
  .modal-content,
  [class*="modal"] > div {
    width: 95vw !important;
    max-width: none !important;
    margin: 10px auto !important;
    max-height: 90vh;
    overflow-y: auto;
  }
  
  .modal-header,
  .modal-body,
  .modal-footer {
    padding: 12px !important;
  }
}

/* =============================================================================
   KALENDER PÅ MOBIL
   ============================================================================= */
@media (max-width: 768px) {
  /* FullCalendar mobilanpassning */
  .fc .fc-toolbar {
    flex-direction: column;
    gap: 8px;
  }
  
  .fc .fc-toolbar-chunk {
    display: flex;
    justify-content: center;
  }
  
  .fc .fc-button {
    padding: 6px 10px;
    font-size: 12px;
  }
  
  .fc .fc-daygrid-day-number {
    font-size: 12px;
    padding: 4px;
  }
}

/* =============================================================================
   UTILITY CLASSES FÖR MOBIL
   ============================================================================= */
@media (max-width: 768px) {
  .hide-mobile {
    display: none !important;
  }
}

@media (min-width: 769px) {
  .show-mobile-only {
    display: none !important;
  }
}

/* Flexibel göm/visa */
.mobile-hidden {
  display: none;
}

@media (min-width: 769px) {
  .mobile-hidden {
    display: block;
  }
  
  .desktop-hidden {
    display: none !important;
  }
}

/* =============================================================================
   TOUCH-FÖRBÄTTRINGAR
   ============================================================================= */
@media (max-width: 768px) {
  /* Större klickyta för touch - minst 44px enligt Apple HIG */
  /* OBS: icon-btn och filter-toggle-btn hanteras separat i tbl-btns sektionen */
  .btn,
  a.btn {
    min-height: 44px;
    min-width: 44px;
  }
  
  /* Generella button (ej icon-buttons) */
  button:not(.icon-btn):not(.filter-toggle-btn):not(.pg-btn):not(.search-toggle-btn) {
    min-height: 44px;
  }
  
  /* Undvik hover-effekter på touch */
  @media (hover: none) {
    button:hover,
    .btn:hover,
    a:hover {
      /* Reset hover states on touch devices */
    }
  }
  
  /* Bättre scrolling */
  .tbl-scroller,
  .modal-body,
  .sidebar {
    -webkit-overflow-scrolling: touch;
  }
  
  /* Förhindra dubbeltap-zoom */
  button,
  a,
  input,
  select,
  textarea {
    touch-action: manipulation;
  }
  
  /* Snabbare klick-respons (ta bort 300ms delay) */
  * {
    -webkit-tap-highlight-color: transparent;
  }
  
  /* Aktiv-state för feedback */
  .btn:active,
  button:active,
  .icon-btn:active {
    transform: scale(0.97);
    transition: transform 0.1s ease;
  }
  
  /* Länkade kort - hela kortet klickbart */
  .tbl-table tbody tr[data-id] {
    cursor: pointer;
  }
  
  .tbl-table tbody tr[data-id]:active {
    transform: scale(0.99);
    transition: transform 0.1s ease;
  }
}

/* =============================================================================
   EDIT-SIDOR PÅ MOBIL (projekt, kunder, fakturor, etc.)
   ============================================================================= */
@media (max-width: 768px) {
  /* Header med titel och knappar - vertikal layout */
  div[style*="display:flex"][style*="justify-content:space-between"][style*="margin-bottom"] {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 12px !important;
  }
  
  div[style*="display:flex"][style*="justify-content:space-between"] > div:last-child {
    width: 100% !important;
    justify-content: flex-end !important;
  }
  
  /* Stat-cards grid - 2 kolumner istället för 4 */
  div[style*="grid-template-columns:repeat(4"] {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px !important;
  }
  
  .stat-card {
    padding: 14px 12px !important;
    border-radius: 12px !important;
  }
  
  .stat-value {
    font-size: 22px !important;
  }
  
  .stat-label {
    font-size: 11px !important;
  }
  
  /* Tabs - horisontell scroll */
  .project-tabs,
  .tabs,
  .tab-navigation,
  [class*="-tabs"] {
    display: flex !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
    gap: 0 !important;
    padding-bottom: 2px !important;
    margin: 0 -16px 16px -16px !important;
    padding-left: 16px !important;
    padding-right: 16px !important;
  }
  
  .project-tabs::-webkit-scrollbar,
  .tabs::-webkit-scrollbar,
  .tab-navigation::-webkit-scrollbar,
  [class*="-tabs"]::-webkit-scrollbar {
    display: none !important;
  }
  
  .project-tab-btn,
  .tab-btn,
  [class*="-tab-btn"] {
    flex-shrink: 0 !important;
    padding: 10px 16px !important;
    font-size: 13px !important;
    white-space: nowrap !important;
  }
  
  /* Form sections - vertikal */
  .form-sections {
    display: flex !important;
    flex-direction: column !important;
    gap: 24px !important;
  }
  
  .form-section {
    width: 100% !important;
    padding: 0 !important;
  }
  
  .form-section-title {
    font-size: 14px !important;
    margin-bottom: 16px !important;
  }
  
  /* Form rows - alltid vertikal på mobil */
  .form-row {
    display: flex !important;
    flex-direction: column !important;
    gap: 16px !important;
  }
  
  .form-row > .form-group {
    width: 100% !important;
    flex: none !important;
  }
  
  /* Grid-baserade formulär - forcera vertikal layout */
  div[style*="display: grid"],
  div[style*="display:grid"],
  div[style*="grid-template-columns"] {
    display: flex !important;
    flex-direction: column !important;
    gap: 16px !important;
  }
  
  /* Inline flex grupper - wrappa */
  div[style*="display:flex"][style*="gap"]:not([style*="flex-direction:column"]) {
    flex-wrap: wrap !important;
  }
  
  /* Stäng-knapp uppe till höger */
  .btn-close-page {
    position: fixed !important;
    top: calc(env(safe-area-inset-top, 0px) + 80px) !important;
    right: 16px !important;
    z-index: 100 !important;
    width: 44px !important;
    height: 44px !important;
    border-radius: 50% !important;
    background: #f3f4f6 !important;
    border: 1px solid #e5e7eb !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1) !important;
  }
  
  /* Modal på mobil - fullskärm */
  .modal,
  [id*="-modal"] .modal {
    width: 100% !important;
    max-width: none !important;
    min-height: 100vh !important;
    border-radius: 0 !important;
    margin: 0 !important;
  }
  
  [id*="-modal"] {
    padding: 0 !important;
    align-items: stretch !important;
  }
  
  /* Options-modal (typ, bransch etc) - fullskärm på mobil */
  .options-modal-content,
  .crm-options-modal-content,
  .cust-types-modal-content {
    max-height: 100vh !important;
    max-height: 100dvh !important;
    height: 100% !important;
    max-width: 100% !important;
    border-radius: 0 !important;
    padding-bottom: env(safe-area-inset-bottom, 20px) !important;
  }
  
  .options-modal-body,
  .crm-options-modal-body,
  .cust-types-modal-body {
    flex: 1 !important;
    overflow-y: auto !important;
    padding-bottom: 100px !important;
  }
  
  .options-add-row,
  .options-add,
  .crm-options-add,
  .cust-types-add {
    position: sticky !important;
    bottom: 0 !important;
    background: #fff !important;
    padding: 12px !important;
    border-top: 1px solid #e5e7eb !important;
    margin: 0 -20px -20px -20px !important;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)) !important;
  }
  
  .modal-body {
    padding: 16px !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }
  
  .modal-footer {
    padding: 16px !important;
    gap: 12px !important;
    flex-direction: column !important;
  }
  
  .modal-footer .btn {
    width: 100% !important;
  }
  
  /* Bildgalleri */
  div[style*="display:grid"][style*="repeat(4"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  
  div[style*="display:grid"][style*="repeat(3"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  
  /* Tabeller inuti edit-sidor */
  .project-tab-content table,
  .tab-content table {
    font-size: 14px !important;
  }
  
  .project-tab-content th,
  .project-tab-content td,
  .tab-content th,
  .tab-content td {
    padding: 10px 8px !important;
  }
  
  /* Action-knappar i formulär */
  .form-actions,
  div[style*="display:flex"][style*="gap"][style*="justify-content:flex-end"] {
    flex-direction: column !important;
    width: 100% !important;
  }
  
  .form-actions .btn,
  .form-actions button {
    width: 100% !important;
  }
  
  /* Suggest/autocomplete dropdowns */
  .suggest {
    max-height: 50vh !important;
  }
}

/* =============================================================================
   PRINT - Göm mobil-specifika element vid utskrift
   ============================================================================= */
@media print {
  .mobile-menu-btn,
  .show-mobile-only {
    display: none !important;
  }
}

/* =============================================================================
   FILTER-BAR & TABLE CONTROLS PÅ MOBIL
   ============================================================================= */

/* Filter toggle-knapp - gömd på desktop */
.filter-toggle-btn {
  display: none;
}

@media (max-width: 768px) {
  /* ===== TBL-FILTERS: Kompakt toolbar ===== */
  .tbl-filters {
    margin-bottom: 12px !important;
  }
  
  .tbl-filter-right {
    width: 100% !important;
    justify-content: flex-end !important;
  }
  
  /* Göm pagination och sök i header */
  .tbl-filters .tbl-pagination,
  .tbl-filters .tbl-search {
    display: none !important;
  }
  
  /* tbl-btns gap - annan gap i filter-toggle context */
  .tbl-btns {
    gap: 4px !important;
  }
  
  /* Filter toggle-knapp - UTSEENDE OCH STORLEK (som icon-btn) */
  .filter-toggle-btn,
  button.filter-toggle-btn,
  .icon-btn.filter-toggle-btn,
  button.icon-btn.filter-toggle-btn,
  .tbl-btns .filter-toggle-btn,
  .tbl-btns .icon-btn.filter-toggle-btn,
  .tbl-btns button.filter-toggle-btn {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    max-width: 36px !important;
    min-height: 36px !important;
    max-height: 36px !important;
    padding: 0 !important;
    background: #f8fafc !important;
    background-color: #f8fafc !important;
    border: 1px solid #e2e8f0 !important;
    border-radius: 8px !important;
    color: #64748b !important;
    cursor: pointer !important;
    position: relative !important;
    flex-shrink: 0 !important;
    order: -1 !important;
    margin-right: auto !important;
    box-shadow: none !important;
  }
  
  .filter-toggle-btn:hover,
  .icon-btn.filter-toggle-btn:hover,
  button.filter-toggle-btn:hover {
    background: #f1f5f9 !important;
    border-color: #cbd5e1 !important;
    color: #475569 !important;
  }
  
  .filter-toggle-btn i,
  .icon-btn.filter-toggle-btn i,
  button.filter-toggle-btn i {
    font-size: 14px !important;
    color: inherit !important;
  }
  
  .filter-toggle-btn:hover,
  .filter-toggle-btn:active {
    background: #f1f5f9 !important;
    border-color: #cbd5e1 !important;
    color: #475569 !important;
  }
  
  .filter-toggle-btn.has-active-filters {
    background: #dbeafe !important;
    border-color: #93c5fd !important;
    color: #1d4ed8 !important;
  }
  
  /* Badge för antal aktiva filter */
  .filter-toggle-btn .filter-badge {
    position: absolute !important;
    top: -4px !important;
    right: -4px !important;
    min-width: 16px !important;
    height: 16px !important;
    background: #ef4444 !important;
    color: #fff !important;
    font-size: 9px !important;
    font-weight: 600 !important;
    border-radius: 7px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 3px !important;
  }
  
  /* ===== FILTER-BAR: Expanderbar panel ===== */
  .filter-bar {
    display: none !important;
    flex-direction: column !important;
    gap: 8px !important;
    padding: 12px !important;
    margin-bottom: 12px !important;
    background: #f9fafb !important;
    border: 1px solid #e5e7eb !important;
    border-radius: 8px !important;
  }

  /* Filter wrapper - kolumn-layout på mobil */
  .filter-wrapper {
    display: block !important;
  }

  /* Actions-knappar för projekt - inline med tbl-btns */
  .filter-bar-actions {
    display: flex !important;
    gap: 6px !important;
    margin-left: 0 !important;
    margin-bottom: 12px !important;
    width: auto !important;
  }

  .filter-bar-actions .filter-icon-btn {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    min-height: 36px !important;
    border-radius: 8px !important;
    background: #f3f4f6 !important;
    border: 1px solid #e5e7eb !important;
    color: #3b82f6 !important;
    text-decoration: none !important;
    font-size: 14px !important;
  }

  .filter-bar-actions .filter-icon-btn:nth-child(2) {
    color: #6b7280 !important;
  }
  
  .filter-bar.filter-expanded {
    display: flex !important;
  }
  
  .filter-bar.filter-expanded > * {
    display: block !important;
    width: 100% !important;
  }
  
  .filter-bar.filter-expanded > select,
  .filter-bar.filter-expanded > .ms-dropdown,
  .filter-bar.filter-expanded > .filter-clear-btn {
    display: flex !important;
  }
  
  .filter-bar > .filter-clear-btn {
    width: 40px !important;
    height: 40px !important;
    order: 100 !important;
    border-radius: 8px !important;
    justify-content: center !important;
    align-self: flex-end !important;
  }
  
  .filter-bar > select {
    height: 44px !important;
    font-size: 15px !important;
    border-radius: 8px !important;
    border: 1px solid #d1d5db !important;
    padding: 0 12px !important;
    background: #fff !important;
  }
  
  /* ===== TBL-FOOTER: Sök + Pagination ===== */
  .tbl-footer {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    padding: 12px 0 !important;
    gap: 10px !important;
  }
  
  .tbl-footer .tbl-summary {
    display: none !important;
  }
  
  /* Footer controls row */
  .tbl-footer .tbl-footer-controls {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 12px !important;
    min-height: 40px !important;
  }
  
  /* Pagination i footer */
  .tbl-footer .tbl-pagination-mobile {
    display: flex !important;
    gap: 8px !important;
    align-items: center !important;
  }
  
  .tbl-footer .tbl-pagination-mobile .pg-btn {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 36px !important;
    height: 36px !important;
    font-size: 14px !important;
    border-radius: 8px !important;
    background: #fff !important;
    border: 1px solid #d1d5db !important;
    color: #374151 !important;
    cursor: pointer !important;
  }
  
  .tbl-footer .pg-info-mobile {
    font-size: 14px !important;
    color: #6b7280 !important;
    white-space: nowrap !important;
    min-width: 40px !important;
    text-align: center !important;
  }
  
  /* Sök-knapp i footer */
  .tbl-footer .search-toggle-btn {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 36px !important;
    height: 36px !important;
    background: #fff !important;
    border: 1px solid #d1d5db !important;
    border-radius: 8px !important;
    color: #6b7280 !important;
    font-size: 14px !important;
    cursor: pointer !important;
  }
  
  .tbl-footer .search-toggle-btn:active {
    background: #f3f4f6 !important;
  }
  
  .tbl-footer .search-toggle-btn.search-active {
    background: #dbeafe !important;
    border-color: #93c5fd !important;
    color: #1d4ed8 !important;
  }
  
  /* Pagination i footer - se .tbl-footer .tbl-pagination-mobile ovan */
  
  /* Expanderbar sökruta i footer */
  .tbl-footer .tbl-search-mobile {
    display: none !important;
    width: 100% !important;
    height: 44px !important;
    padding: 0 12px !important;
    font-size: 16px !important;
    border: 1px solid #d1d5db !important;
    border-radius: 8px !important;
    background: #fff !important;
  }
  
  .tbl-footer .tbl-search-mobile.search-expanded {
    display: block !important;
  }
  
  /* App-footer (copyright) -> mobil-controls */
  footer.footer {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    padding: 8px 16px !important;
    gap: 8px !important;
    background: #fff !important;
    border-top: 1px solid #e5e7eb !important;
  }
  
  footer.footer > div:first-child {
    display: none !important;
  }
  
  /* Footer controls i fasta footern */
  footer.footer .footer-mobile-controls {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
  }
  
  footer.footer .tbl-pagination-mobile {
    display: flex !important;
    gap: 4px !important;
    align-items: center !important;
  }
  
  footer.footer .tbl-pagination-mobile .pg-btn {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 32px !important;
    height: 32px !important;
    min-height: 32px !important;
    max-height: 32px !important;
    font-size: 14px !important;
    border-radius: 6px !important;
    background: #fff !important;
    border: 1px solid #d1d5db !important;
    color: #374151 !important;
    cursor: pointer !important;
    padding: 0 !important;
  }
  
  footer.footer .pg-info-mobile {
    font-size: 13px !important;
    color: #6b7280 !important;
    min-width: 30px !important;
    text-align: center !important;
  }
  
  footer.footer .search-toggle-btn {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 32px !important;
    height: 32px !important;
    min-height: 32px !important;
    max-height: 32px !important;
    background: #fff !important;
    border: 1px solid #d1d5db !important;
    border-radius: 6px !important;
    color: #6b7280 !important;
    font-size: 14px !important;
    cursor: pointer !important;
    padding: 0 !important;
  }
  
  footer.footer .search-toggle-btn.search-active {
    background: #dbeafe !important;
    border-color: #93c5fd !important;
    color: #1d4ed8 !important;
  }
  
  footer.footer .footer-search-input {
    display: none !important;
    width: 100% !important;
    height: 44px !important;
    padding: 0 12px !important;
    font-size: 16px !important;
    border: 1px solid #d1d5db !important;
    border-radius: 8px !important;
    background: #fff !important;
  }
  
  footer.footer .footer-search-input.search-expanded {
    display: block !important;
  }
  
  /* Multiselect dropdown */
  .ms-dropdown {
    width: 100% !important;
  }
  
  .ms-btn {
    width: 100% !important;
    height: 44px !important;
    min-height: 44px !important;
    padding: 0 14px !important;
    font-size: 15px !important;
    border-radius: 8px !important;
    border: 1px solid #d1d5db !important;
    justify-content: space-between !important;
  }
  
  .ms-menu {
    width: 100% !important;
    max-height: 60vh !important;
    border-radius: 8px !important;
  }

  .ms-menu label {
    padding: 12px 14px !important;
    font-size: 15px !important;
    min-height: 44px !important;
    display: flex !important;
    align-items: center !important;
  }
  
  .ms-menu input[type="checkbox"] {
    width: 20px !important;
    height: 20px !important;
    margin-right: 12px !important;
  }
  
  /* Datum-filter */
  .filter-date-group {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 8px !important;
    width: 100% !important;
  }
  
  .filter-date-group input[type="date"] {
    flex: 1 !important;
    height: 44px !important;
    min-height: 44px !important;
    padding: 0 12px !important;
    font-size: 16px !important;
    border-radius: 10px !important;
    border: 1.5px solid #d1d5db !important;
  }
  
  .filter-date-group i {
    flex-shrink: 0;
  }
  
  /* =========================================================================
     RENSA FILTER-KNAPP - Tratt med tydligt streck (pastell)
     ========================================================================= */
  .filter-clear-btn {
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    min-height: 36px !important;
    max-width: 36px !important;
    max-height: 36px !important;
    padding: 0 !important;
    border-radius: 8px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: #fef2f2 !important;
    border: 1.5px solid #fecaca !important;
    color: #dc2626 !important;
    font-size: 14px !important;
    position: relative !important;
    overflow: hidden !important;
    flex-shrink: 0 !important;
  }
  
  /* Dölj befintlig ikon och visa tratt */
  .filter-clear-btn i {
    display: none !important;
  }
  
  .filter-clear-btn::before {
    font-family: "Font Awesome 6 Free" !important;
    font-weight: 900 !important;
    content: "\f0b0" !important; /* fa-filter - tratt */
    font-size: 14px !important;
    color: #dc2626 !important;
  }
  
  /* Rött diagonalt streck över tratten */
  .filter-clear-btn::after {
    content: "" !important;
    position: absolute !important;
    width: 22px !important;
    height: 2px !important;
    background: #dc2626 !important;
    transform: rotate(-45deg) !important;
  }
  
  .filter-clear-btn:hover,
  .filter-clear-btn:active {
    background: #fee2e2 !important;
    border-color: #fca5a5 !important;
  }
  
  /* Icon-knappar i filter */
  .filter-icon-btn {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
    border-radius: 10px !important;
  }
  
  /* Stäng-knapp - annorlunda stil */
  .btn-close-page {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    border-radius: 10px !important;
    background: #f3f4f6 !important;
    border: 1.5px solid #e5e7eb !important;
    color: #6b7280 !important;
  }
  
  /* =============================================================================
     LOGIN / AUTH SIDOR - form-card på mobil
     ============================================================================= */
  .form-card {
    margin: 16px !important;
    margin-top: 86px !important; /* 70px header + 16px avstånd */
    padding: 20px !important;
    background: #fff !important;
    border-radius: 12px !important;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08) !important;
  }
  
  .form-card h2 {
    margin: 0 0 20px 0 !important;
    font-size: 1.25rem !important;
  }
  
  .form-card .form-section {
    padding: 0 !important;
    border: none !important;
    background: transparent !important;
  }
  
  .form-card label {
    display: block !important;
    margin-bottom: 6px !important;
    font-weight: 500 !important;
    color: #374151 !important;
  }
  
  .form-card input[type="email"],
  .form-card input[type="password"],
  .form-card input[type="text"] {
    width: 100% !important;
    padding: 12px 14px !important;
    margin-bottom: 16px !important;
    border: 1px solid #d1d5db !important;
    border-radius: 8px !important;
    font-size: 16px !important; /* Förhindrar zoom på iOS */
    box-sizing: border-box !important;
  }
  
  .form-card input:focus {
    outline: none !important;
    border-color: #3b82f6 !important;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15) !important;
  }
  
  .form-card .btn {
    padding: 12px 24px !important;
    font-size: 15px !important;
    border-radius: 8px !important;
  }
  
  .form-card .alert {
    margin-bottom: 16px !important;
    padding: 12px !important;
    border-radius: 8px !important;
    font-size: 14px !important;
  }

  /* =============================================================================
     MASS ACTION BAR - Kompakt med endast ikoner
     ============================================================================= */
  #massActionBar {
    flex-wrap: wrap !important;
    gap: 8px !important;
    padding: 10px 12px !important;
  }
  
  /* Antal markerade - kompakt */
  #massActionBar > span:first-child {
    font-size: 13px !important;
    white-space: nowrap !important;
  }
  
  /* Knappar - endast ikoner */
  #massActionBar .btn {
    padding: 0 !important;
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    min-height: 36px !important;
    border-radius: 8px !important;
    font-size: 0 !important; /* Döljer texten */
  }
  
  #massActionBar .btn i {
    font-size: 14px !important;
  }
}
