/* ================================================= */
/* --- DEFINIZIONE VARIABILI E STILI DI BASE --- */
/* ================================================= */

:root {
  /* Valori di fallback */
  --primary-color: #143c6a;
  --primary-color-rgb: 20, 60, 106;
  --secondary-color: #009460;
  --secondary-color-rgb: 0, 148, 96;
  --accent-color: #058ED9;
  --accent-color-rgb: 5, 142, 217;

  --focus-shadow-color: rgba(var(--accent-color-rgb), 0.25);
}

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

a {
  text-decoration: none;
  color: var(--accent-color);
  transition: color 0.3s ease;
}

a:hover {
    color: color-mix(in srgb, var(--accent-color) 85%, black);
    text-decoration: underline;
}


body {
    font-family: 'Inter', sans-serif;
    background-color: #ffffff;
    color: #333;
    line-height: 1.6;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Stili per il loader principale dell'applicazione */
.app-loader-container {
  display: flex;
  justify-content: center;
  align-items: center;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: #ffffff; /* Sfondo bianco per coprire il contenuto sotto */
  z-index: 9999;
}

/* Animazione dello spinner */
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Stile base dello spinner (puoi riutilizzarlo anche per quello della ricerca) */
.spinner {
  border: 5px solid #f3f3f3; /* Grigio chiaro */
  border-top: 5px solid var(--primary-color, #3498db); /* Usa il colore primario se definito, altrimenti un blu di default */
  border-radius: 50%;
  width: 50px;
  height: 50px;
  animation: spin 1s linear infinite;
}



/* Stile per il bottone Indietro Fisso */
.back-button {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 1001;
    color: white;
    font-size: 1.6rem;
    padding: 10px;
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 50%;
    width: 45px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s ease, transform 0.2s ease;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.back-button:hover {
    background-color: rgba(0, 0, 0, 0.4);
}

.back-button:active {
    transform: scale(0.95);
}

.logo-ms-container {
  background-color: #FFF;
  padding:10px;
  width: 100%;
}

.logo-ms {
    background-color: #FFF;
    background-image: var(--logo-url);
    background-position: center center;
    background-size: contain;
    background-repeat: no-repeat;
    color: white;
    width: 100%;
    min-height: var(--logo-height);
    text-align: center;
    position: relative;
}

.container {
    max-width: 800px;
    width: 100%;
    background-color: #ffffff;
    padding: 30px 40px;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
}

.header-wrapper {
  padding: 20px 15px 0 15px;
}

.container.sticky {
  padding: 0;
  margin: 0;
  position: sticky;
  top: 0;
  z-index: 5;
}

h2 {
  margin-bottom: 5px;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 20px;
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 10px;
    color: var(--primary-color);
}

.header h1 {
    color: #2c3e50;
    margin-bottom: 10px;
    font-weight: 700;
}

.header p {
    color: var(--primary-color);
    font-size: 0.95em;
}

/* Wrapper per search box */
.search-box-wrapper {
    margin-bottom: 12px;
}

/* Search Box */
.search-box {
    display: flex;
    align-items: center;
    position: relative;
    margin-bottom: 15px;
    gap: 8px;
}

#queryInput {
    flex-grow: 1;
    padding: 12px 40px 12px 12px;
    font-size: 1em;
    border: 1px solid #ccc;
    border-radius: 8px;
    resize: none;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    font-family: 'Inter', sans-serif;
}

#queryInput:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px var(--focus-shadow-color);
}

/* Bottone Clear Dentro l'Input */
.clear-button {
    position: absolute;
    top: 50%;
    right: 110px;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 1.2rem;
    color: #aaa;
    cursor: pointer;
    padding: 5px;
    transition: color 0.3s ease;
    z-index: 2;
}

.clear-button:hover {
    background-color: #f0f0f0;
    color: #666;
    border-color: #aaa;
}

.clear-button:active {
    background-color: #e0e0e0;
}

.clear-button i {
    display: block;
}

.clear-button.hidden {
    display: none;
}

#searchButton {
    padding: 12px 25px;
    font-size: 1em;
    font-weight: 500;
    color: #fff;
    background-color: var(--primary-color);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.1s ease;
    flex-shrink: 0;
    z-index: 1;
}

