/* ========================================== */
/* Top Sheet Main Styles                      */
/* ========================================== */
.top-sheet {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    min-height: 80vh; /* Ensure consistent height */
    max-height: 85vh; 
    background-color: var(--color-bg-surface);
    z-index: 2000; /* Above main menu (1010) and map (1) */
    border-bottom-left-radius: 20px;
    border-bottom-right-radius: 20px;
    box-shadow: var(--shadow-lg);
    transform: translateY(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    display: flex;
    flex-direction: column;
    visibility: visible;
}

.top-sheet.visible {
    transform: translateY(0);
}

/* Grabber area specific for top sheet */
.top-sheet .top-sheet-grabber-wrapper {
    order: 10; 
    width: 100%;
    display: flex;
    justify-content: center;
    height: 40px; /* Fixed height for the grabber area */
    background-color: var(--color-bg-surface);
    border-bottom-left-radius: 20px;
    border-bottom-right-radius: 20px;
    cursor: pointer;
    margin-top: -1px;
    position: relative; /* Context for absolute positioning of chevron */
}

.top-sheet .sheet-grabber-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 5px;
}

.top-sheet .sheet-chevron {
    transform: rotate(0deg);
    width: 24px;
    height: 24px;
    display: block;
}

.top-sheet .modal-content {
    flex-grow: 1;
    min-height: 0;
    overflow-y: auto;
    max-height: calc(85vh - 40px);
}

/* Specific styling for Community Dashboard */
#community-top-sheet,
#community-top-sheet .modal-header,
#community-top-sheet .top-sheet-grabber-wrapper,
#community-top-sheet .modal-content {
    background-color: var(--color-bg-surface-alt) !important;
}

/* ========================================== */
/* Dashboard Styles (Community)               */
/* ========================================== */
.dashboard-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px; /* Reduced gap slightly to fit */
    margin-bottom: 24px;
}

/* Responsive adjustment for small screens */
@media (max-width: 380px) {
    .dashboard-stats-grid {
        grid-template-columns: 1fr; /* Stack on very small screens */
    }
}

.dashboard-stat-card {
    background: var(--color-bg-surface);
    border-radius: 16px;
    padding: 12px; /* Reduced padding slightly */
    display: flex;
    flex-direction: column; /* Stack icon and text for better fit in 3-col */
    align-items: center; /* Center items */
    text-align: center;
    gap: 8px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.04);
    border: 1px solid var(--color-border-light);
}

.stat-icon-bg {
    width: 40px; /* Smaller icon bg */
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-bottom: 4px;
}

.stat-icon-bg.bg-blue-100 { background-color: #e8f0fe; color: #1967d2; }
.stat-icon-bg.bg-green-100 { background-color: #e6f4ea; color: #137333; }
.stat-icon-bg.bg-purple-100 { background-color: #f3e8fd; color: #9333ea; } /* Purple style */

.stat-icon-bg img {
    width: 20px;
    height: 20px;
    /* Filters are handled inline or via class if preferred, keeping inline for now or relying on defaults */
}
/* Adjust filters for specific backgrounds if not inline */
.stat-icon-bg.bg-blue-100 img { filter: invert(36%) sepia(87%) saturate(1633%) hue-rotate(196deg) brightness(85%) contrast(87%); }
.stat-icon-bg.bg-green-100 img { filter: invert(33%) sepia(93%) saturate(1312%) hue-rotate(130deg) brightness(95%) contrast(92%); }
/* Purple filter handled inline in HTML or added here */
.stat-icon-bg.bg-purple-100 img { filter: invert(27%) sepia(51%) saturate(2878%) hue-rotate(246deg) brightness(96%) contrast(96%); }

.stat-info {
    display: flex;
    flex-direction: column;
    width: 100%;
}

.stat-value {
    font-size: 1.25rem; /* Adjusted font size */
    font-weight: 700;
    color: var(--color-text-primary);
    line-height: 1.1;
}

.stat-label {
    font-size: 0.75rem; /* Adjusted font size */
    color: var(--color-text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap; /* Prevent wrapping if possible */
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.dashboard-section .section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.dashboard-section h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--color-text-primary);
    margin: 0;
}

.leaderboard-card {
    background: var(--color-bg-surface);
    border-radius: 16px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.04);
    border: 1px solid var(--color-border-light);
    overflow: hidden;
}

.leaderboard-table-wrapper {
    overflow-x: auto;
}

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
}

.leaderboard-table th {
    background-color: var(--color-bg-surface-alt);
    color: var(--color-text-muted);
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    padding: 12px 16px;
    text-align: left;
}

.leaderboard-table th.text-center { text-align: center; }
.leaderboard-table th.text-right { text-align: right; }

.leaderboard-table td {
    padding: 12px 16px;
    font-size: 0.95rem;
    color: var(--color-text-secondary);
    border-bottom: 1px solid var(--color-border-light);
}

.leaderboard-table tr:last-child td {
    border-bottom: none;
}

.leaderboard-table .rank-cell {
    font-weight: 600;
    color: var(--color-text-muted);
    text-align: center;
}

.leaderboard-table .user-cell {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
}

.leaderboard-table .count-cell {
    text-align: right;
    font-weight: 600;
    color: var(--color-primary);
}

.leaderboard-table tr.highlight-user {
    background-color: var(--color-primary-surface);
}
.leaderboard-table tr.highlight-user td {
    color: var(--color-primary);
}

/* Rank Medals */
.rank-icon {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    font-size: 0.8rem;
    font-weight: bold;
    color: white;
}
.rank-1 { background-color: #FFD700; box-shadow: 0 2px 4px rgba(218, 165, 32, 0.4); }
.rank-2 { background-color: #C0C0C0; box-shadow: 0 2px 4px rgba(169, 169, 169, 0.4); }
.rank-3 { background-color: #CD7F32; box-shadow: 0 2px 4px rgba(160, 82, 45, 0.4); }


/* ========================================== */
/* Item Detail View Styles (Inside Sheet)     */
/* ========================================== */

/* Top Layout - Flex container for Image + Info */
.item-detail-top-layout {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    align-items: flex-start;
}

/* Image Container */
.item-detail-image-container {
    width: 160px; /* Fixed width for consistency */
    flex-shrink: 0;
    text-align: center;
}

#item-detail-image {
    width: 100%;
    height: auto;
    aspect-ratio: 1/1; /* Square aspect ratio */
    object-fit: contain; /* Contain ensures full image visible */
    border-radius: 12px;
    background-color: var(--color-bg-surface); /* White bg for transparent images */
    border: 1px solid var(--color-border);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

/* Info & Actions Column */
.item-detail-info-actions-column {
    flex-grow: 1;
    min-width: 0; /* Prevents flex item overflow */
    display: flex;
    flex-direction: column;
}

/* Item Info Section */
.item-detail-info {
    margin-bottom: 12px;
}

#item-detail-name {
    font-size: 1.25rem; /* ~20px */
    font-weight: 600;
    color: var(--color-text-primary); /* Gray-900 */
    line-height: 1.3;
    margin: 0 0 8px 0;
    word-wrap: break-word;
}

/* Badges Container */
.badges-container {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

/* Price Styling */
#item-detail-price {
    font-size: 1.5rem; /* ~24px */
    font-weight: 800;
    color: var(--color-primary);
    margin: 0 0 4px 0;
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 6px;
}

#item-detail-qty-unit-info {
    font-size: 0.875rem; /* ~14px */
    font-weight: 400;
    color: var(--color-text-muted); /* Gray-500 */
}

#item-detail-price-per-unit {
    font-size: 0.875rem;
    color: var(--color-text-secondary); /* Gray-600 */
    margin: 0;
}

#item-price-per-unit-text {
    font-weight: 500;
}

