/* SigiltecH AI — chat-modal.css */

:root {
    --stai-navy:        #001b36;
    --stai-navy-light:  #002a52;
    --stai-white:       #ffffff;
    --stai-gray-bg:     #f7f8fa;
    --stai-gray-border: #e8eaed;
    --stai-gray-text:   #6b7280;
    --stai-user-bg:     #001b36;
    --stai-user-text:   #ffffff;
    --stai-ai-text:     #1a1a2e;
    --stai-shadow:      0 4px 24px rgba(0,27,54,0.18), 0 1px 4px rgba(0,0,0,0.08);
    --stai-radius:      16px;
    --stai-z:           99990;
}

/* ---- Panel ---- */
.stai-panel {
    position: fixed;
    bottom: 90px;
    right: 24px;
    width: 360px;
    max-width: calc(100vw - 32px);
    height: 520px;
    max-height: calc(100vh - 120px);
    background: var(--stai-white);
    border-radius: var(--stai-radius);
    box-shadow: var(--stai-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: var(--stai-z);
    transform: translateY(12px) scale(0.97);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.22s cubic-bezier(.4,0,.2,1),
                opacity   0.22s cubic-bezier(.4,0,.2,1);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    box-sizing: border-box;
}

.stai-panel.stai-open {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: all;
}

.stai-panel.stai-hidden {
    display: none;
}

.stai-panel *,
.stai-panel *::before,
.stai-panel *::after {
    box-sizing: border-box;
}

/* ---- Header ---- */
.stai-panel-header {
    background: var(--stai-navy);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    border-radius: var(--stai-radius) var(--stai-radius) 0 0;
}

.stai-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.stai-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
    border: 2px solid rgba(255,255,255,0.2);
}

.stai-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.stai-avatar svg {
    width: 22px;
    height: 22px;
    fill: rgba(255,255,255,0.9);
}

.stai-header-name {
    color: var(--stai-white);
    font-weight: 700;
    font-size: 15px;
    letter-spacing: 0.01em;
    line-height: 1;
}

.stai-btn-close {
    background: rgba(255,255,255,0.1) !important;
    border: none !important;
    border-radius: 8px !important;
    width: 30px !important;
    height: 30px !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: background 0.15s !important;
    padding: 0 !important;
    flex-shrink: 0;
    box-shadow: none !important;
    outline: none !important;
}

.stai-btn-close:hover {
    background: rgba(255,255,255,0.22) !important;
}

.stai-btn-close svg {
    width: 16px;
    height: 16px;
    fill: rgba(255,255,255,0.85);
    display: block;
}

/* ---- Messages ---- */
.stai-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--stai-gray-bg);
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

.stai-messages::-webkit-scrollbar { width: 4px; }
.stai-messages::-webkit-scrollbar-track { background: transparent; }
.stai-messages::-webkit-scrollbar-thumb { background: var(--stai-gray-border); border-radius: 4px; }

.stai-msg {
    display: flex;
    flex-direction: column;
    max-width: 84%;
}

.stai-msg-ai   { align-self: flex-start; }
.stai-msg-user { align-self: flex-end; }

.stai-bubble-msg {
    padding: 10px 13px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    margin: 0;
}

.stai-msg-ai .stai-bubble-msg {
    background: var(--stai-white);
    color: var(--stai-ai-text);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.07);
}

.stai-msg-user .stai-bubble-msg {
    background: var(--stai-user-bg);
    color: var(--stai-user-text);
    border-bottom-right-radius: 4px;
}

/* ---- Messaggio limite — elegante ---- */
.stai-msg-limit {
    align-self: center;
    max-width: 92%;
}

