/*
    ========================================
    MODERN & MINIMALIST STYLESHEET
    Designed for the Dictation App
    ========================================
*/

:root {
    /* === MODERNIZED COLOR PALETTE === */
    --primary-color: #007aff;      /* Apple's classic blue for a modern feel */
    --primary-hover: #005ecb;      /* A darker shade for interaction */
    --text-color: #1d1d1f;        /* Near-black for sharp text (body) */
    --text-secondary: #6e6e73;    /* Gray for secondary info */
    --bg-color: #f5f5f7;          /* A slightly off-white, clean background */
    --content-bg: #ffffff;        /* Pure white for content containers */
    --border-color: #d2d2d7;      /* A light, subtle border color */
    --success-color: #34c759;     /* Green for success states */
    --danger-color: #ff3b30;       /* Red for destructive actions */
    --warning-color: #ff9500;     /* Orange for warnings or AI buttons */
    --highlight-bg: #e5f2ff;      /* Light blue to highlight items */

    /* === TYPOGRAPHY & SPACING === */
    --font-family: 'Manrope', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --base-font-size: 16px;
    --border-radius: 12px;        /* Consistent, modern rounded corners */
    --shadow: 0 6px 18px rgba(0, 0, 0, 0.07); /* A softer, more diffused shadow */
    --transition-speed: 0.2s;     /* Consistent transition for interactions */
}

/* === GLOBAL RESET & BODY STYLES === */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-color);
    padding: 24px;
    font-size: var(--base-font-size);
    line-height: 1.6;
}

/* === MAIN APP LAYOUT === */
.app-container {
    max-width: 1800px;
    margin: 0 auto;
    display: grid;
    gap: 24px;
    grid-template-columns: 1fr; /* Mobile-first approach */
    grid-template-areas:
        "header"
        "playlist"
        "main"
        "history";
}

.app-header {
    grid-area: header;
    text-align: center;
    margin-bottom: 16px;
}
.app-header h1 {
    font-size: 2.25rem;
    font-weight: 700;
    color: var(--text-color);
}
.app-header p {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* === SHARED COMPONENTS (Buttons, etc.) === */
.button {
    display: inline-block;
    padding: 12px 24px;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-weight: 600;
    font-family: inherit;
    border: 1px solid transparent;
    transition: all var(--transition-speed) ease;
    font-size: 1rem;
    text-align: center;
}
.button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}
.button.primary { background-color: var(--primary-color); color: white; }
.button.primary:hover { background-color: var(--primary-hover); }

.button-outline {
    background-color: transparent;
    color: var(--primary-color);
    border-color: var(--primary-color);
}
.button-outline:hover, .button-outline.active {
    background-color: var(--primary-color);
    color: white;
}

/* === BASE STYLES FOR CONTENT SECTIONS === */
.playlist-section, .player-section, .results-history-section {
    background: var(--content-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 24px;
    display: flex;
    flex-direction: column;
}

/* === PLAYLIST SECTION === */
.playlist-section { grid-area: playlist; }
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 12px;
}
.section-header h2 { font-size: 1.25rem; }

.folder-selector .button { width: 100%; margin-bottom: 16px; }

#playlist {
    list-style-type: none;
    overflow-y: auto;
    flex-grow: 1;
    max-height: 70vh; /* Set max-height for scrolling */
}
#playlist li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    padding: 12px;
    border-bottom: 1px solid var(--bg-color);
    cursor: pointer;
    transition: background-color var(--transition-speed) ease;
    border-radius: 8px; /* Slightly smaller radius for list items */
}
#playlist li:last-child { border-bottom: none; }
#playlist li:hover { background-color: var(--highlight-bg); }
#playlist li.active {
    background-color: var(--primary-color);
    color: white;
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3);
}
#playlist li.completed {
    background-color: #eef7ee; /* Light green background */
    color: var(--text-secondary);
    opacity: 0.8;
}
#playlist li.completed .track-number { background-color: var(--success-color); color: white; }
#playlist li.active .track-number { background-color: white; color: var(--primary-color); }
#playlist li.active .track-duration { color: white; }

.track-details { display: flex; align-items: center; flex-grow: 1; min-width: 0; }
.track-number {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: var(--bg-color);
    color: var(--text-secondary);
    font-weight: 700;
    font-size: 0.9rem;
    margin-right: 12px;
    display: grid;
    place-items: center;
}
.track-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track-duration { flex-shrink: 0; font-size: 0.9rem; color: var(--text-secondary); }

