/**
 * ITMDesk Utility Classes
 * Common reusable CSS classes to reduce inline styles
 */

/* Layout */
.content-wrapper {
  margin-left: var(--sidebar-width);
  transition: margin-left var(--transition-base);
  padding-top: var(--navbar-height);
}

.sidebar {
  width: var(--sidebar-width);
  height: calc(100vh - var(--navbar-height));
  transition: var(--transition-base);
  position: fixed;
  top: var(--navbar-height);
  left: 0;
  z-index: var(--z-fixed);
  background-color: var(--light-bg);
  border-right: 1px solid var(--border-light);
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
}

/* Navbar */
.navbar {
  height: var(--navbar-height);
  background-color: var(--light-bg);
  box-shadow: var(--shadow-lg);
}

/* Modals */
.custom-modal {
  position: fixed;
  background: var(--text-white);
  z-index: var(--z-modal);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.modal-header-custom {
  background: var(--light-bg);
  padding: var(--spacing-md);
  border-bottom: 1px solid var(--border-color);
}

.modal-body-custom {
  padding: var(--spacing-md);
  overflow-y: auto;
}

.modal-footer-custom {
  padding: var(--spacing-md);
  border-top: 1px solid var(--border-color);
  text-align: right;
}

/* Buttons - Unified System */
.btn,
.swal2-confirm,
.swal2-cancel,
.swal2-deny {
  border-radius: var(--radius-md) !important;
  font-weight: var(--font-medium) !important;
  transition: all var(--transition-fast) !important;
  box-shadow: var(--shadow-sm) !important;
  border: 1px solid transparent !important;
}

/* Primary Button */
.btn-primary,
.swal2-confirm {
  background: var(--primary-color) !important;
  border-color: var(--primary-color) !important;
  color: var(--text-white) !important;
}

.btn-primary:hover,
.swal2-confirm:hover {
  background: var(--primary-hover) !important;
  border-color: var(--primary-hover) !important;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md) !important;
}

.btn-primary:active,
.swal2-confirm:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm) !important;
}

/* Secondary Button */
.btn-secondary,
.swal2-cancel {
  background: var(--text-secondary) !important;
  border-color: var(--text-secondary) !important;
  color: var(--text-white) !important;
}

.btn-secondary:hover,
.swal2-cancel:hover {
  background: var(--btn-secondary-hover-bg) !important;
  border-color: var(--btn-secondary-hover-border) !important;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md) !important;
}

/* Success/Danger/Warning/Info Buttons */
.btn-success {
  background: var(--success-color) !important;
  border-color: var(--success-color) !important;
  color: var(--text-white) !important;
}

.btn-success:hover {
  background: var(--btn-success-hover-bg) !important;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md) !important;
}

.btn-danger {
  background: var(--danger-color) !important;
  border-color: var(--danger-color) !important;
  color: var(--text-white) !important;
}

.btn-danger:hover {
  background: var(--btn-danger-hover-bg) !important;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md) !important;
}

.btn-warning {
  background: var(--warning-color) !important;
  border-color: var(--warning-color) !important;
  color: var(--text-primary) !important;
}

.btn-warning:hover {
  background: var(--btn-warning-hover-bg) !important;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md) !important;
}

.btn-info {
  background: var(--info-color) !important;
  border-color: var(--info-color) !important;
  color: var(--text-primary) !important;
}

.btn-info:hover {
  background: var(--btn-info-hover-bg) !important;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md) !important;
}

/* Disabled State */
.btn:disabled,
.swal2-confirm:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

/* Focus States */
.btn:focus,
.swal2-confirm:focus,
.swal2-cancel:focus {
  outline: none;
  box-shadow: 0 0 0 0.25rem var(--focus-ring-primary) !important;
}

.btn-secondary:focus,
.swal2-cancel:focus {
  box-shadow: 0 0 0 0.25rem var(--focus-ring-secondary) !important;
}

/* Button Icon Helper */
.btn-icon {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-sm);
}

