/* src/styles/inventory-popout.css — Inventory Two-Pane Pop-out Panel */

/* ── Overlay backdrop ──────────────────────────────────────────────────────── */
.inv-overlay {
    position: fixed;
    /* Sit below the sticky nav bar (same pattern as the handbook overlay) */
    top: var(--tab-nav-h, 0px);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.inv-overlay.is-open {
    opacity: 1;
    pointer-events: auto;
}

.inv-overlay-backdrop {
    position: absolute;
    inset: 0;
    background: transparent;
    border: none;
    cursor: default;
    width: 100%;
    height: 100%;
}

/* ── Panel shell ───────────────────────────────────────────────────────────── */
.inv-panel {
    position: relative;
    background: #111009;
    border: 1px solid #5a4530;
    border-radius: 12px;
    box-shadow: 0 20px 80px rgba(0,0,0,0.9), 0 0 0 1px rgba(196,168,130,0.08);
    width: min(860px, 96vw);
    height: min(740px, 90vh);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(12px) scale(0.99);
    transition: transform 0.2s ease;
}

.inv-overlay.is-open .inv-panel {
    transform: translateY(0) scale(1);
}

/* ── Title bar ─────────────────────────────────────────────────────────────── */
.inv-titlebar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0.9rem 0.6rem 1.1rem;
    background: linear-gradient(90deg, rgba(80,52,24,0.6) 0%, rgba(20,14,8,0.5) 100%);
    border-bottom: 1px solid #4a3520;
    flex-shrink: 0;
    gap: 0.75rem;
}

.inv-titlebar-left {
    display: flex;
    align-items: center;
    gap: 0.55rem;
}

.inv-icon {
    font-size: 1.1rem;
    line-height: 1;
}

.inv-title {
    font-family: 'Cinzel', serif;
    font-weight: 700;
    font-size: 1rem;
    color: #d4b896;
    letter-spacing: 0.05em;
    margin: 0;
}

.inv-titlebar-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
}

/* Give button */
.inv-give-btn {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.7rem;
    border-radius: 6px;
    border: 1px solid rgba(34,197,94,0.35);
    background: rgba(20,60,35,0.6);
    color: rgba(134,239,172,0.65);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s;
    white-space: nowrap;
}

.inv-give-btn:not(:disabled):hover {
    background: rgba(22,101,52,0.7);
    border-color: rgba(34,197,94,0.7);
    color: #86efac;
}

.inv-give-btn:disabled {
    opacity: 0.32;
    cursor: not-allowed;
}

.inv-give-btn svg {
    flex-shrink: 0;
}

.inv-close-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: transparent;
    border: none;
    color: #6b7280;
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, color 0.15s ease;
    flex-shrink: 0;
}

.inv-close-btn:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
}

/* ── Body (sidebar + content) ──────────────────────────────────────────────── */
.inv-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ── Sidebar wrapper (holds scroll arrows on mobile) ───────────────────────── */
.inv-sidebar-wrapper {
    display: contents; /* transparent on desktop — sidebar fills its own column */
}

/* ── Sidebar ───────────────────────────────────────────────────────────────── */
.inv-sidebar {
    width: 172px;
    flex-shrink: 0;
    border-right: 1px solid #2e2016;
    overflow-y: auto;
    padding: 0.4rem 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
    background: rgba(0,0,0,0.3);
    scrollbar-width: thin;
    scrollbar-color: rgba(180,140,90,0.55) rgba(0,0,0,0.28);
}

/* ── Sidebar scroll arrows (hidden on desktop) ─────────────────────────────── */
.inv-sidebar-arrow {
    display: none;
}

.inv-sidebar::-webkit-scrollbar { width: 8px; }
.inv-sidebar::-webkit-scrollbar-track { background: rgba(0,0,0,0.28); border-radius: 4px; }
.inv-sidebar::-webkit-scrollbar-thumb { background: rgba(180,140,90,0.55); border-radius: 4px; border: 1px solid rgba(0,0,0,0.15); }
.inv-sidebar::-webkit-scrollbar-thumb:hover { background: rgba(214,158,46,0.72); }

.inv-cat-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.5rem 0.6rem 0.5rem 0.9rem;
    background: transparent;
    border: none;
    border-left: 3px solid transparent;
    border-radius: 0 6px 6px 0;
    color: #7a6045;
    cursor: pointer;
    text-align: left;
    transition: background 0.12s, color 0.12s, border-left-color 0.12s;
    margin-right: 3px;
    gap: 0.3rem;
}

