/* CMMS Agroindustrial - Planta Río Cuarto (Córdoba) */
:root {
  --primary: #1e3a8a;       /* Azul industrial corporativo */
  --primary-hover: #1e40af;
  --secondary: #0f766e;     /* Verde agro / legumbres */
  --accent-amber: #d97706;  /* Alerta polvo / precaución */
  --accent-red: #dc2626;    /* Riesgo crítico / parada */
  --accent-green: #16a34a;  /* Operativa / Conforme */
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

[data-theme="dark"] {
  --bg-main: #0f172a;
  --bg-card: #1e293b;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --border-color: #334155;
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  width: 100%;
  max-width: 100%;
}

body.modal-open {
  overflow: hidden !important;
  touch-action: none !important;
  -webkit-overflow-scrolling: auto !important;
}

/* Touch targets and iOS input styling */
button, select, input, textarea, .touch-btn {
  -webkit-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
}

/* Touch targets: minimum 48px */
button, select, input, .touch-btn {
  min-height: 48px;
  font-size: 1rem;
}

/* Header & Top Bar */
.top-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 0.75rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.brand-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-logo {
  width: 44px;
  height: 44px;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.25rem;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.2;
}

.brand-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* User Role Banner & Selector */
.role-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  background: #e0e7ff;
  color: #3730a3;
}

/* Quick Plant Primary Actions */
.plant-hero-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
}

.big-touch-button {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  padding: 0.85rem 1.25rem;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  transition: all 0.15s ease;
}

.big-touch-button:active {
  transform: scale(0.98);
}

.big-touch-button:hover {
  filter: brightness(1.05);
  box-shadow: 0 3px 6px rgba(0,0,0,0.12);
}

.btn-qr {
  background: #1e3a8a;
  color: white;
}

.btn-new-pedido {
  background: #0f766e;
  color: white;
}

/* Navigation Tabs & Horizontal Scroll System */
.nav-tabs {
  display: flex;
  overflow-x: auto;
  gap: 0.5rem;
  padding: 0.6rem 0.85rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: #3b82f6 #f1f5f9;
}

.nav-tabs::-webkit-scrollbar {
  height: 8px;
  display: block;
}

.nav-tabs::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: 4px;
}

.nav-tabs::-webkit-scrollbar-thumb {
  background: #93c5fd;
  border-radius: 4px;
}

.nav-tabs::-webkit-scrollbar-thumb:hover {
  background: #2563eb;
}

.nav-tabs.wrapped {
  flex-wrap: wrap !important;
  overflow-x: visible !important;
}

.nav-tab-btn {
  white-space: nowrap;
  padding: 0.6rem 1.15rem;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--bg-main);
  color: var(--text-main);
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  user-select: none;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.nav-tab-btn:hover {
  border-color: var(--primary);
  background: #eff6ff;
}

.nav-tab-btn.active {
  background: var(--primary) !important;
  color: white !important;
  border-color: var(--primary) !important;
  box-shadow: 0 1px 3px rgba(30, 58, 138, 0.2);
}

/* CMMS Tables & Sticky Action Columns */
.cmms-table-container,
#requestsTableContainer,
#otsTableContainer,
#prevTableContainer,
#safetyTableContainer,
#instrumentsTableContainer,
#partsTableContainer,
#auditTableContainer {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch !important;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: #3b82f6 #f1f5f9;
  margin-bottom: 1.5rem;
}

.cmms-table-container::-webkit-scrollbar,
#requestsTableContainer::-webkit-scrollbar,
#otsTableContainer::-webkit-scrollbar,
#prevTableContainer::-webkit-scrollbar,
#safetyTableContainer::-webkit-scrollbar,
#instrumentsTableContainer::-webkit-scrollbar,
#partsTableContainer::-webkit-scrollbar,
#auditTableContainer::-webkit-scrollbar {
  height: 9px;
  display: block;
}

.cmms-table-container::-webkit-scrollbar-track,
#requestsTableContainer::-webkit-scrollbar-track,
#otsTableContainer::-webkit-scrollbar-track,
#prevTableContainer::-webkit-scrollbar-track,
#safetyTableContainer::-webkit-scrollbar-track,
#instrumentsTableContainer::-webkit-scrollbar-track,
#partsTableContainer::-webkit-scrollbar-track,
#auditTableContainer::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: 6px;
}

