/**
 * Code of Conquest - Inventory UI Stylesheet
 * Inventory modal, item grid, and combat items sheet
 */

/* ===== INVENTORY VARIABLES ===== */
:root {
    /* Rarity colors */
    --rarity-common: #9ca3af;
    --rarity-uncommon: #22c55e;
    --rarity-rare: #3b82f6;
    --rarity-epic: #a855f7;
    --rarity-legendary: #f59e0b;

    /* Item card */
    --item-bg: var(--bg-input, #1e1e24);
    --item-border: var(--border-primary, #3a3a45);
    --item-hover-bg: rgba(255, 255, 255, 0.05);

    /* Touch targets - WCAG compliant */
    --touch-target-min: 48px;
    --touch-target-primary: 56px;
    --touch-spacing: 8px;
}

/* ===== INVENTORY MODAL ===== */
.inventory-modal {
    max-width: 800px;
    width: 95%;
    max-height: 85vh;
}

.inventory-modal .modal-body {
    display: flex;
    flex-direction: row;
    gap: 1rem;
    padding: 1rem;
    overflow: hidden;
}

/* ===== TAB FILTER BAR ===== */
.inventory-tabs {
    display: flex;
    gap: 0.25rem;
    padding: 0 1rem;
    background: var(--bg-tertiary, #16161a);
    border-bottom: 1px solid var(--play-border, #3a3a45);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.inventory-tabs .tab {
    min-height: var(--touch-target-min);
    padding: 0.75rem 1rem;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary, #a0a0a8);
    font-size: var(--text-sm, 0.875rem);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.inventory-tabs .tab:hover {
    color: var(--text-primary, #e5e5e5);
    background: var(--item-hover-bg);
}

.inventory-tabs .tab.active {
    color: var(--accent-gold, #f3a61a);
    border-bottom-color: var(--accent-gold, #f3a61a);
}

/* ===== INVENTORY CONTENT LAYOUT ===== */
.inventory-body {
    flex: 1;
    display: flex;
    gap: 1rem;
    overflow: hidden;
}

.inventory-grid-container {
    flex: 1;
    overflow-y: auto;
    padding-right: 0.5rem;
}

/* ===== ITEM GRID ===== */
.inventory-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--touch-spacing);
}

/* Responsive grid columns */
@media (max-width: 900px) {
    .inventory-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 600px) {
    .inventory-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ===== INVENTORY ITEM CARD ===== */
.inventory-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.75rem 0.5rem;
    min-height: 96px;
    min-width: 80px;
    background: var(--item-bg);
    border: 2px solid var(--item-border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.inventory-item:hover,
.inventory-item:focus {
    background: var(--item-hover-bg);
    transform: translateY(-2px);
}

.inventory-item:focus {
    outline: 2px solid var(--accent-gold, #f3a61a);
    outline-offset: 2px;
}

.inventory-item.selected {
    border-color: var(--accent-gold, #f3a61a);
    box-shadow: 0 0 12px rgba(243, 166, 26, 0.3);
}

/* Rarity border colors */
.inventory-item.rarity-common { border-color: var(--rarity-common); }
.inventory-item.rarity-uncommon { border-color: var(--rarity-uncommon); }
.inventory-item.rarity-rare { border-color: var(--rarity-rare); }
.inventory-item.rarity-epic { border-color: var(--rarity-epic); }
.inventory-item.rarity-legendary {
    border-color: var(--rarity-legendary);
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.3);
}

/* Item icon */
.inventory-item img {
    width: 40px;
    height: 40px;
    object-fit: contain;
    margin-bottom: 0.5rem;
    opacity: 0.9;
}

/* Item name */
.inventory-item .item-name {
    font-size: var(--text-xs, 0.75rem);
    color: var(--text-primary, #e5e5e5);
    text-align: center;
    line-height: 1.2;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* Item quantity badge */
.inventory-item .item-quantity {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: var(--bg-tertiary, #16161a);
    border: 1px solid var(--item-border);
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-primary, #e5e5e5);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Empty state */
.inventory-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 2rem;
    color: var(--text-muted, #707078);
    font-style: italic;
}

/* ===== ITEM DETAIL PANEL ===== */
.item-detail {
    width: 280px;
    min-width: 280px;
    background: var(--bg-tertiary, #16161a);
    border: 1px solid var(--play-border, #3a3a45);
    border-radius: 8px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
}

.item-detail-empty {
    color: var(--text-muted, #707078);
    text-align: center;
    padding: 2rem 1rem;
    font-style: italic;
}

.item-detail-content {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.item-detail-header {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--play-border, #3a3a45);
}

.item-detail-icon {
    width: 48px;
    height: 48px;
    object-fit: contain;
}

.item-detail-title h3 {
    font-family: var(--font-heading);
    font-size: var(--text-lg, 1.125rem);
    margin: 0 0 0.25rem 0;
}

.item-detail-title .item-type {
    font-size: var(--text-xs, 0.75rem);
    color: var(--text-muted, #707078);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Rarity text colors */
.rarity-text-common { color: var(--rarity-common); }
.rarity-text-uncommon { color: var(--rarity-uncommon); }
.rarity-text-rare { color: var(--rarity-rare); }
.rarity-text-epic { color: var(--rarity-epic); }
.rarity-text-legendary { color: var(--rarity-legendary); }

.item-description {
    font-size: var(--text-sm, 0.875rem);
    color: var(--text-secondary, #a0a0a8);
    line-height: 1.5;
    margin-bottom: 1rem;
}

/* Item stats */
.item-stats {
    background: var(--item-bg);
    border-radius: 6px;
    padding: 0.75rem;
    margin-bottom: 1rem;
}

.item-stats div {
    display: flex;
    justify-content: space-between;
    padding: 0.25rem 0;
    font-size: var(--text-sm, 0.875rem);
}

.item-stats div:not(:last-child) {
    border-bottom: 1px solid var(--item-border);
}

/* Item action buttons */
.item-actions {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.item-actions .action-btn {
    min-height: var(--touch-target-primary);
    padding: 0.75rem 1rem;
    border: none;
    border-radius: 6px;
    font-size: var(--text-sm, 0.875rem);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.item-actions .action-btn--primary {
    background: var(--accent-gold, #f3a61a);
    color: var(--bg-primary, #0a0a0c);
}

.item-actions .action-btn--primary:hover {
    background: var(--accent-gold-hover, #e69500);
}

.item-actions .action-btn--secondary {
    background: var(--bg-input, #1e1e24);
    border: 1px solid var(--play-border, #3a3a45);
    color: var(--text-primary, #e5e5e5);
}

.item-actions .action-btn--secondary:hover {
    background: var(--item-hover-bg);
    border-color: var(--text-muted, #707078);
}

.item-actions .action-btn--danger {
    background: transparent;
    border: 1px solid #ef4444;
    color: #ef4444;
}

.item-actions .action-btn--danger:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* ===== MODAL FOOTER ===== */
.inventory-modal .modal-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.gold-display {
    font-size: var(--text-sm, 0.875rem);
    color: var(--accent-gold, #f3a61a);
    font-weight: 600;
}

.gold-display::before {
    content: "coins ";
    font-size: 1.1em;
}

/* ===== COMBAT ITEMS BOTTOM SHEET ===== */
.combat-items-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 70vh;
    background: var(--bg-secondary, #12121a);
    border: 2px solid var(--border-ornate, #f3a61a);
    border-bottom: none;
    border-radius: 16px 16px 0 0;
    z-index: 1001;
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.3s ease-out;
}

.combat-items-sheet.open {
    transform: translateY(0);
}

/* Sheet backdrop */
.sheet-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

/* Drag handle */
.sheet-handle {
    width: 40px;
    height: 4px;
    background: var(--text-muted, #707078);
    border-radius: 2px;
    margin: 8px auto;
}

/* Sheet header */
.sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--play-border, #3a3a45);
}

.sheet-header h3 {
    font-family: var(--font-heading);
    font-size: var(--text-lg, 1.125rem);
    color: var(--accent-gold, #f3a61a);
    margin: 0;
}

.sheet-close {
    width: var(--touch-target-min);
    height: var(--touch-target-min);
    background: none;
    border: none;
    color: var(--text-muted, #707078);
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sheet-close:hover {
    color: var(--text-primary, #e5e5e5);
}

/* Sheet body */
.sheet-body {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Combat items grid - larger items for combat */
.combat-items-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: var(--touch-spacing);
}

.combat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem;
    min-height: 120px;
    background: var(--item-bg);
    border: 2px solid var(--rarity-common);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.combat-item:hover,
.combat-item:focus {
    background: var(--item-hover-bg);
    border-color: var(--accent-gold, #f3a61a);
}

.combat-item:focus {
    outline: 2px solid var(--accent-gold, #f3a61a);
    outline-offset: 2px;
}

.combat-item.selected {
    border-color: var(--accent-gold, #f3a61a);
    box-shadow: 0 0 12px rgba(243, 166, 26, 0.3);
}

.combat-item img {
    width: 48px;
    height: 48px;
    margin-bottom: 0.5rem;
}

.combat-item .item-name {
    font-size: var(--text-sm, 0.875rem);
    color: var(--text-primary, #e5e5e5);
    font-weight: 500;
    text-align: center;
    margin-bottom: 0.25rem;
}

.combat-item .item-effect {
    font-size: var(--text-xs, 0.75rem);
    color: var(--text-muted, #707078);
    text-align: center;
}

/* Combat item detail section */
.combat-item-detail {
    background: var(--bg-tertiary, #16161a);
    border: 1px solid var(--play-border, #3a3a45);
    border-radius: 8px;
    padding: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.combat-item-detail .detail-info {
    flex: 1;
}

.combat-item-detail .detail-name {
    font-weight: 600;
    color: var(--text-primary, #e5e5e5);
    margin-bottom: 0.25rem;
}

.combat-item-detail .detail-effect {
    font-size: var(--text-sm, 0.875rem);
    color: var(--text-secondary, #a0a0a8);
}

.combat-item-detail .use-btn {
    min-width: 100px;
    min-height: var(--touch-target-primary);
    padding: 0.75rem 1.5rem;
    background: var(--hp-bar-fill, #ef4444);
    border: none;
    border-radius: 6px;
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.combat-item-detail .use-btn:hover {
    background: #dc2626;
}

/* No consumables message */
.no-consumables {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted, #707078);
    font-style: italic;
}

/* ===== MOBILE RESPONSIVENESS ===== */

/* Full-screen modal on mobile */
@media (max-width: 768px) {
    .inventory-modal {
        width: 100vw;
        height: 100vh;
        max-width: 100vw;
        max-height: 100vh;
        border-radius: 0;
        border: none;
    }

    .inventory-modal .modal-body {
        flex-direction: column;
        padding: 0.75rem;
    }

    /* Item detail slides in from right on mobile */
    .item-detail {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: 320px;
        min-width: unset;
        z-index: 1002;
        border-radius: 0;
        border-left: 2px solid var(--border-ornate, #f3a61a);
        transform: translateX(100%);
        transition: transform 0.3s ease;
    }

    .item-detail.visible {
        transform: translateX(0);
    }

    .item-detail-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1001;
    }

    /* Back button for mobile detail view */
    .item-detail-back {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        padding: 0.75rem;
        margin: -1rem -1rem 1rem -1rem;
        background: var(--bg-secondary, #12121a);
        border: none;
        border-bottom: 1px solid var(--play-border, #3a3a45);
        color: var(--accent-gold, #f3a61a);
        font-size: var(--text-sm, 0.875rem);
        cursor: pointer;
        width: calc(100% + 2rem);
    }

    .item-detail-back:hover {
        background: var(--item-hover-bg);
    }

    /* Action buttons fixed at bottom on mobile */
    .item-actions {
        position: sticky;
        bottom: 0;
        background: var(--bg-tertiary, #16161a);
        padding: 1rem;
        margin: auto -1rem -1rem -1rem;
        border-top: 1px solid var(--play-border, #3a3a45);
    }

    /* Larger touch targets on mobile */
    .inventory-item {
        min-height: 88px;
        padding: 0.5rem;
    }

    /* Tabs scroll horizontally on mobile */
    .inventory-tabs {
        padding: 0 0.5rem;
    }

    .inventory-tabs .tab {
        min-height: 44px;
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
    }

    /* Combat sheet takes more space on mobile */
    .combat-items-sheet {
        max-height: 80vh;
    }

    .combat-items-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .combat-item {
        min-height: 100px;
        padding: 0.75rem;
    }
}

/* Extra small screens */
@media (max-width: 400px) {
    .inventory-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .inventory-item {
        min-height: 80px;
    }

    .inventory-item img {
        width: 32px;
        height: 32px;
    }
}

/* ===== LOADING STATE ===== */
.inventory-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: var(--text-muted, #707078);
}

.inventory-loading::after {
    content: "";
    width: 24px;
    height: 24px;
    margin-left: 0.75rem;
    border: 2px solid var(--text-muted, #707078);
    border-top-color: var(--accent-gold, #f3a61a);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== ACCESSIBILITY ===== */

/* Focus visible for keyboard navigation */
.inventory-item:focus-visible,
.combat-item:focus-visible,
.inventory-tabs .tab:focus-visible,
.action-btn:focus-visible {
    outline: 2px solid var(--accent-gold, #f3a61a);
    outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .inventory-item,
    .combat-item,
    .combat-items-sheet,
    .item-detail {
        transition: none;
    }

    .inventory-loading::after {
        animation: none;
    }
}
