:root {
    --bg: var(--tg-theme-bg-color, #f4f5f7);
    --card: var(--tg-theme-secondary-bg-color, #ffffff);
    --text: var(--tg-theme-text-color, #1c1c1e);
    --hint: var(--tg-theme-hint-color, #8a8a8e);
    --accent: var(--tg-theme-button-color, #2ea6ff);
    --accent-text: var(--tg-theme-button-text-color, #ffffff);
    --border: rgba(0,0,0,.08);
    --danger: #ff3b30;
    --ok: #34c759;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    padding-bottom: 76px;
    font-size: 16px;
}

.app-header {
    position: sticky; top: 0; z-index: 20;
    background: var(--bg);
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}
.app-header h1 { margin: 0; font-size: 20px; font-weight: 700; }

.app-main { padding: 14px 16px; }

/* Bottom nav */
.bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
    display: flex; background: var(--card);
    border-top: 1px solid var(--border);
    padding: 6px 0 10px;
}
.nav-item {
    flex: 1; text-align: center; text-decoration: none;
    color: var(--hint); font-size: 11px;
    display: flex; flex-direction: column; gap: 2px; align-items: center;
}
.nav-item .ico { font-size: 22px; }
.nav-item.active { color: var(--accent); font-weight: 600; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    background: var(--accent); color: var(--accent-text);
    border: none; border-radius: 12px; padding: 14px 18px;
    font-size: 16px; font-weight: 600; cursor: pointer; width: 100%;
}
.btn.secondary { background: var(--card); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); }
.btn:disabled { opacity: .5; }
.btn-row { display: flex; gap: 10px; }

/* Inputs */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--hint); margin-bottom: 6px; }
.input, textarea {
    width: 100%; padding: 13px 14px; border-radius: 12px;
    border: 1px solid var(--border); background: var(--card); color: var(--text);
    font-size: 16px; font-family: inherit;
}
textarea { resize: vertical; min-height: 70px; }

.search-bar { display: flex; gap: 8px; margin-bottom: 14px; }
.search-bar .input { flex: 1; }

/* Product grid / cards */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.card {
    background: var(--card); border-radius: 16px; overflow: hidden;
    border: 1px solid var(--border); display: flex; flex-direction: column;
}
.card .thumb {
    width: 100%; aspect-ratio: 1/1; object-fit: cover; background: #e9e9ec;
    display: flex; align-items: center; justify-content: center; font-size: 40px; color: var(--hint);
}
.card .body { padding: 10px 12px; }
.card .name { font-weight: 600; font-size: 15px; line-height: 1.25; }
.card .price { color: var(--accent); font-weight: 700; margin-top: 4px; }
.card .tags { margin-top: 6px; font-size: 11px; color: var(--hint); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.card .score { font-size: 11px; color: var(--ok); margin-top: 4px; }

.empty { text-align: center; color: var(--hint); padding: 40px 16px; }
.empty .big { font-size: 48px; }

/* Preview image */
.preview-wrap { position: relative; border-radius: 16px; overflow: hidden; background: #000; margin-bottom: 14px; }
.preview-wrap img, .preview-wrap video { width: 100%; display: block; }

/* Spinner */
.spinner {
    width: 22px; height: 22px; border: 3px solid rgba(255,255,255,.4);
    border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite;
}
.spinner.dark { border-color: rgba(0,0,0,.2); border-top-color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }

.center { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 24px; color: var(--hint); }

/* Camera */
.camera-stage { position: relative; width: 100%; background: #000; border-radius: 16px; overflow: hidden; }
.camera-stage video { width: 100%; display: block; }
.camera-stage canvas.overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.camera-status {
    text-align: center; padding: 10px; color: var(--hint); font-size: 14px;
}
.detection-list { margin-top: 14px; }
.detection-list .card-row {
    display: flex; align-items: center; gap: 12px; background: var(--card);
    border: 1px solid var(--border); border-radius: 14px; padding: 10px; margin-bottom: 10px;
}
.detection-list .card-row img { width: 54px; height: 54px; border-radius: 10px; object-fit: cover; }
.detection-list .card-row .price { color: var(--accent); font-weight: 700; }

.toast {
    position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
    background: rgba(0,0,0,.85); color: #fff; padding: 10px 16px; border-radius: 20px;
    font-size: 14px; z-index: 100; opacity: 0; transition: opacity .3s; pointer-events: none; max-width: 90%;
}
.toast.show { opacity: 1; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { background: rgba(46,166,255,.12); color: var(--accent); font-size: 12px; padding: 4px 10px; border-radius: 20px; }

.hidden { display: none !important; }
.muted { color: var(--hint); font-size: 13px; }
