/* ===== RESET & BASE ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: #e0e0e0;
    background: #1a1a1a;
    height: 100vh;
    overflow: hidden;
}

/* ===== MAIN LAYOUT ===== */
#chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 800px;
    margin: 0 auto;
    background: #202020;
    border-right: 1px solid #333;
}

/* ===== HEADER ===== */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    background: #202020;
    color: #e0e0e0;
    border-bottom: 1px solid #333;
    flex-shrink: 0;
}

.chat-header h1 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
    color: #e0e0e0;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.status {
    font-size: 0.875rem;
    padding: 0.5rem 1rem;
    background: #333;
    border-radius: 20px;
    color: #b0b0b0;
}

.settings-btn {
    background: none;
    border: none;
    font-size: 0.9rem;
    cursor: pointer;
    color: #b0b0b0;
}

.settings-btn:hover {
    color: #e0e0e0;
}

/* ===== MESSAGES ===== */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 2rem;
    scroll-behavior: smooth;
    min-height: 0;
    background: #1a1a1a;
}

.message {
    margin-bottom: 1.5rem;
    max-width: 85%;
    display: flex;
}

.message.user {
    margin-left: auto;
    justify-content: flex-end;
}

.message.assistant {
    justify-content: flex-start;
}

.message-content {
    padding: 1rem 1.5rem;
    width: fit-content;
    max-width: 600px;
    border-radius: 16px;
    border: 1px solid #333;
}

.message.user .message-content {
    background: #333;
    color: #e0e0e0;
    border-radius: 20px 20px 6px 20px;
}

.message.assistant .message-content {
    background: #2a2a2a;
    color: #e0e0e0;
    border-radius: 20px 20px 20px 6px;
}

/* ===== MESSAGE CONTENT TYPOGRAPHY ===== */
.message-content {
    line-height: 1.5;
}

.message-content > *:first-child {
    margin-top: 0 !important;
}

.message-content > *:last-child {
    margin-bottom: 0 !important;
}

.message-content p {
    margin: 0 0 0.75rem 0;
}

.message-content ul,
.message-content ol {
    margin: 0 0 0.75rem 0;
    padding-left: 1.25rem;
}

.message-content li {
    margin: 0.25rem 0;
}

.message-content li > p {
    margin: 0.25rem 0;
}

.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
    margin: 0.75rem 0 0.5rem 0;
    line-height: 1.3;
}

.message-content blockquote {
    margin: 0.75rem 0;
    padding-left: 1rem;
    border-left: 3px solid #555;
    color: #b0b0b0;
}

.message-content code {
    background: rgba(255, 255, 255, 0.1);
    padding: 0.125rem 0.25rem;
    border-radius: 3px;
    font-size: 0.875em;
}

.message-content pre {
    background: rgba(255, 255, 255, 0.05);
    padding: 0.75rem;
    border-radius: 6px;
    margin: 0.75rem 0;
    overflow-x: auto;
}

.message-content pre code {
    background: none;
    padding: 0;
}

.message.pending .message-content {
    background: #2a2a2a;
    color: #b0b0b0;
}

.message.streaming .message-content {
    background: #2a2a2a;
    color: #e0e0e0;
    border-left: 3px solid #666;
    animation: typing-pulse 1.5s infinite;
}

.message.error .message-content {
    background: #3a2a2a;
    color: #ff9999;
}

/* ===== EMBEDDED CLIPS ===== */
.embedded-clip {
    margin: 1rem 0;
    border: 1px solid #333;
    border-radius: 8px;
    background: #2a2a2a;
    padding: 0.75rem;
    display: flex;
    gap: 12px;
}

.clip-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.clip-header {
    color: #e0e0e0;
    font-weight: 600;
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #333;
    font-size: 14px;
}

.clip-status {
    color: #b0b0b0;
    font-weight: 400;
}

.clip-thumbnail-container {
    flex-shrink: 0;
}

.clip-thumbnail-row {
    margin: 0.5rem 0;
}

.clip-thumb {
    width: 60px;
    height: 60px;
    border-radius: 4px;
    object-fit: cover;
    border: 1px solid #333;
}

.clip-audio-row {
    margin: 0.5rem 0;
}

.clip-audio {
    width: 100%;
    height: 32px;
    outline: none;
}

.clip-loading {
    color: #b0b0b0;
    font-style: italic;
    padding: 0.5rem 0;
    text-align: center;
    background: #333;
    border-radius: 4px;
    margin: 0.5rem 0;
}

/* ===== INPUT AREA ===== */
.chat-input {
    padding: 1.5rem 2rem;
    background: #202020;
    border-top: 1px solid #333;
    flex-shrink: 0;
}

.input-group {
    display: flex;
    gap: 0.75rem;
    max-width: 100%;
}

