/**
 * main.css - Базовые стили
 * Городской портал bgdportal.ru
 */

/* CSS переменные */
:root {
    /* Цветовая палитра - уральский индустриальный с теплыми акцентами */
    --color-primary: #2563eb;
    --color-primary-dark: #1d4ed8;
    --color-primary-light: #3b82f6;
    --color-secondary: #0f766e;
    --color-accent: #f59e0b;
    --color-accent-light: #fbbf24;
    
    /* Нейтральные цвета */
    --color-white: #ffffff;
    --color-gray-50: #f8fafc;
    --color-gray-100: #f1f5f9;
    --color-gray-200: #e2e8f0;
    --color-gray-300: #cbd5e1;
    --color-gray-400: #94a3b8;
    --color-gray-500: #64748b;
    --color-gray-600: #475569;
    --color-gray-700: #334155;
    --color-gray-800: #1e293b;
    --color-gray-900: #0f172a;
    
    /* Системные цвета */
    --color-success: #10b981;
    --color-warning: #f59e0b;
    --color-error: #ef4444;
    --color-info: #3b82f6;
    
    /* Типографика */
    --font-primary: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-display: 'Lora', Georgia, serif;
    
    /* Размеры шрифтов */
    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    --text-3xl: 1.875rem;
    --text-4xl: 2.25rem;
    --text-5xl: 3rem;
    
    /* Отступы */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --spacing-2xl: 3rem;
    --spacing-3xl: 4rem;
    
    /* Скругления */
    --radius-sm: 0.25rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-2xl: 1.5rem;
    --radius-full: 9999px;
    
    /* Тени */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    
    /* Переходы */
    --transition-fast: 150ms ease;
    --transition-base: 200ms ease;
    --transition-slow: 300ms ease;
    
    /* Ширина контейнера */
    --container-max: 1280px;
    --container-padding: 1rem;
}

/* Сброс стилей */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    overflow-x: hidden;
    max-width: 100%;
    background-color: #0f172a;
}

body {
    font-family: var(--font-primary);
    font-size: var(--text-base);
    line-height: 1.6;
    color: var(--color-gray-800);
    background-color: var(--color-white);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    /* Safe area для устройств с вырезом */
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* Базовые элементы */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.3;
    color: var(--color-gray-900);
}

h1 { font-size: var(--text-4xl); }
h2 { font-size: var(--text-3xl); }
h3 { font-size: var(--text-2xl); }
h4 { font-size: var(--text-xl); }
h5 { font-size: var(--text-lg); }
h6 { font-size: var(--text-base); }

p {
    margin-bottom: var(--spacing-md);
}

a {
    color: var(--color-primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--color-primary-dark);
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

ul, ol {
    list-style: none;
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
}

input, textarea, select {
    font-family: inherit;
    font-size: inherit;
}

/* Базовые стили текстовых полей — видимость на белом фоне */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="tel"],
input[type="url"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
textarea,
select {
    background-color: var(--color-gray-50);
    border: 1px solid var(--color-gray-300);
    color: var(--color-gray-800);
}

/* Контейнер */
.container {
    width: 100%;
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 0 var(--container-padding);
}

/* Секции */
.section {
    padding: var(--spacing-3xl) 0;
}

.section__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: var(--spacing-xl);
    gap: var(--spacing-lg);
}

.section__header--center {
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.section__title {
    font-size: var(--text-3xl);
    font-weight: 700;
    color: var(--color-gray-900);
}

.section__subtitle {
    font-size: var(--text-base);
    color: var(--color-gray-500);
    margin-top: var(--spacing-xs);
}

.section__link {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--color-primary);
    white-space: nowrap;
}

.section__link:hover {
    color: var(--color-primary-dark);
}

.section__link svg,
.section__link i {
    transition: transform var(--transition-fast);
}

.section__link:hover svg,
.section__link:hover i {
    transform: translateX(4px);
}

.section__footer {
    text-align: center;
    margin-top: var(--spacing-2xl);
}

/* Алерты */
.alert {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-radius: 0.5rem;
    font-size: 0.9375rem;
    margin-bottom: 1.5rem;
}

.alert i {
    font-size: 1.25rem;
    flex-shrink: 0;
    margin-top: 0.125rem;
}

.alert--success {
    background: #d1fae5;
    color: #065f46;
}

.alert--error {
    background: #fee2e2;
    color: #991b1b;
}

.alert--warning {
    background: #fef3c7;
    color: #92400e;
}

.alert--info {
    background: #dbeafe;
    color: #1e40af;
}

/* Пагинация */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.375rem;
    margin-top: 2rem;
}

.pagination__link {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 2.25rem;
    height: 2.25rem;
    padding: 0 0.625rem;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 0.375rem;
    color: #444;
    text-decoration: none;
    font-size: 0.875rem;
    transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.pagination__link:hover {
    background: #f0f4ff;
    border-color: #1a73e8;
    color: #1a73e8;
}

.pagination__link--active {
    background: #1a73e8;
    border-color: #1a73e8;
    color: #fff;
}

.pagination__link--active:hover {
    background: #1557b0;
    border-color: #1557b0;
    color: #fff;
}

/* Кнопки */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    padding: 0.75rem 1.5rem;
    font-size: var(--text-sm);
    font-weight: 500;
    line-height: 1;
    border-radius: var(--radius-lg);
    transition: all var(--transition-fast);
    cursor: pointer;
    text-decoration: none;
}

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

.btn--primary:hover {
    background: var(--color-primary-dark);
    color: var(--color-white);
}

.btn--outline {
    background: transparent;
    color: var(--color-primary);
    border: 1.5px solid var(--color-primary);
}

