/* --- Shared SaaS Buttons & Search Controls --- */
.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 16px;
  background-color: #ffffff;
  color: #0f172a;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.btn-secondary:hover {
  background-color: #f8fafc;
  border-color: #cbd5e1;
}

.table-controls-header {
  padding: 16px 24px;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.search-box-wrapper {
  position: relative;
  width: 100%;
  max-width: 300px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
  pointer-events: none;
}

.search-box-wrapper input {
  width: 100%;
  height: 38px;
  padding: 0 12px 0 38px;
  font-size: 0.85rem;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #f8fafc;
  color: #0f172a;
  outline: none;
  font-family: inherit;
  transition: all 0.15s ease;
}

.search-box-wrapper input:focus {
  background: #ffffff;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

/* --- Modern SaaS Table Container --- */
.table-card {
  background: var(--bg-surface, #ffffff);
  border: 1px solid #edf2f7;
  border-radius: var(--radius-lg, 12px);
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.04), 0 1px 2px -1px rgba(0, 0, 0, 0.02);
  overflow: hidden;
  margin-bottom: 24px;
}

/* Scrollable container with sticky header support */
.table-responsive {
  width: 100%;
  max-height: 620px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

/* Custom subtle scrollbar */
.table-responsive::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
.table-responsive::-webkit-scrollbar-track {
  background: transparent;
}
.table-responsive::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 9999px;
}

/* --- Table Structure --- */
.saas-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  text-align: left;
  font-size: 0.875rem;
  min-width: 780px;
}

/* Sticky Header */
.saas-table thead {
  position: sticky;
  top: 0;
  z-index: 10;
}

.saas-table th {
  background: #f8fafc;
  padding: 14px 20px;
  font-size: 0.725rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
  border-bottom: 1px solid #e2e8f0;
  white-space: nowrap;
}

/* Softer Borders & Better Spacing */
.saas-table td {
  padding: 16px 20px;
  vertical-align: middle;
  border-bottom: 1px solid #f1f5f9;
  color: #1e293b;
  font-weight: 400;
}

/* Zebra Striping */
.saas-table tbody tr:nth-child(even) {
  background-color: #fafbfc;
}
.saas-table tbody tr:nth-child(odd) {
  background-color: #ffffff;
}

/* Smooth Row Hover */
.saas-table tbody tr {
  transition: background-color 0.15s ease, box-shadow 0.15s ease;
}

.saas-table tbody tr:hover {
  background-color: #f1f5f9;
}

/* Remove bottom border on last row */
.saas-table tbody tr:last-child td {
  border-bottom: none;
}

/* --- Status Badges --- */
.badge-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}

.badge-status::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.badge-optimal {
  background-color: #ecfdf5;
  color: #047857;
  border: 1px solid #a7f3d0;
}
.badge-optimal::before {
  background-color: #10b981;
}

.badge-low {
  background-color: #fffbeb;
  color: #b45309;
  border: 1px solid #fde68a;
}
.badge-low::before {
  background-color: #f59e0b;
}

.badge-out {
  background-color: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
}
.badge-out::before {
  background-color: #ef4444;
}

/* --- Modern Action Buttons --- */
.table-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  transition: all 0.15s ease;
}

.action-btn svg {
  width: 15px;
  height: 15px;
}

.action-btn-edit {
  color: #2563eb;
  background: #eff6ff;
  border-color: #dbeafe;
}
.action-btn-edit:hover {
  background: #2563eb;
  color: #ffffff;
}

.action-btn-delete {
  color: #dc2626;
  background: #fef2f2;
  border-color: #fee2e2;
}
.action-btn-delete:hover {
  background: #dc2626;
  color: #ffffff;
}
/* ==========================================================================
   GLOBAL THEME (DARK MODE) & VIEW DENSITY ENGINE
   ========================================================================== */