.message-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid #333;
    border-radius: 8px;
    font-size: 1rem;
    outline: none;
    background: #2a2a2a;
    color: #e0e0e0;
}

.message-input:focus {
    border-color: #555;
}

.message-input:disabled {
    background: #1a1a1a;
    color: #666;
}

.send-btn {
    padding: 0.75rem 1.5rem;
    background: #555;
    color: #e0e0e0;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
}

.send-btn:hover:not(:disabled) {
    background: #666;
}

.send-btn:disabled {
    background: #333;
    cursor: not-allowed;
}

/* ===== MODAL ===== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.modal-content {
    background: #2a2a2a;
    border-radius: 16px;
    width: 100%;
    max-width: 500px;
    max-height: calc(100vh - 2rem);
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    border: 1px solid #333;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 2rem;
    border-bottom: 1px solid #333;
    flex-shrink: 0;
}

.modal-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #e0e0e0;
}

.close-btn {
    background: #333;
    border: 1px solid #555;
    font-size: 1.5rem;
    cursor: pointer;
    color: #e0e0e0;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    transition: all 0.3s ease;
}

.close-btn:hover {
    background: #555;
    transform: scale(1.05);
}

.modal-body {
    padding: 2rem;
    overflow-y: auto;
    flex: 1;
}

.form-group {
    margin-bottom: 2rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.75rem;
    font-weight: 600;
    color: #e0e0e0;
    font-size: 1rem;
}

.token-input {
    width: 100%;
    padding: 1rem 1.25rem;
    border: 1px solid #333;
    border-radius: 12px;
    font-size: 1rem;
    background: #1a1a1a;
    color: #e0e0e0;
    transition: all 0.3s ease;
}

.token-input:focus {
    outline: none;
    border-color: #555;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.1);
}

.token-input::placeholder {
    color: #666;
}

.token-status {
    margin-top: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
}

.reset-section {
    padding-top: 1.5rem;
    border-top: 1px solid #333;
}

.reset-section h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
    color: #e0e0e0;
}

.reset-section p {
    font-size: 0.875rem;
    color: #b0b0b0;
    margin-bottom: 1rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1.5rem;
    border-top: 1px solid #333;
    flex-shrink: 0;
}

/* ===== BUTTONS ===== */
.btn {
    padding: 0.875rem 1.5rem;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.3s ease;
    border: none;
}

.btn-primary {
    background: #555;
    color: #e0e0e0;
}

.btn-primary:hover {
    background: #666;
}

.btn-secondary {
    background: #333;
    color: #e0e0e0;
}

.btn-secondary:hover {
    background: #444;
}

.reset-btn {
    background: #666;
    color: #e0e0e0;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-size: 0.875rem;
    cursor: pointer;
}

.reset-btn:hover {
    background: #777;
}

/* ===== ANIMATIONS ===== */

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    #chat-container {
        height: 100vh;
        max-width: 100%;
    }
    
    .chat-header {
        padding: 1rem;
    }
    
    .messages-container {
        padding: 0.75rem;
    }
    
    .message {
        max-width: 95%;
    }
    
    .chat-input {
        padding: 1rem;
    }
    
    .modal {
        padding: 0.5rem;
    }
    
    .modal-content {
        max-height: calc(100vh - 1rem);
    }
    
    .header-controls {
        gap: 0.5rem;
    }
    
    .status {
        font-size: 0.75rem;
        padding: 0.25rem 0.5rem;
    }
}

/* ===== UTILITY ===== */
.modal-open {
    overflow: hidden;
}

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: #1a1a1a;
}

::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #444;
}

/* ===== DEBUG MESSAGES ===== */
.message.system.debug {
    background: #2a2a2a;
    border: 1px solid #333;
    border-radius: 6px;
    margin: 0.5rem 0;
    max-width: 100%;
    font-size: 0.8rem;
    opacity: 0.8;
    display: block !important;
}

.debug-summary {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    cursor: pointer;
    user-select: none;
    border-radius: 6px 6px 0 0;
}

.debug-summary:hover {
    background: #333;
}

.debug-icon {
    font-size: 0.75rem;
    color: #b0b0b0;
}

.debug-title {
    font-weight: 500;
    color: #e0e0e0;
    flex: 1;
    font-size: 0.8rem;
}

.debug-toggle {
    color: #b0b0b0;
    font-size: 0.6rem;
    transition: transform 0.2s;
}

.debug-toggle.expanded {
    transform: rotate(180deg);
}

.debug-details {
    padding: 0.75rem;
    background: #2a2a2a;
    border-top: 1px solid #333;
    border-radius: 0 0 6px 6px;
}

.debug-details.collapsed {
    display: none;
}

.debug-item {
    margin-bottom: 0.75rem;
}

