/* Agenda: griglia oraria, vista mese, elenco, finestra evento. */

.agenda-head { flex-wrap: wrap; row-gap: 8px; }
.agenda-title { flex: 1; min-width: 180px; display: flex; align-items: baseline; gap: 10px; }
.agenda-title h1 { flex: none; }
.agenda-tools { gap: 10px; flex-wrap: wrap; }

.agenda-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 20px 10px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 13px;
  text-decoration: none;
}
.agenda-banner:hover { text-decoration: none; filter: brightness(0.98); }
.agenda-banner.err { background: var(--danger-soft); color: var(--danger); }

/* ---- Griglia oraria (giorno e settimana) ---- */

.tg {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-top: 1px solid var(--border);
  --gutter: 54px;
}
.tg-scroll { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }
.tg-top { position: sticky; top: 0; z-index: 5; background: var(--surface); border-bottom: 1px solid var(--border); }
.tg-head, .tg-allday { display: grid; grid-template-columns: var(--gutter) repeat(var(--n), minmax(0, 1fr)); }
.tg-corner { display: grid; place-items: center; }
.tg-day {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  padding: 8px 4px 7px;
  color: var(--text-2);
  text-decoration: none;
  border-left: 1px solid transparent;
}
.tg-day:hover { text-decoration: none; background: var(--surface-2); }
.tg-day .wd { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.tg-day .num { font-size: 17px; font-weight: 650; color: var(--text); min-width: 28px; height: 28px; display: inline-grid; place-items: center; border-radius: 50%; }
.tg-day.today .wd { color: var(--accent); }
.tg-day.today .num { background: var(--accent); color: var(--accent-ink); }
.tg-allday { border-top: 1px solid var(--border); }
.tg-allday-cell { padding: 3px 3px 4px; display: flex; flex-direction: column; gap: 2px; border-left: 1px solid var(--border); min-width: 0; }

.tg-body { display: grid; grid-template-columns: var(--gutter) minmax(0, 1fr); position: relative; }
.tg-hour { height: var(--hour-h); position: relative; }
.tg-hour span {
  position: absolute;
  top: -8px;
  right: 8px;
  font-size: 11px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
.tg-cols {
  display: grid;
  grid-template-columns: repeat(var(--n), minmax(0, 1fr));
  background-image:
    linear-gradient(to bottom, var(--border) 1px, transparent 1px),
    linear-gradient(to bottom, color-mix(in srgb, var(--border) 45%, transparent) 1px, transparent 1px);
  background-size: 100% var(--hour-h), 100% calc(var(--hour-h) / 2);
}
.tg-col { position: relative; border-left: 1px solid var(--border); cursor: crosshair; touch-action: pan-y; }
.tg-col.weekend { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.tg-col.today { background: color-mix(in srgb, var(--accent-soft) 35%, transparent); }

.ev {
  position: absolute;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 3px 7px 3px 8px;
  border-radius: 6px;
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  color: var(--accent-text);
  text-decoration: none;
  overflow: hidden;
  cursor: pointer;
  font-size: 12.5px;
  line-height: 1.25;
  user-select: none;
  -webkit-user-select: none;
  transition: box-shadow 0.12s;
}
.ev:hover { text-decoration: none; box-shadow: var(--shadow-1); z-index: 2; }
.ev-title { font-weight: 650; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.ev-meta { font-size: 11.5px; opacity: 0.85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev.short { flex-direction: row; align-items: center; gap: 6px; padding-top: 0; padding-bottom: 0; }
.ev.short .ev-title { -webkit-line-clamp: 1; flex: 0 1 auto; white-space: nowrap; display: block; }
.ev.short .ev-meta { flex: 1 0 auto; }
.ev.past { opacity: 0.62; }
.ev.ro { border-left-style: dashed; }
.ev.dragging { opacity: 0.9; box-shadow: var(--shadow-2); z-index: 4; cursor: grabbing; }
.ev-note { position: absolute; top: 4px; right: 5px; opacity: 0.8; }
.ev.short .ev-note { position: static; }
.ev-resize { position: absolute; left: 0; right: 0; bottom: 0; height: 6px; cursor: ns-resize; }

.tg-ghost {
  position: absolute;
  left: 2px;
  right: 3px;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 6px;
  border: 1.5px dashed var(--accent);
  background: color-mix(in srgb, var(--accent-soft) 70%, transparent);
  color: var(--accent-text);
  font-size: 12px;
  font-weight: 600;
  pointer-events: none;
}
.tg-ghost.tap { pointer-events: auto; cursor: pointer; }

.now-line {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 3;
  height: 2px;
  background: var(--danger);
  pointer-events: none;
}
.now-line::before {
  content: "";
  position: absolute;
  left: -5px;
  top: -4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger);
}

.ev-chip {
  display: block;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 12px;
  font-weight: 550;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-decoration: none;
}
.ev-chip:hover { text-decoration: none; filter: brightness(0.97); }
.ev-chip .t { font-weight: 500; opacity: 0.8; margin-right: 4px; font-variant-numeric: tabular-nums; }
.ev-chip.has-note { box-shadow: inset 2px 0 0 var(--accent); }

/* ---- Vista mese ---- */

.mg { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--surface); border-top: 1px solid var(--border); }
.mg-head { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-bottom: 1px solid var(--border); }
.mg-head div { padding: 6px 8px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-2); }
.mg-grid { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); grid-template-rows: repeat(6, minmax(0, 1fr)); }
.mg-cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 4px 4px 2px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
  cursor: pointer;
  overflow: hidden;
}
.mg-cell:nth-child(7n) { border-right: 0; }
.mg-cell:hover { background: var(--surface-2); }
.mg-cell.other { background: color-mix(in srgb, var(--bg) 60%, transparent); }
.mg-cell.other .mg-num { color: var(--text-3); }
.mg-num { font-size: 13px; font-weight: 600; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; flex: none; }
.mg-cell.today .mg-num { background: var(--accent); color: var(--accent-ink); }
.mg-events { display: flex; flex-direction: column; gap: 2px; min-height: 0; }
.mg-more { font-size: 11.5px; color: var(--text-3); padding-left: 6px; }
.mg-dots { display: none; gap: 3px; justify-content: center; }
.mg-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }

