/* ===== RESET & BASE ===== */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    min-width: 0;
    font-family: "Segoe UI", Roboto, Arial, sans-serif;
    background-color: #f8f9fb;
    color: #333;
}

/* ===== HEADER ===== */
header {
    background: linear-gradient(135deg, #1e3a8a, #3b82f6);
    color: white;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 1.1rem 1.4rem;
    gap: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    position: relative;
}

header h1 {
    /* Centrato rispetto all'intera larghezza dell'header, non allo spazio rimanente */
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    margin: 0;
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    text-shadow: 0 1px 6px rgba(0, 0, 0, 0.25);
    white-space: nowrap;
    pointer-events: none;
}

/* Gruppo destra: link preferiti + pulsante aggiorna */
.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.header-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: white;
    font-weight: 700;
    font-size: 0.84rem;
    text-decoration: none;
    white-space: nowrap;
    background: linear-gradient(135deg, #e11d48, #f43f5e);
    padding: 8px 16px;
    border-radius: 999px;
    box-shadow: 0 2px 8px rgba(225, 29, 72, 0.45);
    letter-spacing: 0.03em;
    transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
}

.header-link:hover {
    background: linear-gradient(135deg, #be123c, #e11d48);
    transform: scale(1.05);
    box-shadow: 0 4px 14px rgba(225, 29, 72, 0.55);
    text-decoration: none;
}

#btn-update {
    padding: 9px 18px;
    cursor: pointer;
    background-color: #F6863B;
    color: white;
    border: none;
    border-radius: 6px;
    font-weight: 700;
    font-size: 0.82rem;
    white-space: nowrap;
    transition: background-color 0.2s, box-shadow 0.2s;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

#btn-update:hover {
    background-color: #e0721f;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
}

/* ===== LAST UPDATE ===== */
#last-db-update {
    text-align: center;
    margin: 10px 0 6px;
    color: #444;
    font-size: 0.88rem;
}

/* ===== FILTRI ===== */
#filters {
    background-color: white;
    padding: 14px 18px;
    margin: 0 1rem 12px 1rem;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

#filters input[type="text"] {
    padding: 7px 11px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.88rem;
    min-width: 110px;
    flex: 1 1 110px;
    max-width: 180px;
    transition: border-color 0.15s;
}

#filters input[type="text"]:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

#filters input[type="checkbox"] {
    margin-right: 5px;
    accent-color: #3b82f6;
}

#filters label {
    display: flex;
    align-items: center;
    font-size: 0.88rem;
    white-space: nowrap;
    color: #444;
}

#filters button {
    padding: 7px 16px;
    background-color: #3b82f6;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 700;
    font-size: 0.88rem;
    white-space: nowrap;
    transition: background-color 0.2s;
}

#filters button:hover {
    background-color: #2563eb;
}

/* ===== LOG AGGIORNAMENTO ===== */
#risultato {
    background-color: #1e293b;
    color: #10b981;
    padding: 14px;
    margin: 0 1rem 12px 1rem;
    border-radius: 8px;
    font-family: monospace;
    font-size: 0.88rem;
    white-space: pre-wrap;
    max-height: 260px;
    overflow-y: auto;
    display: none;
}

#risultato:not(:empty) {
    display: block;
}

/* ===== MAIN ===== */
main {
    margin: 0 1rem 3rem 1rem;
}

/* ===== TABELLA WRAPPER ===== */
.table-wrapper {
    width: 100%;
    overflow-x: auto;
    overflow-y: visible;
    border-radius: 10px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.09);
    background-color: white;
    -webkit-overflow-scrolling: touch;
}

/* ===== TABELLA ===== */
.styled-table {
    width: 100%;
    min-width: 760px;
    border-collapse: collapse;
    font-size: 0.84rem;
    background-color: white;
    table-layout: fixed;
}

.styled-table th:nth-child(1) {
    width: 5%;
}

.styled-table th:nth-child(2) {
    width: 17%;
}

.styled-table th:nth-child(3) {
    width: 10%;
}

.styled-table th:nth-child(4) {
    width: 10%;
}

.styled-table th:nth-child(5) {
    width: 14%;
}

.styled-table th:nth-child(6) {
    width: 10%;
}

.styled-table th:nth-child(7) {
    width: 7%;
}

.styled-table th:nth-child(8) {
    width: 13%;
}

.styled-table th:nth-child(9) {
    width: 14%;
}

.styled-table thead tr {
    background-color: #2563eb;
    color: white;
    text-align: left;
}