.stai-msg-limit .stai-bubble-msg {
    background: linear-gradient(135deg, #0f2942 0%, #001b36 100%);
    color: rgba(255,255,255,0.92);
    border-radius: 12px;
    padding: 14px 18px;
    text-align: center;
    font-size: 13px;
    line-height: 1.6;
    box-shadow: 0 4px 16px rgba(0,27,54,0.25);
    border: 1px solid rgba(255,255,255,0.08);
    position: relative;
    overflow: hidden;
}

.stai-msg-limit .stai-bubble-msg::before {
    content: '⏳';
    display: block;
    font-size: 22px;
    margin-bottom: 6px;
}

.stai-msg-limit .stai-bubble-msg strong {
    display: block;
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 4px;
    color: #ffffff;
}

/* ---- Messaggio errore generico ---- */
.stai-msg-error .stai-bubble-msg {
    background: #fff8f0;
    color: #92400e;
    border: 1px solid #fde68a;
    border-bottom-left-radius: 4px;
    box-shadow: none;
}

.stai-msg-time {
    font-size: 11px;
    color: var(--stai-gray-text);
    margin-top: 3px;
    padding: 0 2px;
    line-height: 1;
}

.stai-msg-ai   .stai-msg-time { text-align: left; }
.stai-msg-user .stai-msg-time { text-align: right; }
.stai-msg-limit .stai-msg-time { text-align: center; }

/* ---- Typing ---- */
.stai-typing-wrap {
    align-self: flex-start;
}

.stai-typing {
    background: var(--stai-white);
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.07);
}

.stai-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--stai-navy);
    opacity: 0.4;
    display: block;
    animation: stai-bounce 1.3s infinite ease-in-out;
}

.stai-typing span:nth-child(2) { animation-delay: 0.18s; }
.stai-typing span:nth-child(3) { animation-delay: 0.36s; }

@keyframes stai-bounce {
    0%, 60%, 100% { transform: translateY(0);    opacity: 0.4; }
    30%            { transform: translateY(-4px); opacity: 1;   }
}

/* ---- Footer / Input ---- */
.stai-footer {
    padding: 10px 12px 10px;
    background: var(--stai-white);
    border-top: 1px solid var(--stai-gray-border);
    flex-shrink: 0;
}

.stai-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--stai-gray-bg) !important;
    border: 1.5px solid var(--stai-gray-border) !important;
    border-radius: 12px !important;
    padding: 6px 6px 6px 12px;
    transition: border-color 0.15s;
    box-shadow: none !important;
}

.stai-input-wrap:focus-within {
    border-color: var(--stai-navy) !important;
}

.stai-input {
    flex: 1;
    border: none !important;
    border-radius: 0 !important;
    background: transparent !important;
    outline: none !important;
    box-shadow: none !important;
    font-size: 14px !important;
    font-family: inherit !important;
    resize: none !important;
    color: var(--stai-ai-text) !important;
    line-height: 1.5 !important;
    max-height: 100px;
    overflow-y: auto;
    padding: 2px 0 !important;
    margin: 0 !important;
    width: 100%;
    display: block;
    -webkit-appearance: none;
    appearance: none;
}

.stai-input:focus {
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
}

.stai-input::placeholder {
    color: var(--stai-gray-text) !important;
    opacity: 1;
}

.stai-send {
    width: 34px !important;
    height: 34px !important;
    min-width: 34px !important;
    border-radius: 9px !important;
    background: var(--stai-navy) !important;
    border: none !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: background 0.15s, transform 0.1s !important;
    flex-shrink: 0;
    box-shadow: none !important;
    padding: 0 !important;
    outline: none !important;
}

.stai-send:hover:not(:disabled) {
    background: var(--stai-navy-light) !important;
    transform: scale(1.05);
}

.stai-send:disabled {
    background: var(--stai-gray-border) !important;
    cursor: not-allowed !important;
    transform: none !important;
}

.stai-send svg {
    width: 16px;
    height: 16px;
    fill: var(--stai-white);
    margin-left: 1px;
    display: block;
}

.stai-powered {
    text-align: center;
    font-size: 11px;
    color: var(--stai-gray-text);
    margin-top: 7px;
    letter-spacing: 0.01em;
    line-height: 1;
}

/* ---- Bubble ---- */
.stai-bubble {
    position: fixed !important;
    bottom: 24px;
    width: 56px !important;
    height: 56px !important;
    border-radius: 50% !important;
    background: var(--stai-navy) !important;
    border: none !important;
    box-shadow: 0 4px 16px rgba(0,27,54,0.35) !important;
    cursor: pointer !important;
    z-index: calc(var(--stai-z) - 1);
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    overflow: hidden !important;
    transition: transform 0.2s cubic-bezier(.4,0,.2,1), box-shadow 0.2s;
    padding: 0 !important;
    outline: none !important;
}

