@font-face {
    font-family: 'Averta CY';
    src: url('../fonts/AvertaDemoPE-Regular.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Averta CY';
    src: url('../fonts/Averta-CY-W01-Bold.woff2') format('woff2');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

:root {
    --bg-color: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #cbd5e1;
    --card-bg: #ffffff;
    
    --color-green: #22c55e;
    --color-purple: #8b5cf6;
    --color-orange: #f97316;
    --color-red: #ef4444;
    
    --nav-height: 80px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Averta CY', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

.app-container {
    max-width: 600px;
    margin: 0 auto;
    background-color: var(--bg-color);
    min-height: 100vh;
    position: relative;
}

/* Tabs */
.tab-content {
    display: none;
    flex-direction: column;
    padding: 20px 20px 0 20px;
}
.tab-content.active {
    display: flex;
}
.tab-content.hidden {
    display: none;
}

/* Headers */
.page-header {
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

.text-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-red);
    font-weight: 600;
    font-size: 0.95rem;
}

/* Search */
.search-container {
    position: relative;
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    background: var(--card-bg);
    border-radius: var(--radius-md);
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
.search-icon {
    position: absolute;
    left: 16px;
    color: var(--text-secondary);
}
#ingredient-input {
    width: 100%;
    border: none;
    background: transparent;
    padding: 14px 16px 14px 48px;
    font-size: 1rem;
    color: var(--text-primary);
    outline: none;
}
#ingredient-input::placeholder {
    color: var(--text-secondary);
}
.btn-add-custom {
    background: var(--color-green);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    width: 36px;
    height: 36px;
    margin-right: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

/* Category Dropdown Container */
.category-pills-container {
    margin-bottom: 20px;
}

/* Category Dropdown */
.category-dropdown {
    width: 100%;
    padding: 12px 16px;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    background-color: white;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    appearance: none;
    background-image: url('data:image/svg+xml;charset=US-ASCII,<svg width="12" height="8" viewBox="0 0 12 8" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1.5L6 6.5L11 1.5" stroke="%2364748B" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>');
    background-repeat: no-repeat;
    background-position: right 16px center;
    background-size: 12px;
    cursor: pointer;
    transition: border-color 0.2s;
    outline: none;
}

.category-dropdown:focus {
    border-color: #a855f7;
    box-shadow: 0 0 0 3px rgba(168, 85, 247, 0.1);
}

/* Ingredients Grid */
.category-section {
    margin-bottom: 24px;
}

.category-title {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--text-primary);
    margin-bottom: 12px;
    padding-left: 4px;
}

.category-title.collapsible {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.chevron {
    color: var(--text-secondary);
    transition: transform 0.3s ease;
}

.category-section.collapsed .chevron {
    transform: rotate(-90deg);
}

.category-section.collapsed .ingredients-list {
    display: none;
}

.ingredients-list {
    display: flex;
    flex-direction: column;
    gap: 0;
    border-top: 1px solid #e2e8f0;
}

.ingredient-row {
    display: flex;
    align-items: center;
    background: white;
    border-bottom: 1px solid #e2e8f0;
    padding: 14px 0;
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    opacity: 0.5;
}

.ingredient-row:active {
    transform: scale(0.98);
}

.ingredient-row.selected {
    background: #fdf4ff;
    border-color: #d8b4fe;
    opacity: 1;
}

.ingredient-row .ingredient-emoji {
    font-size: 1.4rem;
    margin-right: 8px;
}
.ingredient-row .ingredient-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
    flex: 1;
}

.ingredient-row .ingredient-checkbox {
    width: 24px;
    height: 24px;
    border: 2px solid #cbd5e1;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    margin-right: 12px;
}

.ingredient-row .ingredient-checkbox svg {
    width: 14px;
    height: 14px;
    color: white;
    opacity: 0;
    transform: scale(0.5);
    transition: all 0.2s ease;
}

.ingredient-row.selected .ingredient-checkbox {
    background: #a855f7;
    border-color: #a855f7;
}

.ingredient-row.selected .ingredient-checkbox svg {
    opacity: 1;
    transform: scale(1);
}

/* Sticky Action Button */
.sticky-bottom-action {
    position: fixed;
    bottom: calc(var(--nav-height) + 16px);
    left: 0;
    right: 0;
    margin: 0 auto;
    max-width: 600px;
    padding: 0 20px;
    z-index: 10;
}
.btn-primary {
    width: 100%;
    background: var(--color-green);
    color: white;
    border: none;
    border-radius: var(--radius-lg);
    padding: 16px;
    font-size: 1.1rem;
    font-weight: 700;
    box-shadow: 0 4px 14px rgba(34, 197, 94, 0.3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, opacity 0.2s;
}
.btn-primary:active {
    transform: scale(0.98);
}
.btn-primary:disabled {
    background: var(--border-color);
    color: var(--text-secondary);
    box-shadow: none;
    cursor: not-allowed;
}

/* Recipes Grid */
.recipes-grid {
    display: flex;
    flex-direction: column;
    gap: 20px;
}
.recipe-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    position: relative;
    cursor: pointer;
}
.recipe-img-container {
    height: 180px;
    width: 100%;
    position: relative;
    background: #e2e8f0;
}
.recipe-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.recipe-badge {
    position: absolute;
    top: 12px;
    left: 12px;
    width: 24px;
    height: 24px;
    background: var(--color-green);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.85rem;
    border: 2px solid white;
}
.recipe-actions-top {
    position: absolute;
    top: 12px;
    right: 12px;
    display: flex;
    gap: 8px;
}
.action-circle {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    border: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.action-circle.active {
    color: var(--color-red);
}
.action-circle.active svg {
    fill: var(--color-red);
}
.recipe-content {
    padding: 16px;
}
.recipe-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text-primary);
}
.recipe-meta {
    font-size: 0.85rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 12px;
}
.recipe-chips {
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.recipe-chips::-webkit-scrollbar {
    display: none;
}
.chip {
    white-space: nowrap;
    flex-shrink: 0;
    background: #f1f5f9;
    color: var(--text-secondary);
    padding: 4px 10px;
    border-radius: 100px;
    font-size: 0.75rem;
    font-weight: 600;
}

/* History List */
.history-group-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 16px 0 12px;
}
.history-group-items {
    display: flex;
    flex-direction: column;
}
.history-group-items .list-item {
    margin-bottom: 0;
    border-radius: 0;
    border-bottom: 1px solid var(--border-color);
    box-shadow: none;
}
.history-group-items .list-item:first-child {
    border-top-left-radius: var(--radius-md);
    border-top-right-radius: var(--radius-md);
}
.history-group-items .list-item:last-child {
    border-bottom-left-radius: var(--radius-md);
    border-bottom-right-radius: var(--radius-md);
    border-bottom: none;
}
.history-group-items {
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    border-radius: var(--radius-md);
    background: var(--card-bg);
    margin-bottom: 16px;
}
.history-list-container, .bookmarks-list-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.list-item {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    cursor: pointer;
}
.bookmark-item {
    padding: 0;
    overflow: hidden;
    height: 120px;
    align-items: stretch;
}
.list-item-img {
    width: 60px;
    height: 60px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    background: #e2e8f0;
    flex-shrink: 0;
}
.list-item-img-wide {
    width: 100px;
    height: 75px;
    border-radius: var(--radius-md, 12px);
}
.recipe-tag {
    background: #f1f5f9;
    color: var(--text-secondary);
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 0.65rem;
    font-weight: 500;
}
.list-item-content {
    flex: 1;
    min-width: 0;
}
.list-item-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    white-space: normal;
    line-height: 1.3;
}
.list-item-subtitle {
    font-size: 0.8rem;
    color: var(--text-secondary);
}
.list-item-meta {
    text-align: right;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    align-self: stretch;
    position: relative;
    min-width: 45px;
}
.list-item-time {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: auto;
}
.list-item-action {
    position: absolute;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    color: var(--text-secondary);
    display: flex;
}