.inv-cat-btn:hover {
    background: rgba(196,168,130,0.07);
    color: #c4a882;
}

.inv-cat-btn.active {
    background: rgba(196,168,130,0.12);
    border-left-color: #c4a882;
    color: #e8d5b7;
}

.inv-cat-btn.is-empty {
    opacity: 0.32;
}

.inv-cat-name {
    font-size: 0.77rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    flex: 1;
}

.inv-cat-count {
    font-size: 0.65rem;
    background: rgba(255,255,255,0.06);
    padding: 1px 5px;
    border-radius: 9999px;
    min-width: 18px;
    text-align: center;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

.inv-cat-btn.active .inv-cat-count {
    background: rgba(196,168,130,0.22);
    color: #d4b896;
}

/* ── Content pane ──────────────────────────────────────────────────────────── */
.inv-content {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 1rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(180,140,90,0.55) rgba(0,0,0,0.28);
}

.inv-content::-webkit-scrollbar { width: 8px; }
.inv-content::-webkit-scrollbar-track { background: rgba(0,0,0,0.28); border-radius: 4px; }
.inv-content::-webkit-scrollbar-thumb { background: rgba(180,140,90,0.55); border-radius: 4px; border: 1px solid rgba(0,0,0,0.15); }
.inv-content::-webkit-scrollbar-thumb:hover { background: rgba(214,158,46,0.72); }

.inv-empty-msg {
    color: #4b4030;
    text-align: center;
    padding: 2.5rem 1rem;
    font-style: italic;
    font-size: 0.88rem;
}

/* ── Item rows — dark sleek theme ──────────────────────────────────────────── */

/* Hide the category header (sidebar provides context) */
#inventory-popout-content .inventory-category-header {
    display: none;
}

/* Block layout for single column */
#inventory-popout-content .inventory-column {
    display: block;
}

/* Override parchment with dark card */
#inventory-popout-content .inventory-item {
    background: rgba(18, 14, 9, 0.88) !important;
    background-image: none !important;
    border: 1px solid rgba(80, 58, 34, 0.7);
    border-radius: 8px;
    margin-bottom: 0.4rem;
    padding: 0.45rem 0.75rem;
    position: relative;
    transition: border-color 0.15s, background 0.15s;
    box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

#inventory-popout-content .inventory-item:hover {
    background: rgba(26, 20, 12, 0.95) !important;
    border-color: rgba(120, 90, 50, 0.8);
    box-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

/* Item name color in dark theme */
#inventory-popout-content .item-name {
    color: #d4b896;
    font-size: 0.88rem;
}

/* Rarity labels */
#inventory-popout-content .item-rarity {
    opacity: 0.65;
    font-size: 0.72rem;
}

/* Meta area */
#inventory-popout-content .item-meta {
    gap: 0.5rem;
}

/* ── Equipped items — green border + E badge ───────────────────────────────── */
#inventory-popout-content .inventory-item.is-equipped {
    border-color: rgba(34, 197, 94, 0.55) !important;
    opacity: 1;
    box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.18), 0 1px 4px rgba(0,0,0,0.4);
}

#inventory-popout-content .inventory-item.is-equipped::after {
    content: 'E';
    position: absolute;
    top: 0;
    right: 0;
    width: 18px;
    height: 18px;
    background: rgba(22, 163, 74, 0.85);
    color: #dcfce7;
    font-size: 0.6rem;
    font-weight: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0 7px 0 5px;
    letter-spacing: 0.02em;
    pointer-events: none;
}

/* ── Quantity +/- buttons ──────────────────────────────────────────────────── */
#inventory-popout-content .quantity-controls-vertical {
    align-items: center;
    gap: 0.25rem;
}

#inventory-popout-content .quantity-text {
    color: #f59e0b;
    font-size: 0.78rem;
    font-weight: 700;
}

#inventory-popout-content .uses-max {
    color: #7a5e38;
    font-weight: 400;
    font-size: 0.72rem;
}

#inventory-popout-content .quantity-stepper {
    display: flex;
    gap: 3px;
}

