/* Без горизонтальной прокрутки при увеличении масштаба */
html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

/* Унифицированный заголовок страницы — название сверху, навигация ниже */
.page-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 20px;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid rgba(0,0,0,0.08);
}
html.theme-dark .page-header {
    border-bottom-color: rgba(255,255,255,0.1);
}
.page-title {
    margin: 0;
    font-size: 1.9rem;
    font-weight: 600;
    width: 100%;
}
.page-controls {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 12px;
}
.page-header .back-btn {
    padding: 10px 20px;
    font-size: 1rem;
}

/* Контейнер — без горизонтального переполнения */
.container {
    max-width: 100%;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    padding: 0 15px;
    box-sizing: border-box;
}

/* Глобальный блок навигации — одинаковое отображение на всех страницах */
.global-nav {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: #666;
    margin-left: auto;
    margin-right: auto;
}
.global-nav-user {
    font-size: 0.95rem;
    margin-bottom: 2px;
}
.global-nav-links {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}
/* Строка кнопок навигации */
.global-nav-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 12px;
}
/* Обёртка каждой кнопки — гарантирует отступ между кнопками */
.global-nav-row .nav-btn-wrap {
    display: inline-flex;
    margin: 0 6px;
    flex-shrink: 0;
}
.global-nav-row .btn,
.global-nav-row a.btn {
    margin: 0;
    padding: 12px 24px;
    font-size: 1.05rem;
}

/* Область заголовка с навигацией и доп. элементами (select и т.д.) */
.header-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

/* Кнопки навигации (блок ссылок на всех страницах) */
.btn {
    padding: 8px 16px;
    background: #667eea;
    color: white;
    text-decoration: none;
    border-radius: 5px;
    font-size: 14px;
    display: inline-block;
    transition: background 0.3s;
    border: none;
    cursor: pointer;
}
.btn:hover {
    background: #5568d3;
}
.btn-danger {
    background: #e74c3c;
}
.btn-danger:hover {
    background: #c0392b;
}

/* Базовый размер шрифта для всего сайта — крупнее для читаемости */
html {
    font-size: 20px;
}
body {
    font-size: 1rem;
}
table {
    font-size: 1.05rem;
}

