* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: transparent;
    overflow: hidden;
}

/* Bolla */
#chatbot-bubble {
    position: fixed;
    bottom: 28px;
    right: 28px;
    width: 60px;
    height: 60px;
    background: #012553;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(1,37,83,0.45);
    transition: transform 0.25s, box-shadow 0.25s;
    z-index: 1000;
    user-select: none;
}

#chatbot-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 28px rgba(1,37,83,0.6);
}

/* Finestra chat */
#chatbot-window {
    position: fixed;
    bottom: 100px;
    right: 28px;
    width: 380px;
    height: 520px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 1000;
    transition: opacity 0.3s, transform 0.3s;
}

#chatbot-window.hidden {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
}

/* Header */
#chat-header {
    background: #012553;
    color: #fff;
    padding: 16px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 15px;
}

#close-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 6px;
    transition: background 0.2s;
}

#close-btn:hover { background: rgba(255,255,255,0.2); }

/* Messaggi */
#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f8f9fb;
}

.message {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.message.user {
    align-self: flex-end;
    background: #012553;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.message.bot {
    align-self: flex-start;
    background: #fff;
    color: #333;
    border: 1px solid #e4e6eb;
    border-bottom-left-radius: 4px;
}

/* Markdown formatting in bot messages */
.message.bot h1,
.message.bot h2,
.message.bot h3,
.message.bot h4 {
    color: #012553;
    margin: 10px 0 6px 0;
    line-height: 1.3;
}

.message.bot h1 { font-size: 17px; }
.message.bot h2 { font-size: 15px; }
.message.bot h3 { font-size: 14px; }
.message.bot h4 { font-size: 13px; }

.message.bot p {
    margin: 4px 0;
}

.message.bot strong {
    color: #012553;
    font-weight: 700;
}

.message.bot em {
    font-style: italic;
}

.message.bot ul {
    margin: 6px 0;
    padding-left: 18px;
    list-style: disc;
}

.message.bot ol {
    margin: 6px 0;
    padding-left: 22px;
    list-style: decimal;
}

.message.bot li {
    margin: 3px 0;
    padding-left: 4px;
}

.message.bot ul li {
    list-style: disc;
}

.message.bot ol li {
    list-style: decimal;
}

.message.bot hr {
    border: none;
    border-top: 1px solid #e4e6eb;
    margin: 10px 0;
}

.message.bot pre {
    background: #f0f2f5;
    padding: 8px 10px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 6px 0;
    font-size: 12px;
}

.message.bot code {
    background: #f0f2f5;
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 12px;
    font-family: 'Courier New', monospace;
}

.message.bot pre code {
    background: none;
    padding: 0;
}

/* Tables */
.message.bot table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 12px;
}

.message.bot thead tr {
    background: #012553;
    color: #fff;
}

.message.bot th {
    padding: 6px 10px;
    text-align: left;
    font-weight: 600;
    border: 1px solid #012553;
}

.message.bot td {
    padding: 5px 10px;
    border: 1px solid #e4e6eb;
}

.message.bot tbody tr:nth-child(even) {
    background: #f8f9fb;
}

/* Blockquote */
.message.bot blockquote {
    border-left: 3px solid #012553;
    margin: 8px 0;
    padding: 6px 12px;
    background: #f0f4f8;
    border-radius: 0 6px 6px 0;
    color: #555;
    font-style: italic;
}

/* Task lists */
.message.bot .task-item {
    margin: 3px 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.message.bot .task-item input[type="checkbox"] {
    accent-color: #012553;
    width: 14px;
    height: 14px;
}

.message.bot .task-item s {
    color: #999;
}

/* Definition lists */
.message.bot .def-list {
    margin: 4px 0 4px 10px;
}

.message.bot .def-list dt {
    margin-top: 4px;
}

.message.bot .def-list dd {
    margin-left: 16px;
    color: #555;
}

/* Highlight */
.message.bot mark {
    background: #fff3a8;
    padding: 0 3px;
    border-radius: 3px;
}

/* Links */
.message.bot a {
    color: #012553;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.message.bot a:hover {
    opacity: 0.8;
}

/* Footnotes */
.message.bot .footnote {
    color: #012553;
    font-size: 11px;
    cursor: pointer;
}

/* Nested lists */
.message.bot ul ul,
.message.bot ol ol,
.message.bot ul ol,
.message.bot ol ul {
    margin: 3px 0;
    padding-left: 16px;
}

/* Input */
#chat-input-area {
    display: flex;
    padding: 12px;
    gap: 8px;
    border-top: 1px solid #e4e6eb;
    background: #fff;
    align-items: center;
    position: relative;
}

