/* Dashboard Layout Variables */
:root {
  --sidebar-width: 250px;
  --header-height: 65px;
}

@media (min-width: 1024px) {
  :root {
    --sidebar-width: 220px;
    --header-height: 55px;
  }
}

.dashboard-body {
  background-color: var(--color-bg);
  overflow: hidden; /* Prevent body scroll, layout handles it */
}

.dashboard-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background-color: var(--color-sidebar-bg);
  color: var(--color-sidebar-text);
  display: flex;
  flex-direction: column;
  transition: all 0.3s ease;
  z-index: 10;
  box-shadow: 2px 0 10px rgba(0,0,0,0.1);
}

.sidebar-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  position: relative;
}

.sidebar-logo {
  max-width: 130px;
  transition: all 0.3s ease;
}

.sidebar-toggle {
  background: transparent;
  border: none;
  color: var(--color-sidebar-text);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.4rem;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.sidebar-toggle:hover {
  background-color: rgba(255,255,255,0.05);
  color: var(--color-primary);
}

.sidebar-nav {
  flex: 1;
  padding: 0.5rem 0;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Custom Scrollbar for Sidebar */
.sidebar-nav::-webkit-scrollbar {
  width: 5px;
}
.sidebar-nav::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.1);
}
.sidebar-nav::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 10px;
}
.sidebar-nav::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

.sidebar-nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar-category-header {
  padding: 0.85rem 1rem 0.25rem 1.15rem;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(255, 255, 255, 0.35);
  pointer-events: none;
  transition: all 0.3s ease;
  white-space: nowrap;
}

.nav-item {
  display: flex;
  align-items: center;
  padding: 0.45rem 1.15rem;
  color: var(--color-sidebar-text);
  font-weight: 500;
  transition: all 0.2s ease;
  border-left: 3px solid transparent;
  text-decoration: none;
  white-space: nowrap;
}

.nav-item i {
  margin-right: 0.6rem;
  font-size: 1.15rem;
  flex-shrink: 0;
  transition: margin 0.3s ease;
}

.nav-text {
  opacity: 1;
  transition: opacity 0.2s ease;
  font-size: 0.875rem;
}

.nav-item:hover, .nav-item.active {
  background-color: rgba(255,255,255,0.05);
  color: var(--color-primary);
}

.nav-item.active {
  border-left-color: var(--color-primary);
  background: linear-gradient(90deg, rgba(5,250,147,0.1) 0%, transparent 100%);
}

.sidebar-submenu {
  display: none;
  background: rgba(0, 0, 0, 0.2);
  padding: 0.5rem 0;
}

.sidebar-submenu.active {
  display: block;
}

.sidebar-submenu .nav-item {
  padding: 0.45rem 1.5rem 0.45rem 2.8rem;
  font-size: 0.8rem;
}

.sidebar-footer {
  padding: 1.25rem 1rem;
  border-top: 1px solid rgba(255,255,255,0.1);
  transition: all 0.3s ease;
}

.sidebar-footer .btn:hover {
  background-color: rgba(255,255,255,0.1);
}

/* Collapsed State Styles */
.sidebar.collapsed {
  --sidebar-width: 70px;
}

.sidebar.collapsed .sidebar-header {
  justify-content: center;
  padding: 0;
}

.sidebar.collapsed .sidebar-logo {
  display: none;
}

.sidebar.collapsed .sidebar-category-header {
  padding: 0;
  margin: 0.5rem 0;
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  color: transparent;
  font-size: 0;
}

.menu-badge {
  background-color: #ef4444; /* danger color */
  color: white;
  border-radius: 12px;
  padding: 0.1rem 0.4rem;
  font-size: 0.7rem;
  font-weight: 700;
  margin-left: auto;
  min-width: 1.25rem;
  text-align: center;
  line-height: 1.2;
}

.float-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  border: 2px solid var(--color-bg);
}

.sidebar.collapsed .sidebar-nav {
  overflow: visible;
}

.sidebar.collapsed .nav-text {
  display: none;
}

.sidebar.collapsed .menu-badge {
  display: none !important;
}

.sidebar.collapsed .nav-item {
  justify-content: center;
  padding: 0.75rem 0;
  position: relative;
}

.sidebar.collapsed .nav-item:hover .nav-text {
  display: flex;
  position: absolute;
  left: 70px;
  background-color: var(--color-surface);
  color: var(--color-primary);
  padding: 0.5rem 1rem;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  white-space: nowrap;
  box-shadow: 4px 0 10px rgba(0,0,0,0.2);
  z-index: 9999;
  border: 1px solid var(--color-border);
  border-left: none;
  align-items: center;
  font-weight: 600;
  font-size: 0.85rem;
}