.theme-controls-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.theme-toggle-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--text-main, #0f172a);
  background: var(--bg-page, #f8fafc);
  border: 1px solid var(--border-subtle, #e2e8f0);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.theme-toggle-btn:hover {
  border-color: #3b82f6;
}

/* Compact Density Mode */
body.density-compact .main-content {
  padding: 18px 24px;
}

body.density-compact .kpi-grid {
  gap: 12px;
  margin-bottom: 18px;
}

body.density-compact .kpi-card {
  padding: 14px 16px;
}

body.density-compact .kpi-value {
  font-size: 1.35rem;
}

body.density-compact .panel {
  padding: 16px;
  margin-bottom: 16px;
}

body.density-compact .saas-table th {
  padding: 9px 14px;
}

body.density-compact .saas-table td {
  padding: 10px 14px;
  font-size: 0.82rem;
}

/* Dark Mode Theme Overrides */
body.dark-mode {
  --bg-page: #0b1120;
  --bg-canvas: #0b1120;
  --bg-card: #111827;
  --bg-surface: #111827;
  --border-subtle: #1f2937;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --primary-light: rgba(59, 130, 246, 0.16);
  --brand-surface: rgba(59, 130, 246, 0.16);
  background-color: #0b1120 !important;
  color: #f1f5f9 !important;
}

body.dark-mode .sidebar,
body.dark-mode .panel,
body.dark-mode .kpi-card,
body.dark-mode .insight-card,
body.dark-mode .cp-action-card,
body.dark-mode .purchase-form-panel,
body.dark-mode .sales-form-panel,
body.dark-mode .vending-form-panel,
body.dark-mode .table-card {
  background-color: #111827 !important;
  border-color: #1f2937 !important;
  color: #f1f5f9 !important;
}

body.dark-mode .sidebar-brand,
body.dark-mode .sidebar-footer,
body.dark-mode .panel-header,
body.dark-mode .table-controls-header,
body.dark-mode .cp-card-header {
  border-color: #1f2937 !important;
}

body.dark-mode h1,
body.dark-mode h2,
body.dark-mode h3,
body.dark-mode h4,
body.dark-mode .brand-text,
body.dark-mode .kpi-value,
body.dark-mode td strong {
  color: #f8fafc !important;
}

body.dark-mode .nav-item:hover:not(.disabled) {
  background-color: #1e293b !important;
  color: #f8fafc !important;
}

body.dark-mode .nav-item.active {
  background-color: rgba(59, 130, 246, 0.18) !important;
  color: #60a5fa !important;
}

body.dark-mode input,
body.dark-mode select,
body.dark-mode .search-box-wrapper input,
body.dark-mode .filter-input-wrapper input,
body.dark-mode .filter-input-wrapper select,
body.dark-mode .btn-secondary,
body.dark-mode .btn-action-reset,
body.dark-mode .theme-toggle-btn,
body.dark-mode .sync-badge {
  background-color: #1e293b !important;
  border-color: #334155 !important;
  color: #f1f5f9 !important;
}

body.dark-mode .saas-table th {
  background-color: #0f172a !important;
  border-color: #1f2937 !important;
  color: #94a3b8 !important;
}

body.dark-mode .saas-table td {
  border-color: #1f2937 !important;
  color: #e2e8f0 !important;
}

body.dark-mode .saas-table tbody tr:nth-child(odd) {
  background-color: #111827 !important;
}

body.dark-mode .saas-table tbody tr:nth-child(even) {
  background-color: #0f172a !important;
}

body.dark-mode .saas-table tbody tr:hover {
  background-color: #1e293b !important;
}

body.dark-mode .badge {
  background-color: #1e293b !important;
  border-color: #334155 !important;
  color: #cbd5e1 !important;
}

body.dark-mode #pickListModal > div {
  background-color: #111827 !important;
  border: 1px solid #334155;
}

body.dark-mode #pickListModal > div > div:last-child {
  background-color: #0f172a !important;
  border-color: #1f2937 !important;
}
/* ==========================================================================
   MOBILE RESPONSIVE & APP SHELL (iOS / ANDROID / CAPACITOR READY)
   ========================================================================== */
.mobile-top-bar {
  display: none;
}

.sidebar-backdrop {
  display: none;
}

@media (max-width: 860px) {
  body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .app-layout {
    flex-direction: column;
  }

  /* Barra superior fija para móvil */
  .mobile-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 900;
    height: 58px;
    padding: 0 16px;
    background: var(--bg-card, #ffffff);
    border-bottom: 1px solid var(--border-subtle, #e2e8f0);
  }

  body.dark-mode .mobile-top-bar {
    background: #111827;
    border-color: #1f2937;
  }

  .mobile-brand-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-main, #0f172a);
  }

  body.dark-mode .mobile-brand-wrap {
    color: #f8fafc;
  }

  .mobile-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: 1px solid var(--border-subtle, #e2e8f0);
    background: var(--bg-page, #f8fafc);
    color: var(--text-main, #0f172a);
    font-size: 1.25rem;
    cursor: pointer;
  }

  body.dark-mode .mobile-menu-btn {
    background: #1e293b;
    border-color: #334155;
    color: #f1f5f9;
  }

  /* Menú lateral convertido en cajón deslizable (Drawer) */
  .sidebar {
    position: fixed !important;
    top: 0;
    left: -280px;
    width: 265px !important;
    height: 100vh !important;
    z-index: 1000;
    transition: left 0.25s ease;
    box-shadow: 8px 0 24px rgba(0, 0, 0, 0.22);
    overflow-y: auto;
  }

  .sidebar.mobile-open {
    left: 0;
  }

  .sidebar-backdrop.active {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    z-index: 950;
    backdrop-filter: blur(2px);
  }

  /* Contenido principal adaptado a pantalla vertical */
  .main-content {
    margin-left: 0 !important;
    width: 100% !important;
    padding: 16px !important;
  }

  .top-header {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 12px;
  }

  .header-actions {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .header-actions button,
  .header-actions a {
    flex: 1;
    justify-content: center;
    text-align: center;
  }

  .kpi-grid,
  .grid-two-column,
  .charts-grid,
  .cp-row-2 {
    grid-template-columns: 1fr !important;
  }

  /* Tablas con desplazamiento horizontal táctil */
  .table-responsive,
  .table-card {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .saas-table {
    min-width: 640px;
  }
}