/*
 * Вся палитра — переменные темы Telegram: приложение обязано выглядеть родным
 * и в светлой, и в тёмной теме, а какая из них сейчас, решает клиент. Значения
 * после := это запасные варианты на случай старого клиента, который переменных
 * не проставил; своих цветов у мини-аппа ровно один — цвет уровня гостя.
 */
:root {
    --bg: var(--tg-theme-bg-color, #ffffff);
    --section-bg: var(--tg-theme-secondary-bg-color, #f1f1f1);
    --text: var(--tg-theme-text-color, #000000);
    --hint: var(--tg-theme-hint-color, #707579);
    --accent: var(--tg-theme-button-color, #2481cc);
    --accent-text: var(--tg-theme-button-text-color, #ffffff);
    --radius: 14px;
}

* { box-sizing: border-box; }

[x-cloak] { display: none !important; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    /* safe-area: у iPhone снизу полоса жестов, и панель табов не должна под неё лезть. */
    padding-bottom: calc(64px + env(safe-area-inset-bottom));
    min-height: 100vh;
}

h1 { font-size: 20px; margin: 8px 0; }
h2 { font-size: 15px; margin: 0; }

.hint { color: var(--hint); font-size: 14px; margin: 4px 0; }
.center-text { text-align: center; }
.big { font-size: 44px; margin: 0; }

.screen { padding: 16px; }
.center { display: flex; flex-direction: column; align-items: center; justify-content: center;
          gap: 8px; text-align: center; min-height: 70vh; }
.pad { padding: 24px; }

.section-title { margin: 24px 0 8px; color: var(--hint); text-transform: uppercase;
                 letter-spacing: .04em; font-size: 13px; }

/* --- QR --- */

.qr-wrap { display: flex; justify-content: center; margin: 8px 0 4px; }

.qr {
    width: min(66vw, 260px);
    aspect-ratio: 1;
    border-radius: var(--radius);
    display: block;
    transition: width .2s ease;
}

/* Зум по тапу: сотруднику иногда надо считать код с чужого экрана в полутьме. */
body.qr-zoom .qr { width: min(92vw, 420px); }

.skeleton { background: var(--section-bg); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }

.spinner {
    width: 28px; height: 28px; border-radius: 50%;
    border: 3px solid var(--section-bg); border-top-color: var(--accent);
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(1turn); } }

/* --- уровень --- */

.level-card {
    background: var(--section-bg);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-top: 16px;
    /* Цвет уровня — единственный собственный цвет приложения. Тот же, которым
       обведён QR: гость должен узнавать свой уровень, не читая названия. */
    border-left: 4px solid var(--level, var(--accent));
}

.level-head { display: flex; align-items: baseline; justify-content: space-between; }
.level-name { font-size: 22px; font-weight: 600; }
.level-discount { font-size: 22px; font-weight: 600; color: var(--level, var(--accent)); }

.stats { display: flex; gap: 8px; margin-top: 12px; }
.stat {
    flex: 1; background: var(--section-bg); border-radius: var(--radius);
    padding: 12px 8px; text-align: center;
}
.stat-value { display: block; font-size: 22px; font-weight: 600; }
.stat-label { display: block; font-size: 12px; color: var(--hint); }

.progress-block { margin-top: 20px; }
.progress-head { display: flex; justify-content: space-between; align-items: baseline;
                 font-size: 14px; margin-bottom: 6px; }
.progress { height: 8px; background: var(--section-bg); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 4px;
                 transition: width .4s ease; }

.levels { list-style: none; margin: 0; padding: 0;
          background: var(--section-bg); border-radius: var(--radius); overflow: hidden; }
.level-row {
    display: grid; grid-template-columns: 10px 1fr auto auto;
    gap: 10px; align-items: center;
    padding: 10px 14px; font-size: 15px;
    /* Недостигнутые уровни приглушены, но читаемы: это цель, а не запрет. */
    opacity: .5;
}
.level-row.reached { opacity: 1; }
.level-row.current { background: var(--bg); font-weight: 600; }
.dot { width: 10px; height: 10px; border-radius: 50%; }
.level-row-discount { min-width: 40px; text-align: right; }

/* --- купоны --- */

.switch { display: flex; background: var(--section-bg); border-radius: var(--radius);
          padding: 3px; margin-bottom: 14px; }
.switch button {
    flex: 1; border: 0; background: transparent; color: var(--hint);
    padding: 8px; border-radius: calc(var(--radius) - 4px); font: inherit; font-size: 15px;
    cursor: pointer;
}
.switch button.on { background: var(--bg); color: var(--text); font-weight: 600; }

.coupons { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.coupon {
    display: flex; align-items: center; gap: 12px;
    background: var(--section-bg); border-radius: var(--radius); padding: 12px 14px;
}
/* Погашенные и сгоревшие остаются в списке, но не спорят за внимание с активными. */
.coupon.redeemed, .coupon.expired, .coupon.revoked { opacity: .45; }
.coupon-icon { font-size: 26px; }
.coupon-body { flex: 1; min-width: 0; }
.coupon-title { font-size: 17px; font-weight: 600; }
.coupon-status { font-size: 12px; color: var(--hint); text-align: right; }

/* --- кнопки --- */

.btn {
    display: block; width: 100%; margin-top: 12px;
    border: 0; border-radius: var(--radius); padding: 14px;
    background: var(--accent); color: var(--accent-text);
    font: inherit; font-size: 16px; font-weight: 600; cursor: pointer;
}
.btn:active { opacity: .8; }
.btn.ghost { background: var(--section-bg); color: var(--text); }

/* --- табы --- */

.tabs {
    position: fixed; left: 0; right: 0; bottom: 0;
    display: flex;
    background: var(--bg);
    border-top: 1px solid var(--section-bg);
    padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    border: 0; background: transparent; color: var(--hint);
    padding: 8px 0 10px; font: inherit; font-size: 11px; cursor: pointer;
}
.tabs button span:first-child { font-size: 20px; }
.tabs button.on { color: var(--accent); }
