/* INVENTORY CSS */

/* Inventory and Character Panels */
.inventory-panel {
    position: fixed;
    right: auto;
    top: 224px; /* Align the top with the game box, nudged 2px south */
    bottom: auto;
    height: 575px; /* Lock panel size so it does not shrink with window height */
    width: 332px; /* Fixed width for the inventory panel */
    color: #fff;
    padding: 32px;
    padding-bottom: 60px; /* Added padding to make space for navigation */
    display: flex;
    flex-direction: column; /* Column layout */
    align-items: center; /* Center content horizontally */
    z-index: 1200; /* Keep inventory above game box/layers */
    overflow: hidden; /* Prevent content overflow */
    box-sizing: border-box; /* Include border in dimensions */

    /* Full Border Styling */
    border: 6px solid transparent; /* Set the border width to match the border image */
    border-image-source: url('UIAssets/box_main.png'); /* Use the box_main.png image */
    border-image-slice: 6; /* Slice the image into 6px-wide segments */
    border-image-width: 6px; /* Match the border-image width to the border size */
    border-image-repeat: stretch; /* Stretch the sides to fit the panel */
    background-color: #111b2e; /* Dark navy background inside the panel */
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); /* Add shadow for depth */
    font-family: var(--dashboard-font-family);
}

.inventory-panel.dashboard-side-mode {
    position: fixed;
    transform: none;
}

.inventory-panel.dashboard-overlay-mode {
    position: fixed;
    z-index: 1600;
    max-width: min(332px, calc(100vw - 32px));
    max-height: min(575px, calc(100vh - 32px));
}

@supports (height: 100dvh) {
    html.phone-optimised .inventory-panel.dashboard-overlay-mode,
    body.phone-optimised .inventory-panel.dashboard-overlay-mode {
        max-height: min(575px, calc(100dvh - 32px));
    }
}

.inventory-panel.character-view-active {
    padding: 32px 14px 20px;
}

.inventory-panel.is-hidden {
    display: none !important;
}

html.phone-optimised .overlay.dashboard-phone-dimmed,
body.phone-optimised .overlay.dashboard-phone-dimmed {
    background-color: rgba(0, 0, 0, 0.5);
    opacity: 0.5 !important;
    transition: opacity 220ms ease !important;
}

html.phone-optimised .overlay.dashboard-phone-dimmed.dashboard-phone-dimmed-closing,
body.phone-optimised .overlay.dashboard-phone-dimmed.dashboard-phone-dimmed-closing {
    opacity: 0 !important;
}

/* Specific Inventory List */
#inventoryList {
    list-style-type: none;
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: repeat(3, 1fr); /* 3 columns */
    grid-template-rows: repeat(4, 70px); /* Always show 4 fixed rows */
    row-gap: 30px; /* Adjust row spacing here */
    column-gap: 20px; /* Optional: Adjust column spacing if desired */
    justify-content: center; /* Center horizontally */
    image-rendering: pixelated; /* Keep that pixel-art crispness */
}

/* Individual Inventory Slot */
#inventoryList li {
    width: 70px; /* Size of each slot */
    height: 70px; /* Size of each slot */
    background-image: url('UIAssets/Inventory_Empty_Tile.png');
    background-size: cover; /* Cover the entire slot */
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: visible;
    cursor: pointer; /* Change cursor to hand */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

#inventoryList li .inventory-item-art {
    inset: 0;
    width: 100%;
    height: 100%;
    position: absolute;
    object-fit: cover;
    image-rendering: pixelated;
    z-index: 1; /* Ensure the item image is above the slot background */
}

#inventoryList li button {
    background-color: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 14px;
    position: absolute;
    bottom: 0;
    right: 0;
    z-index: 2;
    background: rgba(0, 0, 0, 0.5); /* Semi-transparent button background */
    padding: 2px 5px;
    border-radius: 3px;
    display: none; /* Hidden by default */
}

@media (hover: hover) and (pointer: fine) {
    #inventoryList li:hover button {
        display: block; /* Show button on hover */
    }
}

/* Set cursor to grab for draggable items */
#inventoryList li[draggable="true"] {
    cursor: grab;
}

/* Set cursor to grabbing during the drag operation */
#inventoryList li[draggable="true"]:active {
    cursor: grabbing;
}

#inventoryList.touch-dragging,
#inventoryList.touch-dragging li {
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

#inventoryList li.touch-drag-source {
    opacity: 0.45;
}

#inventoryList li.touch-drop-target .inventory-selection-frame {
    opacity: 1;
}