.styled-table th {
    padding: 11px 10px;
    vertical-align: middle;
    background-color: #2563eb;
    color: white;
    font-weight: 700;
    font-size: 0.74rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

th.sortable {
    cursor: pointer;
    user-select: none;
    transition: background-color 0.15s;
}

th.sortable:hover {
    background-color: #1d4ed8;
}

th.sortable::after {
    content: " ↕";
    opacity: 0.35;
    font-size: 0.68rem;
}

th.sortable.sort-asc::after {
    content: " ↑";
    opacity: 1;
}

th.sortable.sort-desc::after {
    content: " ↓";
    opacity: 1;
}

.styled-table td {
    padding: 10px;
    vertical-align: middle;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border-bottom: 1px solid #e5e7eb;
}

.styled-table tbody tr:last-child td {
    border-bottom: none;
}

.styled-table tbody tr:nth-of-type(even) {
    background-color: #f9fafb;
}

.styled-table tbody tr:hover {
    background-color: #dbeafe;
}

.styled-table td.expandable {
    cursor: pointer;
    color: #1e40af;
    font-style: italic;
}

.styled-table td.expandable:hover {
    text-decoration: underline;
    color: #3b82f6;
}

.styled-table a {
    color: #3b82f6;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.82rem;
}

.styled-table a:hover {
    text-decoration: underline;
}

/* ===== NESSUN DATO ===== */
.no-data {
    text-align: center;
    padding: 4rem 2rem;
    font-size: 1.1rem;
    color: #888;
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.07);
}

/* ===== PAGINAZIONE ===== */
.pagination-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin-top: 14px;
    padding: 14px 20px;
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.pagination-controls button {
    padding: 9px 22px;
    border: none;
    background-color: #3b82f6;
    color: white;
    cursor: pointer;
    border-radius: 6px;
    font-weight: 700;
    font-size: 1rem;
    transition: background-color 0.15s, transform 0.15s;
    min-width: 50px;
}

.pagination-controls button:hover:not(:disabled) {
    background-color: #2563eb;
    transform: scale(1.04);
}

.pagination-controls button:disabled {
    background-color: #bfdbfe;
    cursor: not-allowed;
    opacity: 0.7;
}

.pagination-controls span {
    font-weight: 600;
    font-size: 0.92rem;
    color: #444;
}

/* ===== MODAL ===== */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideIn {
    from {
        transform: translateY(-40px);
        opacity: 0;
    }

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

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.45);
    animation: fadeIn 0.25s;
}

.modal-content {
    background-color: white;
    margin: 6% auto;
    padding: 28px 32px;
    border-radius: 12px;
    width: 88%;
    max-width: 680px;
    max-height: 78vh;
    overflow-y: auto;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
    animation: slideIn 0.25s;
}

.modal-content h2 {
    color: #1e3a8a;
    margin-top: 0;
    margin-bottom: 16px;
    font-size: 1.1rem;
}

.modal-content p {
    line-height: 1.65;
    color: #333;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 0.95rem;
}

.close {
    color: #bbb;
    float: right;
    font-size: 26px;
    font-weight: bold;
    line-height: 18px;
    cursor: pointer;
    transition: color 0.15s;
}

.close:hover {
    color: #333;
}

/* ===== CARD MOBILE (nascoste su desktop) ===== */
.lotto-cards {
    display: none;
}

.lotto-card {
    background-color: white;
    border-radius: 12px;
    border: 3px solid #cbd5e1;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    background: linear-gradient(135deg, #1e3a8a, #3b82f6);
    gap: 8px;
}

.card-prezzo {
    color: white;
    font-weight: 800;
    font-size: 1.05rem;
}

.card-badge {
    background-color: rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 3px 9px;
    border-radius: 20px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 55%;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* ogni riga della card è un .card-field con bordo inferiore spesso */
.card-body {
    padding: 0;
}

.card-field {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 10px 14px;
    border-bottom: 2px solid #e2e8f0;
    gap: 12px;
}

.card-field:last-child {
    border-bottom: none;
}

.card-label {
    font-size: 0.72rem;
    font-weight: 700;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    white-space: nowrap;
    flex-shrink: 0;
}

.card-value {
    font-size: 0.9rem;
    color: #1f2937;
    text-align: right;
    word-break: break-word;
}

.card-value.desc.expandable {
    color: #1e40af;
    font-style: italic;
    cursor: pointer;
    text-align: left;
}

.card-footer {
    padding: 12px 14px;
    border-top: 3px solid #cbd5e1;
    background-color: #f1f5f9;
}

.card-link {
    display: block;
    text-align: center;
    padding: 10px 16px;
    background-color: #2563eb;
    color: white;
    border-radius: 8px;
    font-weight: 700;
    font-size: 0.9rem;
    text-decoration: none;
}

.card-link:active {
    background-color: #1d4ed8;
}

.cards-empty {
    text-align: center;
    padding: 3rem 1rem;
    font-size: 1rem;
    color: #888;
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.07);
}

/* ===== PREFERITI (cuore SVG) ===== */
.fav-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0; /* Padding gestito dalla cella o rimosso per centramento totale */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
    width: 100%;
    height: 100%;
    min-height: 42px; /* Assicura altezza minima per il tocco e il centramento */
}

