/* ── Visual Warehouse Map (PR 7) ───────────────────────────────────────────
 * Live, color-coded bin grid. Sits alongside the existing /warehouse/map
 * page (whose styles live in wms.css under the .map-shell / .loc-detail
 * blocks); this file owns only the new visual-map layout, cell palette,
 * indicator dots, and live-badge pulse.
 *
 * No selectors here overlap with the legacy .map-* classes — those stay
 * untouched. The new page roots at .vwm-shell so the two pages cannot
 * accidentally share theming.
 *
 * Spec reference: Docs/VisualWarehouseMap-Spec.md §7.4.
 * ─────────────────────────────────────────────────────────────────────── */

/* ── Page shell + layout ────────────────────────────────────────────────── */

.vwm-shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 420px;
    gap: 12px;
    min-height: calc(100vh - 200px);
}

.vwm-canvas-wrap {
    background: var(--surface, #fff);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 6px;
    padding: 12px;
    overflow: hidden;
}

.vwm-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 6px 4px 10px;
    border-bottom: 1px solid var(--border, #e5e7eb);
    margin-bottom: 10px;
}

.vwm-toolbar-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted, #6b7280);
}

.vwm-toolbar-spacer { flex: 1; }

.vwm-overlay-toggle {
    display: inline-flex;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 4px;
    overflow: hidden;
}

