:root {
    --bg-color: #ffffff;
    --card-bg: #f9f9fb;
    --text-main: #1a1a1b;
    --text-muted: #57606a;
    --accent: #ff6b6b;
    --accent-soft: #fff0f0;
    --border-radius: 12px;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    margin: 0;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.app-container {
    max-width: 480px;
    margin: 0 auto;
    padding: 16px;
    min-height: 100vh;
}

header {
    margin-bottom: 24px;
}

h1 {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin: 0 0 12px 0;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    position: sticky;
    top: 0;
    background: white;
    z-index: 1000;
    padding: 12px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    /* Slight separation for sticky */
}

.nav-left,
.nav-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-back-btn {
    background: var(--text-main);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 999px;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.nav-back-btn:active {
    transform: scale(0.95);
}

.home-link-subtle {
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 500;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.home-link-subtle:hover {
    opacity: 1;
    color: var(--accent);
}

.hidden {
    display: none !important;
}

.cart-btn {
    background: var(--accent-soft);
    color: var(--accent);
    border: none;
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
    display: flex;
    gap: 6px;
    align-items: center;
}

.cart-btn.has-items {
    background: var(--accent);
    color: white;
}

.cart-btn:active {
    transform: scale(0.95);
}

/* Card Selection */
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.select-toggle {
    background: #fff;
    border: 2px solid #edeff2;
    color: var(--text-muted);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.2s;
}

.recipe-card.selected {
    border: 2px solid var(--accent);
    background: var(--accent-soft);
}

.recipe-card.selected .select-toggle {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* Detail Actions */
.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.detail-actions {
    display: flex;
    gap: 8px;
}

.action-btn {
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.select-btn {
    background: var(--accent-soft);
    color: var(--accent);
}

.select-btn.active {
    background: var(--accent);
    color: white;
}

.share-btn,
.secondary-btn {
    background: #f0f2f5;
    color: var(--text-main);
}

.print-btn {
    background: var(--text-main);
    color: white;
}

/* Cart View */
.cart-items {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 24px;
}

.cart-item {
    background: #fff;
    border: 2px solid #edeff2;
    border-radius: 12px;
    padding: 16px;
}

.cart-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

/* Master List Styling */
.master-list-title {
    color: var(--accent);
    display: flex;
    align-items: center;
    gap: 8px;
}

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

.category-group {
    background: #f8f9fa;
    padding: 16px;
    border-radius: 12px;
    border: 1px solid #e9ecef;
}

.category-name {
    font-size: 0.8rem;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0 0 12px 0;
    font-weight: 800;
}

.shopping-bullets {
    margin: 0;
    padding-left: 0;
    list-style-type: none;
}

.shopping-li {
    margin-bottom: 8px;
    font-size: 0.95rem;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 6px;
    transition: background 0.2s, opacity 0.2s;
}

.shopping-li:hover {
    background: rgba(0, 0, 0, 0.03);
}

.shopping-li.checked {
    opacity: 0.5;
    text-decoration: line-through;
}

.shopping-li input[type="checkbox"] {
    margin-top: 4px;
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--accent);
}

.shopping-li strong {
    color: var(--accent);
}

/* Draggable Items & Scheduling */
.draggable {
    cursor: grab;
    transition: box-shadow 0.2s, transform 0.2s;
}

.draggable:active {
    cursor: grabbing;
    transform: scale(1.02);
}

.drag-handle {
    font-size: 1.5rem;
    color: #ced4da;
    cursor: grab;
}

.cart-item-header {
    display: flex;
    gap: 16px;
    align-items: center;
}

.cart-item-info {
    flex-grow: 1;
}

.cart-item-info h3 {
    margin: 0 0 8px 0;
    border: none;
    padding: 0;
    text-transform: none;
    font-size: 1.1rem;
}

.meal-controls {
    display: flex;
    gap: 8px;
}

.meal-controls input,
.meal-controls select {
    padding: 6px 10px;
    border: 1px solid #ced4da;
    border-radius: 6px;
    font-size: 0.8rem;
    outline: none;
}

.meal-controls input:focus,
.meal-controls select:focus {
    border-color: var(--accent);
}

.recipe-type-tag {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--accent);
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.recipe-type-tag.detail {
    font-size: 0.85rem;
    margin-bottom: 8px;
}

.draggable.dragging {
    opacity: 0.8;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    background: white;
}

.instruction-note {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-style: italic;
    margin-bottom: 16px;
}

.remove-btn {
    background: none;
    border: none;
    color: #ff4d4d;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
}

.cart-item-preview {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* Print Handling */
.print-only {
    display: none;
}

/* Print Optimizations */
@media print {
    body {
        background: white !important;
        color: black !important;
    }

    .app-container {
        max-width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
        min-height: auto !important;
    }

    /* Hide everything except the print-only container */
    .top-bar,
    .category-filters,
    .search-container,
    .detail-header-v2,
    .recipe-title,
    .description,
    .select-btn,
    .print-btn,
    .share-btn,
    .instruction-note,
    .remove-btn,
    .meal-controls,
    .drag-handle,
    .cart-items,
    .master-list-container,
    section:not(.print-section),
    .back-btn,
    .home-link-subtle,
    .nav-left,
    .nav-right,
    header {
        display: none !important;
    }

    .print-only {
        display: block !important;
    }

    .print-main-title {
        font-size: 24pt;
        margin-bottom: 5pt;
        border-bottom: 2pt solid #000;
    }

    .print-date {
        font-size: 10pt;
        color: #666;
        margin-bottom: 20pt;
    }

    .print-sec-title {
        font-size: 18pt;
        margin-top: 20pt;
        border-bottom: 1pt solid #ccc;
        padding-bottom: 5pt;
    }

    .print-schedule-item {
        margin-bottom: 8pt;
        font-size: 11pt;
    }

    .print-cat-name {
        font-size: 14pt;
        margin: 15pt 0 5pt 0;
        background: #f0f0f0;
        padding: 4pt;
    }

    .print-shopping-list {
        margin: 0;
        padding-left: 20pt;
    }

    .print-shopping-list li {
        margin-bottom: 4pt;
        font-size: 10pt;
        list-style-type: square;
    }

    .print-page-break {
        page-break-before: always;
    }

    .print-recipe-block {
        margin-top: 20pt;
        page-break-inside: avoid;
    }

    .print-recipe-block h3 {
        font-size: 16pt;
        margin-bottom: 5pt;
        color: #ff6b6b;
    }

    .print-recipe-cols {
        display: flex;
        gap: 20pt;
        margin-top: 10pt;
    }

    .print-ingredients {
        flex: 1;
    }

    .print-instructions {
        flex: 2;
    }

    .print-recipe-block h4 {
        font-size: 12pt;
        margin-bottom: 5pt;
        border-bottom: 0.5pt solid #eee;
    }

    .print-divider {
        border: none;
        border-top: 1pt dashed #ccc;
        margin: 20pt 0;
    }
}

.search-container {
    position: sticky;
    top: 56px;
    z-index: 100;
    background: white;
    padding: 4px 0 12px 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.category-filters {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

.category-filters::-webkit-scrollbar {
    display: none;
}

.filter-chip {
    padding: 6px 16px;
    background: #f0f2f5;
    border: none;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}

.filter-chip.active {
    background: var(--accent);
    color: white;
}

.filter-chip:hover:not(.active) {
    background: #e4e6e9;
}

#search-input {
    width: 100%;
    padding: 14px 18px;
    border-radius: var(--border-radius);
    border: 2px solid #edeff2;
    font-size: 1rem;
    background-color: #f7f9fc;
    transition: border-color 0.2s, background-color 0.2s;
    outline: none;
}

#search-input:focus {
    border-color: var(--accent);
    background-color: #fff;
}

/* Recipe Cards */
.recipe-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.recipe-card {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    padding: 20px;
    cursor: pointer;
    transition: transform 0.1s;
}

.recipe-card:active {
    transform: scale(0.98);
}

.recipe-card h2 {
    font-size: 1.25rem;
    margin: 0 0 8px 0;
}

.recipe-card p {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin: 0;
}

.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 12px;
}

.tag {
    font-size: 0.75rem;
    padding: 4px 10px;
    background: #fff;
    border: 1px solid #e1e4e8;
    border-radius: 999px;
    color: var(--text-muted);
}

/* Detail View */
.detail-view {
    background: white;
    min-height: 100vh;
}

.back-btn {
    background: none;
    border: none;
    color: var(--accent);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 0;
    cursor: pointer;
    margin-bottom: 16px;
}

.recipe-title {
    font-size: 2rem;
    line-height: 1.1;
    margin-bottom: 12px;
}

.description {
    color: var(--text-muted);
    margin-bottom: 24px;
}

section {
    margin-bottom: 32px;
}

h3 {
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 16px;
    border-bottom: 1px solid #eee;
    padding-bottom: 8px;
}

.ingredient-item {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px dashed #eee;
}

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

.amount {
    font-weight: 600;
    color: var(--text-main);
    min-width: 80px;
    text-align: right;
}

.instruction-step {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
}

.step-number {
    background: var(--accent-soft);
    color: var(--accent);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    flex-shrink: 0;
}

.step-text {
    font-size: 1.1rem;
    line-height: 1.4;
}

.note-box {
    background: #fff8e6;
    border-left: 4px solid #f1c40f;
    padding: 16px;
    border-radius: 0 8px 8px 0;
    margin-top: 12px;
}

.hidden {
    display: none !important;
}

/* Mobile Optimizations */
@media (max-width: 480px) {
    .recipe-title {
        font-size: 1.75rem;
    }
}