.sidebar.collapsed .nav-item i {
  margin-right: 0;
}

.sidebar.collapsed .sidebar-footer {
  padding: 1rem 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.sidebar.collapsed #logout-btn,
.sidebar.collapsed #sidebar-support-btn {
  width: 40px !important;
  height: 40px;
  padding: 0 !important;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar.collapsed #logout-btn .nav-text,
.sidebar.collapsed #sidebar-support-btn .nav-text {
  display: none;
}

.sidebar.collapsed #logout-btn i,
.sidebar.collapsed #sidebar-support-btn i {
  margin: 0;
  font-size: 1.2rem;
}

/* Main Content area */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0; /* Important for flex children to allow text truncation */
}

/* Header */
.top-header {
  height: var(--header-height);
  background-color: var(--color-surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  border-bottom: 1px solid var(--color-border);
  position: relative;
  z-index: 100;
  gap: 1rem;
}

.header-title h2 {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 0;
  color: var(--color-text-main);
  letter-spacing: -0.01em;
}

/* Header right-side action cluster */
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Vertical divider between header sections */
.header-divider {
  width: 1px;
  height: 22px;
  background-color: var(--color-border);
  margin: 0 0.5rem;
  border-radius: 1px;
}

/* UF chip */
.uf-chip {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.7rem;
  border-radius: 99px;
  background: var(--color-surface-hover);
  border: 1px solid var(--color-border);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text-main);
  white-space: nowrap;
  transition: background 0.2s;
}

.uf-chip .uf-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-primary);
}

.uf-chip .uf-icon {
  font-size: 0.85rem;
  color: var(--color-primary);
}

/* Date chip */
.date-chip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  border-radius: 99px;
  background: var(--color-surface-hover);
  border: 1px solid var(--color-border);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--color-text-main);
  white-space: nowrap;
  transition: background 0.2s;
}

.date-chip i {
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

.date-chip .date-day {
  font-weight: 700;
  color: var(--color-text-main);
}

.date-chip .date-rest {
  color: var(--color-text-muted);
  font-weight: 400;
}

/* Icon action buttons in header */
.header-icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: transparent;
  border: 1px solid transparent;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 1.15rem;
  position: relative;
}

.header-icon-btn:hover {
  background: var(--color-surface-hover);
  border-color: var(--color-border);
  color: var(--color-text-main);
}

.header-user {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.header-user span {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--color-text-main);
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 0.8rem;
  flex-shrink: 0;
  border: 2px solid var(--color-border);
}

/* Content Area */
.content-area {
  flex: 1;
  padding: 2rem;
  overflow-y: auto;
}

/* Components (Cards & Tables) */
.card {
  background-color: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: 2rem;
  border: 1px solid var(--color-border);
  overflow: clip;
}

.card-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--color-border);
  background-color: var(--color-surface-hover);
}

.card-header h3 {
  font-size: 1.125rem;
  margin: 0;
}

.card-body {
  padding: 1.5rem;
}

/* Data Table */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th, .data-table td {
  padding: 1rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.875rem;
}

.table-responsive {
  width: 100%;
  overflow: auto;
  max-height: calc(100vh - 240px);
  padding-bottom: 90px !important;
}

.data-table th {
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  background-color: var(--color-surface) !important;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 1px 0 var(--color-border);
}

/* Fix for two-row sticky headers in billing */
.data-table.billing-table thead tr:nth-child(2) th {
  top: 38px; /* Approx height of first row */
  z-index: 9;
}

/* Column Group Styling */
td.col-group-fulf {
  background-color: rgba(59, 130, 246, 0.02) !important;
}
td.col-group-env {
  background-color: rgba(16, 185, 129, 0.02) !important;
}
.col-group-divider {
  border-right: 1px solid var(--color-border) !important;
}
.data-table tbody tr:hover td.col-group-fulf {
  background-color: rgba(59, 130, 246, 0.05) !important;
}
.data-table tbody tr:hover td.col-group-env {
  background-color: rgba(16, 185, 129, 0.05) !important;
}

/* Ensure ALL th elements have solid backgrounds so sticky works properly */
.data-table th.col-group-fulf,
.data-table th.col-group-env,
.th-group-fulf,
.th-group-env {
  background-color: var(--color-surface) !important;
}

.th-group-fulf {
  color: #60a5fa !important;
  border-bottom: 2px solid #3b82f6 !important;
}
.th-group-env {
  color: #34d399 !important;
  border-bottom: 2px solid #10b981 !important;
}

