/* Overrides and custom styles on top of Bootstrap 5 */
:root {
  --sidebar-w: 220px;
}

body {
  background: #f8f9fa;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: #1e293b;
  position: fixed;
  top: 0; left: 0; height: 100vh;
  overflow-y: auto;
  z-index: 1050;
  padding: 0;
  display: flex;
  flex-direction: column;
}
.sidebar .brand {
  padding: 0.8rem 1rem;
  border-bottom: 1px solid #334155;
  margin-bottom: 0.3rem;
  text-align: center;
}
.sidebar .brand img {
  border-radius: 6px;
  background: #fff;
  padding: 4px 8px;
}
.sidebar .nav-link {
  color: #94a3b8;
  padding: 0.55rem 1.1rem;
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  border-radius: 0;
  transition: background 0.12s;
}
.sidebar .nav-link:hover,
.sidebar .nav-link.active {
  background: #334155;
  color: #fff;
}
.sidebar .nav-link .icon { width: 1.3rem; text-align: center; font-size: 1rem; }
.sidebar .nav-link.has-submenu { justify-content: flex-start; position: relative; }
.sidebar .nav-link .submenu-arrow { margin-left: auto; font-size: 0.7rem; transition: transform 0.2s; }
.sidebar .nav-link.has-submenu.open .submenu-arrow { transform: rotate(180deg); }
.sidebar .submenu { display: none; background: #172033; }
.sidebar .submenu.open { display: block; }
.sidebar .nav-link.nav-sub { padding-left: 2.2rem; font-size: 0.82rem; }

/* Main */
.main-content {
  margin-left: var(--sidebar-w);
  padding: 1.2rem 1.5rem;
  min-height: 100vh;
}

/* Pages */
.page { display: none; }
.page.active { display: block; }

/* Stats KPI cards */
.stat-card {
  border-left: 3px solid #dee2e6;
  text-align: left !important;
  transition: box-shadow 0.15s;
}
.stat-card.clickable { cursor: pointer; }
.stat-card.clickable:hover { box-shadow: 0 2px 10px rgba(0,0,0,0.08); }
.stat-card .kpi-label {
  font-size: 0.68rem;
  font-weight: 700;
  color: #6c757d;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.15rem;
}
.stat-card .kpi-value {
  font-size: 1.8rem;
  font-weight: 800;
  line-height: 1.1;
}
.stat-card .kpi-sub {
  font-size: 0.72rem;
  color: #6c757d;
  margin-top: 0.2rem;
}
.stat-card .kpi-icon {
  font-size: 1.3rem;
  opacity: 0.4;
}

/* Chart titles */
.chart-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: #343a40;
  margin-bottom: 0.4rem;
}