#chat-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: 20px;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.4;
    outline: none;
    transition: border-color 0.2s;
    resize: none;
    overflow-y: auto;
    max-height: calc(1.4em * 5 + 20px + 2px);
    min-height: 42px;
    height: 42px;
}

#chat-input:focus { border-color: #012553; }
#chat-input:disabled { opacity: 0.5; cursor: not-allowed; }

#send-btn {
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    background: #012553;
    color: white;
    padding: 10px 16px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 20px;
    overflow: hidden;
    cursor: pointer;
    gap: 6px;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
}

#send-btn .svg-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    order: 0;
    transition: transform 0.25s ease;
}

#send-btn .svg-wrapper svg {
    transition: transform 0.25s ease;
}

#send-btn span {
    display: block;
    white-space: nowrap;
    order: 1;
    transition: transform 0.25s ease, opacity 0.2s ease;
}

#send-btn:hover span {
    transform: translateX(4px);
}

#send-btn:hover .svg-wrapper {
    transition: transform 0.25s ease 0.08s;
    transform: translateX(2px);
}

#send-btn:hover .svg-wrapper svg {
    transition: transform 0.25s ease 0.08s;
    transform: rotate(-45deg) scale(1.15);
}

#send-btn:active {
    transform: scale(0.95);
}

#send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

#send-btn:disabled:hover span,
#send-btn:disabled:hover .svg-wrapper,
#send-btn:disabled:hover .svg-wrapper svg {
    transform: none;
}

/* Scroll to bottom button */
#scroll-bottom-btn {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(6px);
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #012553;
    color: #fff;
    border: 2px solid rgba(255,255,255,0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 3px 12px rgba(1,37,83,0.45), 0 0 0 0 rgba(1,37,83,0.15);
    z-index: 10;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.2s, box-shadow 0.2s, background 0.2s;
}

#scroll-bottom-btn.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0);
}

#scroll-bottom-btn:hover {
    background: #013a7a;
    box-shadow: 0 4px 16px rgba(1,37,83,0.55), 0 0 0 4px rgba(1,37,83,0.12);
    transform: translateX(-50%) translateY(-1px) scale(1.08);
}

#scroll-bottom-btn:active {
    transform: translateX(-50%) scale(0.95);
    box-shadow: 0 2px 8px rgba(1,37,83,0.4);
}

/* Scrollbar */
#chat-messages::-webkit-scrollbar { width: 5px; }
#chat-messages::-webkit-scrollbar-thumb { background: #c4c4c4; border-radius: 10px; }

/* ===== TYPING INDICATOR ===== */
.typing-msg {
    display: flex;
    align-items: center;
    padding: 0 !important;
    background: none !important;
    border: none !important;
    box-shadow: none !important;
}

