/* Nolvix Telegram Mini App: the UI Kit laid out for the Telegram web view
 * (one column, bottom tab bar, safe areas). Components are the Kit's own. */

body.nx-tg {
    min-height: 100vh;
    min-height: var(--tg-viewport-stable-height, 100vh);
    background: var(--color-background);
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: none;
}

.tg-main {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-3);
    max-width: 560px;
    margin: 0 auto;
    padding: calc(var(--spacing-3) + env(safe-area-inset-top)) var(--spacing-3)
             calc(96px + env(safe-area-inset-bottom));
}
.tg-main > .g-alert { margin: 0; }
body.nx-tg.is-loading .tg-main { opacity: .6; }

.tg-title { font-size: var(--font-size-2xl); font-weight: var(--font-weight-semibold); margin: var(--spacing-2) 0 0; }
.tg-titlebar { display: flex; align-items: center; justify-content: space-between; gap: var(--spacing-3); }
.tg-filter { align-self: flex-start; }

/* ---------- bottom tab bar: Kit app-tabbar, always on, with labels ---------- */
.app-tabbar.tg-tabbar {
    position: fixed;
    left: 50%;
    bottom: calc(var(--spacing-3) + env(safe-area-inset-bottom));
    z-index: var(--z-header, 1030);
    display: flex;
    gap: 2px;
    width: min(calc(100% - 2 * var(--spacing-3)), 520px);
    padding: 6px;
    background: var(--color-surface);
    border-radius: var(--radius-pill);
    box-shadow: var(--shadow-md);
    transform: translateX(-50%);
}
.tg-tab {
    display: inline-flex;
    flex: 1 1 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 0;
    height: 52px;
    padding: 0 4px;
    white-space: nowrap;
    border-radius: var(--radius-pill);
    color: var(--color-text-secondary);
    font-size: 11px;
    font-weight: var(--font-weight-medium);
    text-decoration: none;
    transition: background-color .15s, color .15s;
}
.tg-tab i { font-size: 18px; line-height: 1; }
.tg-tab span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.tg-tab[hidden] { display: none; }
.tg-tab:hover { color: var(--color-text-primary); }
.tg-tab.is-active { background: var(--color-primary); color: var(--color-on-primary); }

/* ---------- home ---------- */
.tg-top { display: flex; align-items: center; justify-content: space-between; gap: var(--spacing-3); }
.tg-top__user { display: flex; align-items: center; gap: var(--spacing-3); min-width: 0; color: inherit; text-decoration: none; }
.tg-top__hello { display: flex; flex-direction: column; min-width: 0; }
.tg-top__name { font-weight: var(--font-weight-semibold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tg-top .app-header__bell { position: relative; flex: none; }

.tg-balance .amount { margin: var(--spacing-2) 0 var(--spacing-1, 4px); }
.tg-actions { display: flex; gap: var(--spacing-2); margin-top: var(--spacing-4); }
.tg-actions > * { flex: 1 1 0; min-width: 0; }
.tg-actions > [hidden] { display: none; }
a.tg-action { text-decoration: none; }
.tg-action {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-2);
    padding: var(--spacing-3) var(--spacing-1, 4px);
    border: 0;
    border-radius: var(--radius-md);
    background: var(--color-surface-sunken);
    color: var(--color-text-primary);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
}
.tg-action__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--color-primary);
    color: var(--color-on-primary);
    font-size: 18px;
}
.tg-action:active { transform: scale(.97); }
.tg-action.is-disabled, .tg-action:disabled { opacity: .45; }

.tg-main .g-list-item { padding-inline: 0; }
.tg-main .g-list-item:hover { background: transparent; }
.tg-main button.g-list-item, .tg-main a.g-list-item { width: 100%; border: 0; background: transparent; color: inherit; text-align: left; text-decoration: none; }
.tg-main .g-list-item__body { display: flex; flex-direction: column; min-width: 0; }
.tg-main .g-list-item__title, .tg-main .g-list-item__sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tg-main .g-list-item__meta { display: flex; flex-direction: column; flex: none; }

/* ---------- shared blocks ---------- */
.tg-stack { display: flex; flex-direction: column; gap: var(--spacing-3); }
.tg-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--spacing-3); }
.tg-stats .g-stat__value { font-size: var(--font-size-xl); }
.tg-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--spacing-3); }
.tg-toolbar { display: flex; flex-wrap: wrap; gap: var(--spacing-2); }
.tg-toolbar .g-combo, .tg-toolbar .g-select { flex: 1 1 120px; width: auto; }
.tg-tabs { overflow-x: auto; scrollbar-width: none; }
.tg-tabs::-webkit-scrollbar { display: none; }
.tg-titlebar .tg-title { margin-top: 0; }
.tg-main .nx-deal { display: flex; flex-direction: column; gap: var(--spacing-3); }
.tg-main .nx-panes > .g-tab-pane { padding: var(--spacing-4); }

