/**
 * CRM UI Controls — user toggle, dropdown, search, clock, settings button
 * 
 * Кодировка: UTF-8
 * @version 1.0.0
 */

/* ═══════════════════════════════════════════════════════════════════════
   КНОПКА ПОЛЬЗОВАТЕЛЯ — Fresh
   ═══════════════════════════════════════════════════════════════════════ */
.crm-user-toggle {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    border-radius: 14px;
    padding: 6px 14px 6px 6px;
    background: linear-gradient(135deg, rgba(251, 146, 60, 0.08) 0%, rgba(244, 114, 182, 0.06) 100%);
    border: 1px solid rgba(251, 146, 60, 0.15);
    color: #475569;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    z-index: 10;
}

.crm-user-toggle::before { display: none; }

.crm-user-toggle::after {
    display: none;
}

.crm-user-toggle:hover {
    background: linear-gradient(135deg, rgba(251, 146, 60, 0.14) 0%, rgba(244, 114, 182, 0.1) 100%);
    border-color: rgba(251, 146, 60, 0.25);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(251, 146, 60, 0.12);
}

.crm-user-avatar-img {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    object-fit: cover;
    border: 2px solid rgba(251, 146, 60, 0.2);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
}

.crm-user-toggle:hover .crm-user-avatar-img {
    border-color: rgba(244, 114, 182, 0.35);
    box-shadow: 0 3px 12px rgba(244, 114, 182, 0.15);
}

.crm-user-name-short {
    max-width: 100px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 600;
    font-size: 12px;
    color: #334155;
}

/* ═══════════════════════════════════════════════════════════════════════
   ЧАСЫ — Fresh стиль
   ═══════════════════════════════════════════════════════════════════════ */
.crm-clock {
    color: #64748b;
    background: linear-gradient(135deg, rgba(100, 116, 139, 0.06) 0%, rgba(148, 163, 184, 0.04) 100%);
    border-radius: 12px;
    padding: 8px 14px;
    font-weight: 600;
    font-size: 12px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    gap: 0;
    border: 1px solid rgba(100, 116, 139, 0.1);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.03em;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.02);
    z-index: 10;
    transition: all 0.3s ease;
}

.crm-clock:hover {
    background: linear-gradient(135deg, rgba(100, 116, 139, 0.1) 0%, rgba(148, 163, 184, 0.07) 100%);
    color: #475569;
}

.crm-clock::before { display: none; }

/* ═══════════════════════════════════════════════════════════════════════
   CRM SETTINGS BUTTON — Fresh стиль
   ═══════════════════════════════════════════════════════════════════════ */
.crm-settings-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    margin-left: 12px;
    background: linear-gradient(135deg, rgba(100, 116, 139, 0.06) 0%, rgba(148, 163, 184, 0.04) 100%);
    border: 1px solid rgba(100, 116, 139, 0.1);
    border-radius: 10px;
    color: #64748b;
    cursor: pointer;
    transition: all 0.3s ease;
}

.crm-settings-btn:hover {
    background: linear-gradient(135deg, rgba(100, 116, 139, 0.12) 0%, rgba(148, 163, 184, 0.08) 100%);
    color: #475569;
    transform: rotate(45deg);
}

.crm-settings-btn svg {
    width: 18px;
    height: 18px;
}

/* ═══════════════════════════════════════════════════════════════════════
   USER DROPDOWN MENU — Fresh
   ═══════════════════════════════════════════════════════════════════════ */
.crm-user-menu {
    min-width: 200px;
    z-index: 2100 !important;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98) 0%, rgba(255, 250, 248, 0.98) 100%);
    border: 1px solid rgba(251, 146, 60, 0.12);
    border-radius: 16px;
    box-shadow: 
        0 8px 22px rgba(0, 0, 0, 0.08),
        0 2px 8px rgba(0, 0, 0, 0.04),
        inset 0 1px 0 rgba(255, 255, 255, 0.9);
    padding: 10px;
    margin-top: 10px;
}

.crm-user-menu .dropdown-item {
    color: #475569;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.crm-user-menu .dropdown-item:hover {
    background: linear-gradient(135deg, rgba(251, 146, 60, 0.08) 0%, rgba(244, 114, 182, 0.06) 100%);
    color: #1e293b;
    transform: translateX(4px);
}