#inventory-popout-content .quantity-btn {
    width: 22px;
    height: 22px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 5px;
    background: rgba(70, 52, 28, 0.7) !important;
    border: 1px solid rgba(120, 90, 50, 0.5) !important;
    color: #c4a882 !important;
    font-size: 0.85rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
    box-shadow: none !important;
}

#inventory-popout-content .quantity-btn:hover {
    background: rgba(110, 80, 38, 0.85) !important;
    border-color: rgba(196,168,130,0.7) !important;
    color: #e8d5b7 !important;
}

/* Players can't increment quantity — items come from the GM */
#inventory-popout-content .quantity-btn[data-action="increment"] {
    display: none !important;
}

/* ── Remove (X) button ─────────────────────────────────────────────────────── */
#inventory-popout-content .remove-item-btn {
    width: 22px !important;
    height: 22px !important;
    min-width: unset !important;
    padding: 0 !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    border-radius: 5px !important;
    background: rgba(80, 18, 18, 0.65) !important;
    border: 1px solid rgba(153, 40, 40, 0.45) !important;
    color: #fca5a5 !important;
    font-size: 0.7rem !important;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
    box-shadow: none !important;
    line-height: 1;
}

#inventory-popout-content .remove-item-btn:hover {
    background: rgba(153, 27, 27, 0.8) !important;
    border-color: rgba(220, 60, 60, 0.7) !important;
    color: #fecaca !important;
}

/* ── Uses controls (waterskin / maxUses items) ─────────────────────────────── */
#inventory-popout-content .uses-controls {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

#inventory-popout-content .item-uses-btn {
    padding: 0.18rem 0.55rem;
    border-radius: 5px;
    background: rgba(30, 58, 90, 0.75);
    border: 1px solid rgba(99, 179, 237, 0.45);
    color: #93c5fd;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
    line-height: 1;
    box-shadow: none !important;
}

#inventory-popout-content .item-uses-btn:hover {
    background: rgba(37, 99, 154, 0.88);
    border-color: rgba(99, 179, 237, 0.75);
    color: #bfdbfe;
}

#inventory-popout-content .item-uses-btn--refill {
    background: rgba(22, 60, 38, 0.75);
    border-color: rgba(74, 222, 128, 0.42);
    color: #86efac;
}

#inventory-popout-content .item-uses-btn--refill:hover {
    background: rgba(22, 101, 52, 0.85);
    border-color: rgba(74, 222, 128, 0.72);
    color: #a7f3d0;
}

/* ── GM Unlock button ──────────────────────────────────────────────────────── */
#inventory-popout-content .gm-unlock-btn {
    padding: 0.22rem 0.6rem;
    border-radius: 5px;
    background: linear-gradient(135deg, rgba(120,60,0,0.82) 0%, rgba(160,95,10,0.72) 100%);
    border: 1px solid rgba(234,179,8,0.42);
    color: #fef08a;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
    white-space: nowrap;
    box-shadow: 0 1px 3px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,220,80,0.08);
    line-height: 1;
}

#inventory-popout-content .gm-unlock-btn:hover {
    background: linear-gradient(135deg, rgba(161,80,0,0.92) 0%, rgba(202,120,10,0.88) 100%);
    border-color: rgba(234,179,8,0.68);
    color: #fff9a0;
}

/* ── Hide per-item Give button (replaced by titlebar Give) ─────────────────── */
#inventory-popout-content .give-item-btn {
    display: none !important;
}

/* ── Expanded item details — dark themed ───────────────────────────────────── */
#inventory-popout-content .item-details {
    display: none;
    background: rgba(6, 5, 3, 0.75);
    border: 1px solid rgba(90, 65, 35, 0.6);
    border-radius: 7px;
    padding: 0.75rem;
    margin-top: 0.5rem;
}

#inventory-popout-content .inventory-item.is-expanded .item-details {
    display: block;
}

#inventory-popout-content .inventory-item.is-expanded {
    border-color: rgba(196, 168, 130, 0.5);
}

#inventory-popout-content .inventory-item .item-details p {
    color: #b09a7a;
    font-style: italic;
    margin-bottom: 0.6rem;
    font-size: 0.78rem;
    line-height: 1.45;
}

#inventory-popout-content .inventory-item .item-details h6 {
    color: #c4a882;
    font-weight: 700;
    margin-bottom: 0.2rem;
    font-size: 0.72rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

#inventory-popout-content .inventory-item .item-details ul {
    color: #a08870;
    list-style-type: disc;
    padding-left: 1.25rem;
    font-size: 0.78rem;
}