.typing-content {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Mini loader 3x3 */
.mini-loader {
    display: grid;
    grid-template-columns: repeat(3, 5px);
    gap: 3px;
    flex-shrink: 0;
}

.ml {
    width: 5px;
    height: 5px;
    border-radius: 1px;
    background: #c8c8c8;
    will-change: transform, background;
}

/* Animazioni loader — base #c8c8c8, attivo #012553 */
.ml:nth-child(1) { animation: ml1 3s linear infinite; }
.ml:nth-child(2) { animation: ml2 3s linear infinite; }
.ml:nth-child(3) { animation: ml3 3s linear infinite; }
.ml:nth-child(4) { animation: ml4 3s linear infinite; }
.ml:nth-child(5) { animation: ml5 3s linear infinite; }
.ml:nth-child(6) { animation: ml6 3s linear infinite; }
.ml:nth-child(7) { animation: ml7 3s linear infinite; }
.ml:nth-child(8) { animation: ml8 3s linear infinite; }
.ml:nth-child(9) { animation: ml9 3s linear infinite; }

@keyframes ml1 {
    0%     { background: #c8c8c8; transform: scale(1); }
    3%     { background: #c8c8c8; transform: scale(1.3); }
    3.5%   { background: #012553; transform: scale(1.3); }
    26.5%  { background: #012553; transform: scale(1.3); }
    27%    { background: #c8c8c8; transform: scale(1); }
    31%    { background: #c8c8c8; transform: scale(1.3); }
    31.5%  { background: #012553; transform: scale(1.3); }
    54.5%  { background: #012553; transform: scale(1.3); }
    55%    { background: #c8c8c8; transform: scale(1); }
    63%    { background: #c8c8c8; transform: scale(1.3); }
    63.5%  { background: #012553; transform: scale(1.3); }
    99%    { background: #012553; transform: scale(1.3); }
    100%   { background: #c8c8c8; transform: scale(1); }
}

@keyframes ml2 {
    0%     { background: #c8c8c8; transform: scale(1); }
    5%     { background: #c8c8c8; transform: scale(1.3); }
    5.5%   { background: #012553; transform: scale(1.3); }
    26.5%  { background: #012553; transform: scale(1.3); }
    27%    { background: #c8c8c8; transform: scale(1); }
    29%    { background: #c8c8c8; transform: scale(1.3); }
    29.5%  { background: #012553; transform: scale(1.3); }
    54.5%  { background: #012553; transform: scale(1.3); }
    55%    { background: #c8c8c8; transform: scale(1); }
    65%    { background: #c8c8c8; transform: scale(1.3); }
    65.5%  { background: #012553; transform: scale(1.3); }
    99%    { background: #012553; transform: scale(1.3); }
    100%   { background: #c8c8c8; transform: scale(1); }
}

@keyframes ml3 {
    0%     { background: #c8c8c8; transform: scale(1); }
    6%     { background: #c8c8c8; transform: scale(1.3); }
    6.5%   { background: #012553; transform: scale(1.3); }
    54.5%  { background: #012553; transform: scale(1.3); }
    55%    { background: #c8c8c8; transform: scale(1); }
    66%    { background: #c8c8c8; transform: scale(1.3); }
    66.5%  { background: #012553; transform: scale(1.3); }
    99%    { background: #012553; transform: scale(1.3); }
    100%   { background: #c8c8c8; transform: scale(1); }
}

@keyframes ml4 {
    0%     { background: #c8c8c8; transform: scale(1); }
    33%    { background: #c8c8c8; transform: scale(1); }
    33.5%  { background: #c8c8c8; transform: scale(1.3); }
    34%    { background: #012553; transform: scale(1.3); }
    54.5%  { background: #012553; transform: scale(1.3); }
    55%    { background: #c8c8c8; transform: scale(1); }
    61%    { background: #c8c8c8; transform: scale(1.3); }
    61.5%  { background: #012553; transform: scale(1.3); }
    99%    { background: #012553; transform: scale(1.3); }
    100%   { background: #c8c8c8; transform: scale(1); }
}

@keyframes ml5 {
    0%     { background: #c8c8c8; transform: scale(1); }
    3%     { background: #c8c8c8; transform: scale(1.3); }
    3.5%   { background: #012553; transform: scale(1.3); }
    26.5%  { background: #012553; transform: scale(1.3); }
    27%    { background: #c8c8c8; transform: scale(1); }
    43%    { background: #c8c8c8; transform: scale(1.3); }
    43.5%  { background: #012553; transform: scale(1.3); }
    54.5%  { background: #012553; transform: scale(1.3); }
    55%    { background: #c8c8c8; transform: scale(1); }
    100%   { background: #c8c8c8; transform: scale(1); }
}

@keyframes ml6 {
    0%     { background: #c8c8c8; transform: scale(1); }
    41%    { background: #c8c8c8; transform: scale(1); }
    41.5%  { background: #c8c8c8; transform: scale(1.3); }
    42%    { background: #012553; transform: scale(1.3); }
    54.5%  { background: #012553; transform: scale(1.3); }
    55%    { background: #c8c8c8; transform: scale(1); }
    100%   { background: #c8c8c8; transform: scale(1); }
}

@keyframes ml7 {
    0%     { background: #c8c8c8; transform: scale(1); }
    35%    { background: #c8c8c8; transform: scale(1); }
    35.5%  { background: #c8c8c8; transform: scale(1.3); }
    36%    { background: #012553; transform: scale(1.3); }
    54.5%  { background: #012553; transform: scale(1.3); }
    55%    { background: #c8c8c8; transform: scale(1); }
    59%    { background: #c8c8c8; transform: scale(1.3); }
    59.5%  { background: #012553; transform: scale(1.3); }
    99%    { background: #012553; transform: scale(1.3); }
    100%   { background: #c8c8c8; transform: scale(1); }
}

@keyframes ml8 {
    0%     { background: #c8c8c8; transform: scale(1); }
    0.5%   { background: #c8c8c8; transform: scale(1.3); }
    1%     { background: #012553; transform: scale(1.3); }
    26.5%  { background: #012553; transform: scale(1.3); }
    27%    { background: #c8c8c8; transform: scale(1); }
    37%    { background: #c8c8c8; transform: scale(1.3); }
    37.5%  { background: #012553; transform: scale(1.3); }
    54.5%  { background: #012553; transform: scale(1.3); }
    55%    { background: #c8c8c8; transform: scale(1); }
    57%    { background: #c8c8c8; transform: scale(1.3); }
    57.5%  { background: #012553; transform: scale(1.3); }
    99%    { background: #012553; transform: scale(1.3); }
    100%   { background: #c8c8c8; transform: scale(1); }
}

@keyframes ml9 {
    0%     { background: #c8c8c8; transform: scale(1); }
    39%    { background: #c8c8c8; transform: scale(1); }
    39.5%  { background: #c8c8c8; transform: scale(1.3); }
    40%    { background: #012553; transform: scale(1.3); }
    99%    { background: #012553; transform: scale(1.3); }
    100%   { background: #c8c8c8; transform: scale(1); }
}

/* ===== REASONING SECTION ===== */
.reasoning-info {
    font-size: 11px;
    color: #888;
    padding: 4px 10px;
    margin-bottom: 2px;
    flex-shrink: 0;
    animation: fadeSummary 0.3s ease;
}

.reasoning-info.done {
    color: #012553;
    font-weight: 600;
}

@keyframes fadeSummary {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Typing text — senza contorno, glow bianco che scorre da sinistra a destra */
.typing-text {
    font-size: 13px;
    font-weight: 600;
    color: #012553;
    position: relative;
    background: linear-gradient(90deg, #012553 0%, #012553 30%, #ffffff 45%, #ffffff 55%, #012553 70%, #012553 100%);
    background-size: 300px 100%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: shine 3s linear infinite;
}

@-moz-keyframes shine {
    0%   { background-position: -200px; }
    85%  { background-position: 250px; }
    86%  { background-position: -200px; }
    100% { background-position: -200px; }
}

@-webkit-keyframes shine {
    0%   { background-position: -200px; }
    85%  { background-position: 250px; }
    86%  { background-position: -200px; }
    100% { background-position: -200px; }
}

@-o-keyframes shine {
    0%   { background-position: -200px; }
    85%  { background-position: 250px; }
    86%  { background-position: -200px; }
    100% { background-position: -200px; }
}

@keyframes shine {
    0%   { background-position: -200px; }
    85%  { background-position: 250px; }
    86%  { background-position: -200px; }
    100% { background-position: -200px; }
}
