/* App admin "Orari" (public/js/admin/timetables.js): editor degli orari in stile Calendario.
   Elenco degli orari a sinistra, materie da trascinare, griglia della settimana, schede in vetro. */

.tte-app {
  display: flex;
  flex-direction: column;
}

.tte {
  --line: rgba(60, 60, 67, 0.12);
  --line-strong: rgba(60, 60, 67, 0.2);
  --sheet: rgba(250, 250, 253, 0.97);
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  container-type: inline-size;
}

:root[data-theme='dark'] .tte {
  --line: rgba(235, 235, 245, 0.1);
  --line-strong: rgba(235, 235, 245, 0.18);
  --sheet: rgba(38, 38, 46, 0.97);
}

/* --- elenco degli orari ---------------------------------------------------------------------- */

.tte-side {
  flex-shrink: 0;
  width: 220px;
  padding: 10px 8px 16px;
  overflow-y: auto;
  border-right: 0.5px solid var(--border);
  background: var(--sidebar-bg);
}

.tte-picker {
  display: none;
}

.tte-group + .tte-group {
  margin-top: 12px;
}

.tte-group h4 {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 4px 8px 4px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-3);
}

.tte-group h4 i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.tte-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 8px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--text);
  text-align: left;
}

.tte-item:hover {
  background: var(--hover);
}

.tte-item.on {
  background: var(--accent);
  color: #fff;
}

.tte-item span {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.tte-item strong {
  font-size: 13px;
  font-weight: 600;
}

.tte-item small {
  font-size: 11px;
  opacity: 0.7;
}

.tte-status {
  flex-shrink: 0;
  padding: 1px 7px;
  border-radius: 8px;
  background: var(--hover);
  color: var(--text-2);
  font-size: 10px;
  font-style: normal;
  font-weight: 700;
}

.tte-status.live {
  background: rgba(48, 209, 88, 0.16);
  color: #1f9d48;
}

.tte-item.on .tte-status {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
}

.tte-side-empty {
  margin: 8px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-2);
}

/* --- area principale ---------------------------------------------------------------------------- */

.tte-main {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.tte-welcome {
  margin: auto;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
}

.tte-welcome-icon {
  width: 46px;
  height: 46px;
  color: #ff6a3d;
}

.tte-welcome strong {
  font-size: 17px;
}

.tte-welcome span {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-2);
}

.tte-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  padding: 12px 16px 10px;
  border-bottom: 0.5px solid var(--border);
}

.tte-title {
  flex: 1;
  min-width: 200px;
}

.tte-title h3 {
  margin: 0;
  font-size: 16px;
}

.tte-title small {
  font-size: 11.5px;
  color: var(--text-3);
}

