/* ============================================
   Telegram Mini App — TopBro
   ============================================ */

/* --- Theme Variables --- */
:root {
    --tg-bg: var(--tg-theme-bg-color, #fff);
    --tg-text: var(--tg-theme-text-color, #000);
    --tg-hint: var(--tg-theme-hint-color, #999);
    --tg-link: var(--tg-theme-link-color, #2678b6);
    --tg-btn: var(--tg-theme-button-color, #2678b6);
    --tg-btn-text: var(--tg-theme-button-text-color, #fff);
    --tg-secondary-bg: var(--tg-theme-secondary-bg-color, #f0f0f0);

    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.2s ease;
}

/* --- Reset & Base --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    overflow-x: hidden;
}

body {
    font-family: -apple-system, system-ui, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--tg-bg);
    color: var(--tg-text);
    font-size: 15px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent;
}

#app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

#screen-container {
    flex: 1;
    padding-bottom: 64px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* --- Bottom Navigation --- */
#bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--tg-bg);
    border-top: 0.5px solid var(--tg-hint);
    display: flex;
    align-items: center;
    justify-content: space-around;
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    border: none;
    background: transparent;
    cursor: pointer;
    position: relative;
    transition: color var(--transition);
    -webkit-tap-highlight-color: transparent;
}

.nav-icon {
    font-size: 24px;
    opacity: 0.45;
    transition: opacity var(--transition), transform var(--transition);
}

.nav-tab.active .nav-icon {
    opacity: 1;
    transform: scale(1.15);
}

.nav-tab.active::after {
    content: '';
    position: absolute;
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--tg-btn);
}

/* --- Card --- */
.card {
    background: var(--tg-secondary-bg);
    border-radius: var(--radius);
    padding: 16px;
    margin: 8px 16px;
}

.card + .card {
    margin-top: 8px;
}

/* --- Section Header --- */
.section-header {
    font-weight: 700;
    font-size: 17px;
    padding: 16px 16px 8px;
}

/* --- Stat --- */
.stat-row {
    display: flex;
    gap: 8px;
}

.stat-box {
    flex: 1;
    text-align: center;
    padding: 12px 4px;
}

.stat-number {
    font-size: 32px;
    font-weight: 800;
    line-height: 1.1;
}

.stat-label {
    font-size: 12px;
    color: var(--tg-hint);
    margin-top: 2px;
}

/* --- List Item --- */
.list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: background var(--transition);
    -webkit-tap-highlight-color: transparent;
}

.list-item:active {
    background: var(--tg-secondary-bg);
}

.list-item + .list-item {
    border-top: 0.5px solid var(--tg-secondary-bg);
}

.list-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--tg-secondary-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 600;
    flex-shrink: 0;
    color: var(--tg-hint);
}

.list-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.list-text {
    flex: 1;
    min-width: 0;
}

.list-title {
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-subtitle {
    font-size: 13px;
    color: var(--tg-hint);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-chevron {
    color: var(--tg-hint);
    font-size: 18px;
    flex-shrink: 0;
    opacity: 0.4;
}

.list-value {
    font-weight: 700;
    font-size: 15px;
    flex-shrink: 0;
}

/* --- Progress Bar --- */
.progress-bar {
    height: 6px;
    border-radius: 3px;
    background: var(--tg-secondary-bg);
    overflow: hidden;
    width: 100%;
}

.progress-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.4s ease;
    background: var(--tg-btn);
}

.progress-fill.cat-useful { background: #5ac8fa; }
.progress-fill.cat-kindness { background: #ff9500; }
.progress-fill.cat-activity { background: #34c759; }
.progress-fill.cat-streak { background: #ff3b30; }
.progress-fill.cat-thanks { background: #af52de; }

/* --- Medal Grid --- */
.medal-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 0 16px;
}

.medal-card {
    aspect-ratio: 1;
    border-radius: var(--radius);
    background: var(--tg-secondary-bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px;
    gap: 4px;
    cursor: pointer;
    transition: transform var(--transition), opacity var(--transition);
    position: relative;
    overflow: hidden;
}

.medal-card:active {
    transform: scale(0.95);
}

.medal-card.locked {
    opacity: 0.45;
}

.medal-card.locked .medal-image {
    filter: grayscale(1);
}

.medal-image {
    width: 48px;
    height: 48px;
    object-fit: contain;
}

.medal-emoji {
    font-size: 36px;
    line-height: 1;
}

.medal-title {
    font-size: 10px;
    font-weight: 600;
    text-align: center;
    line-height: 1.2;
    color: var(--tg-text);
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.medal-lock {
    position: absolute;
    bottom: 6px;
    right: 6px;
    font-size: 12px;
    opacity: 0.6;
}

.medal-progress {
    width: 80%;
}

.medal-progress .progress-bar {
    height: 4px;
}

/* --- Chart (Activity Bars) --- */
.chart-container {
    display: flex;
    align-items: flex-end;
    justify-content: space-around;
    height: 100px;
    padding: 8px 0 0;
    gap: 4px;
}

.chart-bar-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    height: 100%;
    justify-content: flex-end;
}

.chart-bar {
    width: 100%;
    max-width: 28px;
    border-radius: 4px 4px 0 0;
    background: var(--tg-btn);
    transition: height 0.4s ease;
    min-height: 2px;
}

.chart-bar-value {
    font-size: 10px;
    font-weight: 700;
    color: var(--tg-text);
}

.chart-label {
    font-size: 11px;
    color: var(--tg-hint);
    font-weight: 500;
}

/* --- Podium (Top-3) --- */
.podium {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 6px;
    padding: 24px 16px 16px;
}

.podium-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    flex: 1;
    max-width: 110px;
}

.podium-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--tg-secondary-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 700;
    color: var(--tg-hint);
    position: relative;
}

.podium-item.first .podium-avatar {
    width: 64px;
    height: 64px;
    font-size: 26px;
    box-shadow: 0 0 0 3px #ffd700;
}

.podium-item.second .podium-avatar {
    box-shadow: 0 0 0 2px #c0c0c0;
}

.podium-item.third .podium-avatar {
    box-shadow: 0 0 0 2px #cd7f32;
}

.podium-rank {
    font-size: 16px;
    font-weight: 800;
}

.podium-item.first .podium-rank { color: #ffd700; }
.podium-item.second .podium-rank { color: #c0c0c0; }
.podium-item.third .podium-rank { color: #cd7f32; }

.podium-name {
    font-size: 12px;
    font-weight: 600;
    text-align: center;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.podium-score {
    font-size: 11px;
    color: var(--tg-hint);
}

.podium-pedestal {
    width: 100%;
    border-radius: 6px 6px 0 0;
    background: var(--tg-secondary-bg);
}

.podium-item.first .podium-pedestal { height: 72px; }
.podium-item.second .podium-pedestal { height: 52px; }
.podium-item.third .podium-pedestal { height: 36px; }

/* --- iOS Toggle Switch --- */
.toggle {
    position: relative;
    display: inline-block;
    width: 51px;
    height: 31px;
    flex-shrink: 0;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #e9e9eb;
    border-radius: 31px;
    transition: background 0.3s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 27px;
    width: 27px;
    left: 2px;
    bottom: 2px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.3s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.toggle input:checked + .toggle-slider {
    background: #34c759;
}

.toggle input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

/* Dark mode toggle background */
@media (prefers-color-scheme: dark) {
    .toggle-slider {
        background: #39393d;
    }
}

/* --- Accordion (FAQ) --- */
.accordion {
    margin: 0 16px;
}

.accordion-item {
    border-bottom: 0.5px solid var(--tg-secondary-bg);
}

.accordion-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 0;
    cursor: pointer;
    font-weight: 600;
    font-size: 15px;
    -webkit-tap-highlight-color: transparent;
    gap: 12px;
}

.accordion-arrow {
    font-size: 14px;
    color: var(--tg-hint);
    transition: transform 0.25s ease;
    flex-shrink: 0;
}

.accordion-item.open .accordion-arrow {
    transform: rotate(90deg);
}

.accordion-body {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
}

.accordion-item.open .accordion-body {
    max-height: 500px;
    padding-bottom: 14px;
}

.accordion-body p {
    font-size: 14px;
    color: var(--tg-hint);
    line-height: 1.5;
}

/* --- Modal --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.2s ease;
    padding: 24px;
}

.modal-overlay.visible {
    opacity: 1;
}

.modal-card {
    background: var(--tg-bg);
    border-radius: 16px;
    padding: 24px;
    width: 100%;
    max-width: 340px;
    position: relative;
    transform: scale(0.95);
    transition: transform 0.2s ease;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-overlay.visible .modal-card {
    transform: scale(1);
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: var(--tg-secondary-bg);
    color: var(--tg-hint);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.modal-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 12px;
    padding-right: 32px;
}

.modal-body {
    font-size: 14px;
    line-height: 1.5;
}

/* --- Form Inputs --- */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--tg-hint);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--tg-secondary-bg);
    border-radius: var(--radius-sm);
    background: var(--tg-secondary-bg);
    color: var(--tg-text);
    font-size: 15px;
    font-family: inherit;
    outline: none;
    transition: border-color var(--transition);
}

.form-input:focus {
    border-color: var(--tg-btn);
}

.form-input::placeholder {
    color: var(--tg-hint);
}

textarea.form-input {
    resize: vertical;
    min-height: 80px;
}

/* --- Number Input with +/- --- */
.number-input {
    display: flex;
    align-items: center;
    gap: 0;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--tg-secondary-bg);
    width: fit-content;
}

.number-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: var(--tg-btn);
    font-size: 20px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.number-btn:active {
    background: var(--tg-btn);
    color: var(--tg-btn-text);
}

.number-value {
    width: 48px;
    text-align: center;
    font-size: 16px;
    font-weight: 700;
    background: transparent;
    border: none;
    color: var(--tg-text);
    font-family: inherit;
    outline: none;
}

/* --- Range Slider --- */
.range-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: var(--tg-secondary-bg);
    outline: none;
}

.range-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--tg-btn);
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.range-slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--tg-btn);
    cursor: pointer;
    border: none;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: opacity var(--transition), transform var(--transition);
    -webkit-tap-highlight-color: transparent;
}

.btn:active {
    transform: scale(0.97);
    opacity: 0.85;
}

.btn-primary {
    background: var(--tg-btn);
    color: var(--tg-btn-text);
}

.btn-secondary {
    background: var(--tg-secondary-bg);
    color: var(--tg-text);
}

.btn-block {
    width: 100%;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

/* --- Setting Row --- */
.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    gap: 12px;
}

.setting-row + .setting-row {
    border-top: 0.5px solid var(--tg-secondary-bg);
}

.setting-label {
    font-size: 15px;
    font-weight: 500;
}

.setting-hint {
    font-size: 12px;
    color: var(--tg-hint);
    margin-top: 2px;
}

/* --- Loading Spinner --- */
.spinner-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px 0;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--tg-secondary-bg);
    border-top-color: var(--tg-btn);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --- Empty State --- */
.empty-state {
    text-align: center;
    padding: 48px 32px;
}

.empty-icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.5;
}

.empty-title {
    font-size: 17px;
    font-weight: 700;
    margin-bottom: 4px;
}

.empty-text {
    font-size: 14px;
    color: var(--tg-hint);
    line-height: 1.4;
}

/* --- Chip / Tag --- */
.chip {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    background: var(--tg-secondary-bg);
    color: var(--tg-hint);
}

.chip-active {
    background: var(--tg-btn);
    color: var(--tg-btn-text);
}

/* --- Chat Selector --- */
.chat-selector {
    display: flex;
    gap: 6px;
    padding: 8px 16px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.chat-selector::-webkit-scrollbar {
    display: none;
}

/* --- Admin Grid --- */
.admin-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 0 16px;
}

.admin-grid-item {
    background: var(--tg-secondary-bg);
    border-radius: var(--radius);
    padding: 20px 16px;
    text-align: center;
    cursor: pointer;
    transition: transform var(--transition);
    -webkit-tap-highlight-color: transparent;
}

.admin-grid-item:active {
    transform: scale(0.97);
}

.admin-grid-icon {
    font-size: 32px;
    margin-bottom: 8px;
}

.admin-grid-label {
    font-size: 14px;
    font-weight: 600;
}

/* --- Screen Transition --- */
.screen-enter {
    animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- Responsive --- */
@media (max-width: 340px) {
    .stat-number {
        font-size: 26px;
    }
    .medal-grid {
        gap: 6px;
        padding: 0 12px;
    }
    .card {
        margin: 6px 12px;
        padding: 12px;
    }
}

/* --- Scrollbar hide for webkit --- */
#screen-container::-webkit-scrollbar {
    display: none;
}

#screen-container {
    scrollbar-width: none;
}

