/* Main Container & Toggle Button */
#scp-chat-container {
    /* Themeable brand color. Per-location webchat_config can override --scp-primary at runtime
       (the widget JS sets it on this element); --scp-primary-dark is the auto-derived hover shade.
       Blank config ⇒ these defaults, i.e. the original look is unchanged. */
    --scp-primary: #0073aa;
    --scp-primary-dark: #005a87;
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
}

#scp-chat-toggle {
    background-color: var(--scp-primary);
    color: white;
    border: none;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    display: none; /* Hidden by default */
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    transition: transform 0.2s ease;
}

/* Show toggle button when it has the visible class */
#scp-chat-toggle.scp-toggle-visible {
    display: flex !important;
}

/* Fallback: Show toggle button only when chat window is hidden (for browsers that support :has) */
#scp-chat-container:has(#scp-chat-window.scp-is-hidden) #scp-chat-toggle {
    display: flex;
}

#scp-chat-toggle:hover {
    transform: scale(1.1);
}

/* Chat Window */
#scp-chat-window {
    position: relative; /* anchors the AI-notice overlay */
    width: 437.5px; /* 25% wider than 350px */
    max-width: 90vw;
    height: 625px; /* 25% taller than 500px */
    max-height: 70vh;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity 0.3s ease, transform 0.3s ease;
    transform-origin: bottom right;
}

#scp-chat-window.scp-is-hidden {
    opacity: 0;
    transform: scale(0);
    pointer-events: none;
    display: none !important; /* Completely remove from layout when hidden */
}

/* Header */
.scp-chat-header {
    background: #f1f1f1;
    padding: 15px;
    font-weight: bold;
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#scp-chat-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #888;
    line-height: 1;
}

.scp-header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

#scp-chat-restart {
    background: none;
    border: none;
    cursor: pointer;
    color: #888;
    padding: 0;
    display: flex;
    align-items: center;
    line-height: 1;
}
#scp-chat-restart:hover {
    color: var(--scp-primary);
}

/* Messages Area */
#scp-chat-messages {
    flex: 1 1 0% !important;
    min-height: 0 !important;
    padding: 15px;
    overflow-y: auto !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 12px;
    height: 0 !important;
}

.scp-message {
    padding: 10px 15px;
    border-radius: 18px;
    max-width: 80%;
    line-height: 1.4;
    word-wrap: break-word;
}

.scp-message.user {
    background-color: var(--scp-primary);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.scp-message.assistant {
    background-color: #e5e5ea;
    color: #000;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

/* Form Input Area */
#scp-chat-form {
    display: flex;
    padding: 10px;
    border-top: 1px solid #ddd;
    flex-shrink: 0 !important;
}

#scp-chat-input {
    flex-grow: 1;
    border: 1px solid #ccc;
    border-radius: 20px;
    padding: 10px 15px;
    font-size: 14px;
}

#scp-chat-input:focus {
    outline: none;
    border-color: var(--scp-primary);
}

#scp-chat-form button {
    background: var(--scp-primary) !important;
    background-color: var(--scp-primary) !important;
    color: white !important;
    border: none !important;
    border-radius: 50% !important;
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
    min-height: 40px !important;
    margin-left: 10px;
    cursor: pointer;
    font-size: 16px;
    display: flex !important;
    align-items: center;
    justify-content: center;
    padding: 0 !important;
    line-height: 1 !important;
    box-shadow: none !important;
}

/* Footer: Powered-by and AI Notice centered on one row, separator in between */
.scp-chat-footer {
    flex-shrink: 0 !important;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    padding: 6px 12px 10px;
    font-size: 13px;
    color: #888;
    background: transparent;
}

.scp-chat-footer-brand {
    font-weight: 600;
    /* Fixed MissionLens brand blue — not themed by the customer's --scp-primary. */
    color: #0073aa;
    text-decoration: none;
}

.scp-chat-footer-brand:hover {
    text-decoration: underline;
}

/* AI notice: footer trigger + in-window popup */
.scp-ai-notice-trigger {
    background: none;
    border: none;
    border-left: 1px solid #ccc; /* separator between the two footer items */
    padding: 0 0 0 10px;
    font-size: 13px;
    color: #888;
    text-decoration: underline;
    cursor: pointer;
}

.scp-ai-notice-trigger:hover {
    color: #555;
}

#scp-ai-notice-overlay {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

.scp-ai-notice-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
}

.scp-ai-notice-panel {
    position: relative;
    display: flex;
    flex-direction: column;
    width: calc(100% - 32px);
    max-height: calc(100% - 32px);
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
}

.scp-ai-notice-header {
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    border-bottom: 1px solid #ddd;
    font-weight: bold;
    font-size: 14px;
}

