/* ==========================================================================
   TrackPlus — Mobile Optimizations
   ========================================================================== */

/* ---------- Стилизация выпадающих списков (Select) ---------- */

select {
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    appearance: none !important;
    background-color: rgba(255, 255, 255, 0.08) !important; /* Стеклянный фон */
    color: inherit !important; /* Наследуем цвет текста от темы */
    border: 1px solid rgba(128, 128, 128, 0.3) !important; /* Тонкая рамка */
    border-radius: 8px !important; /* Скругление */
    padding: 8px 32px 8px 12px !important; /* Место под стрелочку */
    font-family: inherit !important;
    font-size: 14px !important;
    cursor: pointer;
    outline: none !important;
    /* Кастомная стрелочка вниз (SVG) */
    background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23cccccc' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 10px center !important;
    background-size: 14px !important;
}

select:focus {
    border-color: rgba(128, 128, 128, 0.6) !important;
    background-color: rgba(255, 255, 255, 0.12) !important;
}

/* Стилизация самих пунктов списка (работает на Windows и Android) */
select option {
    background-color: #1e1e24 !important; /* Темный фон списка */
    color: #ffffff !important;
    padding: 10px !important;
}

/* ---------- Стили для экрана Статистики (Месячный график) ---------- */

.monthly-chart-section {
    margin-top: 24px;
    margin-bottom: 24px;
    padding: 20px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.monthly-chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}

.monthly-chart-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: inherit;
}

.monthly-chart-controls {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.month-select {
    padding: 6px 30px 6px 10px !important;
    font-size: 13px !important;
}

.monthly-chart-container {
    width: 100%;
    height: 250px;
    position: relative;
}

/* ---------- Стили для СВЕРНУТОГО сайдбара на ПК ---------- */
@media (min-width: 769px) {
    .sidebar.collapsed .glass-title {
        width: 44px !important;
        height: 44px !important;
        padding: 0 !important;
        border-radius: 50% !important; /* Идеальный круг */
        margin: 0 auto !important; /* Центрируем */
        gap: 0 !important;
    }

    .sidebar.collapsed .glass-title .logo-icon,
    .sidebar.collapsed .glass-title .full-text {
        display: none !important; /* Скрываем иконку и полный текст */
    }

    .sidebar.collapsed .glass-title .short-text {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        width: 100% !important;
        height: 100% !important;
        font-size: 18px !important;
        font-weight: 700 !important;
        margin: 0 !important;
    }

    .sidebar.collapsed .sidebar-title {
        padding: 16px 0 !important; /* Убираем боковые отступы у шапки */
    }
}

/* ---------- Глобальные фиксы ---------- */

/* Полностью убираем любые фоны, размытия и тени у шапки */
.sidebar-title {
    position: sticky !important;
    top: 0 !important;
    z-index: 1000 !important;
    background: transparent !important; /* Никаких цветов */
    background-color: transparent !important;
    backdrop-filter: none !important; /* Убираем размытие, которое давало квадрат */
    -webkit-backdrop-filter: none !important;
    box-shadow: none !important;
    border: none !important;
    padding: 12px 10px 8px 10px !important; /* Уменьшили отступ сверху */
    margin-bottom: 0 !important;
    display: flex !important;
    justify-content: center !important;
}

/* Стиль логотипа: строгая капсула без фона */
.glass-title {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 10px !important;
    padding: 8px 24px !important;
    background: transparent !important; /* Абсолютно прозрачно */
    background-color: transparent !important;
    border: 1px solid rgba(128, 128, 128, 0.3) !important; /* Только тонкая рамка */
    border-radius: 16px !important;
    box-shadow: none !important; /* Без теней */
    cursor: default;
}

/* Размер и скругление иконки */
.logo-icon {
    width: 32px !important;
    height: 32px !important;
    object-fit: contain !important;
    border-radius: 8px !important;
    margin: 0 !important;
}

.glass-title .full-text,
.glass-title .short-text {
    font-weight: 700 !important;
    font-size: 22px !important;
    letter-spacing: 0.5px !important;
    color: inherit !important;
}

/* Скрываем меню данных и тем в сайдбаре на ПК */
@media (min-width: 769px) {
    .sidebar-data-section,
    .sidebar-themes-section {
        display: none !important;
    }
}

/* Стили для выпадающего меню в хедере */
.header-data-selector {
    display: inline-block;
}

#header-data-dropdown .nav-item {
    padding: 8px 12px;
    margin: 2px 0;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    white-space: nowrap;
}

