/**
 * Avatar Voice Interface Styles
 * @version 1.5.0
 */

body {
    margin: 0;
    padding: 0;
    background: center center / cover no-repeat #222;
    color: #fff;
    font-family: sans-serif;
    overflow: hidden;
}

#avatar-container {
    width: 100vw;
    height: 100vh;
    display: block;
}

/* ========== Initial State: Mic Button ========== */
#mic-button-container {
    position: absolute;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
}
#mic-button-container.hidden { display: none; }

/* Loading progress ring */
#loading-indicator {
    position: relative;
    width: 80px;
    height: 80px;
}
#loading-indicator.hidden { display: none; }
#loading-indicator svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}
#loading-indicator circle {
    fill: none;
    stroke-width: 6;
}
#loading-indicator .bg { stroke: rgba(255,255,255,0.2); }
#loading-indicator .progress {
    stroke: white;
    stroke-linecap: round;
    stroke-dasharray: 283;
    stroke-dashoffset: 283;
    transition: stroke-dashoffset 0.3s;
}
#loading-indicator span {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 10px;
    font-variant: small-caps;
    letter-spacing: 1px;
    color: rgba(255,255,255,0.7);
}

/* Mic button */
#mic-button {
    display: none;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: none;
    background: #4338ca;
    color: white;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.1s;
}
#mic-button.ready { display: flex; }
#mic-button img { width: 36px; height: 36px; filter: brightness(0) invert(1); }
#mic-button:hover { background: #3730a3; }
#mic-button:active { transform: scale(0.95); }

/* ========== Conversation Mode: CC Region ========== */
#cc-region {
    display: none;
    position: absolute;
    bottom: 40px;
    left: 20px;
    right: 20px;
    z-index: 100;
    background: rgba(0,0,0,0.7);
    border-radius: 16px;
    padding: 16px;
}
#cc-region.active { display: flex; align-items: center; }

/* Transcript area - continuous chat */
#transcript-box {
    flex: 1;
    min-width: 0;
    font-size: 16px;
    line-height: 1.5;
    height: 96px;
    overflow-y: auto;
}
.user-message { color: #9ca3af; }
.user-message .prefix { color: #6b7280; }
.assistant-message { color: #fff; }
.assistant-message .prefix { color: #818cf8; }
.system-message { color: #9ca3af; }
.error-message { color: #fca5a5; }
.error-message .prefix { color: #ef4444; }
.assistant-message a { color: #fff; text-decoration: underline; }
.assistant-message a:hover { color: #e5e7eb; }
.assistant-message .word {
    animation: word-fade 0.25s ease-out forwards;
}
@keyframes word-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Control buttons */
#cc-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-left: 16px;
    flex-shrink: 0;
}

/* Mic button wrapper with speech progress */
#mic-btn-wrapper {
    position: relative;
    width: 76px;
    height: 76px;
    display: flex;
    align-items: center;
    justify-content: center;
}
#speech-progress {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
    pointer-events: none;
}
#speech-progress.hidden {
    display: none;
}
#speech-progress circle {
    fill: none;
    stroke: #fff;
    stroke-width: 3;
    stroke-linecap: round;
    /* stroke-dasharray and stroke-dashoffset set dynamically by JS based on radius */
}

.cc-btn {
    width: 66px;
    height: 66px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
}
.cc-btn img { width: 30px; height: 30px; filter: brightness(0) invert(1); }
.cc-btn .stop-icon { display: none; }
.cc-btn.stop-mode .mic-icon { display: none; }
.cc-btn.stop-mode .stop-icon { display: block; }

/* Mic button states */
#mic-btn {
    background: #4338ca; /* Blue initial state */
    position: relative;
    overflow: hidden;
}
#mic-btn:hover { background: #3730a3; }

/* Listening state - grayish translucent with glow */
#mic-btn.listening {
    background: rgba(100, 100, 110, 0.6);
    animation: mic-glow 2.5s ease-in-out infinite;
}
#mic-btn.listening:hover { background: rgba(100, 100, 110, 0.7); }
@keyframes mic-glow {
    0%, 100% { box-shadow: 0 0 15px 5px rgba(255, 255, 255, 0.5); }
    50% { box-shadow: 0 0 30px 12px rgba(255, 255, 255, 0.8); }
}

/* No glow modifier - removes glow when not in listening state */
#mic-btn.no-glow {
    animation: none;
}

/* Waiting state - show spinner */
#mic-btn.waiting {
    background: rgba(100, 100, 110, 0.6);
}
#mic-btn.waiting .mic-icon { display: none; }
#mic-btn.waiting::after {
    content: '';
    width: 30px;
    height: 30px;
    border: 3px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
/* In stop-mode, hide spinner and show stop icon */
#mic-btn.waiting.stop-mode::after { display: none; }
#mic-btn.waiting.stop-mode .stop-icon { display: block; }

/* Muted state - shows MUTED text overlay (user enforced mute) */
#mic-btn.muted .mic-icon {
    opacity: 0;
    transition: opacity 0.2s ease-out;
}
#mic-btn.muted::after {
    display: none; /* Hide spinner when muted */
}
#mic-btn.muted .stop-icon {
    display: none; /* Hide stop icon when muted */
}
#mic-btn .muted-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: white;
    opacity: 0;
    transition: opacity 0.2s ease-out;
    text-transform: uppercase;
    z-index: 1;
}
#mic-btn.muted .muted-text {
    opacity: 1;
}

