/* ==========================================================================
   06_MUSIC.CSS (FULL FIX: SQUARES + LYRICS + PLAYER)
   ========================================================================== */

:root {
    --primary: #FABF3C;
    --bg-card: #141414;
    --text-main: #ffffff;
    --text-secondary: #aaaaaa;
    --border-color: rgba(255, 255, 255, 0.1);
    --modal-bg: #111;
}

/* --- ОСНОВНОЙ КОНТЕЙНЕР --- */
#music-view {
    display: flex; 
    flex-direction: column; 
    width: 100%; 
    height: 100%; 
    gap: 1rem; 
    overflow: hidden; 
    background-color: var(--bg-panel); 
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    border-radius: 12px; padding: 1rem;
}

/* --- ТАБЫ --- */
.music-tabs {
    flex-shrink: 0; display: flex; gap: 1.5rem; padding-bottom: 0.8rem;
    border-bottom: 1px solid var(--border-color);
}
.music-tab-btn {
    background: none; border: none; color: var(--text-secondary);
    font-weight: 600; font-size: 0.95rem; padding: 0.25rem 0; 
    cursor: pointer; position: relative; transition: 0.3s;
}
.music-tab-btn:hover { color: var(--text-main); }
.music-tab-btn.active { color: var(--primary); }
.music-tab-btn.active::after {
    content: ''; position: absolute; bottom: -14px; left: 0;
    width: 100%; height: 2px; background-color: var(--primary);
}

/* ==========================================================================
   СЕТКА ТРЕКОВ (MUSIC GRID)
   ========================================================================== */
.music-track-list {
    flex-grow: 1; 
    overflow-y: auto; 
    display: grid;
    /* Колонки: минимум 150px, иначе перенос */
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    /* Высота рядов автоматическая */
    grid-auto-rows: max-content; 
    gap: 16px; 
    padding: 4px 8px 40px 4px;
}

/* --- КАРТОЧКА (SQUARE CARD) --- */
.music-card-simple {
    position: relative; 
    width: 100%; 
    aspect-ratio: 1 / 1; /* Квадрат */
    border-radius: 12px; 
    overflow: hidden; 
    border: 1px solid var(--border-color); 
    background-color: #1a1a1a;
    cursor: pointer; 
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    flex-direction: column;
}

.music-card-simple:hover {
    transform: translateY(-4px); 
    box-shadow: 0 8px 20px rgba(0,0,0,0.5);
    border-color: rgba(255,255,255,0.4);
    z-index: 2;
}

/* Обложка */
.simple-card-cover {
    position: absolute; 
    top: 0; left: 0;
    width: 100%; height: 100%; 
    object-fit: cover;
    transition: transform 0.5s ease;
    z-index: 0;
    background-color: #222;
}
.music-card-simple:hover .simple-card-cover { transform: scale(1.05); }

/* Градиент для текста */
.music-card-simple::after {
    content: ''; 
    position: absolute; 
    inset: 0;
    background: linear-gradient(to bottom, transparent 40%, rgba(0,0,0,0.9) 100%);
    z-index: 1;
    pointer-events: none;
}

/* Инфо на карточке */
.simple-card-info {
    position: absolute; 
    bottom: 0; left: 0; 
    width: 100%;
    padding: 12px; 
    z-index: 2;
    pointer-events: none;
    display: flex; flex-direction: column; gap: 4px;
}

.simple-card-title {
    color: #fff; 
    font-weight: 700; 
    font-size: 0.95rem;
    white-space: nowrap; 
    overflow: hidden; 
    text-overflow: ellipsis;
    text-shadow: 0 2px 4px rgba(0,0,0,0.8);
}

.simple-card-status {
    font-size: 0.75rem; 
    color: #ccc;
    white-space: nowrap; 
    overflow: hidden; 
    text-overflow: ellipsis;
}

