/* style.css */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

:root {
    --bg-color: #fffbeb; 
    --text-color: #292524; 
    --primary: #d97706; 
    --primary-hover: #b45309; 
    --secondary: #fef3c7; 
    --accent-sale: #059669; 
    --accent-rent: #ea580c; 
    --accent-exchange: #7c3aed; 
    --accent-loan: #db2777; 
    --glass-bg: rgba(255, 255, 255, 0.85); 
    --glass-border: rgba(0, 0, 0, 0.05); 
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent; /* Rimuove il flash blu su iOS Safari */
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Navbar */
.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 5%;
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--glass-border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo {
    font-size: 1.75rem;
    font-weight: 800;
    background: linear-gradient(to right, #d97706, #ea580c, #db2777);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    cursor: pointer;
    transition: transform 0.3s ease;
}

.logo:hover {
    transform: scale(1.05);
}

/* Map Animations */
.map-pin {
    position: absolute;
    font-size: 1.5rem;
    animation: bounce 2s infinite;
    cursor: pointer;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
    transition: transform 0.2s;
}
.map-pin:hover {
    transform: scale(1.3);
    animation: none;
}
@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}


/* Bookshelf Visuals */
.shelf-container {
    position: relative;
    width: 100%;
    margin: 2rem 0;
    min-height: 150px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}
.shelf-books {
    display: flex;
    align-items: flex-end;
    gap: 5px;
    padding: 0 10px;
    z-index: 2;
    height: 120px;
}
.shelf-board {
    width: 100%;
    height: 20px;
    background: linear-gradient(to bottom, #d97706, #78350f);
    border-radius: 3px;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.3);
    z-index: 1;
}
.spine-book {
    width: 40px;
    height: 110px;
    border-radius: 3px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: inset 2px 0 5px rgba(255,255,255,0.2), inset -2px 0 5px rgba(0,0,0,0.3), 2px 0 4px rgba(0,0,0,0.4);
    transition: transform 0.2s;
    position: relative;
    overflow: hidden;
}
.spine-book:hover {
    transform: translateY(-10px);
}
.spine-title {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    color: white;
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
    transform: rotate(180deg);
}
.chara {
    position: absolute;
    bottom: 20px;
    left: -50px;
    font-size: 3rem;
    z-index: 3;
    transition: left 1s ease-in-out, opacity 0.5s;
}

.nav-links {
    list-style: none;
    display: flex;
    gap: 2rem;
}

.nav-links a {
    color: var(--text-color);
    text-decoration: none;
    font-weight: 500;
    opacity: 0.8;
    transition: all 0.3s ease;
    padding: 0.5rem 0;
    position: relative;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
}

.nav-icon {
    font-size: 1.25rem;
    display: inline-block;
}

.nav-links a::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0%;
    height: 2px;
    background: var(--primary);
    transition: width 0.3s ease;
}

.nav-links a:hover {
    opacity: 1;
    color: var(--primary);
}

.nav-links a.active::after {
    width: 100%;
}

.nav-links a.active {
    opacity: 1;
    color: var(--primary);
}

/* Main Content */
main {
    flex: 1;
    padding: 3rem 5%;
    display: flex;
    flex-direction: column;
}

/* Hero Section */
.hero {
    text-align: center;
    padding: 5rem 1rem;
    background: radial-gradient(circle at center, rgba(217, 119, 6, 0.1), transparent 60%);
    border-radius: 1rem;
    margin-bottom: 3rem;
    animation: fadeIn 1s ease-out;
}

.hero h1 {
    font-size: 4rem;
    font-weight: 800;
    margin-bottom: 1.5rem;
    background: linear-gradient(135deg, #44403c, #78716c);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1.1;
}

.hero p {
    font-size: 1.25rem;
    color: #57534e;
    max-width: 600px;
    margin: 0 auto 2.5rem;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Utilities */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    font-weight: 600;
    font-size: 1rem;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    color: white;
}

.btn:active {
    transform: scale(0.95);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
}

.btn-primary:hover {
    box-shadow: 0 10px 15px -3px rgba(217, 119, 6, 0.4), 0 4px 6px -2px rgba(217, 119, 6, 0.2);
    transform: translateY(-2px);
}

/* Filters */
.filters {
    display: flex;
    gap: 1rem;
    margin-bottom: 2.5rem;
    flex-wrap: wrap;
}

/* Books Grid */
.books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 2rem;
}

/* Book Card */
.book-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    padding: 1.5rem;
    transition: all 0.4s ease;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 380px;
    background-color: #292524;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
}

.book-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: var(--primary);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.4s ease;
    z-index: 10;
}

