/* 基本樣式重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* 移動設備優化 */
html {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    touch-action: manipulation;
}

/* 深色模式變數 */
:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --text-primary: #1d1d1f;
    --text-secondary: #6e6e73;
    --border-color: #e5e5ea;
}

.dark {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2a2a2a;
    --text-primary: #e5e5ea;
    --text-secondary: #a1a1a6;
    --border-color: #3a3a3a;
}

/* 容器樣式 */
.container {
    width: 100%;
    min-height: 100vh;
    padding: 10px;
    display: flex;
    flex-direction: column;
}

/* 桌面版保持原有固定高度 */
@media (min-width: 1025px) {
    .container {
        height: 100vh;
        overflow: hidden;
    }
}

/* 載入畫面 */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.3s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-content {
    text-align: center;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f3f3;
    border-top-width: 4px;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-progress {
    width: 200px;
    height: 4px;
    margin: 0 auto;
}

.progress-bar {
    height: 100%;
    width: 0%;
    transition: width 0.3s ease;
}

/* 標題與控制區 */
.header-section {
    flex-shrink: 0;
    margin-bottom: 10px;
}

.control-status-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 20px;
}

.control-group {
    display: flex;
    gap: 10px;
}

.status-group {
    display: flex;
    gap: 20px;
    align-items: center;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.vad-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.vad-indicator.inactive {
    background-color: #d1d1d6;
}

.vad-indicator.active {
    background-color: #34c759;
    box-shadow: 0 0 8px rgba(52, 199, 89, 0.5);
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.8; }
    100% { transform: scale(1); opacity: 1; }
}

.model-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* 按鈕基礎樣式 */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 500;
    transition: all 0.2s ease;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    border: none;
    outline: none;
    min-height: 44px; /* 符合觸控建議的最小尺寸 */
    min-width: 44px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 觸控設備按鈕優化 */
@media (pointer: coarse) {
    .btn {
        min-height: 48px;
        min-width: 48px;
        padding: 10px 16px;
    }
    
    .btn-sm {
        min-height: 40px;
        min-width: 40px;
        padding: 8px 12px;
    }
    
    /* 增加觸控友好的間距 */
    .control-group {
        gap: 12px;
    }
    
    .download-buttons {
        gap: 12px;
    }
}

/* 主要內容區 */
.main-content {
    display: flex;
    gap: 12px;
    flex: 1;
    min-height: 400px;
}

/* 桌面版固定高度 */
@media (min-width: 1025px) {
    .main-content {
        min-height: 0;
        height: calc(100vh - 110px);
    }
}

/* 視覺化欄位 */
.visualization-column {
    flex: 1.5;
    display: flex;
    flex-direction: column;
}

.chart-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chart-container h3::before {
    content: '';
    width: 3px;
    height: 14px;
    background: currentColor;
    border-radius: 2px;
    margin-right: 8px;
}

.canvas-wrapper {
    width: 100%;
    height: calc(100% - 35px);
    min-height: 100px;
    position: relative;
}

canvas {
    width: 100%;
    height: 100%;
    display: block;
    border: 1px solid var(--border-color);
}

/* 結果欄位 */
.results-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.results-column h3::before {
    content: '';
    width: 3px;
    height: 14px;
    background: currentColor;
    border-radius: 2px;
    margin-right: 8px;
}

.results-container {
    flex: 1;
    overflow-y: auto;
    border: 1px solid #e5e5ea;
    padding: 12px;
    max-height: calc(100% - 40px);
}

