:root {
    --bg: var(--tg-theme-bg-color, #ffffff);
    --text: var(--tg-theme-text-color, #222222);
    --hint: var(--tg-theme-hint-color, #888888);
    --accent: var(--tg-theme-button-color, #2481cc);
    --accent-text: var(--tg-theme-button-text-color, #ffffff);
    --sec-bg: var(--tg-theme-secondary-bg-color, #2c2c2e);
    --danger: #e84545;
}

/* База */

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

html,
body {
    height: 100%;
}

body {
    margin: 0;
    padding: 0;
    font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", Arial;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    -webkit-tap-highlight-color: transparent;
}

h1,
h2,
h3,
h4 {
    margin: 0 0 6px;
    font-weight: 600;
}

/* Контейнер */

.container {
    max-width: 460px;
    margin: 0 auto;
    padding: 16px 16px 18px;
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Верхняя часть (если будете использовать заголовок) */

.page-header {
    margin-bottom: 6px;
}

.page-title {
    font-size: 17px;
    font-weight: 600;
    margin: 0 0 2px;
}

.page-subtitle {
    margin: 0;
    font-size: 13px;
    color: var(--hint);
}

/* Верхние табы */

.tabs {
    display: flex;
    border-bottom: 1px solid var(--sec-bg);
    margin-bottom: 12px;
}

.tab {
    flex: 1;
    text-align: center;
    padding: 9px 4px;
    cursor: pointer;
    color: var(--hint);
    font-weight: 500;
    font-size: 14px;
    user-select: none;
    transition:
        color .12s ease,
        border-color .12s ease,
        background .12s ease;
    border-bottom: 2px solid transparent;
}

.tab.active {
    color: var(--text);
    border-bottom-color: var(--accent);
}

/* Внутренние табы во вкладке "Мои заявки" */

#tickets .tabs {
    margin-top: 8px;
}

/* Секции */

.section {
    display: none;
}

.section.active {
    display: block;
    animation: fade .16s ease;
}

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

/* Вкладки как полноэкранные области */

#support.section.active {
    display: block;
}

#tickets.section.active {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1;
}

/* Маленький текст */

.small {
    font-size: 13px;
    color: var(--hint);
}

/* Инфоблок (если используется) */

.info-card {
    margin-bottom: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--sec-bg);
    font-size: 13px;
}

.info-card-title {
    margin: 0 0 4px;
    font-size: 14px;
    font-weight: 600;
}

/* Список пунктов (меню, темы) */

.list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.item {
    background: var(--sec-bg);
    border-radius: 10px;
    padding: 10px 12px;
    text-align: left;
    cursor: pointer;
    transition: background .12s ease, transform .06s ease;
    border: none;
    width: 100%;
}

.item strong {
    display: block;
    margin-bottom: 2px;
    font-weight: 600;
    font-size: 15px;
}

.item .hint {
    color: var(--hint);
    font-size: 13px;
}

.item:hover {
    background: color-mix(in srgb, var(--sec-bg) 85%, var(--accent));
}

.item:active {
    transform: translateY(1px);
}

/* Поля формы */

.field {
    margin-bottom: 10px;
}

.field-label {
    display: block;
    margin-bottom: 4px;
    font-size: 13px;
    font-weight: 500;
}

.field-hint {
    font-size: 12px;
    color: var(--hint);
}

.field-error {
    margin-top: 4px;
    font-size: 12px;
    color: var(--danger);
}

textarea,
input {
    width: 100%;
    border: 1px solid color-mix(in srgb, var(--sec-bg) 60%, black);
    border-radius: 8px;
    padding: 9px 10px;
    font: inherit;
    background: var(--sec-bg);
    color: var(--text);
    outline: none;
    transition:
        border-color .12s ease,
        background .12s ease;
}

textarea {
    min-height: 90px;
    resize: vertical;
}

input::placeholder,
textarea::placeholder {
    color: color-mix(in srgb, var(--hint) 90%, #000);
}

input:focus-visible,
textarea:focus-visible {
    border-color: var(--accent);
    background: var(--bg);
}

/* Кнопки */

.button {
    display: block;
    width: 100%;
    border: none;
    border-radius: 8px;
    padding: 11px 14px;
    margin-top: 10px;
    background: var(--accent);
    color: var(--accent-text);
    font-weight: 500;
    font-size: 15px;
    cursor: pointer;
    transition:
        opacity .12s ease,
        transform .06s ease;
}

.button:hover {
    opacity: .95;
}

.button:active {
    transform: translateY(1px);
    opacity: .9;
}

.button.secondary {
    background: var(--sec-bg);
    color: var(--text);
}

.button:disabled,
.button[disabled] {
    opacity: .6;
    cursor: default;
}

/* Тикеты в "Мои заявки" */

#ticketsListView {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

#listActive,
#listClosed {
    margin-top: 6px;
}

.ticket {
    background: var(--sec-bg);
    border-radius: 10px;
    padding: 10px 12px;
    margin-top: 8px;
    cursor: pointer;
    transition: background .12s ease, transform .06s ease;
}

.ticket:hover {
    background: color-mix(in srgb, var(--sec-bg) 85%, var(--accent));
}

.ticket:active {
    transform: translateY(1px);
}

.ticket h4 {
    margin: 0 0 2px;
    font-size: 15px;
    font-weight: 600;
}

.ticket-subject {
    font-size: 13px;
}

.ticket-meta {
    margin-top: 2px;
    font-size: 12px;
    color: var(--hint);
    display: flex;
    justify-content: space-between;
    gap: 6px;
}

/* Бейдж статуса */

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 11px;
    border: 1px solid color-mix(in srgb, var(--sec-bg) 50%, black);
}

.badge.status-open {
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 12%, var(--bg));
}

.badge.status-closed {
    color: var(--hint);
    background: color-mix(in srgb, var(--sec-bg) 80%, var(--bg));
}

/* Пустые состояния */

.empty-state {
    text-align: center;
    padding: 24px 10px 8px;
    font-size: 14px;
    color: var(--hint);
}

.empty-state-icon {
    font-size: 24px;
    margin-bottom: 4px;
}

/* Чат — контейнер (полноэкранно внутри вкладки) */

.chat-box {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    margin-top: 12px;
}

/* Шапка чата */

.chat-header {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center; /* центрируем заголовок */
    margin-bottom: 6px;
    /* gap можно убрать, он не нужен при absolute-кнопке */
}

.chat-header-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    text-align: center;       /* текст ровно по центру */
}