.book-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2), 0 10px 10px -5px rgba(0, 0, 0, 0.1);
    border-color: rgba(0,0,0,0.1);
}

.book-card:hover::before {
    transform: scaleX(1);
}

.book-card h3 {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
    color: #fff;
    font-weight: 700;
    z-index: 5;
    text-shadow: 0 2px 4px rgba(0,0,0,0.8);
}

.book-card .author {
    color: #fca5a5;
    font-size: 0.95rem;
    margin-bottom: 1.5rem;
    flex-grow: 1;
    z-index: 5;
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

.badge {
    align-self: flex-start;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    color: #fff;
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    z-index: 5;
}

.book-card .owner {
    font-size: 0.85rem;
    color: #d6d3d1;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(255,255,255,0.2);
    z-index: 5;
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

.book-card.badge-sale::before { background: var(--accent-sale); }
.book-card.badge-exchange::before { background: var(--accent-exchange); }
.book-card.badge-rent::before { background: var(--accent-rent); }
.book-card.badge-loan::before { background: var(--accent-loan); }

/* Form */
.form-container {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    padding: 2rem;
    max-width: 500px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: #44403c;
    font-size: 0.95rem;
}

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    background: #fff;
    border: 1px solid #d6d3d1;
    border-radius: 0.5rem;
    color: var(--text-color);
    font-family: inherit;
    font-size: 1rem;
    transition: all 0.3s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.2);
    background: #fff;
}

.form-control::placeholder {
    color: #a8a29e;
}

/* Chat Styles */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 60vh;
    min-height: 400px;
    background: #fff;
    border-radius: 1rem;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    overflow: hidden;
}
.chat-messages {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    background: #fdfbf7;
}
.chat-bubble {
    max-width: 75%;
    padding: 0.8rem 1.2rem;
    border-radius: 1.2rem;
    font-size: 0.95rem;
    position: relative;
    animation: fadeIn 0.2s ease-out;
}
.chat-bubble.received {
    align-self: flex-start;
    background: #f5f5f4; 
    color: #292524;
    border-bottom-left-radius: 0.2rem;
}
.chat-bubble.sent {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: #fff;
    border-bottom-right-radius: 0.2rem;
}
.chat-input {
    display: flex;
    padding: 1rem;
    background: #fff;
    border-top: 1px solid #e7e5e4;
    gap: 0.5rem;
}
.chat-input input {
    flex: 1;
    padding: 0.8rem 1.5rem;
    border: 1px solid #d6d3d1;
    border-radius: 999px;
    outline: none;
    font-family: inherit;
    font-size: 1rem;
}
.chat-input button {
    border-radius: 50%;
    width: 45px;
    height: 45px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
}
.chat-list-item {
    display: flex;
    align-items: center;
    padding: 1rem 1.5rem;
    background: #fff;
    border-radius: 1rem;
    margin-bottom: 1rem;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.03);
    transition: transform 0.2s, box-shadow 0.2s;
    border: 1px solid var(--glass-border);
}
.chat-list-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(0,0,0,0.05);
}
.chat-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-right: 1rem;
    flex-shrink: 0;
}

/* Map Container Styles */
#map-container {
    width: 100%;
    height: 400px;
    border-radius: 1rem;
    margin-bottom: 2rem;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    border: 1px solid var(--glass-border);
    z-index: 10;
}

.leaflet-popup-content-wrapper {
    border-radius: 0.5rem;
}

.leaflet-popup-content {
    margin: 10px;
    line-height: 1.4;
    text-align: center;
}

.custom-map-popup img {
    margin-bottom: 5px;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    width: 80px; 
    height: 120px;
    object-fit: cover;
}
.custom-map-popup h4 {
    margin: 5px 0;
    font-size: 1rem;
    color: var(--text-color);
    font-weight: bold;
}
.custom-map-popup button {
    margin-top: 5px;
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
    width: 100%;
}


/* Onboarding Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(41, 37, 36, 0.85); /* quasi nero semi-trasparente */
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 99999;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.4s ease, visibility 0.4s;
}

.modal-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.modal-content {
    background: var(--bg-color);
    padding: 3rem;
    border-radius: 1.5rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    max-width: 500px;
    width: 90%;
    text-align: center;
    transform: translateY(0) scale(1);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 1px solid var(--glass-border);
}

.modal-overlay.hidden .modal-content {
    transform: translateY(30px) scale(0.95);
}

/* ==============================================================
   MOBILE APP RESPONSIVENESS (SMARTPHONE PWA STYLE)
   ============================================================== */
