/**
 * Modern Chat UI Styles for ADK Streaming Demo
 */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-color);
    color: #202124;
    line-height: 1.6;
    /* height: 100vh; */
    display: flex;
    flex-direction: column;
}

/* Header */
/* header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 1.5rem 2rem;
  box-shadow: var(--shadow-lg);
  position: relative;
} */

/* h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0;
} */

.subtitle {
    font-size: 0.875rem;
    opacity: 0.9;
    margin-top: 0.25rem;
}

.connection-status {
    position: absolute;
    top: 1.5rem;
    right: 2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #0066cc;
}

.status-indicator.disconnected {
    background-color: #ea4335;
}

@keyframes pulse {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

/* Main Layout: Split view for chat and console */
.main-layout {
    flex: 1;
    display: flex;
    max-width: 1800px;
    width: 100%;
    margin: 0 auto;
    overflow: hidden;
    gap: 0;
}

/* Main Container: Chat area (2/3 of the layout) */
.container-agent {
    height: 450px;
    max-width: 400px;
    flex: 2;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-right: 1px solid var(--border-color);
}

/* Messages Area */
#messages {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    /* background: linear-gradient(to bottom, #f8f9fa 0%, #ffffff 100%); */
}

/* Scroll styling */
#messages::-webkit-scrollbar {
    width: 8px;
}

#messages::-webkit-scrollbar-track {
    background: transparent;
}

#messages::-webkit-scrollbar-thumb {
    background: #dadce0;
    border-radius: 4px;
}

#messages::-webkit-scrollbar-thumb:hover {
    background: #bdc1c6;
}

/* Message Bubbles */
.message {
    display: flex;
    margin-bottom: 0.5rem;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

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

.bubble {
    max-width: 70%;
    padding: 0.75rem 1rem;
    border-radius: 1.25rem;
    word-wrap: break-word;
    box-shadow: var(--shadow);
    position: relative;
    background: #0066cc;
    color: white;
}

.message.user .bubble {
    background-color: var(--user-bubble-bg);
    color: var(--user-text-color);
    border-bottom-right-radius: 0.25rem;
    background: #0066cc;
    color: white;
}

.message.agent .bubble {
    background: #0066cc;
    color: white;
    border-bottom-left-radius: 0.25rem;
}

.bubble-text {
    margin: 0;
    line-height: 1.5;
    color: white;
    font-size: 1.5rem;
}

/* Product card styling */
.bubble-text img.product-image {
    max-width: 200px;
    height: auto;
    border-radius: 8px;
    margin: 10px 0;
    display: block;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.bubble-text a {
    color: #4a9eff;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

.bubble-text a:hover {
    color: #2d7dd2;
    text-decoration: underline;
}

.bubble-text strong {
    font-weight: 600;
}

/* Interrupted message styling */
.message.interrupted .bubble {
    opacity: 0.6;
    background-color: #e8eaed;
    border-left: 3px solid #f4b400;
}

.message.interrupted .bubble::after {
    content: "interrupted";
    display: block;
    font-size: 0.75rem;
    color: #5f6368;
    font-style: italic;
    margin-top: 0.25rem;
}

/* Transcription message styling */
.message.transcription.user .bubble {
    opacity: 0.9;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.message.transcription.user .bubble::before {
    content: "🎤";
    opacity: 0.8;
    margin-right: 0.25rem;
}

/* Typing indicator */
.typing-indicator {
    display: inline-block;
    margin-left: 0.25rem;
    color: #5f6368;
}

.typing-indicator::after {
    content: "...";
    animation: ellipsis 1.5s infinite;
}

@keyframes ellipsis {
    0%,
    20% {
        content: ".";
    }
    40% {
        content: "..";
    }
    60%,
    100% {
        content: "...";
    }
}

/* Image bubble styling */
.bubble.image-bubble {
    padding: 0.25rem;
    max-width: 80%;
}

.bubble-image {
    max-width: 100%;
    max-height: 300px;
    width: auto;
    height: auto;
    border-radius: 0.75rem;
    display: block;
    object-fit: contain;
}

/* Input Form */
.input-container {
    border-top: 1px solid var(--border-color);
    /* background-color: white; */
    padding: 1.5rem 2rem;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
}

#messageForm {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.input-wrapper {
    flex: 1;
    display: flex;
    gap: 0.75rem;
}

#message {
    flex: 1;
    padding: 0.875rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 1.5rem;
    font-size: 1rem;
    font-family: inherit;
    background-color: var(--input-bg);
    transition: all 0.2s ease;
    outline: none;
    box-shadow: 0 0 0 3px rgba(66, 133, 244, 0.1);
}

#message:focus {
    border-color: var(--primary-color);
    background-color: white;
    box-shadow: 0 0 0 3px rgba(66, 133, 244, 0.1);
}

/* Buttons */
button {
    padding: 0.875rem 1.5rem;
    border: none;
    border-radius: 1.5rem;
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    white-space: nowrap;
}

#sendButton {
    background-color: #3367d6;
    color: white;
}

