/*
  Sistema visivo condiviso con ftalo (CLAUDE.md: "l'unica cosa in comune può
  essere l'aspetto — colori, stile, powered by ftalo"). Stessi token, stesso
  font di sistema, stesse spaziature — nessuna dipendenza di codice da ftalo,
  solo lo stesso linguaggio visivo, per non disorientare chi usa entrambi.

  Unica differenza deliberata: il colore identitario è verde, non il blu di
  ftalo — serve a distinguere a colpo d'occhio in quale ambiente ci si trova.
*/

:root {
    /* identità: verde Ask al posto del blu ftalo. Un solo tono per barra e
       azioni (link, pulsanti) — ftalo ne usa due diversi apposta, qui si
       resta più semplici finché non serve altro. */
    --brand: #123524;
    --accent: #123524;
    --accent-dark: #0b2116;

    /* semantici: fissi, mai decorativi */
    --danger: #b3261e;
    --danger-bg: #fdecea;
    --warning: #93650a;
    --warning-bg: #fdf3dc;
    --success: #1e6b3e;
    --success-bg: #e8f5ec;

    /* neutri */
    --gray-950: #14181f;
    --gray-800: #2b323d;
    --gray-600: #5b6472;
    --gray-400: #9aa4b2;
    --gray-200: #d8dee6;
    --gray-100: #eef1f5;
    --gray-050: #f6f8fa;

    --text: var(--gray-950);
    --text-muted: var(--gray-600);
    --bg: #fafbfc;
    --bg-side: #f7f8fa;
    --surface: #ffffff;
    --border: #e5e9ef;

    /* tipografia: una sola famiglia di sistema, quattro misure, non di più */
    --text-sm: 14px;
    --text-base: 16px;
    --text-lg: 20px;
    --text-xl: 38px;

    /* spaziature su scala fissa, niente valori arbitrari */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;

    --radius: 8px;
    --radius-lg: 12px;
    --shadow-card: 0 1px 2px rgba(15, 23, 90, 0.03), 0 4px 12px rgba(15, 23, 90, 0.035);
    --shadow-popover: 0 8px 30px rgba(15, 23, 90, 0.1);
    --tap-min: 44px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: var(--text-base);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible,
textarea:focus-visible, [tabindex]:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

header.topbar {
    background: var(--brand);
    border-bottom: 1px solid var(--brand);
    padding: 0.9rem 1.5rem;
    display: flex;
    flex-wrap: wrap;
    row-gap: 0.4rem;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

header.topbar .brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: #fff;
}
header.topbar .brand { display: inline-flex; align-items: center; }
header.topbar .brand .logo-flab { height: 18px; width: auto; display: block; }
.standalone-brand .logo-flab { height: 30px; width: auto; display: block; }

header.topbar nav { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 1rem; }
header.topbar nav a { font-size: 0.9rem; color: rgba(255, 255, 255, 0.82); }
header.topbar nav a:hover { color: #fff; }

header.topbar nav .avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.7rem;
    height: 1.7rem;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    font-weight: 700;
    font-size: 0.82rem;
    vertical-align: middle;
}
header.topbar nav .avatar:hover { background: rgba(255, 255, 255, 0.3); text-decoration: none; }
header.topbar nav button.avatar {
    border: 0; padding: 0; cursor: pointer; font-family: inherit; line-height: 1;
    /* area di tocco da 44 px senza ingrandire il cerchio */
    position: relative;
}
header.topbar nav button.avatar::after { content: ""; position: absolute; inset: -9px; }

/* Tendina dell'avatar (F3), come ftalo. */
.menu-utente { position: relative; }
.menu-utente-tendina {
    position: absolute; right: 0; top: calc(100% + 10px);
    min-width: 230px; max-width: calc(100vw - 24px);
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-popover);
    padding: var(--space-2) 0; z-index: 150;
}
.menu-utente-tendina[hidden] { display: none; }
.menu-utente-chi { padding: var(--space-2) var(--space-4) var(--space-3); line-height: 1.3; }
.menu-utente-chi strong { display: block; color: var(--text); overflow-wrap: anywhere; }
.menu-utente-chi span { font-size: var(--text-sm); color: var(--text-muted); }
header.topbar .menu-utente-tendina a {
    display: flex; align-items: center; min-height: 40px;
    padding: 0 var(--space-4); color: var(--text); font-size: 0.95rem;
}
header.topbar .menu-utente-tendina a:hover { background: var(--gray-050); color: var(--text); text-decoration: none; }
.menu-utente-tendina hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-2) 0; }

