@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    /* Motyw: czarny + roz + fiolet */
    --bg-primary: #06060b;
    --bg-secondary: #141420;
    --text-primary: #f7f3ff;
    --text-secondary: #c7b7da;

    --accent-color: #f472b6;
    --accent-hover: #ec4899;
    --gradient-primary: linear-gradient(135deg, #f472b6 0%, #8b5cf6 100%);
    --gradient-secondary: linear-gradient(135deg, #ec4899 0%, #7c3aed 100%);

    --border-color: #312446;
    --card-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.45), 0 8px 10px -6px rgba(0, 0, 0, 0.35);
    --soft-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --border-radius: 24px;
    --border-radius-sm: 12px;

    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #06060b;
        --bg-secondary: #141420;
        --text-primary: #f7f3ff;
        --text-secondary: #c7b7da;
        --border-color: #312446;
        --card-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
        --soft-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.35);
    }
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    line-height: 1.6;
}

h1,
h2,
h3,
h4 {
    font-weight: 700;
    letter-spacing: -0.02em;
}

a {
    color: inherit;
    text-decoration: none;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

.flex-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

.text-gradient {
    background: var(--gradient-primary);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.glass-card {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
    border: 1px solid var(--border-color);
    padding: 2rem;
    transition: var(--transition-smooth);
}

.glass-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 15px 30px -5px rgba(0, 0, 0, 0.1);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border-radius: 9999px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-smooth);
    border: none;
    font-size: 1rem;
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
    box-shadow: 0 4px 14px 0 rgba(244, 114, 182, 0.39);
}

.btn-primary:hover {
    transform: scale(1.02);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.btn-outline:hover {
    background: var(--bg-secondary);
    border-color: var(--accent-color);
}

.btn-block {
    width: 100%;
}

.input-field {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: inherit;
    transition: var(--transition-smooth);
    outline: none;
}

.input-field:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(244, 114, 182, 0.15);
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.875rem;
}

select.input-field {
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 1em;
}

/* NAVBAR & HERO */
.navbar {
    padding: 1.5rem 0;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 1.25rem;
}

.nav-links {
    display: flex;
    gap: 1rem;
}

.hero {
    padding: 80px 0;
    text-align: center;
    background: radial-gradient(circle at top right, rgba(244, 114, 182, 0.12), transparent 32%);
}

.hero-content {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.hero h1 {
    font-size: clamp(2.5rem, 5vw, 4rem);
}

.hero-subtitle {
    font-size: 1.125rem;
    color: var(--text-secondary);
    line-height: 1.8;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 9999px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    font-size: 0.875rem;
    font-weight: 500;
}

.badge-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-color);
    box-shadow: 0 0 10px var(--accent-color);
}

.feature-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
    margin-top: 40px;
}

.feature-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.5rem;
}

/* Dashboard Layout */
.dashboard-container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 250px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
}

.sidebar-header {
    margin-bottom: 2.5rem;
    padding: 0 0.5rem;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: var(--border-radius-sm);
    color: var(--text-secondary);
    font-weight: 500;
    transition: var(--transition-smooth);
}

.nav-item:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.nav-item.active {
    background: rgba(244, 114, 182, 0.14);
    color: var(--accent-color);
}

.main-content {
    flex: 1;
    margin-left: 250px;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: 70px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 2rem;
    position: sticky;
    top: 0;
}

.page-content {
    padding: 2rem;
    flex: 1;
    max-width: 1000px;
}

/* Auth Views */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.auth-title {
    margin-bottom: 0.5rem;
}

.auth-subtitle {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.auth-error {
    background: #fee2e2;
    color: #ef4444;
    padding: 0.75rem;
    border-radius: var(--border-radius-sm);
    margin-bottom: 1.5rem;
    font-size: 0.875rem;
}

.auth-footer {
    margin-top: 1.5rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.auth-footer a {
    color: var(--accent-color);
    font-weight: 600;
}

/* Dashboard - Macros */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 2rem;
}

.calorie-card {
    text-align: center;
}

#calorie-card-clickable {
    cursor: pointer;
}

.progress-ring-wrapper {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 2rem 0;
}

.progress-ring-text {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.calories-number {
    font-size: 2.5rem;
    font-weight: 700;
    line-height: 1;
}

.macro-item {
    margin-bottom: 1.25rem;
}

.macro-bar-bg {
    width: 100%;
    height: 8px;
    background: var(--bg-primary);
    border-radius: 999px;
    margin-top: 0.5rem;
    overflow: hidden;
}

.macro-bar-fill {
    height: 100%;
    background: var(--accent-color);
    border-radius: 999px;
}

/* Meal modal */
.meal-modal {
    position: fixed;
    inset: 0;
    display: none;
    z-index: 10050;
}

.meal-modal.is-open {
    display: block;
}

.meal-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(2, 3, 10, 0.72);
}