/* Links */
.nav-link-primary {
  color: var(--primary-color) !important;
  transition: background-color var(--transition-fast);
}

.nav-link-primary:hover {
  background-color: var(--hover-bg);
}

.nav-link-primary.active {
  background-color: var(--active-bg);
}

/* Icons */
.icon-sm {
  font-size: var(--font-sm);
}

.icon-base {
  font-size: var(--font-base);
}

.icon-lg {
  font-size: var(--font-lg);
}

.icon-xl {
  font-size: var(--font-xl);
}

/* Status Colors */
.status-success {
  color: var(--success-color);
}

.status-warning {
  color: var(--warning-color);
}

.status-danger {
  color: var(--danger-color);
}

.status-info {
  color: var(--info-color);
}

/* Spacing Utilities */
.spacing-xs {
  padding: var(--spacing-xs);
}

.spacing-sm {
  padding: var(--spacing-sm);
}

.spacing-md {
  padding: var(--spacing-md);
}

.spacing-lg {
  padding: var(--spacing-lg);
}

.spacing-xl {
  padding: var(--spacing-xl);
}

/* Loading State */
.loading-overlay {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: var(--z-modal);
  background: rgba(0, 0, 0, 0.7);
  color: var(--text-white);
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: var(--radius-md);
  font-size: var(--font-xl);
}

/* Tables */
.table-fixed {
  table-layout: fixed;
  width: 100%;
}

.sortable {
  cursor: pointer;
  user-select: none;
}

.sortable:hover {
  background-color: var(--hover-bg);
}

/* Prevent line breaks in table cells */
table td,
table th {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Allow specific cells to wrap if needed */
table td.wrap-text,
table th.wrap-text {
  white-space: normal;
}

/* Table Row Hover Effect */
table tbody tr {
  transition: background-color var(--transition-fast), box-shadow var(--transition-fast);
  cursor: pointer;
}

table tbody tr:hover {
  background-color: var(--hover-bg) !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: var(--spacing-xxl) var(--spacing-lg);
  color: var(--text-muted);
}

.empty-state i {
  font-size: 3rem;
  margin-bottom: var(--spacing-md);
  opacity: 0.5;
}

.empty-state-illustration {
  display: block;
  margin: 0 auto var(--spacing-md);
  color: var(--text-secondary);
}

.empty-state h5 {
  color: var(--text-secondary);
  margin-bottom: var(--spacing-sm);
  font-weight: var(--font-semibold);
  letter-spacing: -0.01em;
}

.empty-state p {
  margin-bottom: 0;
  font-size: var(--font-sm);
  color: var(--text-muted);
}

/* Search Results Counter */
.search-results-info {
  padding: var(--spacing-xs) var(--spacing-sm);
  background-color: var(--light-bg);
  border-radius: var(--radius-sm);
  font-size: var(--font-sm);
  color: var(--text-secondary);
  display: inline-block;
  margin-bottom: var(--spacing-sm);
}

/* View Toolbar */
.view-toolbar {
  position: fixed;
  top: var(--navbar-height);
  left: var(--sidebar-width);
  right: 0;
  z-index: 900;
  transition: left var(--transition-base);
  background-color: var(--text-white);
  border-bottom: 1px solid var(--border-light);
  padding: var(--spacing-md);
  box-shadow: var(--shadow-sm);
}

/* Detail Panel */
.detail-panel {
  width: var(--detail-panel-width);
  height: 100%;
  position: fixed;
  right: 0;
  top: var(--navbar-height);
  background-color: var(--text-white);
  border-left: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-fixed);
  overflow-y: auto;
  transition: width var(--transition-base);
}

/* Form Elements */
.form-control-custom {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: var(--spacing-sm);
}

.form-control-custom:focus {
  border-color: var(--primary-color);
  outline: none;
  box-shadow: 0 0 0 0.2rem var(--focus-ring-primary);
}

/* Cards */
.card-custom {
  background: var(--text-white);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--spacing-md);
  box-shadow: var(--shadow-sm);
}