main.container {
    max-width: 1140px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    padding: 1.5rem;
    margin-bottom: 1.25rem;
    max-width: 100%;
    overflow-x: auto;
}

@media (max-width: 640px) {
    header.topbar { padding: 0.75rem 1rem; }
    main.container { padding: 1.25rem 1rem; }
    .card { padding: 1.1rem; }
    h1 { font-size: 1.5rem; }
}

h1, h2, h3 { margin: 0 0 var(--space-3); font-weight: 600; line-height: 1.25; }
h1 { font-size: var(--text-xl); font-weight: 700; line-height: 1.15; }
h2 { font-size: var(--text-lg); }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}

th, td {
    text-align: left;
    padding: 0.55rem 0.7rem;
    border-bottom: 1px solid var(--border);
}

th { color: var(--text-muted); font-weight: 600; }

.badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
}

.badge.on { background: var(--success-bg); color: var(--success); }
.badge.off { background: var(--danger-bg); color: var(--danger); }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--tap-min);
    background: var(--accent);
    color: #fff;
    border: 1px solid var(--accent);
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.9rem;
    font-family: inherit;
}

.btn:hover { background: var(--accent-dark); border-color: var(--accent-dark); text-decoration: none; }
.btn.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: var(--gray-050); }
.btn.danger { background: var(--danger); border-color: var(--danger); }

form.inline { display: inline; }

input[type=text], input[type=email], input[type=password], input[type=date],
input[type=number], select, textarea {
    width: 100%;
    min-height: var(--tap-min);
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: var(--text-base);
    font-family: inherit;
    background: var(--surface);
    color: var(--text);
}

label { display: block; font-size: var(--text-sm); color: var(--text-muted); margin-bottom: 0.25rem; }

.field { margin-bottom: 1rem; }

.messages { list-style: none; padding: 0; margin: 0 0 1rem; }
.messages li {
    padding: 0.6rem 0.9rem;
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    background: var(--gray-100);
    color: var(--text-muted);
    font-size: var(--text-sm);
}
.messages li.error { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger); }
.messages li.success { background: var(--success-bg); color: var(--success); border: 1px solid var(--success); }
.messages li.warning { background: var(--warning-bg); color: var(--warning); border: 1px solid var(--warning); }
.messages li.info { background: var(--gray-100); color: var(--text-muted); border: 1px solid var(--border); }

.muted { color: var(--text-muted); font-size: 0.88rem; }

.controls-box {
    background: var(--bg-side);
    border: 1px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
}

.controls-box .row {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
    align-items: flex-end;
}

.dashboard-grid {
    display: flex;
    gap: 1.5rem;
    align-items: flex-start;
}

.dashboard-main { flex: 1; min-width: 0; }

.dashboard-sidebar {
    width: 240px;
    flex-shrink: 0;
    position: sticky;
    top: 4.5rem;
}

@media (max-width: 860px) {
    .dashboard-grid { flex-direction: column; align-items: stretch; }
    .dashboard-sidebar { width: 100%; position: static; }
}

.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    padding: 1rem 1.1rem;
    margin-bottom: 0.9rem;
}

.kpi-value { font-size: 1.7rem; font-weight: 700; line-height: 1.1; }
.kpi-label { color: var(--text-muted); font-size: 0.82rem; margin-top: 0.25rem; }
.kpi-value.warn { color: var(--danger); }

details.collapsible summary {
    cursor: pointer;
    font-size: var(--text-lg);
    font-weight: 700;
    padding: 0.2rem 0;
    list-style: none;
}
details.collapsible summary::-webkit-details-marker { display: none; }
details.collapsible summary::before {
    content: "\25B8";
    display: inline-block;
    margin-right: 0.5rem;
    transition: transform 0.15s ease;
}
details.collapsible[open] summary::before { transform: rotate(90deg); }
details.collapsible .collapsible-body { margin-top: 1rem; }

