/* =========================
   STOCK VIEW LAYOUT
========================= */
.stock-view {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.stock-header h2 {
  margin: 0 0 6px 0;
}

.stock-header .subtle,
.subtle {
  margin: 0;
  opacity: 0.8;
  color: #94a3b8;
}

/* =========================
   STOCK TOOLBAR
========================= */
.stock-toolbar,
.stock-modern-toolbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 190px 200px auto auto auto;
  gap: 12px;
  align-items: center;
}

.stock-sticky-toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(15, 23, 42, 0.94);
  backdrop-filter: blur(12px);
  padding: 8px 0;
}

.stock-toolbar .search {
  width: 100%;
  min-width: 0;
}

.stock-select {
  min-width: 0;
  height: 42px;
  background: #020617;
  color: #e2e8f0;
  border: 1px solid #1e293b;
  border-radius: 10px;
  padding: 0 12px;
}

.stock-toggle {
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #cbd5e1;
  font-size: 14px;
  background: #020617;
  border: 1px solid #1e293b;
  border-radius: 10px;
  padding: 0 12px;
  white-space: nowrap;
}

.stock-toggle input {
  accent-color: #3b82f6;
}

/* =========================
   STOCK SUMMARY
========================= */
.stock-summary,
.stock-modern-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
}

.stock-summary-card {
  background: #020617;
  border: 1px solid #1e293b;
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.18);
}

.stock-summary-card span {
  display: block;
  color: #94a3b8;
  font-size: 13px;
  margin-bottom: 6px;
}

.stock-summary-card strong {
  display: block;
  font-size: 26px;
  line-height: 1;
  color: #f8fafc;
}

.stock-summary-card.warning {
  border-color: #7f1d1d;
  background: linear-gradient(180deg, #1f0a0a 0%, #14080a 100%);
}

/* =========================
   STOCK ERROR / EMPTY
========================= */
.stock-error {
  background: #2a0c0c;
  border: 1px solid #7f1d1d;
  color: #fecaca;
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 14px;
}

.stock-empty,
.stock-modern-empty {
  background: #020617;
  border: 1px dashed #334155;
  border-radius: 16px;
  padding: 24px;
  text-align: center;
  color: #94a3b8;
}

.stock-empty h3,
.stock-modern-empty h3 {
  margin: 0 0 8px 0;
  color: #e2e8f0;
}

/* =========================
   STOCK GRID / CARD
========================= */
.stock-results,
.stock-modern-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.stock-modern-card,
.stock-card {
  background: #020617;
  border: 1px solid #1e293b;
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.stock-modern-card:hover,
.stock-card:hover {
  border-color: #334155;
  transform: translateY(-1px);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.26);
}

.stock-modern-card.is-low,
.stock-card.is-low {
  border-color: #7f1d1d;
}

.stock-modern-card.is-favourite {
  border-color: #f59e0b;
}

.stock-modern-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.stock-title-wrap {
  min-width: 0;
}

.stock-card-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.stock-card-title-row h3,
.stock-card h3 {
  margin: 0;
  font-size: 19px;
  color: #f8fafc;
}

.stock-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  color: #cbd5e1;
  font-size: 14px;
}

.stock-card-meta strong {
  color: #e5e7eb;
}

.stock-card-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.stock-modern-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 16px;
  margin-top: 18px;
  align-items: start;
}

/* =========================
   PART IMAGE / FAVOURITE
========================= */
.stock-part-image {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  object-fit: cover;
  border: 1px solid #1e293b;
  background: #0f172a;
}

.stock-favourite-btn {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid #334155;
  background: #0f172a;
  color: #64748b;
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.stock-favourite-btn:hover,
.stock-favourite-btn.active {
  background: #451a03;
  color: #fbbf24;
  border-color: #f59e0b;
  transform: translateY(-1px);
}

/* =========================
   STOCK LOCATION TILES
========================= */
.stock-location-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
}

