/**
 * Дополнительные стили гаража: спойлер VIN, цвет-попап,
 * подтверждение удаления, настройка полей, шестерёнка.
 */

/* ============ Карточка авто: спойлер VIN ============ */
.vin-spoiler {
    position: relative;
    display: inline-block;
    cursor: pointer;
    user-select: none;
    border-radius: 6px;
    padding: 0 0.35rem;
    color: transparent;
    background: linear-gradient(120deg,
        var(--gray-400) 0%,
        var(--gray-500) 25%,
        var(--gray-400) 50%,
        var(--gray-500) 75%,
        var(--gray-400) 100%);
    background-size: 200% 100%;
    animation: vinShimmer 6s linear infinite;
    transition: filter 200ms ease, background 200ms ease;
    /* Сильное размытие текста + лёгкий шум сверху, чтобы прочитать было нельзя. */
    filter: blur(6px) saturate(0.3);
}

.vin-spoiler::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: repeating-linear-gradient(
        45deg,
        rgba(255, 255, 255, 0.35) 0,
        rgba(255, 255, 255, 0.35) 2px,
        rgba(15, 23, 42, 0.25) 2px,
        rgba(15, 23, 42, 0.25) 4px
    );
    mix-blend-mode: overlay;
    pointer-events: none;
    transition: opacity 200ms ease;
}

.vin-spoiler:hover {
    /* Чуть «приоткрывается», но всё равно не читается. */
    filter: blur(3px) saturate(0.6);
}

.vin-spoiler:hover::after {
    opacity: 0.55;
}

.vin-spoiler.vin-spoiler-revealed {
    background: var(--gray-100);
    color: var(--gray-800);
    filter: none;
    animation: none;
}

.vin-spoiler.vin-spoiler-revealed::after {
    opacity: 0;
}

@keyframes vinShimmer {
    0%   { background-position: 0% 0%; }
    100% { background-position: 200% 0%; }
}

.vehicle-card-stats .muted { color: var(--gray-400); }

.vehicle-plate-chip {
    display: inline-block;
    font-weight: 600;
    letter-spacing: 0.04em;
    padding: 0.15rem 0.5rem;
    border-radius: var(--radius-sm);
    background: var(--primary-50);
    color: var(--primary-700);
}

.vehicle-card-color-inline {
    display: inline-block;
    width: 0.85rem;
    height: 0.85rem;
    border-radius: 50%;
    background: var(--swatch);
    border: 2px solid rgba(15, 23, 42, 0.1);
    vertical-align: -2px;
    margin-right: 0.4rem;
}

.vehicle-card-description {
    margin: 0 0 1rem;
    background: var(--gray-50);
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius-md);
    border-left: 3px solid var(--primary-300, #93c5fd);
    overflow: hidden;
}

/* Внутренний абзац: жёсткий кроп до 4 строк + троеточие. */
.vehicle-card-description-text {
    --desc-lines: 4;
    --desc-line-height: 1.45;
    margin: 0;
    color: var(--gray-600);
    font-size: 0.85rem;
    line-height: var(--desc-line-height);
    /* Переносы по словам и разрыв длинных «слов»/ссылок. */
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
    /* Кроп с многоточием. */
    display: -webkit-box;
    -webkit-line-clamp: var(--desc-lines);
    line-clamp: var(--desc-lines);
    -webkit-box-orient: vertical;
    overflow: hidden;
    /* Подстраховка: не даём блоку быть выше 4 строк, даже если webkit-clamp где-то не сработал. */
    max-height: calc(var(--desc-line-height) * 1em * var(--desc-lines));
}

/* ============ Триггер «Свой цвет» ============ */
.color-custom {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
    position: relative;
}

.color-custom-trigger {
    appearance: none;
    border: 1px solid var(--gray-200);
    background: #fff;
    color: var(--gray-700);
    border-radius: var(--radius-lg);
    padding: 0.55rem 0.9rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.7rem;
    font: inherit;
    transition: border-color 160ms ease, box-shadow 160ms ease, transform 140ms ease;
}

.color-custom-trigger:hover {
    border-color: var(--primary-300, #93c5fd);
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
    transform: translateY(-1px);
}

.color-custom-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.05rem;
    line-height: 1.1;
}

.color-custom-label-text { font-size: 0.85rem; }
.color-custom-hex {
    font-size: 0.75rem;
    color: var(--gray-500);
    font-family: ui-monospace, monospace;
}