/* === MAIN PLAYER SECTION === */
.player-section { grid-area: main; }
.track-info h3 { margin: 0 0 16px; font-size: 1.5rem; }
#audio-player { width: 100%; margin-bottom: 24px; }
.controls-container { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 24px; }
#listen-write-input, #translation-input {
    flex-grow: 1;
    padding: 12px 15px;
    font-size: 1.1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: all var(--transition-speed) ease;
    width: 100%;
}
#listen-write-input:focus, #translation-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.2);
    outline: none;
}
#display-area {
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    min-height: 150px;
    max-height: 300px;
    overflow-y: auto;
    padding: 20px;
}
#subtitle-container p {
    padding: 4px 8px;
    border-radius: 4px;
    transition: background-color 0.3s ease;
    user-select: none;
}
#subtitle-container p.highlight {
    font-weight: 700;
    color: var(--primary-color);
    background-color: var(--highlight-bg);
}

/* === LOG & AI CHECK SECTION === */
.log-and-check-container { margin-top: 24px; }
.log-and-check-container h4 { margin-bottom: 12px; font-size: 1.1rem; }
#log-container {
    background-color: #1d1d1f; /* Dark background for contrast */
    color: #f5f5f7;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 16px;
    font-family: "SF Mono", "Fira Code", monospace;
    max-height: 200px;
    overflow-y: auto;
}
.button.button-gemini {
    width: 100%;
    padding: 12px;
    font-size: 1.1rem;
    background-color: var(--warning-color);
    color: white;
}
.button.button-gemini:disabled {
    background-color: var(--border-color);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(255, 150, 0, 0.6); }
    70% { box-shadow: 0 0 0 12px rgba(255, 150, 0, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 150, 0, 0); }
}
.button-gemini.ready-to-check { animation: pulse 1.5s infinite; }

/* === HISTORY & RESULTS SECTION === */
.results-history-section { grid-area: history; }
#gemini-result-container {
    padding: 20px;
    background-color: #f8f8f8;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    line-height: 1.7;
    margin-bottom: 24px;
}
#gemini-result-container:empty { display: none; }
.gemini-result-title {
    font-size: 1.2rem;
    color: var(--text-color);
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
}
.gemini-result-title .audio-name { font-weight: 700; }
.gemini-result-title .date { font-size: 0.9rem; color: var(--text-secondary); }
#gemini-result-container h2 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary-color);
    margin-top: 20px;
    margin-bottom: 10px;
}
#gemini-result-container ul { list-style-position: inside; padding-left: 10px; }
#history-chart-container { width: 100%; height: 300px; margin-bottom: 24px; }
#history-table-container { max-height: 400px; overflow-y: auto; }
#history-table { width: 100%; border-collapse: collapse; }
#history-table th, #history-table td {
    border: 1px solid var(--border-color);
    padding: 12px;
    text-align: left;
}
#history-table th { background-color: var(--bg-color); position: sticky; top: 0; }
#history-table tbody tr.has-feedback { cursor: pointer; }
#history-table tbody tr.has-feedback:hover { background-color: var(--highlight-bg); }

.hidden { display: none !important; }

/*
    ========================================
    RESPONSIVE DESIGN ENHANCEMENTS
    ========================================
*/

/* --- TABLET VIEW --- */
@media (min-width: 768px) {
    .app-container {
        grid-template-columns: 320px 1fr; /* Playlist on the side */
        grid-template-areas:
            "header header"
            "playlist main"
            "history history";
    }
}

/* --- LARGE DESKTOP VIEW --- */
@media (min-width: 1200px) {
    .app-container {
        grid-template-columns: 350px 1fr 400px; /* Three-column layout */
        grid-template-rows: auto 1fr;
        grid-template-areas:
            "header header header"
            "playlist main history";
    }
    .playlist-section, .results-history-section {
        max-height: calc(100vh - 120px); /* Adjust height for viewport */
        overflow-y: auto;
    }
}
/*
========================================
IMPROVED CONTROLS CONTAINER STYLES
========================================
*/

