/**
 * Recipe Manager - Main Stylesheet
 */

/* =========================================
   CSS Variables
   ========================================= */
:root {
    --primary-color: #667eea;
    --primary-dark: #5a67d8;
    --secondary-color: #764ba2;
    --success-color: #48bb78;
    --danger-color: #f56565;
    --warning-color: #ed8936;
    
    --text-color: #2d3748;
    --text-muted: #718096;
    --text-light: #a0aec0;
    
    --bg-color: #f7fafc;
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    
    --font-family: 'Kanit', -apple-system, BlinkMacSystemFont, sans-serif;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.12);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.15);
    
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 1rem;
    
    --container-width: 1200px;
}

/* =========================================
   Reset & Base
   ========================================= */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font-family);
    font-size: 16px;
    line-height: 1.6;
    color: var(--text-color);
    background: var(--bg-color);
}

a {
    color: var(--primary-color);
    text-decoration: none;
}

a:hover {
    color: var(--primary-dark);
}

img {
    max-width: 100%;
    height: auto;
}

h1, h2, h3, h4 {
    margin: 0 0 1rem;
    line-height: 1.3;
}

p { margin: 0 0 1rem; }

/* =========================================
   Layout
   ========================================= */
.container {
    max-width: var(--container-width);
    margin: 0 auto;
    padding: 0 1rem;
}

.main-content {
    min-height: calc(100vh - 200px);
    padding: 2rem 0;
}

/* =========================================
   Header
   ========================================= */
.main-header {
    background: var(--card-bg);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-color);
}

.main-nav {
    display: flex;
    gap: 1.5rem;
}

.nav-link {
    color: var(--text-muted);
    font-weight: 500;
    padding: 0.5rem 0;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.nav-link:hover, .nav-link.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.search-toggle {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.5rem;
}

.user-menu {
    position: relative;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
}

.user-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--card-bg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 200px;
    padding: 0.5rem 0;
    display: none;
}

.user-menu:hover .user-dropdown {
    display: block;
}

.user-info {
    padding: 0.75rem 1rem;
}

.user-info strong { display: block; }
.user-info small { color: var(--text-muted); }

.user-dropdown hr {
    margin: 0.5rem 0;
    border: none;
    border-top: 1px solid var(--border-color);
}

.logout-link {
    display: block;
    padding: 0.75rem 1rem;
    color: var(--danger-color);
}

.dropdown-link {
    display: block;
    padding: 0.75rem 1rem;
    color: var(--text-color);
}

.dropdown-link:hover {
    background: var(--bg-color);
}

.mobile-menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
}

.search-form {
    display: none;
    padding: 1rem 0;
}

.search-form.active {
    display: flex;
    gap: 0.5rem;
}

.search-form input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
}

/* =========================================
   Mobile Menu
   ========================================= */
.mobile-menu {
    position: fixed;
    top: 64px;
    left: 0;
    right: 0;
    background: var(--card-bg);
    padding: 1rem;
    box-shadow: var(--shadow-lg);
    display: none;
    z-index: 99;
}

.mobile-menu.open { display: block; }

.mobile-menu a {
    display: block;
    padding: 0.75rem 0;
    color: var(--text-color);
    border-bottom: 1px solid var(--border-color);
}

/* =========================================
   Buttons
   ========================================= */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    background: var(--border-color);
    color: var(--text-color);
}

.btn:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

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

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

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

/* =========================================
   Page Header
   ========================================= */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2rem;
}

.page-header h1 {
    margin: 0;
    font-size: 1.75rem;
}

.page-header .count {
    font-weight: 400;
    color: var(--text-muted);
}

/* =========================================
   Filters
   ========================================= */
.filters {
    margin-bottom: 1.5rem;
}

.filter-form select {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--card-bg);
    font-size: 1rem;
}

/* =========================================
   Recipe Grid
   ========================================= */
.recipe-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
}

@media (max-width: 1200px) {
    .recipe-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 900px) {
    .recipe-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }
}

@media (max-width: 480px) {
    .recipe-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }
}

.recipe-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: all 0.3s;
}

.recipe-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.recipe-card-image {
    display: block;
    position: relative;
    aspect-ratio: 4/3;
    overflow: hidden;
}

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

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

