/* ============================================
   Chamanke Workspace — Warehouse & Inventory
   Inherits from theme.css universal system
   Brand: Navy #1e293b + Chamanke Red #e52121
   ============================================ */

/* ---- KPI Grid ---- */
.wh-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.wh-kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: all var(--transition-med);
  box-shadow: var(--shadow-card);
}
.wh-kpi-card:hover {
  border-color: #cbd5e1;
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.wh-kpi-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.25rem; flex-shrink: 0;
  color: #fff;
}
.wh-kpi-info { display: flex; flex-direction: column; gap: 2px }
.wh-kpi-value {
  font-size: 1.5rem; font-weight: 800;
  letter-spacing: -0.03em; line-height: 1.1;
  color: var(--text-primary);
}
.wh-kpi-label {
  font-size: 0.76rem; color: var(--text-secondary); font-weight: 500;
}

/* ---- Analytics Layout ---- */
.wh-charts-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-bottom: 24px;
}
.wh-charts-layout .chart-card {
  padding: 16px;
}
.wh-charts-layout .chart-title {
  margin-bottom: 12px;
  font-size: 0.9rem;
}
.wh-charts-layout .chart-container {
  height: 220px;
}
@media (min-width: 1024px) {
  .wh-charts-layout {
    grid-template-columns: 1.5fr 1fr 1fr;
  }
}

/* ---- Toolbar ---- */
.wh-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.wh-toolbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}
.wh-toolbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.wh-search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  transition: all var(--transition-fast);
  flex: 1;
  max-width: 320px;
}
.wh-search-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(229,33,33,0.08);
}
.wh-search-icon { font-size: 0.85rem; opacity: 0.4; flex-shrink: 0 }
.wh-search-input {
  background: none; border: none; outline: none;
  color: var(--text-primary);
  font-size: 0.85rem; font-family: inherit;
  padding: 9px 0; width: 100%;
}
.wh-search-input::placeholder { color: var(--text-tertiary) }

.wh-filter-select {
  padding: 9px 32px 9px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.85rem; font-family: inherit;
  outline: none; cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: all var(--transition-fast);
}
.wh-filter-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(229,33,33,0.08);
}

/* ---- Table ---- */
.wh-table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  box-shadow: var(--shadow-card);
}
.wh-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.wh-table thead { position: sticky; top: 0; z-index: 5 }
.wh-table th {
  background: var(--table-header-bg);
  padding: 12px 16px;
  text-align: left;
  font-weight: 700;
  color: var(--table-header-text);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-right: 1px solid rgba(255,255,255,0.15);
  white-space: nowrap;
  user-select: none;
}
.wh-table th:last-child {
  border-right: none;
}
.wh-table th.sortable { cursor: pointer; transition: color var(--transition-fast) }
.wh-table th.sortable:hover { color: var(--accent) }
.wh-table th.sorted-asc::after { content: '  '; font-size: 0.65rem; color: var(--accent) }
.wh-table th.sorted-desc::after { content: '  '; font-size: 0.65rem; color: var(--accent) }
.wh-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--table-border);
  border-right: 1px solid var(--table-border);
  vertical-align: middle;
  color: var(--text-primary);
}
.wh-table td:last-child {
  border-right: none;
}
.wh-table tbody tr {
  background: var(--bg-card);
  transition: all var(--transition-fast);
  cursor: pointer;
}
.wh-table tbody tr:hover {
  filter: brightness(0.96);
  box-shadow: inset 0 0 0 1px rgba(30,41,59,0.15);
}
.wh-table tbody tr:last-child td { border-bottom: none }

/* Low stock row highlight */
.wh-table tbody tr.wh-low-stock {
  background: rgba(217,119,6,0.04);
}
.wh-table tbody tr.wh-low-stock td:first-child {
  position: relative;
}
.wh-table tbody tr.wh-low-stock td:first-child::before {
  content: '';
  position: absolute;
  left: 0; top: 4px; bottom: 4px;
  width: 3px;
  background: var(--warning);
  border-radius: 0 2px 2px 0;
}

