:root {
    --primary-bg-color: #f0f8ff;
    --secondary-bg-color: #ffffff;
    --font-color: #333;
    --border-color: #dcdcdc;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --accent-color: #007bff;
    --hover-accent-color: #0056b3;
}

body {
    font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    margin: 0;
    background-color: var(--primary-bg-color);
    color: var(--font-color);
}

.container {
    flex-grow: 1;
    padding: 80px 20px 20px; /* Add top padding to avoid content being hidden by fixed header */
    transition: margin-right 0.3s ease;
}

.fixed-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background-color: var(--secondary-bg-color);
    padding: 6px 15px;
    box-shadow: 0 2px 4px var(--shadow-color);
    z-index: 999;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-sizing: border-box;
}

.header-left, .header-right {
    flex-shrink: 0;
    display: flex; /* Ensure buttons are aligned */
    align-items: center;
    gap: 10px; /* Add some space between buttons */
}
.search-container {
    flex-grow: 1;
    padding: 0 15px;
}

#searchInput {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    font-size: 1em;
    box-sizing: border-box;
    outline: none; /* 移除黄色聚焦边框 */
}

#searchInput:focus {
    border-color: var(--accent-color); /* 聚焦时改变边框颜色，替代黄色框 */
}

.header-btn {
    background: none;
    border: none;
    cursor: pointer;
    position: relative;
    padding: 5px;
    outline: none; /* 移除黄色聚焦边框 */
    display: flex; /* Vertically align SVG icon */
    align-items: center;
    justify-content: center;
    color: var(--font-color); /* Ensure SVG inherits color */
}

.cart-button {
    position: relative;
}

.cart-badge {
    position: absolute;
    top: -8px; /* 调整位置以适应新尺寸 */
    right: -8px;
    background-color: red;
    color: white;
    box-sizing: border-box;
    
    /* --- 胶囊形状逻辑 --- */
    /* 要调整大小，请将 height, min-width, line-height 设置为相同的值, */
    /* 并将 border-radius 设置为该值的一半。 */
    height: 18px;
    min-width: 18px;
    border-radius: 9px;
    padding: 0 5px; /* 垂直内边距为0，水平为5px */
    
    font-size: 12px; /* 使用像素单位以精确控制 */
    font-weight: bold;
    line-height: 18px; /* 与 height 相同，以实现垂直居中 */
    text-align: center;
}

/* Category Dropdown */
.category-dropdown {
    display: none;
    position: absolute;
    top: 55px;
    left: 0;
    background-color: var(--secondary-bg-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-shadow: 0 4px 8px var(--shadow-color);
    z-index: 1000;
    max-height: 450px; /* 增加50%：从300px改为450px */
    /* 如需调整，可修改此值：更高用更大的数字（如500px），更矮用更小的数字（如350px） */
    overflow-y: auto;
    min-width: 25px; /* 确保有一定的最小宽度 */
}
.category-dropdown.show {
    display: block;
}

.category-dropdown a {
    display: block;
    padding: 10px 20px;
    text-decoration: none;
    color: var(--font-color);
    cursor: pointer;
    outline: none; /* 移除黄色聚焦边框 */
}

.category-dropdown a:hover {
    background-color: #f0f0f0;
}

.category-dropdown a:focus {
    background-color: #e8e8e8; /* 聚焦时使用灰色背景，替代黄色框 */
}

.item-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 15px;
    /* 添加以下属性增强布局稳定性 */
    contain: layout;
    will-change: transform;
}

.item-card {
    background-color: var(--secondary-bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
    text-align: center;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    /* 添加以下属性增强布局稳定性 */
    contain: layout;
    backface-visibility: hidden;
    transform: translateZ(0);
}

.item-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 4px 8px var(--shadow-color);
}

.item-card .img-container {
    position: relative;
    width: 100%;
    padding-top: 100%; /* 1:1 Aspect Ratio */
    height: 0;
    margin-bottom: 10px;
    /* 添加以下属性增强稳定性 */
    contain: layout;
}