/*
 * Container chính cho các nút điều khiển
 * Sử dụng Flexbox để căn chỉnh các phần tử con một cách linh hoạt.
 * `flex-wrap: wrap` cho phép các mục tự động xuống dòng trên màn hình nhỏ.
 * `gap` tạo khoảng cách nhất quán giữa các mục.
*/
.controls-container {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px; /* Khoảng cách giữa các nút và nhóm điều khiển */
    background-color: var(--bg-color, #f8f9fa); /* Sử dụng màu nền chung */
    padding: 15px;
    border-radius: var(--border-radius, 12px);
    margin-bottom: 24px;
}

/*
 * Nhóm điều khiển cho phần "Nghỉ giữa câu"
 * Gom label và input thành một khối duy nhất.
*/
.delay-control {
    display: flex;
    align-items: center; /* Căn giữa label và input theo chiều dọc */
    gap: 8px; /* Khoảng cách giữa label và input */
}

/* Kiểu chữ cho nhãn (label) */
.delay-control label {
    font-size: 0.95rem;
    color: var(--text-secondary, #6c757d);
    font-weight: 500;
    white-space: nowrap; /* Tránh label bị xuống dòng */
}

/* Kiểu dáng cho ô nhập số */
#delay-input {
    width: 65px; /* Giảm độ rộng của ô input cho hợp lý */
    padding: 8px 10px;
    font-size: 1rem;
    border: 1px solid var(--border-color, #dee2e6);
    border-radius: 8px; /* Bo góc nhẹ */
    text-align: center;
    transition: all 0.2s ease-in-out;
}

/* Hiệu ứng khi focus vào ô input */
#delay-input:focus {
    border-color: var(--primary-color, #007bff);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.2);
    outline: none;
}
/*
========================================
CẢI TIẾN NÚT BẬT/TẮT CHẾ ĐỘ
========================================
*/

/*
 * Áp dụng cho các nút điều khiển chính trong .controls-container
 * Giúp đồng bộ giao diện và dễ quản lý.
*/
.controls-container .button-outline {
    display: inline-flex; /* Sử dụng flex để căn chỉnh icon và chữ */
    align-items: center;  /* Căn giữa các mục theo chiều dọc */
    gap: 8px;             /* Khoảng cách giữa icon và chữ */
    padding: 10px 18px;   /* Điều chỉnh padding cho cân đối hơn */
    border: 2px solid var(--border-color, #d2d2d7);
    border-radius: var(--border-radius, 12px);
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    background-color: var(--content-bg, #fff);
    color: var(--text-secondary, #6e6e73);
    transition: all 0.2s ease; /* Hiệu ứng chuyển động mượt mà */
}

/*
 * Hiệu ứng khi di chuột qua:
 * Nút sẽ hơi nhô lên và đổi màu để báo hiệu có thể tương tác.
*/
.controls-container .button-outline:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
    border-color: var(--primary-color, #007aff);
    color: var(--primary-color, #007aff);
}

/*
 * TRẠNG THÁI KÍCH HOẠT (.active)
 * Đây là phần quan trọng nhất, cho người dùng biết chế độ đã được bật.
 * Nền xanh, chữ trắng, và có bóng mờ nổi bật.
*/
.controls-container .button-outline.active {
    background-color: var(--primary-color, #007aff);
    border-color: var(--primary-color, #007aff);
    color: white;
    box-shadow: 0 3px 8px rgba(0, 122, 255, 0.35);
}
/*
========================================
CẢI TIẾN NÚT NGHE LẠI (REPLAY BUTTON)
========================================
*/

/*
 * Container chứa ô nhập liệu và nút replay.
 * Sử dụng flex để căn chỉnh các phần tử bên trong.
*/
#input-container {
    display: flex;
    align-items: center;
    gap: 12px; /* Khoảng cách giữa ô input và nút replay */
    width: 100%;
}

/*
 * Kiểu dáng chính cho nút Replay
 * Biến nút thành hình tròn, chỉ có icon, màu sắc nổi bật.
*/
#replay-button {
    flex-shrink: 0; /* Ngăn nút bị co lại khi không đủ không gian */
    width: 44px;    /* Đặt chiều rộng và cao bằng nhau để tạo hình tròn */
    height: 44px;
    padding: 0;     /* Bỏ padding mặc định */
    border-radius: 50%; /* Bo góc 50% để tạo thành hình tròn hoàn hảo */
    border: none;       /* Bỏ đường viền */
    background-color: var(--success-color, #34c759); /* Màu xanh lá cây cho hành động tích cực */
    color: white;
    cursor: pointer;

    /* Căn giữa icon bên trong nút */
    display: flex;
    align-items: center;
    justify-content: center;

    font-size: 1.5rem; /* Tăng kích thước icon cho rõ ràng */
    transition: all 0.2s ease-in-out;
}

/* Hiệu ứng khi di chuột qua */
#replay-button:hover {
    transform: translateY(-2px) scale(1.05); /* Hơi nâng lên và phóng to nhẹ */
    box-shadow: 0 4px 12px rgba(52, 199, 89, 0.4); /* Đổ bóng màu xanh lá */
}

/* Hiệu ứng khi nhấn nút */
#replay-button:active {
    transform: translateY(0) scale(1);
    box-shadow: none;
}

/*
 * Quan trọng: Đảm bảo ô nhập liệu chiếm toàn bộ không gian còn lại
*/
#listen-write-input {
    flex-grow: 1;
}