/* ========== Action Links ========== */
#action-links {
    position: fixed;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    color: rgba(255, 255, 255, 0.4);
    z-index: 101;
    display: flex;
    align-items: center;
    gap: 6px;
}
#action-links .separator {
    color: rgba(255, 255, 255, 0.3);
}
#mode-toggle, #disconnect-link, #settings-link {
    cursor: pointer;
    user-select: none;
    transition: color 0.2s;
}
#mode-toggle:hover, #disconnect-link:hover, #settings-link:hover {
    color: rgba(255, 255, 255, 0.7);
}
#status-display {
    user-select: none;
}

/* ========== Metrics Display ========== */
#metrics-display {
    position: fixed;
    top: 12px;
    right: 12px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.4);
    z-index: 101;
    text-align: right;
    line-height: 1.5;
    user-select: none;
}

/* ========== Drafts Panel ========== */
#drafts-panel {
    position: absolute;
    top: 20px;
    left: 20px;
    bottom: 180px;
    width: 320px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 100;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.3) transparent;
}
@media (max-width: 768px) {
    #drafts-panel {
        left: 20px;
        right: 20px;
        width: auto;
        bottom: 180px;
    }
    .draft-card { padding: 12px; }
}
#drafts-panel::-webkit-scrollbar { width: 6px; }
#drafts-panel::-webkit-scrollbar-track { background: transparent; }
#drafts-panel::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.3); border-radius: 3px; }

.draft-card {
    position: relative;
    background: rgba(0,0,0,0.85);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 12px;
    padding: 16px;
    margin-top: 12px;
    flex-shrink: 0;
}
.draft-card-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 20px;
    height: 20px;
    background: rgba(255,255,255,0.1);
    border: none;
    border-radius: 50%;
    color: #9ca3af;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}
.draft-card-close:hover { background: rgba(255,255,255,0.2); color: #fff; }
.draft-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    font-weight: 600;
    font-size: 14px;
}
.draft-card-header .icon { font-size: 18px; }
.draft-card-field { font-size: 13px; margin-bottom: 8px; color: #d1d5db; }
.draft-card-field strong { color: #9ca3af; }
.draft-card-body {
    font-size: 13px;
    color: #e5e7eb;
    background: rgba(255,255,255,0.05);
    padding: 0;
    border-radius: 8px;
    margin: 8px 0;
    white-space: pre-wrap;
}
.draft-card-body a { color: #e5e7eb; text-decoration: underline; }
.draft-card-body a:hover { color: #fff; }
.draft-card-approve {
    width: 100%;
    padding: 10px;
    margin-top: 12px;
    background: #4338ca;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.draft-card-approve:hover { background: #3730a3; }
.draft-card-approve:disabled { background: #6b7280; cursor: not-allowed; }
.draft-card-send-link {
    display: block;
    text-align: center;
    padding: 10px;
    margin-top: 8px;
    color: #60a5fa;
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    transition: color 0.2s;
}
.draft-card-send-link:hover { color: #93c5fd; }
.draft-card-image-container {
    position: relative;
}
.draft-card-image {
    width: 100%;
    height: auto;
    border-radius: 8px;
    display: block;
}
.draft-card-image-download {
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    font-size: 16px;
    transition: background 0.2s;
}
.draft-card-image-download:hover {
    background: rgba(0, 0, 0, 0.8);
}
.draft-card-attachments {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.draft-card-attachment {
    display: flex;
    align-items: center;
    gap: 10px;
}
.draft-card-attachment-preview {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.08);
    font-size: 20px;
}
.draft-card-attachment-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.draft-card-attachment-name {
    font-size: 13px;
    color: #d1d5db;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ========== Settings Modal ========== */
#settings-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 300;
    align-items: center;
    justify-content: center;
}
#settings-modal.active {
    display: flex;
}
.settings-modal-content {
    background: #1a1a2e;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 16px;
    padding: 24px;
    min-width: 320px;
    max-width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
}
.settings-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}
.settings-modal-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #fff;
}
.settings-modal-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: #9ca3af;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: background 0.2s, color 0.2s;
}
.settings-modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}
.settings-section {
    margin-bottom: 20px;
}
.settings-section-label {
    font-size: 12px;
    font-weight: 600;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}
.settings-device-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.settings-device-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}
.settings-device-item:hover {
    background: rgba(255, 255, 255, 0.08);
}
.settings-device-item.selected {
    background: rgba(67, 56, 202, 0.2);
    border-color: #4338ca;
}
.settings-device-radio {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.settings-device-item.selected .settings-device-radio {
    border-color: #4338ca;
}
.settings-device-radio::after {
    content: '';
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #4338ca;
    display: none;
}
.settings-device-item.selected .settings-device-radio::after {
    display: block;
}
.settings-device-name {
    font-size: 14px;
    color: #e5e7eb;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.settings-no-devices {
    color: #9ca3af;
    font-size: 14px;
    padding: 12px;
    text-align: center;
}
.settings-checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 14px;
    color: #e5e7eb;
}
.settings-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #4338ca;
}
.settings-reset-btn {
    width: 100%;
    padding: 12px;
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid rgba(239, 68, 68, 0.4);
    border-radius: 10px;
    color: #fca5a5;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}
.settings-reset-btn:hover {
    background: rgba(239, 68, 68, 0.3);
    border-color: rgba(239, 68, 68, 0.6);
}