.card-custom:hover {
  box-shadow: var(--shadow-md);
}

/* Badges */
.badge-custom {
  display: inline-block;
  padding: var(--spacing-xs) var(--spacing-sm);
  font-size: var(--font-sm);
  font-weight: var(--font-semibold);
  border-radius: var(--radius-sm);
}

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

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

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

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

/* View Transitions */
.view {
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Loading Skeleton */
.skeleton {
  background: linear-gradient(90deg, var(--skeleton-light) 25%, var(--skeleton-mid) 50%, var(--skeleton-light) 75%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.skeleton-text {
  height: 1rem;
  margin-bottom: var(--spacing-xs);
}

.skeleton-title {
  height: 1.5rem;
  width: 60%;
  margin-bottom: var(--spacing-sm);
}

.skeleton-row {
  height: 3rem;
  margin-bottom: var(--spacing-xs);
}

/* Tooltips Enhancement */
.tooltip {
  font-size: var(--font-sm);
}

/* Dark Mode Adaptive Classes */
.bg-adaptive-light {
    background-color: var(--bs-light-bg) !important;
}

.bg-adaptive-card {
    background-color: var(--bs-modal-bg) !important;
}

.bg-adaptive-secondary {
    background-color: var(--bs-secondary-bg) !important;
}

.text-adaptive {
    color: var(--bs-body-color) !important;
}

.text-adaptive-muted {
    color: var(--text-secondary) !important;
}

.border-adaptive {
    border-color: var(--bs-border-color) !important;
}

/* Responsive Utilities */
@media (max-width: 768px) {
  .sidebar {
    width: var(--sidebar-collapsed-width);
  }

  .content-wrapper {
    margin-left: var(--sidebar-collapsed-width);
  }

  /* Detail Panel Mobile */
  .detail-panel {
    width: 100% !important;
    height: 70vh !important;
    top: auto !important;
    bottom: 0 !important;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    animation: slideUp 0.3s ease;
  }

  @keyframes slideUp {
    from {
      transform: translateY(100%);
    }
    to {
      transform: translateY(0);
    }
  }

  /* Modals Mobile */
  #alertsModal,
  #ticketsModal {
    width: 90% !important;
    left: 5% !important;
    top: 10% !important;
    height: auto !important;
    max-height: 80vh !important;
  }

  /* View Toolbar Mobile */
  .view-toolbar {
    left: var(--sidebar-collapsed-width);
    padding: var(--spacing-sm);
  }

  /* FAB Button Mobile */
  .fab-button {
    bottom: var(--spacing-sm);
    right: var(--spacing-sm);
  }
}

@media (max-width: 576px) {
  .custom-modal {
    width: 90% !important;
    left: 5% !important;
  }

  /* Even smaller modals on mobile */
  #alertsModal,
  #ticketsModal {
    width: 95% !important;
    left: 2.5% !important;
    top: 5% !important;
    max-height: 90vh !important;
  }

  /* Hide sidebar text on very small screens */
  .sidebar-text {
    display: none !important;
  }

  /* Stack buttons vertically on small screens */
  .d-flex.gap-2 {
    flex-direction: column !important;
  }
}


/* ============================================================
   Global search — inline navbar input + anchored dropdown
   ============================================================ */

/* Wrapper sits in the navbar between logo and right-side icons. Uses
   position:relative so the dropdown can be absolutely positioned right
   below the input. */
.gs-navbar-wrapper {
  position: relative;
  flex: 1;
  max-width: 480px;
  display: flex;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--radius-md);
  padding: 0 0.75rem;
  height: 36px;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}
.gs-navbar-wrapper:focus-within {
  border-color: var(--primary-color);
  background: var(--surface-1);
}
.gs-navbar-icon {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-right: 0.5rem;
  flex-shrink: 0;
}
.gs-navbar-input {
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  height: 100%;
  min-width: 0;
}
.gs-navbar-input::placeholder { color: var(--text-muted); }
/* Chip uses a text-color tint instead of a fixed surface tier, so contrast
   self-adjusts in both light and dark themes (was using --surface-1 which
   in dark mode is DARKER than the wrapper's --surface-2 → invisible). */
