body { font-family: 'Inter', sans-serif; zoom: 0.85; }
.page { transition: opacity 0.3s ease-in-out; }
.hidden-page { display: none; }
.visible-page { display: block; }
.modal-backdrop { 
    transition: opacity 0.3s ease-in-out; 
    z-index: 50; /* <-- Добавили это свойство */
}
.tab-button.active, .filter-button.active { 
    border-color: #4f46e5; 
    color: #4f46e5; 
    background-color: #eef2ff; 
}
.disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
#toast-container { position: fixed; top: 1.5rem; right: 1.5rem; z-index: 9999; display: flex; flex-direction: column; gap: 0.75rem; }
.toast { display: flex; align-items: center; padding: 1rem; border-radius: 0.5rem; box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05); transform: translateX(100%); opacity: 0; transition: all 0.3s ease-in-out; min-width: 250px; }
.toast.show { transform: translateX(0); opacity: 1; }
.toast-success { background-color: #f0fdf4; color: #166534; }
.toast-error { background-color: #fef2f2; color: #991b1b; }
.toast-manual { background-color: #eff6ff; color: #1e3a8a; }
.calendar-day { min-height: 120px; }
.search-dropdown { position: relative; }
.search-dropdown-list { position: absolute; top: 100%; left: 0; right: 0; z-index: 10; max-height: 200px; overflow-y: auto; background-color: white; border: 1px solid #e5e7eb; border-radius: 0.375rem; margin-top: 0.25rem; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06); }

/* --- ДОБАВЛЕННЫЕ СТИЛИ --- */
.search-container { 
    position: relative; 
}
#clear-search-btn {
    position: absolute;
    right: 0.75rem; /* 12px */
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    color: #9ca3af; /* gray-400 */
    font-size: 1.5rem; /* 24px */
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem; /* 32px */
    height: 2rem; /* 32px */
}
#clear-search-btn:hover {
    color: #1f2937; /* gray-800 */
}
#clear-search-btn.hidden {
    display: none;
}

#deal-popover {
    /* Скрыт по умолчанию */
    opacity: 0;
    transform: scale(0.95);
    pointer-events: none; /* Нельзя взаимодействовать, когда скрыт */
    transition: opacity 0.2s ease-out, transform 0.2s ease-out; /* <--- ДОБАВЛЕНО/ИЗМЕНЕНО */
}

#deal-popover.show {
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
}

