/* Reset box-sizing for everything */
*, *::before, *::after {
    box-sizing: border-box;
}

/* Base styles */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
    min-height: 95vh;
    margin: 0;
    padding: 0;
    background-color: #f5f7fa;
    color: #333;
    box-sizing: border-box;
    overflow-x: hidden;
}

/* Container: centered app look */
.container {
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    max-width: 800px;
    margin: 10px auto;
    height: 95vh; /*calc(100vh - 80px);   Subtract top + bottom margin */
    display: flex;
    flex-direction: column;
}

/* When running inside Tableau (iframe), use all available space */
body.in-extension .container {
    max-width: 100vw !important;
    width: 100vw !important;
    margin: 0 !important;
    border-radius: 0;
    height: 100vh;
    min-height: 0;
}

/* Chat box should flex and scroll as needed */
.chat-box {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    background: #fafbfc;
    min-height: 0;
}

/* Header styles */
header {
    background: #2c3e50;
    color: white;
    padding: 20px 24px;
    text-align: left;
}

.header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

header h1 {
    margin: 0;
    font-size: 1.6em;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.connect-btn,
.disconnect-btn {
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
}

.connect-btn {
    background: #27ae60;
    color: white;
}

.connect-btn:hover:not(:disabled) {
    background: #1e8449;
}

.connect-btn:disabled {
    background: #6c757d;
    cursor: wait;
    opacity: 0.9;
}

.connect-btn-large {
    font-size: 16px;
    padding: 14px 24px;
}

.connect-btn.is-loading {
    position: relative;
    padding-left: 36px;
}

.connect-btn.is-loading::before {
    content: "";
    position: absolute;
    left: 14px;
    top: 50%;
    width: 14px;
    height: 14px;
    margin-top: -7px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: connect-spin 0.7s linear infinite;
}

.connect-status {
    margin: 0;
    color: #475569;
    font-size: 14px;
    font-weight: 600;
}

.connect-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.45);
}

.connect-overlay[hidden] {
    display: none !important;
}

.connect-overlay-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 28px 36px;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
    text-align: center;
    color: #1e293b;
}

.connect-overlay-card p {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.connect-overlay-hint {
    font-size: 13px !important;
    font-weight: 400 !important;
    color: #64748b;
}

.connect-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid #dbeafe;
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: connect-spin 0.7s linear infinite;
}

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

.disconnect-btn {
    background: #ffffff;
    color: #2c3e50;
}

.pre-auth {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 40px 24px;
    text-align: center;
}

.pre-auth[hidden],
#chatPanel[hidden] {
    display: none !important;
}

#chatPanel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.context-panel {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    border-bottom: 1px solid #dee2e6;
    background: #f1f5f9;
    color: #334155;
    font-size: 14px;
}

.context-panel[hidden] {
    display: none !important;
}

#contextLabel {
    font-weight: 600;
}

#datasourceSelect {
    flex: 1;
    min-width: 0;
    padding: 8px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: white;
    color: #1e293b;
}

.context-retry-btn {
    padding: 8px 12px;
    border: 1px solid #94a3b8;
    border-radius: 6px;
    background: #fff;
    color: #1e293b;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.context-retry-btn:hover:not(:disabled) {
    background: #f8fafc;
}

.context-retry-btn:disabled {
    cursor: wait;
    opacity: 0.7;
}

.context-retry-btn[hidden] {
    display: none !important;
}

header p {
    margin: 0;
    opacity: 0.9;
}

/* Chat message styles */
.message {
    margin: 15px 0;
    padding: 12px 16px;
    border-radius: 8px;
    max-width: 80%;
    line-height: 1.4;
}

.message.user {
    background: #007bff;
    color: white;
    margin-left: auto;
    text-align: right;
}

.message.bot {
    background: #e9ecef;
    color: #495057;
}

.message.bot.welcome-message {
    max-width: 100%;
}

.message.bot p {
    margin: 0 0 0.6em;
}

.message.bot p:last-child {
    margin-bottom: 0;
}

.welcome-disclaimer {
    font-size: 0.95em;
    line-height: 1.45;
    padding: 8px 10px;
    border-left: 3px solid #6c757d;
    background: rgba(255, 255, 255, 0.55);
}

.welcome-note {
    font-size: 0.9em;
    opacity: 0.9;
}

.welcome-examples-label {
    margin-top: 0.75em !important;
    margin-bottom: 0.35em !important;
    font-weight: 600;
}

.welcome-examples {
    margin: 0;
    padding-left: 1.25em;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.welcome-examples li {
    font-size: 0.95em;
    line-height: 1.35;
    color: #343a40;
}

/* Input area at the bottom */
.input-area {
    display: flex;
    gap: 10px;
    padding: 20px;
    background: white;
    border-top: 1px solid #dee2e6;
}

#messageInput {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #dee2e6;
    border-radius: 6px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s;
}

#messageInput:focus {
    border-color: #007bff;
}

#sendBtn {
    padding: 12px 24px;
    background: #007bff;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
    transition: background-color 0.2s;
}

#sendBtn:hover {
    background: #0056b3;
}

#sendBtn:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

/* Responsive for smaller screens */
@media (max-width: 600px) {
    .container {
        max-width: 100vw;
        width: 100vw;
        margin: 0;
        border-radius: 0;
        height: 100vh;
    }
    body {
        padding: 0;
    }
    header {
        padding: 20px;
    }
    header h1 {
        font-size: 1.5em;
    }
    .chat-box {
        padding: 15px;
    }
    .input-area {
        padding: 15px;
        flex-direction: column;
    }
    .context-panel {
        align-items: stretch;
        flex-direction: column;
        gap: 6px;
        padding: 10px 15px;
    }
    #sendBtn {
        padding: 12px;
    }
}