#scp-ai-notice-close {
    background: none;
    border: none;
    font-size: 22px;
    color: #888;
    cursor: pointer;
    line-height: 1;
    padding: 0;
}

.scp-ai-notice-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px 15px;
    font-size: 13px;
    line-height: 1.5;
    color: #333;
}

.scp-ai-notice-body p {
    margin: 0 0 10px;
}

.scp-ai-notice-body p:last-child {
    margin-bottom: 0;
}

.scp-ai-notice-privacy a {
    color: var(--scp-primary);
}

/* Typing Indicator */
#scp-typing-indicator {
    padding: 10px 15px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0 15px 5px 15px;
    flex-shrink: 0;
}
#scp-typing-indicator.scp-is-hidden {
    display: none !important;
}

.scp-thinking-label {
    color: #666;
    font-size: 14px;
    font-style: italic;
    margin-left: 8px;
    animation: none !important;
    transition: none !important;
    opacity: 1 !important;
    transform: none !important;
}

/* Loader Animation — spinning wheel (rotating label text set by JS) */
#scp-typing-indicator .scp-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(0, 115, 170, 0.25);
    border-top-color: var(--scp-primary);
    border-radius: 50%;
    animation: scp-spin 0.8s linear infinite;
    flex-shrink: 0;
}

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

/* Starter / suggested questions — full-width outlined cards, stacked */
.scp-suggestions {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 4px 15px 12px 15px;
    flex-shrink: 0 !important;
}
.scp-suggestions.scp-is-hidden {
    display: none !important;
}
.scp-suggestions-lead {
    align-self: flex-start;
    background-color: #e5e5ea;
    color: #000;
    padding: 8px 14px;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    font-size: 14px;
    line-height: 1.4;
}
.scp-suggestion-chip {
    display: block;
    width: 100%;
    text-align: left;
    background: #fff;
    border: 1px solid var(--scp-primary);
    color: var(--scp-primary);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 13.5px;
    line-height: 1.35;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}
.scp-suggestion-chip:hover {
    background: var(--scp-primary);
    color: #fff;
}

/* Welcome message — a persistent assistant-style greeting bubble at the top */
.scp-welcome-message {
    align-self: flex-start;
    background-color: #e5e5ea;
    color: #000;
    padding: 10px 15px;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    max-width: 80%;
    margin: 10px 15px 4px 15px;
    line-height: 1.4;
    font-size: 14px;
    flex-shrink: 0;
}
.scp-welcome-message.scp-is-hidden {
    display: none !important;
}

/* HTML/Markdown styling within messages */
.scp-message h1,
.scp-message h2,
.scp-message h3,
.scp-message h4,
.scp-message h5,
.scp-message h6 {
    margin: 0.5em 0;
    font-weight: bold;
    line-height: 1.2;
}

.scp-message h1 { font-size: 1.3em; }
.scp-message h2 { font-size: 1.2em; }
.scp-message h3 { font-size: 1.1em; }
.scp-message h4 { font-size: 1.05em; }
.scp-message h5 { font-size: 1em; }
.scp-message h6 { font-size: 0.95em; }

.scp-message p {
    margin: 0.5em 0;
}

.scp-message p:first-child {
    margin-top: 0;
}

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

.scp-message code {
    background-color: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.scp-message.assistant code {
    background-color: rgba(0, 0, 0, 0.15);
}

.scp-message pre {
    background-color: rgba(0, 0, 0, 0.05);
    padding: 10px;
    border-radius: 5px;
    overflow-x: auto;
    margin: 0.5em 0;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    line-height: 1.4;
}

.scp-message.assistant pre {
    background-color: rgba(0, 0, 0, 0.08);
}

.scp-message pre code {
    background-color: transparent;
    padding: 0;
    display: block;
}

.scp-message a {
    color: var(--scp-primary);
    text-decoration: underline;
}

.scp-message.assistant a {
    color: var(--scp-primary-dark);
}

.scp-message a:hover {
    opacity: 0.8;
}

.scp-message strong {
    font-weight: bold;
}

.scp-message em {
    font-style: italic;
}

.scp-message u {
    text-decoration: underline;
}

.scp-message ul,
.scp-message ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}

.scp-message li {
    margin: 0.25em 0;
    line-height: 1.4;
}

.scp-message blockquote {
    border-left: 3px solid #ccc;
    padding-left: 1em;
    margin: 0.5em 0;
    font-style: italic;
    color: #666;
}

.scp-message hr {
    border: none;
    border-top: 1px solid #ddd;
    margin: 1em 0;
}

/* ===== Auth Screen ===== */

#scp-auth-screen {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    padding: 20px;
    overflow-y: auto;
}

#scp-auth-screen.scp-is-hidden {
    display: none;
}

