/**
 * Factory & Depot Management ERP - Global Custom Stylesheet
 * Responsive, Mobile-First, Dark & Light Mode
 */

:root {
  --primary-rgb: 13, 110, 253;
  --sidebar-width: 260px;
  --topbar-height: 64px;
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --border-subtle: #e9ecef;
  --card-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.05);
  --card-hover-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.08);
}

[data-bs-theme="dark"] {
  --border-subtle: #2d3748;
  --card-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.3);
  --card-hover-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.4);
}

body {
  font-family: var(--font-sans);
  min-height: 100vh;
  background-color: var(--bs-body-bg);
  color: var(--bs-body-color);
  overflow-x: hidden;
}

/* Layout Structure */
#wrapper {
  display: flex;
  width: 100%;
  align-items: stretch;
  min-height: 100vh;
}

#sidebar {
  min-width: var(--sidebar-width);
  max-width: var(--sidebar-width);
  background: #1e293b;
  color: #e2e8f0;
  transition: all 0.3s ease;
  z-index: 1040;
  display: flex;
  flex-direction: column;
}

#sidebar.toggled {
  margin-left: calc(-1 * var(--sidebar-width));
}

#sidebar .sidebar-brand {
  height: var(--topbar-height);
  padding: 0.75rem 1.25rem;
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  background: #0f172a;
  color: #fff;
  text-decoration: none;
}

#sidebar .sidebar-brand span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#sidebar .nav-item {
  position: relative;
}

#sidebar .nav-link {
  color: #94a3b8;
  padding: 0.6rem 1.15rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.88rem;
  font-weight: 500;
  transition: all 0.2s ease;
  text-decoration: none;
  border-radius: 6px;
  margin: 2px 10px;
}

#sidebar .nav-link:hover {
  color: #ffffff;
  background-color: rgba(255, 255, 255, 0.08);
}

#sidebar .nav-link.active {
  background-color: #2563eb;
  color: #ffffff;
  font-weight: 600;
}

#sidebar .nav-link i {
  font-size: 1.1rem;
  width: 20px;
  text-align: center;
}

/* Collapsible Dropdown Toggle Link */
#sidebar .sidebar-dropdown-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
}

#sidebar .sidebar-dropdown-toggle .sidebar-chevron {
  font-size: 0.75rem;
  transition: transform 0.25s ease;
  opacity: 0.7;
}

#sidebar .sidebar-dropdown-toggle:not(.collapsed) {
  color: #ffffff;
  background-color: rgba(255, 255, 255, 0.05);
}

#sidebar .sidebar-dropdown-toggle:not(.collapsed) .sidebar-chevron {
  transform: rotate(180deg);
  opacity: 1;
}

#sidebar .sidebar-dropdown-toggle.active {
  color: #60a5fa;
  background-color: rgba(37, 99, 235, 0.12);
}

/* Collapsible Submenu Container */
#sidebar .sidebar-submenu {
  margin-left: 1.5rem;
  padding-left: 0.5rem;
  border-left: 1px solid rgba(255, 255, 255, 0.12);
  margin-bottom: 0.4rem;
  margin-top: 0.15rem;
}

#sidebar .sidebar-submenu .nav-link {
  padding: 0.42rem 0.85rem;
  font-size: 0.83rem;
  margin: 1px 4px;
  color: #94a3b8;
  border-radius: 5px;
}

#sidebar .sidebar-submenu .nav-link:hover {
  color: #ffffff;
  background-color: rgba(255, 255, 255, 0.08);
}

#sidebar .sidebar-submenu .nav-link.active {
  background-color: #2563eb;
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.35);
}

#sidebar .sidebar-submenu .nav-link i {
  font-size: 0.95rem;
  width: 18px;
  opacity: 0.85;
}

#sidebar .sidebar-heading {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: #64748b;
  padding: 1rem 1.25rem 0.25rem;
}

#sidebar .sidebar-footer {
  margin-top: auto;
  padding: 1rem;
  background: #0f172a;
  font-size: 0.8rem;
}

/* Content Area */
#content-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background-color: var(--bs-tertiary-bg);
}

.topbar {
  height: var(--topbar-height);
  background: var(--bs-body-bg);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 1030;
}

.main-content {
  flex: 1;
  padding: 1.5rem;
}

/* KPI Cards */
.kpi-card {
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  background: var(--bs-body-bg);
  box-shadow: var(--card-shadow);
  transition: transform 0.2s, box-shadow 0.2s;
  overflow: hidden;
  height: 100%;
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--card-hover-shadow);
}

.kpi-card .card-body {
  padding: 1.25rem;
}