/* 轉譯項目樣式 */
.transcription-item {
    padding: 12px;
    margin-bottom: 8px;
    background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
    border-radius: 8px;
    animation: slideIn 0.3s ease;
    position: relative;
    border: 1px solid #e5e5ea;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.dark .transcription-item {
    background: linear-gradient(135deg, #2a2a2a 0%, #1a1a1a 100%);
    border-color: #3a3a3a;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.transcription-item:hover {
    transform: translateX(5px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    border-color: #0066cc;
}

.transcription-item .timestamp {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.transcription-item .timestamp::before {
    content: '\f017';
    font-family: 'Font Awesome 6 Free';
    font-weight: 400;
    margin-right: 4px;
}

.transcription-item .text {
    font-size: 14px;
    color: var(--text-primary);
    word-wrap: break-word;
    margin-bottom: 4px;
    line-height: 1.5;
}

.audio-controls {
    position: absolute;
    top: 12px;
    right: 12px;
}

.play-btn {
    background: linear-gradient(135deg, #0066cc 0%, #004499 100%);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    box-shadow: 0 2px 4px rgba(0, 102, 204, 0.2);
}

.play-btn:hover {
    background: linear-gradient(135deg, #0051a3 0%, #003366 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 102, 204, 0.3);
}

.play-btn:active {
    transform: translateY(0);
}

/* 移除 ::before 偽元素，因為我們會使用 Font Awesome class */

/* 動畫 */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* 滾動條美化 */
.results-container::-webkit-scrollbar {
    width: 8px;
}

.results-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.results-container::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.results-container::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* 主題切換按鈕 */
.theme-toggle {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.theme-toggle:hover {
    transform: scale(1.1);
}

/* 語言選擇器深色模式 */
#languageSelect {
    color: #1f2937;
}

.dark #languageSelect {
    color: #e5e7eb;
}

#languageSelect option {
    background-color: #f3f4f6;
    color: #1f2937;
}

.dark #languageSelect option {
    background-color: #374151;
    color: #e5e7eb;
}

/* 響應式設計 */

/* 平板橫向 (1024px 以下) */
@media (max-width: 1024px) {
    .control-status-row {
        flex-wrap: wrap;
        padding: 10px 15px;
    }
    
    .main-content {
        flex-direction: column;
        gap: 16px;
    }
    
    .visualization-column {
        flex-direction: row;
        min-height: 300px;
    }
    
    .results-column {
        min-height: 400px;
    }
    
    /* 調整圖表容器高度 */
    .chart-container {
        min-height: 200px;
    }
}

/* 平板直向與小型平板 (768px 以下) */
@media (max-width: 768px) {
    .container {
        padding: 8px;
    }
    
    .control-status-row {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        padding: 12px;
    }
    
    .control-group {
        justify-content: center;
        flex-wrap: wrap;
    }
    
    .status-group {
        justify-content: space-around;
        flex-wrap: wrap;
    }
    
    .model-group {
        justify-content: center;
        flex-wrap: wrap;
    }
    
    .visualization-column {
        flex-direction: column;
        gap: 16px;
    }
    
    .chart-container {
        min-height: 180px;
    }
    
    .results-column {
        min-height: 300px;
    }
    
    /* 標題適配 */
    h1 {
        font-size: 1.25rem !important;
        text-align: center;
    }
    
    /* 按鈕大小適配 */
    .btn {
        padding: 8px 12px !important;
        font-size: 14px;
    }
    
    .btn-sm {
        padding: 6px 10px !important;
        font-size: 12px;
    }
}

/* 手機橫向 (640px 以下) */
@media (max-width: 640px) {
    .container {
        padding: 6px;
    }
    
    .header-section {
        margin-bottom: 8px;
    }
    
    .control-status-row {
        padding: 8px;
        gap: 10px;
    }
    
    .main-content {
        gap: 12px;
    }
    
    .chart-container {
        min-height: 150px;
    }
    
    .results-column {
        min-height: 250px;
    }
    
    /* 下載按鈕區域優化 */
    .download-buttons {
        flex-wrap: wrap;
        gap: 8px !important;
    }
    
    .download-buttons .btn {
        flex: 1;
        min-width: 100px;
    }
}

/* 手機直向 (480px 以下) */
@media (max-width: 480px) {
    .container {
        padding: 4px;
    }
    
    .control-status-row {
        padding: 6px;
    }
    
    .main-content {
        gap: 10px;
    }
    
    /* 更緊湊的控制按鈕 */
    .control-group {
        gap: 6px;
    }
    
    .btn {
        padding: 6px 10px !important;
        font-size: 13px;
    }
    
    .btn-sm {
        padding: 4px 8px !important;
        font-size: 11px;
    }
    
    /* 狀態指示器調整 */
    .status-group {
        gap: 12px;
    }
    
    .status-item {
        font-size: 12px;
    }
    
    /* 圖表區域最小化 */
    .chart-container {
        min-height: 120px;
    }
    
    .chart-container h3 {
        font-size: 14px;
        margin-bottom: 8px;
    }
    
    .results-column {
        min-height: 200px;
    }
    
    /* 轉譯項目緊湊化 */
    .transcription-item {
        padding: 8px;
        margin-bottom: 6px;
    }
    
    .transcription-item .timestamp {
        font-size: 10px;
    }
    
    .transcription-item .text {
        font-size: 13px;
        line-height: 1.4;
    }
    
    .audio-controls {
        top: 8px;
        right: 8px;
    }
    
    .play-btn {
        padding: 3px 8px;
        font-size: 11px;
    }
}

/* 超小螢幕 (360px 以下) */
@media (max-width: 360px) {
    .container {
        padding: 2px;
    }
    
    h1 {
        font-size: 1.1rem !important;
    }
    
    .control-status-row {
        padding: 4px;
    }
    
    .btn {
        padding: 4px 8px !important;
        font-size: 12px;
    }
    
    .chart-container {
        min-height: 100px;
    }
    
    .results-column {
        min-height: 180px;
    }
    
    .transcription-item {
        padding: 6px;
    }
    
    .transcription-item .text {
        font-size: 12px;
    }
}

/* iOS Safari 特殊優化 */
@supports (-webkit-touch-callout: none) {
    /* iOS Safari 視窗高度修正 */
    .container {
        min-height: -webkit-fill-available;
    }
    
    /* 防止橡皮筋效果 */
    body {
        position: fixed;
        overflow: hidden;
        width: 100%;
        height: 100%;
    }
    
    /* 但在平板和手機上允許滾動 */
    @media (max-width: 1024px) {
        body {
            position: static;
            overflow: visible;
            height: auto;
        }
    }
    
    /* iOS 輸入元素優化 */
    input, select, button {
        -webkit-appearance: none;
        border-radius: 0;
    }
    
    /* 防止縮放 */
    input[type="file"] {
        font-size: 16px;
    }
}

/* 日誌視窗深色模式樣式 */
#logWindow {
    --log-window-bg: rgba(255, 255, 255, 0.95);
    --log-window-border: rgba(255, 255, 255, 0.3);
}

#logWindow.dark {
    --log-window-bg: rgba(26, 26, 26, 0.95);
    --log-window-border: rgba(58, 58, 58, 0.5);
    background: rgba(26, 26, 26, 0.95);
    border-color: rgba(58, 58, 58, 0.5);
}

