/* ============================================================
   Compiti · Registro di classe
   Quaderno a righe (area settimana) + lavagna (barra classi)
   ============================================================ */

:root {
  --velvet: #1E2726;        /* pannello lavagna */
  --velvet-2: #273331;
  --chalk: #E9EFE6;
  --chalk-dim: #9FB0A8;
  --paper: #F4F3EE;
  --paper-2: #ECE9E0;
  --ink: #232A2E;
  --ink-soft: #4C575B;
  --ink-faint: #7A8487;
  --margin: #B5463A;        /* rosso riga di margine */
  --leaf: #2E6B34;

  --green: #3E8F57;         --green-soft: rgba(62, 143, 87, .10);
  --yellow: #C9992B;        --yellow-soft: rgba(201, 153, 43, .12);
  --orange: #CE7222;        --orange-soft: rgba(206, 114, 34, .12);
  --red: #BE3E35;           --red-soft: rgba(190, 62, 53, .12);

  --rule: #DDD8CC;
  --serif: 'Literata', Georgia, 'Times New Roman', serif;
  --sans: 'Archivo', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; height: 100%; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

button { font-family: inherit; cursor: pointer; }

/* ------------- Topbar ------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 22px;
  border-bottom: 3px double var(--rule);
  background: var(--paper);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 14px;
  height: 14px;
  background: var(--margin);
  border-radius: 1px;
  flex: none;
}
.brand h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 700;
  font-size: 22px;
  line-height: 1.1;
  letter-spacing: .3px;
}
.brand-sub { margin: 2px 0 0; color: var(--ink-faint); font-size: 12.5px; }

.weeknav {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-inline: auto;
  position: relative;
  padding: 2px 6px;
}
.weeknav-buttons { display: flex; align-items: center; gap: 10px; }
.week-goto {
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  padding: 0 0 2px;
  cursor: pointer;
  border-bottom: 1px dashed var(--margin);
}
.week-goto:hover, .week-goto:focus-visible { color: var(--margin); outline: none; }
.week-goto strong { display: block; font-size: 15px; }
.week-picker {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
  border: 0;
}
.weeknav-buttons .ghost { font-size: 12px; padding: 7px 12px; }
.weeknav-buttons .iconbtn { width: 34px; height: 34px; }

.actions { display: flex; gap: 10px; }

/* ------------- Pulsanti ------------- */

.ghost, .primary, .iconbtn {
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink);
  padding: 8px 14px;
  font-size: 13.5px;
  font-weight: 600;
  border-radius: 6px;
  transition: background .12s ease, border-color .12s ease;
}
.ghost:hover { background: var(--paper-2); }
.primary { background: var(--leaf); border-color: var(--leaf); color: #F3F7F1; }
.primary:hover { background: #275F2B; }
.iconbtn { width: 38px; height: 38px; padding: 0; font-size: 14px; }
.ghost:focus-visible, .primary:focus-visible,
.iconbtn:focus-visible, .modal-x:focus-visible,
input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--margin);
  outline-offset: 2px;
}

/* ------------- Layout ------------- */

.layout {
  display: flex;
  flex: 1 1 0;
  min-height: 0;
  gap: 26px;
  padding: 26px 22px 30px;
  align-items: stretch;
}

.week {
  display: grid;
  grid-template-columns: repeat(5, minmax(190px, 1fr));
  gap: 14px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  overflow-y: auto;
}

/* ------------- Day column ------------- */

.day {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--rule);
  border-radius: 8px 8px 0 0;
  overflow: hidden;
  min-width: 190px;
  background: var(--paper);
}

.day-head {
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: #16231F;
}
.day-head .day-name {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 19px;
  line-height: 1.15;
}
.day-head .day-date { font-size: 12.5px; opacity: .85; font-weight: 500; }
.day-head .day-stamp {
  margin-top: 6px;
  font-family: var(--sans);
  font-weight: 800;
  font-size: 15px;
  align-self: center;
  letter-spacing: .2px;
}

.day.load-0 .day-head { background: var(--paper-2); color: var(--ink-soft); }
.day.load-1 .day-head { background: var(--green); }
.day.load-2 .day-head { background: var(--yellow); }
.day.load-3 .day-head { background: var(--orange); }
.day.load-4 .day-head { background: var(--red); }

.day.load-1 .day-body { background: var(--green-soft); }
.day.load-2 .day-body { background: var(--yellow-soft); }
.day.load-3 .day-body { background: var(--orange-soft); }
.day.load-4 .day-body { background: var(--red-soft); }

.day-body {
  flex: 1;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-top: 1px solid var(--rule);
}

