:root {
    --bg: #f4f5f7;
    --card: #ffffff;
    --ink: #1f2733;
    --muted: #5b626d;
    --border: #e3e6ea;
    --brand: #2f5fe0;
    --brand-dark: #244bb3;
    --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.04);
}

* { box-sizing: border-box; }

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

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

/* Focus visibile da tastiera (accessibilità) */
:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
    border-radius: 4px;
}
input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline-offset: 0;
    border-color: var(--brand);
}

/* Header */
.topbar {
    background: var(--ink);
    color: #fff;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
}
.topbar .brand { font-weight: 700; font-size: 18px; color: #fff; }
.topbar nav a { color: #cfd6e4; margin-left: 18px; font-size: 14px; }
.topbar nav a:hover, .topbar nav a.active { color: #fff; text-decoration: none; }
.topbar .user { color: #9aa6bd; font-size: 13px; margin-left: 18px; }

.container { max-width: 1080px; margin: 24px auto; padding: 0 20px; }

h1 { font-size: 24px; margin: 0 0 4px; }
h2 { font-size: 18px; margin: 24px 0 12px; }
.subtitle { color: var(--muted); margin: 0 0 20px; }

/* Cards */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 18px;
}

/* Buttons */
.btn {
    display: inline-block;
    background: var(--brand);
    color: #fff;
    border: none;
    border-radius: 7px;
    padding: 9px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.is-loading { pointer-events: none; opacity: 0.65; cursor: default; }
.btn.secondary { background: #eef1f6; color: var(--ink); }
.btn.secondary:hover { background: #e2e7ef; }
.btn.danger { background: #d64545; }
.btn.small { padding: 5px 10px; font-size: 13px; }

/* Forms */
.form-row { margin-bottom: 14px; }
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
input, select, textarea {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: 7px;
    font-size: 14px;
    font-family: inherit;
    background: #fff;
}
textarea { resize: vertical; min-height: 80px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
/* Cifre tabellari: colonne di numeri/date allineate */
td { font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: none; }

/* Badges */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.s-assegnato      { background:#eef1f6; color:#475467; }
.s-in_lavorazione { background:#fff3d6; color:#9a6b00; }
.s-consegnato     { background:#dcecff; color:#1c52b3; }
.s-in_revisione   { background:#f0e2ff; color:#6c2bd9; }
.s-pubblicato     { background:#d9f5e3; color:#0a7a3d; }

.i-pianificazione { background:#eef1f6; color:#475467; }
.i-in_corso       { background:#dcecff; color:#1c52b3; }
.i-chiuso         { background:#d9f5e3; color:#0a7a3d; }

/* Alerts */
.alert { padding: 11px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.alert.error { background:#fde7e7; color:#a12626; }
.alert.success { background:#dcf5e6; color:#0a7a3d; }
.alert.info { background:#e7f0fd; color:#1c52b3; }

.cover-thumb {
    width: 120px;
    aspect-ratio: 3 / 4;
    height: auto;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border);
    display: block;
}

.muted { color: var(--muted); }
.right { text-align: right; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.overdue { color: #d64545; font-weight: 600; }

/* Login */
.login-wrap { max-width: 380px; margin: 8vh auto; padding: 0 20px; }
.login-wrap h1 { text-align: center; margin-bottom: 20px; }

/* Stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px,1fr)); gap: 14px; margin-bottom: 20px; }
.tile { background: var(--card); border:1px solid var(--border); border-radius:10px; padding:16px; box-shadow: var(--shadow); }
.tile .num { font-size: 28px; font-weight: 700; }
.tile .lbl { color: var(--muted); font-size: 13px; }

@media (max-width: 640px) {
    .grid2 { grid-template-columns: 1fr; }
    .hide-mobile { display: none; }

    /* Nav scorrevole in orizzontale invece di andare a capo */
    .topbar { padding: 0 12px; }
    .topbar nav { display: flex; align-items: center; overflow-x: auto; max-width: 72vw; }
    .topbar nav a { margin-left: 12px; white-space: nowrap; }

    /* Tabelle larghe: scroll orizzontale invece di sfondare la pagina */
    table { display: block; overflow-x: auto; white-space: nowrap; }

    /* Campi a 16px per evitare l'auto-zoom di iOS Safari al focus */
    input, select, textarea { font-size: 16px; }
}
