﻿body {
    background-image: url('../fabulatabula sfondo.webp');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    min-height: 100vh;
    font-family: 'Georgia', serif;
    background-color: var(--fabule-bg-light);
}

.container {
    max-width: 800px;
    padding: 0 15px 4rem 15px;
}

/* Riduzione del margine superiore */
.container.mt-5 {
    margin-top: 1rem !important; /* Ridotto da 3rem (mt-5) a 1rem */
}

.card {
    background-color: rgba(var(--fabule-secondary-rgb), 0.3); /* Sfondo pergamena leggero per integrazione con tema */
    backdrop-filter: blur(5px);
    margin-top: 0px;
}

.card-title {
    font-family: 'Charm', cursive;
    font-size: 1.3rem;
    color: var(--fabule-text-dark);
    margin-bottom: 1rem;
}

.list-group-item {
    background-color: rgba(var(--fabule-secondary-rgb), 0.6);
}

/* Prominent upload call-to-action title for upload screen */
.upload-cta {
    font-family: 'Charm', cursive;
    font-weight: 700;
    color: var(--fabule-text-dark); /* dark ink for high contrast */
    font-size: clamp(1.1rem, 3.2vw, 1.9rem);
    line-height: 1.1;
    margin: 0 0 0.75rem 0;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.12);
    word-break: break-word;
}

@media (max-width: 480px) {
    .upload-cta {
        font-size: clamp(1rem, 4.5vw, 1.3rem);
    }
}

/* Upload page section titles with Charm font */
.file-limit-indicator strong,
h6.mb-3 {
    font-family: 'Charm', cursive;
    font-size: 1.2rem;
}

.chat-response {
    margin: 20px 0;
    padding: 20px;
    border-left: 4px solid var(--fabule-secondary);
    background-color: rgba(var(--fabule-secondary-rgb), 0.95);
    backdrop-filter: blur(5px);
    border-radius: 10px;
    font-family: 'Georgia', serif;
    line-height: 1.6;
    color: var(--fabule-text-dark);
}

#loading {
    background-color: rgba(204, 229, 255, 0.95);
    backdrop-filter: blur(5px);
}

h1.mb-4 {
    font-family: 'Charm', cursive;
    color: var(--fabule-ink-red);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    font-size: clamp(2.5rem, 8vw, 4.5rem);
    text-align: center;
    margin-bottom: 2rem !important;
    padding: 0 10px;
}

h1 {
    font-family: 'Charm', cursive;
    color: var(--fabule-primary);
}

.file-info-container {
    width: 100%;
    margin-bottom: 20px;
    background-color: rgba(255, 255, 255, 0.6);
    border-radius: 5px;
    padding: 10px;
}

.file-title {
    position: relative;
    padding: 8px 15px;
    background-color: rgba(248, 249, 250, 0.6);
    border-radius: 5px;
    font-style: italic;
    font-size: 0.9rem;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    border: 1px solid var(--fabule-secondary-dark);
    color: var(--fabule-text-medium);
    width: 100%;
    backdrop-filter: blur(3px);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
}

.file-title .file-name {
    font-weight: bold;
    margin-right: 10px;
}

.file-title h2 {
    font-family: 'Charm', cursive;
    color: #8B1A1A;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    font-size: clamp(1.2rem, 4vw, 2.2rem);
    margin: 0;
    padding: 8px 15px;
    background-color: rgba(255, 255, 255, 0.9);
    border-radius: 5px;
    backdrop-filter: blur(5px);
    word-break: break-word;
}

.last-sentence {
    font-size: 0.85rem;
    max-height: 80px;
    overflow-y: auto;
    padding: 8px;
    border-left: 3px solid #6c757d;
    margin-top: 10px;
    background-color: rgba(var(--fabule-secondary-rgb), 0.3);
    border-radius: 5px;
    width: 100%;
    transition: max-height 0.3s ease;
}

.last-sentence.expanded {
    max-height: none;
    overflow-y: visible;
}

.upload-area {
    transition: opacity 0.5s ease-out;
}

.card, .btn, .form-control {
    transition: all 0.3s ease;
}

select, button, input[type="file"] {
    min-height: 44px;
}

.question-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 15px;
    align-items: center;
}