@media screen and (max-width: 768px) {
    body {
        padding-bottom: 5rem;
        background-color: #f5f5f4; /* Stone 100 */
    }
    
    .navbar {
        justify-content: center;
        padding: 1rem;
        border-bottom: 1px solid var(--glass-border);
        box-shadow: 0 2px 10px rgba(0,0,0,0.02);
    }
    
    .logo {
        font-size: 1.5rem;
    }

    /* Fixed Bottom Navigation iOS/Android Style */
    .nav-links {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        background: #ffffff;
        border-top: 1px solid #e7e5e4;
        box-shadow: 0 -4px 20px rgba(0,0,0,0.05);
        padding: 0.5rem 1rem 1rem 1rem;
        display: flex;
        justify-content: space-around;
        gap: 0;
        z-index: 9999;
        margin: 0;
    }

    .nav-links a {
        flex-direction: column;
        gap: 0.25rem;
        padding: 0.25rem 0.5rem;
        opacity: 0.5;
        transition: all 0.2s;
    }
    
    .nav-links a::after {
        display: none; 
    }
    
    .nav-links a.active {
        color: var(--primary);
        font-weight: 700;
        opacity: 1;
        transform: scale(1.05); 
    }

    .nav-icon {
        display: block;
        font-size: 1.4rem;
        margin-bottom: 0px;
    }

    .nav-text {
        font-size: 0.70rem;
        font-weight: 600;
        letter-spacing: -0.01em;
    }

    main {
        padding: 1rem;
    }

    .hero {
        padding: 3rem 1rem;
        border-radius: 0;
        margin-left: -1rem;
        margin-right: -1rem;
        margin-top: -1rem;
    }

    .hero h1 {
        font-size: 2.2rem;
    }

    h1[style] {
        font-size: 2rem !important;
    }

    h2[style] {
        font-size: 1.5rem !important;
    }

    /* Scrollable Horizontal Filters for Smartphone */
    .filters {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 1rem;
        margin-left: -1rem;
        margin-right: -1rem;
        padding-left: 1rem;
        padding-right: 1rem;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none; 
    }
    
    .filters::-webkit-scrollbar {
        display: none; 
    }

    .filters .btn {
        flex: 0 0 auto;
        white-space: nowrap;
        font-size: 0.85rem;
        padding: 0.6rem 1rem;
    }

    .books-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .book-card {
        min-height: 220px; 
        border-radius: 1rem;
        padding: 1rem;
    }

    .book-card h3 {
        font-size: 0.9rem;
    }

    .book-card .author {
        font-size: 0.75rem;
        margin-bottom: 0.5rem;
    }

    .badge {
        font-size: 0.6rem;
        padding: 0.15rem 0.4rem;
        margin-bottom: 0.5rem;
    }

    .book-card .owner {
        font-size: 0.7rem;
        margin-top: 0.5rem;
        padding-top: 0.5rem;
    }

    .form-container {
        padding: 1.5rem 1rem;
        border-radius: 1rem;
        border: 1px solid #e7e5e4;
        background: #fff;
        box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.05);
    }
    
    .chat-container {
        height: 65vh;
        border-radius: 1rem;
    }
}

/* Photo Upload Preview Styles */
.photo-preview-container {
    display: flex;
    gap: 1.5rem;
    overflow-x: auto;
    padding: 1rem 0;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    min-height: 200px;
    align-items: flex-start;
    flex-wrap: wrap;
}
.photo-preview-container::-webkit-scrollbar {
    display: none;
}
.photo-preview-item {
    position: relative;
    flex: 0 0 180px;
    height: 240px;
    border-radius: 1rem;
    overflow: hidden;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
    border: 3px solid white;
    transition: all 0.3s ease;
}
.photo-preview-item:hover {
    transform: scale(1.02);
    box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1);
}
.photo-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.photo-preview-remove {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    background: rgba(239, 68, 68, 0.95);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: bold;
    border: none;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    z-index: 10;
}
.photo-add-button {
    flex: 0 0 180px;
    height: 240px;
    border: 2px dashed #cbd5e1;
    border-radius: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: white;
}
.photo-add-button:hover {
    border-color: var(--primary);
    background: var(--secondary);
}

/* Quick Replies */
.quick-replies-container {
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    overflow-x: auto;
    background: #fff;
    border-top: 1px solid #e7e5e4;
    white-space: nowrap;
    scrollbar-width: none;
}
.quick-replies-container::-webkit-scrollbar { display: none; }
.quick-reply-chip {
    padding: 0.5rem 1rem;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 999px;
    font-size: 0.85rem;
    color: #475569;
    cursor: pointer;
    transition: all 0.2s;
}
.quick-reply-chip:hover {
    background: var(--secondary);
    border-color: var(--primary);
    color: var(--primary);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Responsive Overrides */
@media screen and (max-width: 480px) {
    .books-grid {
        grid-template-columns: 1fr;
    }
}