/* Иконка Play при наведении */
.simple-play-overlay {
    position: absolute; inset: 0; z-index: 3;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.3); opacity: 0; transition: 0.2s;
}
.music-card-simple:hover .simple-play-overlay { opacity: 1; }

.simple-play-icon {
    width: 56px; height: 56px; border-radius: 50%;
    background: rgba(255,255,255,0.2); backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center;
    color: #fff; border: 1px solid rgba(255,255,255,0.5);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

/* ==========================================================================
   ЗАГЛУШКА (LOADING PLACEHOLDER)
   ========================================================================== */
.music-track-card.is-loading {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.03);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    text-align: center; padding: 15px; gap: 15px;
    overflow: hidden; backdrop-filter: blur(5px);
}

.loading-visualizer {
    display: flex; align-items: flex-end; gap: 4px; height: 40px;
}

.visualizer-bar {
    width: 6px; background-color: var(--primary);
    border-radius: 2px;
    animation: sound-wave 1s infinite ease-in-out;
}
.visualizer-bar:nth-child(1) { height: 40%; animation-delay: 0s; }
.visualizer-bar:nth-child(2) { height: 70%; animation-delay: 0.2s; }
.visualizer-bar:nth-child(3) { height: 50%; animation-delay: 0.4s; }

@keyframes sound-wave {
    0%, 100% { height: 20%; opacity: 0.5; }
    50% { height: 100%; opacity: 1; box-shadow: 0 0 10px var(--primary); }
}

.is-loading .track-title {
    font-size: 0.9rem; font-weight: 700; color: #fff;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.is-loading .track-status {
    font-size: 0.75rem; color: var(--text-secondary);
    text-transform: uppercase; letter-spacing: 0.5px;
}

/* ==========================================================================
   МОДАЛЬНОЕ ОКНО ПЛЕЕРА (PLAYER)
   ========================================================================== */
#musicPlayerModal { z-index: 1055 !important; }

.music-player-content {
    background-color: var(--modal-bg); color: #fff;
    border: 1px solid var(--border-color); border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.8);
}
.modal-header { border-bottom: 1px solid rgba(255,255,255,0.05); }
.modal-header .btn-close { filter: invert(1); opacity: 0.7; }

.player-layout {
    display: flex; gap: 2rem; align-items: flex-start; padding: 10px 0;
}
.player-cover-column { width: 280px; flex-shrink: 0; }
.player-cover-large {
    width: 100%; aspect-ratio: 1/1; object-fit: cover;
    border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.1);
}
.player-controls-column { 
    flex-grow: 1; min-width: 0; display: flex; flex-direction: column; 
    justify-content: center; height: 280px;
}

.player-track-info-header h3 {
    font-size: 1.5rem; font-weight: 800; margin-bottom: 0.5rem;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.2;
}

/* Слайдер */
.player-progress-wrapper {
    display: flex; align-items: center; gap: 12px; margin: 1.5rem 0;
    font-size: 0.8rem; color: var(--text-secondary); font-family: monospace;
}
.styled-slider {
    flex-grow: 1; -webkit-appearance: none; height: 4px; background: rgba(255,255,255,0.1);
    border-radius: 2px; outline: none; cursor: pointer; position: relative;
}
.styled-slider::-webkit-slider-thumb {
    -webkit-appearance: none; width: 12px; height: 12px; border-radius: 50%;
    background: #fff; cursor: pointer; transition: 0.2s; 
    box-shadow: 0 0 10px rgba(255,255,255,0.5);
}
.styled-slider::-webkit-slider-thumb:hover { transform: scale(1.3); background: var(--primary); }

/* Кнопки плеера */
.player-main-controls { display: flex; justify-content: center; margin-bottom: 1.5rem; }
.player-play-btn-large {
    width: 70px; height: 70px; border-radius: 50%;
    background: var(--primary); color: #000; border: none;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: 0.2s; box-shadow: 0 0 25px rgba(250, 191, 60, 0.2);
}
.player-play-btn-large:hover { transform: scale(1.05); box-shadow: 0 0 35px rgba(250, 191, 60, 0.4); }

