/* ===== CSS Custom Properties (Telegram theme-aware) ===== */
:root {
    --bg: var(--tg-theme-bg-color, #0f0f13);
    --bg2: var(--tg-theme-secondary-bg-color, #1a1a24);
    --text: var(--tg-theme-text-color, #f0f0f0);
    --hint: var(--tg-theme-hint-color, #7a7a90);
    --link: var(--tg-theme-link-color, #6c7eff);
    --accent: var(--tg-theme-button-color, #6c7eff);
    --accent-text: var(--tg-theme-button-text-color, #ffffff);
    --danger: #ff5b6e;
    --success: #4fd1a5;
    --warning: #f5a623;

    --card-bg: var(--bg2);
    --border: rgba(255, 255, 255, 0.07);

    --radius-sm: 10px;
    --radius: 16px;
    --radius-lg: 24px;

    --space-xs: 6px;
    --space-sm: 12px;
    --space: 16px;
    --space-md: 20px;
    --space-lg: 28px;

    --nav-h: 64px;

    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    /* Tag colours by category */
    --tag-category: #3b4fd9;
    --tag-allergen: #c0392b;
    --tag-diet: #27ae60;
    --tag-taste: #8e44ad;
}

/* ===== Reset ===== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding-bottom: calc(var(--nav-h) + var(--space));
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

/* ===== Layout ===== */
#app {
    max-width: 480px;
    margin: 0 auto;
    padding: var(--space);
}

/* ===== Section ===== */
.section {
    display: none;
}

.section.active {
    display: block;
    animation: fadeUp 0.22s ease;
}

@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-md);
    padding-top: var(--space-sm);
}

h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

/* ===== Cards ===== */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: var(--space);
    margin-bottom: var(--space-sm);
    border: 1px solid var(--border);
}

/* ===== Spinner ===== */
.loading-state {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 120px;
}

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

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

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 14px 20px;
    border: none;
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.1s;
    text-align: center;
}

.btn:active {
    transform: scale(0.97);
    opacity: 0.85;
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent);
    color: var(--accent-text);
}

.btn-secondary {
    background: var(--card-bg);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-ghost {
    background: transparent;
    color: var(--accent);
    border: 1.5px solid var(--accent);
}

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

.btn-sm {
    padding: 9px 16px;
    font-size: 0.875rem;
    border-radius: var(--radius-sm);
}

.btn-icon {
    font-size: 1.1em;
}

/* ===== Input / Form ===== */
.form-group {
    margin-bottom: var(--space);
}

.form-label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--hint);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    padding: 13px 16px;
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font);
    font-size: 1rem;
    line-height: 1.4;
    outline: none;
    transition: border-color 0.2s;
    -webkit-appearance: none;
}

.form-input:focus {
    border-color: var(--accent);
}

.form-input::placeholder {
    color: var(--hint);
}

/* Number input tweaks */
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
    -webkit-appearance: none;
}

/* ===== Segmented Control (Gender / Goal) ===== */
.seg-control {
    display: flex;
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 4px;
    gap: 4px;
    border: 1.5px solid var(--border);
}

.seg-btn {
    flex: 1;
    padding: 10px 8px;
    border: none;
    background: none;
    border-radius: calc(var(--radius-sm) - 2px);
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--hint);
    cursor: pointer;
    transition: all 0.2s;
}

.seg-btn.active {
    background: var(--accent);
    color: var(--accent-text);
    font-weight: 600;
}

/* ===== Tag Pills ===== */
.tags-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: var(--space-sm);
}

.tag-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 7px 13px;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 500;
    border: 1.5px solid transparent;
    cursor: pointer;
    transition: all 0.18s;
    user-select: none;
    background: var(--bg);
    color: var(--hint);
    border-color: var(--border);
}

.tag-pill:active {
    transform: scale(0.95);
}

/* Selected states per tag type */
.tag-pill.selected[data-type="category"] {
    background: rgba(59, 79, 217, 0.18);
    border-color: #3b4fd9;
    color: #8aa0ff;
}

.tag-pill.selected[data-type="allergen"] {
    background: rgba(192, 57, 43, 0.18);
    border-color: #e74c3c;
    color: #ff7b72;
}

.tag-pill.selected[data-type="diet"] {
    background: rgba(39, 174, 96, 0.18);
    border-color: #27ae60;
    color: #5feba3;
}

.tag-pill.selected[data-type="taste"] {
    background: rgba(142, 68, 173, 0.18);
    border-color: #8e44ad;
    color: #c39bd3;
}

/* ===== Search ===== */
.search-wrap {
    position: relative;
    margin-bottom: var(--space);
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1rem;
}

.search-input {
    width: 100%;
    padding: 12px 16px 12px 40px;
    background: var(--card-bg);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}

.search-input:focus {
    border-color: var(--accent);
}

.search-input::placeholder {
    color: var(--hint);
}

/* ===== Recipe Card ===== */
.recipe-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: var(--space);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: transform 0.15s, border-color 0.15s;
    margin-bottom: 10px;
}

.recipe-card:active {
    transform: scale(0.98);
    border-color: var(--accent);
}

.recipe-card .title {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 4px;
}

.recipe-card .meta {
    font-size: 0.82rem;
    color: var(--hint);
    margin-bottom: 8px;
}