/* Специально для кнопки назад в шапке чата */
.chat-header .back-link {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
}

#chatTitle {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
}

.chat-status {
    font-size: 12px;
    color: var(--hint);
}

/* Область сообщений — без отдельной "карты", как в Telegram */

.chat {
    flex: 1;
    min-height: 0;
    padding: 4px 0;
    background: transparent;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* Скроллбар в чате */

.chat::-webkit-scrollbar {
    width: 4px;
}

.chat::-webkit-scrollbar-track {
    background: transparent;
}

.chat::-webkit-scrollbar-thumb {
    background: color-mix(in srgb, var(--hint) 40%, transparent);
    border-radius: 999px;
}

/* Сообщения */

.msg {
    display: inline-block;
    margin: 2px 8px;
    padding: 6px 8px 4px;
    border-radius: 14px;
    max-width: 80%;
    font-size: 14px;
    word-wrap: break-word;
}

.msg.user {
    background: var(--accent);
    color: var(--accent-text);
    margin-left: auto;
    margin-right: 8px;
    border-bottom-right-radius: 4px;
}

.msg.sys {
    background: var(--sec-bg);
    color: var(--text);
    margin-right: auto;
    margin-left: 8px;
    border-bottom-left-radius: 4px;
}

.msg-time {
    display: block;
    margin-top: 2px;
    font-size: 11px;
    opacity: .8;
    text-align: right;
}

/* Разделитель (дата и т.п.) */

.chat-separator {
    align-self: center;
    margin: 6px 0;
    padding: 3px 8px;
    font-size: 11px;
    color: var(--hint);
    border-radius: 999px;
    background: color-mix(in srgb, var(--sec-bg) 85%, var(--bg));
}

/* Строка ввода сообщения — как в Telegram */

.chat-input-row {
    margin-top: 8px;
}

.chat-input-shell {
    position: relative;
    width: 100%;
    border-radius: 22px;
    background: var(--sec-bg);
    border: 1px solid color-mix(in srgb, var(--sec-bg) 60%, black);
    padding: 8px 44px 8px 12px;
    display: flex;
    align-items: center;
}

.chat-input-shell textarea {
    border: none;
    background: transparent;
    resize: none;
    width: 100%;
    min-height: 24px;
    max-height: 80px;
    padding: 0;
    margin: 0;
    font: inherit;
    color: var(--text);
    outline: none;
}

.chat-input-shell textarea::placeholder {
    color: color-mix(in srgb, var(--hint) 90%, #000);
}

.chat-send-icon {
    position: absolute;
    right: 8px;
    bottom: 6px;
    width: 30px;
    height: 30px;
    border-radius: 999px;
    border: none;
    background: var(--accent);
    color: var(--accent-text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 15px;
    padding: 0;
}

.chat-send-icon:active {
    transform: translateY(1px);
    opacity: .9;
}

.chat-send-icon-arrow {
    transform: translateX(1px);
}

/* Нижняя строка чата: подсказка + индикатор отправки */

.chat-footer-row {
    margin-top: 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

/* Индикатор "Отправка..." */

.inline-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--hint);
}

.spinner {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid color-mix(in srgb, var(--hint) 30%, transparent);
    border-top-color: var(--accent);
    animation: spin .7s linear infinite;
}

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

/* Кнопки "назад" */

.back-row {
    margin-bottom: 6px;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0;
    border: none;
    background: transparent;
    font: inherit;
    font-size: 14px;
    color: var(--accent);
    cursor: pointer;
}

.back-link:active {
    transform: translateY(1px);
    opacity: 0.85;
}

/* Низ страницы (если нужен) */

.page-footer {
    margin-top: 14px;
    text-align: center;
    font-size: 11px;
    color: var(--hint);
}

/* Адаптив */

@media (max-width: 420px) {
    .container {
        padding: 12px 12px 16px;
    }
}