/* ---- Badges ---- */
.wh-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.76rem;
  font-weight: 600;
  white-space: nowrap;
}
.wh-badge-new { background: rgba(37,99,235,0.08); color: #2563eb }
.wh-badge-good { background: rgba(22,163,74,0.08); color: #16a34a }
.wh-badge-fair { background: rgba(217,119,6,0.08); color: #d97706 }
.wh-badge-damaged { background: rgba(220,38,38,0.08); color: #dc2626 }

.wh-location-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.76rem;
  font-weight: 500;
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border-input);
}
.wh-section-code {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent);
}
.wh-qty {
  font-weight: 700;
  font-size: 0.95rem;
}
.wh-qty-low {
  color: var(--warning);
}
.wh-qty-ok {
  color: var(--text-primary);
}
.wh-unit {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  margin-left: 3px;
}

/* ---- Empty State ---- */
.wh-empty {
  text-align: center;
  padding: 60px 20px;
}
.wh-empty .empty-icon {
  font-size: 3.5rem;
  margin-bottom: 16px;
  opacity: 0.6;
}
.wh-empty h3 {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-primary);
}
.wh-empty p {
  color: var(--text-secondary);
  margin-bottom: 24px;
  font-size: 0.9rem;
}

/* ---- Table Footer ---- */
.wh-table-footer {
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--bg-primary);
}
.wh-record-count {
  font-size: 0.82rem;
  color: var(--text-tertiary);
  font-weight: 500;
}

/* ---- Section Header ---- */
.wh-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  flex-wrap: wrap;
  gap: 10px;
}
.wh-section-header h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* ---- Checkout Badge ---- */
.wh-badge-checkout {
  background: rgba(147,51,234,0.08);
  color: #9333ea;
}

/* ---- Checkout Toggle Button ---- */
.wh-co-toggle {
  display: block;
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-primary);
  border: 1px dashed var(--border-input);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: all var(--transition-fast);
  margin-bottom: 8px;
}
.wh-co-toggle:hover {
  background: var(--bg-primary);
  border-color: var(--accent);
  color: var(--text-primary);
}

/* ---- Checkout History List ---- */
.wh-co-history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
}

/* ---- Checkout Entry Card ---- */
.wh-co-entry {
  padding: 12px 14px;
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  transition: all var(--transition-fast);
}
.wh-co-entry.wh-co-active {
  border-left: 3px solid #9333ea;
  background: rgba(147,51,234,0.03);
}
.wh-co-entry-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.wh-co-entry-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.wh-co-entry-info strong {
  color: var(--text-primary);
}
.wh-co-site {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  background: rgba(30,41,59,0.05);
  padding: 2px 6px;
  border-radius: 4px;
}
.wh-co-purpose {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin: 4px 0;
  font-style: italic;
}
.wh-co-entry-dates {
  display: flex;
  gap: 16px;
  font-size: 0.75rem;
  color: var(--text-tertiary);
  margin-top: 4px;
}
.wh-co-entry-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--bg-primary);
}

/* ---- Responsive ---- */
@media(max-width: 768px) {
  .wh-kpi-grid { grid-template-columns: repeat(2, 1fr) }
  .wh-toolbar { flex-direction: column; align-items: stretch }
  .wh-toolbar-left { flex-direction: column }
  .wh-search-wrap { max-width: 100% }
  .wh-toolbar-right { justify-content: flex-end }
}
@media(max-width: 480px) {
  .wh-kpi-grid { grid-template-columns: 1fr }
}

/* ===== IMPROVEMENTS ===== */

/* Analytics block — header + collapsible chart layout */
.wh-analytics-block { margin-bottom: 18px; }
.wh-analytics-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  background: transparent; border: 1px solid var(--border-primary);
  color: var(--text-secondary);
  padding: 6px 12px; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 0.82rem; font-weight: 600;
  margin-bottom: 10px;
  transition: all var(--transition-fast);
}
.wh-analytics-toggle:hover { background: var(--bg-input); color: var(--text-primary); }

/* Sticky toolbar so it stays visible when scrolling the table */
.wh-toolbar-sticky {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg-main);
  padding: 10px 0;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border-primary);
}

/* Persistent + Add button emphasis */
.wh-add-btn { font-weight: 700; }

/* Square icon-only secondary buttons in toolbar */
.btn-icon-square {
  width: 36px; height: 36px;
  padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1rem;
}

/* Low Stock toggle button */
.wh-low-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.82rem; font-weight: 600;
  transition: all var(--transition-fast);
}
.wh-low-toggle:hover { color: var(--text-primary); border-color: var(--warning); }
.wh-low-toggle.active {
  background: rgba(217,119,6,0.14);
  border-color: var(--warning);
  color: var(--warning);
}
.wh-low-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  background: var(--warning); color: #fff;
  border-radius: 9px;
  font-size: 0.72rem; font-weight: 700;
}