.player-actions-row { display: flex; justify-content: center; gap: 1rem; }
.player-action-btn {
    width: 42px; height: 42px; border-radius: 50%;
    background: rgba(255,255,255,0.05); color: #fff; border: 1px solid transparent;
    display: flex; align-items: center; justify-content: center; cursor: pointer; transition: 0.2s;
}
.player-action-btn:hover { background: rgba(255,255,255,0.15); transform: translateY(-2px); }
.player-action-btn.danger:hover { color: #ff4d4d; background: rgba(255, 77, 77, 0.1); }

/* Кнопка избранного */
#player-fav-btn .star-outline { display: block !important; }
#player-fav-btn .star-filled { display: none !important; }
#player-fav-btn.active .star-outline { display: none !important; }
#player-fav-btn.active .star-filled { display: block !important; filter: drop-shadow(0 0 5px var(--primary)); }
#player-fav-btn.active {
    color: var(--primary) !important; border-color: var(--primary) !important;
    background-color: rgba(250, 191, 60, 0.15) !important;
}

/* Доп. детали */
.player-divider { border-color: rgba(255,255,255,0.1); margin: 1.5rem 0; }
.player-detail-box {
    background: rgba(255,255,255,0.03); border-radius: 8px; padding: 16px;
    border: 1px solid rgba(255,255,255,0.05);
}
.detail-header {
    display: flex; justify-content: space-between; margin-bottom: 10px;
    font-size: 0.75rem; text-transform: uppercase; letter-spacing: 1px; color: var(--text-secondary);
}
.copy-btn-sm {
    background: none; border: 1px solid rgba(255,255,255,0.2); color: var(--text-secondary);
    font-size: 0.7rem; padding: 2px 8px; border-radius: 4px; cursor: pointer; transition: 0.2s;
}
.copy-btn-sm:hover { color: var(--primary); border-color: var(--primary); }
.detail-content { font-size: 0.95rem; line-height: 1.5; color: #eee; white-space: pre-wrap; margin: 0; }

/* Ремикс модалка (выше плеера) */
#musicReplaceModal { z-index: 1060 !important; }
.modal-backdrop + .modal-backdrop { z-index: 1058 !important; }

/* Адаптив плеера */
@media (max-width: 768px) {
    .music-track-list { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .player-layout { flex-direction: column; align-items: center; gap: 1.5rem; text-align: center; }
    .player-cover-column { width: 100%; max-width: 280px; }
    .player-controls-column { height: auto; width: 100%; }
    .player-track-info-header h3 { font-size: 1.2rem; }
    .player-actions-row { gap: 0.5rem; }
}

/* ==========================================================================
   ИСТОРИЯ ТЕКСТОВ (LYRICS HISTORY) - ДОБАВЛЕНО
   ========================================================================== */

/* Контейнер для истории текстов - Сетка */
/* Контейнер для истории текстов */
#lyrics-history-container {
    display: grid;
    /* Адаптивные колонки */
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    padding: 4px 10px 4px 4px; /* Чуть больше отступа справа для скроллбара */
    margin-top: 10px;
    
    /* === ДОБАВЛЕНО ДЛЯ СКРОЛЛА === */
    max-height: 500px;  /* Ограничиваем высоту (примерно пол-экрана) */
    overflow-y: auto;   /* Включаем вертикальную прокрутку */
    
    /* Красивый скроллбар (как в Spotify/Dark themes) */
    scrollbar-width: thin;
    scrollbar-color: var(--primary) transparent;
}

/* Стилизация полосы прокрутки для Chrome/Safari */
#lyrics-history-container::-webkit-scrollbar {
    width: 6px;
}
#lyrics-history-container::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
}
#lyrics-history-container::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}
#lyrics-history-container::-webkit-scrollbar-thumb:hover {
    background-color: var(--primary);
}