.fav-icon {
    width: 17px;
    height: 17px;
    /* Default: solo contorno, riempimento trasparente */
    fill: none;
    stroke: #9ca3af;
    stroke-width: 2.5px; /* Stroke leggermente più spesso per visibilità alla dimensione ridotta */
    transition: fill 0.25s ease, stroke 0.25s ease;
    display: block;
}

.fav-btn.active .fav-icon {
    fill: #e74c3c;
    stroke: #e74c3c;
}

.fav-btn:hover .fav-icon {
    stroke: #e74c3c;
}

.fav-btn:hover {
    transform: scale(1.2);
}

/* ===== FOOTER ===== */
footer {
    text-align: center;
    padding: 1.4rem;
    background-color: #e5e7eb;
    color: #666;
    font-size: 0.85rem;
    border-top: 1px solid #d1d5db;
    margin-top: 2rem;
}

/* ===== TABLET (769–1100px) ===== */
@media screen and (min-width: 769px) and (max-width: 1100px) {
    .styled-table {
        font-size: 0.78rem;
    }

    .styled-table th,
    .styled-table td {
        padding: 9px 7px;
    }
}

/* ===== MOBILE (≤768px) ===== */
@media screen and (max-width: 768px) {

    html,
    body {
        overflow-x: hidden;
        width: 100%;
    }

    /* Nascondi tabella, mostra card */
    #table-wrapper {
        display: none;
    }

    .lotto-cards {
        display: flex;
        flex-direction: column;
        gap: 16px;
    }

    /* Header mobile: colonna centrata */
    header {
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 1rem;
        gap: 10px;
        text-align: center;
    }

    /* Su mobile h1 torna nel flusso normale */
    header h1 {
        position: static;
        transform: none;
        font-size: 1.2rem;
        white-space: normal;
        text-align: center;
        pointer-events: auto;
    }

    .header-actions {
        flex-direction: column;
        align-items: center;
        gap: 8px;
        width: 100%;
    }

    .header-link {
        font-size: 0.9rem;
    }

    #btn-update {
        width: 100%;
        max-width: 280px;
        text-align: center;
        font-size: 0.88rem;
    }

    /* Filtri: colonna unica */
    #filters {
        flex-direction: column;
        align-items: stretch;
        margin: 8px 0.4rem;
        gap: 7px;
        padding: 12px;
    }

    #filters input[type="text"] {
        max-width: 100%;
        width: 100%;
        flex: none;
    }

    #filters button {
        width: 100%;
        padding: 10px;
        font-size: 0.92rem;
    }

    main {
        margin: 0 0.4rem 2rem 0.4rem;
    }

    /* Paginazione compatta */
    .pagination-controls {
        padding: 10px 8px;
        gap: 8px;
        margin-top: 10px;
        flex-wrap: wrap;
    }

    .pagination-controls button {
        padding: 9px 18px;
        font-size: 0.92rem;
        min-width: 44px;
    }

    .pagination-controls span {
        font-size: 0.82rem;
    }

    /* Modal quasi full screen */
    .modal-content {
        margin: 8% auto;
        width: 94%;
        padding: 20px;
        max-height: 84vh;
    }
}

/* Adattamento colonne tabella desktop */
.styled-table th:nth-child(9) {
    width: 12%;
}

.styled-table th:nth-child(10) {
    width: 5%;
    text-align: center;
}

/* Centramento cella preferiti — fix iPad */
.styled-table td:last-child {
    text-align: center;
    vertical-align: middle;
    padding: 0;
    width: 50px; /* Larghezza fissa per la colonna preferiti per evitare spostamenti */
}

/* Card mobile: cuore più grande */
.lotto-card .fav-icon {
    width: 28px;
    height: 28px;
}

/* ===== REPORT BUTTON ===== */
.report-btn {
    background: linear-gradient(135deg, #059669, #10b981);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 5px 10px;
    font-size: 0.72rem;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
    box-shadow: 0 1px 4px rgba(5, 150, 105, 0.3);
    letter-spacing: 0.02em;
}

.report-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #047857, #059669);
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(5, 150, 105, 0.45);
}

.report-btn:disabled {
    cursor: wait;
    opacity: 0.7;
}

.report-btn.loading {
    background: linear-gradient(135deg, #6b7280, #9ca3af);
    animation: pulse-report 1.2s ease-in-out infinite;
}

.report-btn.done {
    background: linear-gradient(135deg, #2563eb, #60a5fa);
}

.report-btn.error {
    background: linear-gradient(135deg, #dc2626, #f87171);
}

@keyframes pulse-report {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

/* Report button nella colonna tabella */
.styled-table th:nth-child(11) {
    width: 6%;
    text-align: center;
}

.styled-table td:nth-last-child(1) {
    text-align: center;
}

/* Report button nelle card mobile */
.lotto-card .report-btn {
    padding: 8px 14px;
    font-size: 0.82rem;
    border-radius: 8px;
}