.crm-user-menu .dropdown-header {
    color: #94a3b8;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 10px 16px 6px;
    font-weight: 600;
}

.crm-user-menu .dropdown-divider {
    border-color: rgba(0, 0, 0, 0.06);
    margin: 8px 0;
}

.crm-user-menu .btn-outline-danger {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.08) 0%, rgba(220, 38, 38, 0.05) 100%);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: #dc2626;
    font-size: 12px;
    font-weight: 600;
    border-radius: 12px;
    transition: all 0.3s ease;
}

.crm-user-menu .btn-outline-danger:hover {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.15) 0%, rgba(220, 38, 38, 0.1) 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.15);
}

/* ═══════════════════════════════════════════════════════════════════════
   DROPDOWN — Z-index и overflow fixes
   ═══════════════════════════════════════════════════════════════════════ */
.dropdown { z-index: 2100; position: relative; }

/* allow dropdown to appear above other panels */
.dropdown-menu {
    z-index: 99999 !important;
}

/* ensure page containers don't clip dropdowns */
.container-fluid, .row, .col-12, .col-lg-4, .col-xl-8 {
    overflow: visible !important;
}

/* ═══════════════════════════════════════════════════════════════════════
   ПОИСК — Fresh стиль
   ═══════════════════════════════════════════════════════════════════════ */
.crm-search-wrapper {
    flex: 1 1 320px;
    max-width: 420px;
    margin: 0 28px;
    z-index: 10;
}

.search-input-wrap {
    position: relative;
    width: 100%;
}

.crm-search-input {
    width: 100%;
    padding: 10px 70px 10px 40px;
    border-radius: 14px;
    border: 1px solid rgba(0, 0, 0, 0.06);
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.9) 0%, rgba(255, 252, 250, 0.9) 100%);
    color: #1e293b;
    outline: none;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.25s ease;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.03);
}

.search-input-wrap::before {
    content: '';
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E");
    background-size: contain;
    pointer-events: none;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.crm-search-input::placeholder { 
    color: #94a3b8;
    font-weight: 400;
}

.crm-search-input:focus {
    background: #fff;
    border-color: rgba(251, 146, 60, 0.35);
    box-shadow: 
        0 0 0 3px rgba(251, 146, 60, 0.08),
        inset 0 1px 2px rgba(0, 0, 0, 0.02);
}

.crm-search-input:focus + .search-input-wrap::before,
.search-input-wrap:focus-within::before {
    opacity: 1;
}

.crm-search-btn {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    border: 0;
    background: linear-gradient(135deg, #fb923c, #f472b6);
    color: #fff;
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 10px;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(251, 146, 60, 0.25);
}

.crm-search-btn:hover {
    background: linear-gradient(135deg, #ea580c, #db2777);
    box-shadow: 0 4px 12px rgba(251, 146, 60, 0.35);
    transform: translateY(-50%) scale(1.02);
}

/* ═══════════════════════════════════════════════════════════════════════
   РЕЗУЛЬТАТЫ ПОИСКА
   ═══════════════════════════════════════════════════════════════════════ */
#global-search-results {
    margin-top: 4px;
    width: 100%;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    border: 1px solid #e5e7eb;
    overflow: hidden;
}

#global-search-results .list-group-item {
    background: transparent;
    border: none;
    border-bottom: 1px solid #f3f4f6;
    color: #374151;
    padding: 10px 12px;
    font-size: 12px;
    transition: background 0.1s;
}

#global-search-results .list-group-item:hover,
#global-search-results .list-group-item.active {
    background: #f9fafb;
}

#global-search-results .list-group-item.active {
    outline: 2px solid var(--focus-ring, rgba(59,130,246,.9));
    outline-offset: -2px;
}

#global-search-results .list-group-item:last-child {
    border-bottom: none;
}

#global-search-results .fw-semibold {
    color: #1a1a1a;
}

#global-search-results .text-muted {
    color: #9ca3af !important;
}

/* ═══════════════════════════════════════════════════════════════════════
   HEADER RIGHT — Отступы
   ═══════════════════════════════════════════════════════════════════════ */
.crm-header-right > * { 
    margin-left: 4px; 
    display: inline-flex; 
    align-items: center; 
}

.crm-header-right > *:first-child {
    margin-left: 0;
}

@media (max-width: 640px) {
    .crm-search-wrapper { display: none; }
}
