/* ── Reset ── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: clamp(14px, 1.5vw, 16px);
    background: #f8f7f4;
    color: #1a1a1a;
    padding-bottom: clamp(80px, 10vh, 120px);
}

/* ── Header ── */
header {
    background: white;
    border-bottom: 1px solid #e5e7eb;
    padding: clamp(12px, 2vw, 20px) clamp(16px, 3vw, 32px);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 8px rgba(0,0,0,0.06);
}

#header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: clamp(8px, 1.5vw, 16px);
    margin-bottom: clamp(10px, 1.5vh, 16px);
}

header h1 {
    font-size: clamp(1.1rem, 2.5vw, 1.6rem);
    font-weight: 600;
    color: #1a1a1a;
    letter-spacing: -0.02em;
}

/* ── Nav ── */
#group-nav {
    display: flex;
    align-items: center;
    gap: clamp(4px, 0.8vw, 8px);
    flex-wrap: wrap;
}

#group-nav button {
    background: transparent;
    border: 1px solid #e5e7eb;
    border-radius: 999px;
    padding: clamp(4px, 0.8vh, 8px) clamp(10px, 1.5vw, 18px);
    font-size: clamp(0.75rem, 1.1vw, 0.9rem);
    cursor: pointer;
    color: #6b7280;
    transition: all 0.15s;
    white-space: nowrap;
}

#group-nav button:hover {
    border-color: #9ca3af;
    color: #1a1a1a;
}

#group-nav button.active {
    background: #1a1a1a;
    border-color: #1a1a1a;
    color: white;
    font-weight: 500;
}

/* ── Filter bar ── */
#filter-bar {
    display: flex;
    gap: clamp(6px, 1vw, 12px);
    flex-wrap: wrap;
    align-items: center;
}

#filter-bar input,
#filter-bar select {
    padding: clamp(8px, 1.2vh, 12px) clamp(10px, 1.5vw, 16px);
    border: 1px solid #e5e7eb;
    border-radius: clamp(6px, 0.8vw, 10px);
    font-size: clamp(0.8rem, 1.1vw, 0.95rem);
    background: #f8f7f4;
    color: #1a1a1a;
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
    font-family: inherit;
}

#filter-bar input {
    flex: 2;
    min-width: clamp(160px, 30vw, 280px);
}

#filter-bar select {
    flex: 1;
    min-width: clamp(120px, 18vw, 180px);
    cursor: pointer;
}

#filter-bar input:focus,
#filter-bar select:focus {
    border-color: #1a1a1a;
    box-shadow: 0 0 0 3px rgba(0,0,0,0.06);
    background: white;
}
/* –– Status Filter –– */
#availability-filter {
    display: flex;
    gap: 4px;
    padding: 4px;
    border-radius: 8px;
}

.status-btn {
    background-color: #6b7280;
    border: 2px solid transparent;
    font-size: clamp(0.6rem, 0.85vw, 0.7rem);
    padding: clamp(2px, 0.3vh, 3px) clamp(6px, 0.8vw, 10px);
    border-radius: 999px;
    cursor: pointer;
    font-family: inherit;
    font-weight: 500;
    transition: all 0.15s;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    color: white;

}

.status-btn::after { 
    content: '';
    position: absolute;
    inset: 0;
    background: white;
    opacity: 0;
    transition: opacity 0.15s;
    pointer-events: none;
}

.status-btn:hover::after { opacity: 0.3; }
.status-btn.active::after { opacity: 0.35; }

#avail-all {
    background: #1a1a1a;
    color: #ece9e0;
    border-color: #1a1a1a;
}

/* Available button */
#available-filter {
    background: #22c55e;
    color: #f8f7f4;
    border-color: #22c55e;
}

/* In Use button */
#unavailable-filter {
    background: #f97316;
    color: #f8f7f4;
    border-color: #f97316;
}

/* ── Main ── */
main {
    padding: clamp(16px, 3vw, 32px);
}

/* ── Loading message ── */
#loading-msg {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: clamp(40px, 8vh, 80px) 0;
    color: #9ca3af;
    gap: 16px;
}

#loading-msg p {
    font-size: clamp(0.85rem, 1.2vw, 1rem);
}

/* ── Cards ── */
#inventory-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(clamp(160px, 22vw, 260px), 1fr));
    gap: clamp(10px, 1.8vw, 20px);
}

.card {
    position: relative;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: clamp(8px, 1.2vw, 14px);
    padding: clamp(10px, 1.5vw, 16px);
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.08);
}

