/* ==========================================================================
   Design System & Styling per Orario Scolastico ICS Veneziano - Novelli
   ========================================================================== */

:root {
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  
  /* Primary & Accents */
  --color-primary: #2563EB;
  --color-primary-hover: #1D4ED8;
  --color-primary-light: #EFF6FF;
  --color-indigo: #4F46E5;
  --color-emerald: #10B981;
  --color-emerald-dark: #059669;
  --color-amber: #F59E0B;
  --color-rose: #F43F5E;
  --color-slate-50: #F8FAFC;
  --color-slate-100: #F1F5F9;
  --color-slate-200: #E2E8F0;
  --color-slate-300: #CBD5E1;
  --color-slate-400: #94A3B8;
  --color-slate-500: #64748B;
  --color-slate-600: #475569;
  --color-slate-700: #334155;
  --color-slate-800: #1E293B;
  --color-slate-900: #0F172A;

  --bg-app: #F8FAFC;
  --bg-surface: #FFFFFF;
  --border-color: #E2E8F0;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-app);
  color: var(--color-slate-800);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ================= HEADER ================= */
.app-header {
  background: linear-gradient(135deg, #0F172A 0%, #1E293B 100%);
  color: #FFFFFF;
  padding: 1.25rem 2rem 1rem 2rem;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1.5rem;
  max-width: 1700px;
  margin: 0 auto;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.brand-logo {
  width: 52px;
  height: 52px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
}

.brand-badge {
  display: inline-block;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  font-weight: 700;
  background: rgba(59, 130, 246, 0.25);
  color: #93C5FD;
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
  margin-bottom: 0.25rem;
  border: 1px solid rgba(147, 197, 253, 0.3);
}

.brand-name {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.brand-subtitle {
  font-size: 0.85rem;
  color: var(--color-slate-400);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* ================= METRICS BAR ================= */
.metrics-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  max-width: 1700px;
  margin: 1rem auto 0 auto;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.metric-chip {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
}

.metric-label {
  color: var(--color-slate-400);
}

.metric-val {
  font-weight: 700;
  color: #FFFFFF;
}

.chip-success {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.3);
}
.chip-success .metric-val {
  color: #6EE7B7;
}

.chip-info {
  background: rgba(59, 130, 246, 0.15);
  border-color: rgba(59, 130, 246, 0.3);
}
.chip-info .metric-val {
  color: #93C5FD;
}

.text-success {
  color: #10B981 !important;
}

/* ================= BUTTONS ================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 1rem;
  font-size: 0.88rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease-in-out;
  border: none;
  text-decoration: none;
}

.btn-primary {
  background: linear-gradient(135deg, #2563EB 0%, #1D4ED8 100%);
  color: #FFFFFF;
  box-shadow: 0 2px 4px rgba(37, 99, 235, 0.3);
}
.btn-primary:hover {
  background: linear-gradient(135deg, #1D4ED8 0%, #1E40AF 100%);
  transform: translateY(-1px);
}

.btn-emerald {
  background: linear-gradient(135deg, #10B981 0%, #059669 100%);
  color: #FFFFFF;
  box-shadow: 0 2px 4px rgba(16, 185, 129, 0.3);
}
.btn-emerald:hover {
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
  transform: translateY(-1px);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.12);
  color: #FFFFFF;
  border: 1px solid rgba(255, 255, 255, 0.2);
}
.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.2);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--color-slate-700);
}
.btn-outline:hover {
  background: var(--color-slate-100);
}

.btn-xs {
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
}

/* ================= TABS NAVIGATION ================= */
.main-tabs {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 105px;
  z-index: 40;
}

.tabs-container {
  max-width: 1700px;
  margin: 0 auto;
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 2rem 0 2rem;
  overflow-x: auto;
}

.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 0.75rem 1.25rem;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--color-slate-600);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.tab-btn:hover {
  color: var(--color-primary);
  background: var(--color-slate-50);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.tab-btn.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
  background: transparent;
}

/* ================= MAIN CONTENT ================= */
.app-content {
  flex: 1;
  max-width: 1700px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 2rem;
}

.tab-panel {
  display: none;
}
.tab-panel.active {
  display: block;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.panel-title {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--color-slate-900);
}

.panel-desc {
  font-size: 0.88rem;
  color: var(--color-slate-500);
}

.panel-tools {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

/* Form Controls */
.search-input, .custom-select, .form-control {
  padding: 0.5rem 0.85rem;
  font-size: 0.88rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--color-slate-800);
  outline: none;
  transition: border-color 0.15s;
}
.search-input:focus, .custom-select:focus, .form-control:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.search-input {
  min-width: 250px;
}

.select-label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--color-slate-700);
}

.custom-select {
  font-weight: 600;
  cursor: pointer;
}

/* ================= TABLES ================= */
.table-container {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
  margin-bottom: 1.5rem;
}

.master-table-wrapper {
  max-height: 75vh;
  overflow-y: auto;
}

.timetable-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  text-align: center;
}