/* ---- Righe evento (elenco e pagina Oggi) ---- */

.event-row { align-items: stretch; padding: 10px 12px; }
.event-row + .event-row { border-top: 1px solid var(--border); border-radius: 0; }
.event-row > .chip { align-self: center; }
.event-time { display: flex; flex-direction: column; width: 46px; flex: none; font-size: 13px; line-height: 1.3; }
.event-time span { color: var(--text-3); }
.event-bar { width: 3px; border-radius: 2px; background: var(--accent); flex: none; }
.event-row.past { opacity: 0.6; }
.event-row.live .event-bar { background: var(--danger); }
.today-label { color: var(--accent) !important; }

/* ---- Finestra evento ---- */

.title-input { font-size: 18px; font-weight: 600; height: 44px; }
.when-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.when-grid .row { gap: 6px; }
.when-grid .time { width: 104px; flex: none; }
.people-input {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 5px 6px;
  min-height: 38px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.people-input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.people-input input { flex: 1; min-width: 140px; border: 0; outline: 0; background: transparent; padding: 2px 4px; }
.chip-x { border: 0; background: transparent; padding: 0; margin-right: -3px; color: inherit; display: grid; place-items: center; opacity: 0.7; }
.chip-x:hover { opacity: 1; }
.form-error { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--danger-soft); color: var(--danger); font-size: 13.5px; }

@media (max-width: 720px) {
  .agenda-banner { margin: 0 14px 8px; }
  .agenda-tools { width: 100%; justify-content: space-between; gap: 6px; }
  .agenda-tools .seg button { padding: 0 8px; }
  .tg { --gutter: 42px; }
  .tg-day { flex-direction: column; align-items: center; gap: 0; padding: 5px 0; }
  .tg-day .wd { font-size: 10.5px; }
  .tg-day .num { font-size: 15px; min-width: 26px; height: 26px; }
  .tg-hour span { right: 5px; font-size: 10px; }
  .ev { padding: 2px 4px 2px 5px; font-size: 11.5px; }
  .mg-events { display: none; }
  .mg-dots { display: flex; }
  .mg-cell { align-items: center; padding-top: 6px; }
  .when-grid { grid-template-columns: 1fr; }
}
