/* ============================================
   PANNELLO INVENTARIO / EQUIPAGGIAMENTO / CRAFTING
   Overlay HTML fisso sullo schermo - NON dipende da Phaser
   ============================================ */

#inventory-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(820px, 96vw);
    max-height: min(88vh, calc(var(--goregrid-vvh, 100dvh) - 24px));
    background: linear-gradient(160deg, rgba(5,10,25,0.97) 0%, rgba(10,20,40,0.97) 100%);
    border: 1px solid rgba(0,200,255,0.35);
    border-radius: 14px;
    box-shadow: 0 0 40px rgba(0,200,255,0.18), 0 0 0 1px rgba(255,255,255,0.05);
    display: flex;
    flex-direction: column;
    z-index: 5000;
    font-family: 'Rajdhani', 'Orbitron', sans-serif;
    overflow: hidden;
    touch-action: manipulation;
    animation: invSlideIn 0.18s ease;
    box-sizing: border-box;
}

@keyframes invSlideIn {
    from { opacity: 0; transform: translate(-50%, -48%) scale(0.97); }
    to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* ---- HEADER ---- */
.inv-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px 0;
    border-bottom: 1px solid rgba(0,200,255,0.15);
    background: rgba(0,150,255,0.05);
    flex-shrink: 0;
}

.inv-tabs {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    touch-action: pan-x;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
    scroll-padding-inline: 10px;
}

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

.inv-tabs::before,
.inv-tabs::after {
    content: '';
    flex: 0 0 8px;
}

