:root {
    --primary-color: #0f172a;
    --background-color: #f8fafc;
    --card-bg: #ffffff;
    --text-color: #334155;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--background-color);
    color: var(--text-color);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

header {
    background-color: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 0.5rem 1.5rem;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--border-color);
}

.header-left {
    display: flex;
    align-items: center;
}

h1 {
    margin: 0;
    color: var(--primary-color);
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.home-link {
    text-decoration: none;
    transition: opacity 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--primary-color);
}

.home-link:hover {
    opacity: 0.8;
}

.controls {
    display: flex;
    gap: 1.25rem;
    align-items: center;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.search-wrapper {
    position: relative;
    min-width: 250px;
    display: flex;
    align-items: center;
}

.search-toggle-btn {
    position: absolute;
    left: 0.8rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none; /* Acts as just an icon on desktop */
}

.search-clear-btn {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 0.3rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.search-clear-btn:hover {
    background-color: #eee;
}

.filter-search {
    width: 100%;
    padding: 0.4rem 0.75rem 0.4rem 2rem;
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background-color: var(--card-bg);
    color: var(--text-color);
    font-family: inherit;
    box-sizing: border-box;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.filter-search:focus {
    border-color: #94a3b8;
    outline: none;
    box-shadow: 0 0 0 3px rgba(15, 23, 42, 0.1);
}

.filter-search::placeholder {
    color: #94a3b8;
}

.roaster-dropdown {
    position: relative;
    min-width: 200px;
}

.roaster-dropdown .filter-select {
    width: 100%;
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background-color: var(--card-bg);
    cursor: pointer;
    font-family: inherit;
    color: var(--text-color);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.roaster-dropdown .filter-select:hover, .roaster-dropdown .filter-select:focus {
    border-color: #94a3b8;
    outline: none;
    box-shadow: 0 0 0 3px rgba(15, 23, 42, 0.1);
}

.roaster-dropdown .arrow {
    font-size: 0.6rem;
    color: var(--text-muted);
}

.roaster-dropdown .custom-dropdown-content {
    max-height: 400px;
    overflow-y: auto;
    width: auto;
    min-width: 100%;
    top: 100%;
    left: 0;
    right: auto;
    margin-top: 0.25rem;
}

#roaster-dropdown-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: calc(100% - 1rem); /* Space for arrow */
}

/* More Menu & Header Icons */
.more-menu-container {
    position: relative;
}

.more-btn, .collection-top-link {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0.4rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, color 0.2s;
}

.more-btn:hover, .collection-top-link:hover {
    background-color: #ecf0f1;
    color: var(--text-color);
}

.collection-top-link {
    margin-left: auto;
}

.more-menu-content {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    margin-top: 0.5rem;
    background-color: var(--card-bg);
    border-radius: 12px;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
    border: 1px solid var(--border-color);
    padding: 0.4rem;
    min-width: 220px;
    z-index: 1000;
}

.more-menu-content.show {
    display: block;
    animation: fadeIn 0.2s ease-in-out;
}

.menu-divider {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 0.4rem 0;
}

.menu-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.6rem 1rem;
    background: none;
    border: none;
    font-size: 0.9rem;
    color: var(--text-color);
    cursor: pointer;
    text-decoration: none;
    font-family: inherit;
    border-radius: 6px;
    box-sizing: border-box;
    transition: background-color 0.2s;
}

.menu-item:hover {
    background-color: #f1f5f9;
}

/* Modern Switch Toggle */
.ancillary-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    cursor: pointer;
    user-select: none;
    padding: 0.6rem 1rem;
    border-radius: 6px;
    transition: background-color 0.2s;
}

.ancillary-toggle:hover {
    background-color: #f1f5f9;
}

.toggle-text {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
}

.switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #cbd5e1;
    transition: .3s;
    border-radius: 20px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

input:checked + .slider {
    background-color: var(--primary-color);
}

input:checked + .slider:before {
    transform: translateX(16px);
}

.selection-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.custom-dropdown {
    position: relative;
    display: inline-flex;
}

/* Invisible bridge to prevent hover from dropping off when moving to the menu */
.custom-dropdown::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    height: 12px; /* Increased to bridge the 0.5rem gap securely */
    background: transparent;
    z-index: 999;
}

