/* ===========================================
   INVENTORY TABLE (inside sidebar)
   =========================================== */

#inventory-container {
    /* No margin-top — sidebar section handles spacing */
}

#inventory-container h3 {
    text-align: center;
    margin-bottom: var(--space-lg);
    color: var(--text-primary);
    font-weight: 600;
    font-size: 1.125rem;
}

#inventory-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-primary);
    font-size: 12px;
    /* Sprint 5: table-layout: fixed respects the <col> widths in HTML
       and prevents long Name values from blowing out the table width. */
    table-layout: fixed;
}

#inventory-table thead {
    background: var(--bg-primary);
    position: sticky;
    top: 0;
    z-index: 1;
}

/* Table headers hidden by default — shown when real data renders.
   inventoryManager.render() adds .has-data; clear() removes it. */
#inventory-table:not(.has-data) thead {
    display: none;
}

#inventory-table th {
    padding: var(--space-sm);
    text-align: left;
    font-weight: 500;
    font-size: var(--text-xs);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--bg-tertiary);
    min-height: 36px;
    white-space: nowrap;
}

/* Sortable headers — tap to toggle sort direction */
#inventory-table th.sortable {
    cursor: pointer;
    user-select: none;
    transition: color var(--duration-fast);
}

#inventory-table th.sortable:active,
#inventory-table th.sortable.sorted {
    color: var(--text-primary);
}

.sort-icon {
    font-size: 8px;
    margin-left: 2px;
    vertical-align: middle;
}

#inventory-table td {
    padding: var(--space-sm);
    text-align: left;
    color: var(--text-primary);
}

/* Two-line rows: both columns stack two lines vertically */
.inventory-row__info,
.inventory-row__qty-cell {
    white-space: normal;
    line-height: 1.3;
    vertical-align: top;
}

/* Left column — Name + Order · Item */
.inventory-row__name {
    display: block;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.inventory-row__meta {
    display: block;
    font-size: var(--text-sm);
    color: var(--text-muted);
    margin-top: 3px;
    letter-spacing: 0.3px;
}

/* Right column — Qty + Grade stacked, left-aligned like name column */
.inventory-row__qty-cell {
    text-align: left;
}

.inventory-row__qty {
    display: block;
    font-size: var(--text-sm);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    color: var(--text-primary);
}

.inventory-row__grade {
    display: block;
    font-size: var(--text-sm);
    color: var(--text-muted);
    margin-top: 3px;
}

/* First column — extra left padding compensates for scrollbar on the left.
   Without this, plant names sit flush against the scrollbar. */
#inventory-table thead th:first-child,
#inventory-table tbody td:first-child {
    padding-left: var(--space-lg);
}

/* Qty column — left-aligned so number + grade lines share the same edge.
   Extra right padding for breathing room against sidebar right edge. */
#inventory-table thead th:last-child,
#inventory-table tbody td:last-child {
    text-align: left;
    padding-right: var(--space-lg);
}

#inventory-table tbody tr {
    border-bottom: 1px solid var(--bg-tertiary);
    transition: background 0.1s ease;
}

#inventory-table tbody tr:last-child {
    border-bottom: none;
}

@media (hover: hover) {
    #inventory-table tbody tr:hover {
        background: var(--bg-tertiary);
    }
}

/* Current pick — the lot salespeople should sell from first.
   Class added by inventoryManager.render() based on is_current_pick flag. */
#inventory-table tbody tr.current-pick {
    background: var(--accent-soft);
}


/* -------------------------------------------
   Sprint 5: Compact Rows — Clickable + Expandable
   ------------------------------------------- */

/* Compact rows are clickable — pointer cursor signals interactivity */
#inventory-table tbody tr.inventory-row {
    cursor: pointer;
}

/* Expanded row gets a subtle accent highlight so the user knows which
   row the detail panel belongs to */
#inventory-table tbody tr.inventory-row.expanded {
    background: var(--bg-tertiary);
    border-bottom-color: transparent;
}

/* Current-pick stays green even when expanded — pick status outranks expand state */
#inventory-table tbody tr.inventory-row.expanded.current-pick {
    background: var(--accent-soft);
}