.stock-location-tile {
  background: #0f172a;
  border: 1px solid #1e293b;
  border-left: 4px solid var(--depot-colour, #3b82f6);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.stock-location-action {
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.stock-location-action:hover {
  border-color: #3b82f6;
  background: #172554;
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.22);
}

.stock-location-action:hover .stock-location-qty {
  background: #2563eb;
  color: #ffffff;
}

.stock-location-action:active {
  transform: scale(0.98);
}

.stock-location-tile strong {
  display: block;
  color: #f8fafc;
  font-size: 14px;
  margin-bottom: 3px;
}

.stock-location-tile span,
.stock-location-tile small {
  display: block;
  color: #94a3b8;
  font-size: 12px;
}

.stock-location-qty {
  min-width: 40px;
  height: 40px;
  border-radius: 12px;
  background: #1e3a8a;
  color: #bfdbfe;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.stock-location-tile.low-stock {
  background: #450a0a;
  border-color: #7f1d1d;
}

.stock-location-tile.low-stock .stock-location-qty {
  background: #7f1d1d;
  color: #fee2e2;
}

.selected-transfer-tile {
  border-color: #f59e0b !important;
  background: rgba(245, 158, 11, 0.12) !important;
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.22);
}

/* =========================
   STOCK TOTALS PANEL
========================= */
.stock-modern-totals {
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 16px;
  padding: 14px;
  display: grid;
  gap: 10px;
}

.stock-modern-totals div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  border-bottom: 1px solid rgba(148, 163, 184, 0.14);
  padding-bottom: 8px;
}

.stock-modern-totals div:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.stock-modern-totals span {
  color: #94a3b8;
  font-size: 13px;
}

.stock-modern-totals strong {
  color: #f8fafc;
  font-size: 14px;
  text-align: right;
}

/* =========================
   EXPANDED PANELS
========================= */
.stock-expanded-panel {
  margin-top: 18px;
  border-top: 1px solid rgba(148, 163, 184, 0.16);
  padding-top: 16px;
}

.stock-expanded-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
}

.stock-info-panel {
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 16px;
  padding: 14px;
  min-height: 120px;
}

.stock-info-panel h4 {
  margin: 0 0 10px 0;
  color: #f8fafc;
  font-size: 15px;
}

.stock-info-panel p {
  margin: 0 0 10px 0;
  color: #cbd5e1;
}

.stock-reorder-panel {
  border-color: #f59e0b;
  background: linear-gradient(180deg, rgba(245, 158, 11, 0.14), rgba(15, 23, 42, 0.95));
}

.stock-mini-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
  padding: 8px 0;
  color: #cbd5e1;
  font-size: 13px;
}

.stock-mini-row:last-child {
  border-bottom: 0;
}

.stock-mini-row strong {
  color: #f8fafc;
}

.stock-timeline {
  position: relative;
  display: grid;
  gap: 10px;
}

.stock-timeline-item {
  position: relative;
  padding-left: 18px;
  color: #cbd5e1;
}

.stock-timeline-item::before {
  content: "";
  position: absolute;
  left: 0;
  top: 5px;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #3b82f6;
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.14);
}

.stock-timeline-item strong,
.stock-timeline-item span,
.stock-timeline-item small {
  display: block;
}

.stock-timeline-item strong {
  color: #f8fafc;
  font-size: 13px;
}

.stock-timeline-item span {
  color: #cbd5e1;
  font-size: 12px;
}

.stock-timeline-item small {
  color: #94a3b8;
  font-size: 11px;
  margin-top: 2px;
}

/* =========================
   BUTTONS / BADGES
========================= */
.btn-details {
  background: #2563eb;
  color: white;
  border: 0;
  border-radius: 10px;
  padding: 11px 15px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  transition: background 0.15s ease, transform 0.15s ease;
}