/* Таблицы — прокрутка внутри блока, без горизонтальной прокрутки страницы */
.table-wrapper {
    overflow-x: auto;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
}
.table-wrapper table {
    min-width: 0;
    width: 100%;
    table-layout: fixed;
    font-size: 1.05rem;
}
.table-wrapper th,
.table-wrapper td {
    white-space: normal;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* На мобильных — включаем горизонтальную прокрутку, чтобы заголовки не ломались по буквам */
@media (max-width: 768px) {
    .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .table-wrapper table {
        table-layout: auto;
        min-width: 900px;
    }
    .table-wrapper th,
    .table-wrapper td {
        white-space: nowrap;
    }
}
h1 { font-size: 1.9rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.3rem; }
.period-selector a,
.btn,
.pagination a,
.pagination span,
select,
input[type="text"],
input[type="password"] {
    font-size: 1.05rem;
}

/* Тёмная тема для TG Analytics */
html.theme-dark body {
    background: #1a1a2e;
    color: #e8e8e8;
}
html.theme-dark .container {
    background: #16213e;
    box-shadow: 0 2px 15px rgba(0,0,0,0.3);
}
html.theme-dark h1,
html.theme-dark h2,
html.theme-dark h3 {
    color: #e8e8e8;
}
html.theme-dark .user-info,
html.theme-dark .global-nav,
html.theme-dark .global-nav-user,
html.theme-dark .pagination-info,
html.theme-dark .stats li {
    color: #b8b8d1;
}
html.theme-dark .stats {
    background: #1a1a2e;
}
html.theme-dark .stats li {
    background: #16213e;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
html.theme-dark table {
    color: #e8e8e8;
}
html.theme-dark th {
    background: #1a1a2e !important;
    color: #e8e8e8 !important;
    border-bottom-color: #2a2a4a !important;
}
html.theme-dark td {
    border-bottom-color: #2a2a4a !important;
}
html.theme-dark tr:hover {
    background: #1a1a2e !important;
}
html.theme-dark a {
    color: #7c9cff;
}
html.theme-dark a:hover {
    color: #9db4ff;
}
html.theme-dark .back-link {
    color: #7c9cff;
}
html.theme-dark .period-selector a {
    background: #3d5a9e;
    color: #e8e8e8;
}
html.theme-dark .period-selector a:hover,
html.theme-dark .period-selector a.active {
    background: #4d6ab8;
}
html.theme-dark .btn,
html.theme-dark .nav-links a,
html.theme-dark .back-btn {
    background: #3d5a9e;
    color: #e8e8e8;
}
html.theme-dark .back-btn:hover {
    background: #4d6ab8;
}
html.theme-dark .btn:hover,
html.theme-dark .nav-links a:hover {
    background: #4d6ab8;
}
html.theme-dark .btn-danger {
    background: #8b3a3a;
}
html.theme-dark .btn-danger:hover {
    background: #a04545;
}
html.theme-dark .pagination a,
html.theme-dark .pagination span {
    border-color: #2a2a4a;
    background: #16213e;
    color: #e8e8e8;
}
html.theme-dark .pagination a:hover {
    background: #3d5a9e;
    border-color: #3d5a9e;
}
html.theme-dark .pagination .current {
    background: #3d5a9e !important;
    border-color: #3d5a9e !important;
}
html.theme-dark .pagination .disabled {
    background: #1a1a2e !important;
    color: #666 !important;
}
html.theme-dark select {
    background: #16213e;
    color: #e8e8e8;
    border-color: #2a2a4a;
}
html.theme-dark label {
    color: #b8b8d1;
}
html.theme-dark .sortable,
html.theme-dark th.sort-asc,
html.theme-dark th.sort-desc {
    color: #e8e8e8 !important;
}

/* Блоки под графиками (Начало, Конец, Прирост и т.д.) */
.chart-summary-box {
    background: #fff;
    color: #333;
}
.chart-summary-green {
    background: #d4edda;
}
.chart-summary-blue {
    background: #cce5ff;
}
.chart-summary-gray {
    background: #e9ecef;
}

/* Тёмная тема */
html.theme-dark .chart-summary-box {
    background: #1a1a2e !important;
    color: #e8e8e8 !important;
    border: 1px solid #2a2a4a;
}
html.theme-dark .chart-summary-box strong {
    color: #e8e8e8 !important;
}
html.theme-dark .chart-summary-box span {
    color: #e8e8e8 !important;
}
html.theme-dark .chart-summary-green {
    background: #1e3a2f !important;
    border-color: #2d5a47;
}
html.theme-dark .chart-summary-blue {
    background: #1e2a3a !important;
    border-color: #2d4a6a;
}
html.theme-dark .chart-summary-gray {
    background: #252540 !important;
    border-color: #2a2a4a;
}

/* Страница входа */
html.theme-dark .login-box {
    background: #16213e;
    box-shadow: 0 10px 40px rgba(0,0,0,0.4);
}
html.theme-dark .login-box h1 {
    color: #e8e8e8;
}
html.theme-dark .login-box label {
    color: #b8b8d1;
}
html.theme-dark .login-box input[type="text"],
html.theme-dark .login-box input[type="password"] {
    background: #1a1a2e;
    color: #e8e8e8;
    border-color: #2a2a4a;
}
html.theme-dark .login-box button {
    background: #3d5a9e;
}
html.theme-dark .login-box button:hover {
    background: #4d6ab8;
}

/* Админка — тёмная тема */
html.theme-dark .section {
    background: #1a1a2e;
    color: #e8e8e8;
}
html.theme-dark .section h2 {
    color: #e8e8e8;
}
html.theme-dark .section label {
    color: #b8b8d1;
}
html.theme-dark .section input[type="text"],
html.theme-dark .section input[type="password"],
html.theme-dark .section select {
    background: #16213e;
    color: #e8e8e8;
    border-color: #2a2a4a;
}
html.theme-dark .section table {
    color: #e8e8e8;
}
html.theme-dark .section th {
    background: #16213e !important;
    color: #e8e8e8 !important;
    border-bottom-color: #2a2a4a !important;
}
html.theme-dark .section td {
    border-bottom-color: #2a2a4a !important;
    color: #e8e8e8;
}
html.theme-dark .section tr:hover {
    background: #16213e !important;
}
/* Модальное окно смены пароля */
html.theme-dark .modal-content {
    background: #16213e;
    color: #e8e8e8;
}
html.theme-dark .modal-content h2 {
    color: #e8e8e8;
}
html.theme-dark .modal-content label {
    color: #b8b8d1;
}
html.theme-dark .modal-content input[type="password"] {
    background: #1a1a2e;
    color: #e8e8e8;
    border-color: #2a2a4a;
}
html.theme-dark .modal-close {
    color: #b8b8d1;
}
html.theme-dark .modal-close:hover {
    color: #e8e8e8;
}