.vwm-overlay-toggle button {
    background: transparent;
    border: 0;
    padding: 4px 12px;
    font-size: 12px;
    cursor: pointer;
    color: var(--text-muted, #6b7280);
}

.vwm-overlay-toggle button.on {
    background: var(--primary, #1287cc);
    color: #fff;
}

.vwm-refresh-btn {
    background: transparent;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 4px;
    padding: 4px 10px;
    font-size: 12px;
    cursor: pointer;
}

.vwm-refresh-btn:hover { background: var(--surface-2, #f3f4f6); }
.vwm-refresh-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Live badge (pulse animation) ───────────────────────────────────────── */

.vwm-live-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted, #6b7280);
}

.vwm-live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.vwm-live-dot--online {
    background: #22c55e;
    animation: vwm-pulse 2s infinite;
}

.vwm-live-dot--offline { background: #9ca3af; }

@keyframes vwm-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6); }
    70%  { box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
    100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

/* ── Stats bar ──────────────────────────────────────────────────────────── */

.vwm-stats-bar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.vwm-stat-pill {
    background: var(--surface-2, #f3f4f6);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 999px;
    padding: 4px 12px;
    font-size: 12px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.vwm-stat-pill .vwm-stat-value { font-weight: 600; }

.vwm-stat-pill .vwm-stat-chip {
    width: 8px; height: 8px; border-radius: 50%;
}

.vwm-stat-chip--fresh      { background: #22c55e; }
.vwm-stat-chip--aging      { background: #f59e0b; }
.vwm-stat-chip--overdue    { background: #ef4444; }
.vwm-stat-chip--quarantine { background: #a855f7; }
.vwm-stat-chip--occupancy  { background: #3b82f6; }

/* ── Zone tabs ──────────────────────────────────────────────────────────── */

.vwm-zone-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border, #e5e7eb);
    margin-bottom: 10px;
    overflow-x: auto;
}

.vwm-zone-tab {
    background: transparent;
    border: 0;
    padding: 8px 14px;
    font-size: 13px;
    cursor: pointer;
    color: var(--text-muted, #6b7280);
    border-bottom: 2px solid transparent;
    white-space: nowrap;
}

.vwm-zone-tab.on {
    color: var(--primary, #1287cc);
    border-bottom-color: var(--primary, #1287cc);
}

.vwm-zone-temp {
    font-size: 11px;
    color: var(--text-muted, #6b7280);
    margin-left: 4px;
}

/* ── Aisle / rack / cell grid ───────────────────────────────────────────── */

.vwm-zone-grid {
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 6px 4px;
    overflow-x: auto;
}

.vwm-aisle {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.vwm-aisle-label {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-muted, #6b7280);
    width: 72px;
    flex-shrink: 0;
    padding-top: 18px;
}

.vwm-aisle-racks {
    display: flex;
    gap: 10px;
    flex-wrap: nowrap;
}

.vwm-rack {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.vwm-rack-label {
    font-size: 10px;
    color: var(--text-muted, #6b7280);
    margin-bottom: 2px;
}

.vwm-rack-levels {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* 2D rack grid — bays run left→right (X-axis), levels stack bottom→top
   (Y-axis). Each .rack-level-row is one tier; bays sit inside, ordered
   by BaySequence. L1 carries .level-ground for the dashed floor cue. */
.wh-map-rack {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 6px;
    padding: 4px;
    gap: 2px;
}

.rack-level-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 2px;
}

.rack-level-row.level-ground {
    border-top: 1px dashed var(--border, #e5e7eb);
    padding-top: 3px;
    margin-top: 1px;
}

.rack-level-label {
    font-size: 10px;
    color: var(--text-muted, #6b7280);
    width: 16px;
    flex-shrink: 0;
    text-align: right;
}

/* ── Bin cell (the unit of the heatmap) ─────────────────────────────────── */

.bin-cell {
    width: 28px;
    height: 20px;
    border-radius: 3px;
    cursor: pointer;
    border: 1px solid var(--border-subtle, #d1d5db);
    position: relative;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.bin-cell:hover {
    transform: scale(1.15);
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    z-index: 10;
}

.bin-cell.selected {
    outline: 2px solid var(--primary, #1287cc);
    outline-offset: 1px;
}

/* Aging overlay palette */
.bin-cell--empty       { background: var(--surface-2, #f3f4f6); }
.bin-cell--fresh       { background: #22c55e; }
.bin-cell--aging       { background: #f59e0b; }
.bin-cell--overdue     { background: #ef4444; }
.bin-cell--quarantine  { background: #a855f7; }

/* Occupancy overlay palette (4 bands) */
.bin-cell--occ-low     { background: #bbf7d0; }
.bin-cell--occ-mid     { background: #86efac; }
.bin-cell--occ-high    { background: #4ade80; }
.bin-cell--occ-full    { background: #16a34a; }

/* Status overrides — always win regardless of overlay */
.bin-cell--inactive    { background: var(--surface-3, #e5e7eb); opacity: 0.4; cursor: not-allowed; }
.bin-cell--blocked     {
    background: repeating-linear-gradient(
        45deg, #f97316 0, #f97316 3px, transparent 3px, transparent 8px);
}
.bin-cell--reserved    {
    background: rgba(245, 158, 11, 0.15);
    border: 1px dashed #f59e0b;
}

/* Indicator dots — corner overlays for anomaly/allocation flags */
.bin-quarantine-dot {
    position: absolute; top: 2px;
    inset-inline-end: 2px;            /* RTL-safe — sits in the trailing corner */
    width: 5px; height: 5px;
    border-radius: 50%; background: #a855f7;
    pointer-events: none;
}
.bin-allocated-dot {
    position: absolute; bottom: 2px;
    inset-inline-end: 2px;
    width: 5px; height: 5px;
    border-radius: 50%; background: #3b82f6;
    pointer-events: none;
}

/* Overfill anomaly — base qty exceeds one SKU's worth at a BinLocation.
   Distinct from the small status dots: a red dashed outline frames the
   whole cell and a centered `!` glyph makes the error legible at a
   glance regardless of overlay mode (aging / occupancy). */
.bin-cell--overfilled {
    outline: 2px dashed #dc2626;       /* red-600 */
    outline-offset: -1px;
    animation: bin-overfill-pulse 1.5s ease-in-out infinite;
}

.bin-overfill-mark {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #dc2626;
    font-weight: 700;
    font-size: 13px;
    line-height: 1;
    text-shadow: 0 0 2px rgba(255,255,255,0.9);
    pointer-events: none;
}

@keyframes bin-overfill-pulse {
    0%, 100% { outline-color: #dc2626; }
    50%      { outline-color: #fca5a5; } /* red-300 — softens then snaps back */
}

/* ── Legend ────────────────────────────────────────────────────────────── */

.vwm-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding: 10px 4px 4px;
    border-top: 1px solid var(--border, #e5e7eb);
    margin-top: 12px;
    font-size: 11px;
    color: var(--text-muted, #6b7280);
}

.vwm-legend-item {
    display: inline-flex; align-items: center; gap: 6px;
}

.vwm-legend-swatch {
    width: 14px; height: 14px; border-radius: 3px;
    border: 1px solid var(--border-subtle, #d1d5db);
}

/* ── Detail panel ──────────────────────────────────────────────────────── */

.vwm-detail {
    background: #18223a;
    color: #e5e7eb;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.vwm-detail-header {
    padding: 16px 18px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.vwm-detail-header.band-fresh      { border-top: 3px solid #22c55e; }
.vwm-detail-header.band-aging      { border-top: 3px solid #f59e0b; }
.vwm-detail-header.band-overdue    { border-top: 3px solid #ef4444; }
.vwm-detail-header.band-quarantine { border-top: 3px solid #a855f7; }
.vwm-detail-header.band-empty      { border-top: 3px solid #4b5563; }

.vwm-detail-code {
    font-family: "IBM Plex Mono", monospace;
    font-size: 18px;
    font-weight: 600;
    color: #fff;
}

.vwm-detail-type {
    font-size: 12px;
    color: rgba(255,255,255,0.55);
    margin-top: 2px;
}

.vwm-detail-customer-badge {
    display: inline-block;
    margin-top: 6px;
    padding: 2px 8px;
    background: rgba(59,130,246,0.18);
    color: #93c5fd;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
}

.vwm-allocated-warning {
    margin: 10px 18px 0;
    padding: 8px 10px;
    background: rgba(59,130,246,0.12);
    border-inline-start: 3px solid #3b82f6;
    color: #bfdbfe;
    font-size: 12px;
    border-radius: 4px;
}

.vwm-detail-body {
    flex: 1;
    overflow-y: auto;
    padding: 14px 18px;
}

.vwm-detail-empty {
    text-align: center;
    padding: 40px 20px;
    color: rgba(255,255,255,0.5);
    font-size: 13px;
}

.vwm-detail-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    font-size: 12px;
}

.vwm-detail-row .vwm-key   { color: rgba(255,255,255,0.55); }
.vwm-detail-row .vwm-val   { color: #fff; }

.vwm-detail-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 14px;
}

.vwm-flag-btn {
    background: #1287cc;
    color: #fff;
    border: 0;
    border-radius: 4px;
    padding: 6px 14px;
    font-size: 12px;
    cursor: pointer;
}

.vwm-flag-btn:hover { background: #1576b3; }
.vwm-flag-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.vwm-flag-msg {
    margin-top: 10px;
    padding: 8px 10px;
    border-radius: 4px;
    font-size: 12px;
}

.vwm-flag-msg.ok  { background: rgba(34,197,94,0.15); color: #86efac; }
.vwm-flag-msg.err { background: rgba(239,68,68,0.15); color: #fca5a5; }

.vwm-section { margin-top: 16px; }
.vwm-section-hdr {
    font-size: 11px;
    text-transform: uppercase;
    color: rgba(255,255,255,0.55);
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.vwm-section-loading,
.vwm-section-empty {
    color: rgba(255,255,255,0.4);
    font-size: 12px;
    padding: 8px 0;
}

.vwm-content-card {
    background: rgba(255,255,255,0.04);
    border-radius: 4px;
    padding: 8px 10px;
    margin-bottom: 6px;
    font-size: 12px;
}

.vwm-content-line1 {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.vwm-content-sku { font-family: "IBM Plex Mono", monospace; color: #fff; }
.vwm-content-qty { color: #fff; font-weight: 500; }
.vwm-content-name { color: rgba(255,255,255,0.7); font-size: 11px; }
.vwm-content-meta {
    display: flex; gap: 6px; flex-wrap: wrap;
    margin-top: 4px;
}
.vwm-content-chip {
    background: rgba(255,255,255,0.05);
    color: rgba(255,255,255,0.6);
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 10px;
}
.vwm-content-chip.mono { font-family: "IBM Plex Mono", monospace; }

/* Loading state */
.vwm-loading-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted, #6b7280);
}

/* Empty state */
.vwm-empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted, #6b7280);
}

/* Page header */
.vwm-page-hdr {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border, #e5e7eb);
}

.vwm-page-hdr h1 {
    font-size: 18px;
    margin: 0;
}

.vwm-page-hdr p {
    margin: 4px 0 0;
    font-size: 12px;
    color: var(--text-muted, #6b7280);
}