.btn-details:hover {
  background: #1d4ed8;
  transform: translateY(-1px);
}

.stock-scan-btn {
  background: #0f766e;
}

.stock-scan-btn:hover {
  background: #0d9488;
}

.stock-transfer-selected {
  background: #f59e0b;
  color: #111827;
}

.stock-transfer-selected:hover {
  background: #fbbf24;
}

.low-badge,
.ok-badge,
.reserved-badge {
  display: inline-flex;
  align-items: center;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.low-badge {
  background: #7f1d1d;
  color: #fee2e2;
  border: 1px solid #b91c1c;
}

.ok-badge {
  background: #064e3b;
  color: #bbf7d0;
  border: 1px solid #047857;
}

.reserved-badge {
  background: #312e81;
  color: #c7d2fe;
  border: 1px solid #4338ca;
}

.hidden {
  display: none !important;
}

/* =========================
   STOCK DETAIL MODAL
========================= */
#stockDetailModal .modal-content {
  width: min(92vw, 680px);
  max-height: calc(100dvh - 40px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#stockDetailModal .modal-header {
  flex-shrink: 0;
}

#stockDetailModal .modal-body {
  overflow-y: auto;
  flex: 1;
  padding: 18px 22px;
}

#stockDetailModal .form-group {
  margin-bottom: 14px;
}

#stockDetailModal #auditLog {
  background: #041225;
  border: 1px solid #294a77;
  border-radius: 12px;
  padding: 12px;
  max-height: 260px;
  overflow-y: auto;
  font-size: 13px;
}

#stockDetailModal .modal-footer {
  flex-shrink: 0;
  padding: 14px 22px;
}

/* =========================
   LOCATION ROWS INSIDE MODAL
========================= */
.detail-location-row {
  width: 100%;
  text-align: left;
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 12px;
  padding: 10px;
  margin-bottom: 8px;
  cursor: pointer;
  color: #e2e8f0;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.detail-location-row:hover {
  border-color: #3b82f6;
  background: #172554;
  transform: translateY(-1px);
}

.selected-location-row {
  border: 1px solid #3b82f6 !important;
  background: rgba(37, 99, 235, 0.14) !important;
}

.selected-location-row small {
  display: block;
  margin-top: 4px;
  color: #93c5fd;
}

/* =========================
   ADJUST / TRANSFER MODALS
========================= */
#adjustModal textarea {
  height: 80px !important;
  min-height: 80px;
  max-height: 120px;
}

#transferModal .modal-content,
#adjustModal .modal-content {
  width: min(92vw, 560px);
}

#transferModal .form-group,
#adjustModal .form-group {
  margin-bottom: 14px;
}

#transferModal select,
#transferModal input,
#adjustModal input,
#adjustModal textarea {
  width: 100%;
}

/* =========================
   LIGHT MODE SUPPORT
========================= */
body.light-mode .stock-sticky-toolbar {
  background: rgba(248, 250, 252, 0.94);
}

body.light-mode .stock-select,
body.light-mode .stock-toggle {
  background: #ffffff !important;
  color: #0f172a !important;
  border-color: #cbd5e1 !important;
}

body.light-mode .stock-summary-card,
body.light-mode .stock-modern-card,
body.light-mode .stock-card,
body.light-mode .stock-modern-totals,
body.light-mode .stock-location-tile,
body.light-mode .stock-empty,
body.light-mode .stock-modern-empty,
body.light-mode .stock-info-panel {
  background: #ffffff !important;
  color: #0f172a !important;
  border-color: #e5e7eb !important;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.06);
}

body.light-mode .stock-summary-card span,
body.light-mode .stock-card-meta,
body.light-mode .stock-location-tile span,
body.light-mode .stock-location-tile small,
body.light-mode .stock-modern-totals span,
body.light-mode .stock-info-panel p,
body.light-mode .stock-mini-row,
body.light-mode .stock-timeline-item span,
body.light-mode .stock-timeline-item small,
body.light-mode .subtle {
  color: #64748b !important;
}

