/* ==========================================================================
   IPv4 TradeHub ERP - Modern SaaS Design System & Theme Engine
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  /* Color Palette - Vibrant Indigo SaaS */
  --erp-primary: #4f46e5;
  --erp-primary-hover: #4338ca;
  --erp-primary-subtle: rgba(79, 70, 229, 0.12);
  --erp-secondary: #64748b;
  
  --erp-accent: #06b6d4;
  --erp-accent-hover: #0891b2;
  
  --erp-success: #10b981;
  --erp-success-subtle: rgba(16, 185, 129, 0.12);
  
  --erp-warning: #f59e0b;
  --erp-warning-subtle: rgba(245, 158, 11, 0.15);
  
  --erp-danger: #ef4444;
  --erp-danger-subtle: rgba(239, 68, 68, 0.12);
  
  --erp-info: #3b82f6;
  --erp-info-subtle: rgba(59, 130, 246, 0.12);

  /* Light Theme Surfaces & Text */
  --erp-bg: #f8fafc;
  --erp-card-bg: #ffffff;
  --erp-card-border: #e2e8f0;
  --erp-text-main: #0f172a;
  --erp-text-muted: #64748b;
  --erp-sidebar-bg: #0f172a;
  --erp-sidebar-text: #94a3b8;
  --erp-sidebar-active: #ffffff;
  --erp-sidebar-hover: #1e293b;
  --erp-navbar-bg: #ffffff;
  --erp-navbar-border: #e2e8f0;
  --erp-input-bg: #ffffff;
  --erp-input-border: #cbd5e1;
  --erp-shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --erp-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --erp-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --erp-radius: 0.625rem;
  --erp-font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --erp-font-mono: 'JetBrains Mono', monospace;
}

[data-bs-theme="dark"] {
  /* Dark Theme Surfaces & Text */
  --erp-bg: #0b0f19;
  --erp-card-bg: #111827;
  --erp-card-border: #1f2937;
  --erp-text-main: #f8fafc;
  --erp-text-muted: #94a3b8;
  --erp-sidebar-bg: #0b0f19;
  --erp-sidebar-text: #94a3b8;
  --erp-sidebar-active: #ffffff;
  --erp-sidebar-hover: #1e293b;
  --erp-navbar-bg: #111827;
  --erp-navbar-border: #1f2937;
  --erp-input-bg: #1f2937;
  --erp-input-border: #374151;
  --erp-shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.5);
  --erp-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  --erp-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}

/* Global Typography & Base */
body {
  font-family: var(--erp-font-sans);
  background-color: var(--erp-bg);
  color: var(--erp-text-main);
  min-height: 100vh;
  margin: 0;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.mono {
  font-family: var(--erp-font-mono);
}

/* App Layout Wrapper */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* Sidebar Navigation */
.app-sidebar {
  width: 260px;
  background-color: var(--erp-sidebar-bg);
  color: var(--erp-sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 1030;
  transition: all 0.25s ease-in-out;
  overflow-y: auto;
  border-right: 1px solid rgba(255, 255, 255, 0.05);
}

.app-sidebar.collapsed {
  margin-left: -260px;
}

@media (min-width: 992px) {
  .app-sidebar.collapsed {
    margin-left: 0;
    width: 78px;
  }
  .app-sidebar.collapsed .sidebar-brand-text,
  .app-sidebar.collapsed .sidebar-nav-title,
  .app-sidebar.collapsed .nav-text,
  .app-sidebar.collapsed .badge {
    display: none !important;
  }
  .app-sidebar.collapsed .nav-link {
    text-align: center;
    padding: 0.75rem;
  }
  .app-sidebar.collapsed .nav-link i {
    font-size: 1.25rem;
    margin: 0 auto;
  }
}

.sidebar-brand {
  padding: 1.25rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 700;
  font-size: 1.125rem;
  color: #ffffff;
  text-decoration: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--erp-primary), var(--erp-accent));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.2rem;
  box-shadow: 0 4px 10px rgba(79, 70, 229, 0.4);
}

.sidebar-nav {
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.sidebar-nav-title {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.075em;
  color: #64748b;
  padding: 0.75rem 0.75rem 0.25rem 0.75rem;
}

.app-sidebar .nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.875rem;
  color: var(--erp-sidebar-text);
  font-weight: 500;
  font-size: 0.875rem;
  border-radius: var(--erp-radius);
  transition: all 0.15s ease;
  text-decoration: none;
}

