/**
 * Foglio di stile principale di ilcodicefiscale.it
 * Sistema moderno, responsive, mobile-first, con Dark/Light Mode e zero dipendenze.
 * Ottimizzato per Core Web Vitals (LCP < 1.2s, CLS = 0, FID/INP < 50ms).
 */

:root {
    /* Palette Chiara (Default) */
    --bg-page: #f8fafc;
    --bg-surface: #ffffff;
    --bg-surface-elevated: #ffffff;
    --bg-input: #ffffff;
    --border-color: #e2e8f0;
    --border-focus: #00897b;

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;

    --brand-primary: #00897b;
    --brand-primary-hover: #00796b;
    --brand-primary-light: #e0f2f1;
    --brand-accent: #f59e0b;

    --status-valid-bg: #ecfdf5;
    --status-valid-text: #065f46;
    --status-valid-border: #a7f3d0;

    --status-invalid-bg: #fef2f2;
    --status-invalid-text: #991b1b;
    --status-invalid-border: #fecaca;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);

    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: "Consolas", "Courier New", monospace;

    --container-max: 1080px;
}

[data-theme="dark"] {
    /* Palette Scura */
    --bg-page: #0f172a;
    --bg-surface: #1e293b;
    --bg-surface-elevated: #334155;
    --bg-input: #0f172a;
    --border-color: #334155;
    --border-focus: #2dd4bf;

    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;

    --brand-primary: #2dd4bf;
    --brand-primary-hover: #14b8a6;
    --brand-primary-light: rgba(45, 212, 191, 0.12);
    --brand-accent: #fbbf24;

    --status-valid-bg: rgba(6, 95, 70, 0.2);
    --status-valid-text: #6ee7b7;
    --status-valid-border: rgba(110, 231, 183, 0.3);

    --status-invalid-bg: rgba(153, 27, 27, 0.2);
    --status-invalid-text: #fca5a5;
    --status-invalid-border: rgba(252, 165, 165, 0.3);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}

/* =========================================
   RESET E BASE
   ========================================= */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    overflow-x: hidden; /* Previene lo scroll orizzontale globale */
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-page);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background-color 0.25s ease, color 0.25s ease;
    overflow-x: hidden; /* Previene lo scroll orizzontale su mobile */
}

a {
    color: var(--brand-primary);
    text-decoration: none;
    transition: color 0.2s ease;
}
a:hover {
    color: var(--brand-primary-hover);
    text-decoration: underline;
}

/* =========================================
   LAYOUT CONTAINER
   ========================================= */
.container {
    width: 100%;
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 0 16px;
}

/* =========================================
   HEADER E NAVIGAZIONE
   ========================================= */
.site-header {
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
    transition: background-color 0.25s ease, border-color 0.25s ease;
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
}

.logo-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    font-size: 1.25rem;
    color: var(--text-primary);
    text-decoration: none;
}
.logo-wrapper:hover {
    text-decoration: none;
}

.logo-icon {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    background: var(--brand-primary);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: 18px;
    box-shadow: 0 2px 6px rgba(0, 137, 123, 0.35);
}

.main-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-link {
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.925rem;
    transition: background-color 0.2s, color 0.2s;
}
.nav-link:hover, .nav-link.active {
    background-color: var(--brand-primary-light);
    color: var(--brand-primary);
    text-decoration: none;
}

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

.theme-toggle-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    width: 38px;
    height: 38px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    transition: background-color 0.2s, border-color 0.2s;
}
.theme-toggle-btn:hover {
    background-color: var(--border-color);
}

/* Selettore Lingua */
.lang-dropdown-container {
    position: relative;
}

.lang-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
}

.lang-menu {
    position: absolute;
    right: 0;
    top: 100%;
    margin-top: 6px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: none;
    flex-direction: column;
    min-width: 140px;
    padding: 6px;
    z-index: 110;
}
.lang-dropdown-container:hover .lang-menu {
    display: flex;
}
.lang-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 500;
}
.lang-item:hover {
    background-color: var(--brand-primary-light);
    color: var(--brand-primary);
    text-decoration: none;
}

@media (max-width: 768px) {
    .main-nav {
        display: none; /* Mobile menu o tab bar */
    }
}

/* =========================================
   MOBILE TAB BAR (NAVIGAZIONE MOBILE)
   ========================================= */