#logWindow #logHeader {
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
}

#logWindow #logHeader span {
    color: #495057;
}

#logWindow.dark #logHeader {
    background: #2a2a2a;
    border-bottom-color: #3a3a3a;
}

#logWindow.dark #logHeader span {
    color: #e5e5ea;
}

#logWindow #logContent {
    background: #ffffff;
}

#logWindow.dark #logContent {
    background: #1a1a1a;
    color: #e5e5ea;
}

#logWindow.dark .log-entry {
    border-bottom-color: #3a3a3a;
}

#logWindow.dark .log-entry:hover {
    background: #2a2a2a;
}

#logWindow.dark #logClear,
#logWindow.dark #logClose {
    color: #a1a1a6;
}

#logWindow.dark #logClear:hover {
    background: #3a3a3a !important;
    color: #e5e5ea;
}

#logWindow.dark #logClose:hover {
    color: #ff6b6b !important;
}

#logWindow.dark #logResize {
    background: linear-gradient(135deg, transparent 50%, #3a3a3a 50%);
}

/* 設定視窗深色模式樣式 */
#settingsWindow {
    --settings-window-bg: rgba(255, 255, 255, 0.95);
    --settings-window-border: rgba(255, 255, 255, 0.3);
    --settings-content-bg: #ffffff;
    --select-bg: white;
    --select-color: #333;
}

