body { font-family: Arial, sans-serif; margin: 10px; background: #f4f4f4; }
.container { max-width: 2100px; margin: 0 auto; background: white; padding: 14px 20px; border-radius: 8px; }
.filters { margin-bottom: 16px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters select, .filters input { padding: 6px 8px; }
.filters input[type="text"], .filters input[type="date"] { min-width: 8.5rem; }

.copy-btn { background: none; border: none; cursor: pointer; padding: 0 4px; font-size: 1em; }
.icon-link { text-decoration: none; margin: 0 4px; font-size: 1.2em; }
.icon-link.disabled { opacity: 0.5; cursor: not-allowed; }
.actions { white-space: nowrap; }
.quick-range { margin: 8px 0 0; display: flex; flex-wrap: wrap; gap: 6px; }

/* Pulsanti del form filtri e delle fasce rapide: forma omogenea */
.filters button, .filter-bar button, .quick-btn {
    padding: 6px 12px;
    border: 1px solid #b9c2cc;
    border-radius: 5px;
    background: #f1f3f5;
    color: #333;
    cursor: pointer;
    font: inherit;
    font-size: 0.9rem;
    line-height: 1.25;
}
.filters button:hover, .filter-bar button:hover, .quick-btn:hover { background: #e4e7ea; }
.filters > button[type="submit"] {          /* "Filtra": azione primaria */
    background: #007BFF; border-color: #0069d9; color: #fff; font-weight: 600;
}
.filters > button[type="submit"]:hover { background: #0069d9; }

.pagination { margin: 20px 0; text-align: center; display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; align-items: center; }
.pagination a, .pagination span {
    padding: 6px 12px; border: 1px solid #ccc; border-radius: 6px;
    text-decoration: none; color: #333; background: #fff; display: inline-block;
}
.pagination .current { background: #007BFF; color: #fff; border-color: #007BFF; font-weight: bold; }
.pagination .disabled { opacity: 0.5; pointer-events: none; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 5px 9px; text-align: left; border-bottom: 1px solid #ddd; font-size: 0.92rem; }
th { background: #007BFF; color: white; }
th a { color: #fff; }
tr:hover { background: #f1f1f1; }
a { color: #007BFF; text-decoration: none; }

.nav-links { margin: 0 0 12px; }
.nav-links a { margin-right: 14px; }

.fav-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1em;
    line-height: 1;
    padding: 0 4px;
    color: #bbb;
}
.fav-btn.is-fav { color: #f5b301; }
.fav-btn:disabled { opacity: 0.4; cursor: default; }
.fav-static { color: #f5b301; padding: 0 4px; }
.fav-note { font-style: italic; color: #6c757d; }

.table-scroll { overflow-x: auto; }
.muted { color: #6c757d; font-size: 0.85em; }
.model-silhouette { height: 16px; width: auto; vertical-align: middle; margin-right: 5px; }
img.flag-icon { height: 11px; width: auto; max-width: 18px; vertical-align: middle; border-radius: 2px; }
.op-logo { height: 15px; width: auto; vertical-align: middle; margin-right: 4px; }
.autorefresh { margin: 6px 0 14px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.autorefresh select { padding: 4px; }
.mil-badge { color: #b23b3b; font-weight: bold; }
.conf { display: inline-block; padding: 1px 6px; border-radius: 4px; font-variant-numeric: tabular-nums; }
.conf-hi { background: #d4edda; color: #155724; }
.conf-mid { background: #fff3cd; color: #856404; }
.conf-lo { background: #f1f1f1; color: #666; }

/* Statistiche */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; align-items: start; }
.stats-card { border: 1px solid #e0e0e0; border-radius: 8px; padding: 12px 14px; overflow-x: auto; }
.stats-card h2 { margin: 0 0 8px; font-size: 1rem; }
.stats-card table { font-size: 0.86rem; width: 100%; }
.stats-card th, .stats-card td { padding: 4px 6px; white-space: nowrap; }
.stats-card td:first-child { white-space: normal; }        /* i nomi lunghi possono andare a capo */
.stats-card td .bar { max-width: 120px; }
.kpi-row { display: flex; flex-wrap: wrap; gap: 14px; margin: 10px 0 20px; }
.kpi { border: 1px solid #e0e0e0; border-radius: 8px; padding: 10px 14px; min-width: 120px; }
.kpi .n { font-size: 1.5rem; font-weight: bold; }
.kpi .l { color: #6c757d; font-size: 0.82rem; }
.bar { background: #007BFF; height: 10px; border-radius: 3px; display: inline-block; vertical-align: middle; max-width: 100%; }

/* Diario di bordo */
.msg { padding: 8px 12px; border-radius: 6px; margin: 10px 0; }
.msg.ok { background: #d4edda; color: #155724; }
.msg.err { background: #f8d7da; color: #721c24; }
.diary-jump { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 10px 0; }
.diary-jump button, .diary-admin button {
    padding: 6px 12px; border: 1px solid #b9c2cc; border-radius: 5px;
    background: #f1f3f5; color: #333; cursor: pointer; font: inherit; font-size: 0.9rem;
}
.diary-jump button:hover, .diary-admin button:hover { background: #e4e7ea; }
.diary-admin { border: 1px solid #e0e0e0; border-radius: 8px; padding: 12px 14px; margin: 12px 0 18px; background: #fafbfc; }
.diary-admin form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.diary-admin hr { width: 100%; border: 0; border-top: 1px solid #e0e0e0; margin: 12px 0; }
.diary-admin .ai-edit { display: block; }
.diary-admin textarea { width: 100%; box-sizing: border-box; font: 0.86rem/1.4 ui-monospace, Menlo, Consolas, monospace; padding: 8px; margin: 4px 0 8px; }
.diary-admin .ai-edit > div { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.diary-admin .btn-primary { background: #007BFF; border-color: #0069d9; color: #fff; font-weight: 600; }
.diary-admin .btn-primary:hover { background: #0069d9; }
.diary-admin .btn-warn { background: #e0a800; border-color: #c69500; color: #fff; font-weight: 600; }
.diary-admin .btn-warn:hover { background: #c69500; }
.diary-narrative { border: 1px solid #d5e3f0; background: #f5f9fd; border-radius: 8px; padding: 4px 18px 12px; margin: 14px 0 20px; }
.diary-narrative h3 { font-size: 1.02rem; margin: 14px 0 6px; }
.ai-note { font-size: 0.8rem; color: #6c757d; border-top: 1px solid #d5e3f0; padding-top: 8px; margin-top: 12px; }
.badge-pub { color: #155724; font-weight: bold; font-size: 0.82rem; }
.badge-draft { color: #856404; font-weight: bold; font-size: 0.82rem; }
table.diary-list td, table.diary-list th { padding: 5px 9px; }

/* =====================================================================
   RESPONSIVE — solo entro @media: la vista desktop resta identica.
   ===================================================================== */

/* Tablet e desktop stretti: le tabelle larghe scorrono invece di comprimersi. */
@media (max-width: 992px) {
    .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .table-scroll > table { min-width: 760px; }
}

/* Smartphone: margini ridotti, filtri impilati, tabelle-dati come schede. */
@media (max-width: 560px) {
    body { margin: 6px; }
    .container { padding: 12px; border-radius: 0; }
    h1 { font-size: 1.3rem; }
    .nav-links a { display: inline-block; margin: 0 12px 6px 0; }

    /* Barra filtri: un campo per riga, a tutta larghezza */
    .container .filters,
    .container .filter-bar { flex-direction: column; align-items: stretch; gap: 8px; }
    .container .filters > *,
    .container .filters input,
    .container .filters select,
    .container .filter-bar > * { width: 100%; margin: 0; box-sizing: border-box; }
    .container .filters label,
    .container .filter-bar label { display: flex; align-items: center; gap: 8px; }
    .container .filters label input[type="checkbox"],
    .container .filters label select { width: auto; }
    .quick-range { display: flex; flex-wrap: wrap; }
    .quick-range .quick-btn { flex: 1 1 45%; }

    /* Tabelle marcate .cards: intestazione nascosta, ogni riga = scheda */
    .table-scroll { overflow: visible; }
    table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; }
    table.cards { min-width: 0; width: 100%; }
    table.cards thead { display: none; }
    table.cards tr {
        border: 1px solid #ddd;
        border-radius: 8px;
        margin-bottom: 12px;
        padding: 6px 10px;
        background: #fff;
    }
    table.cards tr:hover { background: #fff; }
    table.cards td {
        border: none;
        border-bottom: 1px solid #f0f0f0;
        padding: 7px 0;
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        gap: 12px;
        text-align: right;
        word-break: break-word;
    }
    table.cards td:last-child { border-bottom: none; }
    table.cards td::before {
        content: attr(data-label);
        font-weight: bold;
        color: #555;
        text-align: left;
        flex: 0 0 38%;
    }
    table.cards td[data-label=""] { justify-content: flex-start; text-align: left; }
    table.cards td[data-label=""]::before { content: none; }
    table.cards td.actions { padding-top: 10px; }

    /* Statistiche */
    .stats-grid { grid-template-columns: 1fr; }
    .stats-card { overflow-x: auto; }
    .kpi-row { gap: 10px; }
    .kpi { flex: 1 1 44%; min-width: 0; padding: 10px 12px; }
    .kpi .n { font-size: 1.35rem; }
}