.recipe-card-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--border-color);
    font-size: 3rem;
}

.recipe-card-time {
    position: absolute;
    bottom: 0.75rem;
    left: 0.75rem;
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
}

.recipe-card-content {
    padding: 1rem;
}

.recipe-card-content h3 {
    margin: 0 0 0.5rem;
    font-size: 1.125rem;
}

.recipe-card-content h3 a {
    color: var(--text-color);
}

.recipe-card-category {
    display: inline-block;
    background: #FFF5F5;
    border: 1px solid #FED7D7;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    color: #E53E3E;
}

.recipe-card-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    flex-wrap: wrap;
}

.recipe-card-difficulty {
    display: inline-block;
    background: #FFF5F5;
    border: 1px solid #FED7D7;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    color: #E53E3E;
}

.recipe-card-actions {
    display: flex;
    gap: 0.5rem;
}

/* Mobile recipe card adjustments */
@media (max-width: 600px) {
    .recipe-card-content {
        padding: 0.75rem;
    }
    
    .recipe-card-content h3 {
        font-size: 0.95rem;
        line-height: 1.3;
    }
    
    .recipe-card-meta {
        font-size: 0.75rem;
        gap: 0.5rem;
        flex-wrap: wrap;
    }
    
    .recipe-card-category {
        font-size: 0.7rem;
        padding: 0.2rem 0.4rem;
    }
    
    .recipe-card-actions .btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
    }
    
    .recipe-card-time {
        font-size: 0.75rem;
        padding: 0.2rem 0.4rem;
    }
}

/* =========================================
   Empty State
   ========================================= */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
}

.empty-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.empty-state h2 {
    color: var(--text-muted);
}

/* =========================================
   Pagination
   ========================================= */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 2rem;
}