.custom-dropdown-btn {
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: space-between;
    font-family: inherit;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.action-btn {
    background-color: var(--primary-color);
    color: white;
}

.custom-dropdown-btn.action-btn {
    background-color: var(--primary-color);
    color: white;
}

.action-split-group {
    display: inline-flex;
    align-items: stretch;
}

.action-split-group .main-action {
    border-radius: 8px 0 0 8px;
    margin: 0;
}

.action-split-group .dropdown-toggle {
    border-radius: 0 8px 8px 0;
    border-left: 1px solid rgba(255, 255, 255, 0.2);
    padding-left: 0.4rem;
    padding-right: 0.4rem;
    margin: 0;
}

.custom-dropdown-btn:hover {
    opacity: 0.9;
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.custom-dropdown-btn:disabled {
    background-color: var(--text-muted);
    color: white;
    cursor: not-allowed;
    opacity: 1;
    transform: none;
    box-shadow: none;
}

.custom-dropdown-content {
    opacity: 0;
    visibility: hidden;
    position: absolute;
    right: 0;
    top: 100%;
    margin-top: 0.5rem;
    background-color: var(--card-bg);
    border-radius: 12px;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
    border: 1px solid var(--border-color);
    z-index: 1000;
    min-width: 160px;
    overflow: hidden;
    padding: 0.4rem;
    transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
    transform: translateY(4px);
}

/* Hover for desktop with a tiny delay to prevent finnicky closing */
@media (min-width: 601px) {
    .custom-dropdown:hover .custom-dropdown-content {
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
        transition-delay: 0s;
    }
    
    .custom-dropdown .custom-dropdown-content {
        transition-delay: 0.1s; /* Stay open for 100ms after mouse leaves */
    }
}

.custom-dropdown-content.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    text-align: left;
    padding: 0.6rem 1rem;
    background: none;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    color: var(--text-color);
    cursor: pointer;
    transition: background-color 0.2s ease;
    font-family: inherit;
}

.dropdown-item svg {
    flex-shrink: 0;
    color: var(--text-muted);
}

.dropdown-item:hover svg, .dropdown-item.active svg {
    color: var(--primary-color);
}

.dropdown-item:hover, .dropdown-item.active {
    background-color: #f1f5f9;
}

.clear-btn {
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.clear-btn:hover {
    background-color: #f8fafc;
    color: var(--text-color);
    border-color: #cbd5e1;
}

main {
    padding: 1.5rem 2rem;
    max-width: 1400px;
    margin: 0 auto;
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
}

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

@media (max-width: 600px) {
    .grid-container {
        grid-template-columns: 1fr;
    }

    header {
        display: contents;
    }

    .home-link {
        display: flex;
        padding: 0.5rem 1rem 0.25rem;
        background-color: var(--background-color);
    }

    h1 {
        font-size: 1.1rem;
    }

    .controls {
        flex-direction: row;
        align-items: center;
        gap: 0.4rem;
        justify-content: space-between;
        position: sticky;
        top: 0;
        z-index: 100;
        background-color: var(--card-bg);
        padding: 0.35rem 0.75rem;
        margin: 0;
        width: 100%;
        border-bottom: 1px solid var(--border-color);
        box-shadow: 0 2px 8px rgba(0,0,0,0.05);
        box-sizing: border-box;
    }

    .filter-group {
        flex-direction: row;
        align-items: center;
        flex-grow: 1;
        width: auto;
    }

    .roaster-dropdown {
        flex: 1;
        min-width: 120px; /* Ensure it doesn't shrink to nothing */
    }

    .search-wrapper {
        flex: 0 0 auto;
        width: 36px;
        min-width: 36px; /* Override the desktop min-width */
        height: 36px;
        border-radius: 8px;
        background-color: transparent;
        border: 1px solid transparent;
        transition: all 0.2s ease;
        overflow: hidden;
    }

    .search-wrapper.expanded {
        flex: 1;
        width: auto;
        background-color: var(--card-bg);
        border-color: var(--primary-color);
    }

    .search-toggle-btn {
        pointer-events: auto; /* Clickable on mobile */
        cursor: pointer;
        width: 36px;
        height: 36px;
        z-index: 2;
        left: 0;
    }

    .search-clear-btn {
        right: 0.25rem;
    }

    .filter-select {
        width: 100%;
        padding: 0.75rem 0.5rem 0.75rem 0.75rem;
        font-size: 0.9rem;
        background-color: #f8f9fa;
    }

    .filter-search {
        padding-left: 2.5rem;
        padding-right: 2rem;
        background-color: transparent;
        border: none;
        box-shadow: none;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s;
        height: 100%;
    }

    .filter-search:focus {
        box-shadow: none;
    }

    .search-wrapper.expanded .filter-search {
        opacity: 1;
        pointer-events: auto;
    }

    .search-wrapper.expanded ~ .roaster-dropdown {
        display: none !important;
    }

    .more-menu-content {
        right: 0;
        left: auto;
        min-width: 250px;
    }

    /* Fixed floating action button at bottom for mobile */
    .selection-actions {
        position: fixed;
        bottom: 1rem;
        left: 1rem;
        width: calc(100% - 2rem);
        z-index: 1000;
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }

    .selection-actions .action-split-group {
        width: 100%;
        display: flex;
        box-shadow: 0 4px 12px rgba(0,0,0,0.3);
        border-radius: 8px;
    }

    .selection-actions .custom-dropdown {
        flex-grow: 0;
    }

    .selection-actions .action-btn {
        background-color: var(--primary-color);
        color: white;
        border: none;
        box-shadow: none; /* Remove individual shadows */
    }

    .selection-actions .action-split-group .main-action {
        flex-grow: 1;
        padding: 1rem;
        font-size: 1rem;
        border-radius: 8px 0 0 8px;
        justify-content: center;
    }

    .selection-actions .action-split-group .dropdown-toggle {
        padding: 1rem;
        border-radius: 0 8px 8px 0;
        justify-content: center;
        border-left: 1px solid rgba(255, 255, 255, 0.2);
    }

    .selection-actions .custom-dropdown-content {
        top: auto;
        bottom: 100%;
        margin-bottom: 0.5rem;
        width: 100%;
    }

    .selection-actions .clear-btn {
        width: 100%;
        padding: 1rem;
        border-radius: 8px;
        box-shadow: 0 4px 12px rgba(0,0,0,0.3);
        background-color: var(--card-bg);
        order: -1; /* Stack "Clear Selection" above "Actions" */
    }

    main {
        padding-bottom: 12.5rem; /* Prevent content from being hidden behind FABs */
    }
}

.card {
    background-color: var(--card-bg);
    border-radius: 16px;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-color);
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    overflow: hidden; /* Ensure image doesn't bleed out of radius */
    position: relative;
}

.card.archived {
    opacity: 0.7;
    filter: grayscale(0.8);
}

.archived-badge {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background-color: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(4px);
    color: white;
    padding: 0.25rem 0.6rem;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    z-index: 2;
}

.card-image {
    width: 100%;
    aspect-ratio: 4 / 3;
    background-color: #f1f5f9;
    position: relative;
    overflow: hidden;
}

.card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
}