#sendButton:hover:not(:disabled) {
    background-color: #3367d6;
    box-shadow: var(--shadow);
    transform: translateY(-1px);
}

#sendButton:disabled {
    background-color: #dadce0;
    color: #80868b;
    cursor: not-allowed;
    opacity: 0.6;
}

#startAudioButton {
    background-color: #0066cc;
    color: white;
}

#startAudioButton:hover:not(:disabled) {
    background-color: #2d8e47;
    box-shadow: var(--shadow);
    transform: translateY(-1px);
}

#startAudioButton:disabled {
    background-color: #dadce0;
    color: #80868b;
    cursor: not-allowed;
    opacity: 0.6;
}

#cameraButton {
    background-color: #ea4335;
    color: white;
}

#cameraButton:hover:not(:disabled) {
    background-color: #d33426;
    box-shadow: var(--shadow);
    transform: translateY(-1px);
}

#cameraButton:disabled {
    background-color: #dadce0;
    color: #80868b;
    cursor: not-allowed;
    opacity: 0.6;
}

/* System Messages */
.system-message {
    text-align: center;
    color: #5f6368;
    font-size: 0.875rem;
    padding: 0.5rem;
    margin: 1rem 0;
    font-style: italic;
}

/* Console Panel (1/3 of the layout) */
.console-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: #1e1e1e;
    color: #d4d4d4;
    font-family: "Monaco", "Menlo", "Ubuntu Mono", "Consolas", "source-code-pro",
        monospace;
    overflow: hidden;
}

.console-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background-color: #2d2d2d;
    border-bottom: 1px solid #3e3e3e;
}

.console-header h2 {
    font-size: 0.875rem;
    font-weight: 600;
    margin: 0;
    color: #cccccc;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.console-clear-btn {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
    background-color: #3e3e3e;
    color: #cccccc;
    border: 1px solid #4e4e4e;
    border-radius: 0.25rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.console-clear-btn:hover {
    background-color: #4e4e4e;
    border-color: #5e5e5e;
}

.console-content {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
    font-size: 0.75rem;
    line-height: 1.5;
}

/* Console entry */
.console-entry {
    margin-bottom: 0.75rem;
    padding: 0.5rem;
    border-left: 3px solid transparent;
    background-color: rgba(255, 255, 255, 0.06);
    border-radius: 0.25rem;
    transition: background-color 0.2s ease;
}

.console-entry.outgoing {
    border-left-color: #4285f4;
}

.console-entry.incoming {
    border-left-color: #0066cc;
}

.console-entry.error {
    border-left-color: #ea4335;
    background-color: rgba(234, 67, 53, 0.15);
}

/* Expandable console entries */
.console-entry.expandable {
    cursor: pointer;
}

.console-entry.expandable:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.console-entry.expanded {
    background-color: rgba(255, 255, 255, 0.08);
}

.console-entry-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.375rem;
}

.console-entry-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.console-entry-emoji {
    font-size: 0.9rem;
    line-height: 1;
    display: inline-block;
    user-select: none;
    min-width: 16px;
    text-align: center;
}

.console-expand-icon {
    font-size: 0.6rem;
    color: #858585;
    width: 12px;
    display: inline-block;
    transition: transform 0.2s ease;
    user-select: none;
}

