/**
 * pulsion-mobile.css — Mobilní responzivita pro PULSION
 *
 * Breakpointy:
 *   - Tablet: <= 900px
 *   - Mobil: <= 640px
 *
 * Princip:
 *   - Grid layouty přejdou na 1 sloupec
 *   - Tabulky se transformují v karty (data-label atributy)
 *   - Sticky top nav s hamburger menu
 *   - Touch-friendly padding (min. 44px cíle)
 */

/* ============================================================
   GLOBAL — sticky nav + touch scrolling
   ============================================================ */
@media (max-width: 900px) {
  html, body {
    -webkit-overflow-scrolling: touch;
  }

  /* App header sticky vždy nahoře */
  .app-header {
    position: sticky !important;
    top: 0;
    z-index: 200;
  }
}

/* ============================================================
   TABLET (<=900px)
   ============================================================ */
@media (max-width: 900px) {
  /* Grid 3-4 col -> 2 col */
  .cards {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px !important;
  }
  .stations-grid {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 12px !important;
  }
  .stats-row {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px !important;
  }
  .kpi-row {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Main container padding */
  .container, main, .main {
    padding-left: 16px !important;
    padding-right: 16px !important;
  }

  /* Login stránka */
  .app {
    grid-template-columns: 1fr !important;
    height: auto !important;
    min-height: 100vh;
  }
  .left {
    padding: 24px 20px !important;
  }
  .right {
    padding: 32px 20px !important;
  }
  .machine-preview {
    max-height: 40vh !important;
  }
}

/* ============================================================
   MOBIL (<=640px)
   ============================================================ */
@media (max-width: 640px) {
  html, body {
    overflow-x: hidden;
  }

  /* --- TOP NAV: hamburger menu --- */
  .app-header {
    padding: 8px 12px !important;
    height: auto !important;
    min-height: 48px;
    flex-wrap: nowrap !important;
    gap: 8px !important;
  }

  /* Zobrazit hamburger */
  .app-header .nav-toggle {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: #fff;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 8px;
    width: 36px;
    height: 36px;
    cursor: pointer;
    flex-shrink: 0;
    padding: 0;
  }

  /* Logo menší */
  .app-header .logo-wrap {
    flex: 1;
    min-width: 0;
  }
  .app-header .logo-img {
    height: 28px !important;
  }
  .app-header .header-divider {
    display: none !important;
  }
  .app-header .app-title {
    font-size: 13px !important;
    max-width: 160px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Hlavní nav — skrytý defaultně, otevírán hamburgerem */
  .app-header .main-nav {
    display: none;
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    background: #0f172a;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0 !important;
    padding: 8px 0;
    border-top: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 8px 20px rgba(0,0,0,0.3);
    max-height: calc(100vh - 56px);
    overflow-y: auto;
    z-index: 999;
  }
  .app-header.nav-open .main-nav {
    display: flex;
  }
  .app-header .main-nav .header-link {
    padding: 12px 20px !important;
    font-size: 15px !important;
    border-radius: 0 !important;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    color: rgba(255,255,255,0.85) !important;
  }
  .app-header .main-nav .header-link.active {
    background: rgba(59,130,246,0.15) !important;
    color: #fff !important;
    border-left: 3px solid #3b82f6;
    padding-left: 17px !important;
  }

  .app-header .header-spacer {
    flex: 0 !important;
  }

  /* User + logout kompaktní */
  .app-header #nav-user-name {
    display: none !important;
  }
  .app-header .logout-btn {
    padding: 4px 8px !important;
    font-size: 11px !important;
  }
  .app-header .logout-btn span,
  .app-header .logout-btn {
    font-size: 0 !important;
  }
  .app-header .logout-btn svg {
    width: 18px !important;
    height: 18px !important;
  }
  .app-header .admin-btn,
  .app-header .cart-btn {
    padding: 6px 8px !important;
    min-width: 36px;
  }
  .app-header .cart-btn span {
    font-size: 12px !important;
  }

  /* --- MAIN LAYOUT --- */
  .container, main, .main {
    padding: 12px !important;
  }

  h1, .page-title { font-size: 22px !important; letter-spacing: -0.3px; }
  h2 { font-size: 18px !important; }
  h3 { font-size: 16px !important; }

  /* Dashboard cards 1 col */
  .cards {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }
  .card {
    padding: 16px !important;
  }
  .card-icon {
    width: 42px !important;
    height: 42px !important;
    font-size: 20px !important;
  }
  .card-title { font-size: 15px !important; }
  .card-desc { font-size: 12px !important; }

  /* Stats row 2 col */
  .stats-row, .kpi-row, .kpi-cards {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }
  .stat, .kpi {
    padding: 10px 12px !important;
  }
  .stat-value {
    font-size: 22px !important;
  }
  .stat-label, .kpi .label {
    font-size: 10px !important;
  }

  /* Mapa stanic dlaždice 2 col */
  .stations-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }
  .station-card {
    padding: 10px !important;
  }
  .station-card .thumb {
    height: 90px !important;
  }
  .station-card .name {
    font-size: 12px !important;
  }
  .station-card .meta {
    font-size: 10px !important;
  }

  /* Machine preview / hero */
  .machine-preview img {
    max-height: 240px !important;
  }
  .machine-badge {
    font-size: 10px !important;
    padding: 4px 10px !important;
  }

  /* Filter bar */
  .filter-bar, .filters {
    flex-wrap: wrap !important;
    gap: 6px !important;
    padding: 10px !important;
  }
  .filter-bar input,
  .filter-bar select,
  .filters input,
  .filters select {
    width: 100% !important;
    font-size: 14px !important;
    padding: 8px 10px !important;
  }
  .filter-bar .priority-buttons {
    flex-wrap: wrap;
    width: 100%;
  }
  .filter-bar .pbtn {
    flex: 1;
    min-width: 90px;
  }
  .filter-bar .results-count,
  .filter-bar .reset {
    width: 100%;
    text-align: center;
    margin-top: 4px;
  }

  /* Admin panel */
  .admin-panel {
    flex-direction: column !important;
    align-items: stretch !important;
    padding: 12px !important;
  }
  .admin-panel .actions {
    flex-direction: column;
    gap: 6px;
    width: 100%;
  }
  .admin-panel .btn {
    width: 100%;
    justify-content: center;
  }

  /* --- TABULKY: přeměna na karty --- */
  .nd-table thead {
    display: none;
  }
  .nd-table, .nd-table tbody, .nd-table tr, .nd-table td {
    display: block;
    width: 100%;
  }
  .nd-table tr {
    background: #fff;
    border: 1px solid #e2e8f0 !important;
    border-radius: 10px;
    margin-bottom: 10px;
    padding: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  }
  .nd-table td {
    border: none !important;
    padding: 4px 0 !important;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
  }
  .nd-table td::before {
    content: attr(data-label);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #94a3b8;
    min-width: 90px;
    flex-shrink: 0;
  }
  /* Náhled: velký obrázek nahoře v kartě */
  .nd-table td.thumb {
    padding: 0 0 8px 0 !important;
    justify-content: center;
    display: flex;
  }
  .nd-table td.thumb::before {
    display: none;
  }
  .nd-table .thumb-img {
    width: 80px !important;
    height: 80px !important;
  }
  .nd-table td.pn {
    font-size: 12px;
    justify-content: flex-start;
  }
  .nd-table td.pn::before {
    content: '';
    display: none;
  }
  .nd-table td.name {
    font-weight: 600;
    color: #0f172a;
    justify-content: flex-start;
  }
  .nd-table td.name::before {
    display: none;
  }
  .nd-table td.acts {
    padding-top: 8px !important;
  }
  .nd-table td.acts::before {
    display: none;
  }
  .nd-table td.acts button {
    width: 100%;
    padding: 10px !important;
  }

  /* Košík poptávky */
  .cart-item {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
  }
  .cart-item .actions {
    justify-content: space-between;
    width: 100%;
  }

  /* FAT/SAT dashboard */
  .test-list-grid {
    grid-template-columns: 1fr !important;
  }

  /* Compliance kalendář */
  .compliance-item {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  /* Fotogalerie */
  .photos-grid, .fotogalerie-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }
  .photo-card {
    padding: 6px !important;
  }

  /* Linka 3D — sidebar collapse */
  .l3d-page .l3d-content {
    grid-template-columns: 1fr !important;
    grid-template-rows: auto auto 1fr !important;
  }
  .l3d-page .picker-panel,
  .l3d-page .bom-panel {
    max-height: 30vh !important;
    overflow-y: auto;
  }
  .l3d-page .viewer-wrap {
    min-height: 300px;
  }

  /* Modaly full-screen na mobilu */
  .modal-overlay .modal,
  .modal {
    max-width: 100% !important;
    max-height: 100vh !important;
    width: 100% !important;
    margin: 0 !important;
    border-radius: 0 !important;
  }

  /* Formulářové inputy touch-friendly */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="search"],
  textarea,
  select {
    font-size: 16px !important; /* iOS nezoomuje pri fokusu */
  }

  /* Tlačítka min. 44px pro touch */
  button, .btn, a.btn {
    min-height: 40px;
  }

  /* Utility: skrýt na mobilu */
  .hide-mobile {
    display: none !important;
  }
}

/* ============================================================
   VELMI MALÉ (<=380px) — iPhone SE apod.
   ============================================================ */
@media (max-width: 380px) {
  .cards {
    gap: 8px !important;
  }
  .stats-row, .kpi-row {
    grid-template-columns: 1fr !important;
  }
  .stations-grid {
    grid-template-columns: 1fr !important;
  }
  h1, .page-title { font-size: 20px !important; }
  .card-title { font-size: 14px !important; }
}
