/* ============================================================
 ТЕМА
 Переменные заполняются в рантайме из Telegram.WebApp.themeParams,
 а дефолтные значения ниже — это официальные light/dark палитры
 из примеров Telegram Bot API (на случай запуска вне Telegram
 или если какого-то параметра нет).
 ============================================================ */
:root{
--tg-bg:#ffffff;
--tg-secondary-bg:#f1f1f1;
--tg-section-bg:#ffffff;
--tg-text:#000000;
--tg-hint:#999999;
--tg-link:#2481cc;
--tg-button:#2481cc;
--tg-button-text:#ffffff;
--tg-destructive:#e53935;
--tg-divider: rgba(0,0,0,0.09);
--tg-header-bg:#f8f8f8;

--radius-card:12px;
--radius-btn:10px;
--font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

[data-scheme="dark"]{
--tg-bg:#212121;
--tg-secondary-bg:#181818;
--tg-section-bg:#2c2c2c;
--tg-text:#ffffff;
--tg-hint:#aaaaaa;
--tg-link:#8774e1;
--tg-button:#8774e1;
--tg-button-text:#ffffff;
--tg-destructive:#f2726a;
--tg-divider: rgba(255,255,255,0.09);
--tg-header-bg:#1e1e1e;
}

*{ box-sizing:border-box; -webkit-tap-highlight-color:transparent; }
html,body{ margin:0; padding:0; height:100%; }
body{
background:var(--tg-bg);
color:var(--tg-text);
font-family:var(--font);
transition: background .2s ease, color .2s ease;
}
button{ font-family:inherit; cursor:pointer; border:none; background:none; color:inherit; }
img{ display:block; }
h1,h2,h3{ margin:0; }

#app{
max-width:480px;
margin:0 auto;
min-height:100vh;
display:flex;
flex-direction:column;
padding-bottom:78px;
}

/* ---------- Header (как нав-бар Telegram) ---------- */
.topbar{
background:var(--tg-header-bg);
border-bottom:1px solid var(--tg-divider);
padding:14px 16px;
display:flex;
align-items:center;
justify-content:space-between;
position:sticky; top:0; z-index:10;
}
.topbar h1{ font-size:17px; font-weight:600; }
.topbar .sub{ font-size:12.5px; color:var(--tg-hint); margin-top:1px; }
.theme-toggle{
width:36px; height:36px; border-radius:50%;
background:var(--tg-secondary-bg);
display:flex; align-items:center; justify-content:center;
font-size:17px;
}

/* ---------- Category tabs (сегмент-контрол в стиле TG) ---------- */
.tabs{
display:flex; gap:6px; padding:10px 16px;
overflow-x:auto; scrollbar-width:none;
}
.tabs::-webkit-scrollbar{ display:none; }
.tab{
flex:0 0 auto;
padding:7px 14px;
background:var(--tg-secondary-bg);
border-radius:999px;
font-size:13.5px;
font-weight:500;
color:var(--tg-text);
}
.tab.active{
background:var(--tg-button);
color:var(--tg-button-text);
}

main{ flex:1; padding:0 16px; }
.screen{ display:none; }
.screen.active{ display:block; animation: fade .15s ease; }
@keyframes fade{ from{opacity:0;} to{opacity:1;} }

.list-title{
font-size:13px; color:var(--tg-hint); text-transform:uppercase;
letter-spacing:.02em; margin:16px 4px 8px; font-weight:600;
}