/* ============================================
   Screen-specific styles
   ============================================ */

/* --- Loading & Error --- */
.loading {
    text-align: center;
    padding: 48px 16px;
    color: var(--tg-hint);
    font-size: 14px;
}

.error {
    text-align: center;
    padding: 32px 16px;
    color: #ff3b30;
    font-size: 14px;
}

.list-empty {
    text-align: center;
    padding: 24px 16px;
    color: var(--tg-hint);
    font-size: 14px;
}

/* --- Generic input --- */
.input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--tg-secondary-bg);
    border-radius: var(--radius-sm);
    background: var(--tg-secondary-bg);
    color: var(--tg-text);
    font-size: 15px;
    font-family: inherit;
    outline: none;
    transition: border-color var(--transition);
}

.input:focus {
    border-color: var(--tg-btn);
}

.input::placeholder {
    color: var(--tg-hint);
}

textarea.input {
    resize: vertical;
    min-height: 60px;
}

select.input {
    -webkit-appearance: none;
    appearance: none;
}

.time-input {
    width: auto;
}

/* --- Profile Screen --- */
.profile-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px 16px 16px;
    gap: 8px;
}

.profile-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--tg-btn);
    color: var(--tg-btn-text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: 700;
}

.profile-name {
    font-size: 20px;
    font-weight: 700;
}