#inventoryList li.touch-drop-target {
    filter: brightness(1.25);
}

.inventory-touch-drag-ghost {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 5000;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: visible;
    background-image: url('UIAssets/Inventory_Empty_Tile.png');
    background-size: cover;
    pointer-events: none;
    image-rendering: pixelated;
    opacity: 0.92;
    filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.45));
    will-change: transform;
}

.inventory-touch-drag-ghost .inventory-item-art {
    inset: 0;
    width: 100%;
    height: 100%;
    position: absolute;
    object-fit: cover;
    image-rendering: pixelated;
    z-index: 1;
}

.inventory-touch-drag-ghost .inventory-selection-frame {
    --inventory-selection-corner-offset: -7px;
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 3;
    opacity: 1;
}

.inventory-touch-drag-ghost .inventory-selection-piece {
    position: absolute;
    width: 50%;
    height: 50%;
    overflow: hidden;
}

.inventory-touch-drag-ghost .inventory-selection-piece img {
    position: absolute;
    width: 190%;
    height: 190%;
    display: block;
    image-rendering: pixelated;
}

.inventory-touch-drag-ghost .inventory-selection-piece.top-left {
    left: var(--inventory-selection-corner-offset);
    top: var(--inventory-selection-corner-offset);
}

.inventory-touch-drag-ghost .inventory-selection-piece.top-right {
    right: var(--inventory-selection-corner-offset);
    top: var(--inventory-selection-corner-offset);
}

.inventory-touch-drag-ghost .inventory-selection-piece.bottom-left {
    left: var(--inventory-selection-corner-offset);
    bottom: var(--inventory-selection-corner-offset);
}

.inventory-touch-drag-ghost .inventory-selection-piece.bottom-right {
    right: var(--inventory-selection-corner-offset);
    bottom: var(--inventory-selection-corner-offset);
}

.inventory-touch-drag-ghost .inventory-selection-piece.top-right img {
    left: -90%;
    top: 0;
}

.inventory-touch-drag-ghost .inventory-selection-piece.bottom-left img {
    left: 0;
    top: -90%;
}

.inventory-touch-drag-ghost .inventory-selection-piece.bottom-right img {
    left: -90%;
    top: -90%;
}

/* Hide the remove button when dragging */
.inventory-panel ul li.dragging .remove-button {
    display: none !important;
}

/* Equipped Item Styling */
#inventoryList li.equipped {
    box-shadow: none;
}

#inventoryList li .inventory-selection-frame {
    --inventory-selection-corner-offset: -7px;
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 3;
    opacity: 0;
}

#inventoryList li .inventory-selection-piece {
    position: absolute;
    width: 50%;
    height: 50%;
    overflow: hidden;
}

#inventoryList li .inventory-selection-piece img {
    position: absolute;
    width: 190%;
    height: 190%;
    display: block;
    image-rendering: pixelated;
}

#inventoryList li .inventory-selection-piece.top-left {
    left: var(--inventory-selection-corner-offset);
    top: var(--inventory-selection-corner-offset);
}

#inventoryList li .inventory-selection-piece.top-right {
    right: var(--inventory-selection-corner-offset);
    top: var(--inventory-selection-corner-offset);
}

#inventoryList li .inventory-selection-piece.bottom-left {
    left: var(--inventory-selection-corner-offset);
    bottom: var(--inventory-selection-corner-offset);
}

#inventoryList li .inventory-selection-piece.bottom-right {
    right: var(--inventory-selection-corner-offset);
    bottom: var(--inventory-selection-corner-offset);
}

#inventoryList li .inventory-selection-piece.top-right img {
    left: -90%;
    top: 0;
}

#inventoryList li .inventory-selection-piece.bottom-left img {
    left: 0;
    top: -90%;
}

#inventoryList li .inventory-selection-piece.bottom-right img {
    left: -90%;
    top: -90%;
}

#inventoryList li.equipped .inventory-selection-frame {
    opacity: 1;
}

@media (hover: hover) and (pointer: fine) {
    #inventoryList li[draggable="true"]:hover .inventory-selection-frame {
        opacity: 1;
    }
}

/* Page Navigation for Both Inventory and Character */
.inventory-panel .page-navigation {
    position: absolute; /* Changed from relative to absolute */
    bottom: 15px; /* 15px from the bottom */
    left: 50%; /* Center horizontally */
    transform: translateX(-50%); /* Adjust to perfectly center */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 30; /* Ensure it is above other elements */
}