.meal-modal-panel {
    position: relative;
    max-width: 860px;
    width: calc(100% - 2rem);
    max-height: calc(100vh - 2rem);
    overflow: auto;
    margin: 1rem auto;
}

.meal-period-block + .meal-period-block {
    margin-top: 1.1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.meal-period-summary {
    color: var(--text-secondary);
    margin: 0.35rem 0 0.75rem;
    font-size: 0.92rem;
}

.meal-empty-row {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.meal-list {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.meal-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.8rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    padding: 0.7rem 0.8rem;
}

.meal-row-main {
    min-width: 0;
}

.meal-row-main strong {
    display: block;
    margin-bottom: 0.2rem;
}

.meal-row-main small {
    color: var(--text-secondary);
    font-size: 0.82rem;
    display: block;
    line-height: 1.35;
}

.meal-delete-btn {
    padding: 0.45rem 0.8rem;
    white-space: nowrap;
}

/* Hydration Widget */
.hydration-card .hydration-total {
    font-size: 1.2rem;
    margin-bottom: 1rem;
}

.hydration-controls {
    display: flex;
    gap: 0.6rem;
    margin-bottom: 1rem;
}

.hydration-btn {
    padding: 0.55rem 0.9rem;
    width: auto;
    flex: 1;
}

.hydration-cups {
    display: flex;
    gap: 0.8rem;
    flex-wrap: wrap;
}

.water-cup {
    width: 98px;
    height: 168px;
    position: relative;
    margin-bottom: 8px;
}

.water-cup-handle {
    position: absolute;
    right: -16px;
    top: 42px;
    width: 24px;
    height: 58px;
    border: 4px solid rgba(195, 170, 220, 0.7);
    border-left: none;
    border-radius: 0 16px 16px 0;
    opacity: 0.9;
    pointer-events: none;
}

.water-cup-shell {
    position: absolute;
    inset: 0;
    border: 3px solid rgba(198, 179, 233, 0.7);
    border-top-width: 6px;
    border-radius: 0 0 24px 24px;
    overflow: hidden;
    background: linear-gradient(to top, rgba(120, 98, 153, 0.2), rgba(22, 22, 36, 0.2));
    box-shadow: inset 0 0 14px rgba(255, 255, 255, 0.08);
}

.water-cup-rim {
    position: absolute;
    top: 0;
    left: -4px;
    right: -4px;
    height: 10px;
    background: linear-gradient(180deg, rgba(235, 219, 255, 0.85), rgba(194, 170, 226, 0.35));
    border-radius: 12px;
    z-index: 3;
    pointer-events: none;
}

.water-cup-fill {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: var(--fill, 0%);
    min-height: 0;
    background: linear-gradient(180deg, rgba(168, 85, 247, 0.88), rgba(217, 70, 239, 0.9));
    transition: height 0.45s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: inset 0 -10px 20px rgba(57, 8, 101, 0.35);
    z-index: 2;
}

.water-cup-fill::before,
.water-cup-fill::after {
    content: "";
    position: absolute;
    left: -50%;
    top: -12px;
    width: 200%;
    height: 24px;
    border-radius: 45%;
    background: rgba(255, 255, 255, 0.42);
    animation: waterWave 3s linear infinite;
}

.water-cup-fill::after {
    top: -16px;
    opacity: 0.55;
    animation-duration: 4.2s;
    animation-direction: reverse;
}

.water-cup-label {
    position: absolute;
    width: 100%;
    bottom: -26px;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

@keyframes waterWave {
    from {
        transform: translateX(0);
    }
    to {
        transform: translateX(50%);
    }
}

/* Anim */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-fade-in {
    animation: fadeIn 0.6s forwards;
}

.loader {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
    display: inline-block;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ===================================
   MOBILE FIRST - wygląd natywnej apki
   =================================== */
@media (max-width: 768px) {

    /* Zmniejsz zaokrąglenia */
    :root {
        --border-radius: 16px;
        --border-radius-sm: 10px;
    }

    body {
        -webkit-tap-highlight-color: transparent;
        overflow-x: hidden;
    }

    /* Layout */
    .dashboard-container {
        flex-direction: column;
        min-height: 100dvh;
    }

    /* ======== BOTTOM NAV (wcześniej sidebar) ======== */
    .sidebar {
        width: 100%;
        height: 62px;
        position: fixed;
        bottom: 0;
        left: 0;
        top: auto;
        border-right: none;
        border-top: 1px solid var(--border-color);
        padding: 0;
        z-index: 9999;
        flex-direction: row;
        align-items: stretch;
        justify-content: space-around;
        box-shadow: 0 -2px 20px rgba(0, 0, 0, 0.15);
        background: var(--bg-secondary);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
    }

    /* Ukryj logo i przycisk wylogowania w bottom nav */
    .sidebar-header,
    .sidebar>div:last-child {
        display: none !important;
    }

    .sidebar-nav {
        flex-direction: row;
        width: 100%;
        height: 100%;
        justify-content: space-around;
        align-items: stretch;
        gap: 0;
        flex: 1;
    }

    /* Elementy nawigacji */
    .nav-item {
        flex-direction: column;
        gap: 3px;
        font-size: 0.6rem;
        font-weight: 600;
        padding: 8px 4px 6px;
        text-align: center;
        flex: 1;
        border-radius: 0;
        letter-spacing: 0;
        min-width: 0;
    }

    .nav-item svg {
        width: 22px;
        height: 22px;
        flex-shrink: 0;
    }

    .nav-item.active {
        background: transparent;
        color: var(--accent-color);
        position: relative;
    }

    /* Kreseczka nad aktywnym elementem */
    .nav-item.active::before {
        content: '';
        position: absolute;
        top: 0;
        left: 20%;
        right: 20%;
        height: 2px;
        background: var(--accent-color);
        border-radius: 0 0 3px 3px;
    }

    /* ======== TREŚĆ GŁÓWNA ======== */
    .main-content {
        margin-left: 0;
        width: 100%;
        padding-bottom: 62px;
        /* Wysokość bottom nav */
        min-height: 100dvh;
    }

    /* Topbar */
    .topbar {
        padding: 0 1rem;
        height: 52px;
        position: sticky;
        top: 0;
        z-index: 100;
        background: var(--bg-secondary);
    }

    .topbar h2 {
        font-size: 1rem;
    }

    /* Zawartość stron */
    .page-content {
        padding: 1rem;
        max-width: 100%;
    }

    /* Karty */
    .glass-card {
        padding: 1rem;
        border-radius: 16px;
        margin-bottom: 0.75rem;
    }

    /* Siatka podsumowania kalorii */
    .summary-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    /* Liczba kalorii */
    .calories-number {
        font-size: 2.25rem;
    }

    /* ======== ZAKŁADKI ======== */
    .tabs {
        display: flex;
        overflow-x: auto;
        gap: 0.5rem;
        padding: 0 0 0.75rem;
        margin-bottom: 1.25rem;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }

    .tabs::-webkit-scrollbar {
        display: none;
    }

    .tab-btn {
        flex: 0 0 auto;
        padding: 0.5rem 1rem;
        font-size: 0.8rem;
        white-space: nowrap;
    }

    /* ======== PRZYCISKI ======== */
    .btn {
        width: 100%;
        padding: 0.9rem 1.25rem;
        font-size: 0.95rem;
    }

    /* Nie rozciągaj przycisków outline w flex row */
    .btn.btn-outline:not(:only-child) {
        width: auto;
    }

    /* ======== FORMULARZE ======== */
    .input-field {
        font-size: 16px;
        /* Zapobiega zoomowaniu na iOS */
        padding: 0.85rem 1rem;
    }

    .form-group {
        margin-bottom: 1rem;
    }

    /* ======== WYNIKI AI ======== */
    .result-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .res-item {
        padding: 0.85rem;
    }

    .meal-modal-panel {
        width: calc(100% - 1rem);
        margin: 0.5rem auto;
        max-height: calc(100vh - 1rem);
        padding: 1rem;
    }

    .meal-row {
        flex-direction: column;
        align-items: stretch;
    }

    .meal-delete-btn {
        width: 100%;
    }

    /* ======== AUTH ======== */
    .auth-wrapper {
        padding: 1.25rem;
        align-items: flex-start;
        padding-top: 2rem;
    }

    .auth-card {
        padding: 1.75rem 1.5rem;
    }

    /* ======== HERO (strona główna) ======== */
    .hero {
        padding: 40px 0;
    }

    .hero h1 {
        font-size: clamp(1.75rem, 8vw, 2.5rem);
    }

    .hero-subtitle {
        font-size: 0.95rem;
    }

    .feature-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
        margin-top: 24px;
    }

    /* Ukryj zbędne elementy na mobile */
    .nav-links {
        display: none;
    }
}

/* Mały telefon */
@media (max-width: 390px) {
    .page-content {
        padding: 0.75rem;
    }

    .glass-card {
        padding: 0.875rem;
    }

    .nav-item {
        font-size: 0.55rem;
    }
}

/* Safe area dla iPhone (notch/Dynamic Island) */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    @media (max-width: 768px) {
        .sidebar {
            padding-bottom: env(safe-area-inset-bottom);
            height: calc(62px + env(safe-area-inset-bottom));
        }

        .main-content {
            padding-bottom: calc(62px + env(safe-area-inset-bottom));
        }
    }
}