.recipe-card .nutrition {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.recipe-card .nutrition .badge {
    background: var(--bg);
    color: var(--hint);
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 500;
}

.recipe-card .nutrition .badge.kcal {
    color: var(--warning);
}

/* ===== Profile: Compact View ===== */
.profile-header {
    display: flex;
    align-items: center;
    gap: var(--space);
    margin-bottom: var(--space-lg);
}

.avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #a04ff5);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    flex-shrink: 0;
}

.profile-name {
    font-size: 1.2rem;
    font-weight: 700;
}

.profile-sub {
    font-size: 0.85rem;
    color: var(--hint);
    margin-top: 2px;
}

.kbzhu-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: var(--space);
}

.kbzhu-cell {
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 12px 4px;
    text-align: center;
    border: 1px solid var(--border);
}

.kbzhu-cell .k-val {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
}

.kbzhu-cell .k-label {
    font-size: 0.7rem;
    color: var(--hint);
    margin-top: 2px;
}

.kbzhu-cell.kcal .k-val {
    color: var(--warning);
}

.kbzhu-cell.protein .k-val {
    color: #6cb8ff;
}

.kbzhu-cell.fat .k-val {
    color: #ffb347;
}

.kbzhu-cell.carbs .k-val {
    color: var(--success);
}

.profile-rows {
    margin-bottom: var(--space);
}

.profile-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 11px 0;
    border-bottom: 1px solid var(--border);
}

.profile-row:last-child {
    border-bottom: none;
}

.profile-row .pr-label {
    font-size: 0.88rem;
    color: var(--hint);
}

.profile-row .pr-val {
    font-size: 0.92rem;
    font-weight: 500;
}

.pref-section {
    margin-bottom: var(--space);
}

.pref-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--hint);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 8px;
}

/* ===== Profile Incomplete Banner ===== */
.banner {
    background: linear-gradient(135deg, rgba(108, 126, 255, 0.15), rgba(160, 79, 245, 0.15));
    border: 1.5px solid rgba(108, 126, 255, 0.3);
    border-radius: var(--radius);
    padding: var(--space);
    margin-bottom: var(--space);
    text-align: center;
}

.banner .banner-icon {
    font-size: 2rem;
    margin-bottom: 8px;
}

.banner .banner-title {
    font-weight: 700;
    font-size: 1.05rem;
    margin-bottom: 4px;
}

.banner .banner-sub {
    font-size: 0.87rem;
    color: var(--hint);
    margin-bottom: var(--space);
}

/* ===== Plan Section ===== */
.macro-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: var(--space);
}

.macro-cell {
    text-align: center;
    background: var(--card-bg);
    border-radius: var(--radius-sm);
    padding: 10px 4px;
    border: 1px solid var(--border);
}

.macro-cell .m-val {
    font-size: 1.1rem;
    font-weight: 700;
}

.macro-cell .m-label {
    font-size: 0.7rem;
    color: var(--hint);
    margin-top: 2px;
}

.meal-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: var(--space);
    border: 1px solid var(--border);
    margin-bottom: 10px;
}

.meal-label {
    font-size: 0.78rem;
    color: var(--hint);
    font-weight: 600;
    margin-bottom: 4px;
}

.meal-title {
    font-weight: 600;
    font-size: 1rem;
}

/* ===== Bottom Navigation ===== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--nav-h);
    background: rgba(15, 15, 19, 0.92);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 100;
    padding: 0 var(--space);
}

.nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    background: none;
    border: none;
    color: var(--hint);
    cursor: pointer;
    padding: 8px 20px;
    border-radius: var(--radius-sm);
    transition: color 0.15s;
    min-width: 72px;
}

.nav-btn.active {
    color: var(--accent);
}

.nav-icon {
    font-size: 1.4rem;
}

.nav-label {
    font-size: 0.68rem;
    font-weight: 500;
}

/* ===== Modal (bottom sheet) ===== */
.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.modal.hidden {
    display: none;
}

.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    animation: fadeIn 0.2s;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal-sheet {
    position: relative;
    background: var(--bg2);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: var(--space-sm) var(--space) calc(var(--nav-h) + var(--space));
    max-height: 92vh;
    overflow-y: auto;
    animation: slideUp 0.28s cubic-bezier(0.34, 1.22, 0.64, 1);
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }

    to {
        transform: translateY(0);
    }
}

.modal-handle {
    width: 40px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 0 auto var(--space-sm);
}

/* ===== Step indicator ===== */
.steps-indicator {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-bottom: var(--space-md);
}

.step-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--border);
    transition: all 0.25s;
}

.step-dot.active {
    background: var(--accent);
    width: 24px;
    border-radius: 4px;
}

.step-dot.done {
    background: var(--success);
}

/* ===== Modal content ===== */
.modal-content {
    min-height: 300px;
}

.step-title {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 4px;
}

.step-sub {
    font-size: 0.88rem;
    color: var(--hint);
    margin-bottom: var(--space-md);
    line-height: 1.45;
}

.tag-group-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--hint);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin: var(--space-sm) 0 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.tag-group-label::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

.modal-footer {
    display: flex;
    gap: 10px;
    margin-top: var(--space-md);
}

.modal-footer .btn {
    flex: 1;
}

/* ===== Utility ===== */
.hidden {
    display: none !important;
}

.mt-sm {
    margin-top: var(--space-sm);
}

.mt {
    margin-top: var(--space);
}

.text-hint {
    color: var(--hint);
    font-size: 0.88rem;
}

.placeholder-state {
    text-align: center;
    color: var(--hint);
    padding: 40px 0;
    font-size: 0.95rem;
}