.rank-badge {
    padding: 4px 12px;
    border-radius: 12px;
    background: var(--tg-secondary-bg);
    font-size: 13px;
    font-weight: 600;
    color: var(--tg-btn);
}

.scope-label {
    margin-top: 4px;
    font-size: 13px;
    color: var(--tg-hint);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    padding: 0 16px;
    margin-bottom: 8px;
}

.stat-card {
    background: var(--tg-secondary-bg);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
}

.stat-card.accent-green .stat-number { color: #34c759; }
.stat-card.accent-red .stat-number { color: #ff3b30; }

.section-title {
    font-weight: 700;
    font-size: 15px;
    padding: 4px 0 8px;
}

/* Activity chart (profile-specific) */
.activity-chart {
    display: flex;
    align-items: flex-end;
    justify-content: space-around;
    height: 80px;
    gap: 4px;
}

.chart-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    height: 100%;
    justify-content: flex-end;
}

.chart-value {
    font-size: 10px;
    font-weight: 700;
    color: var(--tg-text);
    min-height: 14px;
}

.chart-day {
    font-size: 11px;
    color: var(--tg-hint);
}

.chart-empty {
    text-align: center;
    color: var(--tg-hint);
    padding: 16px;
    font-size: 13px;
}

/* Breakdown */
.breakdown-empty {
    text-align: center;
    color: var(--tg-hint);
    padding: 12px;
    font-size: 13px;
}

.breakdown-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
}