#searchButton:hover {
    background-color: color-mix(in srgb, var(--primary-color) 85%, black);
}

#searchButton:active {
    transform: scale(0.98);
}

#searchButton:disabled {
    background-color: #bdc3c7;
    cursor: not-allowed;
}

/* Loading Indicator */
.loading-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    text-align: center;
    color: #555;
    margin-bottom: 20px;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--focus-shadow-color);
    border-top-color: var(--accent-color); /* Usa accent-color per l'interazione */
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 10px;
}

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

/* Error Message */
.error-message {
    background-color: #f8d7da;
    color: #721c24;
    padding: 15px;
    border: 1px solid #f5c6cb;
    border-radius: 8px;
    margin-bottom: 20px;
    text-align: center;
}

/* Results Container */
.results-container {
    padding-top: 5px;
    flex-grow: 1;
}

.category-group {
  border: 1px solid #e0e0e0;
  margin-bottom: 15px;
  border-radius: 5px;
}

.category-header {
  background-color: #f7f7f7;
  padding: 12px 15px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #e0e0e0;
  position: sticky;
  z-index: 2;
  top: calc(var(--containerSticky-height)) !important;
}

.category-group.open .category-header {
   border-bottom-color: transparent;
}

.category-title-text {
  margin: 0;
  font-size: 1.2em;
  color: var(--primary-color);
}

.category-toggle-icon {
  font-size: 0.9em;
  color: #555;
  transition: transform 0.2s ease-in-out;
}

.category-questions-wrapper {
  padding: 0px 15px 15px 15px;
  background-color: #fff;
}

.category-questions-wrapper .result-item {
  margin-top: 15px;
  border-bottom: 1px dashed #eee;
  padding-bottom: 15px;
}
.category-questions-wrapper .result-item:last-child {
  border-bottom: none;
  padding-bottom: 5px;
}
.category-questions-wrapper .result-item:first-child {
  margin-top: 5px;
}

.results-description {
    margin-bottom: 20px;
    padding: 12px 16px;
    background-color: #f8f9fa;
    border-left: 3px solid var(--accent-color); /* Accent color per dettaglio UI */
    border-radius: 4px;
}

.results-description p {
    margin: 0;
    font-size: 14px;
    color: #6c757d;
    line-height: 1.4;
}

.result-item {
    background-color: #f9f9f9;
    border: 1px solid #d3d3d3;
    border-radius: 8px;
    padding: 20px 15px 10px 15px;
    margin-bottom: 20px;
    transition: box-shadow 0.3s ease;
    opacity: 0;
    transform: translateY(10px);
    animation: fadeIn 0.5s ease forwards;
    box-shadow: 0 2px 5px rgba(0, 0, 0, .4);
    position: relative; /* Necessario per il posizionamento dello score */
}

.result-item ul {
    margin-right: 15px;
}

.result-item ol {
    list-style: none;
    counter-reset: item;
    margin-top: 10px;
    margin-bottom: 10px;
}
.result-item ol li {
   counter-increment: item;
   margin-bottom: 5px;
}

.result-item ul li {
  margin-left: 18px;
  margin-bottom: 5px;
}

.result-item ol li:before {
    margin-right: 7px;
    content: counter(item);
    background: var(--accent-color); /* Accent color per dettaglio UI */
    border-radius: 100%;
    color: white;
    font-size: 13px;
    width: 1.5em;
    text-align: center;
    display: inline-block;
}

.result-item:hover {
   box-shadow: 0 5px 15px rgba(0, 0, 0, 0.07);
}

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

.result-item:nth-child(1) { animation-delay: 0.1s; margin-top: 20px !important;}
.result-item:nth-child(2) { animation-delay: 0.2s; }
.result-item:nth-child(3) { animation-delay: 0.3s; }
.result-item:nth-child(4) { animation-delay: 0.4s; }
.result-item:nth-child(5) { animation-delay: 0.5s; }

.result-item h3 {
    color: var(--accent-color); /* Titolo del risultato è un elemento interattivo/chiave */
    margin-bottom: 8px;
    font-size: 1.1em;
    font-weight: 500;
}

.result-item .answer {
    color: var(--primary-color);
    margin-bottom: 15px;
    font-size: 0.95em;
}

