/* ── Reset & Base ─────────────────────────────── */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
    --bg: var(--tg-theme-bg-color, #1a1a2e);
    --bg2: var(--tg-theme-secondary-bg-color, #16213e);
    --text: var(--tg-theme-text-color, #e0e0e0);
    --hint: var(--tg-theme-hint-color, #999);
    --link: var(--tg-theme-link-color, #4ade80);
    --btn: var(--tg-theme-button-color, #22c55e);
    --btn-text: var(--tg-theme-button-text-color, #fff);
    --border: rgba(255,255,255,0.08);
    --card: rgba(255,255,255,0.04);
    --radius: 12px;
}
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding-bottom: 70px;
    -webkit-user-select: none;
    user-select: none;
}
a { color: var(--link); text-decoration: none; }

/* ── Search ──────────────────────────────────── */
.search-bar {
    display: flex; gap: 8px;
    padding: 12px 16px; margin-bottom: 0;
    position: sticky; top: 0; z-index: 100;
    background: var(--bg);
}
.search-bar input {
    flex: 1; padding: 10px 14px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text); font-size: 14px;
    outline: none;
}
.search-bar input::placeholder { color: var(--hint); }
.search-bar input:focus { border-color: var(--btn); }
.btn-reset {
    padding: 10px 14px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--hint); font-size: 13px;
    cursor: pointer;
}

/* ── Category list ───────────────────────────── */
.cat-list { padding: 0 16px; }
.cat-item {
    display: flex; align-items: center;
    justify-content: space-between;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: opacity 0.15s;
}
.cat-item:active { opacity: 0.6; }
.cat-left { display: flex; align-items: center; gap: 10px; }
.cat-arrow {
    font-size: 10px; color: var(--hint);
    transition: transform 0.2s;
    width: 14px;
}
.cat-arrow.open { transform: rotate(90deg); }
.cat-name { font-size: 15px; font-weight: 500; }
.cat-count {
    background: var(--btn);
    color: var(--btn-text);
    font-size: 12px; font-weight: 700;
    min-width: 28px; height: 22px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 11px; padding: 0 8px;
}
.cat-children {
    padding-left: 24px;
    display: none;
}
.cat-children.open { display: block; }

/* ── Product list ────────────────────────────── */
.product-list { padding: 0 16px; }
.product-item {
    display: flex; justify-content: space-between;
    align-items: center;
    padding: 14px 12px;
    margin-bottom: 8px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s;
}
.product-item:active { background: rgba(255,255,255,0.08); }
.p-info { flex: 1; }
.p-name { font-size: 14px; font-weight: 600; }
.p-article { font-size: 12px; color: var(--hint); margin-top: 2px; }
.p-price {
    font-size: 15px; font-weight: 700;
    color: var(--btn);
    white-space: nowrap; margin-left: 12px;
}

/* ── Product detail ──────────────────────────── */
.product-detail { padding: 0 16px; }
.pd-image-wrap {
    width: 100%; aspect-ratio: 4/3;
    background: var(--bg2);
    border-radius: var(--radius);
    overflow: hidden; margin-bottom: 16px;
    display: flex; align-items: center; justify-content: center;
}
.pd-image-wrap img {
    max-width: 100%; max-height: 100%;
    object-fit: contain;
}
.pd-no-image { color: var(--hint); font-size: 48px; }
.pd-name { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.pd-article { color: var(--hint); font-size: 13px; margin-bottom: 12px; }
.pd-info-row {
    display: flex; justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}
.pd-info-label { color: var(--hint); }
.pd-info-value { font-weight: 600; }
.pd-price-row { margin-top: 16px; }
.pd-price {
    font-size: 24px; font-weight: 700;
    color: var(--btn);
}
.pd-per { font-size: 14px; color: var(--hint); }

/* ── Quantity control ────────────────────────── */
.qty-control {
    display: flex; align-items: center;
    justify-content: center; gap: 0;
    margin: 20px 0;
    background: var(--bg2);
    border-radius: var(--radius);
    overflow: hidden;
}
.qty-btn {
    width: 56px; height: 48px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; font-weight: 700;
    background: none; border: none;
    color: var(--btn); cursor: pointer;
}
.qty-btn:active { background: rgba(255,255,255,0.05); }
.qty-value {
    width: 80px; text-align: center;
    font-size: 22px; font-weight: 700;
    color: var(--text);
    background: none; border: none;
}

/* ── Buttons ─────────────────────────────────── */
.btn-primary {
    display: block; width: 100%;
    padding: 14px; border: none;
    border-radius: var(--radius);
    background: var(--btn);
    color: var(--btn-text);
    font-size: 16px; font-weight: 700;
    cursor: pointer;
    transition: opacity 0.15s;
}
.btn-primary:active { opacity: 0.8; }
.btn-primary:disabled { opacity: 0.4; cursor: default; }
.btn-secondary {
    display: block; width: 100%;
    padding: 12px; border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg2);
    color: var(--text);
    font-size: 14px; font-weight: 600;
    cursor: pointer; margin-top: 8px;
}

/* ── Back button ─────────────────────────────── */
.back-row {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 0; margin-bottom: 8px;
    cursor: pointer; color: var(--hint); font-size: 14px;
}
.back-row:active { color: var(--text); }

/* ── Breadcrumbs ─────────────────────────────── */
.breadcrumbs {
    padding: 8px 16px;
    font-size: 12px; color: var(--hint);
    display: flex; flex-wrap: wrap; gap: 4px;
}
.breadcrumbs span { cursor: pointer; }
.breadcrumbs span:hover { color: var(--link); }
.breadcrumbs .bc-sep { cursor: default; }

/* ── Cart badge ──────────────────────────────── */
.cart-badge {
    position: absolute; top: -5px; right: -5px;
    background: #ef4444; color: #fff;
    font-size: 10px; font-weight: 700;
    min-width: 16px; height: 16px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    padding: 0 4px;
}

/* ── Bottom nav ──────────────────────────────── */
.bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--bg);
    border-top: 1px solid var(--border);
    display: flex; height: 60px; z-index: 100;
    padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-item {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 3px; cursor: pointer;
    color: var(--hint); font-size: 11px;
    position: relative;
    transition: color 0.15s;
}
.nav-item.active { color: var(--btn); }
.nav-icon { font-size: 22px; }

/* ── Orders ──────────────────────────────────── */
.order-list { padding: 0 16px; }
.order-item {
    padding: 14px 12px;
    margin-bottom: 8px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
}
.order-item:active { background: rgba(255,255,255,0.08); }
.o-header { display: flex; justify-content: space-between; margin-bottom: 6px; }
.o-name { font-weight: 600; font-size: 14px; }
.o-date { font-size: 12px; color: var(--hint); }
.o-footer { display: flex; justify-content: space-between; }
.o-status { font-size: 13px; }
.o-sum { font-weight: 700; color: var(--btn); font-size: 14px; }

/* ── Cart ────────────────────────────────────── */
.cart-list { padding: 0 16px; }
.cart-item {
    display: flex; align-items: center;
    padding: 12px;
    margin-bottom: 8px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.ci-info { flex: 1; }
.ci-name { font-size: 14px; font-weight: 600; }
.ci-price { font-size: 12px; color: var(--hint); }
.ci-qty {
    display: flex; align-items: center; gap: 0;
    background: var(--bg2); border-radius: 8px;
}
.ci-qty-btn {
    width: 36px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    border: none; background: none;
    color: var(--btn); font-size: 16px; font-weight: 700;
    cursor: pointer;
}
.ci-qty-val {
    width: 36px; text-align: center;
    font-size: 15px; font-weight: 700;
    color: var(--text);
}
.ci-del {
    margin-left: 10px; border: none; background: none;
    color: #ef4444; font-size: 18px; cursor: pointer;
    padding: 4px 8px;
}
.cart-total {
    padding: 16px;
    font-size: 18px; font-weight: 700;
    text-align: right;
}
.cart-total span { color: var(--btn); }
.cart-actions { padding: 0 16px 16px; }

/* ── Empty state ─────────────────────────────── */
.empty {
    text-align: center; padding: 60px 20px;
    color: var(--hint);
}
.empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-text { font-size: 15px; }

/* ── Loading ─────────────────────────────────── */
.loading {
    text-align: center; padding: 40px;
    color: var(--hint); font-size: 14px;
}
.spinner {
    display: inline-block;
    width: 24px; height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--btn);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Load more button ────────────────────────── */
.load-more {
    display: block; width: calc(100% - 32px);
    margin: 8px 16px 16px; padding: 12px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--link); font-size: 14px;
    font-weight: 600; cursor: pointer;
    text-align: center;
}

/* ── Notification ────────────────────────────── */
.toast {
    position: fixed; top: 16px; left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: var(--btn);
    color: var(--btn-text);
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 14px; font-weight: 600;
    z-index: 1000;
    transition: transform 0.3s ease;
    pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ── Login page ─────────────────────────────────── */
.login-page {
    padding: 40px 24px; text-align: center;
}
.login-icon { font-size: 64px; margin-bottom: 16px; }
.login-title {
    font-size: 20px; font-weight: 700;
    margin-bottom: 8px;
}
.login-subtitle {
    color: var(--hint); font-size: 14px;
    margin-bottom: 24px;
}
.login-form {
    display: flex; flex-direction: column;
    gap: 12px; max-width: 320px; margin: 0 auto;
}
.login-input {
    padding: 14px 16px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text); font-size: 16px;
    outline: none;
}
.login-input::placeholder { color: var(--hint); }
.login-input:focus { border-color: var(--btn); }
select.login-input {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23999' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
    padding-right: 40px;
}
.login-hint {
    color: var(--hint); font-size: 12px;
    margin-top: 16px;
}

/* ── Account page ───────────────────────────────── */
.account-page { padding: 32px 16px; text-align: center; }
.account-avatar { font-size: 64px; margin-bottom: 12px; }
.account-name { font-size: 20px; font-weight: 700; }
.account-phone {
    color: var(--hint); font-size: 14px;
    margin-top: 4px;
}
.account-menu {
    margin-top: 24px;
    display: flex; flex-direction: column; gap: 8px;
}
.account-menu-item {
    padding: 16px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 15px; font-weight: 600;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s;
}
.account-menu-item:active { background: rgba(255,255,255,0.08); }

/* ── Admin page ─────────────────────────────────── */
.admin-page { padding: 24px 16px; }
.admin-title {
    font-size: 20px; font-weight: 700;
    margin-bottom: 20px; text-align: center;
}
.admin-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.admin-card {
    padding: 20px 12px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-align: center;
    cursor: pointer;
    transition: background 0.15s;
}
.admin-card:active { background: rgba(255,255,255,0.08); }
.admin-card-icon { font-size: 32px; margin-bottom: 8px; }
.admin-card-label { font-size: 13px; font-weight: 600; }

/* ── Admin actions ──────────────────────────────── */
.admin-actions {
    display: flex; flex-direction: column;
    gap: 8px; margin-top: 16px;
}
.btn-danger {
    display: block; width: 100%;
    padding: 14px; border: none;
    border-radius: var(--radius);
    background: #ef4444;
    color: #fff;
    font-size: 16px; font-weight: 700;
    cursor: pointer;
}
.btn-danger:active { opacity: 0.8; }

/* ── Nav label ──────────────────────────────────── */
.nav-label { font-size: 11px; }

/* ── Small button ──────────────────────────────── */
.btn-sm {
    padding: 8px 14px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--link);
    font-size: 12px; font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}
.btn-sm:active { opacity: 0.7; }

/* ── Category admin button (⋯) ─────────────────── */
.cat-admin-btn {
    font-size: 18px;
    color: var(--hint);
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}
.cat-admin-btn:active { color: var(--link); }

/* ── Admin badge ───────────────────────────────── */
.admin-badge {
    position: absolute;
    top: -5px; right: -8px;
    background: #ef4444; color: #fff;
    font-size: 10px; font-weight: 700;
    min-width: 16px; height: 16px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    padding: 0 4px;
}

/* ── Admin grid responsive ─────────────────────── */
@media (min-width: 400px) {
    .admin-grid {
        grid-template-columns: 1fr 1fr 1fr;
    }
}