#header-data-dropdown .nav-item:hover {
    background: rgba(128, 128, 128, 0.15);
}

/* ---------- Базовые вещи ---------- */

@media (max-width: 768px) {
    /* Скрываем меню данных и тем в хедере на мобилках */
    .header-data-selector,
    .header-theme-selector {
        display: none !important;
    }

    input, select, textarea,
    .add-task-input, .search-input, .date-input,
    .folder-name-input, .folder-select, .repeat-select, .sort-select {
        font-size: 16px !important;
    }

    body {
        padding-left: env(safe-area-inset-left, 0);
        padding-right: env(safe-area-inset-right, 0);
        grid-template-columns: 1fr !important;
    }

    .sidebar {
        padding-top: max(8px, env(safe-area-inset-top));
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }

    .task-item:hover,
    .btn:hover,
    .icon-btn:hover,
    .nav-item:hover {
        background: inherit;
        filter: none;
    }
    
    .monthly-chart-container {
        height: 200px;
    }
    
    .monthly-chart-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .monthly-chart-controls {
        width: 100%;
    }
    
    .monthly-chart-controls select {
        flex: 1;
    }
}

/* ---------- Сайдбар → off-canvas drawer ---------- */

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 85vw;
        max-width: 320px;
        transform: translateX(-100%);
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 1000;
        height: 100vh;
        height: 100dvh;
        display: flex !important;
        flex-direction: column !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
        padding-bottom: 30px !important;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    /* Отменяем мини-режим для мобилок */
    .sidebar.collapsed {
        width: 85vw !important;
        max-width: 320px !important;
    }

    /* ПРИНУДИТЕЛЬНО показываем весь текст в меню на мобилке */
    .sidebar .nav-text,
    .sidebar .header-controls,
    .sidebar .nav-count {
        display: inline-block !important;
        opacity: 1 !important;
        visibility: visible !important;
        color: inherit !important;
        font-size: 15px !important;
    }
    
    .sidebar.collapsed .full-text { display: inline-block !important; }
    .sidebar.collapsed .short-text { display: none !important; }

    /* Базовые отступы и Flexbox для всех строк меню */
    .sidebar .nav-item,
    .sidebar .lists-header {
        display: flex !important;
        align-items: center !important;
        justify-content: flex-start !important;
        padding: 14px 16px !important; 
        width: 100% !important;
        box-sizing: border-box !important;
        gap: 12px !important;
    }

    /* --- 1. ЗАГОЛОВКИ СЕКЦИЙ (ПАПКИ, ТЕГИ, ТЕМЫ) --- */
    
    /* Текст заголовка занимает всё свободное место и прижимает кнопки вправо */
    .lists-header > .nav-text:not(.header-controls) {
        flex: 1 1 auto !important;
        text-align: left !important;
        font-weight: 700 !important;
        text-transform: uppercase !important;
        letter-spacing: 0.5px !important;
        margin: 0 !important;
        white-space: nowrap !important;
    }

    /* Иконка заголовка */
    .lists-header > .nav-icon {
        width: 24px !important;
        min-width: 24px !important;
        text-align: center !important;
        display: flex !important;
        justify-content: center !important;
        flex-shrink: 0 !important;
    }

    /* Контейнер с кнопками + и ▼ жестко справа */
    .lists-header .header-controls {
        flex: 0 0 auto !important; /* не растягивается */
        margin-left: auto !important; /* прижимается вправо */
        display: flex !important;
        align-items: center !important;
        gap: 8px !important;
        background: transparent !important;
        padding: 0 !important;
        width: auto !important;
    }

    /* Сами кнопки (размер 36x36px) */
    .lists-header .btn-icon-sm {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        min-height: 36px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        font-size: 16px !important;
        padding: 0 !important;
        margin: 0 !important;
        border-radius: 8px !important;
    }

    /* --- 2. ПУНКТЫ МЕНЮ (Все задачи, Важное и т.д.) --- */

    .sidebar .nav-item .nav-icon {
        width: 24px !important;
        min-width: 24px !important;
        text-align: center !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        font-size: 18px !important;
        flex-shrink: 0 !important;
    }

    /* Текст пункта занимает всё место */
    .sidebar .nav-item > .nav-text:not(.nav-count):not(.overdue-badge) {
        flex: 1 1 auto !important;
        text-align: left !important;
        opacity: 1 !important;
        color: inherit !important;
        margin: 0 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }

    /* Цифры в аккуратных кружочках строго справа */
    .sidebar .nav-count {
        flex: 0 0 auto !important; /* фиксированный размер */
        margin-left: auto !important; /* прижимается вправо */
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        min-width: 24px !important;
        height: 24px !important;
        padding: 0 6px !important;
        border-radius: 12px !important; /* круглая/овальная форма */
        font-size: 12px !important;
        font-weight: 600 !important;
        box-sizing: border-box !important;
        width: auto !important;
        text-align: center !important;
    }
    
    /* Красный бейдж просрочки (если есть) */
    .sidebar .overdue-badge {
        flex: 0 0 auto !important;
        margin-right: 4px !important;
    }

    /* ФИКС ЦВЕТА ТЕМ: заставляем пункты тем игнорировать свои data-theme цвета */
    .sidebar .theme-sidebar-item,
    .sidebar .theme-sidebar-item .nav-text,
    .sidebar .theme-sidebar-item .nav-icon {
        color: inherit !important;
    }

    /* Закрывающий оверлей */
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        opacity: 0;
        transition: opacity 0.28s ease;
    }

    .sidebar-overlay.visible {
        display: block;
        opacity: 1;
    }

    body.sidebar-is-open {
        overflow: hidden;
        overscroll-behavior: none;
    }

    .main {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100vw;
    }

    .sidebar-footer {
        display: none;
    }
}