.app-sidebar .nav-link i {
  font-size: 1.1rem;
  width: 20px;
  text-align: center;
  opacity: 0.85;
}

.app-sidebar .nav-link:hover {
  background-color: var(--erp-sidebar-hover);
  color: var(--erp-sidebar-active);
}

.app-sidebar .nav-link.active {
  background-color: var(--erp-primary);
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35);
}

.app-sidebar .nav-link.active i {
  opacity: 1;
}

/* App Main Content Canvas */
.app-main {
  flex: 1;
  margin-left: 260px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left 0.25s ease-in-out;
}

.app-sidebar.collapsed + .app-main {
  margin-left: 0;
}

@media (min-width: 992px) {
  .app-sidebar.collapsed + .app-main {
    margin-left: 78px;
  }
}

@media (max-width: 991.98px) {
  .app-sidebar {
    margin-left: -260px;
  }
  .app-sidebar.show-mobile {
    margin-left: 0;
  }
  .app-main {
    margin-left: 0 !important;
  }
}

/* Top Navbar */
.app-header {
  height: 64px;
  background-color: var(--erp-navbar-bg);
  border-bottom: 1px solid var(--erp-navbar-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 1020;
  box-shadow: var(--erp-shadow-sm);
}

.header-search {
  max-width: 380px;
  width: 100%;
}

.header-search .form-control {
  background-color: var(--erp-bg);
  border-color: var(--erp-card-border);
  font-size: 0.875rem;
  border-radius: 20px;
  padding-left: 2.25rem;
}

/* ERP Cards */
.erp-card {
  background-color: var(--erp-card-bg);
  border: 1px solid var(--erp-card-border);
  border-radius: var(--erp-radius);
  box-shadow: var(--erp-shadow-sm);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.erp-card.hover-lift:hover {
  transform: translateY(-2px);
  box-shadow: var(--erp-shadow);
}

.erp-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 0.75rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--erp-card-border);
}

.erp-card-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* KPI Metric Cards */
.kpi-card {
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--erp-primary), var(--erp-accent));
}

.kpi-card.kpi-success::before {
  background: var(--erp-success);
}
.kpi-card.kpi-danger::before {
  background: var(--erp-danger);
}
.kpi-card.kpi-warning::before {
  background: var(--erp-warning);
}
.kpi-card.kpi-info::before {
  background: var(--erp-info);
}

.kpi-value {
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0.25rem 0;
}

.kpi-label {
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--erp-text-muted);
}

.kpi-icon-wrapper {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
}

/* Status Badges */
.badge-tier-critical {
  background-color: var(--erp-danger-subtle);
  color: var(--erp-danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
  font-weight: 600;
  padding: 0.35em 0.65em;
  border-radius: 6px;
}

.badge-tier-urgent {
  background-color: var(--erp-warning-subtle);
  color: #b45309;
  border: 1px solid rgba(245, 158, 11, 0.4);
  font-weight: 600;
  padding: 0.35em 0.65em;
  border-radius: 6px;
}

.badge-tier-upcoming {
  background-color: var(--erp-info-subtle);
  color: var(--erp-info);
  border: 1px solid rgba(59, 130, 246, 0.3);
  font-weight: 600;
  padding: 0.35em 0.65em;
  border-radius: 6px;
}

.badge-tier-normal {
  background-color: var(--erp-success-subtle);
  color: var(--erp-success);
  border: 1px solid rgba(16, 185, 129, 0.3);
  font-weight: 600;
  padding: 0.35em 0.65em;
  border-radius: 6px;
}

/* Modern ERP Table */
.erp-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.erp-table th {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--erp-text-muted);
  background-color: var(--erp-bg);
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--erp-card-border);
}

.erp-table td {
  padding: 0.875rem 1rem;
  vertical-align: middle;
  border-bottom: 1px solid var(--erp-card-border);
  font-size: 0.875rem;
}

.erp-table tbody tr:hover {
  background-color: rgba(79, 70, 229, 0.03);
}

/* Buttons */
.btn-erp-primary {
  background: linear-gradient(135deg, var(--erp-primary), var(--erp-primary-hover));
  color: #ffffff;
  font-weight: 500;
  border: none;
  box-shadow: 0 2px 4px rgba(79, 70, 229, 0.25);
  border-radius: var(--erp-radius);
  transition: all 0.15s ease;
}

.btn-erp-primary:hover {
  background: var(--erp-primary-hover);
  color: #ffffff;
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(79, 70, 229, 0.35);
}