/* Active filter chips strip */
.wh-filter-chips {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin: 0 0 12px;
  font-size: 0.78rem;
}
.wh-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 8px 4px 10px;
  background: var(--bg-input); border: 1px solid var(--border-input);
  border-radius: 14px;
  color: var(--text-secondary);
}
.wh-chip button {
  background: none; border: none; cursor: pointer;
  color: var(--text-tertiary); font-size: 1rem; line-height: 1;
  padding: 0 2px;
}
.wh-chip button:hover { color: var(--accent); }
.wh-chip-clear-all {
  background: none; border: none; color: var(--accent);
  cursor: pointer; font-weight: 600; font-size: 0.78rem;
  padding: 4px 8px;
}
.wh-chip-clear-all:hover { text-decoration: underline; }

/* Quick qty +/- in table cell */
.wh-qty-cell {
  display: inline-flex; align-items: center; gap: 6px;
}
.wh-qty-val { min-width: 56px; text-align: center; }
.wh-qty-step {
  width: 24px; height: 24px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg-input); border: 1px solid var(--border-input);
  color: var(--text-secondary);
  border-radius: 6px; cursor: pointer;
  font-size: 1rem; font-weight: 700; line-height: 1;
  transition: all var(--transition-fast);
  user-select: none;
}
.wh-qty-step:hover {
  background: var(--accent); color: #fff; border-color: var(--accent);
}

/* Small hint text used on form labels */
.wh-hint {
  font-weight: 400;
  color: var(--text-tertiary);
  font-size: 0.75em;
  margin-left: 4px;
}

/* ===== ATTACHMENTS ===== */
.wh-dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px;
  padding: 24px 16px;
  border: 2px dashed var(--border-primary);
  border-radius: var(--radius-md);
  background: var(--bg-input);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: center;
}
.wh-dropzone:hover, .wh-dropzone-active {
  border-color: var(--accent);
  background: rgba(229,33,33,0.04);
}
.wh-dropzone-icon { font-size: 1.6rem; }
.wh-dropzone-text { font-weight: 600; color: var(--text-primary); font-size: 0.9rem; }
.wh-dropzone-hint { font-size: 0.75rem; color: var(--text-tertiary); }

.wh-attachments-list {
  display: flex; flex-direction: column; gap: 8px;
  margin-top: 12px;
}
.wh-att-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px;
  background: var(--bg-card-hover);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-sm);
}
.wh-att-thumb {
  width: 48px; height: 48px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid var(--border-primary);
  background: var(--bg-input);
  cursor: zoom-in;
  flex-shrink: 0;
}
.wh-att-thumb-file {
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem;
  cursor: pointer;
}
.wh-att-info { flex: 1; min-width: 0; }
.wh-att-name {
  font-weight: 600; font-size: 0.85rem; color: var(--text-primary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.wh-att-meta { font-size: 0.72rem; color: var(--text-tertiary); margin-top: 2px; }
.wh-att-actions { display: flex; gap: 4px; flex-shrink: 0; }

/* Row badge / inline thumb in the item cell */
.wh-item-cell { display: flex; align-items: center; gap: 8px; }
.wh-row-thumb {
  width: 36px; height: 36px;
  border-radius: 5px;
  object-fit: cover;
  border: 1px solid var(--border-primary);
  cursor: zoom-in;
  flex-shrink: 0;
}
.wh-att-badge {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 7px;
  background: rgba(37,99,235,0.10);
  color: #60a5fa;
  border-radius: 10px;
  font-size: 0.72rem; font-weight: 600;
}
.wh-att-badge-small { font-size: 0.68rem; padding: 1px 6px; }

/* Lightbox viewer */
.wh-viewer {
  position: relative;
  width: 92%; max-width: 1100px;
  max-height: 90vh;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-primary);
  overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-modal);
}
.wh-viewer-close {
  position: absolute; top: 10px; right: 10px;
  z-index: 2;
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.55);
  color: #fff;
  border: none; border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
}
.wh-viewer-close:hover { background: rgba(0,0,0,0.8); }
.wh-viewer-body {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  min-height: 300px;
  background: #0b1220;
  padding: 12px;
}
.wh-viewer-img { max-width: 100%; max-height: 78vh; object-fit: contain; }
.wh-viewer-iframe { width: 100%; height: 78vh; border: none; background: #fff; }
.wh-viewer-fallback {
  text-align: center; color: var(--text-secondary);
}
.wh-viewer-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  border-top: 1px solid var(--border-primary);
  background: var(--bg-card);
  font-size: 0.82rem;
  color: var(--text-secondary);
  gap: 10px;
}
.wh-viewer-footer #whViewerDownload { padding: 6px 12px; }