.timetable-table th, .timetable-table td {
  border: 1px solid var(--border-color);
  padding: 0.5rem;
}

.timetable-table thead th {
  background: var(--color-slate-800);
  color: #FFFFFF;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 10;
}

.day-header {
  background: var(--color-primary) !important;
  color: #FFFFFF;
  font-size: 0.88rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.5rem !important;
}

.hour-sub-header {
  background: var(--color-slate-100) !important;
  color: var(--color-slate-700) !important;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.35rem !important;
}

.class-row-header {
  background: var(--color-slate-100);
  font-weight: 700;
  color: var(--color-slate-800);
  position: sticky;
  left: 0;
  z-index: 5;
  width: 65px;
}

/* Master Grid Cells */
.master-cell {
  height: 52px;
  min-width: 110px;
  padding: 0.3rem !important;
  vertical-align: middle;
  font-size: 0.78rem;
  transition: transform 0.1s, box-shadow 0.1s;
}
.master-cell:hover {
  filter: brightness(0.97);
  box-shadow: inset 0 0 0 2px var(--color-primary);
}

.cell-subject {
  font-weight: 700;
  line-height: 1.2;
}

.cell-teacher {
  font-size: 0.7rem;
  color: var(--color-slate-600);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Single Grid (Class / Teacher) */
.single-grid-table {
  table-layout: fixed;
  width: 100%;
}

.single-grid-table th:first-child,
.single-grid-table td:first-child {
  width: 145px !important;
  min-width: 145px !important;
  max-width: 145px !important;
  text-align: center;
  padding: 0.5rem;
  vertical-align: middle;
}

.single-grid-table th:not(:first-child) {
  width: calc((100% - 145px) / 5);
}

.single-grid-table td:not(:first-child) {
  height: 88px;
  vertical-align: top;
  padding: 0.5rem;
  width: calc((100% - 145px) / 5);
}

.lesson-card {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
}
.lesson-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.lesson-card.is-selected {
  outline: 3px solid var(--color-primary);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.25);
}

.lesson-card.is-swap-target {
  outline: 2px dashed var(--color-emerald);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.02); }
  100% { transform: scale(1); }
}

.lc-subject {
  font-weight: 700;
  font-size: 0.95rem;
}

.lc-teacher {
  font-size: 0.82rem;
  color: var(--color-slate-600);
  margin-top: 0.25rem;
}

.lc-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.72rem;
  margin-top: 0.35rem;
}

.time-col-cell {
  background: var(--color-slate-50);
  vertical-align: middle !important;
  padding: 0.4rem !important;
  text-align: center;
}

.time-slot-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.5rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  white-space: nowrap;
  width: 100%;
}

.time-slot-num {
  font-size: 0.92rem;
  font-weight: 800;
  color: var(--color-slate-900);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.time-slot-hours {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--color-slate-500);
  margin-top: 0.2rem;
  white-space: nowrap;
}

.free-slot {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-slate-400);
  font-size: 0.85rem;
  font-style: italic;
  border: 1px dashed var(--color-slate-300);
  border-radius: var(--radius-sm);
  background: var(--color-slate-50);
}

.gap-slot {
  background: #FEF3C7 !important;
  border: 1px solid #FCD34D !important;
  color: #B45309 !important;
  font-weight: 600;
}

/* ================= BANNER & CARDS ================= */
.teacher-info-banner {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.badge-area {
  background: var(--color-primary-light);
  color: var(--color-primary);
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.t-banner-metrics {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.t-stat {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.t-stat-label {
  font-size: 0.75rem;
  color: var(--color-slate-500);
}

.t-stat-num {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-slate-900);
}

.badge-pill {
  color: var(--color-emerald-dark);
  background: #ECFDF5;
  padding: 0.1rem 0.5rem;
  border-radius: 9999px;
  border: 1px solid #A7F3D0;
}

.class-summary-card {
  display: flex;
  gap: 2rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem 1.5rem;
  margin-bottom: 1.25rem;
}

.cs-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.cs-label {
  font-size: 0.85rem;
  color: var(--color-slate-500);
}
.cs-value {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--color-slate-800);
}

.swap-indicator {
  background: #FEF3C7;
  border: 1px solid #FCD34D;
  color: #92400E;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* ================= DATA TABLES ================= */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  text-align: left;
}
.data-table th {
  background: var(--color-slate-100);
  color: var(--color-slate-700);
  font-weight: 600;
  padding: 0.75rem 1rem;
  border-bottom: 2px solid var(--border-color);
}
.data-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--color-slate-800);
}
.data-table tr:hover {
  background: var(--color-slate-50);
}