.corso-manage-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}
.corso-manage-row.inactive { opacity: 0.55; }
.corso-manage-row .meta { font-size: 0.82rem; color: var(--text-muted); }

.competenza-review {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1rem;
    margin-bottom: 0.75rem;
}
.competenza-review .promote-form {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
    align-items: flex-end;
    margin-top: 0.75rem;
}
.competenza-review .promote-form .field { margin-bottom: 0; min-width: 140px; }

.report-index-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 1rem;
}
.report-index-grid a.card { display: block; color: var(--text); }
.report-index-grid a.card:hover { border-color: var(--brand); text-decoration: none; }
.report-index-grid .tag {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--brand);
    margin-bottom: 0.4rem;
}

.confidential-banner {
    background: var(--warning-bg);
    border: 1px solid var(--warning);
    color: var(--warning);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    font-size: 0.85rem;
    margin-bottom: 1.25rem;
}

.report-status { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; }
.report-status .dot { width: 0.6rem; height: 0.6rem; border-radius: 50%; display: inline-block; }
.report-status.done .dot { background: var(--success); }
.report-status.todo .dot { background: var(--danger); }

.report-section { max-width: 860px; }
.report-section h2 { margin-top: 2rem; border-top: 1px solid var(--border); padding-top: 1.5rem; }
.report-section h2:first-of-type { border-top: none; padding-top: 0; margin-top: 0; }

/* ── Pagine "isolate": login e messaggi (chiusa/pin/errore) ──────────────
   Stesso schema di ftalo: il login ha lo sfondo pieno del colore identitario
   con una scheda bianca al centro; le pagine di messaggio restano su sfondo
   neutro, senza il colore identitario, per non sembrare un errore grave. */

.standalone-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: var(--space-5);
}

.standalone-page.on-brand { background: var(--brand); }

.standalone-card {
    width: 100%;
    max-width: 380px;
    padding: var(--space-6);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-card);
}

.standalone-card h1 { text-align: center; margin-bottom: var(--space-2); }
.standalone-card .lead { text-align: center; color: var(--text-muted); margin-bottom: var(--space-5); }

.standalone-brand {
    display: flex;
    justify-content: center;
    margin-bottom: var(--space-6);
    font-weight: 700;
    font-size: var(--text-lg);
    color: var(--brand);
}

.powered-by {
    text-align: center;
    color: var(--gray-400);
    font-size: var(--text-sm);
    margin-top: var(--space-4);
}

/* ── Tabelle che diventano schede sotto i 900px (come in ftalo) ─────────── */

@media (max-width: 640px) {
    table.stack-on-mobile thead { display: none; }
    table.stack-on-mobile, table.stack-on-mobile tbody,
    table.stack-on-mobile tr, table.stack-on-mobile td { display: block; width: 100%; }
    table.stack-on-mobile tr {
        margin-bottom: var(--space-3);
        border: 1px solid var(--border);
        border-radius: var(--radius-lg);
        overflow: hidden;
    }
    table.stack-on-mobile td {
        min-height: var(--tap-min);
        display: flex;
        align-items: center;
        border-bottom: 1px solid var(--border);
    }
    table.stack-on-mobile td:last-child { border-bottom: none; }
    table.stack-on-mobile td::before {
        content: attr(data-label);
        flex: 0 0 40%;
        font-size: 12px;
        font-weight: 600;
        color: var(--text-muted);
    }
}

@media print {
    header.topbar, .no-print, footer.piede { display: none !important; }
    main.container { max-width: 100%; padding: 0; }
    .card { border: none; padding: 0; box-shadow: none; }
    a { color: var(--text) !important; text-decoration: none !important; }
}