.kpi-icon-badge {
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  flex-shrink: 0;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.kpi-value {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-top: 0.25rem;
  margin-bottom: 0;
}

.kpi-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--bs-secondary-color);
}

/* Tables & Card Styling */
.card-table {
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  background: var(--bs-body-bg);
  box-shadow: var(--card-shadow);
}

.table th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  color: var(--bs-secondary-color);
  background: var(--bs-tertiary-bg);
  border-bottom: 2px solid var(--border-subtle);
  white-space: nowrap;
}

.table td {
  vertical-align: middle;
  font-size: 0.88rem;
}

/* Status Badges */
.badge-status {
  padding: 0.35em 0.65em;
  font-weight: 600;
  border-radius: 6px;
  font-size: 0.75rem;
  text-transform: capitalize;
}

/* POS Screen Styles */
.pos-container {
  display: flex;
  gap: 1rem;
  height: calc(100vh - var(--topbar-height) - 3rem);
}

.pos-product-area {
  flex: 7;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.pos-cart-area {
  flex: 5;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bs-body-bg);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 1rem;
  box-shadow: var(--card-shadow);
}

.pos-product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  grid-auto-rows: max-content;
  align-content: start;
  align-items: start;
  gap: 0.65rem;
  overflow-y: auto;
  padding: 0.5rem 0.35rem;
  flex: 1;
}

.pos-product-card {
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: var(--bs-body-bg);
  padding: 0;
  cursor: pointer;
  user-select: none;
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  height: auto;
}

.pos-product-card:active,
.pos-product-card:hover {
  border-color: #2563eb;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.14);
}

.pos-product-card:hover .pos-product-img {
  transform: scale(1.05);
}

.pos-product-img-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  height: auto;
  background: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-bottom: 1px solid var(--border-subtle);
}

[data-bs-theme="dark"] .pos-product-img-wrapper {
  background: #1e293b;
}

.pos-product-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.25s ease;
}

.pos-product-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
  color: #64748b;
  user-select: none;
}

[data-bs-theme="dark"] .pos-product-placeholder {
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  color: #94a3b8;
}

.pos-product-card-body {
  padding: 0.45rem 0.55rem;
  display: flex;
  flex-direction: column;
  flex: 1;
  justify-content: space-between;
}

.pos-product-title {
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.2;
  color: var(--bs-body-color);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  height: 1.95rem;
  text-align: left;
  margin-bottom: 0.2rem;
}

.pos-product-sku {
  font-size: 0.65rem;
  color: #64748b;
  font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  display: block;
  text-align: left;
  background: var(--bs-tertiary-bg);
  padding: 1px 5px;
  border-radius: 3px;
  border: 1px solid var(--border-subtle);
  margin-bottom: 0.3rem;
}

.pos-cart-items {
  flex: 1;
  overflow-y: auto;
  border-top: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
  margin: 0.5rem 0;
  padding: 0.25rem 0;
}

/* Mobile Responsiveness */
@media (max-width: 991.98px) {
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100vh;
    height: 100dvh;
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    max-width: 85vw;
    margin-left: 0;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1050;
    box-shadow: 0 0 25px rgba(0, 0, 0, 0.5);
    pointer-events: auto;
  }

  #sidebar.show {
    transform: translateX(0);
    margin-left: 0;
  }

  .sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    background: rgba(15, 23, 42, 0.65);
    z-index: 1040;
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    pointer-events: auto;
  }

  #sidebarAccordion {
    position: relative;
    z-index: 2;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .pos-container {
    flex-direction: column;
    height: auto;
  }

  .pos-cart-area {
    margin-top: 0.75rem;
    height: auto;
    min-height: 480px;
  }

  body.overflow-hidden {
    overflow-y: auto !important;
  }
}

/* Print Styles */
@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 11pt;
  }

  #sidebar, .topbar, .no-print, .btn, footer, .modal-backdrop {
    display: none !important;
  }

  #wrapper, #content-wrapper, .main-content {
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    background: transparent !important;
  }

  .print-only {
    display: block !important;
  }

  .invoice-box {
    width: 100%;
    max-width: 800px;
    margin: auto;
    padding: 15px;
    border: none !important;
    box-shadow: none !important;
  }

  /* Thermal Receipt Printing */
  .thermal-receipt {
    width: 78mm;
    max-width: 78mm;
    margin: 0 auto;
    font-size: 9pt;
    line-height: 1.2;
    padding: 2mm;
  }
}

/* Common UI Helper Utilities */
.cursor-pointer {
  cursor: pointer !important;
}

.btn-xs {
  padding: 0.15rem 0.45rem !important;
  font-size: 0.75rem !important;
  line-height: 1.2 !important;
  border-radius: 4px !important;
}

.border-dashed {
  border-style: dashed !important;
}