.breakdown-label {
    font-size: 13px;
    color: var(--tg-hint);
    width: 90px;
    flex-shrink: 0;
}

.breakdown-track {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: var(--tg-bg);
    overflow: hidden;
}

.breakdown-bar {
    height: 100%;
    border-radius: 3px;
    background: var(--tg-btn);
    transition: width 0.3s ease;
}

.breakdown-bar.negative {
    background: #ff3b30;
}

.breakdown-value {
    font-size: 13px;
    font-weight: 700;
    width: 48px;
    text-align: right;
    flex-shrink: 0;
}

.breakdown-value.negative {
    color: #ff3b30;
}

/* Trend */
.trend {
    padding: 8px 0 0;
    font-size: 13px;
}

.trend-up { color: #34c759; }
.trend-down { color: #ff3b30; }
.trend-neutral { color: var(--tg-hint); }

/* Streak */
.streak-info {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.streak-current {
    font-size: 28px;
    font-weight: 800;
}

.streak-record {
    font-size: 13px;
    color: var(--tg-hint);
}

/* Recent medals row */
.medals-row {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 4px 0;
    -webkit-overflow-scrolling: touch;
}

.medal-small {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
    width: 56px;
}

.medal-small .medal-emoji {
    font-size: 28px;
}

.medal-small .medal-title {
    font-size: 9px;
    color: var(--tg-hint);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

/* --- Achievements Screen --- */
.medal-grid-item {
    background: var(--tg-secondary-bg);
    border-radius: var(--radius-sm);
    padding: 12px 8px;
    text-align: center;
    cursor: pointer;
    transition: transform var(--transition);
}

.medal-grid-item:active {
    transform: scale(0.96);
}

.medal-grid-item.locked {
    opacity: 0.4;
}

.medal-grid-emoji {
    font-size: 32px;
    display: block;
    margin-bottom: 4px;
}

.medal-grid-title {
    font-size: 11px;
    font-weight: 600;
    display: block;
}

.goal-row {
    padding: 10px 0;
}

.goal-row + .goal-row {
    border-top: 0.5px solid var(--tg-bg);
}

.goal-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
}

.goal-emoji {
    font-size: 20px;
}

.goal-title {
    font-size: 14px;
    font-weight: 600;
}

.progress-track {
    height: 6px;
    border-radius: 3px;
    background: var(--tg-bg);
    overflow: hidden;
    margin-bottom: 4px;
}

.goal-numbers {
    font-size: 12px;
    color: var(--tg-hint);
    text-align: right;
}

/* Catalog */
.catalog-section {
    margin-bottom: 16px;
}

.catalog-category {
    font-weight: 700;
    font-size: 14px;
    padding: 8px 0 6px;
}

.catalog-levels {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.catalog-medal {
    background: var(--tg-bg);
    border-radius: var(--radius-sm);
    padding: 10px 6px;
    text-align: center;
    cursor: pointer;
    transition: transform var(--transition);
}

.catalog-medal:active {
    transform: scale(0.96);
}

.catalog-medal.locked {
    opacity: 0.4;
}

.catalog-medal-icon {
    font-size: 24px;
    margin-bottom: 4px;
}

.catalog-emoji {
    font-size: 24px;
}

.catalog-lock {
    font-size: 18px;
    opacity: 0.5;
}

.catalog-medal-title {
    font-size: 10px;
    font-weight: 600;
    line-height: 1.2;
    margin-bottom: 2px;
}

.catalog-medal-threshold {
    font-size: 10px;
    color: var(--tg-hint);
}

/* Medal modal (achievements) */
.modal-emoji {
    font-size: 48px;
    text-align: center;
    margin-bottom: 8px;
}

.modal-category {
    text-align: center;
    font-size: 13px;
    color: var(--tg-hint);
    margin-bottom: 4px;
}

.modal-threshold {
    text-align: center;
    font-size: 14px;
    color: var(--tg-text);
    margin-bottom: 12px;
}

.modal-earned {
    text-align: center;
    font-size: 14px;
    color: #34c759;
    font-weight: 600;
    margin-bottom: 12px;
}

.modal-locked {
    text-align: center;
    font-size: 14px;
    color: var(--tg-hint);
    margin-bottom: 12px;
}

.modal-close-btn {
    display: block;
    width: 100%;
    padding: 10px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--tg-secondary-bg);
    color: var(--tg-text);
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
}

/* --- Leaderboard Screen --- */
.podium-card {
    padding: 8px 16px 16px;
}

.podium-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    max-width: 110px;
}

.podium-col.empty {
    visibility: hidden;
}

.podium-col.first {
    order: 2;
}

.podium-col.second {
    order: 1;
}

.podium-col.third {
    order: 3;
}

.podium-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--tg-secondary-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 700;
    color: var(--tg-hint);
}

.podium-col.first .podium-avatar {
    width: 64px;
    height: 64px;
    font-size: 26px;
    box-shadow: 0 0 0 3px #ffd700;
}

.podium-avatar.gold { box-shadow: 0 0 0 3px #ffd700; }
.podium-avatar.silver { box-shadow: 0 0 0 2px #c0c0c0; }
.podium-avatar.bronze { box-shadow: 0 0 0 2px #cd7f32; }

.podium-points {
    font-size: 12px;
    color: var(--tg-hint);
}

.podium-bar {
    width: 100%;
    border-radius: 6px 6px 0 0;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 8px;
}

.podium-bar.gold { height: 72px; background: linear-gradient(180deg, #ffd700 0%, #f0c800 100%); }
.podium-bar.silver { height: 52px; background: linear-gradient(180deg, #e0e0e0 0%, #c0c0c0 100%); }
.podium-bar.bronze { height: 36px; background: linear-gradient(180deg, #e0a060 0%, #cd7f32 100%); }

.podium-place {
    font-size: 18px;
    font-weight: 800;
    color: #fff;
}

/* Leaderboard list */
.lb-list {
    padding: 0;
}

.lb-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
}

.lb-row + .lb-row {
    border-top: 0.5px solid var(--tg-bg);
}

.lb-row.current-user {
    background: color-mix(in srgb, var(--tg-btn) 10%, transparent);
    border-radius: var(--radius-sm);
}

.lb-position {
    font-size: 14px;
    font-weight: 700;
    width: 28px;
    text-align: center;
    flex-shrink: 0;
    color: var(--tg-hint);
}

.lb-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--tg-secondary-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 600;
    color: var(--tg-hint);
    flex-shrink: 0;
}

.lb-info {
    flex: 1;
    min-width: 0;
}

.lb-name {
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lb-rank {
    font-size: 12px;
    color: var(--tg-hint);
}

.lb-points {
    font-size: 15px;
    font-weight: 700;
    flex-shrink: 0;
}

.lb-separator {
    text-align: center;
    padding: 8px;
    color: var(--tg-hint);
    font-size: 16px;
}

.lb-user-extra {
    padding: 0;
}

/* --- FAQ Screen --- */
.faq-list {
    padding: 0 16px;
}

.faq-item {
    border-bottom: 0.5px solid var(--tg-bg);
}

.faq-item:last-child {
    border-bottom: none;
}

.faq-question {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 14px 0;
    border: none;
    background: transparent;
    color: var(--tg-text);
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    gap: 8px;
    -webkit-tap-highlight-color: transparent;
}

.faq-q-text {
    flex: 1;
}

.faq-chevron {
    font-size: 14px;
    color: var(--tg-hint);
    transition: transform 0.25s ease;
    flex-shrink: 0;
}

.faq-item.open .faq-chevron {
    transform: rotate(180deg);
}

.faq-answer {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.faq-answer-inner {
    padding-bottom: 14px;
    font-size: 14px;
    color: var(--tg-hint);
    line-height: 1.5;
}

/* --- CRM Screen --- */
.search-bar {
    padding: 8px 16px;
}

.crm-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 16px 8px;
}
.crm-count {
    font-size: 12px;
    color: var(--tg-hint);
}
.btn-small {
    padding: 4px 12px;
    font-size: 12px;
    border-radius: 8px;
}

.crm-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background var(--transition);
}

.crm-row:active {
    background: var(--tg-secondary-bg);
}

.crm-row + .crm-row {
    border-top: 0.5px solid var(--tg-secondary-bg);
}

.crm-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--tg-btn);
    color: var(--tg-btn-text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
    flex-shrink: 0;
}

.crm-info {
    flex: 1;
    min-width: 0;
}

.crm-name {
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.crm-username {
    color: var(--tg-hint);
    font-weight: 400;
    font-size: 13px;
}

.crm-meta {
    display: flex;
    gap: 8px;
    font-size: 12px;
    color: var(--tg-hint);
    margin-top: 2px;
}

.crm-role-badge {
    background: var(--tg-secondary-bg);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 11px;
}

.crm-last-seen {
    font-size: 11px;
}

.crm-arrow {
    color: var(--tg-hint);
    font-size: 20px;
    opacity: 0.4;
    flex-shrink: 0;
}

/* CRM Detail */
.detail-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
}

.back-btn, .edit-btn {
    border: none;
    background: transparent;
    color: var(--tg-btn);
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    padding: 4px 0;
    -webkit-tap-highlight-color: transparent;
}

.detail-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 16px 16px;
    gap: 6px;
}

.detail-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--tg-btn);
    color: var(--tg-btn-text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 700;
}

.detail-name {
    font-size: 18px;
    font-weight: 700;
}

.detail-username {
    font-size: 14px;
    color: var(--tg-hint);
}

.detail-tabs {
    display: flex;
    gap: 0;
    padding: 0 16px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    border-bottom: 0.5px solid var(--tg-secondary-bg);
}

.detail-tabs::-webkit-scrollbar {
    display: none;
}

.detail-tab {
    border: none;
    background: transparent;
    color: var(--tg-hint);
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    padding: 10px 12px;
    cursor: pointer;
    white-space: nowrap;
    position: relative;
    -webkit-tap-highlight-color: transparent;
}

.detail-tab.active {
    color: var(--tg-btn);
}

.detail-tab.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 12px;
    right: 12px;
    height: 2px;
    background: var(--tg-btn);
    border-radius: 1px;
}

.detail-body {
    padding: 8px 16px;
}

.detail-actions {
    display: flex;
    gap: 8px;
    padding: 16px;
}

.field-row {
    padding: 10px 0;
}

.field-row + .field-row {
    border-top: 0.5px solid var(--tg-secondary-bg);
}

.field-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--tg-hint);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 4px;
}

.field-value {
    font-size: 15px;
}

.confirmed-icon {
    font-size: 12px;
}

/* --- Dashboard Screen --- */
.admin-header {
    padding: 16px 16px 8px;
}

.admin-header h2 {
    font-size: 20px;
    font-weight: 700;
}

.admin-subtitle {
    font-size: 13px;
    color: var(--tg-hint);
    margin-top: 2px;
}

.top-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
}

.top-row + .top-row {
    border-top: 0.5px solid var(--tg-bg);
}

.top-pos {
    width: 28px;
    text-align: center;
    font-size: 16px;
    flex-shrink: 0;
}

.top-name {
    flex: 1;
    font-size: 15px;
    font-weight: 500;
}

.top-points {
    font-size: 15px;
    font-weight: 700;
    flex-shrink: 0;
}

.admin-menu {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 16px;
}

.admin-menu-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 14px 16px;
    border: none;
    border-radius: var(--radius);
    background: var(--tg-secondary-bg);
    color: var(--tg-text);
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    transition: transform var(--transition);
    -webkit-tap-highlight-color: transparent;
}