.mobile-tabs {
    display: none;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    padding: 8px 16px;
    overflow-x: auto;
    white-space: nowrap;
    gap: 8px;
}
@media (max-width: 768px) {
    .mobile-tabs {
        display: flex;
    }
}
.mobile-tab-item {
    padding: 6px 14px;
    border-radius: var(--radius-full);
    font-size: 0.85rem;
    font-weight: 600;
    background: var(--bg-page);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}
.mobile-tab-item.active {
    background: var(--brand-primary);
    color: #ffffff;
    border-color: var(--brand-primary);
}

/* =========================================
   HERO / TITOLO PAGINA
   ========================================= */
.hero-section {
    text-align: center;
    padding: 32px 0 20px;
}
.hero-title {
    font-size: 2.1rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.5px;
    line-height: 1.25;
}
.hero-subtitle {
    font-size: 1.05rem;
    color: var(--text-secondary);
    margin-top: 8px;
    max-width: 680px;
    margin-left: auto;
    margin-right: auto;
}

@media (max-width: 600px) {
    .hero-title {
        font-size: 1.6rem;
    }
    .hero-subtitle {
        font-size: 0.95rem;
    }
}

/* =========================================
   GRIGLIA PRINCIPALE (FORM + RISULTATO/TESSERA)
   ========================================= */
.calculator-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
    margin: 20px 0 40px;
    align-items: start;
    /* Impedisce ai figli della grid di espandersi oltre la larghezza allocata */
    width: 100%;
}

/* Tutti i figli diretti della grid: min-width: 0 è essenziale per evitare
   che il contenuto (es. testo nowrap, tessera fissa) espanda la cella oltre 1fr */
.calculator-grid > * {
    min-width: 0;
}

@media (max-width: 900px) {
    .calculator-grid {
        grid-template-columns: 1fr;
        gap: 24px;
    }
}

/* Variante per la pagina CF Inverso: colonne leggermente asimmetriche su desktop */
.calculator-grid--inverso {
    grid-template-columns: 1.1fr 0.9fr;
}

@media (max-width: 900px) {
    .calculator-grid--inverso {
        grid-template-columns: 1fr;
    }
}

/* Card Contenitore */
.cf-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-md);
    transition: background-color 0.25s ease, border-color 0.25s ease;
}

/* =========================================
   FORM E CONTROLLI INPUT
   ========================================= */
.form-group {
    margin-bottom: 18px;
    position: relative;
}

.form-label {
    display: block;
    font-weight: 700;
    font-size: 0.875rem;
    color: var(--text-primary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.form-control {
    width: 100%;
    height: 48px;
    padding: 10px 14px;
    font-size: 1rem;
    font-family: inherit;
    color: var(--text-primary);
    background-color: var(--bg-input);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
}
.form-control:focus {
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px var(--brand-primary-light);
}

.form-control.uppercase {
    text-transform: uppercase;
}

/* Griglia per Data di Nascita */
.date-inputs-row {
    display: grid;
    grid-template-columns: 1fr 1.3fr 1.1fr;
    gap: 8px;
}

/* Toggle Sesso Maschio / Femmina */
.sex-toggle-wrapper {
    display: flex;
    gap: 10px;
}
.sex-option {
    flex: 1;
    position: relative;
}
.sex-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}
.sex-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 46px;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}
.sex-option input[type="radio"]:checked + .sex-btn.male {
    background-color: #0284c7;
    border-color: #0284c7;
    color: #ffffff;
}
.sex-option input[type="radio"]:checked + .sex-btn.female {
    background-color: #e11d48;
    border-color: #e11d48;
    color: #ffffff;
}

/* =========================================
   AUTOCOMPLETE DROPDOWN
   ========================================= */
.autocomplete-wrapper {
    position: relative;
}

.autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 4px;
    background-color: var(--bg-surface);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    max-height: 250px;
    overflow-y: auto;
    z-index: 150;
    display: none;
}
.autocomplete-dropdown.open {
    display: block;
}

.autocomplete-item {
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.925rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background-color 0.15s ease;
}
.autocomplete-item:last-child {
    border-bottom: none;
}
.autocomplete-item:hover, .autocomplete-item.active {
    background-color: var(--brand-primary-light);
    color: var(--brand-primary);
}
.badge-prov {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-left: 4px;
}
.badge-code {
    background: var(--border-color);
    color: var(--text-secondary);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 700;
}