.cmms-table-container::-webkit-scrollbar-thumb,
#requestsTableContainer::-webkit-scrollbar-thumb,
#otsTableContainer::-webkit-scrollbar-thumb,
#prevTableContainer::-webkit-scrollbar-thumb,
#safetyTableContainer::-webkit-scrollbar-thumb,
#instrumentsTableContainer::-webkit-scrollbar-thumb,
#partsTableContainer::-webkit-scrollbar-thumb,
#auditTableContainer::-webkit-scrollbar-thumb {
  background: #3b82f6;
  border-radius: 6px;
}

.cmms-table-container::-webkit-scrollbar-thumb:hover,
#requestsTableContainer::-webkit-scrollbar-thumb:hover,
#otsTableContainer::-webkit-scrollbar-thumb:hover,
#prevTableContainer::-webkit-scrollbar-thumb:hover,
#safetyTableContainer::-webkit-scrollbar-thumb:hover,
#instrumentsTableContainer::-webkit-scrollbar-thumb:hover,
#partsTableContainer::-webkit-scrollbar-thumb:hover,
#auditTableContainer::-webkit-scrollbar-thumb:hover {
  background: #1d4ed8;
}

.cmms-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.cmms-table th {
  background: #f8fafc;
  color: #475569;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border-color);
}
.cmms-table td,
.cmms-table td {
  padding: 0.75rem;
}

/* Sticky Action Column (Rightmost) so options are ALWAYS visible on screen! */
.cmms-table th:last-child,
.cmms-table td:last-child {
  position: sticky;
  right: 0;
  background: var(--bg-card);
  box-shadow: -4px 0 8px rgba(0, 0, 0, 0.08);
  z-index: 5;
  text-align: right;
  white-space: nowrap;
}

.cmms-table thead th:last-child {
  background: var(--bg-main);
  z-index: 6;
}

/* Main Container */
.main-content {
  flex: 1;
  padding: 1rem;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* KPI Card Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.kpi-title {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
}

.kpi-value {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--primary);
  margin: 0.25rem 0;
}

.kpi-sub {
  font-size: 0.75rem;
  font-weight: 600;
}

/* Machine Cards Grid */
.machine-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
}

.machine-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  box-shadow: 0 2px 4px rgba(0,0,0,0.04);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.machine-card:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 8px rgba(0,0,0,0.08);
}

.machine-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.tag-badge {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--primary);
  background: #eff6ff;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  border: 1px solid #bfdbfe;
}

.badges-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 9999px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  line-height: 1.2;
}