#inventory-popout-content .inventory-item .item-details li {
    margin-bottom: 0.2rem;
    line-height: 1.4;
}

/* Bonus pills and other sub-elements inside expanded details */
#inventory-popout-content .inventory-item .item-details .bonus-label,
#inventory-popout-content .inventory-item .item-details .parchment-subheader {
    font-size: 0.75rem;
    color: #c4a882;
}

#inventory-popout-content .inventory-item .item-details .text-xs,
#inventory-popout-content .inventory-item .item-details small {
    font-size: 0.7rem;
}

/* Read Tome button inside details */
#inventory-popout-content .read-tome-btn {
    margin-top: 0.4rem;
    padding: 0.3rem 0.8rem;
    font-size: 0.75rem;
    background: rgba(60, 44, 20, 0.8);
    border: 1px solid rgba(196,168,130,0.4);
    color: #d4b896;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

#inventory-popout-content .read-tome-btn:hover {
    background: rgba(90, 66, 30, 0.9);
    border-color: rgba(196,168,130,0.7);
}

/* ── Alternating row tints ─────────────────────────────────────────────────── */
#inventory-popout-content .inv-cat-content .inventory-item:nth-child(odd) {
    background: rgba(18, 14, 9, 0.88) !important;
}

#inventory-popout-content .inv-cat-content .inventory-item:nth-child(even) {
    background: rgba(28, 21, 12, 0.92) !important;
}

/* ── Category accent — colored left border per item type ───────────────────── */
#inventory-popout-content .inv-cat-content[data-category="Recovery"]    .inventory-item { border-left: 3px solid rgba(74, 222, 128, 0.52) !important; }
#inventory-popout-content .inv-cat-content[data-category="Consumables"] .inventory-item { border-left: 3px solid rgba(99, 179, 237, 0.52) !important; }
#inventory-popout-content .inv-cat-content[data-category="General"]     .inventory-item { border-left: 3px solid rgba(196, 168, 130, 0.42) !important; }
#inventory-popout-content .inv-cat-content[data-category="Weapon"]      .inventory-item { border-left: 3px solid rgba(251, 146, 60, 0.52) !important; }
#inventory-popout-content .inv-cat-content[data-category="Armor"]       .inventory-item { border-left: 3px solid rgba(125, 211, 252, 0.52) !important; }
#inventory-popout-content .inv-cat-content[data-category="Accessory"]   .inventory-item { border-left: 3px solid rgba(183, 148, 244, 0.52) !important; }
#inventory-popout-content .inv-cat-content[data-category="Key Item"]    .inventory-item { border-left: 3px solid rgba(251, 211, 80, 0.6) !important; }
#inventory-popout-content .inv-cat-content[data-category="Tome"]        .inventory-item { border-left: 3px solid rgba(167, 139, 250, 0.58) !important; }

/* Keep equipped green border overriding the category accent on its right/top/bottom */
#inventory-popout-content .inv-cat-content .inventory-item.is-equipped {
    border-color: rgba(34, 197, 94, 0.55) !important;
    border-left-width: 3px !important;
}

/* ── Category accent — sidebar active state colors ─────────────────────────── */
#inventory-popout-sidebar .inv-cat-btn[data-category="Recovery"].active    { border-left-color: rgba(74,222,128,0.8);   color: #a7f3d0; }
#inventory-popout-sidebar .inv-cat-btn[data-category="Consumables"].active { border-left-color: rgba(99,179,237,0.8);   color: #bfdbfe; }
#inventory-popout-sidebar .inv-cat-btn[data-category="Weapon"].active      { border-left-color: rgba(251,146,60,0.8);   color: #fed7aa; }
#inventory-popout-sidebar .inv-cat-btn[data-category="Armor"].active       { border-left-color: rgba(125,211,252,0.8);  color: #bae6fd; }
#inventory-popout-sidebar .inv-cat-btn[data-category="Accessory"].active   { border-left-color: rgba(183,148,244,0.8);  color: #e9d5ff; }
#inventory-popout-sidebar .inv-cat-btn[data-category="Key Item"].active    { border-left-color: rgba(251,211,80,0.8);   color: #fef08a; }
#inventory-popout-sidebar .inv-cat-btn[data-category="Tome"].active        { border-left-color: rgba(167,139,250,0.8);  color: #ddd6fe; }

