/* ══════════════════════════════════════════════════════════════
   Responsive CSS — Lidomatic CRM Dashboard
   Breakpoints: Tablet (768-1024px), Mobile (<768px)
   ══════════════════════════════════════════════════════════════ */

/* ── Hamburger button (hidden on desktop) ── */
.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  color: #475569;
  border-radius: 8px;
  flex-shrink: 0;
}

.sidebar-toggle:hover {
  background: #e2e8f0;
}

/* ── Sidebar overlay backdrop (mobile only) ── */
.sidebar-backdrop {
  display: none;
}

/* ══════════════════════════════════════════════════════════════
   TABLET (768px — 1024px)
   ═��══════════════════════════��═════════════════════════════════ */

@media (max-width: 1024px) {
  /* Sidebar: collapse to icons only */
  .sidebar {
    width: 60px;
    padding: 0 8px 8px;
    overflow: visible;
  }

  .sidebar-logo {
    padding: 16px 0;
    justify-content: center;
    margin-bottom: 16px;
  }

  .sidebar-logo span:not(.sidebar-logo-icon) {
    display: none;
  }

  .sidebar-item {
    padding: 10px;
    justify-content: center;
    border-left: none;
    border-radius: 8px;
  }

  .sidebar-item span {
    display: none;
  }

  .sidebar-item svg {
    margin: 0;
  }

  .sidebar-item.active {
    border-left: none;
    background: rgba(59, 130, 246, 0.2);
  }

  .sidebar-footer {
    padding: 8px 0;
  }

  .sidebar-footer-version {
    text-align: center;
    font-size: 9px;
  }

  /* Main: adjust for collapsed sidebar */
  .main {
    margin-left: 60px;
    padding: 16px;
  }

  /* Header */
  .header {
    flex-wrap: wrap;
    gap: 8px;
  }

  .search-input {
    width: 100%;
    order: 2;
  }

  .header-actions {
    order: 1;
    margin-left: auto;
  }

  /* KPI grids */
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Data tables: horizontal scroll */
  .data-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Detail grids */
  .detail-grid-2 {
    grid-template-columns: 1fr !important;
  }
}

/* ══════════════════════════════════════════════════════════════
   MOBILE (<768px)
   ═══════════════════════════════════════════════��══════════════ */

@media (max-width: 768px) {
  /* Show hamburger */
  .sidebar-toggle {
    display: flex;
    align-items: center;
  }

  /* Sidebar: off-screen drawer */
  .sidebar {
    width: 260px;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: none;
    z-index: 200;
  }

  .sidebar.sidebar-open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
  }

  /* Show text again in mobile drawer */
  .sidebar.sidebar-open .sidebar-logo span:not(.sidebar-logo-icon) {
    display: inline;
  }

  .sidebar.sidebar-open .sidebar-item {
    justify-content: flex-start;
    padding: 12px 16px;
  }

  .sidebar.sidebar-open .sidebar-item span {
    display: inline;
  }

  .sidebar.sidebar-open .sidebar-footer-version {
    text-align: left;
    font-size: 11px;
  }

  /* Main: full width */
  .main {
    margin-left: 0;
    padding: 12px;
  }

  /* Header */
  .header {
    flex-wrap: wrap;
    gap: 8px;
  }

  .search-input {
    width: 100%;
    order: 3;
    font-size: 16px; /* prevent iOS zoom */
  }

  .header-actions {
    order: 2;
    margin-left: auto;
    flex-wrap: wrap;
  }

  /* Hide button text on mobile, show only icon */
  .header-actions .btn {
    font-size: 12px;
    padding: 6px 10px;
  }

  /* KPI grids: single column */
  .kpi-grid {
    grid-template-columns: 1fr !important;
  }

  /* Cards */
  .card {
    padding: 14px;
  }

  .card-title {
    font-size: 15px;
  }

  /* Section titles */
  .section-title {
    font-size: 18px;
  }

  /* Data tables */
  .data-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    font-size: 12px;
  }

  .data-table th,
  .data-table td {
    padding: 8px 10px;
    white-space: nowrap;
  }

  /* Inline diagnostic grids (machine-detail, client-detail) */
  div[style*="grid-template-columns:repeat(4"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Two-column grids become single */
  div[style*="grid-template-columns:1fr 1fr"],
  div[style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Modals: more space */
  .modal {
    padding: 20px;
    border-radius: 12px;
    width: 95%;
  }

  .modal-overlay {
    align-items: flex-end;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  /* Form rows: stack vertically */
  .form-row {
    flex-direction: column;
    gap: 0;
  }

  /* Filter chips: scrollable */
  .filter-bar {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }

  .filter-chip {
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* Touch targets: minimum 44px */
  .sidebar-item {
    min-height: 44px;
  }

  .btn {
    min-height: 40px;
  }

  .data-table tbody tr {
    min-height: 44px;
  }

  /* Timeline entries */
  .timeline-entry {
    padding: 10px 12px;
  }

  /* Tabs */
  .tab-bar {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .tab-item {
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* Machine detail: stack columns */
  div[style*="grid-template-columns:1fr 1fr;gap:16px"] {
    grid-template-columns: 1fr !important;
  }
}

/* ══════════════════════════════════════════════════════════════
   SMALL MOBILE (<400px)
   ═════════════════════���═════════════════════════���══════════════ */

@media (max-width: 400px) {
  .main {
    padding: 8px;
  }

  .header-actions .btn {
    font-size: 11px;
    padding: 5px 8px;
  }

  .card {
    padding: 10px;
  }

  .modal {
    width: 100%;
    border-radius: 12px 12px 0 0;
  }
}