.question-btn {
    padding: 0.8rem 1rem;
    text-align: left;
    white-space: normal;
    height: 100%;
    position: relative;
    overflow: hidden;
    z-index: 1;
    opacity: 1;
    transform-origin: center;
    transform: scale(1);
    
    /* Stile simile al logout button */
    background-color: var(--fabule-secondary-light); /* Colore pergamena */
    color: var(--fabule-text-dark); /* Colore inchiostro marrone scuro */
    border: 1px solid var(--fabule-secondary-dark);
    border-radius: 5px;
    font-family: 'Charm', cursive;
    font-size: 1.1rem;
    font-weight: 500;
    text-shadow: none;
    box-shadow: 0 3px 5px rgba(0,0,0,0.1), inset 0 0 15px rgba(var(--fabule-secondary-rgb), 0.2);
    transition: all 0.3s ease;
}

.question-btn.unselected {
    opacity: 0.5;
    transform: scale(0.95);
    pointer-events: none;
    cursor: not-allowed;
    transition: all 0.3s ease;
}

.question-btn.hidden {
    display: none;
}

.question-btn:before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, var(--fabule-primary), var(--fabule-accent-3));
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: -1;
}

.question-btn.selected {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1);
    color: var(--fabule-text-dark);
    background-color: var(--fabule-secondary); /* PiÃ¹ scuro del normale per indicare selezione */
    border-color: var(--fabule-accent-1);
    box-shadow: 0 2px 4px rgba(0,0,0,0.15), inset 0 0 15px rgba(var(--fabule-secondary-rgb), 0.4);
}

.question-btn.selected:before {
    opacity: 1;
}

.question-btn:hover:not(:disabled):not(.selected) {
    background-color: var(--fabule-secondary-light);
    color: var(--fabule-text-dark);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15), inset 0 0 20px rgba(var(--fabule-secondary-rgb), 0.3);
    transform: translateY(-2px);
    border-color: var(--fabule-accent-1);
}

.question-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    background-color: var(--fabule-secondary-light);
    color: var(--fabule-text-medium);
}

.question-btn.question-waiting {
    opacity: 0.9; /* Aumentata l'opacitÃ  per migliorare la leggibilitÃ  */
    cursor: wait;
    pointer-events: none;
    background-color: var(--fabule-bg-medium); /* Sfondo pergamena chiaro */
    color: var(--fabule-text-dark); /* Colore testo marrone scuro per un buon contrasto */
    box-shadow: none !important;
    transform: none !important;
}

/* Miglioramento della leggibilitÃ  dei pulsanti delle domande selezionate */
.question-btn.active, .question-btn:active {
    background-color: #0056b3 !important; /* Colore di sfondo piÃ¹ scuro */
    color: white !important; /* Testo bianco per maggior contrasto */
    font-weight: bold; /* Testo in grassetto */
    border-color: #004085 !important; /* Bordo piÃ¹ scuro */
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25); /* Effetto di evidenziazione */
}

/* Assicurarsi che il testo rimanga leggibile anche durante l'elaborazione */
.processing .question-btn.active, .processing .question-btn:active {
    opacity: 0.9; /* Leggera trasparenza ma mantenendo la leggibilitÃ  */
    color: white !important; /* Assicurarsi che il testo rimanga bianco */
}

#customQuestionDiv {
    margin-bottom: 1rem;
}

.button-group {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
    align-items: center;
    margin-top: 15px;
    display: flex;
    gap: 10px;
}

.button-group button {
    flex: 0 1 auto;
}

.header-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 1px;
    text-align: center;
    width: 100%;
}

/* New style for header container with left alignment */
.header-container.left-aligned {
    align-items: flex-start;
    text-align: left;
}

.title-logout-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

/* Updated logout button styles - Ink and parchment theme */
.logout-btn {
    position: relative;
    display: inline-block;
    padding: 8px 15px;
    background-color: var(--fabule-secondary-light); /* Parchment color */
    color: var(--fabule-text-dark); /* Dark brown ink color */
    border: 1px solid var(--fabule-secondary-dark);
    border-radius: 5px;
    font-family: 'Charm', cursive;
    font-size: 1.1rem;
    text-shadow: none;
    box-shadow: 0 3px 5px rgba(0,0,0,0.1), inset 0 0 15px rgba(var(--fabule-secondary-rgb), 0.2);
    transition: all 0.3s ease;
    white-space: nowrap;
    text-align: center;
    width: auto;
    min-width: 120px;
    margin: 0;
}