/* Bottom Nav */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: var(--card-bg);
    display: flex;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -4px 12px rgba(0,0,0,0.03);
    z-index: 100;
    max-width: 600px;
    margin: 0 auto;
    padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
    background: none;
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: var(--text-secondary);
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    flex: 1;
    height: 100%;
}
.nav-icon-wrapper {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
.nav-btn.active {
    color: var(--text-primary);
}
.nav-btn#nav-btn-ingredients.active { color: var(--color-green); }
.nav-btn#nav-btn-recipes.active { color: var(--color-purple); }
.nav-btn#nav-btn-history.active { color: var(--color-orange); }
.nav-btn#nav-btn-favorites.active { color: var(--color-red); }

.nav-btn.active .nav-icon-wrapper {
    transform: translateY(-2px);
}

.empty-state {
    text-align: center;
    color: var(--text-secondary);
    padding: 30px 20px;
    font-size: 0.95rem;
}

/* Modal */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    backdrop-filter: blur(2px);
}
.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--card-bg);
    width: 90%;
    max-width: 400px;
    border-radius: var(--radius-lg);
    padding: 24px;
    z-index: 1001;
    box-shadow: 0 10px 40px rgba(0,0,0,0.1);
}

.loader {
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
/* =========================================================
   RECIPE DETAILS OVERLAY
   ========================================================= */
.page-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #fff;
    z-index: 9999;
    overflow-y: auto;
    overflow-x: hidden;
    animation: slideUp 0.3s ease forwards;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.recipe-details-header {
    position: relative;
    height: 300px;
    width: 100%;
    background: #f1f5f9;
}

.recipe-details-image-container {
    width: 100%;
    height: 100%;
}

.recipe-details-image-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.details-back-btn {
    position: absolute;
    top: 20px;
    left: 20px;
    width: 40px;
    height: 40px;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    z-index: 10;
}

.details-fav-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    z-index: 10;
}