.day-empty {
  border: 1px dashed var(--rule);
  border-radius: 6px;
  color: var(--ink-faint);
  font-size: 12.5px;
  padding: 14px 12px;
  text-align: center;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.day-empty button {
  border: none;
  background: transparent;
  color: var(--ink-faint);
  font-family: var(--serif);
  font-style: italic;
  font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.day-empty button:hover { color: var(--margin); }

/* ------------- Compito card ------------- */

.week .materia-group .group-label {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .5px;
  color: var(--margin);
  margin: 10px 0 6px;
  text-transform: none;
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.week .materia-group:first-child .group-label { margin-top: 0; }

.card {
  background: #FCFBF7;
  border: 1px solid var(--rule);
  border-left: 3px solid var(--margin);
  border-radius: 5px;
  padding: 10px 12px;
  cursor: pointer;
  transition: border-color .12s ease, transform .12s ease;
}
.card:hover { border-color: var(--ink-soft); transform: translateY(-1px); }
.card h4 {
  margin: 0 0 4px;
  font-family: var(--serif);
  font-weight: 700;
  font-size: 14px;
}
.card .card-tempo {
  float: right;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
}
.card .card-testo {
  margin: 0;
  font-size: 13px;
  color: var(--ink-soft);
  white-space: pre-wrap;
  word-break: break-word;
}
.card .card-parti { margin: 8px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 3px; }
.card .card-parti li {
  font-size: 12px;
  color: var(--ink-soft);
  display: flex;
  gap: 6px;
}
.card .card-parti .p-tipo { font-weight: 700; color: var(--ink); flex: none; }
.card .card-meta {
  margin-top: 8px;
  font-size: 11px;
  color: var(--ink-faint);
  border-top: 1px dotted var(--rule);
  padding-top: 6px;
}

/* ------------- Lavagna (sidebar) ------------- */

.lavagna {
  width: 240px;
  flex: none;
  background: var(--velvet);
  color: var(--chalk);
  border-radius: 8px;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.lavagna-title {
  margin: 0 0 14px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1.2px;
  color: var(--chalk-dim);
}

.plessi { display: flex; flex-direction: column; gap: 8px; }
.plesso-btn {
  border: 1px solid rgba(233, 239, 230, .28);
  background: transparent;
  color: var(--chalk);
  padding: 9px 12px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  text-align: left;
  transition: background .12s ease;
}
.plesso-btn:hover { background: var(--velvet-2); }
.plesso-btn.selected { background: var(--chalk); color: var(--velvet); border-color: var(--chalk); }

.classi-label {
  margin: 20px 0 8px;
  font-size: 12px;
  color: var(--chalk-dim);
  border-top: 1px solid rgba(233, 239, 230, .18);
  padding-top: 16px;
}

.classi { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.lavagna-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid rgba(233, 239, 230, .18);
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: stretch;
}
.user-id {
  font-size: 12px;
  color: var(--chalk-dim);
  word-break: break-word;
}
.ghost-light {
  border: 1px solid rgba(233, 239, 230, .28);
  background: transparent;
  color: var(--chalk);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
}
.ghost-light:hover { background: var(--velvet-2); }
.classe-btn {
  border: 1px solid rgba(233, 239, 230, .22);
  background: var(--velvet-2);
  color: var(--chalk);
  padding: 10px 6px;
  border-radius: 6px;
  font-size: 13.5px;
  font-weight: 600;
}
.classe-btn:hover { border-color: var(--chalk); }
.classe-btn.selected {
  background: var(--leaf);
  border-color: var(--leaf);
  color: #F3F7F1;
}
.classe-btn .classe-sub {
  display: block;
  font-size: 10px;
  font-weight: 500;
  opacity: .75;
}

/* ------------- Modali ------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(30, 39, 38, .55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 6vh 16px 32px;
  overflow-y: auto;
  z-index: 50;
}
.modal-backdrop[hidden] { display: none; }

.modal {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 10px;
  max-width: 620px;
  width: 100%;
  padding: 24px 26px 26px;
  position: relative;
  box-shadow: 0 18px 50px rgba(30, 39, 38, .35);
}
.modal-x {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  border: 1px solid var(--rule);
  background: transparent;
  border-radius: 6px;
  font-size: 13px;
  color: var(--ink-soft);
}
.modal-x:hover { background: var(--paper-2); color: var(--ink); }

.modal h3 {
  margin: 0 0 4px;
  font-family: var(--serif);
  font-weight: 700;
  font-size: 20px;
  padding-right: 40px;
}
.modal .modal-sub { margin: 0 0 18px; color: var(--ink-faint); font-size: 13px; }
.modal-small-note { font-size: 12px; color: var(--ink-faint); margin-top: 8px; line-height: 1.4; }

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 700;
  margin-bottom: 5px;
  color: var(--ink-soft);
}
.field input[type="text"], .field input[type="password"],
.field input[type="date"], .field input[type="number"],
.field textarea, .field select {
  width: 100%;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: #FCFBF7;
  color: var(--ink);
  padding: 9px 11px;
  font-size: 14px;
  font-family: inherit;
}
.field textarea { min-height: 84px; resize: vertical; }
.field input:disabled { opacity: .45; background: var(--paper-2); cursor: not-allowed; }
.field .hint { font-size: 11.5px; color: var(--ink-faint); margin-top: 4px; }

.fields-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.fields-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
@media (max-width: 560px) {
  .fields-2, .fields-3 { grid-template-columns: 1fr; }
}

/* stepper ore/minuti */
.stepper {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--rule);
  border-radius: 6px;
  overflow: hidden;
  background: #FCFBF7;
}
.stepper button {
  border: none;
  background: var(--paper-2);
  color: var(--ink);
  width: 40px;
  font-size: 17px;
  font-weight: 700;
}
.stepper button:hover { background: var(--rule); }
.stepper .stepper-val {
  flex: 1;
  text-align: center;
  font-family: var(--sans);
  font-size: 17px;
  font-weight: 700;
  align-self: center;
  padding: 8px 4px;
}
.stepper .stepper-unit { font-size: 11px; font-weight: 500; color: var(--ink-faint); }

.materie {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px;
}
.mat-btn {
  border: 1px solid var(--rule);
  background: #FCFBF7;
  border-radius: 6px;
  padding: 9px 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mat-btn.selected {
  background: var(--leaf);
  border-color: var(--leaf);
  color: #F3F7F1;
}

.parti-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: #FCFBF7;
  margin-bottom: 8px;
}
.parti-row input[type="checkbox"] { margin-top: 3px; accent-color: var(--leaf); width: 16px; height: 16px; }
.parti-row .parti-meta { flex: 1; min-width: 0; }
.parti-row .parti-label { font-size: 12.5px; font-weight: 700; }
.parti-row .parti-hint { font-size: 11.5px; color: var(--ink-faint); }
.parti-row input[type="text"] {
  width: 100%;
  border: 1px solid var(--rule);
  border-radius: 5px;
  background: #fff;
  padding: 7px 9px;
  font-size: 13px;
  margin-top: 5px;
  font-family: inherit;
}
.parti-row input[type="text"]:disabled { background: var(--paper-2); opacity: .5; }

.creator-badge {
  display: inline-block;
  font-size: 12px;
  color: var(--ink-soft);
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 20px;
  padding: 3px 10px;
  margin-bottom: 14px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
  border-top: 1px solid var(--rule);
  padding-top: 16px;
  flex-wrap: wrap;
}
.modal-actions .spacer { flex: 1; }
.btn-danger {
  background: var(--red);
  border: 1px solid var(--red);
  color: #FDF4F2;
}
.btn-danger:hover { background: #A4342C; }
.btn-ghost-danger { border: 1px solid var(--red); color: var(--red); background: transparent; }
.btn-ghost-danger:hover { background: var(--red-soft); }

.form-error { margin: 10px 0 0; color: var(--red); font-size: 13px; font-weight: 600; }
.form-error ul { margin: 6px 0 0; padding-left: 18px; }
.form-error li { font-weight: 500; }

.conferma-ditta { font-size: 13px; color: var(--ink-soft); margin-top: 8px; }

/* ------------- Toast ------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  background: var(--velvet);
  color: var(--chalk);
  padding: 11px 20px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(30, 39, 38, .35);
  z-index: 60;
  animation: toast-in .18s ease;
}
.toast[hidden] { display: none; }
.toast.error { background: var(--red); color: #FDF4F2; }

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ------------- Responsive ------------- */

@media (max-width: 960px) {
  .topbar { position: sticky; top: 0; z-index: 40; }
  .layout { flex: none; flex-direction: column-reverse; min-height: 0; }
  .week { overflow: visible; }
  .lavagna { width: 100%; flex-direction: row; flex-wrap: wrap; gap: 12px; align-items: baseline; overflow: visible; }
  .lavagna-title { width: 100%; margin-bottom: 4px; }
  .plesso-btn.selected, .classe-btn { padding: 7px 10px; }
  .classi { flex: 1; }
  .topbar { gap: 12px; flex-wrap: wrap; }
  .weeknav { order: 3; width: 100%; }
}

@media (orientation: portrait) {
  .week { grid-template-columns: 1fr; }
  .day { min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}