.desiderata-info-alert {
  background: #EFF6FF;
  border: 1px solid #BFDBFE;
  color: #1E40AF;
  padding: 0.9rem 1.25rem;
  border-radius: var(--radius-md);
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  font-size: 0.88rem;
  margin-bottom: 1.25rem;
}
.alert-icon {
  font-size: 1.25rem;
}

/* ================= STATS CARDS ================= */
.stats-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.sc-title {
  font-size: 0.85rem;
  color: var(--color-slate-500);
  font-weight: 500;
}

.sc-val {
  font-size: 1.8rem;
  font-weight: 800;
  margin: 0.25rem 0;
}

.sc-sub {
  font-size: 0.78rem;
  color: var(--color-slate-400);
}

.text-emerald { color: var(--color-emerald-dark); }
.text-amber { color: var(--color-amber); }

/* ================= MODAL ================= */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-dialog {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  max-width: 540px;
  width: 90%;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-header {
  padding: 1.25rem 1.5rem;
  background: var(--color-slate-50);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--color-slate-900);
}

.btn-close-modal {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--color-slate-400);
}
.btn-close-modal:hover {
  color: var(--color-slate-700);
}

.modal-body {
  padding: 1.5rem;
}

.modal-intro {
  font-size: 0.88rem;
  color: var(--color-slate-600);
  margin-bottom: 1.25rem;
}

.form-group {
  margin-bottom: 1.25rem;
}
.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-slate-700);
  margin-bottom: 0.35rem;
}

.form-hint {
  display: block;
  font-size: 0.75rem;
  color: var(--color-slate-400);
  margin-top: 0.25rem;
}

.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.form-row {
  display: flex;
  gap: 1rem;
}
.col-half {
  flex: 1;
}

.modal-dialog-lg {
  max-width: 780px;
  width: 94%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-body-scrollable {
  overflow-y: auto;
  max-height: calc(90vh - 135px);
  padding: 1.25rem 1.5rem;
}

.modal-section-card {
  background: var(--color-slate-50);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
}

.modal-section-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--color-slate-900);
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* Griglia indisponibilità orarie */
.unavail-grid-wrapper {
  overflow-x: auto;
}

.unavail-table {
  width: 100%;
  border-collapse: collapse;
  text-align: center;
  font-size: 0.82rem;
}

.unavail-table th {
  background: #FFFFFF;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border-color);
  font-weight: 700;
  color: var(--color-slate-700);
}

.unavail-cell {
  padding: 0.45rem 0.4rem;
  border: 1px solid var(--border-color);
  cursor: pointer;
  background: #FFFFFF;
  transition: all 0.15s ease;
  user-select: none;
}

.unavail-cell:hover {
  background: #F1F5F9;
}

.unavail-cell.is-blocked {
  background: #FEE2E2 !important;
  color: #DC2626;
  font-weight: 700;
  border-color: #FCA5A5;
}

.unavail-cell.is-available {
  color: #10B981;
  font-weight: 600;
}

/* Assegnazioni classi */
.assignments-list-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  min-height: 42px;
  padding: 0.5rem;
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
}

.assignment-badge-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--color-slate-100);
  border: 1px solid var(--color-slate-300);
  border-radius: 9999px;
  padding: 0.25rem 0.65rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-slate-800);
}

.assignment-badge-item .btn-remove-assign {
  background: none;
  border: none;
  color: #EF4444;
  cursor: pointer;
  font-weight: 800;
  padding: 0 0.2rem;
  font-size: 0.95rem;
  line-height: 1;
}

.assignment-badge-item .btn-remove-assign:hover {
  color: #B91C1C;
}

/* Sortable table headers */
.sortable-th {
  user-select: none;
  transition: background 0.15s ease;
}

.sortable-th:hover {
  background: rgba(241, 245, 249, 0.8);
}

.sort-indicator {
  font-size: 0.75rem;
  opacity: 0.6;
  margin-left: 0.25rem;
}

.sortable-th.active-sort .sort-indicator {
  opacity: 1;
  font-weight: bold;
  color: var(--color-blue-primary);
}