.stai-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(0,27,54,0.45) !important;
}

.stai-bubble img {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

.stai-bubble svg {
    width: 26px;
    height: 26px;
    fill: var(--stai-white);
    display: block;
}

.stai-bubble-bottom-right { right: 24px; }
.stai-bubble-bottom-left  { left: 24px; }

/* ---- Fullscreen ---- */
.stai-panel.stai-fullscreen {
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    height: 100% !important;
    max-height: 100% !important;
    border-radius: 0 !important;
    transform: none !important;
    z-index: 999999 !important;
}

.stai-panel.stai-fullscreen .stai-panel-header {
    border-radius: 0 !important;
}

.stai-panel.stai-fullscreen .stai-footer {
    border-radius: 0 !important;
}

.stai-panel.stai-fullscreen .stai-input-wrap {
    border-radius: 8px !important;
}

/* ---- Mobile ---- */
@media (max-width: 600px) {
    .stai-panel {
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        height: 72vh !important;
        max-height: 72vh !important;
        border-radius: 20px 20px 0 0 !important;
        transform: translateY(20px) scale(1) !important;
    }

    .stai-panel.stai-open {
        transform: translateY(0) scale(1) !important;
    }

    .stai-panel-header {
        border-radius: 20px 20px 0 0;
        padding: 16px 16px;
    }

    .stai-bubble-bottom-right { right: 16px !important; bottom: 16px !important; }
    .stai-bubble-bottom-left  { left: 16px !important;  bottom: 16px !important; }

    .stai-bubble {
        width: 52px !important;
        height: 52px !important;
    }

    .stai-input {
        font-size: 16px !important;
    }
}
/* ---- Contact form inline ---- */
.stai-contact-bubble {
    background: var(--stai-white) !important;
    border: 1.5px solid var(--stai-gray-border);
    padding: 16px !important;
    width: 100%;
    max-width: 100% !important;
}

.stai-cf-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--stai-navy);
    margin-bottom: 12px;
    letter-spacing: 0.01em;
}

.stai-cf-row {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.stai-cf-row .stai-cf-input {
    flex: 1;
}

.stai-cf-input {
    width: 100%;
    border: 1.5px solid var(--stai-gray-border) !important;
    border-radius: 8px !important;
    padding: 8px 10px !important;
    font-size: 13px !important;
    font-family: inherit !important;
    color: var(--stai-ai-text) !important;
    background: var(--stai-gray-bg) !important;
    outline: none !important;
    box-shadow: none !important;
    transition: border-color 0.15s;
    margin-bottom: 8px;
    display: block;
    box-sizing: border-box;
}

.stai-cf-input:focus {
    border-color: var(--stai-navy) !important;
    background: var(--stai-white) !important;
}

.stai-cf-input::placeholder {
    color: var(--stai-gray-text) !important;
}

.stai-cf-full {
    width: 100%;
}

.stai-cf-textarea {
    resize: none !important;
    min-height: 56px;
    line-height: 1.5 !important;
}

.stai-cf-submit {
    width: 100%;
    padding: 10px !important;
    background: var(--stai-navy) !important;
    color: var(--stai-white) !important;
    border: none !important;
    border-radius: 9px !important;
    font-size: 13px !important;
    font-weight: 600 !important;
    font-family: inherit !important;
    cursor: pointer !important;
    transition: background 0.15s !important;
    margin-top: 4px;
    letter-spacing: 0.02em;
}

.stai-cf-submit:hover:not(:disabled) {
    background: var(--stai-navy-light) !important;
}

.stai-cf-submit:disabled {
    background: var(--stai-gray-border) !important;
    cursor: not-allowed !important;
    color: var(--stai-gray-text) !important;
}

.stai-cf-note {
    font-size: 11px;
    color: var(--stai-gray-text);
    margin-top: 8px;
    text-align: center;
}