/* =========================================
   DISPLAY RISULTATO CODICE FISCALE
   ========================================= */
.cf-result-box {
    background: var(--bg-surface-elevated);
    border: 2px solid var(--brand-primary);
    border-radius: var(--radius-md);
    padding: 14px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 16px 0;
    max-width: 100%;     /* Non supera mai il contenitore padre */
    overflow: hidden;    /* Taglia qualsiasi contenuto interno che sfora */
}

.cf-result-text {
    font-family: var(--font-mono);
    font-size: 1.65rem;
    font-weight: 800;
    letter-spacing: 2px;
    color: var(--brand-primary);
    white-space: nowrap;
    overflow-x: auto;
    text-transform: uppercase;
    min-width: 0;        /* Consente all'elemento flex di restringersi */
    flex: 1 1 0;         /* Prende lo spazio disponibile, può restringersi */
}

@media (max-width: 480px) {
    .cf-result-text {
        font-size: 1.25rem;
        letter-spacing: 1px;
    }
}

/* Pulsanti Generici */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 44px;
    padding: 0 18px;
    font-size: 0.95rem;
    font-weight: 700;
    border-radius: var(--radius-md);
    cursor: pointer;
    border: none;
    transition: background-color 0.2s, transform 0.1s;
}
.btn:active {
    transform: scale(0.98);
}
.btn-primary {
    background-color: var(--brand-primary);
    color: #ffffff;
}
.btn-primary:hover {
    background-color: var(--brand-primary-hover);
    color: #ffffff;
    text-decoration: none;
}
.btn-secondary {
    background-color: var(--bg-page);
    color: var(--text-primary);
    border: 1.5px solid var(--border-color);
}
.btn-secondary:hover {
    background-color: var(--border-color);
    text-decoration: none;
}

/* Badge di stato */
.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    font-size: 0.8rem;
    font-weight: 700;
}
.status-badge.valid {
    background: var(--status-valid-bg);
    color: var(--status-valid-text);
    border: 1px solid var(--status-valid-border);
}
.status-badge.invalid {
    background: var(--status-invalid-bg);
    color: var(--status-invalid-text);
    border: 1px solid var(--status-invalid-border);
}
.status-badge.incomplete {
    background: var(--bg-page);
    color: var(--text-muted);
    border: 1px solid var(--border-color);
}

/* =========================================
   SEZIONE FAQ (DOMANDE FREQUENTI PER LA SEO)
   ========================================= */
.faq-section {
    margin: 48px 0 32px;
}
.faq-heading {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 20px;
    text-align: center;
}
.faq-accordion {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.faq-item {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: border-color 0.2s;
}

.faq-question {
    width: 100%;
    text-align: left;
    padding: 16px 20px;
    background: transparent;
    border: none;
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--text-primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}
.faq-question::after {
    content: '+';
    font-size: 1.4rem;
    font-weight: 400;
    color: var(--brand-primary);
    transition: transform 0.25s ease;
}
.faq-item.open .faq-question::after {
    transform: rotate(45deg);
}

.faq-answer {
    padding: 0 20px 16px;
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.6;
    display: none;
}
.faq-item.open .faq-answer {
    display: block;
}

/* =========================================
   FOOTER
   ========================================= */
.site-footer {
    background-color: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    padding: 32px 0 24px;
    margin-top: auto;
    font-size: 0.875rem;
    color: var(--text-muted);
    text-align: center;
}
.footer-disclaimer {
    max-width: 720px;
    margin: 0 auto 16px;
    line-height: 1.5;
}
.footer-links {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-bottom: 12px;
}

/* =========================================
   TOAST E MODAL
   ========================================= */
.cf-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: #1e293b;
    color: #ffffff;
    padding: 12px 20px;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.925rem;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.25s ease, transform 0.25s ease;
    pointer-events: none;
}
.cf-toast.show {
    opacity: 1;
    transform: translateY(0);
}
.cf-toast.warning { background: #d97706; }
.cf-toast.error   { background: #dc2626; }

.cf-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 999;
    padding: 16px;
}
.cf-modal.active {
    display: flex;
}
.cf-modal-dialog {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 480px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}
.cf-modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.cf-modal-body {
    padding: 16px 20px;
    overflow-y: auto;
}
.possibilita-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.possibilita-list li {
    padding: 8px 12px;
    background: var(--bg-page);
    border-radius: var(--radius-sm);
    font-weight: 600;
}