.inv-tab {
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: rgba(180,220,255,0.6);
    font-family: 'Orbitron', sans-serif;
    font-size: 12px;
    font-weight: 700;
    padding: 8px 16px;
    cursor: pointer;
    letter-spacing: 0.05em;
    transition: color 0.18s, border-color 0.18s;
    flex: 0 0 auto;
    white-space: nowrap;
    scroll-snap-align: center;
}
.inv-tab:hover { color: #fff; }
.inv-tab.active {
    color: #00e5ff;
    border-bottom-color: #00e5ff;
}

.inv-close {
    background: transparent;
    border: 1px solid rgba(255,60,60,0.4);
    color: rgba(255,120,120,0.8);
    border-radius: 6px;
    width: 30px; height: 30px;
    font-size: 16px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, color 0.15s;
    margin-bottom: 6px;
}
.inv-close:hover { background: rgba(255,60,60,0.25); color: #fff; }

/* ---- BODY ---- */
.inv-body {
    flex: 1;
    overflow-y: auto;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
    padding: 14px;
    scrollbar-width: thin;
    scrollbar-color: rgba(0,200,255,0.3) transparent;
}
.inv-body::-webkit-scrollbar { width: 5px; }
.inv-body::-webkit-scrollbar-thumb { background: rgba(0,200,255,0.3); border-radius: 4px; }

.inv-section { display: block; }
.inv-section.hidden { display: none; }

/* ---- INVENTARIO - MATERIALI ---- */
.inv-materials-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 8px;
    margin-bottom: 18px;
}

.inv-mat-card {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 10px;
    padding: 10px 6px;
    text-align: center;
    transition: border-color 0.2s, background 0.2s;
}
.inv-mat-card:hover { border-color: rgba(0,200,255,0.3); background: rgba(0,200,255,0.06); }

.inv-mat-icon { font-size: 26px; line-height: 1; margin-bottom: 4px; }
.inv-mat-name { font-size: 11px; color: rgba(180,220,255,0.7); margin-bottom: 4px; }
.inv-mat-qty  { font-size: 20px; font-weight: 700; color: #666; font-family: 'Orbitron', sans-serif; }
.inv-mat-qty.has-items { color: #00e5ff; }

/* ---- INVENTARIO - CONSUMABILI ---- */
.inv-consumables-section h4 {
    font-size: 13px; color: rgba(180,220,255,0.8);
    margin: 0 0 8px; font-family: 'Orbitron', sans-serif;
}

.inv-consumables-list { display: flex; flex-direction: column; gap: 6px; }

.inv-consumable-item {
    display: flex; align-items: center; gap: 10px;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 14px;
    color: #cde;
}
.inv-consumable-item span:first-child { flex: 1; }
.inv-con-qty { color: #00e5ff; font-weight: 700; font-size: 13px; margin-right: 8px; }
.inv-use-btn {
    background: linear-gradient(135deg, #00aa44, #007733);
    border: none; border-radius: 6px;
    color: #fff; font-size: 12px; font-weight: 700;
    padding: 4px 12px; cursor: pointer;
    transition: filter 0.15s;
}
.inv-use-btn:hover { filter: brightness(1.3); }

.inv-empty { color: rgba(150,180,220,0.45); font-size: 13px; font-style: italic; padding: 8px 0; }

/* ---- EQUIPAGGIAMENTO ---- */
.inv-equip-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 14px;
}

.inv-equip-card {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.10);
    border-radius: 10px;
    padding: 12px;
    display: flex;
    gap: 10px;
    transition: border-color 0.2s;
}
.inv-equip-card.equipped { border-color: rgba(0,200,255,0.25); }
.inv-equip-card.empty    { border-color: rgba(255,255,255,0.07); opacity: 0.6; }

.inv-equip-icon { font-size: 28px; flex-shrink: 0; }
.inv-equip-info { flex: 1; min-width: 0; }
.inv-equip-slotname { font-size: 10px; color: rgba(150,200,255,0.6); text-transform: uppercase; letter-spacing: 0.08em; }
.inv-equip-itemname { font-size: 15px; font-weight: 700; color: #c8e8ff; margin: 2px 0; }
.inv-equip-enchants { font-size: 11px; color: #d580ff; margin: 2px 0; }

.inv-dur-bar-wrap {
    width: 100%; height: 5px;
    background: rgba(255,255,255,0.1);
    border-radius: 3px; overflow: hidden;
    margin: 6px 0 2px;
}
.inv-dur-bar { height: 100%; border-radius: 3px; transition: width 0.3s; }
.inv-dur-label { font-size: 10px; }

.inv-equip-btns {
    display: flex; flex-direction: column; gap: 4px; flex-shrink: 0;
}
.inv-repair-btn, .inv-upgrade-btn {
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 6px;
    color: #c8e8ff;
    min-width: 64px;
    min-height: 30px;
    font-size: 11px; padding: 5px 10px;
    cursor: pointer; white-space: nowrap;
    transition: background 0.15s;
}
.inv-repair-btn:hover  { background: rgba(255,150,50,0.25); border-color: #ff9632; }
.inv-upgrade-btn:hover { background: rgba(0,200,255,0.2);   border-color: #00e5ff; }

/* ---- STATS PANEL ---- */
.inv-stats-panel {
    background: rgba(0,200,255,0.05);
    border: 1px solid rgba(0,200,255,0.15);
    border-radius: 10px;
    padding: 12px 16px;
    margin-bottom: 14px;
}
.inv-stats-panel h4 { margin: 0 0 10px; font-size: 13px; color: #00e5ff; font-family: 'Orbitron', sans-serif; }
.inv-stat-row { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; border-bottom: 1px solid rgba(255,255,255,0.06); font-size: 14px; color: #aac; }
.inv-stat-row:last-child { border: none; }
.inv-stat-val { font-weight: 700; color: #00e5ff; font-family: 'Orbitron', sans-serif; }

/* ---- INCANTAMENTI ---- */
.inv-enchant-section h4 { margin: 0 0 10px; font-size: 13px; color: #d580ff; font-family: 'Orbitron', sans-serif; }
.inv-enchant-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.inv-ench-btn {
    background: rgba(180,80,255,0.12);
    border: 1px solid rgba(180,80,255,0.3);
    border-radius: 8px;
    color: #e4b0ff;
    font-size: 12px; padding: 6px 12px;
    cursor: pointer;
    display: flex; flex-direction: column; align-items: center;
    transition: background 0.15s;
}
.inv-ench-btn small { color: rgba(200,160,255,0.6); font-size: 10px; margin-top: 2px; }
.inv-ench-btn:not(.disabled):hover { background: rgba(180,80,255,0.3); }
.inv-ench-btn.disabled { opacity: 0.4; cursor: not-allowed; }

/* ---- CRAFTING ---- */
.craft-cat-bar {
    display: flex; flex-wrap: wrap; gap: 6px;
    margin-bottom: 14px;
}
.craft-cat {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 8px;
    color: rgba(180,220,255,0.7);
    min-height: 30px;
    font-size: 12px; padding: 6px 12px;
    cursor: pointer; font-family: 'Orbitron', sans-serif;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.craft-cat:hover, .craft-cat.active {
    background: rgba(0,200,255,0.15);
    border-color: rgba(0,200,255,0.5);
    color: #00e5ff;
}

.craft-recipes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 10px;
}

.craft-recipe-card {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.09);
    border-radius: 10px;
    padding: 12px;
    display: flex; flex-direction: column; gap: 6px;
    transition: border-color 0.2s;
}
.craft-recipe-card.craftable { border-color: rgba(0,200,255,0.2); }
.craft-recipe-card.locked    { opacity: 0.7; }

.craft-recipe-name { font-size: 14px; font-weight: 700; color: #c8e8ff; }
.craft-recipe-stats { font-size: 11px; color: rgba(150,200,255,0.6); font-style: italic; }
.craft-recipe-mats  { display: flex; flex-wrap: wrap; gap: 4px; }
.craft-mat { font-size: 11px; padding: 2px 7px; border-radius: 4px; }
.craft-mat.ok      { background: rgba(0,200,100,0.15); color: #00ff88; border: 1px solid rgba(0,200,100,0.3); }
.craft-mat.missing { background: rgba(255,60,60,0.1);  color: #ff6666; border: 1px solid rgba(255,60,60,0.25); }

.craft-btn {
    margin-top: auto;
    background: linear-gradient(135deg, rgba(0,200,255,0.25), rgba(0,100,200,0.2));
    border: 1px solid rgba(0,200,255,0.4);
    border-radius: 7px;
    color: #00e5ff;
    font-size: 12px; font-weight: 700;
    padding: 6px 0;
    cursor: pointer;
    font-family: 'Orbitron', sans-serif;
    transition: background 0.15s, filter 0.15s;
}
.craft-btn:not(.disabled):hover { filter: brightness(1.3); }
.craft-btn.disabled {
    background: rgba(100,100,100,0.1);
    border-color: rgba(100,100,100,0.2);
    color: rgba(150,180,200,0.4);
    cursor: not-allowed;
    font-size: 11px;
}

@media (pointer: coarse) {
    .inv-tab {
        min-height: 38px;
        padding-top: 9px;
        padding-bottom: 9px;
    }

    .inv-close {
        flex: 0 0 38px;
        width: 38px;
        height: 38px;
        min-width: 38px;
    }

    .inv-use-btn,
    .inv-repair-btn,
    .inv-upgrade-btn,
    .craft-btn,
    .craft-cat {
        min-height: 38px;
    }
}

@media (max-width: 640px) {
    #inventory-panel {
        width: calc(var(--goregrid-vvw, 100vw) - 14px);
        max-height: calc(var(--goregrid-vvh, 100dvh) - 18px);
        border-radius: 12px;
    }

    .inv-header {
        gap: 8px;
        padding: 8px 10px 0;
    }

    .inv-tabs {
        flex: 1 1 auto;
        min-width: 0;
    }

    .inv-tab {
        min-height: 38px;
        padding: 7px 10px;
        font-size: 10px;
        letter-spacing: 0.04em;
    }

    .inv-close {
        flex: 0 0 38px;
        width: 38px;
        height: 38px;
        min-width: 38px;
    }

    .inv-body {
        padding: 10px;
    }

    .inv-materials-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 7px;
    }

    .inv-mat-card {
        padding: 8px 6px;
    }

    .inv-mat-icon {
        font-size: 22px;
    }

    .inv-mat-qty {
        font-size: 17px;
    }

    .inv-consumable-item {
        flex-wrap: wrap;
        align-items: flex-start;
    }

    .inv-use-btn {
        min-height: 36px;
    }

    .inv-equip-grid,
    .craft-recipes-grid {
        grid-template-columns: 1fr;
    }

    .inv-equip-card {
        padding: 10px;
        gap: 8px;
    }

    .inv-equip-btns {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .inv-repair-btn,
    .inv-upgrade-btn,
    .craft-btn,
    .craft-cat {
        min-height: 36px;
    }
}

@media (max-width: 320px) {
    .inv-tab {
        padding-left: 9px;
        padding-right: 9px;
        font-size: 9.5px;
        letter-spacing: 0.02em;
    }
}

@media (pointer: coarse) and (max-height: 420px) {
    #inventory-panel {
        width: calc(var(--goregrid-vvw, 100vw) - 10px);
        max-height: calc(var(--goregrid-vvh, 100dvh) - 10px);
        border-radius: 10px;
    }

    .inv-header {
        padding: 6px 8px 0;
    }

    .inv-body {
        padding: 8px;
    }

    .inv-tab {
        min-height: 34px;
        padding: 6px 9px;
    }

    .inv-close {
        width: 36px;
        height: 36px;
        min-width: 36px;
    }
}

