/* === ZMIENNE MOTYWU SAAS === */
:root {
    /* Paleta - Emerald (Szmaragd) & Slate (Łupek) */
    --primary: #10b981;
    --primary-hover: #059669;
    --primary-light: #ecfdf5;
    
    --bg-body: #f3f4f6; /* Jasny szary tła */
    --bg-sidebar: #ffffff;
    --bg-surface: #ffffff;
    
    --text-main: #111827; /* Prawie czarny */
    --text-secondary: #6b7280; /* Szary tekst */
    --text-on-primary: #ffffff;

    --border-subtle: #e5e7eb;
    --border-focus: #10b981;

    /* Nowoczesne cienie (Elevation) */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-floating: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

    /* Layout */
    --sidebar-width: 260px;
    --header-height: 70px;
    --radius-md: 12px;
    --radius-lg: 16px;
}

/* Reset */
* { box-sizing: border-box; margin: 0; padding: 0; outline: none; -webkit-tap-highlight-color: transparent; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden; /* Zapobiega przewijaniu całego body */
}

h1, h2, h3 { font-family: 'Plus Jakarta Sans', sans-serif; font-weight: 700; color: var(--text-main); }

/* === GŁÓWNY UKŁAD (LAYOUT) === */
.app-layout {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* 1. Sidebar (Boczny pasek) */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    z-index: 50;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.25rem;
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 2.5rem;
}
.logo-icon { background: var(--primary-light); padding: 6px; border-radius: 8px; font-size: 1.2rem; }

.nav-menu { display: flex; flex-direction: column; gap: 0.5rem; flex: 1; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-weight: 500;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    text-align: left;
    font-size: 0.95rem;
}

.nav-item:hover { background: var(--bg-body); color: var(--primary); }
.nav-item.active { background: var(--primary-light); color: var(--primary-hover); font-weight: 600; }
.nav-item .icon { font-size: 1.1rem; }

.login-btn-sidebar {
    background: var(--text-main);
    color: white;
    border: none;
    padding: 10px;
    border-radius: 8px;
    width: 100%;
    cursor: pointer;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: 0.2s;
}
.login-btn-sidebar:hover { opacity: 0.9; transform: translateY(-1px); }

/* 2. Główny obszar treści */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.top-bar {
    height: var(--header-height);
    padding: 0 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(243, 244, 246, 0.9);
    backdrop-filter: blur(10px);
    z-index: 40;
    flex-shrink: 0;
}
.page-title h1 { font-size: 1.5rem; margin-bottom: 2px; }
.subtitle { font-size: 0.85rem; color: var(--text-secondary); }

/* Kontenery Widoków */
.view-content {
    display: none;
    flex: 1;
    overflow-y: auto; /* Przewijanie tylko wewnątrz widoku */
    padding: 1rem 2rem 2rem 2rem;
}
.view-content.active { display: block; animation: fadeIn 0.3s ease; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

/* === PLANER (SPLIT VIEW) === */
.split-view {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 1.5rem;
    height: 100%; /* Wypełnij wysokość rodzica */
    max-height: calc(100vh - var(--header-height) - 2rem);
}

/* Glass Panel Style */
.glass-panel {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.library-panel { height: 100%; }
.panel-header { padding: 1.25rem; border-bottom: 1px solid var(--border-subtle); background: #fff; }

.saas-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: inherit;
    transition: 0.2s;
    background: #f9fafb;
}
.saas-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); background: white; }

.filter-pills { display: flex; gap: 6px; margin-bottom: 1rem; overflow-x: auto; padding-bottom: 5px; -webkit-overflow-scrolling: touch; }
.pill {
    padding: 6px 12px;
    border-radius: 20px;
    border: 1px solid var(--border-subtle);
    background: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-secondary);
    transition: 0.2s;
    white-space: nowrap;
}
.pill:hover { border-color: var(--primary); color: var(--primary); }
.pill.active { background: var(--primary); color: white; border-color: var(--primary); }