.item-card .img-container img:not(.recipe-overlay) {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    /* 添加过渡效果避免闪烁 */
    transition: opacity 0.3s ease;
}

.item-card .img-container .recipe-overlay {
    position: absolute;
    bottom: 5px;
    right: 5px;
    width: 30% !important;
    height: 30% !important;
    object-fit: contain;
    background-color: transparent;
    z-index: 1;
}

.item-name {
    font-size: 0.9em;
    font-weight: 500;
}

/* Cart Sidebar */

/* Cart Sidebar */
.cart-sidebar {
    width: 300px;
    position: fixed;
    top: 0;
    right: -320px; /* Initially hidden */
    height: 100%;
    background-color: var(--secondary-bg-color);
    box-shadow: -2px 0 5px var(--shadow-color);
    display: flex;
    flex-direction: column;
    padding: 20px;
    box-sizing: border-box;
    transition: right 0.3s ease;
    z-index: 1001;
}

.cart-sidebar.open {
    right: 0;
}

.cart-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
}

.cart-overlay.show {
    display: block;
}



.cart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
    margin-bottom: 15px; /* Add margin to separate from items */
}

h2 {
    margin: 0;
    color: var(--accent-color);
}

.cart-header-actions {
    display: flex;
    gap: 10px;
}

.icon-btn {
    background: none;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-color);
    transition: background-color 0.2s, color 0.2s;
}

.icon-btn:hover {
    background-color: #e6f2ff;
}

.cart-items {
    flex-grow: 1;
    overflow-y: auto;
}

.cart-item {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
}

.cart-item .img-container {
    position: relative;
    width: 50px;
    height: 50px;
    margin-right: 15px;
    flex-shrink: 0;
}

.cart-item .img-container img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 4px;
}

.cart-item .img-container .recipe-overlay {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 40%;
    height: 40%;
    object-fit: contain;
    background-color: transparent;
    z-index: 1;
}

.cart-item-info {
    flex-grow: 1;
}

.cart-item-name {
    display: block;
    font-weight: 500;
}

.cart-item-controls {
    display: flex;
    align-items: center;
    margin-top: 5px;
}

.cart-item-controls button {
    background: none;
    border: 1px solid var(--border-color);
    cursor: pointer;
    width: 25px;
    height: 25px;
    font-size: 1.2em;
    line-height: 1;
}

.cart-item-controls .remove-item-btn {
    background: none;
    border: 1px solid var(--border-color);
    cursor: pointer;
    width: 28px; /* Slightly increase size for better clickability */
    height: 28px;
    font-size: 1em; /* Reset font-size */
    line-height: 1;
    margin-left: 8px;
    color: #dc3545;
    transition: background-color 0.2s, color 0.2s;
    display: flex; /* Center SVG inside the button */
    align-items: center;
    justify-content: center;
    padding: 0; /* Remove padding to let SVG control the size */
}

.cart-item-controls .remove-item-btn:hover {
    background-color: #dc3545;
    color: white;
}

.cart-item-controls input {
    width: 40px;
    text-align: center;
    border: 1px solid var(--border-color);
    margin: 0 5px;
    padding: 4px;
}

