/* ============================================================
   Nutrition Coach PWA — style w duchu iOS (dark mode)
   ============================================================ */

:root {
    --bg: #000000;
    --card: #1c1c1e;
    --card-2: #2c2c2e;
    --separator: rgba(84, 84, 88, 0.6);
    --text: #ffffff;
    --text-2: rgba(235, 235, 245, 0.6);
    --text-3: rgba(235, 235, 245, 0.3);
    --green: #30d158;
    --blue: #0a84ff;
    --orange: #ff9f0a;
    --red: #ff453a;
    --purple: #bf5af2;
    --radius: 16px;

    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

/* --- Stabilny, "natywny" layout: bez odbijania i przewijania strony --- */
html, body {
    height: 100%;
    overflow: hidden;               /* strona sama się nie przewija */
    overscroll-behavior: none;      /* blokada "rubber band" w Safari */
    touch-action: manipulation;     /* bez podwójnego tapnięcia = zoom */
}

body {
    position: fixed;                /* twardo przypięty viewport jak w natywnej appce */
    inset: 0;
    width: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

input, textarea {
    -webkit-user-select: text;
    user-select: text;
}

.hidden { display: none !important; }

/* ============ EKRAN LOGOWANIA ============ */

.auth-screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    padding-top: calc(var(--safe-top) + 24px);
    background: radial-gradient(120% 80% at 50% 0%, #0e2a1a 0%, #000 60%);
}

.auth-box {
    width: 100%;
    max-width: 360px;
    text-align: center;
}

.auth-logo { font-size: 64px; margin-bottom: 12px; }
.auth-title { font-size: 28px; font-weight: 700; letter-spacing: -0.4px; }
.auth-subtitle { color: var(--text-2); font-size: 15px; margin: 6px 0 28px; }

.auth-box form { display: flex; flex-direction: column; gap: 12px; }

.auth-error {
    color: var(--red);
    font-size: 14px;
    margin-top: 14px;
}

.btn-link {
    background: none;
    border: none;
    color: var(--blue);
    font-size: 15px;
    margin-top: 22px;
    cursor: pointer;
    font-family: inherit;
    display: block;
    width: 100%;
}

.btn-link-muted { color: var(--text-2); margin-top: 12px; font-size: 14px; }

/* ============ ELEMENTY WSPÓLNE ============ */

.input {
    width: 100%;
    background: var(--card-2);
    border: 1px solid transparent;
    border-radius: 12px;
    color: var(--text);
    font-size: 16px;             /* >=16px — iOS nie przybliża pola przy fokusie */
    padding: 13px 15px;
    outline: none;
    font-family: inherit;
    appearance: none;
    -webkit-appearance: none;
}

.auth-box .input { background: var(--card); }

.input:focus { border-color: var(--green); }
.input::placeholder { color: var(--text-3); }
.input:disabled { color: var(--text-2); }

select.input {
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23999' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
}

.btn {
    border: none;
    border-radius: 12px;
    font-size: 17px;
    font-weight: 600;
    padding: 14px 18px;
    cursor: pointer;
    font-family: inherit;
    transition: opacity 0.15s, transform 0.1s;
}

.btn:active { opacity: 0.7; transform: scale(0.98); }
.btn:disabled { opacity: 0.5; }

.btn-primary { background: var(--green); color: #000; }
.btn-secondary { background: var(--card-2); color: var(--text); }
.btn-danger { background: rgba(255, 69, 58, 0.15); color: var(--red); }

.btn-logout {
    display: block;
    width: 100%;
    background: var(--red);
    color: #fff;
    font-size: 17px;
    font-weight: 700;
    padding: 16px;
    margin: 8px 0 24px;
    border-radius: 14px;
}
.btn-small { padding: 12px 14px; font-size: 15px; flex-shrink: 0; }
.btn-full { width: 100%; margin-top: 14px; }

.icon-btn {
    background: var(--card-2);
    border: none;
    color: var(--text);
    width: 44px;
    height: 44px;
    border-radius: 12px;
    font-size: 18px;
    cursor: pointer;
    flex-shrink: 0;
    transition: opacity 0.15s, transform 0.1s;
}

.icon-btn:active { opacity: 0.7; transform: scale(0.95); }
.icon-btn.recording { background: var(--red); animation: pulse 1s infinite; }
.icon-btn.off { opacity: 0.4; }

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.08); }
}

.row-form { display: flex; gap: 8px; align-items: center; }

.hint {
    font-size: 12px;
    color: var(--text-3);
    margin-top: 10px;
    line-height: 1.4;
}

.field-label {
    display: block;
    font-size: 13px;
    color: var(--text-2);
    margin: 12px 0 6px;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 12px;
}

.card-head-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.card-head-row .card-title { margin-bottom: 0; }
.card-head-row .icon-btn { width: 34px; height: 34px; font-size: 15px; border-radius: 10px; }

/* ============ NAWIGACJA GÓRNA ============ */

.navbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 20;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    padding: 10px 20px 10px;
    padding-top: calc(var(--safe-top) + 10px);
    background: rgba(0, 0, 0, 0.75);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 0.5px solid var(--separator);
}

.navbar h1 {
    font-size: 30px;
    font-weight: 800;
    letter-spacing: -0.5px;
}

/* ============ TREŚĆ ============ */

.content {
    position: absolute;
    inset: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;   /* płynne przewijanie wewnątrz */
    overscroll-behavior: contain;        /* scroll nie "ucieka" do strony */
    padding: 20px;
    padding-top: calc(var(--safe-top) + 72px);
    padding-bottom: calc(var(--safe-bottom) + 110px);
}

.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 16px;
}

.card-title {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-2);
    margin-bottom: 14px;
}

/* ============ COACH DNIA ============ */

.coach-card { border-left: 3px solid var(--green); }

.coach-text {
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    white-space: pre-wrap;
}

/* ============ PIERŚCIEŃ KALORII ============ */

.ring-card { display: flex; flex-direction: column; align-items: center; }

.ring-wrap { position: relative; width: 180px; height: 180px; }

.ring { width: 100%; height: 100%; transform: rotate(-90deg); }

.ring-bg, .ring-fill {
    fill: none;
    stroke-width: 11;
    stroke-linecap: round;
}

.ring-bg { stroke: var(--card-2); }

.ring-fill {
    stroke: var(--green);
    stroke-dasharray: 326.7;     /* 2πr, r=52 */
    stroke-dashoffset: 326.7;
    transition: stroke-dashoffset 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}

