/* =========================================================
   Auth/Login visibility fixes
   ========================================================= */

.hidden {
    display: none !important;
}

body.auth-locked .sidebar,
body.auth-locked .topbar,
body.auth-locked #chatContainer {
    display: none !important;
}

body.auth-locked {
    padding: 0;
}

body.auth-locked .app-shell {
    display: block;
    max-width: none;
    width: 100%;
    height: 100vh;
    margin: 0;
    border-radius: 0;
    box-shadow: none;
    background: #f5f7fb;
}

body.auth-locked .main-area {
    width: 100%;
    height: 100vh;
}

body.auth-locked #loginCard {
    display: flex !important;
    min-height: 100vh;
    height: 100vh;
    align-items: center;
    justify-content: center;
}

body.auth-locked #loginCard .card {
    width: 420px;
    max-width: 92%;
}

.btn-google {
    cursor: pointer;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
html, body {
    width: 100%;
    height: 100%;
    min-height: 100%;
    margin: 0;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: #f5f7fb;
    color: #222;
}

.app-shell {
    width: 100%;
    height: 100dvh;
    min-height: 100dvh;
    margin: 0 auto;
    background: white;
    border-radius: 0;
    box-shadow: none;
    display: flex;
    gap: 0;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    padding: 20px;
    border-right: 1px solid #eef2f7;
    display: flex;
    flex-direction: column;
    gap: 18px;
    background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
}
/* fix sidebar width when using flex layout */
.sidebar {
    width: 260px;
    min-width: 220px;
    max-width: 320px;
    overflow-y: auto;
}

.sidebar-top {
    display: flex;
    gap: 12px;
    align-items: center;
}

.logo {
    font-size: 28px;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 12px;
}

.app-title .title-line {
    font-weight: 700;
    color: #222;
}

.app-title .subtitle {
    font-size: 12px;
    color: #586074;
}

/* Session Info */
.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.session-id {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: monospace;
}

.session-id span {
    background: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-small {
    padding: 4px 8px;
    font-size: 12px;
    border: 1px solid #ddd;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-small:hover {
    background: #f0f0f0;
    border-color: #667eea;
}

.btn-primary, .btn-secondary {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.2s;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5568d3;
    transform: translateY(-2px);
}

.btn-secondary {
    background: #fff;
    color: #667eea;
    border: 2px solid #667eea;
}

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

/* Health Status */
.sidebar-status {
    padding: 8px 0;
}

.status-item {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    background: #f0f0f0;
}

.status-item.ok {
    background: #d4edda;
    color: #155724;
}

.status-item.error {
    background: #f8d7da;
    color: #721c24;
}

/* Chat Area */
.main-area {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.topbar {
    flex: 0 0 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    border-bottom: 1px solid #eef2f7;
}

.session-title {
    font-weight: 700;
    color: #222;
}

.user-area {
    display: flex;
    gap: 12px;
    align-items: center;
}

.chat-container, #chatContainer {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    height: auto;
    overflow: hidden;
    padding: 0;
    margin: 0;
}

/* Ensure the chat container fills the viewport space under the topbar */
.chat-container {
    height: calc(100vh - 64px);
}

/* remove extra inner paddings that shrink frame area */
#chatContainer {
    padding: 0;
    margin: 0;
    display: flex;
}

.main-area {
    padding: 0;
}

.chat-area {
    flex: 1 1 auto;
    min-height: 0; /* allow proper flex overflow */
    overflow-y: auto;
    padding: 18px 20px 120px 20px; /* bottom padding to avoid input overlay */
    background: #f7f9fb;
}

/* iframe chat frame styling */
.chat-frame, #chatFrame {
    display: block;
    width: 100%;
    height: 100%;
    min-height: 0;
    flex: 1 1 auto;
    border: 0;
}

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 14px;
    align-items: stretch;
}

.welcome-message {
    text-align: center;
    padding: 40px 20px;
    color: #999;
}