/* Printable Document Styling */
@media print {
  .app-sidebar,
  .app-header,
  .no-print,
  .btn,
  .pagination {
    display: none !important;
  }

  .app-main {
    margin: 0 !important;
    padding: 0 !important;
  }

  body {
    background-color: #ffffff !important;
    color: #000000 !important;
    font-size: 11pt;
  }

  .erp-card {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
  }

  .printable-invoice {
    padding: 20px;
    page-break-after: auto;
  }
}

/* ==========================================================================
   Select2 ERP Theme & Dark Mode Integration
   ========================================================================== */

.select2-container--bootstrap-5 {
  display: block;
}

.select2-container--bootstrap-5 .select2-selection {
  border-color: var(--erp-input-border);
  background-color: var(--erp-input-bg);
  border-radius: var(--erp-radius);
  font-family: var(--erp-font-sans);
  font-size: 0.875rem;
  color: var(--erp-text-main);
  min-height: 38px;
  transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.select2-container--bootstrap-5 .select2-selection--single {
  padding: 0.375rem 0.75rem;
}

.select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered {
  color: var(--erp-text-main);
  padding: 0;
  line-height: 1.5;
}

.select2-container--bootstrap-5 .select2-selection--single .select2-selection__placeholder {
  color: var(--erp-text-muted);
}

.select2-container--bootstrap-5.select2-container--focus .select2-selection,
.select2-container--bootstrap-5.select2-container--open .select2-selection {
  border-color: var(--erp-primary);
  box-shadow: 0 0 0 0.25rem rgba(79, 70, 229, 0.15);
}

.select2-container--bootstrap-5 .select2-dropdown {
  border-color: var(--erp-card-border);
  background-color: var(--erp-card-bg);
  color: var(--erp-text-main);
  border-radius: var(--erp-radius);
  box-shadow: var(--erp-shadow-lg);
  font-size: 0.875rem;
  z-index: 1095;
  overflow: hidden;
}

.select2-container--bootstrap-5 .select2-dropdown .select2-search {
  padding: 0.5rem;
}

.select2-container--bootstrap-5 .select2-dropdown .select2-search .select2-search__field {
  background-color: var(--erp-input-bg);
  color: var(--erp-text-main);
  border: 1px solid var(--erp-input-border);
  border-radius: calc(var(--erp-radius) - 2px);
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
}

.select2-container--bootstrap-5 .select2-dropdown .select2-search .select2-search__field:focus {
  border-color: var(--erp-primary);
  outline: none;
  box-shadow: 0 0 0 0.2rem rgba(79, 70, 229, 0.15);
}

.select2-container--bootstrap-5 .select2-results__option {
  padding: 0.45rem 0.75rem;
  color: var(--erp-text-main);
  font-size: 0.875rem;
}

.select2-container--bootstrap-5 .select2-results__option--highlighted[aria-selected] {
  background-color: var(--erp-primary);
  color: #ffffff;
}

.select2-container--bootstrap-5 .select2-results__option--selected,
.select2-container--bootstrap-5 .select2-results__option[aria-selected="true"] {
  background-color: var(--erp-primary-subtle);
  color: var(--erp-primary);
  font-weight: 600;
}

/* Compact / Small Select2 sizing for tables and form-select-sm */
.select2-container--bootstrap-5.select2-container--sm .select2-selection,
select.form-select-sm + .select2-container--bootstrap-5 .select2-selection {
  min-height: 31px;
  height: 31px;
  padding: 0.2rem 0.5rem;
  font-size: 0.8125rem;
  border-radius: calc(var(--erp-radius) - 2px);
}

select.form-select-sm + .select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered {
  line-height: 23px;
  padding-right: 1.25rem;
}

select.form-select-sm + .select2-container--bootstrap-5 .select2-selection--single .select2-selection__arrow {
  top: 3px;
}

select.mono + .select2-container--bootstrap-5 .select2-selection,
select.mono + .select2-container--bootstrap-5 .select2-selection__rendered {
  font-family: var(--erp-font-mono);
}

/* Ensure Select2 within table cells takes full width cleanly */
.table td .select2-container {
  width: 100% !important;
}

/* Dark Mode Overrides for Select2 */
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection {
  background-color: var(--erp-input-bg);
  border-color: var(--erp-input-border);
  color: var(--erp-text-main);
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered {
  color: var(--erp-text-main);
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection--single .select2-selection__placeholder {
  color: var(--erp-text-muted);
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-dropdown {
  background-color: var(--erp-card-bg);
  border-color: var(--erp-card-border);
  color: var(--erp-text-main);
  box-shadow: var(--erp-shadow-lg);
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-dropdown .select2-search .select2-search__field {
  background-color: var(--erp-input-bg);
  border-color: var(--erp-input-border);
  color: var(--erp-text-main);
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-results__option {
  color: var(--erp-text-main);
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-results__option--highlighted[aria-selected] {
  background-color: var(--erp-primary);
  color: #ffffff;
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-results__option--selected,
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-results__option[aria-selected="true"] {
  background-color: rgba(79, 70, 229, 0.25);
  color: #a5b4fc;
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection--single .select2-selection__arrow b {
  border-color: #94a3b8 transparent transparent transparent;
}

[data-bs-theme="dark"] .select2-container--bootstrap-5.select2-container--open .select2-selection--single .select2-selection__arrow b {
  border-color: transparent transparent #94a3b8 transparent;
}

/* Validation styling for Select2 */
select.is-invalid + .select2-container--bootstrap-5 .select2-selection,
select.input-validation-error + .select2-container--bootstrap-5 .select2-selection {
  border-color: var(--erp-danger) !important;
}

select.is-invalid + .select2-container--bootstrap-5.select2-container--focus .select2-selection,
select.input-validation-error + .select2-container--bootstrap-5.select2-container--focus .select2-selection {
  box-shadow: 0 0 0 0.25rem rgba(239, 68, 68, 0.25) !important;
}

.col-auto > .select2-container {
  min-width: 220px;
}

/* ==========================================================================
   Voucher Line Item Tables - Compact 5px Horizontal Padding for Cells & Fields
   ========================================================================== */

/* Reduce left & right padding of voucher table header and data cells to 5px to maximize field space */
.voucher-table th,
.voucher-table td,
#linesTable th,
#linesTable td,
#pLinesTable th,
#pLinesTable td,
#jvLinesTable th,
#jvLinesTable td {
  padding-left: 5px !important;
  padding-right: 5px !important;
}

/* Reduce left & right padding of all form fields (inputs, textareas) inside voucher tables to 5px */
.voucher-table .form-control,
.voucher-table .form-control-sm,
.voucher-table input,
.voucher-table textarea,
#linesTable .form-control,
#linesTable .form-control-sm,
#linesTable input,
#linesTable textarea,
#pLinesTable .form-control,
#pLinesTable .form-control-sm,
#pLinesTable input,
#pLinesTable textarea,
#jvLinesTable .form-control,
#jvLinesTable .form-control-sm,
#jvLinesTable input,
#jvLinesTable textarea {
  padding-left: 5px !important;
  padding-right: 5px !important;
}

/* Reduce left padding of dropdown selects inside voucher tables to 5px */
.voucher-table .form-select,
.voucher-table .form-select-sm,
#linesTable .form-select,
#linesTable .form-select-sm,
#pLinesTable .form-select,
#pLinesTable .form-select-sm,
#jvLinesTable .form-select,
#jvLinesTable .form-select-sm {
  padding-left: 5px !important;
  padding-right: 1.5rem !important;
}

/* Reduce left & right padding of input group addons (e.g. $ symbol) to 5px */
.voucher-table .input-group-text,
#linesTable .input-group-text,
#pLinesTable .input-group-text,
#jvLinesTable .input-group-text {
  padding-left: 5px !important;
  padding-right: 5px !important;
}

/* Ensure Select2 within voucher table cells takes full width cleanly */
.voucher-table td .select2-container,
.erp-table td .select2-container,
#linesTable td .select2-container,
#pLinesTable td .select2-container,
#jvLinesTable td .select2-container {
  width: 100% !important;
}

/* Select2 selection padding inside voucher tables */
.voucher-table .select2-container--bootstrap-5 .select2-selection,
#linesTable .select2-container--bootstrap-5 .select2-selection,
#pLinesTable .select2-container--bootstrap-5 .select2-selection,
#jvLinesTable .select2-container--bootstrap-5 .select2-selection {
  padding-left: 5px !important;
  padding-right: 5px !important;
}

.voucher-table .select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered,
#linesTable .select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered,
#pLinesTable .select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered,
#jvLinesTable .select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered {
  padding-left: 0 !important;
  padding-right: 1.25rem !important;
}