.color-custom-trigger i {
    color: var(--gray-400);
    transition: transform 200ms ease;
}

/* ============ Поп-ап выбора цвета (fixed — поверх модалки) ============ */
.color-picker {
    position: relative;
    overflow: visible;
}

.vehicle-color-section.is-color-popover-open {
    position: relative;
    z-index: 2;
}

.color-popover {
    position: fixed;
    z-index: 2500;
    width: min(280px, calc(100vw - 1.5rem));
    padding: 0.85rem;
    border-radius: 1rem;
    background: #fff;
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.22), 0 4px 10px rgba(15, 23, 42, 0.08);
    border: 1px solid var(--gray-200);
    animation: popIn 180ms ease both;
}

.color-popover[hidden] {
    display: none !important;
}

@keyframes popIn {
    from { opacity: 0; transform: translateY(-6px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.color-popover-arrow {
    position: absolute;
    top: -6px;
    left: 1.25rem;
    width: 12px;
    height: 12px;
    background: #fff;
    border-left: 1px solid var(--gray-200);
    border-top: 1px solid var(--gray-200);
    transform: rotate(45deg);
}

.color-square {
    --hue-color: #00b4ff;
    position: relative;
    width: 100%;
    height: 160px;
    border-radius: 0.75rem;
    background: var(--hue-color);
    overflow: hidden;
    cursor: crosshair;
    user-select: none;
}

.color-square-overlay-saturation,
.color-square-overlay-value {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.color-square-overlay-saturation {
    background: linear-gradient(to right, #fff, rgba(255, 255, 255, 0));
}

.color-square-overlay-value {
    background: linear-gradient(to top, #000, rgba(0, 0, 0, 0));
}

.color-square-cursor {
    position: absolute;
    width: 14px;
    height: 14px;
    border: 2px solid #fff;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35), 0 2px 6px rgba(0, 0, 0, 0.4);
    pointer-events: none;
    transition: background 80ms linear;
}

.color-hue {
    position: relative;
    margin-top: 0.7rem;
    height: 14px;
    border-radius: 999px;
    background: linear-gradient(to right,
        #ff0000 0%, #ffff00 17%, #00ff00 33%, #00ffff 50%,
        #0000ff 67%, #ff00ff 83%, #ff0000 100%);
    cursor: ew-resize;
}

.color-hue-cursor {
    position: absolute;
    top: 50%;
    width: 16px;
    height: 16px;
    border: 2px solid #fff;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3), 0 2px 4px rgba(0, 0, 0, 0.3);
    pointer-events: none;
}

.color-popover-foot {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.7rem;
}

.color-popover-preview {
    width: 2rem;
    height: 2rem;
    border-radius: 0.5rem;
    border: 1px solid var(--gray-200);
}

.color-popover .color-hex-input {
    flex: 1;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    padding: 0.45rem 0.6rem;
    font: inherit;
    text-transform: uppercase;
    font-family: ui-monospace, monospace;
}

.color-popover .color-hex-input:focus {
    outline: none;
    border-color: var(--primary-400);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.12);
}

/* ============ Опасная зона в карточке авто ============ */
.vehicle-danger-zone {
    border-color: rgba(239, 68, 68, 0.25) !important;
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.04), transparent 70%) !important;
}

.vehicle-section-title-danger i {
    background: rgba(239, 68, 68, 0.12);
    color: #ef4444;
}

.vehicle-danger-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.vehicle-danger-hint {
    margin: 0;
    color: var(--gray-500);
    font-size: 0.8rem;
}

/* ============ Confirm-modal ============ */
.confirm-modal-content {
    max-width: 460px;
    width: min(460px, 94vw);
    padding: 1.75rem 1.5rem 1.25rem;
    border-radius: 1.25rem;
    text-align: center;
    background: #fff;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.2);
    animation: confirmIn 220ms cubic-bezier(0.2, 0.9, 0.3, 1.05);
}

@keyframes confirmIn {
    from { opacity: 0; transform: translateY(10px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.confirm-icon {
    width: 4rem;
    height: 4rem;
    border-radius: 50%;
    background: rgba(239, 68, 68, 0.12);
    color: #ef4444;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    margin: 0 auto 0.75rem;
}

.confirm-title {
    margin: 0 0 0.5rem;
    font-family: var(--font-heading);
    font-size: 1.25rem;
    color: var(--gray-900);
}

.confirm-text {
    margin: 0 0 1.25rem;
    color: var(--gray-600);
    line-height: 1.5;
    font-size: 0.95rem;
}

.confirm-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
}

.confirm-actions .btn {
    flex: 1;
    min-width: 8rem;
}

.btn-danger {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: #fff;
    border: none;
    box-shadow: 0 8px 16px rgba(239, 68, 68, 0.25);
}

.btn-danger:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 22px rgba(239, 68, 68, 0.32);
}

#vehicle-confirm-modal.modal.active,
#vehicle-fields-modal.modal.active { z-index: 2200; }

/* ============ Fields-modal ============ */
.fields-modal-content {
    position: relative;
    max-width: 460px;
    width: min(460px, 94vw);
    padding: 1.5rem 1.5rem 1.25rem;
    border-radius: 1.25rem;
    background: #fff;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.18);
    animation: confirmIn 220ms ease both;
}

/* Заголовок не заходит под крестик (44×44, top/right 1.5rem). */
.fields-modal-content > .modal-title,
.fields-modal-content > .modal-subtitle {
    padding-right: 3.5rem;
}

.fields-modal-content > .modal-title {
    margin: 0 0 0.35rem;
    font-family: var(--font-heading);
    font-size: 1.25rem;
    line-height: 1.3;
}

.fields-modal-content > .modal-subtitle {
    margin: 0;
    color: var(--gray-500);
    font-size: 0.875rem;
    line-height: 1.45;
}

.fields-list {
    display: grid;
    gap: 0.4rem;
    margin: 1rem 0 1rem;
    max-height: 60vh;
    overflow-y: auto;
    /* Запас сверху/снизу, чтобы рамка пункта не обрезалась при hover. */
    padding: 0.2rem 0.1rem;
    scroll-padding: 0.25rem 0;
}

.field-toggle {
    display: grid;
    grid-template-columns: 1.75rem 1fr 1.25rem;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
    background: #fff;
}

.field-toggle:hover {
    border-color: var(--primary-300, #93c5fd);
    background: var(--primary-50);
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.07);
}

.field-toggle input[type="checkbox"] {
    appearance: none;
    width: 0;
    height: 0;
    margin: 0;
    visibility: hidden;
    grid-column: 3;
    grid-row: 1;
}

.field-toggle-icon {
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 0.5rem;
    background: var(--gray-100);
    color: var(--gray-600);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    transition: background 160ms ease, color 160ms ease;
}

.field-toggle-label {
    font-size: 0.92rem;
    color: var(--gray-800);
}

.field-toggle-mark {
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    border: 2px solid var(--gray-300);
    color: transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    transition: background 160ms ease, border-color 160ms ease, color 160ms ease;
}

.field-toggle input[type="checkbox"]:checked ~ .field-toggle-mark {
    background: var(--primary-500);
    border-color: var(--primary-500);
    color: #fff;
}

.field-toggle:has(input:checked) {
    border-color: var(--primary-400, #60a5fa);
    background: var(--primary-50);
}

.field-toggle:has(input:checked) .field-toggle-icon {
    background: var(--primary-100);
    color: var(--primary-700);
}

.fields-actions {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
}

.fields-actions .btn { flex: 1; }

/* ============ Кнопки внутри карточки авто (одинаковая высота) ============ */
.vehicle-card-actions .btn {
    min-height: 2.25rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.btn.btn-square {
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    flex: 0 0 2.25rem;
    aspect-ratio: 1 / 1;
}

.btn.btn-square i { margin: 0; }

.btn-restore:hover {
    border-color: var(--primary-500);
    color: var(--primary-700);
    background: var(--primary-50);
}

/* Маленький счётчик в кнопке «Дневник» в карточке авто. */
.vehicle-card-diary {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.diary-btn-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    /* Кружок ровно вписывается в высоту строки кнопки и центрируется по тексту. */
    height: 1.45em;
    min-width: 1.45em;
    padding: 0 0.45em;
    font-size: 0.78em;
    line-height: 1;
    font-weight: 700;
    line-height: 1;
    color: #fff;
    background: rgba(255, 255, 255, 0.22);
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 999px;
    letter-spacing: 0.02em;
}

.vehicle-card-title {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.vehicle-card-title-btn {
    appearance: none;
    border: none;
    background: transparent;
    padding: 0;
    margin: 0;
    font: inherit;
    font-weight: inherit;
    color: inherit;
    cursor: pointer;
    text-align: left;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    border-radius: 4px;
    transition: color 160ms ease;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.vehicle-card-title-btn:hover {
    color: var(--primary-700);
}

.vehicle-card-title-btn:focus-visible {
    outline: 2px solid var(--primary-400);
    outline-offset: 3px;
}

/* ============ Архив: визуально приглушённая карточка ============ */
.vehicle-card-archived {
    background: rgba(248, 250, 252, 0.85);
    border-style: dashed;
    border-color: var(--gray-300);
    box-shadow: none;
}

.vehicle-card-archived:hover {
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.06);
    transform: none;
}

.vehicle-card-archived .vehicle-card-icon {
    filter: grayscale(0.4);
}

.vehicle-card-archived::after {
    content: 'В архиве';
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
    background: var(--gray-100);
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
}

.vehicle-card-archived { position: relative; }

/* ============ Модалка: режим просмотра ============ */
.vehicle-modal-view input,
.vehicle-modal-view textarea,
.vehicle-modal-view select {
    background: var(--gray-50) !important;
    color: var(--gray-700) !important;
    cursor: default;
}

.vehicle-modal-view .input-with-icon i {
    color: var(--gray-400);
}

.vehicle-modal-view .chip {
    cursor: default;
    pointer-events: none;
}

.vehicle-modal-view .chip:not(.chip-active) {
    opacity: 0.5;
}

.vehicle-modal-view .color-swatch {
    cursor: default;
    pointer-events: none;
    opacity: 0.85;
}

.vehicle-modal-view .color-swatch:not(.color-swatch-active) {
    opacity: 0.5;
}

.vehicle-modal-view .color-custom-trigger {
    cursor: default;
    opacity: 0.85;
    pointer-events: none;
}

/* ============ Бэйдж «Просмотр» рядом с заголовком ============ */
.vehicle-modal-title-row {
    display: flex;
    align-items: baseline;
    gap: 0.55rem;
    flex-wrap: wrap;
}

.vehicle-modal-mode-badge {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--primary-600);
    background: var(--primary-50);
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    line-height: 1;
    white-space: nowrap;
    /* Сдвигаем чуть вниз под визуальный baseline заголовка. */
    position: relative;
    top: -0.2em;
}

.vehicle-modal-mode-badge[hidden] { display: none !important; }

/* ============ Принудительное скрытие в режиме просмотра ============ */
.vehicle-modal-view #vehicle-form-submit,
.vehicle-modal-view .avatar-edit-controls,
.vehicle-modal-view .color-palette,
.vehicle-modal-view .color-custom,
.vehicle-modal-view .color-popover,
.vehicle-form-section[hidden] {
    display: none !important;
}

/* ============ Просмотр: крупная аватарка, цвет одной таблеткой ============ */
.vehicle-modal-view .vehicle-avatar-edit {
    padding: 0;
    border: none;
    background: transparent;
}

.vehicle-modal-view .avatar-edit-compact {
    display: block;
}

.vehicle-modal-view .vehicle-avatar-preview {
    width: 100%;
    aspect-ratio: 1 / 1;
    height: auto;
    max-width: none;
    border-radius: 1rem;
    overflow: hidden;
    background: linear-gradient(135deg, var(--primary-50), var(--gray-100));
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 4rem;
    color: var(--primary-400);
}

.vehicle-modal-view .vehicle-avatar-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* В режиме просмотра textarea с описанием растягивается под весь текст,
   но не «занимает место под 1000 символов» — высота строго по контенту. */
.vehicle-modal-view #vehicle-description {
    resize: none;
    overflow: hidden;
    min-height: 0;
    height: auto;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
    line-height: 1.45;
}

/* В режиме просмотра скрываем счётчик символов. */
.vehicle-modal-view .vehicle-desc-hint {
    display: none !important;
}

/* Подсказка-счётчик описания. */
.vehicle-desc-hint {
    display: block;
    margin-top: 0.35rem;
    font-size: 0.75rem;
    color: var(--gray-500);
    text-align: right;
}

/* Только выбранный цвет в просмотре — один круглишок. */
.color-readonly {
    display: inline-block;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    background: var(--swatch);
    border: 2px solid rgba(15, 23, 42, 0.08);
    box-shadow: inset 0 0 0 3px #fff, 0 4px 10px rgba(15, 23, 42, 0.08);
}