/* Карточка истории */
.lyrics-history-item {
    background-color: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 12px;
    transition: transform 0.2s, background-color 0.2s;
    min-height: 140px; /* Чтобы карточки были +/- одинаковые */
}

.lyrics-history-item:hover {
    background-color: rgba(255, 255, 255, 0.08);
    transform: translateY(-2px);
    border-color: rgba(255, 255, 255, 0.3);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

/* Текст идеи */
.history-item-info {
    flex-grow: 1;
    overflow: hidden;
}

.history-idea-text {
    font-size: 0.9rem;
    color: var(--text-main);
    line-height: 1.4;
    /* Ограничение количества строк (троеточие) */
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0.9;
}

/* Кнопка "Взять" */
.use-lyrics-btn {
    width: 100%;
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 8px 0;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.use-lyrics-btn:hover {
    background-color: var(--primary);
    color: #000;
    border-color: var(--primary);
    box-shadow: 0 0 15px rgba(250, 191, 60, 0.2);
}

/* ==========================================================================
   LYRICS EDIT SCREEN (РЕДАКТОР ТЕКСТА - СТУДИЙНЫЙ СТИЛЬ)
   ========================================================================== */

/* Контейнер экрана редактирования */
#lyrics-edit-screen {
    display: none; /* JS включает flex */
    flex-direction: column;
    width: 100%;
    max-width: 1000px; /* Ограничиваем ширину на больших экранах */
    margin: 0 auto;
    height: 100%;
    gap: 1.5rem;
    padding-bottom: 2rem;
    animation: fadeIn 0.4s ease-out; /* Плавное появление */
}

/* Группы полей */
.lyrics-input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
}

/* Лейблы (Заголовки полей) */
#lyrics-edit-screen .form-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Декоративная оранжевая точка перед заголовком */
#lyrics-edit-screen .form-label::before {
    content: '';
    display: block;
    width: 6px;
    height: 6px;
    background-color: var(--primary);
    border-radius: 50%;
    box-shadow: 0 0 5px var(--primary);
}

/* --- ПОЛЯ ВВОДА (СТИЛЬ IDE/РЕДАКТОРА) --- */
#generated-style-input,
#generated-lyrics-input {
    background-color: #0f0f0f; /* Очень темный фон */
    border: 1px solid var(--border-color);
    color: var(--text-main);
    border-radius: var(--radius-md);
    padding: 16px;
    font-size: 1rem;
    line-height: 1.6;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    width: 100%;
    resize: none; /* Убираем уголок растягивания */
    
    /* Эффект "вдавленности" */
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.6);
}

/* Эффект при наведении */
#generated-style-input:hover,
#generated-lyrics-input:hover {
    border-color: rgba(255, 255, 255, 0.2);
    background-color: #161616;
}

/* Эффект при фокусе (Неоновая подсветка) */
#generated-style-input:focus,
#generated-lyrics-input:focus {
    border-color: var(--primary);
    background-color: #1a1a1a;
    outline: none;
    box-shadow: 0 0 0 1px rgba(250, 191, 60, 0.3), inset 0 2px 6px rgba(0, 0, 0, 0.6);
}

/* Специфика поля Стиль */
#generated-style-input {
    min-height: 80px;
    font-family: var(--font-family);
    font-weight: 500;
    color: var(--primary); /* Стиль подсвечиваем оранжевым */
}

/* Специфика поля Текст (Моноширинный шрифт для ритма) */
#generated-lyrics-input {
    flex-grow: 1; /* Растягиваем на все место */
    font-family: 'Courier New', monospace; 
    white-space: pre-wrap;
    /* Красивый скроллбар */
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

/* ==========================================================================
   КНОПКИ ДЕЙСТВИЙ (LYRICS ACTIONS)
   ========================================================================== */

/* Контейнер для кнопок */
.lyrics-actions-row {
    display: flex;       /* Выстраиваем в ряд */
    gap: 15px;           /* Расстояние между кнопками */
    margin-top: 2rem;    /* Отступ сверху от полей ввода */
    width: 100%;
}