.debug-item:last-child {
    margin-bottom: 0;
}

.debug-label {
    color: #b0b0b0;
    font-size: 0.75rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.debug-value {
    font-size: 0.75rem;
    background: #1a1a1a;
    padding: 0.5rem;
    border-radius: 4px;
    border: 1px solid #333;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 120px;
    overflow-y: auto;
    color: #e0e0e0;
}

.debug-value.inline {
    display: inline;
    padding: 0.125rem 0.25rem;
    background: #333;
    white-space: normal;
    word-break: normal;
}

/* Status indicators */
.status-pending { color: #ccc; }
.status-complete { color: #aaa; }
.status-error { color: #999; }

/* ===== CLIP PLAYBACK STATES ===== */

/* Playing state - highlight the clip with a subtle animation */
.embedded-clip.clip-playing {
    border-color: #666;
    background: #333;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1);
    animation: pulse-playing 2s ease-in-out infinite;
}

.embedded-clip.clip-playing .clip-header {
    color: #e0e0e0;
    border-bottom-color: #666;
}

.embedded-clip.clip-playing .clip-status {
    color: #b0b0b0;
    font-weight: 600;
}

/* Stopped state - subtle indication */
.embedded-clip.clip-stopped {
    border-color: #333;
    background: #2a2a2a;
}

.embedded-clip.clip-stopped .clip-status {
    color: #b0b0b0;
}

/* Error state - red indication */
.embedded-clip.clip-error {
    border-color: #555;
    background: #3a2a2a;
}

.embedded-clip.clip-error .clip-status {
    color: #cc9999;
    font-weight: 600;
}

/* Pulse animation for playing clips */
@keyframes pulse-playing {
    0% {
        box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1);
    }
    50% {
        box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.15);
    }
    100% {
        box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1);
    }
}

/* Original status preservation */
.clip-status .original-status {
    font-weight: normal;
    color: #b0b0b0;
}

/* Playing indicator in status */
.embedded-clip.clip-playing .clip-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.embedded-clip.clip-playing .clip-status::before {
    content: "🎵";
    font-size: 0.875rem;
    animation: bounce 1s ease-in-out infinite;
}

@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-2px);
    }
}

@keyframes typing-pulse {
    0%, 100% {
        border-left-color: #666;
        opacity: 1;
    }
    50% {
        border-left-color: #777;
        opacity: 0.7;
    }
}

/* Spinner animation for loading states */
.spinner_V8m1{transform-origin:center;animation:spinner_zKoa 2s linear infinite}.spinner_V8m1 circle{stroke-linecap:round;animation:spinner_YpOn 1.5s ease-in-out infinite}@keyframes spinner_zKoa{100%{transform:rotate(360deg)}}@keyframes spinner_YpOn{0%{stroke-dasharray:0 150;stroke-dashoffset:0}47.5%{stroke-dasharray:42 150;stroke-dashoffset:-16}95%,100%{stroke-dasharray:42 150;stroke-dashoffset:-59}}

#global-audio-player {
    width: 100%;
    background: #1a1a1a;
    border-radius: 4px;
}

#player-track-title {
    color: #b0b0b0;
    font-size: 0.8rem;
    margin-bottom: 0.5rem;
}

#global-audio-player audio {
    width: 100%;
    height: 32px;
    opacity: 0.8;
}

#debug-panel {
    grid-area: debug;
}

/* ===== AUDIO INTERFACE LAYOUT ===== */
/* Two-column layout for audio interface */
body.audio-interface {
    margin: 0;
    height: 100vh;
    display: grid;
    grid-template-columns: 1fr 1fr;
    overflow: hidden;
}

#main-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* Override external CSS for two-column layout */
body.audio-interface #chat-container {
    max-width: none !important;
    margin: 0 !important;
    height: 100vh !important;
}

#right-panel {
    background: #202020;
    border-left: 1px solid #333;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

#music-panel {
    background: #1a1a1a;
    display: flex;
    flex-direction: column;
    height: 50vh;
    border-bottom: 1px solid #333;
}

#debug-panel {
    background: #1a1a1a;
    display: flex;
    flex-direction: column;
    height: 50vh;
}

.music-header, .debug-header {
    padding: 0.5rem 1rem;
    background: #202020;
    border-bottom: 1px solid #333;
    font-weight: 600;
    font-size: 1rem;
    flex-shrink: 0;
    color: #e0e0e0;
}

#track-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    height: 0;
}

#global-player-container {
    padding: 0.75rem 1rem;
    border-top: 1px solid #333;
    background: #202020;
    flex-shrink: 0;
}

.player-info {
    margin-bottom: 0.5rem;
    font-size: 0.8rem;
    color: #b0b0b0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#debug-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem;
    font-size: 0.75rem;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-word;
    height: 0;
    background: #1a1a1a;
    color: #b0b0b0;
}