.pagination a {
    padding: 0.5rem 1rem;
    background: var(--card-bg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

/* =========================================
   Flash Messages
   ========================================= */
.flash-message {
    position: fixed;
    top: 80px;
    right: 1rem;
    padding: 1rem 2rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 1rem;
    animation: slideIn 0.3s ease;
}

.flash-success { background: #c6f6d5; color: #276749; }
.flash-error { background: #fed7d7; color: #c53030; }

.flash-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    opacity: 0.6;
}

.flash-message.fade-out {
    opacity: 0;
    transform: translateX(100%);
    transition: all 0.3s;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* =========================================
   Recipe Single View
   ========================================= */
.breadcrumb {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.breadcrumb a { color: var(--text-muted); }
.breadcrumb span { margin: 0 0.5rem; }

.recipe-header {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-bottom: 2rem;
}

.recipe-header h1 {
    font-size: 2rem;
    margin-bottom: 1rem;
}

.recipe-description {
    color: var(--text-muted);
    font-size: 1.125rem;
}

.recipe-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin: 1.5rem 0;
}

.meta-item {
    background: var(--bg-color);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
}

.recipe-header-image img {
    width: 100%;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.recipe-actions {
    display: flex;
    gap: 0.75rem;
}

.recipe-body {
    display: grid;
    grid-template-columns: 350px 1fr;
    gap: 2rem;
}

/* =========================================
   Ingredients Sidebar
   ========================================= */
.recipe-sidebar {
    position: sticky;
    top: 80px;
    height: fit-content;
}

.recipe-ingredients,
.recipe-timer,
.recipe-nutrition {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.recipe-ingredients h2,
.recipe-timer h3,
.recipe-nutrition h3 {
    margin-bottom: 1rem;
}

/* =========================================
   Serving Calculator ⭐
   ========================================= */
.serving-calculator {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    padding: 1rem;
    border-radius: var(--radius-md);
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.serving-decrease,
.serving-increase {
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255,255,255,0.2);
    color: white;
    border-radius: 50%;
    font-size: 1.25rem;
    cursor: pointer;
    transition: background 0.2s;
}

.serving-decrease:hover,
.serving-increase:hover {
    background: rgba(255,255,255,0.3);
}

.serving-input {
    width: 50px;
    height: 36px;
    text-align: center;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1.125rem;
    font-weight: 600;
}

/* =========================================
   Ingredients List
   ========================================= */
.ingredients-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.ingredient-item {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.ingredient-item:hover {
    background: var(--bg-color);
}

.ingredient-item.checked {
    text-decoration: line-through;
    color: var(--text-light);
}

.ingredient-checkbox {
    margin-right: 0.5rem;
}

.ingredient-item.checked .ingredient-checkbox::after {
    content: '✓';
}

.ingredient-header {
    font-weight: 700;
    color: var(--primary-color);
    padding: 1rem 0 0.5rem;
    border: none;
}

.ingredient-amount {
    font-weight: 600;
}

.ingredient-note {
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* =========================================
   Timer
   ========================================= */
.timer-display {
    font-size: 3rem;
    font-weight: 700;
    text-align: center;
    font-family: monospace;
    margin-bottom: 1rem;
}

.timer-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.timer-minutes {
    width: 60px;
    padding: 0.5rem;
    text-align: center;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}

.timer-buttons {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
}

.recipe-timer.timer-alarm {
    animation: pulse 0.5s infinite alternate;
}

@keyframes pulse {
    from { box-shadow: 0 0 0 0 rgba(245,101,101,0.7); }
    to { box-shadow: 0 0 20px 10px rgba(245,101,101,0.3); }
}

/* =========================================
   Recipe Steps
   ========================================= */
.steps-list {
    list-style: none;
    padding: 0;
    margin: 0;
    counter-reset: step;
}

.recipe-step {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-sm);
}

.recipe-step.completed {
    opacity: 0.6;
}

.step-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.step-number {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    flex-shrink: 0;
}

.step-checkbox {
    cursor: pointer;
    font-size: 1.25rem;
}

.recipe-step.completed .step-checkbox::after {
    content: '✓';
    color: var(--success-color);
}

.step-title {
    margin: 0;
    flex: 1;
}

.step-duration {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.step-images {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.75rem;
    margin-top: 1rem;
}

.step-images img {
    border-radius: var(--radius-md);
}

/* =========================================
   Nutrition
   ========================================= */
.nutrition-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.nutrition-list li {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color);
}

.nutrition-value {
    font-weight: 600;
}

/* =========================================
   Video
   ========================================= */
.video-wrapper {
    position: relative;
    padding-bottom: 56.25%;
    height: 0;
    overflow: hidden;
    border-radius: var(--radius-lg);
}

.video-wrapper iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
}

/* =========================================
   Gallery
   ========================================= */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.gallery-item img {
    border-radius: var(--radius-md);
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
}

/* =========================================
   Footer
   ========================================= */
.main-footer {
    background: var(--card-bg);
    padding: 2rem 0;
    margin-top: 3rem;
    text-align: center;
    color: var(--text-muted);
    border-top: 1px solid var(--border-color);
}

/* =========================================
   Autosuggest
   ========================================= */
.autosuggest-wrapper {
    position: relative;
    flex: 1;
}

.autosuggest-wrapper input {
    width: 100%;
}

.autosuggest-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: white;
    border: 2px solid var(--primary-color);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
    max-height: 250px;
    overflow-y: auto;
    z-index: 1000;
}

.autosuggest-item {
    padding: 0.875rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background 0.15s;
}

.autosuggest-item:last-child {
    border-bottom: none;
}

.autosuggest-item:hover,
.autosuggest-item.selected {
    background: #FFF5F5;
}

.autosuggest-item-name strong {
    color: var(--primary-color);
}

.autosuggest-create {
    background: #f8f9fa;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
}

.autosuggest-create:hover {
    background: #FFF5F5;
}

.autosuggest-create-icon {
    width: 24px;
    height: 24px;
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
}

/* =========================================
   Responsive
   ========================================= */
@media (max-width: 768px) {
    .main-nav { display: none; }
    .mobile-menu-toggle { display: block; }
    
    .recipe-header {
        grid-template-columns: 1fr;
    }
    
    .recipe-body {
        grid-template-columns: 1fr;
    }
    
    .recipe-sidebar {
        position: static;
    }
    
    .page-header {
        flex-direction: column;
        gap: 1rem;
        align-items: flex-start;
    }
}