.recipes-scroll-area {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Karta Przepisu (Soft UI) */
.recipe-card {
    background: #fff;
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 12px;
    cursor: grab;
    transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative;
    user-select: none;
    /* Zapobiegamy problemom z drag na mobilkach */
    touch-action: none; 
}
.recipe-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: transparent;
}
.recipe-card:active { cursor: grabbing; }

.recipe-card-header { display: flex; justify-content: space-between; align-items: flex-start; }
.recipe-name { font-weight: 600; font-size: 0.95rem; color: var(--text-main); line-height: 1.3; margin-bottom: 6px; }
.recipe-tag {
    font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 700; padding: 2px 6px; border-radius: 4px; display: inline-block;
}
.tag-breakfast { background: #fff7ed; color: #c2410c; }
.tag-lunch { background: #f0fdf4; color: #15803d; }
.tag-dinner { background: #eff6ff; color: #1d4ed8; }

.card-actions { display: flex; gap: 4px; opacity: 0; transition: 0.2s; justify-content: flex-end; margin-top: 8px; }
.recipe-card:hover .card-actions { opacity: 1; }

/* Na mobilnych zawsze pokazuj akcje, bo nie ma hover */
@media (hover: none) {
    .card-actions { opacity: 1; }
}

.btn-mini { background: var(--bg-body); border: none; border-radius: 6px; width: 28px; height: 28px; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 0.9rem; color: var(--text-secondary); transition: 0.2s; }
.btn-mini:hover { background: var(--primary); color: white; }
.btn-mini.delete:hover { background: #ef4444; color: white; }

/* Siatka Planera (Grid) */
.calendar-panel { flex: 1; display: flex; flex-direction: column; height: 100%; overflow: hidden; }
.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.btn-text-danger { background: none; border: none; color: #ef4444; font-weight: 600; font-size: 0.85rem; cursor: pointer; padding: 6px 12px; border-radius: 6px; transition: 0.2s; display: flex; align-items: center; gap: 5px;}
.btn-text-danger:hover { background: #fee2e2; }

.week-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr); /* Desktop: 7 kolumn */
    gap: 12px;
    flex: 1;
    overflow-y: auto;
    padding-bottom: 20px;
}

.day-column {
    background: #fff;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    display: flex;
    flex-direction: column;
    min-width: 150px;
    box-shadow: var(--shadow-sm);
    transition: 0.2s;
}
.day-column:hover { box-shadow: var(--shadow-md); }

.day-header {
    padding: 12px;
    text-align: center;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-subtle);
    background: #f9fafb;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.meal-slot {
    padding: 8px;
    min-height: 110px;
    border-bottom: 1px dashed var(--border-subtle);
    position: relative;
    transition: background 0.2s;
    display: flex;
    flex-direction: column;
}
.meal-slot:last-child { border-bottom: none; }
.meal-slot-label {
    font-size: 0.65rem; color: #9ca3af; text-transform: uppercase; font-weight: 600; margin-bottom: 6px; pointer-events: none;
}
.meal-slot.sortable-over { background: var(--primary-light); border-color: var(--primary); }

/* Pusty Slot - Placeholder */
.empty-slot-placeholder {
    flex: 1; display: flex; align-items: center; justify-content: center; 
    opacity: 0; transition: 0.2s; pointer-events: none;
}
.meal-slot:hover .empty-slot-placeholder { opacity: 0.5; }
.empty-icon { font-size: 1.5rem; color: var(--primary); font-weight: bold; }

/* Sortable Ghost */
.sortable-ghost { opacity: 0.4; background: var(--bg-body); border: 2px dashed var(--primary); }
.sortable-drag { opacity: 0.9; transform: scale(1.05) rotate(2deg); box-shadow: var(--shadow-floating); z-index: 100; cursor: grabbing; }

/* === ZAKUPY (LISTA) === */
.shopping-container-saas { max-width: 1000px; margin: 0 auto; padding-bottom: 40px;}
.shopping-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 2rem; }

.shopping-card { background: white; border-radius: var(--radius-lg); box-shadow: var(--shadow-md); overflow: hidden; border: 1px solid var(--border-subtle); transition: 0.3s; }
.card-header-bg {
    background: linear-gradient(135deg, var(--primary) 0%, #059669 100%);
    padding: 1.2rem 1.5rem; color: white; display: flex; justify-content: space-between; align-items: center; cursor: pointer;
}
.card-header-bg h3 { color: white; margin: 0; font-size: 1.1rem; }
.badge-pill { background: rgba(255,255,255,0.2); padding: 4px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: 600; margin-top: 4px; display: inline-block;}
.collapse-icon { font-size: 0.8rem; transition: transform 0.3s; }

.shopping-card.collapsed .collapse-icon { transform: rotate(-90deg); }
.shopping-card.collapsed .shopping-list-body { max-height: 0; }

.shopping-list-body { 
    padding: 0; 
    max-height: 2000px; /* Duża wartość dla animacji */
    overflow: hidden; 
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.shopping-category-group { padding: 0; }
.category-header {
    background: #f9fafb; padding: 8px 16px; font-size: 0.75rem; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid var(--border-subtle); display: flex; align-items: center; gap: 8px;
}
.shopping-item-row {
    display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border-subtle); transition: 0.2s; cursor: pointer;
}
.shopping-item-row:last-child { border-bottom: none; }
.shopping-item-row:hover { background: #f9fafb; }

.custom-checkbox {
    appearance: none; width: 20px; height: 20px; border: 2px solid #d1d5db; border-radius: 6px; cursor: pointer; transition: 0.2s; position: relative; flex-shrink: 0;
}
.custom-checkbox:checked { background: var(--primary); border-color: var(--primary); }
.custom-checkbox:checked::after {
    content: '✓'; position: absolute; color: white; font-size: 14px; top: 50%; left: 50%; transform: translate(-50%, -50%);
}

.item-text { flex: 1; font-size: 0.95rem; color: var(--text-main); transition: 0.2s; }
.item-checked .item-text { text-decoration: line-through; color: #9ca3af; }
.item-qty { background: var(--bg-body); padding: 2px 8px; border-radius: 6px; font-size: 0.8rem; font-weight: 600; color: var(--text-secondary); white-space: nowrap;}

/* === FORMULARZ DODAWANIA === */
.form-container-saas { max-width: 600px; margin: 0 auto; padding: 2rem; }
.form-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 1rem; }
.input-group { margin-bottom: 1.25rem; }
.input-group label { display: block; margin-bottom: 0.5rem; font-weight: 600; font-size: 0.9rem; }
.hint { color: var(--text-secondary); font-weight: 400; font-size: 0.8rem; }
.area { min-height: 120px; resize: vertical; font-family: inherit;}
.btn-primary-lg {
    width: 100%; background: var(--primary); color: white; padding: 14px; border: none; border-radius: var(--radius-md); font-size: 1rem; font-weight: 600; cursor: pointer; transition: 0.2s; box-shadow: 0 4px 6px rgba(16, 185, 129, 0.2);
}
.btn-primary-lg:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: 0 6px 12px rgba(16, 185, 129, 0.3); }

/* === MODALE I TOASTY === */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.4); backdrop-filter: blur(5px);
    z-index: 9999; display: flex; align-items: center; justify-content: center;
    
    /* Domyślnie ukryte */
    opacity: 0; 
    visibility: hidden; 
    pointer-events: none; /* To ważne: kliknięcia przechodzą przez ukryty modal */
    transition: 0.3s;
}

/* Pokaż modal, gdy ma klasę .active (używane przez przepis i potwierdzenie) */
.modal-overlay.active { 
    opacity: 1; 
    visibility: visible; 
    pointer-events: auto; /* Włączamy klikanie */
}

/* Specjalny wyjątek dla logowania (Auth Overlay) */
/* Ten modal działa odwrotnie - jest widoczny, dopóki nie dostanie klasy .hidden */
#authOverlay:not(.hidden) { 
    opacity: 1; 
    visibility: visible; 
    pointer-events: auto;
}