/* ===== TRACK ITEMS ===== */
.track-item {
    background: #2a2a2a;
    border: 1px solid #333;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
    transition: all 0.2s ease;
    cursor: pointer;
}

.track-item:hover {
    background: #333;
}

.track-item.playing {
    border-color: #555;
    background: #333;
}

.track-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.5rem;
}

.track-title {
    font-weight: bold;
    font-size: 0.9rem;
    color: #e0e0e0;
}

.track-status {
    font-size: 0.8rem;
    color: #b0b0b0;
    text-transform: uppercase;
}

.track-content {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.track-thumbnail {
    width: 60px;
    height: 60px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
}

.track-thumbnail-placeholder {
    width: 60px;
    height: 60px;
    border-radius: 6px;
    background: #333;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.track-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
    flex-grow: 1;
    min-width: 0;
}

.track-status-container {
    display: flex;
}

.track-controls {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    justify-content: center;
    align-items: center;
}

.play-track-btn {
    width: 40px;
    height: 40px;
    font-size: 1.5rem;
    cursor: pointer;
    border: none;
    background: none;
    color: #b0b0b0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.play-track-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.track-item.playing .play-track-btn {
    color: #e0e0e0;
}

.track-audio {
    width: 100%;
    height: 32px;
}

.track-loading {
    color: #b0b0b0;
    font-style: italic;
    font-size: 0.9rem;
}

.no-tracks {
    text-align: center;
    color: #b0b0b0;
    font-style: italic;
    margin-top: 2rem;
}

/* ===== AUDIO INTERFACE CONTROLS ===== */
#transcript-container {
    padding: 1rem 2rem;
    min-height: 3em;
    color: #b0b0b0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    font-size: 1rem;
    background: #1a1a1a;
    border-top: 1px solid #333;
}

#transcript.interim {
    color: #666;
    font-style: italic;
}

#controls {
    display: flex;
    flex-direction: column;
    padding: 0.5rem 1rem;
    gap: 0.4rem;
    border-top: 1px solid #333;
    background: #202020;
}

.control-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    height: 32px;
}

.button-row {
    display: flex;
    justify-content: center;
}

.audio-input-dropdown {
    padding: 0.2rem 0.4rem;
    border: 1px solid #333;
    border-radius: 2px;
    background: #1a1a1a;
    color: #e0e0e0;
    font-size: 0.8rem;
    min-width: 180px;
    height: 24px;
}

.audio-input-dropdown:focus {
    outline: none;
    border-color: #555;
}

.session-controls {
    display: flex;
    gap: 1rem;
    align-items: center;
    justify-content: center;
    flex: 1;
}

.record-btn {
    padding: 0.3rem 0.8rem;
    font-size: 0.8rem;
    background: #333;
    color: #e0e0e0;
    cursor: pointer;
    min-width: 120px;
    border: none;
    border-radius: 4px;
}

.record-btn:hover {
    background: #444;
}

.record-btn.recording {
    background: #555;
    color: #e0e0e0;
}

.record-btn.listening {
    background: #555;
    color: #e0e0e0;
}

.record-btn:disabled {
    background: #222;
    color: #666;
    cursor: not-allowed;
}

.audio-visualizer {
    display: flex;
    align-items: center;
}

.audio-level-bar {
    width: 6px;
    height: 28px;
    background: #333;
    position: relative;
    overflow: hidden;
}

.audio-level-fill {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    background: #666;
    height: 0%;
    transition: height 0.1s ease;
}

.status-display {
    font-size: 0.75rem;
    color: #b0b0b0;
}

#record-button {
    flex-grow: 1;
    padding: 1rem;
    font-size: 1rem;
    border-radius: 5px;
    border: 1px solid #333;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s, color 0.2s;
    background: #333;
    color: #e0e0e0;
}

#record-button.recording {
    background-color: #555;
    color: #e0e0e0;
    border-color: #666;
    animation: pulse-recording 1.5s infinite;
}

#record-button.listening {
    background-color: #444;
    color: #e0e0e0;
    border-color: #555;
    animation: pulse-listening 2s infinite;
}

#record-button:disabled {
    cursor: not-allowed;
    background-color: #222;
    color: #666;
}

#status {
    flex-shrink: 0;
    min-width: 120px;
    text-align: right;
}

/* ===== AUDIO ANIMATIONS ===== */
@keyframes pulse-recording {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.2);
    }
    50% {
        box-shadow: 0 0 0 10px rgba(255, 255, 255, 0);
    }
}

@keyframes pulse-listening {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.2);
    }
    50% {
        box-shadow: 0 0 0 10px rgba(255, 255, 255, 0);
    }
}