/*
 * Stile dell'app: CSS artigianale, semplice e leggibile anche da mobile.
 * (Scelto al posto di Tailwind per non richiedere alcuna build sul server.)
 */

:root {
    --bg: #f6f7f9;
    --card: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #e5e7eb;
    --primary: #b91c1c;      /* rosso mattoncino */
    --primary-dark: #991b1b;
    --ok: #15803d;
    --warn: #b45309;
    --danger: #b91c1c;
}

* { box-sizing: border-box; }

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

h1 { font-size: 1.4rem; margin: 0.2em 0 0.4em; }

a { color: var(--primary); }

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1rem;
}

/* ---- barra superiore ---- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.6rem 1rem;
    background: var(--card);
    border-bottom: 1px solid var(--border);
}

.topbar .brand {
    font-weight: 700;
    text-decoration: none;
    color: var(--text);
}

.topbar nav { display: flex; align-items: center; gap: 0.8rem; }

/* ---- bottoni ---- */
.btn {
    display: inline-block;
    padding: 0.45rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card);
    color: var(--text);
    font-family: inherit;
    font-size: 0.92rem;
    line-height: 1.5;
    text-decoration: none;
    cursor: pointer;
}

.btn:hover { border-color: #cbd5e1; background: #f1f5f9; }

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.btn-danger {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
    font-weight: 600;
}
.btn-danger:hover { background: var(--primary-dark); }

.btn-danger-outline { color: var(--danger); border-color: #f3c1c1; }
.btn-danger-outline:hover { background: #fef2f2; border-color: var(--danger); }

.btn-ghost { border-color: transparent; background: transparent; }
.btn-small { padding: 0.25rem 0.6rem; font-size: 0.85rem; }
.btn-block { width: 100%; }

/* ---- flash ---- */
.flash {
    padding: 0.6rem 0.9rem;
    border-radius: 8px;
    margin: 0 0 0.75rem;
    border: 1px solid;
}
.flash-success { background: #f0fdf4; border-color: #bbf7d0; color: var(--ok); }
.flash-warning { background: #fffbeb; border-color: #fde68a; color: var(--warn); }
.flash-danger  { background: #fef2f2; border-color: #fecaca; color: var(--danger); }

/* ---- intestazione pagina + azioni ---- */
.page-head { margin: 0.5rem 0 1rem; }

.actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.inline-form { display: inline; }

/* ---- tabella ---- */
.table-wrap {
    overflow-x: auto;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
}

table { width: 100%; border-collapse: collapse; min-width: 720px; }

th, td {
    padding: 0.6rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

tbody tr:last-child td { border-bottom: none; }
th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
td.num, th.num { text-align: right; }
tr.row-muted td { opacity: 0.55; }

.thumb-cell { width: 64px; }
.thumb {
    width: 56px;
    height: 42px;
    object-fit: contain;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
    display: inline-block;
    text-align: center;
    line-height: 42px;
}

.row-actions { white-space: nowrap; }

/* ---- badge ---- */
.badge {
    display: inline-block;
    padding: 0.08rem 0.45rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    border: 1px solid var(--border);
    color: var(--muted);
    vertical-align: middle;
}
.badge-new    { background: #eff6ff; border-color: #bfdbfe; color: #1d4ed8; }
.badge-used   { background: #fefce8; border-color: #fde68a; color: var(--warn); }
.badge-manual { background: #fdf4ff; border-color: #f0abfc; color: #a21caf; }
.badge-update { background: #eff6ff; border-color: #bfdbfe; color: #1d4ed8; }
.badge-create { background: #f0fdf4; border-color: #bbf7d0; color: var(--ok); }
.badge-danger { background: #fef2f2; border-color: #fecaca; color: var(--danger); }

/* ---- form card (login, nuovo/modifica set) ---- */
.login-card, .form-card {
    max-width: 480px;
    margin: 3rem auto;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
}
.form-card { margin-top: 1.5rem; }

.field, form div { margin-bottom: 0.9rem; }

label { display: block; font-weight: 600; margin-bottom: 0.25rem; }

input[type="text"], input[type="password"], input[type="number"], select {
    width: 100%;
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    background: #fff;
}

input:focus, select:focus { outline: 2px solid #fca5a5; border-color: var(--primary); }

/* help e errori dei form Symfony */
form .help-text, form .help { font-size: 0.82rem; color: var(--muted); margin-top: 0.2rem; display: block; }
form ul { color: var(--danger); margin: 0.2rem 0 0; padding-left: 1.1rem; font-size: 0.85rem; }

.form-actions { display: flex; gap: 0.5rem; margin-top: 1.2rem; }

/* ---- varie ---- */
.muted { color: var(--muted); }
.small { font-size: 0.8rem; }
.ok { color: var(--ok); font-weight: 600; }
.ko { color: var(--danger); font-weight: 600; }
.empty-state {
    background: var(--card);
    border: 1px dashed var(--border);
    border-radius: 10px;
    padding: 2rem;
    text-align: center;
    color: var(--muted);
}
.confirm-bar {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    margin-top: 1.2rem;
}

/* =========================================================================
   MOBILE
   ========================================================================= */

/* Tap target comodi: i bottoni diventano un po' più alti e centrati.
   inline-flex centra icona+testo verticalmente su ogni dispositivo. */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
}

@media (max-width: 720px) {
    .container { padding: 0.75rem; }

    /* --- Tabella -> card impilate --- */
    /* Ogni riga diventa una scheda; le celle si mettono in colonna con
       l'etichetta (data-label) sopra al valore. Niente scroll orizzontale. */
    .table-wrap {
        overflow: visible;
        background: transparent;
        border: none;
        border-radius: 0;
    }
    table { min-width: 0; }
    thead { display: none; } /* le intestazioni diventano le etichette dei campi */
    tbody, tr, td { display: block; width: auto; }

    tr {
        background: var(--card);
        border: 1px solid var(--border);
        border-radius: 10px;
        margin-bottom: 0.75rem;
        padding: 0.85rem 1rem;
    }
    tr.row-muted td { opacity: 1; } /* su card la trasparenza rende illeggibile */

    td {
        border: none;
        text-align: left;
        padding: 0.4rem 0;
    }
    td.num { text-align: left; } /* nelle card i prezzi vanno a sinistra, sotto l'etichetta */
    td + td { border-top: 1px solid var(--border); margin-top: 0.1rem; padding-top: 0.6rem; }

    /* Etichetta del campo, ricavata da data-label */
    td[data-label]::before {
        content: attr(data-label);
        display: block;
        font-size: 0.7rem;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: var(--muted);
        margin-bottom: 0.2rem;
    }

    /* Thumbnail più grande in cima alla card */
    .thumb-cell { text-align: center; }
    .thumb { width: 88px; height: 66px; line-height: 66px; }

    /* Azioni riga: bottoni affiancati a piena larghezza */
    .row-actions { display: flex; gap: 0.5rem; }
    .row-actions > .btn,
    .row-actions > .inline-form { flex: 1 1 0; }
    .row-actions .inline-form { display: flex; }
    .row-actions .btn { width: 100%; }

    /* --- Barra azioni in cima: pulsanti a piena larghezza, ben spaziati --- */
    .actions { flex-direction: column; align-items: stretch; }
    .actions > .btn,
    .actions > .inline-form { width: 100%; }
    .actions .inline-form { display: flex; }
    .actions .inline-form .btn { width: 100%; }

    .confirm-bar { flex-direction: column; align-items: stretch; text-align: center; }
    .confirm-bar form, .confirm-bar .btn { width: 100%; }

    /* Card dei form (login, nuovo/modifica) a tutta larghezza */
    .login-card, .form-card { margin: 1rem auto; padding: 1.15rem; }

    /* Nella topbar, su schermi stretti nascondo l'username per fare spazio */
    .topbar .brand { font-size: 0.95rem; }
    .topbar nav .muted { display: none; }
}

/* Bottoni e input più alti/grandi sul touch: comodi da toccare e, soprattutto,
   font >= 16px sugli input evita lo zoom automatico di Safari iOS al focus. */
@media (max-width: 720px) {
    .btn { min-height: 44px; padding: 0.55rem 1rem; }
    .btn-small { min-height: 38px; }

    input[type="text"],
    input[type="password"],
    input[type="number"],
    select {
        font-size: 16px;
        padding: 0.6rem 0.7rem;
    }
}