/* Cards: swipe through the faces. */
.tg-cards {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 86%;
    gap: var(--spacing-3);
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    margin: 0 calc(-1 * var(--spacing-3));
    padding: 0 var(--spacing-3);
}
.tg-cards::-webkit-scrollbar { display: none; }
.tg-cards > * { scroll-snap-align: center; }
.tg-cards.is-single { grid-auto-columns: 100%; }
.tg-main .nx-products { grid-template-columns: repeat(2, minmax(0, 1fr)); }

/* Tables of the cabinet's page scripts → one card per row (cells carry data-label). */
@media (max-width: 767.98px) {
    .tg-main .g-table-wrap { overflow: visible; }
    .tg-main .g-table, .tg-main .g-table tbody, .tg-main .g-table tr, .tg-main .g-table td { display: block; width: 100%; }
    .tg-main .g-table thead { display: none; }
    .tg-main .g-table tbody tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: var(--spacing-2) var(--spacing-3);
        padding: var(--spacing-3);
        margin-bottom: var(--spacing-2);
        border-radius: var(--radius-md);
        background: var(--color-surface-sunken);
    }
    .tg-main .g-table tbody tr.g-table__state, .tg-main .g-table tbody tr.g-table__state td { display: block; background: transparent; padding: 0; }
    .tg-main .g-table td { padding: 0; border: 0; text-align: left !important; white-space: normal !important; overflow-wrap: anywhere; }
    .tg-main .g-table td:first-child { grid-column: 1 / -1; }
    .tg-main .g-table td:last-child:not(:first-child) { grid-column: 1 / -1; }
    .tg-main .g-table td:empty { display: none; }
    .tg-main .g-table td[data-label]::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 2px;
        color: var(--color-text-secondary);
        font-size: var(--font-size-xs);
    }
    .tg-main .g-table td:first-child::before { display: none; }
    .tg-main .g-table td .g-btn { width: 100%; }
    .tg-main .g-table td.text-end .g-btn + .g-btn { margin-top: var(--spacing-2); }
    .tg-main .nx-table-foot { justify-content: center; }
}

/* ---------- more ---------- */
.tg-profile { display: flex; align-items: center; gap: var(--spacing-3); }
.tg-profile__body { min-width: 0; }
.tg-row { display: flex; align-items: center; justify-content: space-between; gap: var(--spacing-3); padding: var(--spacing-3) 0; border-top: 1px solid var(--color-divider); }
.tg-row:first-of-type { border-top: 0; }
.tg-row__label { display: inline-flex; align-items: center; gap: var(--spacing-2); margin: 0; font-weight: var(--font-weight-medium); }
.tg-row__label i { color: var(--color-text-secondary); }
.tg-row__control { max-width: 190px; }
.tg-row .g-combo { max-width: 190px; }
.tg-row__value { color: var(--color-text-secondary); }
.tg-menu > li + li { border-top: 1px solid var(--color-divider); }
.tg-legal { margin-top: var(--spacing-2); }

/* ---------- boot / info screens ---------- */
.tg-boot {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-5);
    min-height: 100vh;
    min-height: var(--tg-viewport-stable-height, 100vh);
    padding: var(--spacing-6) var(--spacing-4);
    text-align: center;
}
.tg-boot__logo { width: 56px; height: 56px; }
:root[data-theme="dark"] .tg-boot__logo { filter: invert(1); } /* logo.svg is dark, like .app-logo in the Kit */
.tg-boot__state, .tg-boot__box { display: flex; flex-direction: column; align-items: center; gap: var(--spacing-3); max-width: 360px; }
.tg-boot__box[hidden], .tg-boot__state[hidden] { display: none; }
.tg-boot__title { font-size: var(--font-size-xl); font-weight: var(--font-weight-semibold); margin: 0; }
.tg-boot form { width: 100%; text-align: left; }

/* Modals as bottom sheets on phones. */
@media (max-width: 575.98px) {
    .nx-tg .modal-dialog-centered { align-items: flex-end; min-height: 100%; margin: 0; }
    .nx-tg .modal-dialog { max-width: none; }
    .nx-tg .modal-content { border-bottom-left-radius: 0; border-bottom-right-radius: 0; padding-bottom: env(safe-area-inset-bottom); }
}

/* Inside Telegram the app does not sign out: Telegram is the account. */
.nx-tg [data-nx-logout] { display: none !important; }