.logout-btn:hover {
    background-color: var(--fabule-secondary-light);
    color: var(--fabule-text-dark);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15), inset 0 0 20px rgba(var(--fabule-secondary-rgb), 0.3);
    transform: translateY(-2px);
    border-color: var(--fabule-accent-1);
}

.logout-btn:active {
    transform: translateY(1px);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1), inset 0 0 10px rgba(160,140,91,0.2);
}

/* Footer with logout button */
.footer {
    position: fixed;
    bottom: 0;
    right: 0;
    padding: 15px;
    z-index: 100;
    width: auto;
    text-align: right;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.version-display {
    font-size: 0.75rem;
    color: var(--fabule-ink-red); /* Darker red for better contrast on parchment */
    opacity: 0.8; /* Increased from 0.5 */
    margin-top: 5px;
    font-family: 'Charm', cursive;
    pointer-events: none;
}

/* Logo styles */
.logo-container {
    display: flex;
    justify-content: center;
    margin-bottom: 15px;
    width: 100%; /* Ensure container takes full width */
}

/* Left-aligned smaller logo */
.logo-container.left-aligned {
    justify-content: flex-start;
    align-items: flex-start;
    text-align: left;
    margin-bottom: 10px;
}

/* Container for logo and nav buttons */
.logo-nav-container {
    display: flex;
    align-items: center;
    width: 100%;
    margin-bottom: 10px;
    gap: 15px;
}

/* Container for header buttons */
.header-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* New button for text selection */
.text-select-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 12px;
    background-color: var(--fabule-secondary-light); /* Parchment color - same as logout button */
    color: var(--fabule-text-dark); /* Dark brown ink color */
    border: 1px solid var(--fabule-secondary-dark);
    border-radius: 5px;
    font-family: 'Charm', cursive;
    font-size: 0.95rem;
    text-shadow: none;
    box-shadow: 0 3px 5px rgba(0,0,0,0.1), inset 0 0 15px rgba(160,140,91,0.2);
    transition: all 0.3s ease;
    white-space: nowrap;
    text-align: center;
    margin: 0;
}



.text-select-btn:hover, .text-select-btn:focus {
    background-color: var(--fabule-secondary-light); /* slightly darker parchment on hover */
    border-color: var(--fabule-accent-1);
    color: var(--fabule-text-dark);
    transform: translateY(-2px);
    box-shadow: 0 10px 22px rgba(0,0,0,0.12), 0 4px 8px rgba(0,0,0,0.12);
}

@media (max-width: 480px) {
    .text-select-btn {
        padding: 12px 16px;
        font-size: 1rem;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Ensure home icon button is square if it only contains an icon */
    .header-buttons .text-select-btn:has(i),
    .header-buttons .text-select-btn:has(svg) {
        min-width: 44px;
        min-height: 44px;
        padding: 8px;
    }
}

.text-select-btn:hover {
    background-color: #e8d9b0;
    color: #1a0c06;
    box-shadow: 0 4px 8px rgba(0,0,0,0.15), inset 0 0 20px rgba(160,140,91,0.3);
    transform: translateY(-2px);
    border-color: #7d6942;
}

.text-select-btn:active {
    transform: translateY(1px);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1), inset 0 0 10px rgba(160,140,91,0.2);
}

.app-logo { 
    height: 180px;
    border-radius: 5px;
    box-shadow: 0 3px 10px rgba(0,0,0,0.2);
    transition: transform 0.3s ease;
}

/* New class for smaller logo */
.small-logo {
    height: 100px !important;
}

.app-logo:hover {
    transform: scale(1.05);
}

.title-container {
    width: 100%;
    text-align: center;
    margin-bottom: 5px;
}

.custom-ask-btn {
    background-color: #5c7cfa;
    border-color: #4263eb;
}