.modal-overlay.hidden { display: none; } 

.modal-card {
    background: white; padding: 2rem; border-radius: 20px; width: 90%; max-width: 400px;
    box-shadow: var(--shadow-floating); transform: scale(0.95); transition: 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
/* Animacja powiększania przy otwarciu */
.modal-overlay.active .modal-card,
#authOverlay:not(.hidden) .modal-card { 
    transform: scale(1); 
}

.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; border-bottom: 1px solid var(--border-subtle); padding-bottom: 10px;}
.btn-icon { background: #f3f4f6; border: none; width: 30px; height: 30px; border-radius: 50%; cursor: pointer; font-size: 1.2rem; display: flex; align-items: center; justify-content: center; transition: 0.2s; color: var(--text-secondary); }
.btn-icon:hover { background: #e5e7eb; color: var(--text-main); }

.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.btn-secondary { flex: 1; padding: 10px; background: #f3f4f6; border: none; border-radius: 8px; cursor: pointer; font-weight: 600; }
.btn-danger { flex: 1; padding: 10px; background: #ef4444; color: white; border: none; border-radius: 8px; cursor: pointer; font-weight: 600; }

.ingredient-checklist { list-style: none; padding: 0; }
.ingredient-checklist li { padding: 8px 0; border-bottom: 1px solid var(--border-subtle); color: var(--text-main); display: flex; align-items: center; gap: 8px; font-size: 0.95rem; }
.ingredient-checklist li::before { content: "•"; color: var(--primary); font-weight: bold; font-size: 1.2rem; }

.toast-notification {
    position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
    background: var(--text-main); color: white; padding: 12px 24px; border-radius: 30px;
    font-size: 0.9rem; font-weight: 600; z-index: 10000;
    box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 10px;
    animation: slideInDown 0.4s ease-out, slideOutUp 0.4s ease-in 2.5s forwards;
}
.toast-notification.error { background: #ef4444; }
@keyframes slideInDown { from { top: -50px; opacity: 0; } to { top: 20px; opacity: 1; } }
@keyframes slideOutUp { from { top: 20px; opacity: 1; } to { top: -50px; opacity: 0; } }
/* === RESPONSYWNOŚĆ (MOBILE) === */
.mobile-bottom-nav { display: none; }

@media (max-width: 768px) {
    .app-layout { flex-direction: column; }
    .sidebar { display: none; }
    
    /* Dolny pasek nawigacji */
    .mobile-bottom-nav {
        display: flex; position: fixed; bottom: 0; left: 0; right: 0; height: 70px;
        background: rgba(255,255,255,0.95); backdrop-filter: blur(10px);
        border-top: 1px solid var(--border-subtle);
        justify-content: space-around; align-items: center; z-index: 100;
        padding-bottom: env(safe-area-inset-bottom); /* Dla iPhone X+ */
        box-shadow: 0 -4px 20px rgba(0,0,0,0.03);
    }
    .mobile-nav-item {
        background: none; border: none; display: flex; flex-direction: column; align-items: center;
        font-size: 0.7rem; color: var(--text-secondary); gap: 4px; flex: 1; height: 100%; justify-content: center;
        font-weight: 500;
    }
    .mobile-nav-item.active { color: var(--primary); }
    .mobile-nav-item .icon { font-size: 1.3rem; margin-bottom: 2px; }

    /* Dopasowanie treści */
    .main-content { padding-bottom: 80px; } /* Miejsce na pasek */
    .top-bar { padding: 0 1rem; }
    .view-content { padding: 1rem 1rem 2rem 1rem; }

    /* Planer na telefonie */
    .split-view { display: flex; flex-direction: column; height: auto; max-height: none;}
    .library-panel { order: 2; max-height: 400px; border-radius: var(--radius-lg); margin-top: 20px;}
    .calendar-panel { order: 1; height: auto; overflow: visible; }

    /* Poziome przewijanie (Snap Scroll) */
    .week-grid {
        display: flex;
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        gap: 12px;
        padding-bottom: 10px;
        /* Ukrycie paska przewijania */
        scrollbar-width: none;
        -ms-overflow-style: none;
    }
    .week-grid::-webkit-scrollbar { display: none; }

    .day-column {
        min-width: 85vw; /* Prawie cały ekran */
        scroll-snap-align: center;
        margin-right: 4px;
    }
    
    .form-grid { grid-template-columns: 1fr; }
    .shopping-grid { grid-template-columns: 1fr; gap: 1rem; }
}