/* SPIN EEN Chatbot - Iframe Widget Style */

:root {
    --primary: #0066CC;
    --primary-dark: #0052A3;
    --primary-light: #E6F0FF;

    --bg-chat: #FFFFFF;
    --bg-app: #F5F7FA;
    --bg-user: linear-gradient(135deg, #0066CC, #0052A3);
    --bg-bot: #F0F4F8;

    --text: #1A1A2E;
    --text-secondary: #64748B;
    --text-light: #94A3B8;

    --border: #E2E8F0;
    --shadow-widget: 0 12px 48px rgba(15, 23, 42, 0.18);

    --radius: 12px;
    --radius-lg: 16px;
    --transition: 0.2s ease;
}

[data-theme="dark"] {
    --bg-chat: #1E293B;
    --bg-app: #0F172A;
    --bg-bot: #334155;
    --text: #F1F5F9;
    --text-secondary: #94A3B8;
    --text-light: #64748B;
    --border: #334155;
    --primary-light: rgba(0, 102, 204, 0.2);
}

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

html, body {
    height: 100%;
    width: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: transparent;          /* trasparente: l'iframe mostra solo il pannello arrotondato */
    color: var(--text);
    overflow: hidden;
}

/* ===== Widget container: riempie l'iframe ===== */
.widget {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-chat);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-widget);
    overflow: hidden;
}

/* ===== Header ===== */
.widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 12px 14px;
    background: var(--bg-chat);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.header-info {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.header-logo {
    height: 28px;
    width: auto;
    object-fit: contain;
    flex-shrink: 0;
}

.header-text {
    min-width: 0;
}

.header-text h1 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 1px;
    letter-spacing: -0.3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.status {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--text-secondary);
}

.status-dot {
    width: 7px;
    height: 7px;
    background: #10B981;
    border-radius: 50%;
    animation: pulse 2s infinite;
    flex-shrink: 0;
}

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

.header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

/* Lang segmented toggle */
.lang-toggle {
    display: flex;
    border: 1px solid var(--border);
    border-radius: 7px;
    overflow: hidden;
}

.lang-btn {
    padding: 5px 7px;
    font-size: 11px;
    font-weight: 600;
    font-family: inherit;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: var(--transition);
    line-height: 1;
}

.lang-btn:hover {
    color: var(--primary);
}

.lang-btn.active {
    background: var(--primary);
    color: #fff;
}

.icon-btn {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 7px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: var(--transition);
    flex-shrink: 0;
}

.icon-btn:hover {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
}

.icon-btn svg {
    width: 16px;
    height: 16px;
}

.close-btn:hover {
    background: rgba(239, 68, 68, 0.12);
    color: #EF4444;
    border-color: #EF4444;
}

.icon-btn .moon { display: none; }
[data-theme="dark"] .icon-btn .sun { display: none; }
[data-theme="dark"] .icon-btn .moon { display: block; }

/* ===== Messages area ===== */
.widget-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: var(--bg-app);
}

.widget-messages::-webkit-scrollbar { width: 6px; }
.widget-messages::-webkit-scrollbar-track { background: transparent; }
.widget-messages::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

/* ===== Message bubbles ===== */
.message {
    display: flex;
    gap: 8px;
    max-width: 88%;
    animation: fadeIn 0.3s ease;
}

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

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message.bot { align-self: flex-start; }

.message-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.message.bot .message-avatar {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    box-shadow: 0 2px 8px rgba(0, 102, 204, 0.3);
}

.message.user .message-avatar { background: #64748B; }

.message-avatar svg {
    width: 17px;
    height: 17px;
}

.message-content {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.message-bubble {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

.message.user .message-bubble {
    background: var(--bg-user);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.message.bot .message-bubble {
    background: var(--bg-bot);
    color: var(--text);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

/* Markdown in bot messages */
.message.bot .message-bubble p { margin-bottom: 8px; }
.message.bot .message-bubble p:last-child { margin-bottom: 0; }
.message.bot .message-bubble strong { font-weight: 600; }
.message.bot .message-bubble ul,
.message.bot .message-bubble ol {
    margin: 8px 0;
    padding-left: 18px;
}
.message.bot .message-bubble li { margin-bottom: 4px; }
.message.bot .message-bubble a {
    color: var(--primary);
    text-decoration: underline;
    word-break: break-word;
}
.message.bot .message-bubble pre {
    background: rgba(0,0,0,0.06);
    padding: 10px;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 12px;
}
[data-theme="dark"] .message.bot .message-bubble pre { background: rgba(0,0,0,0.3); }
.message.bot .message-bubble code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12.5px;
}

/* Source links */
.message-sources {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px 12px;
    background: var(--primary-light);
    border-radius: 8px;
    font-size: 12px;
}

.sources-title {
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.source-link {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--primary);
    text-decoration: none;
    transition: var(--transition);
}

.source-link:hover { text-decoration: underline; }

.source-link svg {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
}

/* Social links */
.message-social {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

.social-link {
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-bot);
    border-radius: 6px;
    color: var(--text-secondary);
    transition: var(--transition);
}

.social-link:hover {
    background: var(--primary);
    color: #fff;
}

.social-link svg {
    width: 13px;
    height: 13px;
}

/* Welcome message */
.welcome-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 20px 8px;
    margin: auto 0;
}

.welcome-message .bot-bubble {
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--primary-light), rgba(0, 102, 204, 0.08));
    color: var(--text);
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.55;
    border: 1px solid rgba(0, 102, 204, 0.15);
}

/* Typing indicator */
.typing {
    display: none;
    padding: 0 16px 8px;
    background: var(--bg-app);
    flex-shrink: 0;
}

.typing.active { display: block; }

.typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    background: var(--bg-bot);
    border-radius: var(--radius);
    border-bottom-left-radius: 4px;
}

.typing-dots span {
    width: 7px;
    height: 7px;
    background: var(--text-light);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* Input area */
.widget-input {
    padding: 12px 14px;
    background: var(--bg-chat);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.widget-input form {
    display: flex;
    gap: 10px;
    align-items: center;
}

.widget-input input {
    flex: 1;
    min-width: 0;
    padding: 11px 14px;
    font-size: 14px;
    font-family: inherit;
    color: var(--text);
    background: var(--bg-app);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    outline: none;
    transition: var(--transition);
}

.widget-input input::placeholder { color: var(--text-light); }

.widget-input input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.widget-input button {
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    color: #fff;
    transition: var(--transition);
    flex-shrink: 0;
}

.widget-input button:hover {
    background: var(--primary-dark);
    transform: scale(1.05);
}

.widget-input button:disabled {
    background: var(--border);
    cursor: not-allowed;
    transform: none;
}

.widget-input button svg {
    width: 19px;
    height: 19px;
}

/* Streaming cursor */
.streaming-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: var(--primary);
    animation: blink 1s infinite;
    vertical-align: text-bottom;
    margin-left: 2px;
}

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

/* Su viewport molto stretti (widget a tutta larghezza su mobile),
   il pannello diventa a spigolo vivo perché riempie lo schermo. */
@media (max-width: 420px) {
    .widget {
        border-radius: 0;
        border: none;
        box-shadow: none;
    }
    .message { max-width: 92%; }
}
