* { box-sizing: border-box; margin: 0; padding: 0; }
body { 
    font-family: system-ui, sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    min-height: 100vh; color: #fff;
}
.container { max-width: 900px; margin: 0 auto; padding: 20px; }
h1 { text-align: center; padding: 15px 0; font-size: 1.5em; }
.subtitle { text-align: center; font-size: 0.85em; color: rgba(255,255,255,0.5); margin-bottom: 15px; }

/* Loading Overlay */
#loadingOverlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.95);
    display: flex; flex-direction: column;
    justify-content: center; align-items: center;
    z-index: 1000; transition: opacity 0.5s;
}
#loadingOverlay.hidden { opacity: 0; pointer-events: none; }
.loading-spinner {
    width: 50px; height: 50px;
    border: 4px solid rgba(255,255,255,0.1);
    border-top-color: #7c3aed;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 
    0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(124,58,237,0.7); }
    50% { transform: scale(1.1); box-shadow: 0 0 0 10px rgba(124,58,237,0); }
}
.loading-text { margin-top: 20px; font-size: 1.2em; }
.loading-status { margin-top: 10px; color: rgba(255,255,255,0.6); }
.loading-error { color: #ef4444; margin-top: 15px; max-width: 400px; text-align: center; }

.checklist { margin-top: 25px; width: 350px; }
.check-item { 
    padding: 10px 12px; margin: 6px 0;
    background: rgba(255,255,255,0.05);
    border-radius: 8px;
    display: flex; align-items: center; gap: 10px;
    font-size: 0.9em;
}
.check-item.done { background: rgba(34,197,94,0.2); }
.check-item.active { background: rgba(124,58,237,0.3); border: 1px solid #7c3aed; }
.check-item .url { font-size: 0.75em; color: rgba(255,255,255,0.4); }

/* GPU Monitor */
.gpu-monitor {
    background: rgba(0,0,0,0.3);
    border-radius: 12px; padding: 12px 15px; margin-bottom: 15px;
}
.gpu-header { 
    display: flex; justify-content: space-between; 
    align-items: center; margin-bottom: 8px; 
    font-size: 0.85em; color: rgba(255,255,255,0.7);
}
.server-info {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 8px; font-size: 0.75em; color: rgba(255,255,255,0.5);
    margin-bottom: 10px; padding-bottom: 10px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.server-item {
    display: flex; align-items: center; gap: 6px;
    background: rgba(255,255,255,0.05);
    padding: 6px 10px; border-radius: 6px;
}
.server-item .icon { font-size: 1.1em; }
.server-item .name { color: rgba(255,255,255,0.8); }
.server-item .port { font-size: 0.85em; color: rgba(255,255,255,0.5); }
.server-item .status { 
    margin-left: auto; 
    width: 10px; height: 10px; 
    border-radius: 50%; 
    background: #22c55e;
    box-shadow: 0 0 6px #22c55e;
    transition: all 0.3s;
}
.server-item .status.offline { 
    background: #ef4444; 
    box-shadow: 0 0 6px #ef4444;
    animation: blink 1s infinite;
}
@keyframes blink {
    50% { opacity: 0.5; }
}

.gpu-stats { display: flex; gap: 15px; flex-wrap: wrap; }
.stat-item { text-align: center; min-width: 60px; }
.stat-value { font-size: 1.3em; font-weight: bold; }
.stat-label { font-size: 0.65em; color: rgba(255,255,255,0.5); text-transform: uppercase; }
.stat-value.speed { color: #22c55e; }
.vram-bar {
    width: 100%; height: 8px;
    background: rgba(255,255,255,0.1);
    border-radius: 4px; margin-top: 10px; overflow: hidden;
}
.vram-fill { height: 100%; border-radius: 4px; transition: width 0.3s; }
.vram-low { background: linear-gradient(90deg, #22c55e, #4ade80); }
.vram-mid { background: linear-gradient(90deg, #eab308, #facc15); }
.vram-high { background: linear-gradient(90deg, #ef4444, #f87171); }

/* Chat */
#chat { 
    background: rgba(255,255,255,0.05); 
    border-radius: 12px; height: 50vh; 
    overflow-y: auto; padding: 15px; margin-bottom: 15px;
}
.msg { 
    margin: 8px 0; padding: 10px 14px; 
    border-radius: 12px; max-width: 85%;
    white-space: pre-wrap; word-wrap: break-word;
    position: relative;
}
.user { background: #7c3aed; margin-left: auto; }
.bot { background: rgba(255,255,255,0.1); }
.system { 
    background: rgba(255,193,7,0.2); 
    text-align: center; max-width: 100%; 
    font-size: 0.85em; 
}
.msg-header {
    font-size: 0.75em;
    color: rgba(255,255,255,0.6);
    margin-bottom: 4px;
}
.lang-badge, .speed-badge {
    display: inline-block;
    padding: 2px 6px;
    background: rgba(255,255,255,0.15);
    border-radius: 4px;
    font-size: 0.7em;
    margin-left: 5px;
}
.speed-badge {
    background: rgba(34,197,94,0.3);
    color: #4ade80;
}

/* Action Buttons */
.msg-actions {
    position: absolute;
    right: 8px;
    bottom: 8px;
    display: flex;
    gap: 4px;
}
.action-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.2s;
    font-size: 12px;
}
.action-btn:hover { opacity: 1; }
.action-btn.playing { background: #22c55e; opacity: 1; }

/* Controls */
.controls { display: flex; gap: 10px; flex-wrap: wrap; }
#textInput { 
    flex: 1; min-width: 200px; padding: 12px 15px; 
    border-radius: 12px; border: none; 
    background: rgba(255,255,255,0.1); 
    color: #fff; font-size: 1em;
}
#textInput:disabled { opacity: 0.5; }

button { 
    padding: 12px 18px; border-radius: 12px; border: none; 
    cursor: pointer; font-size: 1em; font-weight: 600;
    transition: all 0.2s;
}
button:hover:not(:disabled) { transform: scale(1.05); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

#recordBtn { background: #ef4444; color: white; min-width: 50px; }
#recordBtn.recording { background: #22c55e; animation: pulse 1s infinite; }
#recordBtn.stop-btn { background: #f59e0b; animation: none; }
@keyframes pulse { 50% { opacity: 0.7; } }

#sendBtn { background: #7c3aed; color: white; }

.status-bar { 
    display: flex; justify-content: space-between;
    align-items: center; padding: 8px 0;
    font-size: 0.8em; color: rgba(255,255,255,0.5);
}

/* TTS Control */
.tts-control {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 8px;
    background: rgba(255,255,255,0.05);
    transition: background 0.2s;
}
.tts-control:hover { background: rgba(255,255,255,0.1); }
#ttsStatus { font-size: 0.85em; }
#ttsStatus.off { color: rgba(255,255,255,0.4); }
#ttsStatus.on { color: #4ade80; }
#ttsStatus.loading { color: #fbbf24; }
#ttsStatus.playing { color: #22c55e; }

.tts-progress {
    width: 60px;
    height: 4px;
    background: rgba(255,255,255,0.2);
    border-radius: 2px;
    overflow: hidden;
}
.tts-progress-bar {
    height: 100%;
    background: #22c55e;
    width: 0%;
    transition: width 0.1s;
}

#ttsStopBtn {
    background: #f59e0b;
    border: none;
    border-radius: 4px;
    padding: 2px 8px;
    cursor: pointer;
    font-size: 14px;
    color: white;
}
#ttsStopBtn:hover { background: #d97706; }

.toggle-container { display: flex; align-items: center; gap: 8px; }
.toggle {
    width: 40px; height: 22px;
    background: rgba(255,255,255,0.2);
    border-radius: 11px;
    position: relative;
    cursor: pointer;
    transition: background 0.3s;
}
.toggle.active { background: #22c55e; }
.toggle::after {
    content: '';
    position: absolute;
    width: 18px; height: 18px;
    background: white;
    border-radius: 50%;
    top: 2px; left: 2px;
    transition: transform 0.3s;
}
.toggle.active::after { transform: translateX(18px); }

/* Voice Selector - Hiển thị sau mỗi câu trả lời của bot */
.voice-selector-wrapper {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 8px;
    padding: 4px 8px;
    background: rgba(0,0,0,0.2);
    border-radius: 8px;
    font-size: 0.85em;
    cursor: pointer;
    transition: background 0.2s;
}

.voice-selector-wrapper:hover {
    background: rgba(0,0,0,0.3);
}

.voice-selector-wrapper label {
    font-size: 1.2em;
    cursor: pointer;
    user-select: none;
}

.voice-selector {
    display: none;
    padding: 4px 8px;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 6px;
    font-size: 0.9em;
    background: rgba(0,0,0,0.6);
    color: #fff;
    cursor: pointer;
    transition: all 0.2s;
    max-width: 220px;
}

.voice-selector.show {
    display: inline-block;
}

.voice-selector:hover {
    border-color: rgba(255,255,255,0.5);
    background: rgba(0,0,0,0.7);
}

.voice-selector:focus {
    outline: none;
    border-color: #4ade80;
    box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.2);
}

.voice-selector option.cached { background: rgba(34,197,94,0.2); }

/* Cache info */
.cache-info {
    font-size: 0.7em;
    color: rgba(255,255,255,0.4);
    text-align: center;
    padding: 4px 0;
}