.welcome-message h2 {
    font-size: 20px;
    margin-bottom: 10px;
    color: #667eea;
}

.message {
    display: flex;
    gap: 10px;
    animation: slideIn 0.18s ease-out;
    width: 100%;
    max-width: 820px;
    align-items: flex-end;
    position: relative; /* anchor for absolute feedback panel */
}

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

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

.message-bubble {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 12px;
    word-wrap: break-word;
    line-height: 1.45;
    box-shadow: 0 6px 18px rgba(20, 20, 40, 0.04);
}

.message.user .message-bubble {
    background: linear-gradient(90deg, #6b7bf3 0%, #5b5fe6 100%);
    color: white;
    border-radius: 12px 6px 12px 12px;
}

.message.assistant .message-bubble {
    background: white;
    color: #222;
    border-radius: 6px 12px 12px 12px;
}

.message-id {
    font-size: 11px;
    color: #999;
    margin-top: 4px;
}

/* Feedback Section */
.feedback-panel {
    position: absolute;
    right: -240px; /* sit to the right of message */
    top: 0;
    width: 220px;
    max-width: 60vw;
    background: #ffffff;
    border-radius: 8px;
    border: 1px solid #e6e9f2;
    padding: 8px;
    box-shadow: 0 8px 24px rgba(20, 20, 40, 0.06);
    font-size: 13px;
    transition: transform 0.15s ease, opacity 0.15s ease;
    z-index: 5;
}

.feedback-panel .feedback-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    background: #f5f7ff;
    border: 1px solid #e6e9f2;
}

.feedback-panel.collapsed {
    width: auto;
    right: 8px;
    top: 8px;
    padding: 0;
    background: transparent;
    border: none;
    box-shadow: none;
}

.feedback-panel.collapsed .feedback-content {
    display: none;
}

.feedback-panel .feedback-content {
    margin-top: 8px;
}

.feedback-section.submitted {
    background: #d4edda;
    border-left-color: #28a745;
}

.feedback-form {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
    margin-bottom: 6px;
}

.feedback-form select {
    padding: 6px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 13px;
    background: white;
    cursor: pointer;
}

.feedback-comment {
    width: 100%;
    padding: 6px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 13px;
    resize: vertical;
    min-height: 40px;
}

.feedback-buttons {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.btn-feedback, .btn-cancel {
    flex: 1;
    padding: 8px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-feedback {
    background: #667eea;
    color: white;
}

.btn-feedback:hover:not(:disabled) {
    background: #5568d3;
}

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

.btn-cancel:hover {
    background: #d0d0d0;
}

.btn-feedback:disabled, .btn-cancel:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.feedback-status {
    font-size: 12px;
    color: #28a745;
    margin-top: 5px;
    font-weight: 600;
}

/* Loading Indicator */
.loading-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 15px;
    background: #f0f4ff;
    border-radius: 8px;
    color: #667eea;
    margin: 10px 0;
}

.loading-indicator.hidden {
    display: none;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid #e0e0e0;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Error Display */
.error-display {
    padding: 12px;
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
    border-radius: 8px;
    margin: 10px 0;
    font-size: 13px;
}

.error-display.hidden {
    display: none;
}

/* Input Area */
.input-area {
    display: flex;
    gap: 10px;
    padding: 14px 20px;
    background: white;
    border-top: 1px solid #eef2f7;
}

/* Keep input area fixed/sticky at bottom of chat container */
.chat-container .input-area {
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    z-index: 3;
}

#messageInput {
    flex: 1;
    padding: 12px 14px;
    border: 1px solid #e9eef6;
    border-radius: 14px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    transition: box-shadow 0.15s, border-color 0.15s;
}

#messageInput:focus {
    box-shadow: 0 6px 18px rgba(20, 20, 40, 0.04);
    border-color: #6b7bf3;
}