#scp-chat-screen {
    flex: 1 1 0% !important;
    min-height: 0 !important;
    height: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
}

#scp-chat-screen.scp-is-hidden {
    display: none;
}

.scp-auth-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 16px;
    border-bottom: 2px solid #e5e5e5;
}

.scp-auth-tab {
    flex: 1;
    background: none;
    border: none;
    padding: 10px 0;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: #888;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.2s, border-color 0.2s;
}

.scp-auth-tab:hover,
.scp-auth-tab:focus,
.scp-auth-tab:active {
    color: #555;
    background: none !important;
    outline: none !important;
    box-shadow: none !important;
}

.scp-auth-tab-active,
.scp-auth-tab-active:hover,
.scp-auth-tab-active:focus,
.scp-auth-tab-active:active {
    color: var(--scp-primary) !important;
    border-bottom-color: var(--scp-primary);
    background: none !important;
    outline: none !important;
    box-shadow: none !important;
}

.scp-auth-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.scp-auth-form.scp-is-hidden {
    display: none;
}

.scp-auth-form input {
    border: 1px solid #ccc;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.scp-auth-form input:focus {
    border-color: var(--scp-primary);
}

.scp-auth-form input:-webkit-autofill,
.scp-auth-form input:-webkit-autofill:hover,
.scp-auth-form input:-webkit-autofill:focus,
.scp-auth-form input:-webkit-autofill:active {
    -webkit-box-shadow: 0 0 0 9999px #fff inset !important;
    -webkit-text-fill-color: #333 !important;
    box-shadow: 0 0 0 9999px #fff inset !important;
    background-color: #fff !important;
    background-clip: content-box !important;
    transition: background-color 9999s ease-in-out 0s;
    caret-color: #333;
}

.scp-auth-submit {
    background: var(--scp-primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.scp-auth-submit:hover {
    background: var(--scp-primary-dark);
}

.scp-auth-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.scp-auth-error {
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 13px;
    margin-bottom: 12px;
}

.scp-auth-error.scp-is-hidden {
    display: none;
}

.scp-auth-success {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 13px;
    margin-bottom: 12px;
}

.scp-auth-success.scp-is-hidden {
    display: none;
}

.scp-membership-notice {
    background: #fffbeb;
    color: #92400e;
    border-bottom: 1px solid #fde68a;
    padding: 8px 14px;
    font-size: 12px;
    line-height: 1.4;
    flex-shrink: 0;
}

.scp-membership-notice.scp-is-hidden {
    display: none;
}

.scp-guest-link {
    text-align: center;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid #e5e5e5;
}

.scp-guest-link a {
    color: var(--scp-primary);
    text-decoration: none;
    font-size: 13px;
}

.scp-guest-link a:hover {
    text-decoration: underline;
}

/* Agent Label (Daxko / GroupEx) */
.scp-agent-label {
    font-size: 0.75rem;
    color: rgba(0, 0, 0, 0.5);
    font-weight: 500;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    padding-top: 0.4rem;
    margin-top: 0.4rem;
}

.scp-icon-people::before {
    content: "\1F465";
    margin-right: 2px;
}

.scp-icon-calendar::before {
    content: "\1F4C5";
    margin-right: 2px;
}

.scp-icon-operations::before {
    content: "\1F3E2";
    margin-right: 2px;
}

/* Daxko & GroupEx table styling */
.scp-message.assistant table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.5em 0;
    font-size: 0.85em;
}

.scp-message.assistant th,
.scp-message.assistant td {
    border: 1px solid rgba(0, 0, 0, 0.15);
    padding: 6px 10px;
    text-align: left;
}

.scp-message.assistant th {
    background-color: rgba(0, 0, 0, 0.08);
    font-weight: 600;
}

.scp-message.assistant tr:nth-child(even) {
    background-color: rgba(0, 0, 0, 0.03);
}

.scp-is-hidden {
    display: none !important;
}

/* Password toggle */
.scp-password-wrapper {
    position: relative;
    display: flex;
}

.scp-password-wrapper input {
    flex: 1;
    padding-right: 40px;
}

#scp-chat-container .scp-password-toggle {
    position: absolute !important;
    right: 8px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    background: none !important;
    background-color: transparent !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    cursor: pointer;
    color: #888;
    padding: 4px !important;
    margin: 0 !important;
    min-width: auto !important;
    min-height: auto !important;
    width: auto !important;
    height: auto !important;
    display: flex !important;
    align-items: center;
    line-height: 1;
}

#scp-chat-container .scp-password-toggle:hover,
#scp-chat-container .scp-password-toggle:focus,
#scp-chat-container .scp-password-toggle:active {
    color: #555;
    background: none !important;
    background-color: transparent !important;
    border: none !important;
    box-shadow: none !important;
    outline: none !important;
}