.data-table tbody tr {
  transition: background-color 0.2s ease;
}

.data-table tbody tr:hover {
  background-color: var(--color-surface-hover);
}

/* Status Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-success {
  background-color: var(--badge-success-bg);
  color: var(--badge-success-text);
}

.badge-warning {
  background-color: var(--badge-warning-bg);
  color: var(--badge-warning-text);
}

.badge-danger {
  background-color: var(--badge-danger-bg);
  color: var(--badge-danger-text);
}

.badge-info {
  background-color: var(--badge-info-bg);
  color: var(--badge-info-text);
}

.badge-neutral {
  background-color: var(--badge-neutral-bg);
  color: var(--badge-neutral-text);
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: var(--color-surface);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  transform: translateY(20px) scale(0.95);
  transition: all 0.3s ease;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-overlay.active .modal-content {
  transform: translateY(0) scale(1);
}

.modal-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.25rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--color-text-muted);
}

.modal-content > form {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 1.25rem 1.5rem;
  background: var(--color-surface-hover);
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
  flex-shrink: 0;
}

/* Wider modal for edit product */
#modal-edit-product .modal-content {
  max-width: 750px;
}

/* Searchable dropdown */
.searchable-select-wrapper {
  position: relative;
  flex: 1;
}

.searchable-select-wrapper input.searchable-select-input {
  width: 100%;
  height: 38px;
  padding: 0.5rem 2rem 0.5rem 0.75rem;
  background: var(--color-surface);
  color: var(--color-text-main);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  box-sizing: border-box;
}

.searchable-select-wrapper input.searchable-select-input:focus {
  border-color: var(--color-primary);
  outline: none;
  box-shadow: 0 0 0 2px rgba(59,130,246,0.15);
}

.searchable-select-wrapper .searchable-select-arrow {
  position: absolute;
  right: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--color-text-muted);
  font-size: 1rem;
}

.searchable-select-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 200px;
  overflow-y: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-primary);
  border-top: none;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  z-index: 100;
  box-shadow: var(--shadow-md);
}

.searchable-select-dropdown.open {
  display: block;
}

.searchable-select-option {
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--color-text-main);
  transition: background 0.15s;
  border-bottom: 1px solid var(--color-border);
}

.searchable-select-option:last-child {
  border-bottom: none;
}

.searchable-select-option:hover,
.searchable-select-option.highlighted {
  background: rgba(59,130,246,0.1);
  color: var(--color-primary);
}

.searchable-select-option .sku-hint {
  font-family: monospace;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-left: 0.25rem;
}

/* Table Action Menu (Hover Dropdown) */
.table-action-menu {
  position: relative;
  display: inline-block;
}

.table-action-menu-btn {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.35rem 0.5rem;
  color: var(--color-text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  transition: all 0.2s ease;
  font-family: var(--font-family);
}

.table-action-menu-btn:hover {
  background: var(--color-surface-hover);
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.table-action-menu-content {
  display: none;
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 0.25rem;
  background-color: var(--color-surface);
  min-width: 130px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  z-index: 50;
  padding: 0.25rem 0;
}
.table-action-menu-content.show {
  display: block;
}
/* Open upwards for the last 3 rows to prevent clipping by overflow container,
   but ONLY if they are not among the first 2 rows of the table */
tr:nth-child(n+3):last-child .table-action-menu-content,
tr:nth-child(n+3):nth-last-child(2) .table-action-menu-content,
tr:nth-child(n+3):nth-last-child(3) .table-action-menu-content {
  top: auto;
  bottom: 100%;
  margin-top: 0;
  margin-bottom: 0.25rem;
}

.table-action-menu-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  width: 100%;
  border: none;
  background: none;
  text-align: left;
  font-size: 0.75rem;
  color: var(--color-text-main);
  cursor: pointer;
  transition: background-color 0.2s;
  font-family: var(--font-family);
}

.table-action-menu-item:hover {
  background-color: var(--color-surface-hover);
}

.table-action-menu-item i {
  font-size: 0.9rem;
}

.table-action-menu-item.danger {
  color: var(--color-danger);
}

.table-action-menu-item.danger:hover {
  background-color: rgba(239, 68, 68, 0.1);
}

/* Floating Support Button */
.floating-support-btn {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  z-index: 1000;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  text-decoration: none;
}

.floating-support-btn::after {
  content: 'Soporte';
  position: absolute;
  right: 70px;
  background-color: var(--color-surface);
  color: var(--color-text-main);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transform: translateX(10px);
  transition: all 0.3s ease;
  white-space: nowrap;
  border: 1px solid var(--color-border);
}

.floating-support-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  color: white;
}