.card.selected {
    outline: 2px solid #3b82f6;
    background: #eff6ff;
}

.card img {
    width: 100%;
    /* aspect-ratio: 1; */
    object-fit: cover;
    border-radius: clamp(4px, 0.6vw, 8px);
    margin-top: clamp(6px, 1vh, 10px);
}

.card h2 {
    font-size: clamp(0.85rem, 1.3vw, 1rem);
    font-weight: 600;
    margin: clamp(2px, 0.4vh, 6px) 0;
    line-height: 1.3;
}

.card p {
    font-size: clamp(0.75rem, 1vw, 0.85rem);
    color: #6b7280;
    margin-bottom: 2px;
    line-height: 1.4;
}

.tags {
    font-size: clamp(0.7rem, 0.9vw, 0.78rem) !important;
    color: #9ca3af !important;
}

/* ── Select button ── */
.card-select-btn {
    position: absolute;
    top: clamp(6px, 1vw, 10px);
    right: clamp(6px, 1vw, 10px);
    width: clamp(21px, 3vw, 23px);
    height: clamp(21px, 3vw, 23px);
    border-radius: 50%;
    border: 1.5px solid #d1d5db;
    background: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(0.65rem, 1vw, 0.8rem);
    z-index: 10;
    transition: all 0.15s;
    color: #6b7280;
}

.card-select-btn:hover {
    border-color: #3b82f6;
    color: #3b82f6;
}

.card-select-btn.selected {
    background: #3b82f6;
    border-color: #3b82f6;
    color: white;
}

/* ── Status badge ── */
.status-badge {
    display: inline-block;
    color: white;
    font-size: clamp(0.6rem, 0.85vw, 0.7rem);
    font-weight: 500;
    padding: clamp(2px, 0.3vh, 3px) clamp(6px, 0.8vw, 10px);
    border-radius: 999px;
    margin-bottom: clamp(6px, 0.8vh, 10px);
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

/* ── Item modal ── */
.modal {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.4);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: clamp(12px, 2vw, 24px);
    overflow-y: auto;
    backdrop-filter: blur(2px);
}

.modal-content {
    background: white;
    border-radius: clamp(10px, 1.5vw, 18px);
    padding: clamp(20px, 3vw, 36px);
    max-width: clamp(300px, 88vw, 580px);
    width: 100%;
    max-height: 88vh;
    overflow-y: auto;
    position: relative;
    margin: auto;
}

#close {
    position: absolute;
    top: clamp(10px, 1.5vw, 18px);
    right: clamp(14px, 2vw, 22px);
    font-size: clamp(1.3rem, 2.5vw, 1.8rem);
    cursor: pointer;
    color: #9ca3af;
    line-height: 1;
    transition: color 0.15s;
}

#close:hover { color: #1a1a1a; }

#modal-details h2 {
    font-size: clamp(1.1rem, 2vw, 1.4rem);
    font-weight: 600;
    margin-bottom: clamp(4px, 0.6vh, 8px);
}

#modal-details img {
    width: 100%;
    border-radius: clamp(6px, 1vw, 10px);
    margin: clamp(10px, 1.5vh, 18px) 0;
}

#modal-details p {
    font-size: clamp(0.82rem, 1.2vw, 0.95rem);
    margin-bottom: clamp(4px, 0.6vh, 8px);
    line-height: 1.6;
    color: #374151;
}

#modal-details hr {
    margin: clamp(10px, 1.8vh, 18px) 0;
    border: none;
    border-top: 1px solid #f3f4f6;
}

#modal-details button {
    padding: clamp(8px, 1.2vh, 12px) clamp(14px, 2vw, 22px);
    border: none;
    border-radius: clamp(6px, 0.8vw, 10px);
    cursor: pointer;
    font-size: clamp(0.82rem, 1.1vw, 0.95rem);
    font-family: inherit;
    font-weight: 500;
    transition: opacity 0.15s;
    margin-top: clamp(4px, 0.8vh, 8px);
}

#modal-details button:hover { opacity: 0.85; }

#checkout-btn { background: #1a1a1a; color: white; }
#borrow-btn { background: #f3f4f6; color: #1a1a1a; }
#return-btn, #return-borrow-btn { background: #fef2f2; color: #dc2626; }

/* ── Input modal ── */
#input-modal {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.4);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    padding: clamp(12px, 2vw, 24px);
    backdrop-filter: blur(2px);
}

#input-modal-box {
    background: white;
    border-radius: clamp(10px, 1.5vw, 16px);
    padding: clamp(20px, 3vw, 28px);
    width: 100%;
    max-width: clamp(300px, 88vw, 420px);
}

