/* WebApp Scuola - Buoni Mensa - v2 responsive */
:root {
 --primary: #4f46e5;
 --primary-dark: #3730a3;
 --primary-light: #eef2ff;
 --success: #059669;
 --success-light: #d1fae5;
 --danger: #dc2626;
 --danger-light: #fee2e2;
 --warning: #d97706;
 --warning-light: #fef3c7;
 --gray-bg: #f1f5f9;
 --card-bg: #ffffff;
 --gray-border: #e2e8f0;
 --text: #0f172a;
 --text-muted: #64748b;
 --radius: 12px;
 --shadow: 0 1px 3px rgba(15,23,42,.08), 0 4px 14px rgba(15,23,42,.06);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body { font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: var(--gray-bg); color: var(--text); min-height: 100vh; }
.hidden { display: none !important; }

h2.page-title { font-size: 1.5rem; margin: 4px 0 16px; color: var(--primary-dark); }
h3 { margin-bottom: 10px; font-size: 1.1rem; }

/* ---------- LOGIN ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
 background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #a855f7 100%); }
.login-card { background: var(--card-bg); padding: 36px 32px; border-radius: 18px; box-shadow: 0 20px 50px rgba(0,0,0,.25); width: 100%; max-width: 400px; }
.login-card h1 { font-size: 1.6rem; text-align: center; color: var(--primary-dark); margin-bottom: 4px; }
.login-title { display: flex; align-items: center; justify-content: center; gap: 10px; }
.login-logo { height: 44px; width: auto; display: block; border-radius: 4px; }
.login-card .subtitle { text-align: center; color: var(--text-muted); margin-bottom: 22px; font-size: .95rem; }
.demo-creds { margin-top: 20px; padding: 14px; background: var(--primary-light); border-radius: var(--radius); font-size: .85rem; }
.demo-creds strong { display: block; margin-bottom: 8px; color: var(--primary-dark); }
.demo-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.demo-btn { flex: 1 1 40%; padding: 8px 6px; border: 1px solid var(--primary); background: #fff; color: var(--primary); border-radius: 8px; cursor: pointer; font-size: .85rem; transition: all .15s; }
.demo-btn:hover { background: var(--primary); color: #fff; }

/* ---------- TOPBAR ---------- */
.topbar { background: linear-gradient(90deg, var(--primary-dark), var(--primary)); color: #fff; padding: 10px 20px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; box-shadow: var(--shadow); position: sticky; top: 0; z-index: 50; }
.brand { font-size: 1.15rem; font-weight: 700; letter-spacing: .3px; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.brand-logo { height: 34px; width: auto; display: block; border-radius: 4px; background: #fff; padding: 2px; }
#nav-links { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
#nav-links a { color: #e0e7ff; text-decoration: none; padding: 7px 12px; border-radius: 8px; font-size: .9rem; transition: background .15s; white-space: nowrap; }
#nav-links a:hover { background: rgba(255,255,255,.15); }
#nav-links a.active { background: rgba(255,255,255,.22); color: #fff; font-weight: 600; }
.user-box { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.user-info { text-align: right; line-height: 1.2; }
#user-name { font-weight: 600; font-size: .9rem; }
#user-role { font-size: .72rem; opacity: .8; text-transform: capitalize; }

/* ---------- LAYOUT ---------- */
#main { max-width: 1200px; margin: 0 auto; padding: 20px 16px 60px; }
.card { background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; }
.card.stat { text-align: center; margin-bottom: 0; }
.card.stat .num { font-size: 2rem; font-weight: 800; color: var(--primary); }

/* ---------- FORM ---------- */
.form-group { margin-bottom: 12px; flex: 1; }
.form-group label { display: block; font-size: .82rem; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; }
input, select, textarea { width: 100%; padding: 9px 12px; border: 1.5px solid var(--gray-border); border-radius: 8px; font-size: .95rem; font-family: inherit; background: #fff; transition: border-color .15s; }
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }

/* ---------- BOTTONI ---------- */
.btn { display: inline-block; padding: 9px 18px; border: 1.5px solid var(--gray-border); background: #fff; color: var(--text); border-radius: 8px; cursor: pointer; font-size: .92rem; font-weight: 600; text-decoration: none; transition: all .15s; font-family: inherit; }
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { background: #047857; color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; color: #fff; }
.btn-sm { padding: 5px 10px; font-size: .8rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- TABELLE ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; padding: 10px 12px; background: var(--primary-light); color: var(--primary-dark); font-size: .78rem; text-transform: uppercase; letter-spacing: .4px; }
td { padding: 10px 12px; border-bottom: 1px solid var(--gray-border); }
tbody tr:hover { background: #f8fafc; }

/* ---------- TAG/BADGE ---------- */
.tag { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: .78rem; font-weight: 700; }
.tag.si, .tag.attivo { background: var(--success-light); color: var(--success); }
.tag.no { background: var(--gray-border); color: var(--text-muted); }
.badge { background: var(--primary-light); color: var(--primary-dark); padding: 2px 10px; border-radius: 12px; font-size: .78rem; font-weight: 600; }

/* ---------- MESSAGGI ---------- */
.error { background: var(--danger-light); color: var(--danger); padding: 14px 16px; border-radius: var(--radius); border-left: 4px solid var(--danger); }
.msg-ok { background: var(--success-light); color: var(--success); padding: 10px 14px; border-radius: 8px; margin-top: 10px; font-size: .9rem; }
.warn-card { background: var(--warning-light) !important; border-left: 4px solid var(--warning); }

/* ---------- TOAST ---------- */
#toast { position: fixed; bottom: 24px; right: 24px; background: var(--text); color: #fff; padding: 13px 22px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.25); z-index: 300; animation: slideIn .25s ease; max-width: 90vw; }
#toast.err { background: var(--danger); }
@keyframes slideIn { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- MODAL ---------- */
#modal { position: fixed; inset: 0; background: rgba(15,23,42,.55); display: flex; align-items: center; justify-content: center; z-index: 200; padding: 16px; }
.modal-box { background: #fff; border-radius: 14px; padding: 24px; width: 100%; max-width: 480px; max-height: 88vh; overflow-y: auto; position: relative; box-shadow: 0 24px 60px rgba(0,0,0,.3); }
.modal-close { position: absolute; top: 10px; right: 12px; background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--text-muted); }
.modal-box.modal-wide { max-width: 900px; padding: 18px; }

/* ---------- CALENDARIO SETTIMANALE ---------- */
.cal-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.cal-header h3 { margin: 0; font-size: 1.15rem; text-transform: capitalize; }
.cal-nav { display: flex; gap: 6px; align-items: center; }
.week-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.week-col { background: #f8fafc; border: 1px solid var(--gray-border); border-radius: 10px; min-height: 120px; padding: 8px; display: flex; flex-direction: column; }
.week-col.today { border-color: var(--primary); background: var(--primary-light); box-shadow: 0 0 0 2px rgba(79,70,229,.18); }
.week-col.other-month { opacity: .55; }
.week-col .dow-head { text-align: center; font-weight: 700; font-size: .8rem; color: var(--text-muted); text-transform: uppercase; margin-bottom: 2px; display: flex; align-items: center; justify-content: center; gap: 4px; }
.stampa-giorno { background: var(--primary); color: #fff; border: none; border-radius: 4px; font-size: .6rem; padding: 2px 6px; cursor: pointer; text-transform: none; font-weight: 600; letter-spacing: 0; }
.stampa-giorno:hover { background: var(--primary-dark); }
.stampa-giorno:active { transform: scale(.96); }
.week-col .dow-num { text-align: center; font-size: 1.15rem; font-weight: 800; color: var(--primary-dark); margin-bottom: 8px; }
.week-alunno { background: #fff; border: 1px solid var(--gray-border); border-radius: 7px; padding: 5px 7px; margin-bottom: 5px; font-size: .78rem; cursor: pointer; transition: all .12s; display: flex; justify-content: space-between; align-items: center; gap: 4px; }
.week-alunno:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.week-alunno.usato { background: var(--success-light); border-color: var(--success); color: var(--success); font-weight: 600; }
.week-alunno.prenotato { background: #fff9d6; border-color: #e6c229; color: #8a7500; font-weight: 600; }
.week-alunno:not(.clickable):not(.usato):not(.prenotato) { cursor: default; }
.week-alunno:not(.clickable):hover { border-color: var(--gray-border); box-shadow: none; }
.week-alunno .check { font-size: .85rem; }
.week-nome { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-legend { margin-top: 12px; font-size: .82rem; color: var(--text-muted); }
.cal-legend .week-alunno { display: inline-flex; margin: 0 6px 0 0; cursor: default; }
.giorno-count { text-align: center; font-size: .72rem; color: var(--text-muted); margin-top: auto; padding-top: 6px; }
.classe-picker { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; margin-bottom: 14px; }
.classe-picker .form-group { margin: 0; max-width: 300px; }
.no-class-msg { text-align: center; color: var(--text-muted); padding: 20px; }

/* ---------- MENU MENSA (griglia 4 sett x 5 giorni) ---------- */
.menu-table { width: 100%; border-collapse: collapse; min-width: 900px; }
.menu-table th, .menu-table td { border: 1px solid var(--gray-border); padding: 10px; vertical-align: top; }
.menu-table thead th { background: var(--primary); color: #fff; text-align: center; font-size: .85rem; text-transform: uppercase; letter-spacing: .03em; padding: 10px 8px; }
.menu-table thead th.today { background: var(--primary-dark); box-shadow: inset 0 -3px 0 #fbbf24; }
.menu-week-head { width: 130px; background: var(--primary-dark) !important; }
.menu-week-cell { background: #f8fafc; text-align: center; font-weight: 700; color: var(--primary-dark); }
.menu-week-name { font-size: .95rem; }
.menu-fascia { font-size: .7rem; font-weight: 500; color: var(--text-muted); margin-top: 3px; }
.menu-cell { background: #fff; min-width: 150px; font-size: .82rem; line-height: 1.45; position: relative; transition: box-shadow .12s; }
.menu-cell .menu-text { min-height: 70px; }
.menu-cell.today { background: var(--primary-light); box-shadow: inset 0 0 0 2px var(--primary); }
.menu-cell .menu-empty { color: var(--text-muted); }
.menu-cell .menu-upd { font-size: .68rem; color: var(--text-muted); margin-top: 6px; }
.menu-edit-btn { margin-top: 8px; width: 100%; font-size: .72rem; padding: 4px 6px; }
.menu-row.current-week .menu-week-cell { background: #d1fae5; box-shadow: inset 3px 0 0 #10b981; }
.menu-row.current-week .menu-week-cell .menu-week-name::after { content: " — attuale"; font-size: .7rem; font-weight: 600; color: #047857; }
.menu-row.current-week td { background: #f0fdf4; }
.menu-row.current-week .menu-week-cell,
.menu-row.current-week .menu-cell.today { background: #d1fae5; }
.menu-note { font-size: .75rem; color: var(--text-muted); margin-top: 12px; }

/* ---------- ELENCO ALUNNI (giorno) ---------- */
.elenco-alunno { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--gray-border); border-radius: 8px; margin-bottom: 6px; background: #fff; }
.elenco-alunno.usato { background: var(--success-light); border-color: var(--success); }
.riga-usato span:first-child { text-decoration: line-through; opacity: .75; }

/* ---------- RESPONSIVE ---------- */
@media (max-width: 900px) {
 .week-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 720px) {
 html { font-size: 14px; }
 .topbar { padding: 10px 12px; }
 .brand { width: 100%; }
 .user-box { margin-left: 0; }
 #main { padding: 14px 10px 50px; }
 .card { padding: 14px; }
}
@media (max-width: 560px) {
 .week-grid { grid-template-columns: 1fr 1fr; }
 .week-col { min-height: 90px; }
 #nav-links a { padding: 6px 9px; font-size: .84rem; }
 .login-card { padding: 26px 20px; }
 .user-info { display: none; }
}
@media print {
 .topbar, #toast, .cal-header .cal-nav, button, .classe-picker { display: none !important; }
 body { background: #fff; }
 .card { box-shadow: none; border: 1px solid #ccc; }
}

/* ---- Barra ricerca + paginazione elenchi ---- */
.list-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 10px 0;
}
.list-bar .list-search { flex: 1 1 200px; min-width: 160px; }
.list-bar .list-q {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border, #ccc);
  border-radius: 8px;
  font-size: .9rem;
  background: var(--surface, #fff);
  color: var(--text, #222);
}
.list-bar .list-pager { display: flex; align-items: center; gap: 8px; }
.list-bar .pg-info { font-size: .85rem; color: var(--text-muted, #666); }
.list-bar .pg-total { font-size: .8rem; color: var(--text-muted, #666); }
.list-bar .btn-sm { padding: 4px 10px; }