/* --- Стили для подсветки сделки --- */
@keyframes highlight-blink-animation {
    0% { background-color: #eef2ff; border-color: #4f46e5; } /* indigo-50 / indigo-600 */
    50% { background-color: #dbeafe; border-color: #3b82f6; } /* blue-100 / blue-500 */
    100% { background-color: #eef2ff; border-color: #4f46e5; }
}

.highlight-blink {
    border-width: 2px;
    /* Анимация 1 секунда, 5 повторений (всего 10 сек) */
    animation: highlight-blink-animation 1s 5; 
}

/* --- Стили для скрытия "моргания" при загрузке --- */
body.auth-loading #login-screen,
body.auth-loading #app-container {
    opacity: 0;
    transition: none;
}


/* =========================================
   МОБИЛЬНАЯ АДАПТАЦИЯ (для экранов < 768px)
   ========================================= */
@media (max-width: 768px) {

    /* --- ГЛОБАЛЬНЫЕ НАСТРОЙКИ --- */
    #app { padding: 10px !important; }

    /* --- МОДАЛЬНЫЕ ОКНА --- */
    .fixed.inset-0 .bg-white {
        width: 100% !important;
        height: 100% !important;
        max-width: none !important;
        border-radius: 0 !important;
        display: flex;
        flex-direction: column;
    }
    .fixed.inset-0 .bg-white form {
        overflow-y: auto;
        flex-grow: 1;
        padding-bottom: 80px;
    }

    /* --- ШАПКА ПРОФИЛЯ (FLEX-ВЕРСТКА) --- */
    
    #rep-card-header {
        padding: 16px !important;
        height: auto !important;
        min-height: auto !important;
    }

    /* Возвращаем Flex, чтобы элементы чувствовали друг друга */
    #rep-card-header .flex {
        display: flex !important;
        flex-direction: row !important; /* В ряд: слева Имя, справа Кнопки */
        justify-content: space-between !important;
        align-items: center !important; /* <--- ИЗМЕНЕНИЕ: ЦЕНТРИРОВАНИЕ ПО ВЕРТИКАЛИ */
        gap: 10px;
    }

    /* 1. Имя и Город (Слева) */
    #rep-card-header .header-info {
        flex: 1; /* Занимает всё свободное место */
        min-width: 0; /* Позволяет тексту сокращаться (...) если экран супер-узкий */
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
    }

    #rep-card-header h1 {
        font-size: 1.3rem !important;
        line-height: 1.1;
        margin-bottom: 2px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    #rep-card-header p {
        font-size: 0.85rem !important;
        color: #9ca3af;
    }

    /* 2. Блок кнопок (Справа) */
    #rep-card-header .header-controls {
        position: static !important; /* Убираем absolute, чтобы не прилипало к краю */
        width: auto !important;
        margin: 0 !important;
        
        display: flex !important;
        /* column-reverse: Кнопка "Назад" (2-я в HTML) встанет СВЕРХУ, а фильтр (1-й) - СНИЗУ */
        flex-direction: column-reverse !important; 
        align-items: flex-end !important; /* Прижимаем к правому краю */
        gap: 8px; /* Расстояние между кнопкой и фильтром */
        flex-shrink: 0; /* Запрещаем сжиматься */
    }

    /* 3. Кнопка НАЗАД */
    #rep-card-header .back-btn {
        width: auto !important;
        padding: 6px 12px !important;
        font-size: 0.75rem !important;
        border-radius: 6px !important;
        background-color: #f3f4f6 !important;
        color: #374151 !important;
        border: 1px solid #d1d5db;
        box-shadow: none !important;
    }

    /* 4. Фильтр даты */
    #rep-card-header .date-filter-group {
        display: flex !important;
        width: auto !important;
        padding: 0 !important;
        background: transparent !important;
        border: none !important;
        justify-content: flex-end;
    }
    
    /* Скрываем текст "Данные за:" */
    #rep-card-header .date-filter-group label {
        display: none !important;
    }
    
    /* Сам селект */
    #rep-card-header .date-filter-group select {
        font-size: 0.75rem !important;
        padding: 4px 24px 4px 8px !important; /* Чуть больше места справа для галочки */
        height: auto !important;
        background-color: #fff;
        border: 1px solid #e5e7eb;
        border-radius: 6px;
        color: #6b7280;
        
        /* УБИРАЕМ direction: rtl, чтобы точка не улетала в начало */
        direction: ltr !important; 
        text-align: right; /* Пытаемся выровнять текст */
    }

    /* --- ТАБЛИЦЫ (БЕЗ СТРЕЛОЧЕК) --- */
    table thead { display: none; }
    
    table tbody tr {
        display: block;
        background: #fff;
        margin-bottom: 10px;
        border: 1px solid #e5e7eb;
        border-radius: 12px;
        box-shadow: 0 1px 2px rgba(0,0,0,0.05);
        padding: 10px 15px;
        position: relative;
        cursor: pointer;
    }

    /* УБИРАЕМ СТРЕЛОЧКУ ТАБЛИЦЫ */
    table tbody tr::after { display: none !important; content: none !important; }

    /* Логика скрытия ячеек (Аккордеон) */
    table tbody tr:not(.expanded) td { display: none; }
    
    table tbody tr:not(.expanded) td:nth-child(1),
    table tbody tr:not(.expanded) td:nth-child(2),
    table tbody tr:not(.expanded) td:nth-last-child(2) {
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-bottom: none;
        padding: 2px 0;
    }

    /* Сумма жирная */
    table tbody tr:not(.expanded) td:nth-last-child(2) {
        font-weight: bold;
        color: #059669;
        font-size: 1.1em;
        margin-top: 4px;
    }

    table tbody tr.expanded td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 0;
        border-bottom: 1px dashed #f3f4f6;
        text-align: right;
        font-size: 14px;
        animation: fadeIn 0.3s;
    }
    table tbody tr.expanded td:last-child {
        border-bottom: none;
        justify-content: center;
        padding-top: 15px;
    }
    table tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #9ca3af;
        text-align: left;
        font-size: 11px;
        text-transform: uppercase;
        margin-right: auto;
    }

    /* --- АККОРДЕОНЫ (КРУГЛАЯ КНОПКА) --- */
    .mobile-accordion-header {
        display: flex !important;
        justify-content: space-between;
        align-items: center;
        background: #f9fafb;
        padding: 12px 16px !important;
        border-radius: 8px;
        margin: -1rem -1rem 0 -1rem !important;
        width: calc(100% + 2rem);
        cursor: pointer;
        border-bottom: 1px solid #e5e7eb;
    }
    
    .mobile-accordion-header h3 {
        margin-bottom: 0 !important;
        border-bottom: none !important;
        font-size: 0.95rem !important;
        color: #1f2937;
    }

    /* Убираем старую стрелку заголовков */
    .mobile-accordion-header::after { display: none !important; }

    .accordion-icon {
        width: 24px;
        height: 24px;
        border-radius: 50%;
        border: 1px solid #d1d5db;
        display: flex;
        align-items: center;
        justify-content: center;
        background: white;
        transition: all 0.2s;
        flex-shrink: 0;
    }
    
    .accordion-icon::after {
        content: "+";
        font-size: 16px;
        font-weight: bold;
        color: #6b7280;
        line-height: 1;
        margin-top: -1px;
    }

    .mobile-accordion-header.expanded .accordion-icon {
        background: #e5e7eb;
        border-color: #9ca3af;
    }
    .mobile-accordion-header.expanded .accordion-icon::after {
        content: "−";
        color: #111827;
    }

    .mobile-accordion-content {
        display: none;
        padding-top: 16px;
    }
    .mobile-accordion-content.open {
        display: block;
        animation: fadeIn 0.3s;
    }

    /* --- КОМПАКТНЫЕ ОТСТУПЫ МЕЖДУ БЛОКАМИ --- */

    /* 1. Сжимаем расстояние между элементами списка (было 24px, станет 10px) */
    #rep-card-page .space-y-6 > * + * {
        margin-top: 10px !important;
    }

    /* 2. Сжимаем расстояние между колонками и строками сетки */
    #rep-card-page .grid.gap-6 {
        gap: 10px !important;
    }

    /* 3. Убираем лишний отступ под кнопками СДЭК (так как он суммируется с grid-gap) */
    .cdek-actions-mobile {
        margin-bottom: 0 !important;
    }
    
    /* 4. Чуть уменьшаем отступы внутри самих карточек (опционально, для компактности) */
    #rep-card-page .bg-white.p-6,
    #rep-card-page .bg-white.p-4 {
        padding: 12px !important;
    }
    
    /* Компенсируем уменьшение padding для заголовков аккордеонов, чтобы они оставались от края до края */
    .mobile-accordion-header {
        margin: -12px -12px 0 -12px !important;
        width: calc(100% + 24px) !important;
        padding: 10px 12px !important;
    }
}

/* =========================================
   ЛОГИКА КНОПОК СДЭК (ВНЕ МЕДИА-ЗАПРОСОВ)
   ========================================= */

/* 1. По умолчанию (Десктоп): Мобильные скрыты, Десктопные видны */
.cdek-actions-mobile { display: none !important; }
.cdek-actions-desktop { display: block !important; }

/* 2. На мобильных (переопределяем) */
@media (max-width: 768px) {
    .cdek-actions-desktop { display: none !important; }
    .cdek-actions-mobile { display: grid !important; }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- ЭКРАН ВХОДА (ЛОГО + БЭКГРАУНД) --- */

#login-screen {
    background: url('img/bg.jpg') no-repeat center center;
    background-size: cover;
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    display: flex; 
    align-items: center;
    justify-content: center;
}

#login-screen.hidden {
    display: none !important;
}

/* Добавляем полупрозрачное затемнение поверх картинки */
#login-screen::before {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5); /* 50% затемнения */
    backdrop-filter: blur(3px); /* Легкое размытие фона (эффект стекла) */
    z-index: 0; /* Под формой, но над картинкой */
}

/* Убеждаемся, что сама форма лежит ПОВЕРХ затемнения */
#login-screen > div {
    position: relative;
    z-index: 10;
}