/* ---------- Product grid ---------- */
.grid{ display:grid; grid-template-columns:1fr 1fr; gap:10px; padding-top:4px;}
.card{
background:var(--tg-section-bg);
border-radius:var(--radius-card);
overflow:hidden;
display:flex; flex-direction:column;
border:1px solid var(--tg-divider);
}
.card .thumb{
height:96px; background:var(--tg-secondary-bg);
display:flex; align-items:center; justify-content:center;
font-size:34px; position:relative;
}
.card .fav-btn{
position:absolute; top:8px; right:8px;
width:28px; height:28px; border-radius:50%;
background:rgba(0,0,0,0.35);
color:#fff;
display:flex; align-items:center; justify-content:center; font-size:14px;
}
.card .fav-btn.active{ color:var(--tg-destructive); background:rgba(255,255,255,0.85); }
.card .body{ padding:9px 10px 11px; display:flex; flex-direction:column; gap:5px; flex:1; }
.card .cat{ font-size:10.5px; color:var(--tg-hint); }
.card .name{ font-size:13.5px; font-weight:500; line-height:1.28; min-height:34px; }
.price-row{ display:flex; align-items:center; justify-content:space-between; margin-top:auto; }
.price{ font-size:14px; font-weight:600; }
.add-btn{
width:28px; height:28px; border-radius:50%;
background:var(--tg-button); color:var(--tg-button-text);
font-size:16px; font-weight:600;
display:flex; align-items:center; justify-content:center;
}
.add-btn.in-cart{ font-size:12.5px; }

.empty{ text-align:center; padding:56px 20px; color:var(--tg-hint); }
.empty .big{ font-size:38px; margin-bottom:10px; }
.empty .cta{
margin-top:14px; display:inline-block; background:var(--tg-button); color:var(--tg-button-text);
padding:9px 18px; border-radius:var(--radius-btn); font-size:13.5px; font-weight:600;
}

/* ---------- Списки (корзина / заказы) — стиль grouped table view ---------- */
.tg-section{
background:var(--tg-section-bg);
border-radius:var(--radius-card);
overflow:hidden;
border:1px solid var(--tg-divider);
margin-bottom:14px;
}
.tg-row{
display:flex; gap:12px; align-items:center;
padding:11px 12px;
border-bottom:1px solid var(--tg-divider);
}
.tg-row:last-child{ border-bottom:none; }
.tg-row .thumb-sm{
width:46px; height:46px; border-radius:9px; background:var(--tg-secondary-bg);
display:flex; align-items:center; justify-content:center; font-size:21px; flex:0 0 auto;
}
.tg-row .info{ flex:1; min-width:0; }
.tg-row .name{ font-size:14px; font-weight:500; }
.tg-row .unit{ font-size:12px; color:var(--tg-hint); margin-top:2px; }
.qty-ctrl{ display:flex; align-items:center; gap:8px; }
.qty-ctrl button{
width:25px; height:25px; border-radius:50%; background:var(--tg-secondary-bg);
font-weight:700; font-size:14px; display:flex; align-items:center; justify-content:center;
}
.qty-ctrl .qty{ font-size:13px; font-weight:600; min-width:16px; text-align:center; }
.remove-x{ color:var(--tg-hint); font-size:16px; padding:4px; }

.cart-summary{ position:sticky; bottom:0; background:var(--tg-bg); padding:12px 0 4px; }
.summary-row{ display:flex; justify-content:space-between; font-size:14px; margin-bottom:4px; color:var(--tg-hint); }
.summary-row.total{ font-size:16px; font-weight:700; color:var(--tg-text); margin:6px 0 12px; }
.btn-primary{
width:100%; background:var(--tg-button); color:var(--tg-button-text);
padding:13px; border-radius:var(--radius-btn); font-size:15px; font-weight:600;
}
.btn-primary:disabled{ opacity:.5; }

/* ---------- Профиль ---------- */
.profile-head{ display:flex; align-items:center; gap:14px; padding:16px 4px 18px; }
.profile-head img{ width:60px; height:60px; border-radius:50%; object-fit:cover; background:var(--tg-secondary-bg); }
.profile-head h2{ font-size:17px; font-weight:600; }
.profile-head .username{ font-size:13px; color:var(--tg-hint); margin-top:2px; }

.profile-tabs{ display:flex; gap:6px; margin-bottom:14px; }
.ptab{
flex:1; text-align:center; padding:8px; border-radius:var(--radius-btn); font-size:12.5px; font-weight:600;
background:var(--tg-secondary-bg); color:var(--tg-hint);
}
.ptab.active{ background:var(--tg-button); color:var(--tg-button-text); }