#pull-refresh-indicator {
    position: fixed;
    left: 50%;
    top: 0.6rem;
    transform: translate(-50%, -140%);
    opacity: 0;
    z-index: 200;
    width: 2.3rem;
    height: 2.3rem;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-popover);
    pointer-events: none;
}
#pull-refresh-indicator.settling { transition: transform 0.2s ease, opacity 0.2s ease; }
#pull-refresh-icon { display: inline-block; font-size: 1.15rem; color: var(--accent); line-height: 1; }
#pull-refresh-indicator.spinning #pull-refresh-icon { animation: pr-spin 0.6s linear infinite; }
@keyframes pr-spin { to { transform: rotate(360deg); } }

/* App «a tutto schermo da telefono» (contratto delle app): sotto i 768 px la
   barra sparisce e al suo posto il telaio mette «‹ F-Lab», che porta alla home
   (dove barra e logout ci sono sempre). Sul computer non cambia niente. */
.torna-flab { display: none; }
@media (max-width: 767px) {
    body.schermo-intero header.topbar { display: none; }
    body.schermo-intero main.container { padding: 0; max-width: none; }
    body.schermo-intero footer.piede { display: none; }
    body.schermo-intero .torna-flab {
        display: inline-flex;
        align-items: center;
        position: absolute;
        top: 10px;
        left: 10px;
        z-index: 50;
        min-height: 44px;
        min-width: 44px;
        padding: 0 14px;
        border-radius: 22px;
        background: rgba(0, 0, 0, 0.28);
        color: #fff;
        font-weight: 600;
        font-size: 0.95rem;
        text-decoration: none;
        -webkit-backdrop-filter: blur(6px);
        backdrop-filter: blur(6px);
    }
}

/* Piè di pagina del telaio (F3). */
footer.piede {
    max-width: 1140px; margin: 0 auto; padding: var(--space-5) 1.5rem var(--space-6);
    font-size: 12.5px; color: var(--text-muted); text-align: center;
}
footer.piede a { color: var(--text-muted); text-decoration: underline; }

/* Home a card (F3). Una colonna su telefono. */
.home { position: relative; }
.home-vista { display: flex; justify-content: flex-end; gap: 4px; margin-bottom: var(--space-4); }
.home-vista button {
    font: inherit; font-size: var(--text-sm); min-height: 36px; padding: 0 var(--space-3);
    background: var(--surface); color: var(--text-muted); border: 1px solid var(--border);
    border-radius: var(--radius); cursor: pointer;
}
.home-vista button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.app-griglia { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--space-4); }
.home .app-elenco { display: none; }
.home.vista-elenco .app-griglia { display: none; }
.home.vista-elenco .app-elenco { display: block; }
@media (max-width: 640px) { .app-griglia { grid-template-columns: 1fr; } }

.app-card {
    display: flex; flex-direction: column; gap: var(--space-2);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card); padding: var(--space-4) var(--space-5); color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}
.app-card:hover { text-decoration: none; border-color: var(--gray-400); box-shadow: var(--shadow-popover); }
.app-card-testa { display: flex; align-items: center; gap: var(--space-3); }
.app-icona { width: 44px; height: 44px; border-radius: 10px; flex: 0 0 44px; object-fit: cover; }
.app-icona.iniziale {
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--brand); color: #fff; font-weight: 700; font-size: 1.2rem;
}
.app-titolo { font-weight: 700; line-height: 1.25; }
.app-cliente { font-size: var(--text-sm); color: var(--text-muted); }
.app-descrizione {
    margin: 0; font-size: 0.93rem; color: var(--gray-800);
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.app-stato { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.badge.fase { background: var(--gray-100); color: var(--gray-800); }
.app-date { font-size: 13px; color: var(--text-muted); }
.app-diag {
    display: flex; gap: var(--space-2); align-items: flex-start;
    margin-top: var(--space-1); padding-top: var(--space-2); border-top: 1px solid var(--border);
    font-size: 12px; color: var(--text-muted); line-height: 1.45;
}
.app-diag-cella { font-size: 12px; color: var(--text-muted); }
.pallino {
    display: inline-block; flex: 0 0 9px; width: 9px; height: 9px; border-radius: 50%;
    background: #e8870e; margin-top: 4px; margin-right: 2px;
}
