:root {
    --bg-color: var(--tg-theme-bg-color, #fff);
    --text-color: var(--tg-theme-text-color, #000);
    --card-bg: var(--tg-theme-secondary-bg-color, rgba(255,255,255,0.8));
    --accent: var(--tg-theme-button-color, #34c759);
    --accent-text: var(--tg-theme-button-text-color, #fff);
    --hint: var(--tg-theme-hint-color, #8e8e93);
    --shadow: 0 4px 20px rgba(0,0,0,0.05);
    --danger: #ff3b30;
}

* {
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.bg-blobs {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: -1;
    overflow: hidden;
    opacity: 0.3;
    pointer-events: none;
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(60px);
}

.blob-1 {
    width: 200px; height: 200px;
    background: #34c759;
    top: -50px; right: -50px;
    animation: float 10s infinite alternate;
}

.blob-2 {
    width: 250px; height: 250px;
    background: #007aff;
    bottom: -50px; left: -50px;
    animation: float 12s infinite alternate-reverse;
}

@keyframes float {
    0% { transform: translate(0, 0); }
    100% { transform: translate(30px, 50px); }
}

.tab-bar {
    display: flex;
    justify-content: space-around;
    padding: 10px 0;
    background: var(--bg-color);
    border-bottom: 1px solid rgba(0,0,0,0.05);
    position: relative;
    z-index: 200;
    flex-shrink: 0;
}

.tab {
    font-weight: 600;
    font-size: 14px;
    color: var(--hint);
    cursor: pointer;
    position: relative;
    padding: 5px 10px;
    transition: 0.2s;
}

.tab.active {
    color: var(--text-color);
}

.tab.active::after {
    content: '';
    position: absolute;
    bottom: -11px; left: 0; width: 100%;
    height: 2px;
    background: var(--text-color);
    border-radius: 2px;
}

#cart-badge {
    background: var(--danger);
    color: white;
    font-size: 10px;
    padding: 2px 5px;
    border-radius: 10px;
    position: absolute;
    top: 0; right: -5px;
}

.hidden { display: none !important; }
.screen {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding-bottom: 20px;
}
.screen.active { display: block; }

#chat-screen.active {
    display: flex;
    flex-direction: column;
    padding-bottom: 0;
    height: 100%;
    overflow: hidden;
}

.header-sticky { padding: 10px 0; }
.title-box { padding: 0 20px; margin-bottom: 10px; }
.title { font-size: 28px; font-weight: 800; }
.subtitle { font-size: 13px; color: var(--hint); }

.categories-wrapper {
    position: relative;
    margin: 0 20px 10px 20px;
}

.categories {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 5px;
    scrollbar-width: none;
    scroll-behavior: smooth;
}
.categories::-webkit-scrollbar { display: none; }

.chip {
    padding: 8px 16px;
    background: rgba(128,128,128, 0.1);
    border-radius: 20px;
    font-size: 14px; font-weight: 600;
    white-space: nowrap; cursor: pointer;
    transition: 0.2s;
}

.chip.active {
    background: var(--text-color);
    color: var(--bg-color);
}

.grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 10px 20px;
}

.card {
    background: var(--card-bg);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--shadow);
    display: flex; flex-direction: column;
    opacity: 0;
    animation: slide-up 0.4s forwards;
    cursor: pointer;
}

@keyframes slide-up { to { opacity: 1; } }

.img-wrap { width: 100%; padding-top: 100%; position: relative; background: #eee; }
.img-wrap img { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; }

.info { padding: 10px; flex: 1; display: flex; flex-direction: column; }
.prod-name { font-weight: 700; font-size: 14px; margin-bottom: 4px; line-height: 1.2; }
.prod-desc { font-size: 11px; color: var(--hint); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-bottom: 8px;}
.bottom { margin-top: auto; display: flex; justify-content: space-between; align-items: center; }
.price { font-weight: 800; font-size: 15px; }

.add-btn {
    width: 30px; height: 30px; border-radius: 10px;
    background: var(--accent); color: white; border: none;
    font-size: 20px; display: flex; align-items: center; justify-content: center;
}

.cart-header { font-size: 24px; font-weight: 800; padding: 20px; }
.cart-list { padding: 0 20px; min-height: 200px; }
.cart-item {
    display: flex; align-items: center; gap: 10px;
    background: var(--card-bg); padding: 10px; border-radius: 12px;
    margin-bottom: 10px; box-shadow: var(--shadow);
}
.cart-item img { width: 50px; height: 50px; border-radius: 8px; object-fit: cover; }
.cart-info { flex: 1; }
.cart-name { font-weight: 600; font-size: 14px; }
.cart-flavor { font-size: 12px; color: var(--hint); }
.cart-price { font-size: 13px; color: var(--hint); }
.cart-controls { display: flex; align-items: center; gap: 8px; }
.cart-btn {
    width: 24px; height: 24px; border-radius: 6px; background: rgba(128,128,128,0.2);
    border: none; font-weight: bold;
}

.cart-footer { padding: 20px; }
#comment {
    width: 100%; border: none; background: rgba(128,128,128,0.1);
    border-radius: 12px; padding: 10px; font-family: inherit;
    resize: none; height: 60px; box-sizing: border-box; margin-bottom: 10px;
}

.total-row { display: flex; justify-content: space-between; font-weight: 800; font-size: 18px; }
.empty-cart { text-align: center; color: var(--hint); margin-top: 50px; }

.profile-header {
    display: flex; align-items: center; gap: 15px;
    margin: 20px; padding: 20px; background: var(--card-bg);
    border-radius: 20px; box-shadow: var(--shadow);
}

.profile-stats {
    display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
    margin: 0 20px 20px 20px;
}

.stat-card {
    background: var(--card-bg); padding: 15px; border-radius: 16px;
    text-align: center; box-shadow: var(--shadow);
}

.stat-val { font-size: 20px; font-weight: 800; color: var(--accent); }
.stat-label { font-size: 12px; color: var(--hint); margin-top: 5px; }

.menu-list { margin: 0 20px; display: flex; flex-direction: column; gap: 10px; }
.menu-item {
    background: var(--card-bg); padding: 15px; border-radius: 12px;
    display: flex; align-items: center; gap: 15px; text-decoration: none; color: var(--text-color);
    box-shadow: var(--shadow); transition: 0.1s;
    border: none; width: 100%; font-family: inherit; font-size: 16px; text-align: left;
    box-sizing: border-box;
    cursor: pointer;
}
.menu-item:active { transform: scale(0.98); }
.icon { font-size: 20px; }
.arrow { margin-left: auto; color: var(--hint); font-weight: bold; }

.popup-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); z-index: 999;
    display: flex; align-items: flex-end;
    opacity: 0; pointer-events: none; transition: 0.3s;
}
.popup-overlay.active { opacity: 1; pointer-events: all; }