.badge-operativa { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.badge-parada { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.badge-mantenimiento { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.badge-polvo { background: #fff7ed; color: #9a3412; border: 1px solid #fed7aa; }
.badge-alimento { background: #f5f3ff; color: #5b21b6; border: 1px solid #ddd6fe; }
.badge-crit-a { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.badge-crit-b { background: #fefce8; color: #854d0e; border: 1px solid #fef08a; }
.badge-crit-c { background: #f8fafc; color: #475569; border: 1px solid #e2e8f0; }
.badge-neutral { background: #f1f5f9; color: #334155; border: 1px solid #cbd5e1; }

/* Filter Bar */
.filter-bar {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
  align-items: center;
}

.filter-input {
  flex: 1;
  min-width: 200px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-main);
  color: var(--text-main);
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
  backdrop-filter: blur(2px);
}

.modal-card {
  background: var(--bg-card);
  border-radius: 14px;
  max-width: 750px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 25px rgba(0,0,0,0.3);
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 1.25rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-body {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

.modal-body > * {
  flex-shrink: 0;
}

.modal-form-table-container {
  flex-shrink: 0 !important;
  min-height: 140px !important;
  width: 100% !important;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 1rem;
  background: var(--bg-card);
}

.modal-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* Forms */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-main);
}

.form-control {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-main);
  color: var(--text-main);
}

.switch-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem;
  background: var(--bg-main);
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

/* Offline Sync Alert */
.offline-banner {
  background: #f59e0b;
  color: #78350f;
  padding: 0.5rem 1rem;
  font-weight: 700;
  font-size: 0.9rem;
  text-align: center;
  display: none;
}

/* Print Styles: Never show printable document inline on screen */
#printableDocument, .printable-document {
  display: none !important;
  visibility: hidden !important;
  position: fixed !important;
  left: -99999px !important;
  top: -99999px !important;
  width: 0 !important;
  height: 0 !important;
  opacity: 0 !important;
  overflow: hidden !important;
  pointer-events: none !important;
  z-index: -9999 !important;
}

@media print {
  body {
    background: white !important;
    color: black !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  .modal-overlay, .modal-card, .top-header, .plant-hero-actions, .nav-tabs, .filter-bar, .no-print, button {
    display: none !important;
  }
}

/* Mobile Header & Drawer Defaults (Desktop: hidden) */
.mobile-header-controls {
  display: none;
}
.mobile-menu-drawer-overlay {
  display: none;
}
.header-desktop-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

@media (max-width: 900px) {
  /* Eliminate Horizontal Sliding Instruction and Hint */
  .table-scroll-helper,
  .table-scroll-hint {
    display: none !important;
  }

  /* Compact Top Header (Native iOS App Header with Notch / Safe Area Support) */
  .top-header {
    position: sticky !important;
    top: 0 !important;
    z-index: 100 !important;
    background: var(--bg-card) !important;
    border-bottom: 1px solid var(--border-color) !important;
    height: auto !important;
    min-height: calc(50px + env(safe-area-inset-top, 0px)) !important;
    padding-top: calc(6px + env(safe-area-inset-top, 0px)) !important;
    padding-bottom: 6px !important;
    padding-left: calc(0.6rem + env(safe-area-inset-left, 0px)) !important;
    padding-right: calc(0.6rem + env(safe-area-inset-right, 0px)) !important;
    display: flex !important;
    flex-direction: row !important;
    justify-content: space-between !important;
    align-items: center !important;
    box-sizing: border-box !important;
    gap: 0.35rem !important;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05) !important;
  }
  .brand-container {
    display: flex !important;
    align-items: center !important;
    gap: 0.4rem !important;
    min-width: 0 !important;
    flex: 1 1 auto !important;
  }
  #headerLogoContainer {
    width: 28px !important;
    height: 28px !important;
    min-width: 28px !important;
    min-height: 28px !important;
  }
  #headerLogoContainer img {
    max-height: 24px !important;
    max-width: 28px !important;
    object-fit: contain !important;
  }
  #headerLogoBadge {
    width: 28px !important;
    height: 28px !important;
    min-width: 28px !important;
    min-height: 28px !important;
    font-size: 0.72rem !important;
    border-radius: 6px !important;
  }
  .brand-text-block {
    min-width: 0 !important;
    overflow: hidden !important;
  }
  .brand-title-full {
    display: none !important;
  }
  .brand-title-short {
    display: inline-block !important;
    font-size: 0.92rem !important;
    font-weight: 800 !important;
    white-space: nowrap !important;
    color: var(--text-main) !important;
    letter-spacing: -0.2px !important;
  }
  .brand-sub {
    display: none !important;
  }

  /* Hide Desktop actions bar on mobile */
  .header-desktop-actions {
    display: none !important;
  }

  /* Mobile Quick Header Controls */
  .mobile-header-controls {
    display: flex !important;
    align-items: center !important;
    gap: 0.3rem !important;
    flex-shrink: 0 !important;
  }
  .mobile-user-chip {
    display: flex !important;
    align-items: center !important;
    gap: 0.25rem !important;
    background: var(--bg-main) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 20px !important;
    padding: 2px 5px 2px 2px !important;
    cursor: pointer !important;
  }
  .user-avatar-sm {
    width: 24px !important;
    height: 24px !important;
    border-radius: 50% !important;
    background: var(--primary) !important;
    color: white !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-weight: 800 !important;
    font-size: 0.68rem !important;
  }
  .mobile-user-name {
    font-size: 0.74rem !important;
    font-weight: 700 !important;
    color: var(--text-main) !important;
    max-width: 52px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }
  .mobile-notif-btn {
    width: 32px !important;
    height: 32px !important;
    min-height: 32px !important;
    min-width: 32px !important;
    padding: 0 !important;
    border-radius: 8px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: var(--bg-main) !important;
    border: 1px solid var(--border-color) !important;
  }
  .mobile-menu-btn {
    display: flex !important;
    align-items: center !important;
    gap: 0.2rem !important;
    background: var(--primary) !important;
    color: white !important;
    border: none !important;
    border-radius: 8px !important;
    padding: 0 0.45rem !important;
    min-height: 32px !important;
    height: 32px !important;
    cursor: pointer !important;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12) !important;
  }

  /* Mobile Options Drawer Overlay & Card */
  .mobile-menu-drawer-overlay {
    position: fixed !important;
    inset: 0 !important;
    background: rgba(15, 23, 42, 0.6) !important;
    backdrop-filter: blur(4px) !important;
    -webkit-backdrop-filter: blur(4px) !important;
    z-index: 10005 !important;
    display: none;
    justify-content: flex-end !important;
  }
  .mobile-menu-drawer-overlay.active {
    display: flex !important;
  }
  .mobile-menu-drawer-card {
    background: var(--bg-card) !important;
    width: 82% !important;
    max-width: 320px !important;
    height: 100% !important;
    height: 100dvh !important;
    display: flex !important;
    flex-direction: column !important;
    box-shadow: -4px 0 20px rgba(0,0,0,0.2) !important;
    animation: drawerSlideIn 0.2s ease-out !important;
    padding-top: env(safe-area-inset-top, 0px) !important;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 20px)) !important;
  }
  @keyframes drawerSlideIn {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
  }
  .mobile-menu-drawer-header {
    padding: calc(0.85rem + env(safe-area-inset-top, 0px)) 1rem 0.85rem 1rem !important;
    border-bottom: 1px solid var(--border-color) !important;
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    background: var(--bg-main) !important;
  }
  .mobile-menu-drawer-body {
    flex: 1 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    padding: 0.5rem !important;
  }
  .mobile-menu-item-btn {
    width: 100% !important;
    display: flex !important;
    align-items: center !important;
    gap: 0.65rem !important;
    padding: 0.6rem 0.75rem !important;
    background: transparent !important;
    border: none !important;
    border-radius: 8px !important;
    cursor: pointer !important;
    text-align: left !important;
  }
  .mobile-menu-item-btn:active {
    background: var(--bg-main) !important;
  }
  .menu-item-icon {
    width: 34px !important;
    height: 34px !important;
    border-radius: 8px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 1.05rem !important;
    flex-shrink: 0 !important;
  }
  .menu-item-content {
    flex: 1 !important;
    min-width: 0 !important;
    line-height: 1.25 !important;
  }
  .menu-item-content strong {
    display: block !important;
    font-size: 0.86rem !important;
    color: var(--text-main) !important;
  }
  .menu-item-content small {
    display: block !important;
    font-size: 0.72rem !important;
    color: var(--text-muted) !important;
  }
  .menu-item-arrow {
    font-size: 1.2rem !important;
    font-weight: 700 !important;
    color: var(--text-muted) !important;
  }

  /* Compact Plant Hero Actions: 2x2 grid instead of 4 stacked full-height blocks */
  .plant-hero-actions {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 0.45rem !important;
    padding: 0.45rem 0.65rem !important;
  }
  .big-touch-button {
    min-height: 40px !important;
    padding: 0.45rem 0.6rem !important;
    font-size: 0.8rem !important;
    border-radius: 8px !important;
  }

  /* Navigation Bar: Sticky & Super Slim Jump */
  .nav-tabs-wrapper {
    position: sticky !important;
    top: calc(50px + env(safe-area-inset-top, 0px)) !important;
    z-index: 90 !important;
    background: var(--bg-card) !important;
    border-bottom: 2px solid var(--border-color) !important;
    box-shadow: 0 2px 4px rgba(0,0,0,0.04) !important;
  }
  /* Ocultar botones redundantes en móviles para no ahogar la pantalla */
  .nav-tabs,
  #btnNavScrollLeft,
  #btnNavScrollRight,
  #btnToggleNavWrap {
    display: none !important;
  }
  .nav-tabs-wrapper > div:first-child {
    padding: 0.3rem 0.65rem !important;
  }
  #navQuickSelect {
    height: 36px !important;
    min-height: 36px !important;
    font-size: 16px !important;
    border-color: var(--primary) !important;
    font-weight: 700 !important;
    border-radius: 8px !important;
    background-color: var(--bg-card) !important;
  }
  .tab-view {
    padding-top: 0.5rem !important;
    padding-bottom: calc(2rem + env(safe-area-inset-bottom, 20px)) !important;
    scroll-margin-top: calc(90px + env(safe-area-inset-top, 0px)) !important;
  }

  /* Compact KPIs: 2 columns, minimal vertical padding */
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.45rem !important;
    margin-bottom: 0.75rem !important;
  }
  .kpi-card {
    padding: 0.5rem 0.65rem !important;
    border-radius: 10px !important;
  }
  .kpi-value {
    font-size: 1.25rem !important;
    margin: 0.15rem 0 !important;
  }
  .kpi-label {
    font-size: 0.72rem !important;
  }

  /* Filter bars compact layout */
  .filter-bar {
    display: flex !important;
    flex-direction: column !important;
    gap: 0.4rem !important;
    padding: 0.65rem !important;
    margin-bottom: 0.75rem !important;
  }
  .filter-bar input,
  .filter-bar select,
  .filter-bar button {
    width: 100% !important;
    min-height: 36px !important;
  }

  /* Main Content Container: full width on phone */
  .main-content {
    padding: 0.5rem !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  /* =========================================================================
     TABLES TO MODERN MOBILE CARDS (ELIMINATES 100% HORIZONTAL SLIDING)
     ========================================================================= */
  .cmms-table-container,
  #requestsTableContainer,
  #otsTableContainer,
  #prevTableContainer,
  #safetyTableContainer,
  #instrumentsTableContainer,
  #partsTableContainer,
  #poTableContainer,
  #auditTableContainer,
  #machinesTableContainer {
    overflow-x: visible !important;
    overflow-y: visible !important;
    min-width: 0 !important;
    width: 100% !important;
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin-bottom: 0.75rem !important;
  }

  .cmms-table {
    display: block !important;
    min-width: 0 !important;
    width: 100% !important;
    border: none !important;
  }

  .cmms-table thead {
    display: none !important;
  }

  .cmms-table tbody {
    display: block !important;
    width: 100% !important;
  }

  .cmms-table tbody tr {
    display: block !important;
    background: var(--bg-card) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 12px !important;
    margin-bottom: 0.75rem !important;
    padding: 0.85rem !important;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05) !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  .cmms-table tbody td {
    display: block !important;
    width: 100% !important;
    box-sizing: border-box !important;
    padding: 0.3rem 0 !important;
    border: none !important;
    text-align: left !important;
    position: static !important;
    background: transparent !important;
    white-space: normal !important;
    max-width: 100% !important;
  }

  /* Bottom Actions within Card */
  .cmms-table tbody td:last-child {
    border-top: 1px dashed var(--border-color) !important;
    margin-top: 0.5rem !important;
    padding-top: 0.6rem !important;
    display: flex !important;
    flex-wrap: wrap !important;
    justify-content: flex-end !important;
    align-items: center !important;
    gap: 0.35rem !important;
    position: static !important;
    box-shadow: none !important;
    background: transparent !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  .cmms-table tbody td:last-child div {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 0.35rem !important;
    width: 100% !important;
    justify-content: flex-end !important;
    align-items: center !important;
  }

  .cmms-table tbody td:last-child button,
  .cmms-table tbody td:last-child .touch-btn {
    flex: 1 1 auto !important;
    min-height: 38px !important;
    justify-content: center !important;
    text-align: center !important;
    font-size: 0.82rem !important;
    padding: 0.4rem 0.6rem !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    white-space: nowrap !important;
    box-sizing: border-box !important;
    border-radius: 8px !important;
  }

  /* Botón de papelera/eliminar en tarjetas: permanece cuadrado y compacto */
  .cmms-table tbody td:last-child button[title*="eliminar" i],
  .cmms-table tbody td:last-child button[title*="baja" i],
  .cmms-table tbody td:last-child button[title*="borrar" i],
  .cmms-table tbody td:last-child button.btn-danger-outline {
    flex: 0 0 40px !important;
    width: 40px !important;
    min-width: 40px !important;
    max-width: 40px !important;
    padding: 0 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 1.15rem !important;
  }

  /* Form Tables inside Modals (e.g. Órdenes de Compra ítems, Recepción Pañol, Carga Lotes):
     Preserves clean horizontal table format with column headers and touch-friendly controls */
  .modal-form-table {
    display: table !important;
    width: 100% !important;
    border-collapse: collapse !important;
  }
  .modal-form-table thead {
    display: table-header-group !important;
  }
  .modal-form-table thead tr {
    display: table-row !important;
    position: static !important;
  }
  .modal-form-table tbody {
    display: table-row-group !important;
  }
  .modal-form-table tbody tr {
    display: table-row !important;
    background: transparent !important;
    border: none !important;
    border-bottom: 1px solid var(--border-color) !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    margin-bottom: 0 !important;
    padding: 0 !important;
  }
  .modal-form-table td,
  .modal-form-table th {
    display: table-cell !important;
    padding: 6px 8px !important;
    position: static !important;
    border-top: none !important;
    box-shadow: none !important;
    white-space: normal !important;
    width: auto !important;
  }
  .modal-form-table td:last-child {
    display: table-cell !important;
    border-top: none !important;
    box-shadow: none !important;
    margin-top: 0 !important;
    padding-top: 6px !important;
    width: 50px !important;
    text-align: center !important;
  }
  .modal-form-table td:last-child button,
  .modal-form-table td:last-child .touch-btn {
    flex: none !important;
    min-height: 28px !important;
    width: auto !important;
    padding: 2px 6px !important;
  }

  /* Mobile Modals (iOS Bottom Sheet & Safe Area Inset) */
  .modal-overlay {
    padding: 0 !important;
    align-items: flex-end !important;
    position: fixed !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    height: 100dvh !important;
    background: rgba(15, 23, 42, 0.7) !important;
    backdrop-filter: blur(4px) !important;
    -webkit-backdrop-filter: blur(4px) !important;
    z-index: 10005 !important;
    overscroll-behavior: contain !important;
  }
  .modal-card {
    max-width: 100% !important;
    width: 100% !important;
    max-height: calc(92dvh - env(safe-area-inset-top, 0px)) !important;
    border-radius: 20px 20px 0 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    box-shadow: 0 -6px 30px rgba(0, 0, 0, 0.3) !important;
  }
  .modal-header {
    flex-shrink: 0 !important;
    padding: 0.85rem 1rem !important;
    border-radius: 20px 20px 0 0 !important;
  }
  .modal-body {
    flex: 1 1 auto !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    overscroll-behavior: contain !important;
    padding: 0.85rem 1rem !important;
    max-height: none !important;
  }
  .modal-footer {
    flex-shrink: 0 !important;
    padding: 0.75rem 1rem !important;
    padding-bottom: calc(0.85rem + env(safe-area-inset-bottom, 20px)) !important;
    background: var(--bg-card) !important;
    border-top: 1px solid var(--border-color) !important;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.05) !important;
    display: flex !important;
    justify-content: flex-end !important;
    gap: 0.5rem !important;
  }
  #modalSignature .modal-card {
    max-width: 100% !important;
    width: 100% !important;
  }

  /* Distribución de formularios en 1 columna en móviles para evitar saltos de línea */
  .modal-body [style*="grid-template-columns: 1fr 1fr"],
  .modal-body [style*="grid-template-columns: 1fr 1fr 1fr"],
  .modal-body [style*="grid-template-columns: repeat(2"],
  .modal-body [style*="grid-template-columns: repeat(3"],
  .modal-body .form-row,
  .modal-body .form-grid-2 {
    display: flex !important;
    flex-direction: column !important;
    gap: 0.65rem !important;
  }
  .modal-body .form-group {
    margin-bottom: 0.65rem !important;
  }
  .modal-body .form-group label {
    margin-bottom: 0.3rem !important;
    font-size: 0.85rem !important;
    font-weight: 700 !important;
  }

  /* Evitar auto-zoom molesto en Safari de iOS */
  input, select, textarea, .form-control {
    font-size: 16px !important;
  }
}