/* ---------- Кнопка-гамбургер ---------- */

.mobile-menu-btn {
    display: none;
}

@media (max-width: 768px) {
    .mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        font-size: 22px;
        background: transparent;
        border: 1px solid rgba(128, 128, 128, 0.25);
        border-radius: 10px;
        cursor: pointer;
        flex-shrink: 0;
        order: -1;
        color: inherit;
        padding: 0;
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-menu-btn:active {
        background: rgba(128, 128, 128, 0.15);
    }
}

/* ---------- Хедер ---------- */

@media (max-width: 768px) {
    .header {
        position: relative;
        flex-wrap: wrap;
        gap: 8px;
        padding: 8px 10px;
        align-items: center;
    }

    .header-left {
        flex: 1 1 100%;
        flex-wrap: wrap;
        gap: 6px;
        align-items: center;
        min-width: 0;
    }

    .header-title {
        font-size: 18px;
        flex: 1 1 auto;
        order: 1;
        margin: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        min-width: 0;
    }

    .search-box {
        flex: 1 1 100%;
        order: 2;
        margin-top: 2px;
    }

    .header-actions {
        flex: 1 1 100%;
        flex-wrap: wrap;
        gap: 6px;
        align-items: center;
    }

    .header-actions > * {
        flex: 0 1 auto;
    }

    .header-actions .btn {
        padding: 8px 10px;
        font-size: 13px;
        min-height: 40px;
    }

    .sort-select {
        font-size: 13px;
        padding: 6px 8px;
        min-height: 40px;
    }
}

/* ---------- Контент и задачи ---------- */

@media (max-width: 768px) {
    .content { padding: 8px; }
    .task-item { padding: 10px 12px; gap: 8px; border-radius: 12px; }
    .task-title { font-size: 15px; word-break: break-word; }
    .task-checkbox, .batch-checkbox { width: 24px; height: 24px; min-width: 24px; cursor: pointer; }
    .task-content { min-width: 0; gap: 4px; }
    .task-meta { flex-wrap: wrap; gap: 4px; }
    .task-meta > * { font-size: 12px; }
    .task-tags { flex-wrap: wrap; gap: 4px; }
    .task-tag { font-size: 11px; padding: 2px 8px; }
    .task-actions { flex-direction: column; gap: 2px; flex-shrink: 0; }
    .task-actions .icon-btn { width: 36px; height: 36px; min-width: 36px; font-size: 16px; padding: 0; }
    .task-actions .icon-btn:not(.delete):not(.star) { display: none; }
    .date-input { min-height: 36px; }
}