/* Page Buttons */
.inventory-panel .page-navigation .page-button {
    background-color: transparent;
    border: none;
    color: rgb(129, 119, 119);
    font-size: 24px;
    cursor: pointer;
    z-index: 30; /* Ensure buttons are above other elements */
    padding: 0 10px; /* Add padding to increase clickable area */
}

.inventory-panel .page-navigation span#pageNumber,
.inventory-panel .page-navigation span#characterPageNumber {
    margin: 0 10px;
    font-size: 16px;
    z-index: 30; /* Ensure page number is above other elements */
}

/* Tooltip Styles */
.tooltip {
    position: absolute;
    background-color: rgba(255, 255, 255, 0.85); /* White background with some transparency */
    color: black; /* Black text color */
    padding: 5px 10px;
    font-size: 14px;
    pointer-events: none; /* Tooltip won't interfere with mouse actions */
    display: none; /* Hidden by default */
    z-index: 2000; /* Ensure tooltip is on top of other elements */
    border: 2px solid black; /* Black border */
    line-height: 1.25; /* Adjusted line spacing */
    border-radius: 4px; /* Optional: Rounded corners for better aesthetics */
    max-width: 200px; /* Optional: Prevent tooltip from becoming too wide */
    word-wrap: break-word; /* Optional: Handle long words or URLs */
}

html.phone-optimised .tooltip,
body.phone-optimised .tooltip {
    display: none !important;
}

.inventory-panel .item-quantity {
    position: absolute;
    bottom: 5px;
    right: 5px;
    background-color: rgba(0, 0, 0, 0.75);
    color: #fff;
    padding: 2px 5px;
    border-radius: 3px;
    font-size: 14px;
    z-index: 4;
}

/* Equipment Boxes (Used in Inventory and Character Sections) */
.inventory-panel .equipment-box {
    width: 70px; /* Size of each slot */
    height: 70px; /* Size of each slot */
    background-image: url('UIAssets/Inventory_Empty_Tile.png');
    background-size: cover; /* Cover the entire slot */
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    cursor: pointer; /* Change cursor to hand */
    margin-right: 20px;
    color: #fff; /* Ensure text is visible */
    font-size: 12px; /* Font size for the slot text */
    text-align: center; /* Center the text */
}

.inventory-panel .equipment-box img {
    width: 100%; /* Make the image fit the width of the slot */
    height: 100%; /* Make the image fit the height of the slot */
    object-fit: cover; /* Ensure the image covers the slot without distortion */
}

/* Equipment Labels */
.inventory-panel .equipment-label {
    font-size: 16px;
    color: #fff;
    margin-left: 10px; /* Add more space between the tile and the text */
}

/* Equipment Container */
.inventory-panel .equipment-container {
    display: flex;
    align-items: center;
    margin-bottom: 20px; /* Increased space between equipment containers */
    justify-content: flex-start; /* Align containers to the left */
    width: 100%; /* Ensure containers take full width for proper alignment */
}

/* Character Pages */
.inventory-panel .character-page {
    width: 100%;
    display: none; /* Hide all pages by default */
    flex-direction: column;
    align-items: flex-start; /* Align items to the start for left alignment */
}

.inventory-panel .character-page.active {
    display: flex; /* Show the active page */
}

/* Ensure equipment containers inside character pages align correctly */
.inventory-panel .character-page .equipment-container {
    width: 100%; /* Ensure full width for proper alignment */
}


.action-menu {
    position: absolute;
    width: 70px; /* Width of the menu */
    height: auto; /* Adjust the height automatically based on the content */
    background-color: #111B2E; /* Match the upgrade button background */
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 2100;
    overflow: visible; /* Allow elements to extend beyond the box */
    padding: 1px 0; /* Add some vertical padding */
    gap: 5px; /* Add spacing between buttons */
    opacity: 0; /* Initial hidden state */
    transform: translateY(10px); /* Slide down initially */
    transition: opacity 0.3s ease, transform 0.3s ease; /* Smooth fade and slide */
}

.action-menu.appear {
    opacity: 1; /* Fully visible */
    transform: translateY(0); /* Reset slide */
}

.action-menu .menu-button {
    width: 100%; /* Match the width of the action menu */
    height: 24px; /* Adjust to be slightly smaller than the original upgrade button */
    margin: 2px 0; /* Add a bit of space between buttons */
    background-color: #101625; /* Same as the action menu background */
    color: #939292; /* Light gray text color */
    font-size: 10px; /* Match the font size of upgrade buttons */
    font-family: var(--dashboard-font-family);
    letter-spacing: 2px; /* Consistent letter spacing */
    padding: 2px 5px;
    border: 2px solid #2c3852; /* Matching border color */
    border-radius: 2.5px; /* Same corner rounding */
    cursor: pointer;
    transition: background-color 1s ease, border-color 1s ease, color 1s ease; /* Smooth transitions */
}