/* Emergency Alarm & Siren Keyframes */
@keyframes emergencyPulse {
  0% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.7); filter: brightness(1); }
  50% { box-shadow: 0 0 20px 8px rgba(220, 38, 38, 0.5); filter: brightness(1.2); }
  100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); filter: brightness(1); }
}

@keyframes rotateSiren {
  0% { transform: scale(1) rotate(0deg); }
  25% { transform: scale(1.15) rotate(-15deg); }
  75% { transform: scale(1.15) rotate(15deg); }
  100% { transform: scale(1) rotate(0deg); }
}

/* ============================================================================
   NOTIFICATION BELL & SYSTEM NOTIFICATIONS CENTER
   ============================================================================ */
.notif-bell-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, background-color 0.2s ease;
}

.notif-bell-btn:active {
  transform: scale(0.95);
}

.mobile-notif-btn {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  min-height: 40px;
  min-width: 44px;
  padding: 0.35rem 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.notif-badge {
  position: absolute;
  top: -4px;
  right: -6px;
  background: #dc2626;
  color: #ffffff;
  font-size: 0.7rem;
  font-weight: 800;
  line-height: 1;
  padding: 2px 5px;
  border-radius: 10px;
  min-width: 17px;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  border: 1.5px solid white;
}

.notif-badge.has-emergency {
  animation: badgeBlink 1s infinite alternate;
}

@keyframes badgeBlink {
  from { background-color: #dc2626; transform: scale(1); }
  to { background-color: #ef4444; transform: scale(1.2); }
}

.notif-card {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 0.85rem 1rem;
  border-radius: 8px;
  margin-bottom: 0.65rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  transition: all 0.2s ease;
  cursor: pointer;
  position: relative;
}

.notif-card:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
}

.notif-card.unread {
  background: #f8fafc;
  border-left: 4px solid var(--primary);
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.notif-card.emergencia {
  background: #fff5f5;
  border-left: 5px solid #dc2626;
  border-color: #fecaca;
}

.notif-card.emergencia:hover {
  background: #fee2e2;
}

.notif-card.ot-asignada {
  border-left: 4px solid #0284c7;
}

.notif-icon-circle {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  background: #e2e8f0;
}

.notif-card.emergencia .notif-icon-circle {
  background: #fee2e2;
  color: #dc2626;
}

.notif-card.ot-asignada .notif-icon-circle {
  background: #e0f2fe;
  color: #0369a1;
}

.notif-content {
  flex: 1;
}

.notif-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.notif-title {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-main);
}

.notif-card.emergencia .notif-title {
  color: #991b1b;
}

.notif-date {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.notif-msg {
  font-size: 0.82rem;
  color: #475569;
  line-height: 1.35;
  margin-bottom: 0.4rem;
}

.notif-tag {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  background: #e2e8f0;
  color: #334155;
}

.notif-card.emergencia .notif-tag {
  background: #dc2626;
  color: white;
}

.notif-card.ot-asignada .notif-tag {
  background: #0284c7;
  color: white;
}

@media (max-width: 900px) {
  .notif-card {
    padding: 0.75rem 0.85rem !important;
    gap: 0.65rem !important;
  }
  .notif-title-row {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 3px !important;
  }
  .notif-title {
    font-size: 0.88rem !important;
    line-height: 1.25 !important;
    white-space: normal !important;
    word-break: break-word !important;
  }
  .notif-date {
    font-size: 0.7rem !important;
  }
  .notif-msg {
    font-size: 0.8rem !important;
    line-height: 1.35 !important;
  }
}