.ring-center {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.ring-value { font-size: 34px; font-weight: 800; letter-spacing: -1px; }
.ring-label { font-size: 13px; color: var(--text-2); margin-top: 2px; }

.ring-meta {
    display: flex;
    justify-content: space-around;
    width: 100%;
    margin-top: 18px;
}

.meta-item { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.meta-value { font-size: 18px; font-weight: 700; }
.meta-label { font-size: 12px; color: var(--text-2); }

/* ============ MAKRO ============ */

.macro { margin-bottom: 16px; }
.macro:last-child { margin-bottom: 0; }

.macro-head {
    display: flex;
    justify-content: space-between;
    font-size: 15px;
    margin-bottom: 7px;
}

.macro-nums { color: var(--text-2); font-size: 13px; }

.bar {
    height: 8px;
    background: var(--card-2);
    border-radius: 4px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    width: 0%;
    border-radius: 4px;
    transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

.bar-fill.protein { background: var(--blue); }
.bar-fill.carbs   { background: var(--orange); }
.bar-fill.fat     { background: var(--purple); }

/* ============ SEGMENTED CONTROL (iOS) ============ */

.segmented {
    display: flex;
    background: var(--card-2);
    border-radius: 10px;
    padding: 2px;
    margin-bottom: 16px;
}

.seg-item {
    flex: 1;
    background: none;
    border: none;
    border-radius: 8px;
    color: var(--text-2);
    font-size: 13px;
    font-weight: 600;
    padding: 8px 4px;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.2s, color 0.2s;
    white-space: nowrap;
}

.seg-item.active {
    background: #636366;
    color: var(--text);
}

/* ============ WYKRES SŁUPKOWY (jak kroki w iOS) ============ */

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 4px;
}

.chart-big { font-size: 30px; font-weight: 800; letter-spacing: -0.8px; }
.chart-small { font-size: 18px; font-weight: 700; text-align: right; }
.chart-sub { font-size: 12px; color: var(--text-2); }
.chart-right { text-align: right; }

.chart-info {
    font-size: 13px;
    color: var(--green);
    font-weight: 600;
    min-height: 18px;
    margin-bottom: 6px;
}

.chart-area {
    position: relative;
    height: 160px;
    margin-top: 4px;
}

.chart-bars {
    display: flex;
    align-items: flex-end;
    gap: 7%;          /* nadpisywane przez JS w zależności od liczby słupków */
    height: 100%;
}

.chart-bar {
    flex: 1;
    background: var(--green);
    border-radius: 4px 4px 2px 2px;
    min-height: 2px;
    opacity: 0.85;
    transition: height 0.5s cubic-bezier(0.22, 1, 0.36, 1);
    cursor: pointer;
}

.chart-bar.empty { background: var(--card-2); opacity: 0.6; }
.chart-bar.over { background: var(--orange); }
.chart-bar.selected { opacity: 1; outline: 2px solid #fff3; }

.chart-target-line {
    position: absolute;
    left: 0; right: 0;
    border-top: 1.5px dashed rgba(235, 235, 245, 0.35);
    z-index: 2;
    pointer-events: none;
}

.chart-target-label {
    position: absolute;
    right: 0;
    top: -16px;
    font-size: 10px;
    color: var(--text-3);
}

.chart-labels {
    display: flex;
    gap: 7%;
    margin-top: 6px;
}

.chart-label {
    flex: 1;
    text-align: center;
    font-size: 10px;
    color: var(--text-3);
    overflow: hidden;
    white-space: nowrap;
}

/* ============ INSIGHTY ============ */

.insights-box { font-size: 14px; color: var(--text-2); line-height: 1.5; }

.insight-item {
    display: flex;
    gap: 10px;
    padding: 8px 0;
    font-size: 14px;
    color: var(--text);
    border-bottom: 0.5px solid var(--separator);
    align-items: flex-start;
}

.insight-item:last-child { border-bottom: none; }
.insight-item .emoji { flex-shrink: 0; }

/* ============ WAGA ============ */

.weight-chart {
    width: 100%;
    height: 80px;
    margin-top: 16px;
}

/* ============ ULUBIONE ============ */

.fav-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
}

.fav-chip {
    display: inline-flex;
    align-items: center;
    background: var(--card-2);
    border-radius: 18px;
    overflow: hidden;
}

.fav-name {
    background: none;
    border: none;
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
    padding: 9px 4px 9px 14px;
    cursor: pointer;
    font-family: inherit;
}

.fav-name small { color: var(--text-3); font-size: 11px; margin-left: 3px; }

.fav-x {
    background: none;
    border: none;
    color: var(--text-3);
    font-size: 12px;
    padding: 9px 12px 9px 8px;
    cursor: pointer;
}

.fav-x:active { color: var(--red); }

/* ============ LISTY (posiłki, waga) ============ */

.list-item {
    background: var(--card);
    border-radius: var(--radius);
    padding: 12px 14px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.list-thumb {
    width: 52px;
    height: 52px;
    border-radius: 10px;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--card-2);
}

.list-main { flex: 1; min-width: 0; }

.list-title {
    font-size: 16px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.list-sub { font-size: 13px; color: var(--text-2); margin-top: 3px; }

.list-delete {
    background: none;
    border: none;
    color: var(--red);
    font-size: 18px;
    cursor: pointer;
    padding: 6px;
    flex-shrink: 0;
}

.empty-state {
    text-align: center;
    color: var(--text-3);
    font-size: 15px;
    padding: 40px 20px;
}

/* ============ CZAT ============ */

.chips-row {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
}

.chip {
    background: var(--card);
    border: 1px solid var(--separator);
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    padding: 9px 14px;
    border-radius: 18px;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
    flex-shrink: 0;
    transition: opacity 0.15s;
}

.chip:active { opacity: 0.6; }

.chip-voice { border-color: var(--green); color: var(--green); }

.chip-voice.recording {
    background: var(--red);
    border-color: var(--red);
    color: #fff;
    animation: pulse 1s infinite;
}

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-bubble {
    max-width: 82%;
    padding: 12px 16px;
    border-radius: 20px;
    font-size: 16px;
    line-height: 1.4;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.chat-bubble.user {
    align-self: flex-end;
    background: var(--blue);
    color: #fff;
    border-bottom-right-radius: 6px;
}

.chat-bubble.coach {
    align-self: flex-start;
    background: var(--card);
    border-bottom-left-radius: 6px;
}

.chat-bubble.typing { color: var(--text-2); font-style: italic; }

.chat-input-bar {
    position: fixed;
    left: 0; right: 0;
    bottom: calc(var(--safe-bottom) + 64px);
    z-index: 25;
    padding: 10px 16px;
    background: rgba(0, 0, 0, 0.75);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
    border-top: 0.5px solid var(--separator);
}

/* ============ DOLNY TAB BAR (iOS) ============ */

.tabbar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 30;
    display: flex;
    justify-content: space-around;
    padding-top: 8px;
    padding-bottom: calc(var(--safe-bottom) + 6px);
    background: rgba(22, 22, 24, 0.82);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
    border-top: 0.5px solid var(--separator);
}

.tabbar-item {
    background: none;
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    font-size: 10px;
    font-weight: 500;
    color: var(--text-3);
    cursor: pointer;
    font-family: inherit;
    min-width: 56px;
    padding: 2px 4px;
}

.tabbar-item.active { color: var(--green); }
.tabbar-icon { font-size: 22px; line-height: 1; }

/* ============ TOAST ============ */

.toast {
    position: fixed;
    top: calc(var(--safe-top) + 14px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    background: var(--card-2);
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
    padding: 12px 20px;
    border-radius: 22px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
    max-width: 86%;
    text-align: center;
    animation: toast-in 0.25s ease;
}

.toast.error { background: var(--red); color: #fff; }

@keyframes toast-in {
    from { opacity: 0; transform: translate(-50%, -8px); }
    to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ============ LOADER ============ */

.busy {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0, 0, 0, 0.7);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.busy-box {
    background: var(--card);
    border-radius: 18px;
    padding: 26px 32px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    font-size: 15px;
    color: var(--text-2);
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--card-2);
    border-top-color: var(--green);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Większe ekrany — appka trzyma szerokość telefonu */
@media (min-width: 560px) {
    .content, .navbar, .tabbar, .chat-input-bar {
        max-width: 560px;
        margin-left: auto;
        margin-right: auto;
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        width: 100%;
    }
    .toast { transform: translateX(-50%); }
}