.text-muted.fst-italic {
    color: var(--fabule-text-medium) !important;
    padding: 6px;
    border-radius: 5px;
    background-color: rgba(var(--fabule-secondary-rgb), 0.3);
    border-left: 2px solid var(--fabule-text-medium);
    line-height: 1.5;
}

.reset-inline {
    margin-left: 10px;
    align-self: center;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    vertical-align: middle;
    background-color: var(--fabule-secondary-light);
    color: var(--fabule-text-dark);
    border: 1px solid var(--fabule-secondary-dark);
    font-family: 'Charm', cursive;
}

.reset-inline:hover {
    background-color: #e8d9b0;
    color: #1a0c06;
}

#newTextButton {
    background-color: #f3e7c9; /* Match the pergamena style */
    color: #2d160e;
    border: 1px solid #a08c5b;
    font-family: 'Charm', cursive;
}

#newTextButton:hover {
    background-color: var(--fabule-secondary-light);
    color: var(--fabule-text-dark);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15), inset 0 0 20px rgba(var(--fabule-secondary-rgb), 0.3);
    transform: translateY(-2px);
    border-color: var(--fabule-accent-1);
}

/* Make sure these classes work for both buttons */
.reset-inline, .new-text-inline {
    margin-left: 10px;
    align-self: center;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    vertical-align: middle;
}

/* Add this new style for the inline buttons container */
.inline-buttons {
    display: inline-flex;
    margin-left: 10px;
    vertical-align: middle;
    gap: 5px;
}

/* Make sure both buttons appear consistently */
#resetButton, #newTextButton {
    display: none;
    background-color: #f3e7c9;
    color: #2d160e;
    border: 1px solid #a08c5b;
    font-family: 'Charm', cursive;
    transition: all 0.3s ease;
}

#resetButton:hover, #newTextButton:hover {
    background-color: var(--fabule-secondary-light);
    color: var(--fabule-text-dark);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15), inset 0 0 20px rgba(var(--fabule-secondary-rgb), 0.3);
    transform: translateY(-2px);
    border-color: var(--fabule-accent-1);
}

/* Add this new style for disabled state */
#resetButton:disabled, #newTextButton:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    background-color: var(--fabule-secondary-light);
    color: var(--fabule-text-medium);
    box-shadow: none;
}

.button-waiting {
    opacity: 0.7;
    cursor: wait;
}

.token-count {
    margin-left: 5px;
    font-size: 0.85rem;
    color: var(--fabule-text-medium);
    font-style: italic;
}