.gs-navbar-shortcut {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-primary);
  background: color-mix(in srgb, var(--text-primary) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--text-primary) 20%, transparent);
  border-radius: var(--radius-sm);
  padding: 0.05rem 0.35rem;
  margin-left: 0.5rem;
  flex-shrink: 0;
}
.gs-navbar-wrapper:focus-within .gs-navbar-shortcut {
  opacity: 0.5;
}

/* Dropdown anchored below the wrapper. Width matches wrapper unless the
   viewport is too tight, in which case it overhangs to the left. */
.gs-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--surface-1);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  z-index: 2000;
  max-height: min(560px, 70vh);
  display: none;
  flex-direction: column;
}
.gs-dropdown.is-visible { display: flex; }

/* Hide the inline search on small screens — the navbar gets too cramped.
   Cmd+K still focuses the input when revealed via dev tools / future
   responsive treatment, but visually we drop it. */
@media (max-width: 768px) {
  .gs-navbar-wrapper { display: none; }
}

.gs-results {
  overflow-y: auto;
  padding: 0.25rem 0;
  flex: 1;
}

.gs-section { padding: 0.4rem 0 0.6rem; }
.gs-section + .gs-section { border-top: 1px solid var(--bs-border-color-translucent); }
.gs-section-title {
  font-size: 0.7rem;
  font-weight: var(--font-semibold);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.3rem 1rem;
}

.gs-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 1rem;
  cursor: pointer;
  transition: background var(--transition-fast);
}
.gs-item:hover, .gs-item.is-active {
  background: var(--surface-2);
}
.gs-item-icon {
  flex-shrink: 0;
  width: 1.1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.gs-item.is-active .gs-item-icon { color: var(--primary-color); }
.gs-item-body { flex: 1; min-width: 0; }
.gs-item-badge {
  display: inline-block;
  margin-left: 0.5rem;
  font-family: var(--font-sans);
  font-size: 0.62rem;
  font-weight: var(--font-semibold);
  color: var(--text-secondary);
  background: var(--surface-2);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--radius-sm);
  padding: 0.05rem 0.4rem;
  vertical-align: middle;
}
.gs-item.is-active .gs-item-badge {
  background: color-mix(in srgb, var(--primary-color) 15%, transparent);
  border-color: var(--primary-color);
  color: var(--primary-color);
}
.gs-item-title {
  font-size: 0.875rem;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gs-item-title em {
  background: color-mix(in srgb, var(--primary-color) 20%, transparent);
  color: var(--primary-color);
  font-style: normal;
  padding: 0 0.1rem;
  border-radius: 2px;
}
.gs-item-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 0.1rem;
}
.gs-item-enter {
  color: var(--text-muted);
  font-size: 0.7rem;
  opacity: 0;
  transition: opacity var(--transition-fast);
}
.gs-item.is-active .gs-item-enter { opacity: 1; color: var(--primary-color); }

.gs-empty {
  text-align: center;
  padding: var(--spacing-xl);
  color: var(--text-muted);
}
.gs-empty i { font-size: 1.5rem; opacity: 0.4; margin-bottom: 0.5rem; display: block; }

.gs-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 1rem;
  font-size: 0.7rem;
  color: var(--text-secondary);
  border-top: 1px solid var(--bs-border-color-translucent);
  background: var(--surface-2);
}
/* Same self-adjusting tint as .gs-navbar-shortcut — fixes the dark-mode
   issue where surface-1 chips on a surface-2 footer disappeared. */
.gs-footer kbd {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-primary);
  background: color-mix(in srgb, var(--text-primary) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--text-primary) 22%, transparent);
  border-radius: var(--radius-sm);
  padding: 0.05rem 0.3rem;
  margin: 0 0.1rem;
}