.tte-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tte-field {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tte-field small {
  font-size: 11.5px;
  color: var(--text-2);
}

.tte-ay {
  width: 84px;
  height: 28px;
  padding: 0 8px;
  font-size: 12.5px;
}

.tte-seg {
  display: inline-flex;
  padding: 2px;
  border-radius: 8px;
  background: var(--hover);
}

.tte-seg-btn {
  height: 24px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
}

.tte-seg-btn.on {
  background: var(--seg-on);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

/* Interruttore "Pubblicato", come le impostazioni di iOS */
.tte-publish {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  border: 0.5px solid var(--border);
  border-radius: 20px;
  background: var(--window-bg);
  color: var(--text);
  text-align: left;
}

.tte-publish span {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.tte-publish strong {
  font-size: 12.5px;
}

.tte-publish small {
  font-size: 10.5px;
  color: var(--text-2);
}

.tte-switch {
  position: relative;
  width: 40px;
  height: 24px;
  border-radius: 12px;
  background: rgba(120, 120, 128, 0.32);
  transition: background 0.25s;
}

.tte-switch b {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.25);
  transition: transform 0.28s cubic-bezier(0.3, 1.4, 0.5, 1);
}

.tte-publish.on .tte-switch {
  background: #34c759;
}

.tte-publish.on .tte-switch b {
  transform: translateX(16px);
}

.tte-hint {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  font-size: 11.5px;
  color: var(--text-2);
  border-bottom: 0.5px solid var(--border);
  background: var(--banner-bg);
}

.tte-hint .svg {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  color: var(--accent);
}

.tte-body {
  flex: 1;
  min-height: 0;
  display: flex;
}

/* --- materie da trascinare -------------------------------------------------------------------------- */

.tte-palette {
  flex-shrink: 0;
  width: 210px;
  padding: 10px 10px 14px;
  overflow-y: auto;
  border-right: 0.5px solid var(--border);
}

.tte-palette h4 {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 2px 2px 8px;
  font-size: 12px;
}

.tte-palette h4 small {
  font-weight: 500;
  color: var(--text-3);
}

.tte-chips {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.tte-chip {
  --c: var(--accent);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border: 0.5px solid color-mix(in srgb, var(--c) 35%, var(--border));
  border-radius: 10px;
  background: color-mix(in srgb, var(--c) 10%, var(--window-bg));
  color: var(--text);
  text-align: left;
  cursor: grab;
  user-select: none;
  transition: transform 0.15s, box-shadow 0.15s;
}

.tte-chip:hover {
  transform: translateX(2px);
  box-shadow: 0 4px 12px -6px color-mix(in srgb, var(--c) 70%, transparent);
}

.tte-chip:active {
  cursor: grabbing;
}

.tte-chip > i {
  flex-shrink: 0;
  width: 4px;
  align-self: stretch;
  border-radius: 2px;
  background: var(--c);
}

.tte-chip span {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.tte-chip strong {
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.25;
}

.tte-chip small {
  font-size: 10.5px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tte-chip em {
  flex-shrink: 0;
  font-size: 10.5px;
  font-style: normal;
  font-weight: 600;
  color: var(--text-3);
}

.tte-chip-other {
  border-style: dashed;
  background: none;
  cursor: pointer;
}

.tte-chip-other .svg {
  width: 14px;
  height: 14px;
  color: var(--text-2);
}

.tte-drag-chip {
  --c: var(--accent);
  position: fixed;
  z-index: 99999;
  padding: 6px 10px 6px 12px;
  border-radius: 10px;
  border-left: 4px solid var(--c);
  background: var(--window-bg);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.3);
  font-size: 12.5px;
  font-weight: 600;
  pointer-events: none;
  transform: rotate(-2deg);
}

.tte-drag-chip[data-when]:not([data-when=''])::after {
  content: attr(data-when);
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-2);
}

/* --- griglia ------------------------------------------------------------------------------------------ */

.tte-gridbox {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow-x: auto;
}

.tte-dayheads,
.tte-grid {
  min-width: 620px;
}

.tte-dayheads {
  display: grid;
  grid-template-columns: 46px repeat(6, 1fr);
  flex-shrink: 0;
  border-bottom: 0.5px solid var(--line-strong);
}

.tte-dayheads > div {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 5px;
  padding: 8px 0 7px;
}

.tte-dayheads strong {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-2);
}

.tte-dayheads small {
  font-size: 10.5px;
  color: var(--text-3);
}

.tte-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.tte-grid {
  position: relative;
  display: grid;
  grid-template-columns: 46px 1fr;
  margin: 8px 0 12px;
}

.tte-times {
  position: relative;
}

.tte-times span {
  position: absolute;
  right: 7px;
  transform: translateY(-50%);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  color: var(--text-3);
}

.tte-cols {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  background-image:
    linear-gradient(to bottom, var(--line-strong) 0.5px, transparent 0.5px),
    linear-gradient(to bottom, transparent calc(50% - 0.25px), var(--line) calc(50% - 0.25px), var(--line) calc(50% + 0.25px), transparent calc(50% + 0.25px));
  background-size: 100% var(--hour);
}

.tte-col {
  position: relative;
  border-left: 0.5px solid var(--line);
  cursor: crosshair;
  transition: background 0.15s;
}

.tte-col:hover {
  background: rgba(10, 132, 255, 0.03);
}

.tte-col.drop {
  background: rgba(10, 132, 255, 0.09);
  box-shadow: inset 0 0 0 1.5px rgba(10, 132, 255, 0.45);
}

.tte-ghost {
  position: absolute;
  left: 3px;
  right: 3px;
  z-index: 3;
  display: grid;
  place-items: center;
  border: 1.5px dashed var(--accent);
  border-radius: 9px;
  background: rgba(10, 132, 255, 0.12);
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 700;
  pointer-events: none;
}

.tte-lesson {
  --c: var(--accent);
  position: absolute;
  left: 3px;
  right: 3px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 5px 8px 5px 11px;
  overflow: hidden;
  border: 0.5px solid color-mix(in srgb, var(--c) 45%, transparent);
  border-radius: 9px;
  background: color-mix(in srgb, var(--c) 18%, var(--window-bg));
  box-shadow: 0 4px 12px -6px color-mix(in srgb, var(--c) 70%, transparent);
  color: var(--text);
  cursor: grab;
  user-select: none;
  animation: tte-pop 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
  transition: box-shadow 0.15s, transform 0.15s;
}

.tte-lesson::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 5px;
  bottom: 5px;
  width: 3px;
  border-radius: 2px;
  background: var(--c);
}

.tte-lesson:hover,
.tte-lesson:focus-visible {
  z-index: 4;
  box-shadow: 0 10px 24px -10px color-mix(in srgb, var(--c) 90%, transparent), 0 0 0 1.5px var(--c);
  outline: none;
}

/* Dopo una modifica la griglia si ridisegna senza far "saltare" tutte le lezioni */
.tte-grid.still .tte-lesson {
  animation: none;
}

.tte-lesson.dragging {
  z-index: 5;
  cursor: grabbing;
  opacity: 0.92;
  transform: scale(1.02);
  box-shadow: 0 16px 34px -10px rgba(0, 0, 0, 0.4), 0 0 0 1.5px var(--c);
  transition: none;
  animation: none;
}

.tte-lesson.clash {
  box-shadow: 0 0 0 2px #ff3b30, 0 16px 34px -10px rgba(255, 59, 48, 0.5);
  background: color-mix(in srgb, #ff3b30 18%, var(--window-bg));
}

.tte-lesson strong {
  font-size: 12px;
  font-weight: 650;
  line-height: 1.2;
  color: color-mix(in srgb, var(--c) 45%, var(--text));
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tte-lesson-time,
.tte-lesson-room,
.tte-lesson-who {
  font-size: 10.5px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tte-lesson-time {
  font-variant-numeric: tabular-nums;
}

.tte-lesson-room {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-weight: 600;
  color: var(--text);
}

.tte-lesson-room .svg {
  width: 11px;
  height: 11px;
}

/* Aula non ancora indicata: lo facciamo notare */
.tte-lesson-room.missing {
  color: #ff9f0a;
  font-style: italic;
}

.tte-resize {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 11px;
  cursor: ns-resize;
}

.tte-resize::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 2px;
  width: 22px;
  height: 3px;
  border-radius: 2px;
  background: color-mix(in srgb, var(--c) 60%, transparent);
  transform: translateX(-50%);
  opacity: 0;
  transition: opacity 0.15s;
}

.tte-lesson:hover .tte-resize::after {
  opacity: 1;
}

/* --- annulla ---------------------------------------------------------------------------------------- */

.tte-undo {
  position: absolute;
  left: 50%;
  bottom: 16px;
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 8px 14px;
  border-radius: 18px;
  background: rgba(28, 28, 30, 0.9);
  color: #fff;
  font-size: 12.5px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  transform: translateX(-50%);
  animation: tte-rise 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.tte-undo small {
  opacity: 0.55;
  font-size: 11px;
}

.tte-undo button {
  padding: 4px 10px;
  border: 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
}

/* --- schede (lezione, nuovo orario, duplica) ------------------------------------------------------------ */

.tte-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
}

.tte-scrim {
  position: absolute;
  inset: 0;
  background: rgba(10, 12, 30, 0.25);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.tte-sheet {
  position: relative;
  width: min(460px, 100%);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 18px;
  overflow-y: auto;
  border: 0.5px solid var(--border);
  border-radius: 20px;
  background: var(--sheet);
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  animation: tte-rise 0.32s cubic-bezier(0.2, 0.9, 0.3, 1.15);
}

.tte-create {
  width: min(600px, 100%);
}

.tte-sheet header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tte-sheet h3 {
  flex: 1;
  margin: 0;
  font-size: 17px;
}

.tte-sheet-color {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  box-shadow: 0 0 10px currentColor;
}

.tte-x {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--hover);
  color: var(--text-2);
}

.tte-x .svg {
  width: 13px;
  height: 13px;
}

.tte-form-row {
  display: grid;
  grid-template-columns: 112px 1fr;
  align-items: center;
  gap: 10px;
}

.tte-form-row[hidden] {
  display: none;
}

.tte-form-row > span {
  font-size: 12.5px;
  color: var(--text-2);
}

.tte-form-row .field {
  width: 100%;
  min-width: 0;
}

.tte-days {
  display: flex;
  gap: 4px;
}

.tte-day {
  flex: 1;
  height: 30px;
  border: 0.5px solid var(--btn-border);
  border-radius: 8px;
  background: var(--btn-bg);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
}

.tte-day.on {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.tte-times-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tte-times-row .field {
  width: 100px;
}

.tte-times-row b {
  color: var(--text-3);
}

.tte-duration {
  margin-left: 4px;
  font-size: 12px;
  color: var(--text-2);
}

.tte-duration.bad {
  color: #ff3b30;
}

.tte-error {
  margin: 0;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 59, 48, 0.1);
  color: #d70015;
  font-size: 12.5px;
}

:root[data-theme='dark'] .tte-error {
  color: #ff6961;
}

.tte-sheet footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
}

.tte-sheet footer > div {
  display: flex;
  gap: 8px;
}

.tte-note {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--text-2);
}

.tte-create-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tte-create-body h4 {
  margin: 0 0 6px;
  font-size: 12.5px;
}

.tte-create-body .appear {
  animation: tte-rise 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.15);
}