.modal-footer {
  padding: 1rem 1.5rem;
  background: var(--color-slate-50);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

.gen-status-box {
  background: #F0FDF4;
  border: 1px solid #BBF7D0;
  padding: 1rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: #166534;
  font-weight: 600;
  font-size: 0.88rem;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 3px solid rgba(22, 101, 52, 0.2);
  border-top-color: #166534;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ================= TOASTS ================= */
.toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background: var(--color-slate-900);
  color: #FFFFFF;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 0.88rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  animation: slideIn 0.2s ease-out;
}

.toast.toast-error {
  background: #991B1B;
}

.toast.toast-success {
  background: #065F46;
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.hidden {
  display: none !important;
}

/* ================= FLOATING UNIVERSAL SWAP BAR ================= */
.universal-swap-bar {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-slate-900);
  color: #FFFFFF;
  padding: 0.85rem 1.5rem;
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.35);
  z-index: 150;
  display: flex;
  align-items: center;
  max-width: 900px;
  width: 90%;
  border: 1px solid rgba(255, 255, 255, 0.15);
  animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
  from { transform: translate(-50%, 100%); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

.usb-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 1.25rem;
}

.usb-icon {
  font-size: 1.5rem;
  background: rgba(59, 130, 246, 0.2);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.usb-text {
  flex: 1;
}

.usb-title {
  font-weight: 700;
  font-size: 0.92rem;
  color: #93C5FD;
}

.usb-desc {
  font-size: 0.82rem;
  color: var(--color-slate-300);
  margin-top: 0.1rem;
}

.usb-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

/* Slot Modal Boxes */
.slot-info-box {
  background: var(--color-slate-50);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.slot-preview-box {
  background: var(--color-slate-50);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  font-size: 0.85rem;
  margin-top: 0.75rem;
}

.master-cell {
  cursor: pointer;
}

.master-cell.is-selected {
  outline: 3px solid var(--color-primary) !important;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.4) !important;
  z-index: 8;
  position: relative;
}

.master-cell.is-swap-target {
  animation: pulse 1.5s infinite;
  outline: 2px dashed var(--color-emerald) !important;
}

/* ================= COMPONENTI ASSISTENTE IA & STILI EXTRA ================= */
.highlight-tab {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.12), rgba(168, 85, 247, 0.12)) !important;
  color: #6366F1 !important;
  border: 1px solid rgba(99, 102, 241, 0.25) !important;
  font-weight: 600;
}
.highlight-tab:hover, .highlight-tab.active {
  background: linear-gradient(135deg, #6366F1, #8B5CF6) !important;
  color: #FFFFFF !important;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
}

.ai-grid-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-top: 1rem;
}
@media (max-width: 992px) {
  .ai-grid-container {
    grid-template-columns: 1fr;
  }
}

.ai-card {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.card-header-icon {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 1.25rem;
}
.icon-avatar {
  font-size: 2rem;
  background: var(--color-slate-100);
  padding: 0.5rem 0.75rem;
  border-radius: 12px;
  line-height: 1;
}

.pdf-drop-zone {
  border: 2px dashed var(--color-slate-300);
  border-radius: 12px;
  padding: 2rem 1.5rem;
  text-align: center;
  background: var(--color-slate-50);
  cursor: pointer;
  transition: all 0.2s ease;
}
.pdf-drop-zone:hover, .pdf-drop-zone.dragover {
  border-color: #6366F1;
  background: rgba(99, 102, 241, 0.05);
}
.drop-icon {
  font-size: 2.5rem;
  display: block;
  margin-bottom: 0.5rem;
}

.spinner-inline {
  display: inline-block;
  width: 2rem;
  height: 2rem;
  border: 3px solid rgba(99, 102, 241, 0.2);
  border-radius: 50%;
  border-top-color: #6366F1;
  animation: spin 0.8s linear infinite;
}

.quick-prompts-container {
  background: var(--color-slate-50);
  padding: 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--color-slate-200);
}
.chip-btn {
  background: #FFFFFF;
  border: 1px solid var(--color-slate-300);
  border-radius: 20px;
  padding: 0.25rem 0.65rem;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s ease;
  color: var(--color-slate-700);
}
.chip-btn:hover {
  background: #6366F1;
  color: #FFFFFF;
  border-color: #6366F1;
}