/* 1. Кнопка "НАЗАД" (Второстепенная) */
#back-to-idea-btn {
    flex: 0 0 auto;      /* Не растягивается, ширина по содержимому */
    min-width: 110px;    /* Минимальная ширина для удобства */
    height: 56px;        /* Высота кнопки */
    
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: 12px;
    
    font-family: 'Manrope', sans-serif;
    font-weight: 600;
    font-size: 0.95rem;
    
    transition: all 0.2s ease;
    cursor: pointer;
}

#back-to-idea-btn:hover {
    border-color: var(--text-main);
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.05);
    transform: translateX(-2px); /* Легкий сдвиг влево */
}

/* 2. Кнопка "СОЗДАТЬ ТРЕК" (Основная, Акцентная) */
#send-to-suno-btn {
    flex: 1;             /* Занимает все оставшееся место */
    height: 56px;
    
    background-color: var(--primary); /* #FABF3C (Ваш оранжевый) */
    color: #000000;      /* Черный текст для контраста */
    border: none;
    border-radius: 12px;
    
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;           /* Отступ между иконкой и текстом */
    
    font-family: 'Manrope', sans-serif;
    font-weight: 800;    /* Жирный шрифт */
    font-size: 1.1rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    
    box-shadow: 0 4px 20px rgba(250, 191, 60, 0.25); /* Оранжевое свечение */
    transition: all 0.2s ease-in-out;
    cursor: pointer;
}

/* Ховер эффект для главной кнопки */
#send-to-suno-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 30px rgba(250, 191, 60, 0.4);
    background-color: #ffcf67; /* Чуть светлее */
}

/* Нажатие */
#send-to-suno-btn:active {
    transform: translateY(-1px);
    box-shadow: 0 2px 10px rgba(250, 191, 60, 0.3);
}

/* Настройка иконки ноты внутри кнопки */
#send-to-suno-btn svg {
    width: 22px;
    height: 22px;
    fill: currentColor; /* Цвет берется от цвета текста (черный) */
}

/* --- ПЕРЕКЛЮЧАТЕЛЬ (СОХРАНЯЕМ ВАШ, НО ВЫРАВНИВАЕМ) --- */
.custom-switch-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    padding: 5px 0;
}

.custom-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
    margin-bottom: 0;
}

.custom-switch input { opacity: 0; width: 0; height: 0; }

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px; width: 18px;
    left: 3px; bottom: 3px;
    background-color: var(--text-secondary);
    transition: .4s;
    border-radius: 50%;
}

.custom-switch input:checked + .slider {
    background-color: rgba(250, 191, 60, 0.2);
    border-color: var(--primary);
}

.custom-switch input:checked + .slider:before {
    transform: translateX(22px);
    background-color: var(--primary);
    box-shadow: 0 0 10px var(--primary-glow);
}

.switch-label-text {
    font-size: 0.95rem;
    color: var(--text-secondary);
    transition: 0.3s;
}
.custom-switch input:checked ~ .switch-label-text {
    color: var(--text-main);
}

/* --- АДАПТИВ ДЛЯ МОБИЛЬНЫХ --- */
@media (max-width: 768px) {
    #lyrics-edit-screen {
        padding: 0;
        gap: 1rem;
    }

    #generated-lyrics-input {
        font-size: 0.9rem; /* Чуть меньше шрифт на телефоне */
        padding: 12px;
    }

    .lyrics-actions {
        /* На телефоне кнопки становятся в столбик или остаются 1/2 если экран широкий */
        grid-template-columns: 1fr 1.5fr; 
        gap: 10px;
    }

    .lyrics-actions-row {
        flex-direction: column-reverse; /* Кнопка "Назад" уходит вниз */
        gap: 10px;
    }
    
    #back-to-idea-btn {
        width: 100%; /* На телефоне кнопки во всю ширину */
        height: 48px;
    }
    
    #send-to-suno-btn {
        width: 100%;
        height: 56px;
    }
}