.cart-footer {
    border-top: 1px solid var(--border-color);
    padding-top: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.primary-btn {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 4px;
    background-color: var(--accent-color);
    color: white;
    font-size: 1.1em;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s;
}

.primary-btn:hover {
    background-color: var(--hover-accent-color);
}

.iceland-pagination {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 10px;
}

.iceland-pagination button {
    background-color: var(--accent-color);
    border: none;
    color: white;
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.3s;
    font-size: 0.9em;
}

.iceland-pagination button:hover {
    background-color: #e0e0e0;
}

.iceland-pagination button.copied {
    background-color: #28a745;
    color: white;
}
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

.pagination button, .pagination span {
    background-color: transparent;
    border: 1px solid transparent; /* Add transparent border for consistent sizing */
    color: #007bff;
    padding: 8px 12px;
    margin: 0 2px;
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.3s, color 0.3s;
    font-size: 1em;
    min-width: 40px;
    text-align: center;
    box-sizing: border-box;
}

.pagination button:hover:not(:disabled) {
    background-color: #f0f0f0;
}

.pagination button.active {
    background-color: #007bff;
    color: white;
    font-weight: bold;
    border-color: #007bff;
}

.pagination button:disabled {
    color: #ccc;
    cursor: not-allowed;
    background-color: transparent;
}

.pagination .prev-btn, .pagination .next-btn {
    font-weight: bold;
    color: #999;
}

.pagination .ellipsis {
    color: #999;
    cursor: default;
    padding: 8px 0;
}

.stack-size {
    position: absolute;
    bottom: 5px;
    right: 5px;
    background-color: transparent;
    color: #6b2121;
    padding: 1px 4px;
    border-radius: 3px;
    font-family: "Arial", sans-serif;
    font-size: 10pt;
    font-weight: bold;
    z-index: 2;
    pointer-events: none;
}

@media (max-width: 768px) {
    .item-grid {
        grid-template-columns: repeat(3, calc((100% - 30px) / 3));
        /* 在移动端使用固定列数，精确计算列宽以避免第一列被挤压 */
        grid-auto-rows: min-content;
    }
    
    .container {
        padding: 80px 10px 20px;
    }
}
/* New Variant Indicator for Item Card */
.item-card .img-container .variant-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: -2px;
    left: -2px;
    width: 24px;
    height: 24px;
    background-color: rgba(255, 255, 255, 0.85);
    border: 1px solid var(--border-color);
    color: var(--font-color);
    border-radius: 50%;
    cursor: pointer;
    z-index: 3;
    font-size: 16px;
    line-height: 24px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    transition: transform 0.2s, box-shadow 0.2s;
}

.item-card .img-container .variant-indicator:hover {
    transform: scale(1.1);
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

/* Drawer Styles */
.drawer-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 1002;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.drawer-overlay.show {
    display: block;
    opacity: 1;
}

.drawer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background-color: var(--secondary-bg-color);
    box-shadow: 0 -5px 15px rgba(0,0,0,0.2);
    z-index: 1003;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    max-height: 80vh; /* Drawer will take up max 60% of the screen height */
}

.drawer.open {
    transform: translateY(0);
}

.drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.drawer-header h3 {
    margin: 0;
    font-size: 1.2em;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.8em;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    color: #888;
}

.drawer-body {
    padding: 20px;
    overflow-y: auto;
    display: grid;
    /* Use the same grid layout as the main page */
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 15px;
}

/* Ensure the drawer's grid also respects the mobile-first column rule */
@media (max-width: 768px) {
    .drawer-body {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Copy Success Modal Styles */
.copy-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 10000;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

.copy-modal.show {
    display: flex;
}

.copy-modal-content {
    background-color: var(--secondary-bg-color);
    border-radius: 12px;
    padding: 32px 24px;
    text-align: center;
    max-width: 280px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    animation: slideUp 0.3s ease;
    position: relative;
}

.copy-modal-icon {
    width: 48px;
    height: 48px;
    background-color: #28a745;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 29px;
    font-weight: bold;
    margin: 0 auto 16px;
}

.copy-modal-text {
    font-size: 1.04em;
    font-weight: bold;
    color: var(--font-color);
    margin-bottom: 12px;
}

.copy-modal-subtext {
    font-size: 0.8em;
    color: #666;
    line-height: 1.5;
    margin-bottom: 12px;
}

.copy-modal-image {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.copy-modal-close {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    font-size: 28px;
    color: #999;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}

.copy-modal-close:hover {
    color: #333;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}