.tte-create-extra {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 10px;
  border-top: 0.5px solid var(--line);
}

.tte-opts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 6px;
}

.tte-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tte-opt {
  --c: var(--accent);
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 6px 12px;
  border: 0.5px solid var(--btn-border);
  border-radius: 10px;
  background: var(--btn-bg);
  color: var(--text);
  text-align: left;
}

.tte-opt i {
  flex-shrink: 0;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--c);
}

.tte-opt span {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.tte-opt strong {
  font-size: 12.5px;
}

.tte-opt small {
  font-size: 10.5px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tte-opt.on {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--btn-bg));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.tte-opt:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

@keyframes tte-pop {
  from {
    opacity: 0;
    transform: scale(0.94);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes tte-rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* --- finestre strette (telefono) ---------------------------------------------------------------------------- */

@container (max-width: 760px) {
  .tte {
    flex-direction: column;
  }

  .tte-side {
    width: auto;
    padding: 8px 12px;
    border-right: 0;
    border-bottom: 0.5px solid var(--border);
    overflow: visible;
  }

  .tte-group,
  .tte-side-empty {
    display: none;
  }

  .tte-picker {
    display: block;
    width: 100%;
  }

  .tte-body {
    flex-direction: column;
  }

  .tte-palette {
    width: auto;
    max-height: 132px;
    border-right: 0;
    border-bottom: 0.5px solid var(--border);
  }

  .tte-chips {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .tte-chip {
    flex: 1 1 150px;
  }

  .tte-hint {
    display: none;
  }

  .tte-form-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}