.btn-send {
    padding: 12px 24px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-send:hover {
    background: #5568d3;
    transform: translateY(-2px);
}

.btn-send:active {
    transform: translateY(0);
}

.btn-send:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Login Card & Center */
.center-card {
    display: flex;
    align-items: center;
    justify-content: center;
    height: calc(100% - 64px);
}

.card {
    width: 420px;
    padding: 28px;
    border-radius: 12px;
    background: white;
    box-shadow: 0 10px 30px rgba(20, 30, 60, 0.06);
    text-align: center;
}

.btn-google {
    margin-top: 14px;
    padding: 10px 16px;
    background: linear-gradient(90deg,#4285f4 0%, #2a6ae0 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
}

/* Modal */
.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    z-index: 1001;
    max-width: 700px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal.hidden {
    display: none;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
}

.modal-overlay.hidden {
    display: none;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 12px 12px 0 0;
}

.modal-header h2 {
    font-size: 20px;
}

.btn-close {
    background: white;
    border: none;
    font-size: 24px;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}

.btn-close:hover {
    transform: scale(1.1);
}

.modal-body {
    padding: 20px;
}

/* Analytics Content */
.analytics-stat {
    background: #f7f9fc;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 12px;
}

.analytics-stat-label {
    font-size: 12px;
    color: #999;
    margin-bottom: 5px;
}

.analytics-stat-value {
    font-size: 24px;
    font-weight: bold;
    color: #667eea;
}

.analytics-section {
    margin-bottom: 20px;
}

.analytics-section h3 {
    font-size: 14px;
    margin-bottom: 10px;
    color: #333;
    border-bottom: 2px solid #667eea;
    padding-bottom: 8px;
}

.distribution-item {
    display: flex;
    justify-content: space-between;
    padding: 8px;
    background: white;
    border-radius: 4px;
    margin-bottom: 6px;
    font-size: 13px;
}

.feedback-item {
    background: white;
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 8px;
    border-left: 3px solid #667eea;
    font-size: 12px;
}

.feedback-item-meta {
    color: #999;
    margin-top: 4px;
}

/* Scrollbar */
.chat-area::-webkit-scrollbar {
    width: 8px;
}

.chat-area::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.chat-area::-webkit-scrollbar-thumb {
    background: #667eea;
    border-radius: 4px;
}

.chat-area::-webkit-scrollbar-thumb:hover {
    background: #5568d3;
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        height: 100vh;
        border-radius: 0;
    }

    .header h1 {
        font-size: 20px;
    }

    .message-bubble {
        max-width: 85%;
    }

    .session-info {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .modal {
        width: 95%;
        max-height: 90vh;
    }

    .feedback-form {
        grid-template-columns: 1fr;
    }

    /* On small screens position feedback below message */
    .feedback-panel {
        position: static;
        right: auto;
        top: auto;
        width: 100%;
        box-shadow: none;
        border: 1px solid #e6e9f2;
        margin-top: 8px;
    }
    .feedback-panel.collapsed {
        right: auto;
        top: auto;
    }
}

/* =========================================================
   Auth/Login visibility fixes - keep this at VERY BOTTOM
   ========================================================= */

.hidden {
    display: none !important;
}

body.auth-locked {
    padding: 0 !important;
    background: #f5f7fb;
}

body.auth-locked .sidebar,
body.auth-locked .topbar,
body.auth-locked #chatContainer {
    display: none !important;
}

body.auth-locked .app-shell {
    display: block !important;
    max-width: none !important;
    width: 100% !important;
    height: 100vh !important;
    margin: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: #f5f7fb !important;
}

body.auth-locked .main-area {
    display: flex !important;
    width: 100% !important;
    height: 100vh !important;
}

body.auth-locked #loginCard {
    display: flex !important;
    width: 100% !important;
    min-height: 100vh !important;
    height: 100vh !important;
    align-items: center !important;
    justify-content: center !important;
}

body.auth-locked #loginCard .card {
    width: 420px;
    max-width: 92%;
}

.btn-google {
    cursor: pointer;
}