/* ---------- Панель добавления задачи ---------- */

@media (max-width: 768px) {
    .add-task-area { padding: 8px 10px; border-radius: 12px; }
    .add-task-form { flex-direction: column; gap: 8px; }
    .add-task-input { width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 10px; }
    .add-task-actions { flex-wrap: wrap; gap: 6px; width: 100%; }
    .add-task-actions > * { flex: 1 1 auto; min-height: 40px; min-width: 0; }
    .add-task-actions .folder-select, .add-task-actions .repeat-select { flex: 1 1 calc(50% - 3px); }
    .add-task-actions .date-input { flex: 1 1 calc(50% - 3px); min-width: 0; }
    .add-task-actions .btn { padding: 8px 10px; font-size: 14px; }
}

/* ---------- Модальные окна → bottom-sheet ---------- */

@media (max-width: 768px) {
    .modal { padding: 0; align-items: flex-end; }
    .modal-content { width: 100%; max-width: 100%; max-height: 92vh; max-height: 92dvh; margin: 0; border-radius: 20px 20px 0 0; padding-bottom: env(safe-area-inset-bottom, 0); }
    .modal-sm { width: 100%; max-width: 100%; }
    .modal-body { max-height: 60vh; max-height: 60dvh; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px; }
    .modal-header h3 { font-size: 17px; }
    .modal-footer { padding: 12px 14px; flex-wrap: wrap; gap: 8px; }
    .modal-footer .btn { min-height: 44px; flex: 1 1 auto; }
    .color-option { width: 36px; height: 36px; }
    .folder-name-input { min-height: 44px; padding: 10px 12px; }
}

/* ---------- Контекстное меню ---------- */

@media (max-width: 768px) {
    .context-menu { min-width: 220px; max-width: calc(100vw - 16px); border-radius: 14px; padding: 6px; font-size: 15px; }
    .context-menu-item { padding: 12px 14px; min-height: 44px; font-size: 15px; border-radius: 8px; }
    .context-menu-icon { font-size: 18px; margin-right: 10px; }
    .context-menu-separator { margin: 4px 0; }
    .folder-dot, .tag-dot { width: 14px; height: 14px; min-width: 14px; }
}

/* ---------- Массовые действия ---------- */

@media (max-width: 768px) {
    .batch-toolbar { flex-wrap: wrap; gap: 8px; padding: 8px 10px; position: relative; }
    .batch-info { flex: 1 1 100%; display: flex; align-items: center; gap: 8px; }
    .batch-actions { flex: 1 1 100%; flex-wrap: wrap; gap: 6px; }
    .batch-actions .btn { flex: 1 1 calc(33% - 4px); min-height: 40px; padding: 8px; font-size: 13px; }
    .batch-close { position: absolute; top: 8px; right: 8px; width: 36px; height: 36px; }
}

/* ---------- Статистика ---------- */

@media (max-width: 768px) {
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .stat-card { padding: 12px; }
    .stat-value { font-size: 24px; }
    .stat-label { font-size: 12px; }
    .heatmap-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 8px; }
    .heatmap-wrapper { min-width: max-content; }
}

/* ---------- Уведомления ---------- */

@media (max-width: 768px) {
    .notification { left: 8px !important; right: 8px !important; bottom: max(8px, env(safe-area-inset-bottom)) !important; max-width: none !important; transform: none !important; border-radius: 14px !important; padding: 12px 14px !important; font-size: 14px; }
    .notification-action { min-height: 36px; padding: 6px 12px; font-size: 13px; }
}

/* ---------- Мелкие экраны ---------- */

@media (max-width: 480px) {
    .header-title { font-size: 16px; }
    .header-actions .btn, .sort-select { font-size: 12px; padding: 6px 8px; min-height: 36px; }
    .task-item { padding: 8px 10px; }
    .stats-grid { gap: 6px; }
    .stat-value { font-size: 20px; }
    .stat-label { font-size: 11px; }
    .modal-content { max-height: 95vh; max-height: 95dvh; }
}