.order-row{ padding:11px 12px; border-bottom:1px solid var(--tg-divider); }
.order-row:last-child{ border-bottom:none; }
.order-row .top{ display:flex; justify-content:space-between; font-size:12px; color:var(--tg-hint); margin-bottom:5px; }
.status{ font-size:10.5px; font-weight:700; padding:2px 8px; border-radius:999px; background:var(--tg-secondary-bg); }
.status.done{ color:#3ba55c; }
.status.progress{ color:var(--tg-link); }
.order-row .items{ font-size:13.5px; margin-bottom:5px; }
.order-row .total{ font-size:13.5px; font-weight:700; text-align:right; }

/* ---------- Theme switcher (сегмент в профиле) ---------- */
.theme-row{
display:flex; align-items:center; justify-content:space-between;
padding:12px; background:var(--tg-section-bg); border:1px solid var(--tg-divider);
border-radius:var(--radius-card); margin-bottom:14px;
}
.theme-row .label{ font-size:14px; font-weight:500; }
.theme-row .label .hint{ display:block; font-size:11.5px; color:var(--tg-hint); font-weight:400; margin-top:1px; }
.seg{ display:flex; background:var(--tg-secondary-bg); border-radius:8px; padding:2px; }
.seg button{ padding:6px 10px; border-radius:6px; font-size:12px; font-weight:600; color:var(--tg-hint); }
.seg button.active{ background:var(--tg-section-bg); color:var(--tg-text); box-shadow:0 1px 2px rgba(0,0,0,0.15); }

/* ---------- Bottom nav ---------- */
.bottom-nav{
position:fixed; left:0; right:0; bottom:0;
max-width:480px; margin:0 auto;
background:var(--tg-header-bg);
border-top:1px solid var(--tg-divider);
display:flex;
padding:7px 6px calc(7px + env(safe-area-inset-bottom));
}
.nav-btn{
flex:1; display:flex; flex-direction:column; align-items:center; gap:2px;
padding:6px 0; border-radius:10px; font-size:10.5px; color:var(--tg-hint); font-weight:500;
position:relative;
}
.nav-btn .ic{ font-size:19px; }
.nav-btn.active{ color:var(--tg-link); }
.badge{
position:absolute; top:0; right:22%;
background:var(--tg-destructive); color:#fff; font-size:9.5px; font-weight:700;
min-width:15px; height:15px; border-radius:50%;
display:flex; align-items:center; justify-content:center; padding:0 3px;
}

/* ---------- Modal (нижний шит, как в TG) ---------- */
.modal-backdrop{
position:fixed; inset:0; background:rgba(0,0,0,0.42);
display:flex; align-items:flex-end; justify-content:center; z-index:50;
}
.modal-backdrop.hidden{ display:none; }
.modal-sheet{
width:100%; max-width:480px; background:var(--tg-bg);
border-radius:14px 14px 0 0; padding:10px 18px 22px;
max-height:86vh; overflow-y:auto;
animation: slideup .2s ease;
}
@keyframes slideup{ from{ transform:translateY(24px); opacity:0;} to{ transform:translateY(0); opacity:1;} }
.sheet-handle{ width:36px; height:4px; background:var(--tg-divider); border-radius:99px; margin:4px auto 14px; }
.modal-sheet .thumb-lg{
height:140px; border-radius:12px; background:var(--tg-secondary-bg);
display:flex; align-items:center; justify-content:center; font-size:58px; margin-bottom:14px;
}
.modal-sheet .cat{ font-size:12px; color:var(--tg-hint); }
.modal-sheet h2{ font-size:19px; font-weight:600; margin:4px 0 8px; }
.modal-sheet .desc{ font-size:13.5px; color:var(--tg-hint); line-height:1.5; margin-bottom:16px; }
.modal-qty{ display:flex; align-items:center; justify-content:space-between; margin-bottom:16px; }
.modal-qty .price{ font-size:17px; font-weight:700; }

.toast{
position:fixed; left:50%; bottom:94px; transform:translateX(-50%) translateY(10px);
background:var(--tg-section-bg); color:var(--tg-text); padding:10px 18px; border-radius:999px;
font-size:12.5px; font-weight:600; opacity:0; transition:.2s ease; pointer-events:none; z-index:60;
white-space:nowrap; border:1px solid var(--tg-divider);
}
.toast.show{ opacity:1; transform:translateX(-50%) translateY(0); }