#settingsWindow.dark {
    --settings-window-bg: rgba(26, 26, 26, 0.95);
    --settings-window-border: rgba(58, 58, 58, 0.5);
    --settings-content-bg: #1a1a1a;
    --select-bg: #374151;
    --select-color: #e5e7eb;
    background: rgba(26, 26, 26, 0.95);
    border-color: rgba(58, 58, 58, 0.5);
}

#settingsWindow #settingsHeader {
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
}

#settingsWindow #settingsHeader span {
    color: #495057;
}

#settingsWindow.dark #settingsHeader {
    background: #2a2a2a;
    border-bottom-color: #3a3a3a;
}

#settingsWindow.dark #settingsHeader span {
    color: #e5e5ea;
}

#settingsWindow.dark #settingsContent {
    background: #1a1a1a;
    color: #e5e5ea;
}

#settingsWindow.dark .setting-item {
    border-bottom-color: #3a3a3a;
}

#settingsWindow.dark .setting-item:hover {
    background: #2a2a2a;
}

#settingsWindow .setting-item label {
    color: #333;
}

#settingsWindow .setting-item .toggle-label > div > div:first-child {
    color: #333;
}

#settingsWindow .setting-item .toggle-label > div > div:last-child {
    color: #666;
}

#settingsWindow.dark .setting-item label {
    color: #e5e5ea;
}

#settingsWindow.dark .setting-item .toggle-label > div > div:first-child {
    color: #e5e5ea;
}

#settingsWindow.dark .setting-item .toggle-label > div > div:last-child {
    color: #a1a1a6;
}

#settingsWindow.dark label {
    color: #e5e5ea;
}

#settingsWindow.dark input[type="checkbox"] {
    background: #2a2a2a;
    border-color: #3a3a3a;
}

#settingsWindow.dark input[type="checkbox"]:checked {
    background: #0066cc;
    border-color: #0066cc;
}

#settingsWindow.dark input[type="range"] {
    background: #2a2a2a;
}

#settingsWindow.dark input[type="range"]::-webkit-slider-track {
    background: #3a3a3a;
}

#settingsWindow.dark input[type="range"]::-webkit-slider-thumb {
    background: #0066cc;
    border-color: #004499;
}

#settingsWindow.dark input[type="range"]::-moz-range-track {
    background: #3a3a3a;
}

#settingsWindow.dark input[type="range"]::-moz-range-thumb {
    background: #0066cc;
    border-color: #004499;
}

#settingsWindow.dark select {
    background: #2a2a2a;
    color: #e5e5ea;
    border-color: #3a3a3a;
}

#settingsWindow.dark select option {
    background: #2a2a2a;
    color: #e5e5ea;
}

#settingsWindow.dark #settingsSave,
#settingsWindow.dark #settingsClose {
    color: #a1a1a6;
}

#settingsWindow.dark #settingsSave:hover {
    color: #28a745;
}

#settingsWindow.dark #settingsClose:hover {
    color: #ff6b6b !important;
}

/* 即時轉譯顯示樣式 */
.interim-transcription {
    padding: 12px;
    margin-bottom: 8px;
    background: linear-gradient(135deg, #fff3cd 0%, #ffeaa7 100%);
    border: 1px solid #ffeaa7;
    border-radius: 8px;
    font-style: normal;
    color: #856404;
    position: relative;
    display: inline-block;
}

.dark .interim-transcription {
    background: linear-gradient(135deg, #564217 0%, #6b5220 100%);
    border-color: #6b5220;
    color: #ffd93d;
}

/* 終端機游標效果 */
.interim-transcription::after {
    content: '|';
    display: inline-block;
    margin-left: 2px;
    animation: blink-cursor 0.6s ease-in-out infinite;
    font-weight: normal;
    color: inherit;
}

@keyframes blink-cursor {
    0%, 49% {
        opacity: 1;
    }
    50%, 100% {
        opacity: 0;
    }
}