.admin-menu-btn:active {
    transform: scale(0.98);
}

/* --- Rules Screen --- */
.rules-section {
    padding: 0 16px;
    margin-bottom: 16px;
}

.rule-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    gap: 12px;
    position: relative;
}

.rule-row + .rule-row {
    border-top: 0.5px solid var(--tg-secondary-bg);
}

.rule-row.rule-disabled {
    opacity: 0.4;
    pointer-events: none;
}

.rule-row.rule-main {
    padding: 12px 0;
}

.rule-row.rule-sub {
    padding-left: 16px;
}

.rule-info {
    flex: 1;
    min-width: 0;
}

.rule-name {
    font-size: 15px;
    font-weight: 500;
}

.rule-key {
    font-size: 11px;
    color: var(--tg-hint);
    font-family: monospace;
    margin-top: 1px;
}

.rule-control {
    flex-shrink: 0;
}

.rule-reset {
    position: absolute;
    right: -4px;
    top: 2px;
    border: none;
    background: transparent;
    font-size: 14px;
    cursor: pointer;
    padding: 2px;
}

.toggle-disabled {
    opacity: 0.4;
    pointer-events: none;
}

.control-disabled {
    opacity: 0.4;
    pointer-events: none;
}

/* Slider control — full width below label */
.slider-control {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 140px;
    flex: 1;
}