.recipe-details-content {
    position: relative;
    background: white;
    border-radius: 24px 24px 0 0;
    margin-top: -30px;
    padding: 24px;
    min-height: 500px;
    z-index: 5;
}

.details-title-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 12px;
}

.details-title-row h1 {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text-main);
    line-height: 1.3;
    margin: 0;
    flex: 1;
}

.details-rating {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: white;
    border: 1px solid #e2e8f0;
    padding: 8px 12px;
    border-radius: 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.rating-score {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--color-green);
    display: flex;
    align-items: center;
    gap: 4px;
}

.rating-score svg {
    height: 1.25em;
    width: 1.25em;
    fill: currentColor;
}

.rating-count {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.details-description {
    font-size: 0.95rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 24px;
}

.details-stats-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 32px;
}

.stat-card {
    flex: 1;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 8px 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.stat-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.stat-icon svg {
    width: 16px;
    height: 16px;
}

.stat-icon.purple { background: rgba(139, 92, 246, 0.1); color: #8b5cf6; }
.stat-icon.orange { background: rgba(249, 115, 22, 0.1); color: #f97316; }
.stat-icon.green { background: rgba(34, 197, 94, 0.1); color: #22c55e; }

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

.stat-val {
    font-weight: 700;
    font-size: 0.8rem;
    color: var(--text-main);
    white-space: nowrap;
}

.stat-label {
    font-size: 0.55rem;
    color: var(--text-secondary);
    line-height: 1.1;
}

.details-section {
    margin-bottom: 32px;
}

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

.section-title {
    display: flex;
    align-items: center;
    gap: 8px;
}

.section-title h3 {
    font-size: 1.2rem;
    font-weight: 700;
    margin: 0;
    color: var(--text-main);
}

.portions-btn {
    background: rgba(139, 92, 246, 0.1);
    color: #8b5cf6;
    border: none;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ingredients-ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.ingredient-li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-right: 16px;
}

.ing-name {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.7rem;
    color: var(--text-main);
}

.ing-dot {
    width: 6px;
    height: 6px;
    background: #8b5cf6;
    border-radius: 50%;
}

.ing-amount {
    font-size: 0.65rem;
    color: var(--text-secondary);
}

.steps-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.step-item {
    display: flex;
    gap: 12px;
}

.step-num {
    width: 16px;
    height: 16px;
    background: #8b5cf6;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.6rem;
    flex-shrink: 0;
    margin-top: 2px;
}

.step-text {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.4;
    padding-top: 2px;
}

.rating-section {
    background: #f8fafc;
    border-radius: 16px;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.rating-prompt {
    display: flex;
    flex-direction: column;
}

.rating-q {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-main);
}

.rating-sub {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.rating-stars {
    display: flex;
    gap: 4px;
}

.sticky-action-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 16px 24px 32px 24px;
    background: linear-gradient(to top, white 80%, rgba(255,255,255,0));
    z-index: 100;
}

.start-cooking-btn {
    width: 100%;
    padding: 16px;
    background: #8b5cf6;
    color: white;
    border: none;
    border-radius: 16px;
    font-size: 1.1rem;
    font-weight: 700;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 8px 24px rgba(139, 92, 246, 0.3);
}

/* User Rating Section */
.user-rating-section {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    margin-top: 8px;
    gap: 4px;
}

.user-rating-label {
    font-size: 0.85rem;
    color: #64748b;
    font-weight: 500;
}

.star-rating svg {
    width: 24px;
    height: 24px;
    fill: none;
    stroke: var(--color-purple);
    stroke-width: 2;
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), fill 0.2s ease, stroke 0.2s ease;
}

.star-rating svg:hover {
    transform: scale(1.2);
}

.star-rating.has-rating svg.active,
.star-rating svg.hover-active {
    fill: #ffb020;
    stroke: #ffb020;
}

@keyframes starClickAnim {
    0% {
        transform: scale(1) translateY(0) rotate(0deg);
    }
    50% {
        transform: scale(1.4) translateY(-8px) rotate(36deg);
    }
    100% {
        transform: scale(1) translateY(0) rotate(72deg);
    }
}

.star-rating svg.animate-click {
    animation: starClickAnim 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.star-rating.disabled svg {
    cursor: default;
    opacity: 0.7;
}

.star-rating.disabled svg:hover {
    transform: none;
}