#input-modal-box h3 {
    font-size: clamp(1rem, 1.5vw, 1.15rem);
    font-weight: 600;
    margin-bottom: clamp(12px, 2vh, 20px);
    color: #1a1a1a;
}

#input-modal-box input {
    width: 100%;
    padding: clamp(10px, 1.4vh, 14px) clamp(10px, 1.5vw, 14px);
    margin-bottom: clamp(8px, 1.2vh, 12px);
    border: 1px solid #e5e7eb;
    border-radius: clamp(6px, 0.8vw, 10px);
    font-size: clamp(0.85rem, 1.2vw, 1rem);
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
    background: #f8f7f4;
}

#input-modal-box input:focus {
    border-color: #1a1a1a;
    box-shadow: 0 0 0 3px rgba(0,0,0,0.06);
    background: white;
}

#input-modal-confirm {
    background: #1a1a1a;
    color: white;
    border: none;
    padding: clamp(10px, 1.4vh, 14px) clamp(14px, 2vw, 20px);
    border-radius: clamp(6px, 0.8vw, 10px);
    cursor: pointer;
    font-size: clamp(0.85rem, 1.2vw, 1rem);
    font-family: inherit;
    font-weight: 500;
    flex: 1;
    transition: opacity 0.15s;
}

#input-modal-confirm:hover { opacity: 0.85; }

#input-modal-cancel {
    background: #f3f4f6;
    color: #6b7280;
    border: none;
    padding: clamp(10px, 1.4vh, 14px) clamp(14px, 2vw, 20px);
    border-radius: clamp(6px, 0.8vw, 10px);
    cursor: pointer;
    font-size: clamp(0.85rem, 1.2vw, 1rem);
    font-family: inherit;
    transition: opacity 0.15s;
}

/* ── Selection bar ── */
#selection-bar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: #1a1a1a;
    color: white;
    padding: clamp(10px, 1.8vh, 18px) clamp(16px, 2.5vw, 28px);
    display: none;
    align-items: center;
    justify-content: space-between;
    z-index: 500;
    gap: clamp(8px, 1.2vw, 16px);
    flex-wrap: wrap;
}

#selection-count {
    font-size: clamp(0.82rem, 1.2vw, 0.95rem);
    font-weight: 500;
    white-space: nowrap;
    color: #d1d5db;
}

#selection-bar button {
    padding: clamp(6px, 1vh, 10px) clamp(10px, 1.5vw, 16px);
    border-radius: clamp(4px, 0.6vw, 8px);
    border: none;
    cursor: pointer;
    font-size: clamp(0.75rem, 1.1vw, 0.88rem);
    font-family: inherit;
    font-weight: 500;
    background: #374151;
    color: white;
    transition: background 0.15s;
    margin: clamp(2px, 0.3vh, 6px);
}

#selection-bar button:hover { background: #4b5563; }
#selection-bar button:last-child { background: #374151; }

/* ── Loading overlay ── */
#loading-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.35);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(2px);
}

#loading-box {
    background: white;
    border-radius: clamp(10px, 1.5vw, 16px);
    padding: clamp(28px, 4vw, 48px) clamp(36px, 5vw, 60px);
    text-align: center;
}

#loading-box p {
    font-size: clamp(0.88rem, 1.2vw, 1rem);
    color: #6b7280;
    margin-top: 4px;
}

/* ── Spinner (shared) ── */
.spinner {
    width: clamp(28px, 4vw, 40px);
    height: clamp(28px, 4vw, 40px);
    border: 3px solid #e5e7eb;
    border-top: 3px solid #1a1a1a;
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
    margin: 0 auto clamp(10px, 1.5vh, 16px);
}

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

/* ── Mobile ── */
@media (max-width: 900px) {
    #header-top {
        flex-direction: column;
        align-items: flex-start;
    }

    #group-nav {
        width: 100%;
        overflow-x: auto;
        flex-wrap: nowrap;
        padding-bottom: 4px;
    }

    #group-nav button {
        flex-shrink: 0;
    }

    #filter-bar {
        flex-direction: column;
    }

    #filter-bar input,
    #filter-bar select {
        width: 100%;
        min-width: unset;
    }

    #inventory-container {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    #selection-bar {
        flex-direction: column;
        align-items: flex-start;
    }

    #selection-bar > div {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        width: 100%;
    }

    #selection-bar button {
        flex: 1;
        min-width: 80px;
        text-align: center;
    }
}