/* Year toggle buttons */
.year-toggle {
  font-size: 0.68rem;
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  border: 1px solid #dee2e6;
  background: #fff;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.12s;
}
.year-toggle.active { color: #fff; border-color: transparent; }
.year-toggle:not(.active) { opacity: 0.5; background: #f8f9fa; }

/* Tables with rounded card look */
.card .table { margin-bottom: 0; }
.card .table th:first-child { border-top-left-radius: 0.5rem; }
.card .table th:last-child { border-top-right-radius: 0.5rem; }
.card .table tbody tr:last-child td:first-child { border-bottom-left-radius: 0.5rem; }
.card .table tbody tr:last-child td:last-child { border-bottom-right-radius: 0.5rem; }

.table th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #6c757d;
  white-space: nowrap;
  border-bottom-width: 2px;
  background: #f8f9fa;
}
.table td { font-size: 0.82rem; vertical-align: middle; }
.table tr { cursor: default; }

th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { background: #e2e6ea; }
th.sortable .sort-icon::after { content: " \2195"; opacity: 0.3; }
th.sortable.asc .sort-icon::after { content: " \2191"; opacity: 1; }
th.sortable.desc .sort-icon::after { content: " \2193"; opacity: 1; }

/* Thumbnails */
.thumb {
  width: 46px; height: 46px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid #dee2e6;
}
.thumb-placeholder {
  width: 46px; height: 46px;
  border-radius: 4px;
  background: #e9ecef;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #adb5bd;
  font-size: 0.65rem;
}

/* Badges */
.badge-enabled { background: #d1e7dd !important; color: #0f5132 !important; }
.badge-sold { background: #f8d7da !important; color: #842029 !important; }
.badge-scrapped { background: #e2e3e5 !important; color: #41464b !important; }
.badge-reserved { background: #fff3cd !important; color: #664d03 !important; }
.badge-disabled { background: #e9ecef !important; color: #6c757d !important; }

/* Gallery */
.gallery {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.gallery img {
  width: 180px; height: 130px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid #dee2e6;
  cursor: pointer;
  transition: border-color 0.15s;
}
.gallery img:hover { border-color: #1a73e8; }

/* Editable gallery */
.editable-gallery {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: flex-start;
}
.gallery-item {
  position: relative;
  display: inline-block;
}
.gallery-item img {
  width: 180px; height: 130px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid #dee2e6;
  cursor: pointer;
  transition: border-color 0.15s;
}
.gallery-item img:hover { border-color: #1a73e8; }
.gallery-delete {
  position: absolute;
  top: -6px; right: -6px;
  background: #fff;
  border: none;
  border-radius: 50%;
  color: #e74c3c;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  transition: transform 0.12s;
}
.gallery-delete:hover { transform: scale(1.15); color: #c0392b; }
.gallery-upload {
  width: 180px; height: 130px;
  border: 2px dashed #cbd5e1;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #94a3b8;
  font-size: 0.78rem;
  font-weight: 600;
  transition: border-color 0.15s, color 0.15s;
  gap: 0.3rem;
}
.gallery-upload i { font-size: 1.5rem; }
.gallery-upload:hover { border-color: #1a73e8; color: #1a73e8; }
.gallery-upload .drop-hint { font-size: 0.65rem; font-weight: 400; opacity: 0.7; }
.gallery-upload.dragover { border-color: #1a73e8; background: #e8f0fe; color: #1a73e8; }

/* Mobile photo upload slots */
.mp-slot {
  width: 200px; height: 200px;
  border: 2px dashed #cbd5e1;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #94a3b8;
  font-size: 0.8rem;
  font-weight: 600;
  position: relative;
  overflow: hidden;
  background: #fafbfc;
  transition: border-color 0.15s;
}
.mp-slot i { font-size: 2.5rem; margin-bottom: 0.3rem; }
.mp-slot:hover { border-color: #1a73e8; color: #1a73e8; }
.mp-slot img {
  width: 100%; height: 100%;
  object-fit: cover;
  position: absolute;
  top: 0; left: 0;
}
.mp-slot .mp-delete {
  position: absolute; top: 4px; right: 4px;
  background: rgba(255,255,255,0.9);
  border: none; border-radius: 50%;
  color: #e74c3c; font-size: 1.2rem;
  cursor: pointer; padding: 0; line-height: 1;
  z-index: 2;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
.mp-slot .mp-delete:hover { transform: scale(1.15); }
@media (max-width: 768px) {
  .mp-slot { width: 45vw; height: 45vw; }
}

/* Form rows */
.vhd-row {
  display: flex;
  gap: 0.7rem;
  margin-bottom: 0.7rem;
  flex-wrap: wrap;
}
.vhd-field {
  flex: 1;
  min-width: 130px;
}
.vhd-field label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  color: #6c757d;
  text-transform: uppercase;
  margin-bottom: 0.2rem;
}
.vhd-field input,
.vhd-field textarea,
.vhd-field select {
  width: 100%;
  padding: 0.4rem 0.55rem;
  border: 1px solid #dee2e6;
  border-radius: 0.375rem;
  font-size: 0.88rem;
  background: #fafbfc;
  transition: border-color 0.15s;
}
.vhd-field input:focus,
.vhd-field textarea:focus,
.vhd-field select:focus {
  outline: none;
  border-color: #86b7fe;
  box-shadow: 0 0 0 0.2rem rgba(13,110,253,.15);
  background: #fff;
}
.vhd-checks {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.4rem;
}
.vhd-check {
  display: flex !important;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.84rem !important;
  text-transform: none !important;
  cursor: pointer;
}
.vhd-check input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }

/* Filter labels */
.filter-group label {
  font-size: 0.7rem;
  font-weight: 600;
  color: #6c757d;
  text-transform: uppercase;
  margin-bottom: 0.15rem;
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.75);
  z-index: 1060;
  align-items: center;
  justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal-overlay img {
  max-width: 80vw;
  max-height: 90vh;
  border-radius: 8px;
}
.modal-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  font-size: 2rem;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  backdrop-filter: blur(4px);
}
.modal-arrow:hover { background: rgba(255,255,255,0.3); }
.modal-arrow-left { left: 1.5rem; }
.modal-arrow-right { right: 1.5rem; }
.modal-counter {
  position: absolute;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255,255,255,0.7);
  font-size: 0.8rem;
  font-weight: 600;
}

/* Responsive */

/* Hamburger button (hidden on desktop) */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 0.6rem;
  left: 0.6rem;
  z-index: 1051;
  background: #1e293b;
  color: #fff;
  border: none;
  border-radius: 6px;
  width: 40px;
  height: 40px;
  font-size: 1.3rem;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

/* Sidebar overlay (mobile) */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1049;
}

@media (max-width: 991px) {
  .sidebar-toggle { display: flex; }
  .sidebar-overlay.active { display: block; }

  .sidebar {
    width: var(--sidebar-w);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar .brand { display: block; }
  .sidebar .nav-link span:not(.icon) { display: inline; }
  .sidebar .nav-link .submenu-arrow { display: inline; }
  .sidebar .submenu.open .nav-link.nav-sub span:not(.icon) { display: inline; }

  .main-content {
    margin-left: 0;
    padding: 3.5rem 0.7rem 0.7rem;
  }

  /* KPI grid: 2 columns on tablet, 1 on phone */
  .stats-kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Filter rows: stack vertically */
  .card-body .row.g-2 { flex-direction: column; }
  .card-body .row.g-2 .col-auto { width: 100%; }
  .card-body .row.g-2 .col-auto .form-select,
  .card-body .row.g-2 .col-auto .form-control { width: 100% !important; }
  .card-body .filter-group { width: 100%; }
  .card-body .filter-group select,
  .card-body .filter-group input { width: 100% !important; }

  /* Tables: horizontal scroll */
  .table-responsive { -webkit-overflow-scrolling: touch; }

  /* Gallery smaller on mobile */
  .gallery img { width: 120px; height: 90px; }
  .gallery-item img { width: 120px; height: 90px; }
  .gallery-upload { width: 120px; height: 90px; }

  /* Modal image: full width */
  .modal-overlay img { max-width: 95vw; }
}

@media (max-width: 575px) {
  .main-content { padding: 3.2rem 0.4rem 0.5rem; }

  .stats-kpi-grid {
    grid-template-columns: 1fr !important;
  }

  .stat-card .kpi-value { font-size: 1.4rem; }

  h4.fw-bold { font-size: 1.1rem; }

  .table th, .table td { font-size: 0.72rem; padding: 0.3rem 0.4rem; }

  .gallery img { width: 90px; height: 70px; }
  .gallery-item img { width: 90px; height: 70px; }
  .gallery-upload { width: 90px; height: 70px; }

  /* VHD form fields: full width */
  .vhd-row { flex-direction: column; }
  .vhd-field { min-width: 100%; }

  .mp-slot { width: 44vw; height: 44vw; }
}

.report-card { cursor:pointer; transition: box-shadow 0.15s, transform 0.15s; }
.report-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.12); transform: translateY(-2px); }

/* Barcode scanner */
#scanner-reader { border-radius: 8px; overflow: hidden; }
#scanner-reader video { border-radius: 8px; }
#scanner-reader #qr-shaded-region { border-color: rgba(26, 115, 232, 0.5) !important; }
#scanner-part-info td { padding: 0.4rem 0.6rem; font-size: 0.88rem; }
#scanner-sale-section .btn { font-size: 1rem; padding: 0.6rem 1rem; }
@media (max-width: 575px) {
  #scanner-reader { max-width: 100% !important; }
  #scanner-sale-section .btn { font-size: 0.9rem; padding: 0.5rem; }
}