/* Add to Cart Group */
.add-to-cart-group {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: auto; /* Push to bottom if height allows */
}

.add-to-cart-group label {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    font-weight: 500;
    display: none; /* Hide label on mobile to save space, usually implicit */
}

.quantity-input {
    width: 50px;
    text-align: center;
    padding: 10px 5px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text-primary);
    -moz-appearance: textfield; /* Remove spinner buttons on Firefox */
}
.quantity-input::-webkit-outer-spin-button,
.quantity-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.add-to-cart-button {
    background-color: var(--color-success);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 10px 20px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background-color 0.2s ease, transform 0.1s ease;
    box-shadow: 0 2px 4px rgba(16, 185, 129, 0.2);
}

.add-to-cart-button:hover {
    background-color: var(--color-success-dark); /* Green-600 */
}

.add-to-cart-button:active {
    transform: scale(0.98);
}

.icon-add, .icon-cart {
    width: 20px;
    height: 20px;
    filter: brightness(0) invert(1); /* Make icons white */
}

/* Inline Rating (between price and add-to-cart) */
.inline-rating {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}
.inline-rating .popup-rating-display {
    margin-bottom: 0;
    min-height: auto;
    gap: 4px;
}
.inline-rating .stars-display {
    font-size: 1.1em;
    letter-spacing: 1px;
}
.inline-rating .rating-count {
    font-size: 0.8em;
}
.inline-rating .popup-rating-container {
    display: flex;
    align-items: center;
    margin: 0;
    padding: 0;
}
.inline-rating .star-button {
    font-size: 1.3em;
    padding: 0 1px;
}
.inline-rating .input-label {
    font-size: 0.8em;
    margin-right: 2px;
}
.inline-rating .rating-input-status {
    font-size: 0.75em;
}

/* Always-visible detail sections (replaces accordion) */
.item-detail-section {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--color-border);
}

/* Chart container — fixed height, always visible */
#item-detail-chart-section .popup-chart-container {
    height: 160px;
    margin: 0;
    padding: 0;
    border: none;
}

/* Compact action button row */
.detail-action-row {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.detail-action-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 9px 16px;
    border-radius: 10px;
    font-size: 0.82rem;
    font-weight: 600;
    border: 1.5px solid transparent;
    cursor: pointer;
    transition: filter 0.15s, transform 0.1s;
}

.detail-action-pill:active {
    transform: scale(0.97);
}

.detail-action-pill:hover {
    filter: brightness(0.95);
}

/* Directions — blue */
#item-detail-directions-button {
    background-color: #EBF5FF;
    color: #1D4ED8;
    border-color: #BFDBFE;
}

/* Recipes — warm amber */
#item-detail-recipes-button {
    background-color: #FFF7ED;
    color: #C2410C;
    border-color: #FED7AA;
}

/* Report — neutral gray */
#item-detail-fix-error-button {
    background-color: #F9FAFB;
    color: #6B7280;
    border-color: #E5E7EB;
}

.pill-icon {
    font-size: 0.9rem;
    line-height: 1;
}

.pill-icon img {
    width: 14px;
    height: 14px;
    vertical-align: -2px;
}

/* Responsive Adjustments for Mobile */
@media (max-width: 400px) {
    .item-detail-top-layout {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 16px;
    }

    .item-detail-image-container {
        width: 140px; /* Slightly larger on stack */
    }

    .item-detail-info-actions-column {
        width: 100%;
    }

    .badges-container {
        justify-content: center;
    }

    #item-detail-price {
        justify-content: center;
    }
}