:root {
    --bg: var(--tg-theme-bg-color, #ffffff);
    --text: var(--tg-theme-text-color, #1a1a1a);
    --hint: var(--tg-theme-hint-color, #707579);
    --link: var(--tg-theme-link-color, #2481cc);
    --button: var(--tg-theme-button-color, #2481cc);
    --button-text: var(--tg-theme-button-text-color, #ffffff);
    --secondary-bg: var(--tg-theme-secondary-bg-color, #f4f4f5);
    --border: rgba(127, 127, 127, 0.2);
    --danger: #e53935;
    --nav-h: 62px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: 16px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior: contain;
}

/* =========== BOTTOM NAV =========== */

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
    display: flex;
    background: var(--secondary-bg);
    border-top: 1px solid var(--border);
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border: none;
    background: transparent;
    color: var(--hint);
    font-size: 11px;
    cursor: pointer;
    padding: 6px 4px;
    position: relative;
    transition: color 0.15s;
}

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

.nav-icon {
    font-size: 20px;
    line-height: 1;
}

.fav-badge {
    position: absolute;
    top: 6px;
    right: calc(50% - 18px);
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: var(--danger);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
}

/* =========== VIEWS =========== */

.view[hidden] {
    display: none !important;
}

.view {
    min-height: calc(100vh - var(--nav-h));
}

.container {
    max-width: 560px;
    margin: 0 auto;
    padding: 16px 16px calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 80px);
}

.container--cards {
    padding: 16px 12px calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 16px);
    max-width: 100%;
    overflow-x: clip;
}

#view-deals .container--cards {
    overflow-x: clip;
}

/* =========== HEADER =========== */

.header {
    margin-bottom: 16px;
}

.header--compact {
    margin-bottom: 10px;
}

.header h1 {
    font-size: 22px;
    margin: 0 0 4px;
    font-weight: 600;
}

.view-status {
    margin: 0 0 8px;
    color: var(--hint);
    font-size: 13px;
}

.load-status {
    margin: 8px 0 0;
    font-size: 13px;
    padding: 6px 10px;
    border-radius: 8px;
}

.load-status--ok {
    color: #2e7d32;
    background: rgba(46, 125, 50, 0.12);
}

.load-status--warn {
    color: var(--danger);
    background: rgba(229, 57, 53, 0.1);
}

/* =========== FILTERS VIEW =========== */

.card {
    background: var(--secondary-bg);
    border-radius: 14px;
    padding: 14px 16px;
    margin-bottom: 12px;
}

.label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    margin: 0 0 10px;
    color: var(--text);
}

.field-hint {
    margin: -6px 0 8px;
    font-size: 12px;
    line-height: 1.35;
    color: var(--hint);
}

.select {
    width: 100%;
    padding: 12px;
    font-size: 16px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='gray' d='M6 8L0 0h12z'/></svg>");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 10px;
    padding-right: 36px;
}

.chips {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.chips--wide {
    grid-template-columns: 1fr;
}

@media (min-width: 480px) {
    .chips--wide {
        grid-template-columns: 1fr 1fr;
    }
}

.chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
    user-select: none;
    font-size: 15px;
}

.chip input {
    accent-color: var(--button);
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.chip:active {
    transform: scale(0.98);
}

.chip--checked {
    background: color-mix(in srgb, var(--button) 14%, transparent);
    border-color: var(--button);
}

.primary-btn {
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: calc(var(--nav-h) + 12px);
    max-width: 528px;
    margin: 0 auto;
    display: block;
    width: calc(100% - 32px);
    padding: 14px;
    font-size: 16px;
    font-weight: 600;
    color: var(--button-text);
    background: var(--button);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

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

.error {
    margin: 0 0 12px;
    color: var(--danger);
    font-size: 14px;
    text-align: center;
}

.hint {
    margin: 0 0 10px;
    font-size: 13px;
    color: var(--hint);
    font-weight: 400;
}

.tags-editor {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    min-height: 48px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg);
    cursor: text;
}

.tags-editor:focus-within {
    border-color: var(--button);
    outline: none;
}

.tags-list {
    display: contents;
}

.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 100%;
    padding: 6px 10px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--button) 16%, transparent);
    border: 1px solid color-mix(in srgb, var(--button) 35%, transparent);
    font-size: 14px;
    line-height: 1.2;
}

.tag-chip__text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 220px;
}

.tag-chip__remove {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--hint);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
}

.tag-chip__remove:active {
    background: rgba(0, 0, 0, 0.08);
}

.tags-input {
    flex: 1 1 120px;
    min-width: 100px;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text);
    font-size: 16px;
    padding: 4px 0;
}

.tags-input:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* =========== PRODUCT CARDS =========== */

.cards-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 100%;
}

.product-card {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    background: var(--secondary-bg);
    border-radius: 14px;
    padding: 12px;
    position: relative;
    cursor: pointer;
    transition: background 0.12s;
    -webkit-tap-highlight-color: transparent;
    max-width: 100%;
    overflow: hidden;
}

.product-card:active {
    background: color-mix(in srgb, var(--button) 10%, var(--secondary-bg));
}