.btn--outline:hover {
    background: var(--color-primary);
    color: var(--color-white);
}

.btn--sm {
    padding: 0.5rem 1rem;
    font-size: var(--text-xs);
}

.btn--lg {
    padding: 1rem 2rem;
    font-size: var(--text-base);
}

.btn--full {
    width: 100%;
}

.btn--danger {
    background: var(--color-error);
    color: var(--color-white);
}

.btn--danger:hover {
    background: #dc2626;
}

.btn--outline.btn--danger {
    background: transparent;
    border-color: var(--color-error);
    color: var(--color-error);
}

.btn--outline.btn--danger:hover {
    background: var(--color-error);
    color: var(--color-white);
}

/* Адаптивность */
@media (max-width: 1024px) {
    :root {
        --text-5xl: 2.5rem;
        --text-4xl: 2rem;
        --text-3xl: 1.5rem;
    }
}

@media (max-width: 768px) {
    :root {
        --text-5xl: 2rem;
        --text-4xl: 1.75rem;
        --text-3xl: 1.375rem;
        --text-2xl: 1.25rem;
        --spacing-3xl: 3rem;
        --spacing-2xl: 2rem;
    }
    
    .section {
        padding: var(--spacing-2xl) 0;
    }
    
    .section__header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .section__title {
        font-size: var(--text-2xl);
    }
    
    h1 { font-size: var(--text-3xl); }
    h2 { font-size: var(--text-2xl); }
    h3 { font-size: var(--text-xl); }
}

@media (max-width: 480px) {
    :root {
        --container-padding: 1rem;
        --text-5xl: 1.75rem;
        --text-4xl: 1.5rem;
        --text-3xl: 1.25rem;
        --spacing-3xl: 2.5rem;
        --spacing-2xl: 1.5rem;
        --spacing-xl: 1.25rem;
    }
    
    .section {
        padding: var(--spacing-xl) 0;
    }
    
    .btn {
        padding: 0.625rem 1.25rem;
        font-size: var(--text-xs);
    }
    
    .btn--sm {
        padding: 0.5rem 1rem;
    }
}

/* Touch-friendly улучшения */
@media (hover: none) and (pointer: coarse) {
    a, button, .btn {
        min-width: 44px;
    }
    
    .nav__link {
        padding: var(--spacing-sm) var(--spacing-md);
    }
    
    /* Убираем hover-эффекты на touch, заменяем на active */
    .news-card:hover,
    .ad-card:hover,
    .event-card:hover,
    .org-category:hover,
    .info-card:hover {
        transform: none;
        box-shadow: var(--shadow-sm);
    }
    
    .news-card:active,
    .ad-card:active,
    .event-card:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }
    
    /* Увеличиваем зоны нажатия для ссылок и кнопок */
    .footer__menu a {
        padding: var(--spacing-sm) 0;
        min-height: 44px;
        display: flex;
        align-items: center;
    }
    
    .pagination__link {
        min-width: 44px;
        height: 44px;
    }
}

/* Предотвращение зума при фокусе на input (iOS) */
@media screen and (max-width: 768px) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    input[type="tel"],
    input[type="url"],
    input[type="number"],
    textarea,
    select {
        font-size: 16px !important;
    }
}

/* Горизонтальный скролл таблиц на мобильных */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

/* Мобильная фикс для 100vh (учитывает адресную строку браузера) */
.full-height-mobile {
    min-height: 100vh;
    min-height: 100dvh;
}

/* Скрытие скроллбара для горизонтальных контейнеров */
.scroll-hidden::-webkit-scrollbar {
    display: none;
}

.scroll-hidden {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

/* CSP-совместимые утилиты (замена inline style) */
[hidden] {
    display: none !important;
}

.settings-hint {
    color: var(--color-gray-600);
    font-size: var(--text-sm);
    margin-bottom: var(--spacing-lg);
}

.md-img {
    max-width: 100%;
    height: auto;
}

.md-center {
    text-align: center;
}

.md-code {
    background: var(--color-gray-100);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
}

.form-inline {
    display: inline;
}

/* Мобильные утилиты */
@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
    
    /* Стек-лейаут для мобильных */
    .mobile-stack {
        flex-direction: column !important;
    }
    
    .mobile-full {
        width: 100% !important;
    }
}

@media (min-width: 769px) {
    .show-mobile-only {
        display: none !important;
    }
}

/* Оптимизация анимаций для слабых устройств */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Выделение текста на мобильных */
@media (max-width: 768px) {
    .no-select-mobile {
        -webkit-user-select: none;
        user-select: none;
    }
}

/* Фикс для overscroll на iOS */
@media (max-width: 900px) {
    body.menu-open {
        position: fixed;
        width: 100%;
        overflow: hidden;
    }
}

/* Скелетон-загрузка для AJAX-блоков */
@keyframes skeleton-pulse {
    0% { opacity: 1; }
    50% { opacity: 0.4; }
    100% { opacity: 1; }
}

.skeleton {
    background: var(--color-gray-200);
    border-radius: var(--radius-sm);
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}

.skeleton--text {
    height: 0.875rem;
    width: 60%;
}

.skeleton--circle {
    border-radius: 50%;
}

.skeleton--rounded {
    border-radius: var(--radius-md);
}

/* Скелетон для виджета погоды */
.weather-widget .skeleton--temp {
    display: inline-block;
    width: 3em;
    height: 1em;
    vertical-align: middle;
}

/* Плейсхолдер для lazy-загружаемых изображений */
img[loading="lazy"] {
    background: var(--color-gray-100);
}