@media (max-width: 768px) {
    .button-group {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .button-group button {
        width: 100%;
    }
    
    .header-container {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .logout-btn {
        font-size: 0.9rem;
        padding: 8px 16px;
        min-width: 100px;
    }
    
    .footer {
        padding: 10px;
        width: 100%;
        text-align: center;
    }
    
    .container {
        padding-bottom: 5rem;
        max-width: 100%;
        padding-left: 10px;
        padding-right: 10px;
    }
    
    .question-buttons {
        flex-direction: column;
        gap: 8px;
    }
    
    .question-btn {
        width: 100%;
        padding: 12px;
        font-size: 1rem;
    }
    
    .file-title {
        font-size: 0.85rem;
    }
    
    .last-sentence {
        font-size: 0.8rem;
        max-height: 100px;
    }
    
    .card {
        margin-bottom: 15px;
    }
    
    .app-logo {
        height: 120px;
    }
    
    .small-logo {
        height: 80px !important;
    }
    
    h1.mb-4 {
        font-size: clamp(2rem, 6vw, 3rem);
    }

    /* Improve button display on mobile */
    .inline-buttons {
        display: flex;
        margin-top: 10px;
        margin-left: 0;
        width: 100%;
    }
    
    .inline-buttons button {
        flex: 1;
        font-size: 0.9rem;
    }

    .token-count {
        font-size: 0.8rem;
        display: inline-block;
    }

    .logo-nav-container {
        flex-direction: row;
        align-items: flex-start;
        gap: 5px;
    }
    
    .header-buttons {
        gap: 4px;
        flex-wrap: nowrap;
        margin-left: auto;
    }
    
    .text-select-btn {
        font-size: 0.85rem;
        padding: 5px 10px;
        white-space: nowrap;
    }
}

@media (max-width: 480px) {
    .app-logo {
        height: 100px;
    }
    
    .small-logo {
        height: 60px !important; /* Smaller logo on mobile */
    }
    
    .logo-container {
        flex-shrink: 0; /* Don't shrink logo */
        width: auto; /* Natural width */
    }
    
    .card-body {
        padding: 15px 10px;
    }
    
    .button-group {
        gap: 0.4rem;
    }
    
    .footer {
        bottom: 0;
        left: 0;
        right: 0;
    }
    
    .logout-btn {
        width: 100%;
    }
    
    h1.mb-4 {
        font-size: clamp(1.8rem, 5vw, 2.5rem);
    }
    
    .file-title, .last-sentence {
        padding: 5px;
    }
    
    input, select, textarea, button {
        font-size: 16px !important; /* Prevents iOS zoom on focus */
    }

    .logo-nav-container {
        flex-wrap: nowrap; /* Keep logo and buttons on same row */
        align-items: center; /* Vertically center items */
        justify-content: space-between; /* Space between logo and buttons */
    }
    
    .header-buttons {
        margin-top: 0; /* Remove top margin */
        width: auto; /* Allow natural width */
        flex-shrink: 0; /* Prevent buttons from shrinking */
    }
    
    .text-select-btn {
        font-size: 0.75rem; /* Smaller font for mobile */
        padding: 4px 6px; /* Tighter padding */
        margin-top: 0;
    }
}

/* Improve form elements touch target size */
@media (max-width: 768px) {
    input, select, button, .form-control {
        min-height: 44px;
        padding-top: 10px;
        padding-bottom: 10px;
    }
    
    .card-title {
        font-size: 1.2rem;
    }
    
    textarea.form-control {
        min-height: 80px;
    }
    
    .chat-response {
        font-size: 0.95rem;
        padding: 12px;
    }
}

/* Language Selector Styles - Updated for header position */
.language-selector {
    margin: 0;
    padding: 0;
}

/* Unified box: globe icon + select look like one widget */
.language-dropdown {
    display: inline-flex;
    align-items: center;
    gap: 0;
    background-color: var(--fabule-secondary-light);
    border: 1px solid var(--fabule-secondary-dark);
    border-radius: 5px;
    box-shadow: 0 3px 5px rgba(0,0,0,0.1);
    padding: 0 4px 0 8px;
    height: 44px;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.language-dropdown:hover {
    background-color: #e8d9b0;
}

.language-globe-icon {
    font-size: 1rem;
    color: var(--fabule-text-dark);
    pointer-events: none;
    flex-shrink: 0;
    margin-right: 5px;
}

.language-dropdown select {
    border: none;
    background: transparent;
    color: var(--fabule-text-dark);
    font-family: 'Charm', cursive;
    font-size: 0.95rem;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg fill='%232d160e' height='24' viewBox='0 0 24 24' width='24' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/><path d='M0 0h24v24H0z' fill='none'/></svg>");
    background-repeat: no-repeat;
    background-position: right 4px center;
    padding-right: 24px;
    padding-left: 0;
    height: 100%;
    outline: none;
    box-shadow: none;
    min-width: 70px;
}

.language-dropdown select:focus {
    outline: none;
}

.header-buttons .language-selector {
    margin: 0;
}

/* Mobile styling for language selector */
@media (max-width: 768px) {
    .language-selector {
        text-align: left;
        width: 100%;
    }

    .language-dropdown {
        width: 100%;
        height: 48px;
    }

    .language-dropdown select {
        width: 100%;
        font-size: 1rem;
        padding-right: 28px;
    }
    
    .header-buttons .language-selector {
        margin: 0; /* Remove margin to keep inline */
    }
}

/* Hide language text on very small screens to save space */
@media (max-width: 320px) {
    .language-dropdown {
        position: relative;
        width: auto !important;
        padding-right: 2px !important; /* Minimal padding for arrow icon */
    }
    
    .language-dropdown select {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        opacity: 0;
        z-index: 2;
    }

    .language-icons-group {
        z-index: 1;
        padding-right: 5px;
    }
}

/* File selection page styles */
.preloaded-files-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.preloaded-files-container .card {
    background-color: rgba(var(--fabule-secondary-rgb), 0.7);
    backdrop-filter: blur(5px);
    border: 1px solid var(--fabule-secondary-dark);
    transition: transform 0.2s, box-shadow 0.2s;
}

.preloaded-files-container .card:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.preloaded-files-container .card-title {
    font-family: 'Charm', cursive;
    color: #2d160e;
    font-size: 1.2rem;
    margin-bottom: 0.5rem;
}

.preloaded-files-container .card-text {
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

/* Mobile adjustments for file selection */
@media (max-width: 768px) {
    .preloaded-files-container .card {
        margin-bottom: 10px;
    }
    
    .preloaded-files-container .card-body {
        padding: 12px;
    }
}

.markdown-body {
    color: var(--fabule-text-dark);
    line-height: 1.6;
    word-wrap: break-word;
    padding: 1rem;
    background-color: var(--fabule-bg-light);
    border-radius: 5px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
    margin-top: 24px;
    margin-bottom: 16px;
    font-weight: 600;
    line-height: 1.25;
}

.markdown-body h1 { font-size: 2em; }
.markdown-body h2 { font-size: 1.5em; }
.markdown-body h3 { font-size: 1.25em; }
.markdown-body h4 { font-size: 1em; }

.markdown-body code {
    padding: 0.2em 0.4em;
    margin: 0;
    font-size: 85%;
    background-color: rgba(27,31,35,0.05);
    border-radius: 5px;
    font-family: monospace;
}

.markdown-body pre {
    overflow: auto;
    font-size: 85%;
    line-height: 1.45;
    background-color: var(--fabule-bg-medium);
    border-radius: 5px;
}

.markdown-body pre code {
    padding: 0;
    margin: 0;
    overflow: visible;
    font-size: inherit;
    word-break: normal;
    white-space: pre;
    background: transparent;
    border: 0;
}

.markdown-body blockquote {
    padding: 0 1em;
    color: var(--fabule-text-medium);
    border-left: 0.25em solid var(--fabule-secondary);
    margin: 0 0 16px 0;
}

.markdown-body ul,
.markdown-body ol {
    padding-left: 2em;
    margin-bottom: 16px;
}

.markdown-body table {
    display: block;
    width: 100%;
    overflow: auto;
    margin-bottom: 16px;
    border-spacing: 0;
    border-collapse: collapse;
}

.markdown-body table th,
.markdown-body table td {
    padding: 6px 13px;
    border: 1px solid var(--fabule-secondary-dark);
}

.markdown-body table tr:nth-child(2n) {
    background-color: var(--fabule-bg-medium);
}

.markdown-body p {
    margin-bottom: 16px;
}

.markdown-body img {
    max-width: 100%;
    box-sizing: border-box;
}

.markdown-body hr {
    height: 0.25em;
    padding: 0;
    margin: 24px 0;
    background-color: var(--fabule-secondary-dark);
    border: 0;
}

.question-controls {
    display: flex;
    flex-direction: column;
    width: 100%;
    margin-top: 10px;
}

.audio-controls {
    display: flex;
    align-items: center;
}

.audio-controls button {
    padding: 0.375rem 0.75rem;
}

/* Responsiveness for mobile */
@media (max-width: 768px) {
    .question-controls {
        margin-left: 0;
        margin-top: 10px;
        justify-content: flex-start;
        width: 100%;
    }
}



/* Stile unificato per titoli e sottotitoli nelle risposte */
.chat-response h1, 
.chat-response h2, 
.chat-response h3, 
.chat-response h4, 
.chat-response h5, 
.chat-response h6 {
    font-family: 'Charm', cursive;
    color: var(--fabule-text-dark);
    margin-top: 16px;
    margin-bottom: 12px;
    font-weight: 600;
    line-height: 1.2;
}

/* Dimensioni specifiche per ogni livello di titolo, rese meno evidenti */
.chat-response h1 { font-size: 1.5em; }
.chat-response h2 { font-size: 1.3em; }
.chat-response h3 { font-size: 1.15em; }
.chat-response h4 { font-size: 1em; }
.chat-response h5 { font-size: 0.9em; }
.chat-response h6 { font-size: 0.85em; }

/* Stile per elementi di enfasi nelle risposte */
.chat-response strong, 
.chat-response b {
    color: var(--fabule-text-dark);
    font-weight: 600;
}

/* Stile per blocchi di citazione */
.chat-response blockquote {
    border-left: 3px solid var(--fabule-secondary);
    padding-left: 15px;
    margin-left: 0;
    color: var(--fabule-text-medium);
    font-style: italic;
    background-color: rgba(var(--fabule-secondary-rgb), 0.1);
    padding: 10px 15px;
}

/* Stile per elenchi nelle risposte */
.chat-response ul,
.chat-response ol {
    padding-left: 20px;
    margin-bottom: 16px;
}

/* Margine paragrafi */

/* Header Actions Container */
.header-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    margin-left: auto; /* Push to right */
}

/* Top row: Language + Profile */
.header-top-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Stacked buttons container */
.header-stacked-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

/* Ensure all stacked buttons have same width */
.header-stacked-buttons .text-select-btn {
    width: 100%;
    text-align: left;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .header-actions {
        flex-direction: row;
        align-items: center;
        justify-content: flex-end;
        gap: 10px;
        flex: 1;
    }
    
    .header-top-row {
        gap: 8px;
    }
    
    /* Hide stacked buttons on mobile - they go in hamburger menu */
    .header-stacked-buttons {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background-color: rgba(243, 231, 201, 0.98);
        backdrop-filter: blur(10px);
        flex-direction: column;
        padding: 15px;
        gap: 10px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        border-radius: 0 0 10px 10px;
        z-index: 1000;
        margin-top: 10px;
    }
    
    /* Show stacked buttons when hamburger menu is active */
    .header-stacked-buttons.active {
        display: flex;
    }
    
    .logo-nav-container {
        flex-wrap: nowrap;
        position: relative;
    }
}

/* ============================================
   DESKTOP/TABLET HEADER LAYOUT (logo+lang left, 2×2 grid right)
   ============================================ */

/* Outer row: left col + right col + hamburger (mobile-only) */
.header-main-row {
    display: flex;
    align-items: stretch;
    width: 100%;
    gap: 16px;
    margin-bottom: 10px;
}

/* Left column: logo on top, language selector below */
.header-left-col {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    flex-shrink: 0;
}

/* Language selector below logo */
.header-lang-below {
    display: flex;
    align-items: center;
}

/* Globe icon */
.language-dropdown {
    display: flex;
    align-items: center;
    gap: 6px;
}

.language-globe-icon {
    font-size: 1.1rem;
    color: var(--fabule-text-dark);
    pointer-events: none;
    flex-shrink: 0;
}

/* Desktop: header-btn-grid is a 2×2 grid inside header-actions */
.header-btn-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

/* Desktop language selector — hidden by default, shown only on desktop */
.header-lang-desktop {
    display: none;
}

/* Each nav button: fill its cell, fixed height, centered content */
.header-nav-btn {
    width: 100%;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 8px 10px;
    font-size: 0.95rem;
}

/* Invisible placeholder keeps grid shape when "Apri Lettore" is hidden */
.header-nav-placeholder {
    height: 44px;
}

/* Mobile: header-btn-grid behaves exactly like header-stacked-buttons */
@media (max-width: 768px) {
    /* On mobile, header-btn-grid is a hidden dropdown (same as header-stacked-buttons) */
    .header-btn-grid {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        grid-template-columns: 1fr;
        background-color: rgba(243, 231, 201, 0.98);
        backdrop-filter: blur(10px);
        flex-direction: column;
        padding: 15px;
        gap: 10px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        border-radius: 0 0 10px 10px;
        z-index: 1000;
        margin-top: 10px;
    }

    .header-btn-grid.active {
        display: grid;
    }

    /* Full-width, left-aligned buttons inside dropdown */
    .header-nav-btn {
        height: 48px;
        justify-content: flex-start;
        font-size: 1rem;
        padding: 12px 16px;
    }

    /* Language selector in top bar (index.html) */
    .header-top-row .language-dropdown {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 6px;
        padding-right: 4px;
    }

    .header-top-row .language-icons-group {
        display: flex;
        align-items: center;
        gap: 4px;
    }

    .header-top-row .language-flag {
        width: 1.1rem;
        height: 0.83rem;
        border-radius: 1px;
    }

    .header-top-row .language-globe-icon {
        font-size: 1rem;
    }

    .header-top-row .language-select {
        font-size: 0.8rem;
        padding: 2px 20px 2px 4px;
    }

    /* Placeholder invisible on mobile */
    .header-nav-placeholder {
        display: none;
    }
}

/* ============================================================
   DESKTOP/TABLET HOME HEADER — 3-column layout (≥769px only)
   [ logo ] | [ 2×2 grid ] | [ lang selector tall ]
   Mobile is handled by existing hamburger-menu.css — NO CHANGES.
   ============================================================ */

@media (min-width: 769px) {

    /* Hide mobile lang selector (in header-top-row) on desktop */
    .logo-nav-container .header-top-row {
        display: none;
    }

    /* header-actions: flex row, children stretch to same height */
    .logo-nav-container .header-actions {
        display: flex;
        flex-direction: row;
        align-items: stretch;
        gap: 12px;
        flex: 1;
    }

    /* Centre: 2×3 button grid, grows to fill available space, fills from the right */
    .header-btn-grid {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr);
        grid-template-rows: 1fr 1fr;
        grid-auto-flow: column;
        direction: rtl; /* Fill items starting from the right column */
        gap: 8px;
        flex: 1;
        position: static;
        background: none;
        box-shadow: none;
        padding: 0;
        margin-top: 0;
    }

    /* Nav buttons: wider min-width, no text clipping. LTR ensures text reads correctly and icon is before text. */
    .header-nav-btn {
        display: flex;
        flex-direction: row;
        align-items: center;
        height: 44px;
        min-width: 130px;
        justify-content: center;
        font-size: 0.9rem;
        padding: 8px 12px;
        direction: ltr; /* Reset text direction to Left-to-Right */
    }

    .header-nav-placeholder {
        height: 44px;
        direction: ltr;
    }

    /* Right: tall language selector block */
    .header-lang-desktop {
        display: flex;
        align-items: stretch;
        flex-shrink: 0;
    }

    .header-lang-desktop .language-selector {
        display: flex;
        height: 100%;
    }

    .header-lang-desktop .language-dropdown {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        height: 100%;
        min-width: 90px;
        padding: 10px 6px 0 6px; /* Aggiunto padding top per abbassare il tutto */
        gap: 8px; /* Aumentato gap per allineare meglio il testo in basso */
    }

    .header-lang-desktop .language-icons-group {
        display: flex;
        align-items: center;
        gap: 6px;
        margin-bottom: 2px;
    }

    .header-lang-desktop .language-globe-icon {
        font-size: 1.2rem;
    }

    .header-lang-desktop .language-flag {
        width: 1.4rem;
        height: 1.05rem;
        border-radius: 2px;
        box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    }

    .header-lang-desktop .language-dropdown select {
        width: 100%;
        font-size: 0.85rem;
        padding-right: 20px;
        background-position: right 2px center;
    }

}

/* ============================================================
   UTILITY — classi che sostituiscono inline styles nei template
   ============================================================ */

/* Sostituisce: style="display: none;" per elementi nascosti via JS */
.hidden-by-default {
    display: none;
}

/* Sostituisce: style="opacity: 0.5; cursor: not-allowed;" per pulsanti premium disabilitati */
.btn-premium-disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Sostituisce: style="margin-top: 0;" su .version-display inline nel profilo */
.version-display-inline {
    margin-top: 0;
}

/* Sostituisce: style="flex-shrink:0;" sugli SVG inline nei bottoni navigazione */
.svg-flex-shrink {
    flex-shrink: 0;
}

/* Utility for cursor pointer */
.cursor-pointer {
    cursor: pointer;
}

/* Utility for display flex with gap and wrap (replacing multiple inlines) */
.flex-wrap-gap-10 {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

/* Small text utility */
.small-text {
    font-size: 0.8rem;
}

/* Large icon utility */
.large-icon {
    font-size: 1.3rem;
}

/* Link in modal email disclaimer */
.email-link {
    font-weight: bold;
    text-decoration: underline;
    color: var(--fabule-text-dark);
}