.slider {
    -webkit-appearance: none;
    appearance: none;
    flex: 1;
    height: 4px;
    border-radius: 2px;
    background: var(--tg-secondary-bg);
    outline: none;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--tg-btn);
    cursor: pointer;
}

.slider-value {
    font-size: 13px;
    font-weight: 600;
    width: 36px;
    text-align: right;
}

/* Number control (rules) */
.number-control {
    display: flex;
    align-items: center;
    gap: 0;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--tg-secondary-bg);
}

.num-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--tg-btn);
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.num-btn:active {
    background: var(--tg-btn);
    color: var(--tg-btn-text);
}

.num-input {
    width: 40px;
    text-align: center;
    font-size: 14px;
    font-weight: 700;
    border: none;
    background: transparent;
    color: var(--tg-text);
    font-family: inherit;
    outline: none;
    -moz-appearance: textfield;
}

.num-input::-webkit-outer-spin-button,
.num-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* --- Manage Screen --- */
.tabs-header {
    display: flex;
    gap: 0;
    padding: 0 16px;
    border-bottom: 0.5px solid var(--tg-secondary-bg);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.tabs-header::-webkit-scrollbar {
    display: none;
}

.tab-btn {
    border: none;
    background: transparent;
    color: var(--tg-hint);
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    padding: 12px 14px;
    cursor: pointer;
    white-space: nowrap;
    position: relative;
    -webkit-tap-highlight-color: transparent;
}

.tab-btn.active {
    color: var(--tg-btn);
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 14px;
    right: 14px;
    height: 2px;
    background: var(--tg-btn);
    border-radius: 1px;
}

.manage-section {
    padding: 8px 16px;
}

.manage-section .section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
}