.card-img {
    width: 72px;
    height: 72px;
    object-fit: contain;
    border-radius: 8px;
    background: var(--bg);
    flex-shrink: 0;
}

.card-img--missing {
    background: color-mix(in srgb, var(--hint) 12%, var(--secondary-bg));
    object-fit: none;
}

.card-body {
    flex: 1;
    min-width: 0;
    padding-right: 36px;
}

.card-shop {
    font-size: 12px;
    color: var(--hint);
    font-weight: 500;
    margin-bottom: 3px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.card-name {
    font-size: 14px;
    font-weight: 500;
    line-height: 1.35;
    margin-bottom: 6px;
    word-break: break-word;
}

.card-prices {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}

.card-price-new {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}

.card-price-old {
    font-size: 13px;
    color: var(--hint);
    text-decoration: line-through;
}

.card-badge {
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    background: #e53935;
    border-radius: 6px;
    padding: 2px 7px;
}

.card-inactive {
    margin-top: 6px;
    font-size: 11px;
    color: var(--hint);
    font-style: italic;
}

.fav-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    font-size: 20px;
    line-height: 32px;
    text-align: center;
    cursor: pointer;
    border-radius: 50%;
    opacity: 0.35;
    padding: 0;
    transition: opacity 0.15s, transform 0.15s;
}

.fav-btn--active {
    opacity: 1;
}

.fav-btn:active {
    transform: scale(0.85);
}

.fav-btn:disabled {
    cursor: default;
}

/* =========== SEARCH BAR =========== */

.search-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
    align-items: center;
    max-width: 100%;
    min-width: 0;
}

.search-input {
    flex: 1 1 auto;
    min-width: 0;
    width: 0;
    padding: 11px 14px;
    font-size: 16px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--secondary-bg);
    color: var(--text);
    outline: none;
}

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

.tags-btn,
.toggle-btn {
    padding: 10px 12px;
    font-size: 13px;
    font-weight: 500;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--secondary-bg);
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
}

.search-bar--deals {
    position: sticky;
    top: 0;
    z-index: 2;
    padding-bottom: 4px;
    background: var(--bg);
}

.tags-btn--active,
.toggle-btn--active {
    background: color-mix(in srgb, var(--button) 14%, transparent);
    border-color: var(--button);
    color: var(--button);
}

/* =========== EMPTY STATE =========== */

.empty-state {
    text-align: center;
    color: var(--hint);
    font-size: 15px;
    padding: 40px 16px;
    margin: 0;
}

.sentinel {
    height: 1px;
}

/* =========== FREEMIUM LOCKED STATE =========== */

.chip--locked {
    opacity: 0.45;
    cursor: not-allowed;
    position: relative;
}

.chip--locked::after {
    content: "👑";
    font-size: 11px;
    position: absolute;
    top: 4px;
    right: 4px;
}

.deals-filter-hint {
    margin: 0 0 6px;
    font-size: 13px;
    color: var(--hint);
    line-height: 1.35;
}

.deals-plan-hint {
    margin: 0 0 6px;
    font-size: 12px;
    color: var(--hint);
    line-height: 1.35;
}

/* =========== DISCOUNT SLIDER =========== */

.discount-slider {
    display: flex;
    gap: 6px;
    flex-wrap: nowrap;
    margin-top: 10px;
}

.disc-seg {
    flex: 1;
    padding: 8px 0;
    font-size: 14px;
    font-weight: 500;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    background: var(--secondary-bg);
    color: var(--hint);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    text-align: center;
}

.disc-seg--active {
    background: var(--button);
    color: var(--button-text);
    border-color: var(--button);
}

/* =========== NOTIFY CHECKBOXES =========== */

.notify-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 14px;
}

.check-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 15px;
    cursor: pointer;
    user-select: none;
}

.check-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--button);
    flex-shrink: 0;
}

/* =========== SHOPPING LIST (Кошик) =========== */

.cart-input-row {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
    align-items: center;
}

.cart-text-input {
    flex: 1;
    height: 42px;
    border: 1.5px solid var(--border);
    border-radius: 12px;
    padding: 0 14px;
    font-size: 15px;
    background: var(--secondary-bg);
    color: var(--text);
    outline: none;
}

.cart-text-input:focus {
    border-color: var(--button);
}

.cart-add-btn {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    border: none;
    background: var(--button);
    color: var(--button-text);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cards-list--shopping {
    margin-bottom: 10px;
}

.shopping-item {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--secondary-bg);
    border-radius: 14px;
    padding: 12px 44px 12px 14px;
    min-height: 48px;
    position: relative;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.12s;
}

.shopping-item:active {
    background: color-mix(in srgb, var(--button) 10%, var(--secondary-bg));
}

.shopping-item__text {
    flex: 1;
    min-width: 0;
    font-size: 15px;
    font-weight: 500;
    line-height: 1.35;
    word-break: break-word;
}

.shopping-item .fav-btn {
    position: absolute;
    top: 50%;
    right: 10px;
    margin-top: -16px;
}

.shopping-item .fav-btn:active {
    transform: scale(0.85);
}