.card:hover .card-image img {
    transform: scale(1.05);
}

.card-content {
    padding: 1rem 1.25rem 0.75rem 1.25rem;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    border-color: #cbd5e1;
}

.roaster {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 700;
    letter-spacing: 0.5px;
    margin-bottom: 0.25rem;
}

.title {
    font-size: 1.1rem;
    margin: 0 0 0.5rem 0;
    color: var(--primary-color);
    font-weight: 700;
    line-height: 1.4;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
}

.external-link {
    color: var(--text-muted);
    transition: color 0.2s;
    flex-shrink: 0;
    margin-top: 0.2rem;
}

.external-link:hover {
    color: var(--primary-color);
}

.details {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
    font-weight: 600;
}

.price {
    color: #10b981; /* Emerald 500 */
}

.quantity {
    color: var(--text-muted);
    font-weight: 500;
}

.section-title {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 0.35rem;
    margin-top: 0.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 2px;
}

.detail-list {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    margin-bottom: 0.5rem;
}

.detail-list span {
    font-size: 0.8rem;
    line-height: 1.4;
    color: var(--text-color);
}

.detail-list b {
    color: var(--primary-color);
    font-weight: 600;
}

.tasting-notes {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.25rem;
    margin-bottom: 0.25rem;
}

.note-tag {
    background-color: #f1f5f9;
    color: #475569;
    padding: 0.2rem 0.4rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 500;
    border: 1px solid #e2e8f0;
}

.metadata {
    margin-top: auto;
    border-top: 1px solid var(--border-color);
    padding-top: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: auto;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
}

.select-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-color);
    cursor: pointer;
    user-select: none;
    line-height: 1;
}

.select-label input {
    cursor: pointer;
    width: 16px;
    height: 16px;
    accent-color: var(--primary-color);
    margin: 0;
    display: block;
}

.toggle-view-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.85rem;
    padding: 0;
    margin: 0;
    cursor: pointer;
    text-align: right;
    text-decoration: underline;
    text-underline-offset: 4px;
    transition: color 0.2s ease;
    line-height: 1;
    display: flex;
    align-items: center;
}

.toggle-view-btn:hover {
    color: var(--primary-color);
}

.expanded-details {
    animation: fadeIn 0.3s ease-in-out;
}

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

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}

.toast {
    background-color: var(--card-bg);
    color: var(--text-color);
    padding: 0.8rem 1.2rem;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    border: 1px solid var(--border-color);
    font-size: 0.9rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    pointer-events: auto;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s, transform 0.3s;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toast-close:hover {
    color: var(--text-color);
}