.btn-small {
    padding: 6px 12px;
    font-size: 13px;
}

.btn-danger {
    background: #ff3b30;
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    padding: 6px 12px;
    cursor: pointer;
}

/* Challenge cards */
.challenge-card {
    background: var(--tg-secondary-bg);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 8px;
}

.challenge-card.challenge-closed {
    opacity: 0.6;
}

.challenge-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
}

.challenge-title {
    font-size: 15px;
    font-weight: 600;
}

.challenge-hashtag {
    font-size: 13px;
    color: var(--tg-btn);
    font-weight: 500;
}

.challenge-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 12px;
    color: var(--tg-hint);
    margin-bottom: 8px;
}

.challenge-actions {
    display: flex;
    gap: 8px;
}

/* Create form */
.create-form {
    margin-bottom: 12px;
}

.field-row-inline {
    display: flex;
    gap: 12px;
}

.field-row-inline .field-row {
    flex: 1;
}

.form-actions {
    display: flex;
    gap: 8px;
    padding: 8px 0;
}

/* Digest rows */
.digest-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.digest-row + .digest-row {
    border-top: 0.5px solid var(--tg-secondary-bg);
}

.digest-date {
    font-size: 13px;
    font-weight: 600;
    flex-shrink: 0;
    width: 80px;
}