.popup-content {
    width: 100%; background: var(--bg-color);
    border-radius: 20px 20px 0 0;
    padding: 20px; box-sizing: border-box;
    transform: translateY(100%); transition: 0.3s;
    max-height: 80vh; overflow-y: auto;
    display: flex; flex-direction: column;
}
.popup-overlay.active .popup-content { transform: translateY(0); }

.popup-img { width: 100%; height: 200px; border-radius: 12px; object-fit: cover; margin-bottom: 15px; }
.popup-title { font-size: 22px; font-weight: 800; margin-bottom: 5px; }
.popup-price { font-size: 18px; color: var(--accent); font-weight: bold; margin-bottom: 15px; }
.popup-desc { color: var(--hint); font-size: 14px; margin-bottom: 20px; line-height: 1.4; }

.flavors-container { margin-bottom: 20px; }
.flavor-title { font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.flavor-list { display: flex; flex-wrap: wrap; gap: 8px; }

.popup-btn {
    width: 100%; padding: 15px;
    background-color: var(--accent);
    color: white; border: none; border-radius: 12px;
    font-size: 16px; font-weight: 800;
    margin-top: 10px;
}

.close-popup {
    position: absolute; top: 10px; right: 10px;
    background: rgba(0,0,0,0.1); width: 30px; height: 30px;
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    cursor: pointer;
}

.reviews-list { margin-top: 20px; }
.review-item { background: rgba(128,128,128,0.05); padding: 10px; border-radius: 8px; margin-bottom: 8px; }
.review-header { display: flex; justify-content: space-between; font-size: 12px; color: var(--hint); margin-bottom: 4px; }
.review-stars { color: #ffcc00; }
.review-text { font-size: 14px; }

.admin-panel { padding: 20px; }
.admin-form input, .admin-form textarea, .admin-form select {
    width: 100%; padding: 12px; margin-bottom: 10px;
    border: 1px solid rgba(128,128,128,0.2); border-radius: 10px;
    background: var(--bg-color); color: var(--text-color); box-sizing: border-box;
    font-family: inherit; font-size: 14px;
}
.admin-stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 20px; }

.order-item {
    background: var(--card-bg); padding: 15px; border-radius: 12px;
    margin-bottom: 10px; box-shadow: var(--shadow);
    display: flex; flex-direction: column; gap: 5px;
}
.order-header { display: flex; justify-content: space-between; font-weight: bold; font-size: 14px; }
.order-status { font-size: 12px; padding: 3px 8px; border-radius: 4px; }
.status-pending { background: #ff9500; color: white; }
.status-completed { background: #34c759; color: white; }
.status-cancelled { background: #ff3b30; color: white; }
.order-products { font-size: 13px; color: var(--hint); margin-top: 5px; }

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    box-sizing: border-box;
    background: var(--bg-color);
    position: relative;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 15px;
}

/* Spacer element logic replaces margin-top: auto */
#chat-spacer {
    flex-grow: 1;
    min-height: 0;
}

.chat-msg {
    padding: 10px 14px;
    border-radius: 16px;
    max-width: 75%;
    font-size: 14px;
    line-height: 1.4;
    position: relative;
    word-wrap: break-word;
    /* No default animation */
}

.chat-msg.new-msg {
    animation: msg-appear 0.2s ease-out forwards;
}

@keyframes msg-appear {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-msg.me {
    align-self: flex-end;
    background: var(--accent);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-msg.other {
    align-self: flex-start;
    background: var(--card-bg);
    border: 1px solid rgba(128,128,128,0.1);
    border-bottom-left-radius: 4px;
}

.chat-nick {
    font-size: 10px;
    opacity: 0.7;
    margin-bottom: 4px;
    font-weight: bold;
}

.chat-input-area {
    width: 100%;
    display: flex;
    align-items: center;
    padding: 10px;
    background: var(--bg-color);
    gap: 10px;
    box-sizing: border-box;
    border-top: 1px solid rgba(0,0,0,0.05);
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    flex-shrink: 0;
    z-index: 10;
}

.chat-input {
    flex: 1;
    padding: 12px 16px;
    border-radius: 24px;
    border: 1px solid rgba(128,128,128,0.2);
    background: var(--card-bg);
    color: var(--text-color);
    outline: none;
    font-size: 16px;
}

.chat-send-btn {
    width: 48px; height: 48px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    cursor: pointer;
    transition: transform 0.1s;
}

.chat-send-btn.pressed {
    transform: scale(0.8);
}

.user-row {
    display: flex; justify-content: space-between; padding: 10px;
    border-bottom: 1px solid rgba(0,0,0,0.05); font-size: 13px;
}
.edit-btn {
    background: var(--text-color); color: var(--bg-color);
    border: none; padding: 5px 10px; border-radius: 6px; font-size: 12px;
}

.admin-btn-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}
.admin-menu-item {
    background: var(--card-bg);
    padding: 15px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 15px;
    text-decoration: none;
    color: var(--text-color);
    box-shadow: var(--shadow);
    transition: 0.1s;
    border: none;
    width: 100%;
    font-family: inherit;
    font-size: 16px;
    text-align: left;
    box-sizing: border-box;
    cursor: pointer;
}
.admin-menu-item:active { transform: scale(0.98); }