.console-entry-type {
    font-weight: 600;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.console-entry.outgoing .console-entry-type {
    color: #4285f4;
}

.console-entry.incoming .console-entry-type {
    color: #0066cc;
}

.console-entry.error .console-entry-type {
    color: #ea4335;
}

.console-entry-author {
    font-size: 0.65rem;
    font-weight: 500;
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    text-transform: lowercase;
    letter-spacing: 0.3px;
    border: 1px solid;
}

/* Default style (for agents) */
.console-entry-author {
    background-color: rgba(156, 220, 254, 0.15);
    color: #9cdcfe;
    border-color: rgba(156, 220, 254, 0.3);
}

/* User author badge */
.console-entry-author[data-author="user"] {
    background-color: rgba(66, 133, 244, 0.2);
    color: #80b3ff;
    border-color: rgba(66, 133, 244, 0.4);
}

/* System author badge */
.console-entry-author[data-author="system"] {
    background-color: rgba(133, 133, 133, 0.2);
    color: #b0b0b0;
    border-color: rgba(133, 133, 133, 0.3);
}

.console-entry-timestamp {
    color: #858585;
    font-size: 0.65rem;
}

.console-entry-content {
    color: #d4d4d4;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.7rem;
    line-height: 1.4;
    padding-left: 2.5rem; /* Indent to align with header after emoji and icon */
}

.console-entry-content:empty {
    display: none;
}

/* Style for quoted text in summaries (transcriptions, text responses) */
.console-entry-content::first-line {
    color: #e0e0e0;
}

.console-entry-json {
    background-color: #252526;
    padding: 0.5rem;
    border-radius: 0.25rem;
    margin-top: 0.5rem;
    overflow-x: auto;
    max-height: 400px;
    overflow-y: auto;
    transition: all 0.3s ease;
}

.console-entry-json.collapsed {
    display: none;
}

.console-entry-json pre {
    margin: 0;
    color: #9cdcfe;
}

/* Highlight key fields in JSON */
.json-key {
    color: #9cdcfe;
}

.json-string {
    color: #ce9178;
}

.json-number {
    color: #b5cea8;
}

.json-boolean {
    color: #569cd6;
}

.json-null {
    color: #569cd6;
}

/* Console scrollbar */
.console-content::-webkit-scrollbar {
    width: 8px;
}

.console-content::-webkit-scrollbar-track {
    background: #1e1e1e;
}

.console-content::-webkit-scrollbar-thumb {
    background: #3e3e3e;
    border-radius: 4px;
}

.console-content::-webkit-scrollbar-thumb:hover {
    background: #4e4e4e;
}

/* JSON scrollbar */
.console-entry-json::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.console-entry-json::-webkit-scrollbar-track {
    background: #1e1e1e;
}

.console-entry-json::-webkit-scrollbar-thumb {
    background: #3e3e3e;
    border-radius: 3px;
}

.console-entry-json::-webkit-scrollbar-thumb:hover {
    background: #4e4e4e;
}

/* Responsive Design */
@media (max-width: 768px) {
    header {
        padding: 1rem 1.5rem;
    }

    h1 {
        font-size: 1.25rem;
    }

    .connection-status {
        position: static;
        margin-top: 0.5rem;
    }

    /* Stack console panel below chat on mobile */
    .main-layout {
        flex-direction: column;
    }

    .console-panel {
        max-height: 300px;
        border-top: 1px solid var(--border-color);
    }

    .container-agent {
        border-right: none;
    }

    #messages {
        padding: 1rem;
    }

    .bubble {
        max-width: 85%;
    }

    .input-container {
        padding: 1rem;
    }

    #messageForm {
        flex-direction: column;
        gap: 0.75rem;
    }

    .input-wrapper {
        width: 100%;
        flex-direction: column;
    }

    button {
        width: 100%;
    }
}

/* Loading state */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Camera Preview Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: white;
    border-radius: 1rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    max-width: 90%;
    max-height: 90%;
    width: 640px;
    display: flex;
    flex-direction: column;
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: #202124;
}

.close-btn {
    background: none;
    border: none;
    font-size: 2rem;
    line-height: 1;
    color: #5f6368;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.close-btn:hover {
    background-color: #f1f3f4;
    color: #202124;
}

.modal-body {
    padding: 1.5rem;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #000;
    border-radius: 0 0 1rem 1rem;
}

#cameraPreview {
    width: 100%;
    max-height: 480px;
    border-radius: 0.5rem;
    object-fit: contain;
}

.modal-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    background-color: white;
    border-radius: 0 0 1rem 1rem;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
    padding: 0.875rem 1.5rem;
    border: none;
    border-radius: 1.5rem;
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.btn-primary:hover {
    background-color: #3367d6;
    box-shadow: var(--shadow);
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: white;
    color: #5f6368;
    padding: 0.875rem 1.5rem;
    border: 1px solid var(--border-color);
    border-radius: 1.5rem;
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.btn-secondary:hover {
    background-color: #f8f9fa;
    border-color: #bdc1c6;
}
