/**
 * Sotka — Trinity Grid + Neural Black
 * PROJECT_MANIFEST.md v.1.0
 */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* 1. Запрещаем скролл всей страницы - это база WebApp */
html, body {
    margin: 0; padding: 0;
    width: 100%; height: 100%;
    overflow: hidden !important; 
    position: fixed; /* Мертвая фиксация */
    background: #1D2232;
    overscroll-behavior: none; /* жесты не уходят в Telegram */
}

/* 2. Контейнер - это коробка, которая НЕ растет */
.app-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 430px;
    height: 100vh; /* Ровно высота экрана */
    height: -webkit-fill-available;
    margin: 0 auto;
    overflow: hidden; /* Обрезаем всё, что вылазит */
    background: #1D2232;
}

/* 3. Шапка — высота с запасом под панель Telegram или под статус-бар при открытии с иконки (PWA) */
/* --header-safe-fallback: JS ставит 0 при открытии из бота, 24px при открытии с ярлыка; по умолчанию 24px — чтобы с ярлыка всегда был отступ */
:root {
    --header-safe-fallback: 24px;
}
.app-header {
    flex: 0 0 auto;
    width: 100%;
    min-height: calc(72px + max(env(safe-area-inset-top, 0px), var(--header-safe-fallback)));
    padding: max(env(safe-area-inset-top, 0px), var(--header-safe-fallback)) 16px 14px 16px;
    box-sizing: border-box;
    z-index: 100;
    background: #242A38;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    -webkit-tap-highlight-color: transparent;
}

/* Слева: блок выбора канала (занимает оставшееся место) */
.app-header #channel-selector-block,
.app-header .channel-selector-block {
    flex: 1;
    min-width: 0;
    height: 44px;
    background: rgba(31, 36, 50, 0.6);
    border: 1px solid rgba(117, 99, 70, 0.25);
    border-radius: 8px;
    display: flex;
    box-sizing: border-box;
    align-items: center;
    padding: 0 10px 0 12px;
    position: relative;
    z-index: 10;
}

.app-header .channel-selector-block .label {
    flex-shrink: 0;
    font-size: 9px;
    color: #64748B;
    font-weight: 800;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    margin-right: 10px;
}

.app-header .channel-selector-container {
    flex: 1;
    min-width: 0;
    position: relative;
    height: 30px;
}

.app-header .channel-selector-trigger {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 30px;
    border-radius: 6px;
    border: 0;
    background: transparent;
    color: #AEAFB0;
    font-size: 12px;
    padding: 0 24px 0 8px;
    outline: none;
    cursor: pointer;
    text-align: left;
}

.app-header .channel-selector-avatar {
    position: absolute;
    top: 5px;
    left: 0;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #1d2232;
    border: 1px solid rgba(117, 99, 70, 0.5);
    color: #aeafb0;
    font-size: 10px;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
}

.app-header .channel-selector-value {
    position: absolute;
    top: 7px;
    left: 26px;
    right: 20px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #aeafb0;
    font-size: 12px;
}

.app-header .channel-selector-chevron {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 4px solid #756346;
}

.app-header .channel-selector-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    min-width: 100%;
    background: #242a38;
    border: 1px solid rgba(117, 99, 70, 0.3);
    border-radius: 8px;
    display: none;
    z-index: 100;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}

.app-header .channel-selector-menu.open {
    display: block;
}