.ai-chat-history {
  flex: 1;
  min-height: 250px;
  max-height: 380px;
  overflow-y: auto;
  padding: 1rem;
  background: var(--color-slate-50);
  border: 1px solid var(--color-slate-200);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.ai-msg {
  display: flex;
  flex-direction: column;
}
.ai-msg-bot {
  align-items: flex-start;
}
.ai-msg-user {
  align-items: flex-end;
}
.ai-bubble {
  max-width: 85%;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  font-size: 0.85rem;
  line-height: 1.45;
}
.ai-msg-bot .ai-bubble {
  background: #FFFFFF;
  border: 1px solid var(--color-slate-200);
  color: var(--color-slate-800);
  box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}
.ai-msg-user .ai-bubble {
  background: #6366F1;
  color: #FFFFFF;
}

.ai-action-badge {
  display: inline-block;
  margin-top: 0.4rem;
  padding: 0.2rem 0.5rem;
  background: #ECFDF5;
  color: #065F46;
  border: 1px solid #A7F3D0;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
}

.ai-input-bar {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}
.ai-input-bar textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--color-slate-300);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font-family: inherit;
  font-size: 0.85rem;
}
.ai-input-bar textarea:focus {
  outline: none;
  border-color: #6366F1;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.sortable-th {
  transition: background 0.15s ease;
  user-select: none;
}
.sortable-th:hover {
  background: var(--color-slate-200) !important;
}
.sortable-th.active-sort {
  background: #E2E8F0 !important;
  color: var(--color-slate-900) !important;
  font-weight: 700;
}

/* ================= PRINT STYLING (A4 ORIZZONTALE OTTIMIZZATO AL 100%) ================= */
@page {
  size: landscape;
  margin: 4mm 4mm 4mm 4mm;
}

@media print {
  html, body {
    width: 100% !important;
    height: auto !important;
    background: #FFFFFF !important;
    color: #000000 !important;
    font-size: 8pt !important;
    margin: 0 !important;
    padding: 0 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Nascondi tutti i controlli ed elementi non stampabili */
  .app-header,
  .main-tabs,
  .panel-tools,
  .header-actions,
  .universal-swap-bar,
  .modal-overlay,
  .toast-container,
  .btn,
  .print-tab-btn,
  .search-input,
  .search-box,
  .swap-indicator,
  .card-header-bar .search-box {
    display: none !important;
  }

  .app-content {
    max-width: 100% !important;
    width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  /* Mostra solo la scheda attiva */
  .tab-panel {
    display: none !important;
  }
  .tab-panel.active {
    display: block !important;
  }

  .panel-header {
    margin-bottom: 4px !important;
    padding-bottom: 2px !important;
  }
  .panel-title {
    font-size: 13pt !important;
    margin: 0 !important;
    color: #000000 !important;
  }
  .panel-desc {
    font-size: 7.5pt !important;
    color: #475569 !important;
    margin-bottom: 4px !important;
  }

  .table-container {
    border: 1px solid #94A3B8 !important;
    box-shadow: none !important;
    overflow: visible !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* TABELLONE GENERALE (31 colonne): Compressione massima su pagina A4 orizzontale */
  .master-table {
    width: 100% !important;
    table-layout: fixed !important;
    border-collapse: collapse !important;
    font-size: 6pt !important;
    line-height: 1.05 !important;
  }
  .master-table th, 
  .master-table td {
    padding: 1px 1px !important;
    height: 18px !important;
    border: 1px solid #CBD5E1 !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
  }
  .master-table th.class-row-header,
  .master-table td.class-row-header {
    width: 32px !important;
    font-size: 6.5pt !important;
    font-weight: bold !important;
  }
  .master-cell-subject {
    font-size: 5.5pt !important;
    font-weight: bold !important;
    line-height: 1 !important;
  }
  .master-cell-teacher {
    font-size: 5pt !important;
    line-height: 1 !important;
  }

  /* VISTA SINGOLA CLASSE E DOCENTE (6 colonne): riempimento elegante */
  .single-grid-table {
    width: 100% !important;
    table-layout: fixed !important;
    border-collapse: collapse !important;
    font-size: 9pt !important;
  }
  .single-grid-table th, 
  .single-grid-table td {
    padding: 6px 8px !important;
    border: 1px solid #64748B !important;
  }
  .class-summary-card, .teacher-info-banner {
    border: 1px solid #CBD5E1 !important;
    background: #F8FAFC !important;
    margin-bottom: 6px !important;
    padding: 6px 12px !important;
  }

  /* TABELLA STATISTICHE */
  .data-table {
    width: 100% !important;
    border-collapse: collapse !important;
    font-size: 7.5pt !important;
  }
  .data-table th, .data-table td {
    padding: 3px 6px !important;
    border: 1px solid #CBD5E1 !important;
  }

  tr {
    page-break-inside: avoid !important;
  }
}