@media (hover: hover) and (pointer: fine) {
    .action-menu .menu-button:hover {
        background-color: #2c3852; /* Brighter background on hover */
        border-color: #5a7492; /* Lighter border on hover */
        color: #ffffff; /* Change text to white */
    }
}

/* Durability bar for equipped or inventory items */
.durability-bar-container {
  position: absolute;
  bottom: -4px;
  left: 50%;
  transform: translateX(-50%);
  width: 52px;
  height: 2px;
  background-color: rgba(255, 255, 255, 0.15);
  overflow: hidden;
  z-index: 5;
}

.durability-bar {
  height: 100%;
  background-color: #ffffff; /* green when full */
  transition: width 0.2s ease;
}

#inventoryDetailPopup {
    position: absolute;
    left: 0;
    right: 0;
    top: 106px;
    bottom: 34px;
    z-index: 1300;
    box-sizing: border-box;
    overflow: hidden;
}

.inventory-detail-popup-content {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    color: #f5f8ff;
    font-family: var(--dashboard-font-family);
    background: #111b2e;
}

.inventory-detail-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: auto;
    height: auto;
    padding: 0;
    border: none;
    background: transparent;
    color: #f1f6ff;
    font-family: "Arial Black", "Arial", sans-serif;
    font-size: 24px;
    font-weight: 700;
    line-height: 1;
    transform: scaleY(0.9);
    cursor: pointer;
}

.inventory-detail-close:focus-visible {
    color: #ffffff;
    outline: none;
}

@media (hover: hover) and (pointer: fine) {
    .inventory-detail-close:hover {
        color: #ffffff;
        outline: none;
    }
}

.inventory-detail-header {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding: 18px 46px 16px 18px;
    background: rgba(12, 20, 36, 0.98);
}

.inventory-detail-header h3 {
    margin: 0;
    color: #ffffff;
    font-size: 20px;
    font-weight: 700;
    line-height: 1.08;
    letter-spacing: 0.02em;
}

.inventory-detail-tier {
    margin: 0;
    color: #dbe6f7;
    font-size: 12px;
    font-weight: 400;
    line-height: 1.2;
    letter-spacing: 0.04em;
}

.inventory-detail-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 22px;
    padding: 18px 18px 20px;
    min-height: 0;
    overflow-y: auto;
}

.inventory-detail-image-frame {
    width: 98px;
    height: 98px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(17, 27, 46, 0.92);
}

.inventory-detail-image {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    image-rendering: pixelated;
}

.inventory-detail-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
}

.inventory-detail-stat-row {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 0;
    padding: 10px 12px;
    background: rgba(17, 26, 43, 0.92);
    border: 1px solid rgba(63, 82, 114, 0.72);
    border-radius: 4px;
    box-sizing: border-box;
    text-align: center;
}

.inventory-detail-stat-label {
    color: #8ea3c8;
    font-size: 11px;
    font-weight: 400;
    line-height: 1.1;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.inventory-detail-stat-value {
    color: #f5f8ff;
    font-size: 14px;
    font-weight: 400;
    line-height: 1.35;
}

.inventory-detail-stat-row--empty {
    grid-column: 1 / -1;
    color: #d8e2f4;
    font-size: 12px;
    font-style: italic;
    padding: 0;
    background: transparent;
    border: none;
}

.inventory-detail-description {
    margin: 0;
    color: #d8e2f4;
    font-size: 11px;
    font-style: italic;
    font-weight: 400;
    line-height: 1.4;
    text-align: center;
    max-width: 100%;
    padding-top: 4px;
    padding-bottom: 8px;
}

@media (max-width: 820px) {
    #inventoryDetailPopup {
        top: 116px;
        bottom: 28px;
    }

    .inventory-detail-header {
        padding: 16px 42px 14px 14px;
    }

    .inventory-detail-body {
        gap: 20px;
        padding: 16px 14px 16px;
    }

    .inventory-detail-image-frame {
        width: 84px;
        height: 84px;
    }

    .inventory-detail-header h3 {
        font-size: 18px;
    }

    .inventory-detail-stats {
        gap: 8px 10px;
    }

    .inventory-detail-stat-label,
    .inventory-detail-stat-value,
    .inventory-detail-description,
    .inventory-detail-tier {
        font-size: 11px;
    }
}