.result-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85em;
    color: #777;
    border-top: 1px dashed #b7b7b7;
    padding-top: 10px;
}

.result-score {
    position: absolute;
    font-size: 12px;
    right: 0;
    top: 0;
    transform: translate(1px, -50%); /* Leggero aggiustamento per allineamento */
    font-weight: 500;
    padding: 3px 8px;
    border-radius: 4px 0 4px 4px;
    color: #333;
    margin-right: 8px;
}

/* Uso dei colori semantici per lo score */
.result-score.high { background-color: var(--secondary-color); color: white; } /* Verde per alta rilevanza */
.result-score.medium { background-color: #f1c40f; color: #333; }
.result-score.low { background-color: #c63b2c; color: white; }

.result-match-source span {
     margin-right: 15px;
}

.result-match-source strong {
    font-weight: 500;
    color: #555;
}

.no-results {
    text-align: center;
    color: #777;
    padding: 30px;
    font-style: italic;
}

/* Footer */
.footer {
    text-align: center;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #e0e0e0;
    font-size: 0.8em;
    color: #888;
}

/* Stili per le domande di esempio */
.example-questions-container {
     padding: 0 10px;
     border-radius: 8px;
}

.example-heading {
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--primary-color);
    margin-bottom: 4px;
    padding-left: 5px;
}

.example-question-item {
    background-color: rgba(var(--primary-color-rgb), 0.1);
    padding: 10px 15px;
    margin-bottom: 10px;
    border-radius: 20px;
    cursor: pointer;
    transition: background-color 0.3s ease, box-shadow 0.3s ease, color 0.3s ease;
    font-size: 0.95rem;
    color: var(--primary-color);
    display: block;
    text-align: left;
    border: 1px solid rgba(var(--primary-color-rgb), 0.25);
}

.example-question-item:hover {
    background-color: rgba(var(--secondary-color-rgb), 0.15); /* Feedback positivo al passaggio del mouse */
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    color: var(--secondary-color);
    border-color: rgba(var(--secondary-color-rgb), 0.4);
}

/* Responsive Design */
@media (max-width: 600px) {
    body {
      padding: 0 0 70px;
    }
    .container {
        padding: 10px 15px;
        width: 100%;
        margin: 0 0 0 0;
        border-radius: 0;
    }
    #queryInput {
        padding: 12px 35px 12px 12px;
        font-size: 0.95em;
        color: var(--primary-color);
        height: auto;
        min-height: 2.8em;
        max-height: 5.6em;
        line-height: 1.4;
        resize: none;
        font-family: 'Inter', sans-serif;
        overflow-y: hidden;
        transition: height 0.2s ease;
        box-sizing: border-box;
        display: flex;
        align-items: center;
    }
    .clear-button {
         right: 90px;
         font-size: 1.1rem;
    }
     #searchButton {
        padding: 12px 18px;
        font-size: 0.95em;
    }
    .result-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
}

.bottom-nav {
    background: white;
    display: flex;
    justify-content: space-around;
    padding: 12px 0;
    position: fixed;
    bottom: 0;
    width: 100%;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    z-index: 1000;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: #999;
    font-size: 0.7rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.nav-item.active {
    color: var(--secondary-color); /* Verde per indicare lo stato attivo */
}

.nav-item i {
    font-size: 1.3rem;
    margin-bottom: 2px;
}

.activity-link-wrapper {
    display: flex;
    border-radius: 15px;
    overflow: hidden;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    border: 1px solid #e8e8e8;
}

.nav-link-wrapper {
  display: flex;
}

/* Gestione zoom immagini */
body.lightbox-open {
  overflow: hidden;
}

.zoomable-image {
  cursor: zoom-in;
  height: auto;
  display: inline-block;
  margin-bottom: 10px;
}

.lightbox-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 15px;
  box-sizing: border-box;
  overflow-y: auto;
}

.lightbox-overlay img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  margin: auto;
}

.lightbox-close {
  position: absolute;
  top: 15px;
  right: 25px;
  color: white;
  font-size: 35px;
  font-weight: bold;
  cursor: pointer;
  z-index: 1001;
}

.lightbox-close:hover {
  color: #bbb;
}