/* ── Slot Bonuses — 2-column grid ──────────────────────────────────────────── */
#inventory-popout-content .item-details .slot-bonuses-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.15rem 0.7rem;
    list-style: none;
    padding-left: 0;
}

#inventory-popout-content .item-details .slot-bonuses-list li {
    display: flex;
    align-items: center;
    gap: 0.28rem;
    margin-bottom: 0;
}

/* ── Inventory nav button ──────────────────────────────────────────────────── */
.inv-nav-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2px;
    border-radius: 6px;
    border: 1px solid transparent;
    background: transparent;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, opacity 0.15s;
    flex-shrink: 0;
}

.inv-nav-btn img {
    width: 42px;
    height: 42px;
    object-fit: contain;
    display: block;
    opacity: 0.82;
    transition: opacity 0.15s;
}

.inv-nav-btn:hover img,
.inv-nav-btn.is-open img {
    opacity: 1;
}

.inv-nav-btn:hover,
.inv-nav-btn.is-open {
    background: rgba(196,168,130,0.12);
    border-color: rgba(196,168,130,0.3);
}

/* ── Tablet: slightly tighter panel ────────────────────────────────────────── */
@media (max-width: 900px) {
    .inv-panel {
        width: min(740px, 97vw);
        height: min(680px, 88vh);
    }

    .inv-sidebar {
        width: 155px;
    }
}

/* ── Mobile / small tablet: bottom-sheet layout ────────────────────────────── */
@media (max-width: 640px) {
    .inv-overlay {
        align-items: flex-end;
    }

    .inv-panel {
        width: 100vw;
        max-width: 100vw;
        border-radius: 16px 16px 0 0;
        height: calc(100% - env(safe-area-inset-bottom, 0px));
        max-height: 100%;
        transform: translateY(40px);
    }

    .inv-overlay.is-open .inv-panel {
        transform: translateY(0);
    }

    .inv-body {
        flex-direction: column;
        overflow: hidden;
    }

    /* ── Sidebar becomes a horizontal scrollable pill row ── */
    .inv-sidebar-wrapper {
        display: flex;
        align-items: stretch;
        flex-shrink: 0;
        border-bottom: 1px solid #2e2016;
        background: rgba(0,0,0,0.3);
        position: relative;
    }

    .inv-sidebar {
        width: auto;
        flex: 1 1 0;
        min-width: 0;
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        border-right: none;
        border-bottom: none;
        padding: 0.4rem 0.2rem;
        gap: 4px;
        height: auto;
        background: transparent;
        scrollbar-width: none; /* hide scrollbar — arrows handle navigation */
        -webkit-overflow-scrolling: touch;
    }

    .inv-sidebar::-webkit-scrollbar {
        display: none;
    }

    /* ── Scroll arrow buttons ── */
    .inv-sidebar-arrow {
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        width: 28px;
        background: rgba(0,0,0,0.3);
        border: none;
        color: #a08060;
        font-size: 1.4rem;
        line-height: 1;
        cursor: pointer;
        transition: color 0.15s, background 0.15s;
        padding: 0;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.15s;
    }

    .inv-sidebar-arrow.visible {
        opacity: 1;
        pointer-events: auto;
    }

    .inv-sidebar-arrow:hover {
        color: #d4b896;
        background: rgba(80, 52, 24, 0.4);
    }

    .inv-sidebar-arrow--left {
        border-right: 1px solid #2e2016;
    }

    .inv-sidebar-arrow--right {
        border-left: 1px solid #2e2016;
    }

    /* ── Individual pill buttons ── */
    .inv-cat-btn {
        flex-shrink: 0;
        width: auto !important; /* override global width: 100% */
        border-left: none;
        border-bottom: 2px solid transparent;
        border-radius: 9999px;
        padding: 0.3rem 0.7rem;
        margin-right: 0;
        white-space: nowrap;
    }

    .inv-cat-btn.active {
        background: rgba(196,168,130,0.18);
        border-left: none;
        border-bottom-color: #c4a882;
        border-radius: 9999px;
    }

    .inv-cat-count {
        display: none;
    }

    .inv-give-btn span {
        display: none;
    }

    /* Tighter item rows on small screens */
    #inventory-popout-content .inventory-item {
        padding: 0.38rem 0.5rem;
    }
}