.app-header .channel-option {
    position: relative;
    width: 100%;
    height: 34px;
    border: 0;
    background: transparent;
    cursor: pointer;
    text-align: left;
    padding: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.app-header .channel-option:last-child {
    border-bottom: 0;
}

.app-header .channel-option-avatar {
    position: absolute;
    top: 7px;
    left: 8px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #1d2232;
    border: 1px solid rgba(117, 99, 70, 0.45);
    color: #aeafb0;
    font-size: 10px;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
}

.app-header .channel-option-text {
    position: absolute;
    top: 10px;
    left: 34px;
    color: #aeafb0;
    font-size: 12px;
}

.app-header .channel-option-add {
    color: #AFD15C;
    font-weight: 700;
    font-size: 12px;
    padding-left: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.app-header .channel-option-add:active {
    color: #c8e98a;
}

.app-header .channel-option:active {
    background: rgba(117, 99, 70, 0.12);
}

/* Справа: три круглые кнопки в один ряд */
.app-header .header-actions {
    flex-shrink: 0;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
}

.app-header .header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #756346, #9a8462);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.app-header .header-notification {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.app-header .header-notification svg {
    width: 18px;
    height: 18px;
    fill: #64748B;
}

.app-header .header-settings {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.app-header .header-settings svg {
    width: 18px;
    height: 18px;
    fill: #64748B;
}

/* 4. КОНТЕНТ - Единственное место, где работает палец */
.app-body {
    flex: 1; 
    overflow-y: auto !important; 
    -webkit-overflow-scrolling: touch;
    width: 100%;
    display: block;
    min-height: 0;
    overscroll-behavior: none;
    touch-action: pan-y;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.app-body::-webkit-scrollbar {
    display: none;
}

/* Слоты модулей (The Vault) */
.module-slot {
    width: calc(100% - 40px);
    margin: 0 auto 20px auto;
    padding: 20px;
    background: #242A38;
    border-radius: 8px;
    color: #fff;
}
.module-slot:first-of-type {
    margin-top: 20px;
}

/* 5. ПОДВАЛ — по скрину: полоска #363636, скругления по бокам, вырез под кнопку, кнопка с внутренним кругом */
.app-footer {
    flex: 0 0 75px;
    width: 100%;
    z-index: 100005;
    background: #282828;
    position: relative;
}

.app-footer .tab-bar {
    position: relative;
    display: -webkit-grid;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    height: 75px;
    width: 100%;
    z-index: 100;
    background: transparent;
}

.app-footer .tab-bar-bg {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 75px;
    pointer-events: none;
}

/* Картинка подвала (если есть img/footer-bar.png) — поверх fallback-SVG */
.app-footer .tab-bar-bg-img {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 75px;
    background-image: url('../img/footer-bar.png');
    background-size: 100% 100%;
    background-position: bottom center;
    background-repeat: no-repeat;
    z-index: 1;
}

.app-footer .tab-bar-bg-fallback,
.app-footer .tab-bar-bg svg {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 75px;
}

.app-footer .footer-block {
    display: -webkit-flex;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 1;
    min-width: 0;
}

.app-footer .footer-block-center {
    align-items: flex-end;
    padding-bottom: 4px;
}

.app-footer .tab-bar-item {
    display: -webkit-flex;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    padding: 6px 4px;
    margin: 0;
    border: none;
    background: transparent;
    font: inherit;
    color: #94a3b8;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.app-footer .tab-bar-item:focus {
    outline: none;
}

.app-footer .tab-bar-item:focus-visible {
    outline: 2px solid #3B82F6;
    outline-offset: 2px;
}

.app-footer .tab-bar-item svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
    margin-bottom: 4px;
}

.app-footer .tab-bar-item-label {
    font-size: 10px;
    font-weight: 500;
    color: inherit;
    text-align: center;
    line-height: 1.2;
}

.app-footer .tab-bar-item.active,
.app-footer .tab-bar-item.active .tab-bar-item-label {
    color: #3B82F6;
}

.app-footer .tab-bar-item.active svg {
    fill: currentColor;
}

.app-footer .tab-bar-item:active {
    color: #64748B;
}

.app-footer .tab-bar-item:active .tab-bar-item-label {
    color: inherit;
}

.app-footer .tab-bar-item:active svg {
    fill: currentColor;
}

.app-footer .action-hub-btn,
.app-footer #action-hub-btn {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    top: -30px;
    width: 56px;
    height: 56px;
    min-width: 44px;
    min-height: 44px;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: #3B82F6;
    box-shadow: 0 4px 14px rgba(59, 130, 246, 0.4);
    cursor: pointer;
    z-index: 101;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    -webkit-tap-highlight-color: transparent;
}

.app-footer .action-hub-btn-inner {
    position: absolute;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #DDEFFF;
    pointer-events: none;
}

.app-footer .action-hub-btn-icon,
.app-footer #action-hub-btn .action-hub-btn-icon {
    position: relative;
    z-index: 1;
    width: 28px;
    height: 28px;
    color: #3B82F6;
}

.app-footer .action-hub-btn:focus,
.app-footer #action-hub-btn:focus {
    outline: none;
}

.app-footer .action-hub-btn:focus-visible,
.app-footer #action-hub-btn:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.8);
    outline-offset: 2px;
}

.app-footer .action-hub-btn svg:not(.action-hub-btn-icon),
.app-footer #action-hub-btn svg:not(.action-hub-btn-icon) {
    width: 28px;
    height: 28px;
}

.app-footer .action-hub-btn:active,
.app-footer #action-hub-btn:active {
    transform: translateX(-50%) scale(0.95);
    background: #2563EB;
}

.app-footer .action-hub-btn:active .action-hub-btn-inner {
    background: #c8e3ff;
}