.digest-preview {
    font-size: 13px;
    color: var(--tg-hint);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.digest-text {
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
}

/* Old-style modal (manage screen) */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 24px;
}

.modal-content {
    background: var(--tg-bg);
    border-radius: 16px;
    padding: 20px;
    width: 100%;
    max-width: 340px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

/* System (manage) */
.system-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    gap: 12px;
}

.system-row + .system-row {
    border-top: 0.5px solid var(--tg-secondary-bg);
}

.system-info {
    flex: 1;
    min-width: 0;
}

.system-name {
    font-size: 15px;
    font-weight: 500;
}

.system-id {
    font-size: 11px;
    color: var(--tg-hint);
    font-family: monospace;
}

.admin-group {
    margin-bottom: 4px;
}

.admin-group-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 0;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    -webkit-tap-highlight-color: transparent;
}

.admin-count {
    background: var(--tg-secondary-bg);
    padding: 1px 6px;
    border-radius: 8px;
    font-size: 12px;
    color: var(--tg-hint);
}

.expand-arrow {
    color: var(--tg-hint);
    font-size: 16px;
    margin-left: auto;
    transition: transform 0.2s ease;
}

.admin-group-body {
    padding-left: 12px;
}

.admin-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    font-size: 14px;
}

.admin-row + .admin-row {
    border-top: 0.5px solid var(--tg-secondary-bg);
}

.admin-name {
    font-weight: 500;
}

.admin-username {
    color: var(--tg-hint);
    font-size: 13px;
}

.admin-role-badge {
    margin-left: auto;
    background: var(--tg-secondary-bg);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 11px;
    color: var(--tg-hint);
}