/* Detail row — inline panel below the expanded compact row. */
#inventory-table tbody tr.detail-row {
    background: var(--bg-secondary);
    border-bottom: none;
}

@media (hover: hover) {
    #inventory-table tbody tr.detail-row:hover {
        background: var(--bg-secondary);  /* Don't change on hover — it's not clickable */
    }
}

#inventory-table tbody tr.detail-row td {
    padding: var(--space-md) var(--space-xl) var(--space-md) var(--space-lg);
    max-width: none;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
}

/* Detail card — glass-style raised panel within the list.
   Uses the glass visual language (noise, rim, shadow) without
   backdrop-blur (solid white behind it, blur would be invisible). */
.detail-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    padding: var(--space-md);
    box-shadow: 0 2px 8px rgba(40, 50, 40, 0.06),
                0 0 0 1px rgba(0, 0, 0, 0.03),
                inset 0 1px 0 0 rgba(255, 255, 255, 0.6),
                inset 1px 0 0 0 rgba(255, 255, 255, 0.2);
}

.detail-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: var(--glass-noise);
    border-radius: inherit;
    pointer-events: none;
    z-index: 0;
}

/* Hero stats row — Available, Reserved, Grade as big numbers */
.detail-card__stats {
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: var(--space-sm) 0;
}

.detail-card__stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    flex: 1;
}

.detail-card__stat-value {
    font-size: var(--text-xl);
    font-weight: 700;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
    line-height: 1;
}


.detail-card__stat-label {
    font-size: var(--text-xs);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.detail-card__divider {
    width: 1px;
    height: 28px;
    background: var(--border-light);
    flex-shrink: 0;
}

/* All fields — single column list with copy buttons */
.detail-card__fields {
    display: flex;
    flex-direction: column;
}

.detail-card__field {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-xs) 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
    min-height: 28px;
}

.detail-card__field:last-child {
    border-bottom: none;
}

.detail-card__field-label {
    font-size: var(--text-xs);
    color: var(--text-muted);
    flex-shrink: 0;
    width: 56px;
    text-align: left;
}

.detail-card__field-value {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-primary);
    text-align: right;
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
}

/* Copy button — subtle, only visible on hover (desktop) or always on touch */
.detail-card__copy {
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    opacity: 0.4;
    transition: opacity var(--duration-fast), color var(--duration-fast);
}

.detail-card__copy-icon {
    width: 12px !important;
    height: 12px !important;
}

.detail-card__field:hover .detail-card__copy,
.detail-card__copy:active {
    opacity: 1;
}

.detail-card__copy:active {
    color: var(--accent);
}

/* On touch devices, always show copy buttons (no hover) */
@media (pointer: coarse) {
    .detail-card__copy {
        opacity: 0.5;
    }
}


/* =========================================================================
   RESPONSIVE — Phone (< 480px)
   4-column fixed table becomes unreadable below 400px sidebar width.
   Hide the least-important column and shrink font size.
   ========================================================================= */

@media (max-width: 480px) {
    #inventory-table {
        font-size: 11px;
    }
}


/* =========================================================================
   BRANDED EMPTY STATE — No lot loaded
   Monrovia logo centered in the inventory area with subtle tagline.
   Hidden when .has-content is added to #inventory-container.
   ========================================================================= */

.sidebar-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: var(--space-2xl);
    text-align: center;
}

.sidebar-empty-icon {
    width: 48px;
    height: 48px;
    color: var(--accent);
    opacity: 0.15;
    user-select: none;
    pointer-events: none;
}

/* Toggle: hide empty state when inventory has content */
#inventory-container.has-content .sidebar-empty-state {
    display: none;
}

/* Toggle: hide table when empty state is visible */
#inventory-container:not(.has-content) #inventory-table {
    display: none;
}


/* =========================================================================
   LOADING STATE — Spinner in inventory table
   Reuses @keyframes spin from map-controls.css.
   ========================================================================= */

/* Centered loading spinner — matches map loading overlay visual weight */
.inventory-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-2xl) 0;
}

.inventory-loading-spinner {
    display: block;
    width: 24px;
    height: 24px;
    border: 3px solid rgba(0, 0, 0, 0.08);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