body.light-mode .stock-summary-card strong,
body.light-mode .stock-card-title-row h3,
body.light-mode .stock-card h3,
body.light-mode .stock-card-meta strong,
body.light-mode .stock-location-tile strong,
body.light-mode .stock-modern-totals strong,
body.light-mode .stock-empty h3,
body.light-mode .stock-modern-empty h3,
body.light-mode .stock-info-panel h4,
body.light-mode .stock-mini-row strong,
body.light-mode .stock-timeline-item strong {
  color: #0f172a !important;
}

body.light-mode .stock-location-qty {
  background: #dbeafe !important;
  color: #1d4ed8 !important;
}

body.light-mode .stock-summary-card.warning,
body.light-mode .stock-modern-card.is-low,
body.light-mode .stock-card.is-low {
  border-color: #fecaca !important;
  background: #ffffff !important;
}

body.light-mode .stock-location-tile.low-stock {
  background: #fef2f2 !important;
  border-color: #fecaca !important;
}

body.light-mode .stock-location-tile.low-stock .stock-location-qty {
  background: #fee2e2 !important;
  color: #b91c1c !important;
}

body.light-mode .stock-location-action:hover {
  background: #eff6ff !important;
  border-color: #93c5fd !important;
}

body.light-mode .selected-transfer-tile {
  background: #fffbeb !important;
  border-color: #f59e0b !important;
}

body.light-mode .detail-location-row {
  background: #ffffff !important;
  border-color: #e2e8f0 !important;
  color: #0f172a !important;
}

body.light-mode .detail-location-row:hover {
  background: #eff6ff !important;
  border-color: #93c5fd !important;
}

body.light-mode .selected-location-row {
  background: #dbeafe !important;
  border-color: #60a5fa !important;
}

body.light-mode .low-badge {
  background: #fee2e2 !important;
  color: #b91c1c !important;
  border-color: #fecaca !important;
}

body.light-mode .ok-badge {
  background: #dcfce7 !important;
  color: #166534 !important;
  border-color: #bbf7d0 !important;
}

body.light-mode .reserved-badge {
  background: #e0e7ff !important;
  color: #3730a3 !important;
  border-color: #c7d2fe !important;
}

body.light-mode #stockDetailModal #auditLog {
  background: #f8fafc !important;
  color: #0f172a !important;
  border-color: #cbd5e1 !important;
}

/* =========================
   RESPONSIVE
========================= */
@media (max-width: 1200px) {
  .stock-toolbar,
  .stock-modern-toolbar {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .stock-toolbar .search {
    grid-column: 1 / -1;
  }
}

@media (max-width: 900px) {
  .stock-toolbar,
  .stock-modern-toolbar {
    grid-template-columns: 1fr 1fr;
  }

  .stock-modern-card-header {
    flex-direction: column;
  }

  .stock-card-actions {
    width: 100%;
    justify-content: stretch;
  }

  .stock-card-actions .btn-details {
    flex: 1;
  }

  .stock-modern-body {
    grid-template-columns: 1fr;
  }

  .stock-modern-totals {
    width: 100%;
  }

  .btn-details {
    width: 100%;
  }
}

@media (max-width: 640px) {
  .stock-toolbar,
  .stock-modern-toolbar {
    grid-template-columns: 1fr;
  }

  .stock-select,
  .stock-toggle,
  .stock-scan-btn,
  .stock-transfer-selected {
    width: 100%;
  }

  #stockDetailModal .modal-footer {
    flex-direction: column;
  }

  #stockDetailModal .modal-footer button {
    width: 100%;
  }

  .stock-location-grid {
    grid-template-columns: 1fr;
  }

  .stock-expanded-grid {
    grid-template-columns: 1fr;
  }

  .stock-modern-card {
    padding: 14px;
  }
}