.floating-support-btn:hover::after {
  opacity: 1;
  transform: translateX(0);
}

/* ============================================= */
/* Floating Scroll To Top Button                 */
/* ============================================= */
.scroll-to-top-btn {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full, 50%);
  background-color: var(--color-surface, #ffffff);
  color: var(--color-primary, #2563eb);
  border: 1px solid var(--color-border, #cbd5e1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
  cursor: pointer;
  z-index: 998;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(16px) scale(0.85);
  transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1),
              visibility 0.3s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.3s cubic-bezier(0.16, 1, 0.3, 1),
              background-color 0.2s ease,
              color 0.2s ease,
              border-color 0.2s ease,
              box-shadow 0.2s ease;
  outline: none;
  text-decoration: none;
  user-select: none;
}

/* Offset to sit beside the support button if present */
body:has(.floating-support-btn) .scroll-to-top-btn,
.scroll-to-top-btn.has-support-btn {
  right: calc(2rem + 60px + 14px);
}

.scroll-to-top-btn.visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.scroll-to-top-btn:hover {
  background-color: var(--color-primary, #2563eb);
  color: #ffffff;
  border-color: var(--color-primary, #2563eb);
  transform: translateY(-3px) scale(1.06);
  box-shadow: 0 8px 22px rgba(37, 99, 235, 0.38);
}

.scroll-to-top-btn:active {
  transform: translateY(0) scale(0.95);
}

/* Tooltip on hover */
.scroll-to-top-btn::after {
  content: 'Volver arriba';
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background-color: var(--color-surface, #ffffff);
  color: var(--color-text-main, #0f172a);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-md, 6px);
  font-size: 0.75rem;
  font-weight: 600;
  box-shadow: var(--shadow-md, 0 4px 6px -1px rgba(0, 0, 0, 0.1));
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s ease;
  white-space: nowrap;
  border: 1px solid var(--color-border, #cbd5e1);
}

.scroll-to-top-btn:hover::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 768px) {
  .scroll-to-top-btn {
    bottom: 1.25rem;
    right: 1.25rem;
    width: 44px;
    height: 44px;
    font-size: 1.25rem;
  }

  body:has(.floating-support-btn) .scroll-to-top-btn,
  .scroll-to-top-btn.has-support-btn {
    right: calc(1.25rem + 54px + 10px);
  }

  .scroll-to-top-btn::after {
    display: none;
  }
}

/* ============================================= */
/* SweetAlert2 Dark Mode Overrides               */
/* ============================================= */

.swal2-popup {
  background: var(--color-surface) !important;
  color: var(--color-text-main) !important;
  border: 1px solid var(--color-border) !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5) !important;
}

.swal2-title {
  color: var(--color-text-main) !important;
  font-size: 1.25rem !important;
  font-weight: 700 !important;
}

.swal2-html-container {
  color: var(--color-text) !important;
}

.swal2-close {
  color: var(--color-text-muted) !important;
  transition: color 0.2s !important;
}

.swal2-close:hover {
  color: var(--color-danger) !important;
}

/* Inputs inside SweetAlert */
.swal2-input,
.swal2-textarea,
.swal2-select,
.swal2-popup input.swal2-input {
  background: var(--color-bg) !important;
  color: var(--color-text-main) !important;
  border: 1px solid var(--color-border) !important;
  border-radius: var(--radius-md) !important;
  font-size: 0.9rem !important;
}

.swal2-input::placeholder,
.swal2-textarea::placeholder {
  color: var(--color-text-muted) !important;
}

.swal2-input:focus,
.swal2-textarea:focus {
  border-color: var(--color-primary) !important;
  box-shadow: 0 0 0 2px rgba(59,130,246,0.15) !important;
  outline: none !important;
}

/* Buttons */
.swal2-confirm.swal2-styled {
  background: var(--color-primary) !important;
  color: white !important;
  border: none !important;
  border-radius: var(--radius-md) !important;
  font-weight: 600 !important;
  transition: opacity 0.2s !important;
}

.swal2-confirm.swal2-styled:hover {
  opacity: 0.9 !important;
}

.swal2-cancel.swal2-styled {
  background: var(--color-surface-hover) !important;
  color: var(--color-text) !important;
  border: 1px solid var(--color-border) !important;
  border-radius: var(--radius-md) !important;
  font-weight: 500 !important;
}

.swal2-deny.swal2-styled {
  background: var(--color-danger) !important;
  border-radius: var(--radius-md) !important;
}

/* Content items inside popups (list rows) */
.swal2-html-container div[style*="background:rgba(0,0,0,0.05)"] {
  background: var(--color-bg) !important;
  border: 1px solid var(--color-border) !important;
}

/* Scrollable list containers inside Swal */
.swal2-html-container div[style*="border: 1px solid var(--color-border)"] {
  background: var(--color-bg) !important;
}

/* SweetAlert2 backdrop - strictly for centered/modal dialogs, NEVER for toasts */
.swal2-container.swal2-backdrop-show:not(.swal2-top-end):not(.swal2-top-start):not(.swal2-bottom-end):not(.swal2-bottom-start):not(.swal2-toast-shown):not(:has(.swal2-toast)) {
  backdrop-filter: blur(4px) !important;
  background: rgba(0, 0, 0, 0.5) !important;
}

body.swal2-toast-shown .swal2-container,
.swal2-container:has(.swal2-toast) {
  background: transparent !important;
  backdrop-filter: none !important;
  pointer-events: none !important;
}

body.swal2-toast-shown .swal2-popup.swal2-toast,
.swal2-container .swal2-popup.swal2-toast {
  pointer-events: auto !important;
}

/* ============================================= */
/* Stocka Floating Toast Notifications (StockaToast) */
/* ============================================= */
.stocka-toast-container {
  position: fixed;
  top: 1.25rem;
  right: 1.25rem;
  z-index: 999999;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  pointer-events: none;
  max-width: 440px;
  width: calc(100vw - 2.5rem);
}

.stocka-toast {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.9rem 1.1rem 1rem 1rem;
  background: #ffffff;
  color: var(--color-text-main, #1e293b);
  border: 1px solid var(--color-border, #e2e8f0);
  border-radius: 12px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
  pointer-events: auto;
  overflow: hidden;
  box-sizing: border-box;
  animation: stockaToastSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transition: transform 0.25s ease, opacity 0.25s ease, margin 0.25s ease, max-height 0.25s ease;
  max-height: 300px;
}

.stocka-toast.stocka-toast-closing {
  transform: translateX(110%);
  opacity: 0;
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  margin-bottom: -0.75rem;
  border-width: 0;
}

@keyframes stockaToastSlideIn {
  from {
    transform: translateX(110%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* Icon container with soft circular badge */
.stocka-toast-icon-wrap {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  margin-top: 0.05rem;
}

.stocka-toast-success .stocka-toast-icon-wrap {
  background: #ecfdf5;
  color: #10b981;
}

.stocka-toast-error .stocka-toast-icon-wrap {
  background: #fef2f2;
  color: #ef4444;
}

.stocka-toast-warning .stocka-toast-icon-wrap {
  background: #fffbeb;
  color: #f59e0b;
}

.stocka-toast-info .stocka-toast-icon-wrap {
  background: #eff6ff;
  color: #3b82f6;
}

/* Content block: Title + Message cleanly stacked */
.stocka-toast-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.stocka-toast-title {
  font-size: 0.875rem;
  font-weight: 700;
  line-height: 1.35;
  color: var(--color-text-main, #0f172a);
  word-break: break-word;
}

.stocka-toast-message {
  font-size: 0.8rem;
  font-weight: 400;
  line-height: 1.45;
  color: var(--color-text-muted, #64748b);
  word-break: break-word;
  overflow-wrap: break-word;
  white-space: normal;
}

/* Actions block: Action button & Close button */
.stocka-toast-actions {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: 0.25rem;
  margin-top: 0.05rem;
}

.stocka-toast-action-btn {
  background: var(--color-primary, #7117eb);
  color: #ffffff;
  border: none;
  border-radius: 6px;
  font-size: 0.775rem;
  font-weight: 600;
  padding: 0.35rem 0.75rem;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
  white-space: nowrap;
}

.stocka-toast-action-btn:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.stocka-toast-action-btn:active {
  transform: translateY(0);
}

.stocka-toast-close-btn {
  background: transparent;
  border: none;
  color: var(--color-text-muted, #94a3b8);
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1.1rem;
  transition: color 0.2s, background-color 0.2s;
  padding: 0;
}

.stocka-toast-close-btn:hover {
  color: var(--color-text-main, #0f172a);
  background: rgba(0, 0, 0, 0.05);
}

/* Progress bar */
.stocka-toast-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: rgba(0, 0, 0, 0.05);
  overflow: hidden;
}

.stocka-toast-progress-bar {
  height: 100%;
  width: 100%;
  background: var(--color-primary, #7117eb);
}

.stocka-toast-success .stocka-toast-progress-bar {
  background: #10b981;
}

.stocka-toast-error .stocka-toast-progress-bar {
  background: #ef4444;
}

.stocka-toast-warning .stocka-toast-progress-bar {
  background: #f59e0b;
}

.stocka-toast-info .stocka-toast-progress-bar {
  background: #3b82f6;
}

/* Dark Mode Overrides for StockaToast */
[data-theme="dark"] .stocka-toast {
  background: #1e293b;
  border-color: rgba(255, 255, 255, 0.1);
  color: #f8fafc;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .stocka-toast-title {
  color: #ffffff;
}

[data-theme="dark"] .stocka-toast-message {
  color: #94a3b8;
}

[data-theme="dark"] .stocka-toast-close-btn {
  color: #64748b;
}

[data-theme="dark"] .stocka-toast-close-btn:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .stocka-toast-success .stocka-toast-icon-wrap {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
}

[data-theme="dark"] .stocka-toast-error .stocka-toast-icon-wrap {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
}

[data-theme="dark"] .stocka-toast-warning .stocka-toast-icon-wrap {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
}

[data-theme="dark"] .stocka-toast-info .stocka-toast-icon-wrap {
  background: rgba(59, 130, 246, 0.15);
  color: #60a5fa;
}

[data-theme="dark"] .stocka-toast-progress {
  background: rgba(255, 255, 255, 0.05);
}

/* Custom SweetAlert2 Toast Overrides for compact, premium cards (Light/Default Mode) */
.swal2-popup.swal2-toast {
  background: #ffffff !important;
  border: 1px solid var(--color-border) !important;
  border-radius: 12px !important;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.05) !important;
  padding: 0.85rem 1.1rem !important;
  display: grid !important;
  grid-template-columns: auto 1fr auto !important;
  grid-template-rows: auto auto !important;
  grid-template-areas:
    "icon title actions"
    "icon content actions" !important;
  align-items: center !important;
  column-gap: 0.75rem !important;
  row-gap: 0.25rem !important;
  width: auto !important;
  max-width: 440px !important;
  min-width: 320px !important;
  box-sizing: border-box !important;
}

.swal2-popup.swal2-toast .swal2-icon {
  grid-area: icon !important;
  margin: 0 !important;
  align-self: center !important;
  width: 32px !important;
  height: 32px !important;
  font-size: 0.85rem !important;
}

.swal2-popup.swal2-toast .swal2-title {
  grid-area: title !important;
  font-size: 0.875rem !important;
  font-weight: 700 !important;
  color: var(--color-text-main) !important;
  margin: 0 !important;
  padding: 0 !important;
  line-height: 1.35 !important;
  text-align: left !important;
  word-break: break-word !important;
}

.swal2-popup.swal2-toast .swal2-html-container {
  grid-area: content !important;
  font-size: 0.8rem !important;
  color: var(--color-text-muted) !important;
  margin: 0 !important;
  padding: 0 !important;
  text-align: left !important;
  line-height: 1.45 !important;
  word-break: break-word !important;
  overflow-wrap: break-word !important;
  white-space: normal !important;
}

.swal2-popup.swal2-toast .swal2-actions {
  grid-area: actions !important;
  margin: 0 0 0 0.5rem !important;
  padding: 0 !important;
  align-self: center !important;
  display: flex !important;
  align-items: center !important;
  gap: 0.35rem !important;
}

.swal2-popup.swal2-toast .swal2-confirm.swal2-styled {
  margin: 0 !important;
  padding: 0.4rem 0.85rem !important;
  font-size: 0.8rem !important;
  font-weight: 600 !important;
  border-radius: 6px !important;
  background-color: var(--color-primary, #7117eb) !important;
  color: #ffffff !important;
  white-space: nowrap !important;
  box-shadow: none !important;
}

/* Dark Mode Overrides for Toasts */
[data-theme="dark"] .swal2-popup.swal2-toast {
  background: #1e293b !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.3) !important;
}

[data-theme="dark"] .swal2-popup.swal2-toast .swal2-title {
  color: #ffffff !important;
}

[data-theme="dark"] .swal2-popup.swal2-toast .swal2-html-container {
  color: #94a3b8 !important;
}

.swal2-popup.swal2-toast .swal2-success {
  border-color: #22c55e !important;
}

.swal2-popup.swal2-toast .swal2-timer-progress-bar {
  background: var(--color-primary) !important;
  height: 3px !important;
}

/* Icons */
.swal2-icon.swal2-success {
  border-color: #22c55e !important;
  color: #22c55e !important;
}

.swal2-icon.swal2-error {
  border-color: var(--color-danger) !important;
}

.swal2-icon.swal2-warning {
  border-color: #f59e0b !important;
  color: #f59e0b !important;
}

.swal2-icon.swal2-info {
  border-color: var(--color-primary) !important;
  color: var(--color-primary) !important;
}

/* Timer bar */
.swal2-timer-progress-bar {
  background: var(--color-primary) !important;
}

/* ============================================= */
/* Global Dark Mode for Native Selects & Inputs  */
/* ============================================= */

[data-theme="dark"] select,
[data-theme="dark"] select option {
  background-color: var(--color-surface);
  color: var(--color-text-main);
  color-scheme: dark;
}

[data-theme="dark"] input[type="date"],
[data-theme="dark"] input[type="time"],
[data-theme="dark"] input[type="datetime-local"] {
  color-scheme: dark;
}

[data-theme="dark"] select:focus,
[data-theme="dark"] input:focus {
  outline-color: var(--color-primary);
}

/* ============================================= */
/* WMS Order Row Badges Layout                   */
/* ============================================= */

.order-row td {
  border-bottom: none !important;
}

.order-badges-row td {
  border-top: none !important;
  border-bottom: 1px solid var(--color-border) !important;
}

.order-row:hover td,
.order-badges-row:hover td,
.order-row:has(+ .order-badges-row:hover) td,
.order-row:hover + .order-badges-row td {
  background-color: var(--color-surface-hover) !important;
}

/* Mobile Hamburger Button (Hidden on Desktop by default) */
.mobile-menu-toggle {
  display: none !important;
}

/* ============================================= */
/* Mobile Responsive Adjustments (max-width: 768px) */
/* ============================================= */
@media (max-width: 768px) {
  /* Dynamic Hamburger Toggle styling */
  .mobile-menu-toggle {
    display: flex !important;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    font-size: 1.5rem;
    color: var(--color-text-main);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--radius-md);
    transition: background-color 0.2s ease;
    margin-right: 0.5rem;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
  }
  
  .mobile-menu-toggle:hover {
    background-color: var(--color-surface-hover);
    color: var(--color-primary);
  }

  /* Desktop menu collapse button hidden on mobile */
  .sidebar #toggle-sidebar {
    display: none;
  }

  /* Close button on sidebar for mobile */
  .sidebar.mobile-active #toggle-sidebar {
    display: flex !important;
    position: absolute;
    right: 10px;
    top: 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 50%;
    z-index: 1100;
  }

  /* Sidebar drawer layout styling */
  .sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    width: 280px !important;
    height: 100vh !important;
    z-index: 1000 !important;
    transform: translateX(-100%) !important;
    box-shadow: none !important;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    display: flex !important;
    flex-direction: column !important;
  }

  .sidebar.mobile-active {
    transform: translateX(0) !important;
    box-shadow: 5px 0 25px rgba(0, 0, 0, 0.4) !important;
  }

  /* Sidebar Overlay backdrop styling */
  .sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }

  .sidebar-overlay.active {
    opacity: 1;
    pointer-events: auto;
  }

  /* Top header adjustments */
  .top-header {
    height: 55px !important;
    padding: 0 1rem !important;
    gap: 0.5rem !important;
  }

  /* Title optimization to prevent wrap/clipping */
  .header-title h2 {
    font-size: 1rem !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
  }

  /* Hide secondary header widgets on mobile */
  .uf-chip, 
  .date-chip, 
  .header-divider {
    display: none !important;
  }

  /* Hide user name text on mobile, showing only the avatar */
  .header-actions .header-user span {
    display: none !important;
  }
  
  .header-actions {
    gap: 0.25rem !important;
  }

  /* Content area full width */
  .content-area {
    padding: 0.75rem !important;
    width: 100% !important;
    box-sizing: border-box;
  }

  /* Cards optimization on mobile */
  .card {
    border-radius: var(--radius-md) !important;
    margin-bottom: 1rem !important;
  }

  .card-header {
    padding: 1rem !important;
  }

  /* Body optimization: prevent wide elements/tables from breaking layout */
  .card-body {
    padding: 0.75rem !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    width: 100%;
  }

  /* Table responsive scrolling optimization */
  .table-responsive {
    max-height: calc(100vh - 200px) !important;
  }

  /* Filter panels: stack inputs vertically */
  .shipments-filters-panel,
  .filters-panel,
  .filter-row,
  .search-row {
    flex-direction: column !important;
    align-items: stretch !important;
    padding: 1rem !important;
    gap: 0.75rem !important;
  }

  .filter-item, 
  .filter-item-search,
  .search-input-group,
  .filter-select {
    min-width: 100% !important;
    width: 100% !important;
  }

  /* Modal responsive sizing */
  .modal-content {
    max-width: 92% !important;
    margin: 10px auto !important;
    max-height: 92vh !important;
  }

  /* Touch targets minimum height for mobile inputs and buttons */
  .btn, 
  .form-input, 
  .form-select,
  select,
  input[type="text"],
  input[type="search"] {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* On mobile, override collapsed state to always show full menu */
  .sidebar.collapsed {
    width: 280px !important;
  }
  
  .sidebar.collapsed .sidebar-logo {
    display: block !important;
  }
  
  .sidebar.collapsed .sidebar-category-header {
    padding: 0.85rem 1rem 0.25rem 1.15rem !important;
    margin: 0 !important;
    height: auto !important;
    background: transparent !important;
    color: rgba(255, 255, 255, 0.35) !important;
    font-size: 0.65rem !important;
    pointer-events: none !important;
  }
  
  .sidebar.collapsed .nav-text {
    display: inline !important;
  }
  
  .sidebar.collapsed .menu-badge {
    display: inline-flex !important;
  }
  
  .sidebar.collapsed .nav-item {
    justify-content: flex-start !important;
    padding: 0.45rem 1.15rem !important;
    position: static !important;
  }
  
  .sidebar.collapsed .nav-item:hover .nav-text {
    position: static !important;
    background-color: transparent !important;
    color: var(--color-primary) !important;
    padding: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    border: none !important;
  }
  
  .sidebar.collapsed .nav-item i {
    margin-right: 0.6rem !important;
  }
  
  .sidebar.collapsed .sidebar-footer {
    padding: 1.25rem 1rem !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 0.5rem !important;
  }
  
  .sidebar.collapsed #logout-btn,
  .sidebar.collapsed #sidebar-support-btn {
    width: 100% !important;
    height: auto !important;
    padding: 0.5rem 1rem !important;
    border-radius: var(--radius-md) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 0.5rem !important;
  }
  
  .sidebar.collapsed #logout-btn .nav-text,
  .sidebar.collapsed #sidebar-support-btn .nav-text {
    display: inline !important;
  }
  
  .sidebar.collapsed #logout-btn i,
  .sidebar.collapsed #sidebar-support-btn i {
    margin: 0 !important;
  }
}

/* Styling for Support Button in Sidebar to stand out */
#sidebar-support-btn.btn-accent {
  background-color: var(--color-accent) !important;
  color: var(--color-surface) !important;
  font-weight: 600 !important;
  border-left: none !important;
  border: none !important;
  transition: all 0.2s ease-in-out !important;
}

#sidebar-support-btn.btn-accent:hover {
  background-color: var(--color-accent-hover, #4b12bd) !important;
  color: var(--color-surface) !important;
  transform: translateY(-2px) !important;
  box-shadow: var(--shadow-md) !important;
}

#sidebar-support-btn.btn-accent.active {
  background-color: var(--color-accent) !important;
  color: var(--color-surface) !important;
  border-left-color: transparent !important;
  background-image: none !important;
  box-shadow: 0 0 12px rgba(94, 23, 235, 0.4) !important;
}

/* Floating Bulk Actions Bar & Sticky Action Containers */
#wms-sticky-actions-container,
#catalog-bulk-actions-container,
#merchants-bulk-actions-container {
  position: sticky;
  top: 0;
  z-index: 900;
}

#wms-sticky-actions-container {
  background: var(--color-bg);
  padding-top: 0.25rem;
  padding-bottom: 0.5rem;
}

#wms-sticky-actions-container .bulk-actions-bar {
  margin-bottom: 0.5rem;
}

.bulk-actions-bar {
  background: var(--color-primary);
  color: #ffffff;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.2);
  animation: bulkSlideDown 0.2s ease;
  flex-wrap: wrap;
  gap: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

@keyframes bulkSlideDown {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* WMS Order Badges / Tags Interactive Styling */
.wms-order-tag-badge {
  transition: transform 0.15s ease, box-shadow 0.15s ease, outline 0.15s ease, filter 0.15s ease;
  user-select: none;
  cursor: pointer;
}

.wms-order-tag-badge:hover {
  transform: translateY(-1px);
  filter: brightness(0.92);
}

.wms-order-tag-badge.wms-tag-active {
  outline: 2px solid var(--color-primary) !important;
  box-shadow: 0 0 8px rgba(99, 102, 241, 0.5) !important;
  font-weight: 800 !important;
}
