:root {
  --polimi-blue: #002d5a;
  --polimi-navy: #001a35;
  --polimi-accent: #0284c7;
  --polimi-accent-hover: #0369a1;
  --polimi-accent-light: #e0f2fe;
  --polimi-gold: #c29b38;
  --polimi-gold-light: #fef9c3;
  --slate-50: #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;
  --emerald-50: #ecfdf5;
  --emerald-100: #d1fae5;
  --emerald-600: #059669;
  --emerald-700: #047857;
  --amber-50: #fffbeb;
  --amber-100: #fef3c7;
  --amber-600: #d97706;
  --amber-700: #b45309;
  --indigo-50: #eef2ff;
  --indigo-100: #e0e7ff;
  --indigo-600: #4f46e5;
  --indigo-700: #4338ca;
  --rose-50: #fff1f2;
  --rose-100: #ffe4e6;
  --rose-600: #e11d48;
  --rose-700: #be123c;
  --border-radius: 10px;
  --border-radius-sm: 6px;
  --box-shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --box-shadow-md: 0 6px 12px -2px rgba(0, 0, 0, 0.08), 0 3px 6px -3px rgba(0, 0, 0, 0.06);
  --box-shadow-lg: 0 10px 20px -3px rgba(0, 0, 0, 0.12), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
  
  /* Layout constraints */
  --max-content-width: 1480px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: #f1f5f9;
  color: var(--slate-800);
  line-height: 1.5;
  font-size: 14px;
  min-height: 100vh;
}

/* ==========================================================================
   HEADER
   ========================================================================== */
header.site-header {
  background: linear-gradient(135deg, var(--polimi-navy) 0%, #00254a 50%, var(--polimi-blue) 100%);
  color: white;
  padding: 0.85rem 1.5rem;
  border-bottom: 3px solid var(--polimi-gold);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--box-shadow-md);
}

.header-inner {
  max-width: var(--max-content-width);
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.polimi-logo-badge {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fef08a;
  flex-shrink: 0;
}

.header-titles h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.3;
}

.header-titles .subtitle {
  font-size: 0.825rem;
  color: var(--slate-300);
  margin-top: 0.15rem;
}

.header-titles .subtitle strong {
  color: white;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
}

.plan-summary-pill {
  background: rgba(15, 23, 42, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #f8fafc;
  padding: 0.45rem 0.95rem;
  border-radius: 24px;
  font-size: 0.85rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  cursor: pointer;
  transition: all 0.2s ease;
  backdrop-filter: blur(4px);
}

.plan-summary-pill:hover {
  background: rgba(15, 23, 42, 0.65);
  border-color: rgba(255, 255, 255, 0.4);
  transform: translateY(-1px);
}

.req-status-pill {
  padding: 0.2rem 0.65rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-left: 0.25rem;
}
.req-status-pill.pill-ok {
  background: #059669;
  color: white;
}
.req-status-pill.pill-pending {
  background: #d97706;
  color: white;
}
.req-status-pill.pill-error {
  background: #e11d48;
  color: white;
}

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

.header-actions .btn {
  padding: 0.45rem 0.85rem;
  border-radius: var(--border-radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.header-actions .btn-secondary {
  text-decoration: none;
  background: rgba(255, 255, 255, 0.12);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.25);
}
.header-actions .btn-secondary:hover {
  background: rgba(255, 255, 255, 0.22);
  border-color: white;
}


.header-actions .btn-telegram {
  background: rgba(36, 161, 222, 0.2);
  border-color: rgba(36, 161, 222, 0.45);
  color: #7dd3fc;
}
.header-actions .btn-telegram:hover {
  background: rgba(36, 161, 222, 0.35);
  border-color: #38bdf8;
  color: white;
}

.header-actions .btn-secondary.btn-accent {
  background: #0284c7;
  border-color: #38bdf8;
  color: white;
}

/* ==========================================================================
   MAIN CONTAINER (Constrained readable width + centered)
   ========================================================================== */
.main-container {
  max-width: var(--max-content-width);
  margin: 1.25rem auto;
  padding: 0 1.5rem 3rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ==========================================================================
   VALIDATION REQUIREMENTS DASHBOARD CARD
   ========================================================================== */
.validation-card {
  background: white;
  border-radius: var(--border-radius);
  box-shadow: var(--box-shadow);
  border: 1px solid var(--slate-200);
  overflow: hidden;
}

.validation-header {
  padding: 0.85rem 1.25rem;
  background: linear-gradient(to right, #f8fafc, #f1f5f9);
  border-bottom: 1px solid var(--slate-200);
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s ease;
}
.validation-header:hover {
  background: #eef2f6;
}

.validation-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--polimi-blue);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.validation-body {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.req-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.85rem;
}

.req-box {
  background: #fafbfc;
  border: 1.5px solid var(--slate-200);
  border-radius: 8px;
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  position: relative;
  transition: all 0.2s ease;
}

.req-box.status-valid {
  border-color: #86efac;
  background: #f0fdf4;
}

.req-box.status-missing {
  border-color: #fde68a;
  background: #fffbeb;
}

.req-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.req-name {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--slate-800);
}

.req-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  white-space: nowrap;
}
.req-badge.badge-valid {
  background: #dcfce7;
  color: #15803d;
}
.req-badge.badge-missing {
  background: #fee2e2;
  color: #b91c1c;
}

.req-cfu-display {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
}

.req-cfu-current {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--slate-900);
}

.req-cfu-target {
  font-size: 0.775rem;
  color: var(--slate-500);
  font-weight: 500;
}

.req-progress-bar-bg {
  width: 100%;
  height: 6px;
  background: var(--slate-200);
  border-radius: 3px;
  overflow: hidden;
}

.req-progress-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease;
}
.req-progress-bar-fill.fill-valid {
  background: var(--emerald-600);
}
.req-progress-bar-fill.fill-missing {
  background: var(--amber-600);
}

.req-info-sub {
  display: flex;
  justify-content: space-between;
  font-size: 0.725rem;
  color: var(--slate-500);
}

.rules-callout {
  background: #f8fafc;
  border: 1px solid var(--slate-200);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  font-size: 0.775rem;
  color: var(--slate-600);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.validation-summary-banner {
  padding: 0.85rem 1rem;
  border-radius: 8px;
  font-size: 0.825rem;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}
.validation-summary-banner.banner-valid {
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #065f46;
}
.validation-summary-banner.banner-missing {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
}

/* ==========================================================================
   GENERAL INFO CARD
   ========================================================================== */
.info-card {
  background: white;
  border-radius: var(--border-radius);
  box-shadow: var(--box-shadow);
  border: 1px solid var(--slate-200);
  overflow: hidden;
}

.info-header {
  padding: 0.75rem 1.25rem;
  background: #f8fafc;
  border-bottom: 1px solid var(--slate-200);
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
}
.info-header:hover {
  background: #f1f5f9;
}

.info-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--slate-700);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.info-body {
  padding: 1rem 1.25rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  background: white;
}

.info-field label {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--slate-500);
  margin-bottom: 0.15rem;
}

.info-field .value {
  font-size: 0.85rem;
  color: var(--slate-800);
  font-weight: 500;
}

/* ==========================================================================
   CONTROLS & SEARCH PANEL (Uniform, Modern, Sticky)
   ========================================================================== */
.controls-panel {
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: var(--border-radius);
  box-shadow: 0 4px 20px -2px rgba(0, 0, 0, 0.07), 0 2px 6px -1px rgba(0, 0, 0, 0.04);
  border: 1px solid var(--slate-200);
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  position: sticky;
  top: 72px;
  z-index: 90;
  transition: box-shadow 0.2s ease;
}

/* Row 1: Search and Primary Action Buttons */
.search-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.search-box-wrap {
  flex: 1 1 320px;
  min-width: 260px;
  position: relative;
}

.search-icon {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--slate-400);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 38px;
  padding: 0 2.2rem 0 2.4rem;
  border: 1.5px solid var(--slate-300);
  border-radius: var(--border-radius-sm);
  font-size: 0.85rem;
  color: var(--slate-800);
  background: white;
  outline: none;
  transition: all 0.2s ease;
}
.search-input:focus {
  border-color: var(--polimi-accent);
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}
.search-input::placeholder {
  color: var(--slate-400);
}

.search-clear-btn {
  position: absolute;
  right: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  background: var(--slate-200);
  border: none;
  color: var(--slate-600);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  cursor: pointer;
  line-height: 1;
  transition: all 0.15s ease;
}
.search-clear-btn:hover {
  background: var(--slate-300);
  color: var(--slate-900);
}

.controls-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.results-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0 0.75rem;
  height: 38px;
  background: var(--slate-100);
  border: 1px solid var(--slate-200);
  border-radius: var(--border-radius-sm);
  font-size: 0.775rem;
  color: var(--slate-600);
  white-space: nowrap;
  user-select: none;
}
.results-number {
  font-weight: 700;
  color: var(--polimi-blue);
  font-size: 0.9rem;
}
.results-label {
  font-weight: 500;
}

.view-buttons-group {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.btn-ctrl {
  height: 38px;
  padding: 0 0.8rem;
  border-radius: var(--border-radius-sm);
  font-size: 0.775rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  user-select: none;
}

.btn-ctrl-secondary {
  background: white;
  border: 1.5px solid var(--slate-300);
  color: var(--slate-700);
}
.btn-ctrl-secondary:hover {
  background: var(--slate-100);
  border-color: var(--slate-400);
  color: var(--slate-900);
}

.btn-ctrl-reset {
  background: white;
  border: 1.5px solid var(--slate-300);
  color: var(--slate-600);
}
.btn-ctrl-reset:not(:disabled) {
  background: #fef2f2;
  border-color: #fca5a5;
  color: #b91c1c;
}
.btn-ctrl-reset:not(:disabled):hover {
  background: #fee2e2;
  border-color: #f87171;
  color: #991b1b;
}
.btn-ctrl-reset:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  border-color: var(--slate-200);
  color: var(--slate-400);
  background: #f8fafc;
}

.filter-count-badge {
  background: #dc2626;
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* Row 2: Filter Dropdowns Bar (Uniform Grid) */
.filter-dropdowns-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.55rem;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.filter-label {
  font-size: 0.675rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--slate-500);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.filter-select {
  width: 100%;
  height: 38px;
  padding: 0 0.55rem;
  border: 1.5px solid var(--slate-300);
  border-radius: var(--border-radius-sm);
  font-size: 0.775rem;
  color: var(--slate-800);
  background-color: white;
  outline: none;
  cursor: pointer;
  transition: all 0.15s ease;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.filter-select:hover {
  border-color: var(--slate-400);
}
.filter-select:focus {
  border-color: var(--polimi-accent);
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}

/* Row 3: Interactive Filter Pills (Chips Bar) */
.filter-pills-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  border-top: 1px solid var(--slate-200);
  padding-top: 0.75rem;
}

.filter-pills-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--slate-500);
  flex-shrink: 0;
}

.filter-pills-scroll {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.pills-separator {
  width: 1px;
  height: 18px;
  background: var(--slate-300);
  margin: 0 0.2rem;
  flex-shrink: 0;
}

.filter-chip {
  padding: 0.35rem 0.7rem;
  border-radius: 9999px;
  border: 1.5px solid var(--slate-200);
  background: #f8fafc;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--slate-600);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.15s ease;
  user-select: none;
  white-space: nowrap;
}
.filter-chip:hover {
  background: #f1f5f9;
  border-color: var(--slate-300);
  color: var(--slate-900);
}
.filter-chip.active {
  background: var(--polimi-blue);
  border-color: var(--polimi-blue);
  color: white;
  font-weight: 600;
  box-shadow: 0 2px 4px rgba(0, 40, 85, 0.2);
}
.filter-chip.active .chip-dot {
  background-color: white !important;
}

.filter-chip.chip-plan.active {
  background: var(--emerald-600);
  border-color: var(--emerald-600);
  color: white;
  box-shadow: 0 2px 4px rgba(5, 150, 105, 0.2);
}

.chip-icon {
  font-size: 0.8rem;
  line-height: 1;
}

.chip-count {
  background: rgba(0, 0, 0, 0.08);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.1rem 0.4rem;
  border-radius: 10px;
}
.filter-chip.active .chip-count {
  background: rgba(255, 255, 255, 0.25);
  color: white;
}

.chip-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-obbligatorio { background: #ef4444; }
.dot-taba { background: #8b5cf6; }
.dot-tabb { background: #f59e0b; }
.dot-int1 { background: #0284c7; }
.dot-ai { background: #eab308; }
.dot-limit2 { background: #f97316; }
.dot-soft { background: #a855f7; }

/* Row 4: Active Filter Tags Bar (Dismissible Tags) */
.active-filters-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding-top: 0.65rem;
  border-top: 1px dashed var(--slate-200);
}

.active-filters-title {
  font-size: 0.725rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--slate-400);
  flex-shrink: 0;
}

.active-tags-list {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.active-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.55rem;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  color: #0369a1;
  border-radius: 6px;
  font-size: 0.725rem;
  font-weight: 500;
  animation: fadeIn 0.15s ease-in;
}
.active-tag strong {
  font-weight: 700;
}

.active-tag-remove {
  background: transparent;
  border: none;
  color: #0284c7;
  cursor: pointer;
  font-size: 0.8rem;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all 0.15s ease;
  line-height: 1;
}
.active-tag-remove:hover {
  background: #0284c7;
  color: white;
}

.clear-all-tags-btn {
  background: transparent;
  border: none;
  color: #dc2626;
  font-size: 0.725rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  text-decoration: underline;
  transition: all 0.15s ease;
  margin-left: 0.25rem;
}
.clear-all-tags-btn:hover {
  background: #fee2e2;
}

/* Empty State Card */
.no-results-card {
  background: white;
  border-radius: var(--border-radius);
  border: 2px dashed var(--slate-300);
  padding: 3.5rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.75rem;
  box-shadow: var(--box-shadow);
  margin-bottom: 1.5rem;
}
.no-results-icon {
  color: var(--slate-400);
  background: var(--slate-100);
  padding: 0.85rem;
  border-radius: 50%;
  margin-bottom: 0.25rem;
}
.no-results-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--slate-800);
}
.no-results-desc {
  font-size: 0.85rem;
  color: var(--slate-500);
  max-width: 440px;
  line-height: 1.45;
}

/* Section Match Badge */
.section-match-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  background: var(--slate-100);
  color: var(--slate-600);
  border: 1px solid var(--slate-200);
}
.section-match-badge.badge-filtered {
  background: #eff6ff;
  color: #1d4ed8;
  border-color: #bfdbfe;
}


/* ==========================================================================
   TABLES & SECTIONS (Fixed border-radius, clean scrolling, no overflow)
   ========================================================================== */
#tables-wrapper {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.section-card {
  background: white;
  border-radius: var(--border-radius);
  box-shadow: var(--box-shadow);
  border: 1px solid var(--slate-200);
  overflow: hidden;
  transition: box-shadow 0.2s ease;
}
.section-card:hover {
  box-shadow: var(--box-shadow-md);
}

.section-header {
  background: #f8fafc;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--slate-200);
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s ease;
}
.section-header:hover {
  background-color: #f1f5f9;
}
.section-card.is-collapsed .section-header {
  border-bottom: none;
}
.section-card.is-collapsed .table-container,
.section-card.is-collapsed .mobile-scroll-hint {
  display: none !important;
}

.section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--polimi-blue);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.section-badge {
  background: var(--slate-200);
  color: var(--slate-700);
  font-size: 0.725rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
}

.section-plan-badge {
  font-size: 0.725rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 9999px;
  background-color: #ecfdf5;
  color: #047857;
  border: 1px solid #a7f3d0;
  display: inline-flex;
  align-items: center;
}

.section-toggle-btn {
  font-size: 0.8rem;
  color: var(--slate-500);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 500;
  flex-shrink: 0;
}

.section-toggle-icon {
  transition: transform 0.2s ease;
}
.section-card.is-collapsed .section-toggle-icon {
  transform: rotate(-90deg);
}

/* DATA TABLE (Scrollable inside card if needed, padded) */
.table-container {
  overflow-x: auto;
  max-width: 100%;
  scrollbar-width: thin;
  scrollbar-color: var(--slate-300) transparent;
}
.table-container::-webkit-scrollbar {
  height: 6px;
}
.table-container::-webkit-scrollbar-thumb {
  background: var(--slate-300);
  border-radius: 3px;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.825rem;
}

table.data-table th {
  background: #f8fafc;
  color: var(--slate-700);
  font-weight: 700;
  padding: 0.75rem 0.65rem;
  border-bottom: 2px solid var(--slate-200);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 10;
}

table.data-table th.center, table.data-table td.center {
  text-align: center;
}

table.data-table td {
  padding: 0.6rem 0.65rem;
  border-bottom: 1px solid var(--slate-200);
  vertical-align: middle;
  color: var(--slate-800);
}

table.data-table tbody tr {
  transition: background-color 0.1s ease;
}

table.data-table tbody tr:hover {
  background-color: #f8fafc;
}

/* Row states */
tr.row-planned {
  background-color: #f0fdf4 !important;
}
tr.row-passed {
  background-color: #eff6ff !important;
}
tr.row-sovrannumero {
  background-color: #faf5ff !important;
}
tr.row-passed_bachelor {
  background-color: #f0fdfa !important;
}
tr.row-interested {
  background-color: #fffbeb !important;
}
tr.row-excluded {
  opacity: 0.55;
  background-color: #f8fafc !important;
}
tr.choice-rule-row {
  background-color: #f8fafc;
  font-style: italic;
}

.course-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 600;
  color: var(--polimi-navy);
  cursor: pointer;
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  background: var(--slate-100);
  border: 1px solid var(--slate-200);
  font-size: 0.775rem;
  display: inline-block;
}
.course-code:hover {
  background: var(--polimi-accent-light);
  border-color: var(--polimi-accent);
  color: var(--polimi-accent);
}

.course-title-cell {
  min-width: 250px;
}

.course-title-link {
  color: var(--slate-900);
  text-decoration: none;
  font-weight: 600;
  transition: color 0.15s ease;
}
.course-title-link:hover {
  color: var(--polimi-accent);
  text-decoration: underline;
}

.course-tags {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
  margin-top: 0.25rem;
}

.tag-badge {
  font-size: 0.675rem;
  font-weight: 700;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  display: inline-flex;
  align-items: center;
}

.tag-obbligatorio {
  background-color: #fee2e2;
  color: #b91c1c;
  border: 1px solid #fca5a5;
}
.tag-ai {
  background-color: #fef3c7;
  color: #b45309;
  border: 1px solid #fde68a;
}
.tag-limit2 {
  background-color: #ffedd5;
  color: #c2410c;
  border: 1px solid #fed7aa;
}
.tag-dot-soft {
  background-color: #f3e8ff;
  color: #7e22ce;
  border: 1px solid #e9d5ff;
}
.tag-int1 {
  background: #e0f2fe;
  color: #0369a1;
  border: 1px solid #bae6fd;
}
.tag-taba {
  background: #ede9fe;
  color: #6d28d9;
  border: 1px solid #ddd6fe;
}
.tag-tabb {
  background: #fef3c7;
  color: #b45309;
  border: 1px solid #fde68a;
}

.period-badge {
  font-size: 0.725rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 10px;
  white-space: nowrap;
}
.period-1 {
  background: #e0f2fe;
  color: #0284c7;
}
.period-2 {
  background: #fef3c7;
  color: #d97706;
}
.period-annuale {
  background: var(--slate-100);
  color: var(--slate-600);
}

.cfu-badge {
  display: inline-block;
  font-weight: 700;
  color: var(--slate-800);
  background: var(--slate-100);
  border: 1px solid var(--slate-200);
  padding: 0.15rem 0.45rem;
  border-radius: 10px;
  min-width: 36px;
  text-align: center;
  font-size: 0.775rem;
}

.lang-flag {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--slate-600);
}

/* User Controls inside rows */
.status-select {
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--slate-300);
  font-size: 0.775rem;
  font-weight: 500;
  color: var(--slate-800);
  background-color: white;
  outline: none;
  cursor: pointer;
  transition: all 0.2s;
  min-width: 145px;
}
.status-select:focus {
  border-color: var(--polimi-accent);
  box-shadow: 0 0 0 2px rgba(2, 132, 199, 0.2);
}

.status-select.val-planned {
  background-color: #dcfce7;
  border-color: #86efac;
  color: #15803d;
  font-weight: 600;
}
.status-select.val-passed {
  background-color: #dbeafe;
  border-color: #bfdbfe;
  color: #1d4ed8;
  font-weight: 600;
}
.status-select.val-sovrannumero {
  background-color: #f3e8ff;
  border-color: #d8b4fe;
  color: #7e22ce;
  font-weight: 600;
}
.status-select.val-passed_bachelor {
  background-color: #ccfbf1;
  border-color: #99f6e4;
  color: #0f766e;
  font-weight: 600;
}
.status-select.val-interested {
  background-color: #fef3c7;
  border-color: #fde68a;
  color: #b45309;
}
.status-select.val-excluded {
  background-color: #f1f5f9;
  border-color: #cbd5e1;
  color: #64748b;
}

.user-note-input {
  width: 100%;
  min-width: 180px;
  max-width: 380px;
  padding: 0.35rem 0.55rem;
  border: 1px solid var(--slate-300);
  border-radius: 6px;
  font-size: 0.775rem;
  outline: none;
  font-family: inherit;
  transition: all 0.2s;
  background: white;
  resize: vertical;
  min-height: 30px;
  height: 30px;
}
.user-note-input:focus {
  min-height: 60px;
  border-color: var(--polimi-accent);
  box-shadow: 0 0 0 2px rgba(2, 132, 199, 0.2);
}

.note-saved-tick {
  font-size: 0.75rem;
  color: var(--emerald-600);
  display: none;
  font-weight: bold;
}

/* ==========================================================================
   MODAL DIALOGS
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-card {
  background: white;
  border-radius: var(--border-radius);
  box-shadow: var(--box-shadow-lg);
  max-width: 620px;
  width: 100%;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

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

.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--polimi-navy);
}

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

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

.btn {
  padding: 0.5rem 1rem;
  border-radius: var(--border-radius-sm);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
}
.btn-secondary {
  background: var(--slate-200);
  color: var(--slate-700);
}
.btn-secondary:hover {
  background: var(--slate-300);
}
.btn-primary {
  background: var(--polimi-accent);
  color: white;
}
.btn-primary:hover {
  background: var(--polimi-accent-hover);
}

/* ==========================================================================
   RESPONSIVE & MOBILE DESIGN
   ========================================================================== */

/* Prevent full-page horizontal overflow on all screen sizes */
html, body {
  overflow-x: hidden;
  max-width: 100vw;
}

/* Base mobile scroll indicator hint */
.mobile-scroll-hint {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.725rem;
  font-weight: 500;
  color: var(--slate-600);
  background: #f1f5f9;
  padding: 0.45rem 0.85rem;
  border-bottom: 1px solid var(--slate-200);
  user-select: none;
}
.mobile-scroll-hint svg {
  flex-shrink: 0;
  color: var(--polimi-accent);
}

/* Tablet & medium screen adjustments (<= 1024px) */
@media (max-width: 1024px) {
  .controls-panel {
    top: 0;
    position: static;
  }
  .main-container {
    padding: 0 1rem 2.5rem 1rem;
  }
}

/* Small tablets and Mobile devices (<= 768px) */
@media (max-width: 768px) {
  /* Header adjustments */
  header.site-header {
    position: relative;
    padding: 0.75rem 0.85rem;
  }

  .header-inner {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .header-left {
    gap: 0.75rem;
  }

  .polimi-logo-badge {
    width: 38px;
    height: 38px;
    border-radius: 8px;
  }
  .polimi-logo-badge svg {
    width: 22px;
    height: 22px;
  }

  .header-titles h1 {
    font-size: 0.95rem;
    line-height: 1.25;
  }
  .header-titles .subtitle {
    font-size: 0.75rem;
    line-height: 1.3;
  }

  .header-right {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0.55rem;
  }

  .plan-summary-pill {
    width: 100%;
    justify-content: space-between;
    padding: 0.5rem 0.85rem;
    font-size: 0.8rem;
    box-sizing: border-box;
  }

  .header-actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.45rem;
    width: 100%;
  }

  .header-actions .btn {
    width: 100%;
    justify-content: center;
    padding: 0.55rem 0.4rem;
    font-size: 0.75rem;
    box-sizing: border-box;
    white-space: nowrap;
  }

  /* Main container */
  .main-container {
    margin: 0.65rem auto;
    padding: 0 0.5rem 2rem 0.5rem;
    gap: 0.75rem;
  }

  /* Validation Card on Mobile */
  .validation-header {
    padding: 0.75rem 0.85rem;
  }
  .validation-title {
    font-size: 0.825rem;
    gap: 0.4rem;
  }
  .validation-body {
    padding: 0.85rem;
    gap: 0.75rem;
  }
  .req-grid {
    grid-template-columns: 1fr;
    gap: 0.65rem;
  }
  .req-box {
    padding: 0.75rem;
  }
  .req-name {
    font-size: 0.775rem;
  }
  .req-cfu-current {
    font-size: 1.2rem;
  }

  /* Info Card */
  .info-header {
    padding: 0.65rem 0.85rem;
  }
  .info-title {
    font-size: 0.825rem;
  }
  .info-body {
    padding: 0.75rem 0.85rem;
    grid-template-columns: 1fr;
    gap: 0.65rem;
  }

  /* Controls and Filters */
  .controls-panel {
    top: 60px;
    padding: 0.75rem 0.85rem;
    gap: 0.65rem;
  }

  .search-top-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .search-box-wrap {
    min-width: 100%;
    width: 100%;
  }

  .search-input {
    font-size: 16px; /* Avoid iOS auto-zoom */
    padding: 0 2rem 0 2.25rem;
    height: 40px;
  }

  .controls-actions {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
  }

  .results-badge {
    width: 100%;
    justify-content: center;
    height: 34px;
  }

  .view-buttons-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
    flex: 1;
  }

  .view-buttons-group .btn-ctrl {
    width: 100%;
    justify-content: center;
  }

  .btn-ctrl-reset {
    flex: 1;
    justify-content: center;
  }

  .filter-dropdowns-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.45rem;
  }

  .filter-select {
    width: 100%;
    font-size: 16px; /* Avoid iOS auto-zoom */
    padding: 0 0.5rem;
    height: 40px;
  }

  .filter-pills-bar {
    padding-top: 0.55rem;
    gap: 0.4rem;
  }

  .filter-pills-scroll {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.35rem;
    scrollbar-width: none;
  }
  .filter-pills-scroll::-webkit-scrollbar {
    display: none;
  }

  .filter-chip {
    flex-shrink: 0;
    padding: 0.35rem 0.65rem;
    font-size: 0.75rem;
  }

  .no-results-card {
    padding: 2.25rem 1rem;
  }

  /* Section cards & headers */
  .section-header {
    padding: 0.75rem 0.85rem;
  }
  .section-title {
    font-size: 0.85rem;
    gap: 0.4rem;
  }
  .section-badge, .section-plan-badge {
    font-size: 0.675rem;
  }

  /* Reveal mobile scroll hint */
  .mobile-scroll-hint {
    display: flex;
  }

  /* Table optimizations on mobile */
  .table-container {
    -webkit-overflow-scrolling: touch;
  }

  /* Hide low-priority metadata columns on mobile to reduce width */
  /* Col 2: SSD SM 639/24, Col 6: Sede, Col 7: Tipo */
  table.data-table th:nth-child(2),
  table.data-table td:nth-child(2),
  table.data-table th:nth-child(6),
  table.data-table td:nth-child(6),
  table.data-table th:nth-child(7),
  table.data-table td:nth-child(7) {
    display: none;
  }

  /* Sticky First Column: Codice stays visible while scrolling horizontally */
  table.data-table th:first-child,
  table.data-table td:first-child {
    position: sticky;
    left: 0;
    z-index: 5;
    background: #ffffff;
    box-shadow: 2px 0 4px -1px rgba(0, 0, 0, 0.08);
  }
  table.data-table th:first-child {
    z-index: 15;
    background: #f8fafc;
  }

  /* Preserve row status background color on sticky first column */
  tr.row-planned td:first-child {
    background-color: #f0fdf4 !important;
  }
  tr.row-passed td:first-child {
    background-color: #eff6ff !important;
  }
  tr.row-sovrannumero td:first-child {
    background-color: #faf5ff !important;
  }
  tr.row-passed_bachelor td:first-child {
    background-color: #f0fdfa !important;
  }
  tr.row-interested td:first-child {
    background-color: #fffbeb !important;
  }
  tr.row-excluded td:first-child {
    background-color: #f8fafc !important;
  }
  tr.choice-rule-row td:first-child {
    background-color: #f8fafc !important;
  }

  /* Course title cell */
  .course-title-cell {
    min-width: 220px;
    max-width: 290px;
  }
  .course-title-link {
    font-size: 0.85rem;
    line-height: 1.3;
  }

  /* Mobile-friendly touch targets for row inputs */
  .status-select {
    min-width: 145px;
    height: 38px;
    font-size: 16px; /* Avoid iOS zoom */
    border-radius: 8px;
  }

  .user-note-input {
    min-width: 160px;
    font-size: 16px; /* Avoid iOS zoom */
    min-height: 38px;
    height: 38px;
    border-radius: 8px;
  }

  /* Modals on mobile */
  .modal-card {
    padding: 1.15rem;
    max-width: calc(100vw - 1.5rem);
    margin: 0.75rem;
  }
}

/* Very narrow devices (iPhone SE, smaller Android screens <= 400px) */
@media (max-width: 400px) {
  .header-actions {
    grid-template-columns: 1fr;
  }
  .search-row > div:last-child .btn {
    flex: 1 1 100%;
  }
  .plan-summary-pill {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.3rem;
  }
}

@media (max-width: 1200px) {
  .filter-dropdowns-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

/* ==========================================================================
   CACHE STATUS BADGE & EXPORT/IMPORT ENHANCEMENTS
   ========================================================================== */

.cache-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.75rem;
  border-radius: 20px;
  background: rgba(15, 23, 42, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #f1f5f9;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  user-select: none;
  transition: all 0.2s ease;
  backdrop-filter: blur(4px);
}
.cache-status-badge:hover {
  background: rgba(15, 23, 42, 0.7);
  border-color: rgba(255, 255, 255, 0.4);
}
.cache-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.7);
  display: inline-block;
  transition: all 0.2s ease;
}
.cache-dot.saving {
  background: #f59e0b;
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.8);
  animation: cachePulse 0.7s ease infinite alternate;
}
@keyframes cachePulse {
  0% { transform: scale(0.85); opacity: 0.6; }
  100% { transform: scale(1.2); opacity: 1; }
}

/* Modal Statistics & Export Panel */
.modal-stats-card {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  background: var(--slate-50);
  border: 1px solid var(--slate-200);
  border-radius: var(--border-radius-sm);
  padding: 0.75rem 0.5rem;
  margin-bottom: 0.85rem;
  text-align: center;
}
.modal-stat-item {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.modal-stat-val {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--polimi-navy);
  line-height: 1.2;
}
.modal-stat-lbl {
  font-size: 0.7rem;
  color: var(--slate-500);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.modal-action-buttons {
  display: flex;
  gap: 0.65rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}
.btn-icon {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  text-decoration: none;
}
.btn-outline-danger {
  background: transparent;
  border: 1px solid #fca5a5;
  color: #b91c1c;
  padding: 0.5rem 0.85rem;
}
.btn-outline-danger:hover {
  background: #fef2f2;
  border-color: #f87171;
  color: #991b1b;
}
.btn-sm {
  padding: 0.3rem 0.65rem;
  font-size: 0.775rem;
  border-radius: var(--border-radius-sm, 4px);
}

/* File Drag & Drop Zone */
.file-drop-zone {
  border: 2px dashed var(--slate-300);
  border-radius: var(--border-radius);
  background: var(--slate-50);
  padding: 1.25rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  user-select: none;
}
.file-drop-zone:hover, .file-drop-zone.drag-over {
  border-color: var(--polimi-accent);
  background: #f0f9ff;
  transform: scale(1.005);
}
.drop-zone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}
.drop-icon {
  color: var(--polimi-accent);
  margin-bottom: 0.15rem;
}
.drop-zone-text {
  font-size: 0.875rem;
  color: var(--slate-700);
}
.drop-zone-text strong {
  color: var(--polimi-navy);
}
.drop-zone-text .browse-link {
  color: var(--polimi-accent);
  text-decoration: underline;
  font-weight: 600;
}
.drop-zone-sub {
  font-size: 0.75rem;
  color: var(--slate-500);
}
.file-status-badge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--border-radius-sm);
  font-size: 0.8rem;
  margin-top: 0.65rem;
  font-weight: 500;
}
.file-status-badge.status-ok {
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #065f46;
}
.file-status-badge.status-err {
  background: #fff1f2;
  border: 1px solid #fecdd3;
  color: #9f1239;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  min-width: 280px;
  max-width: 440px;
  padding: 0.75rem 1.15rem;
  border-radius: 8px;
  box-shadow: 0 10px 25px -3px rgba(0, 0, 0, 0.15), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  font-size: 0.85rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  opacity: 0;
  transform: translateY(12px);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.toast.toast-show {
  opacity: 1;
  transform: translateY(0);
}
.toast-success {
  background: #064e3b;
  color: #f0fdf4;
  border-left: 4px solid #10b981;
}
.toast-error {
  background: #881337;
  color: #fff1f2;
  border-left: 4px solid #f43f5e;
}
.toast-info {
  background: #0c4a6e;
  color: #f0f9ff;
  border-left: 4px solid #38bdf8;
}

@media (max-width: 640px) {
  .modal-stats-card {
    grid-template-columns: repeat(2, 1fr);
  }
  .modal-action-buttons button {
    width: 100%;
    justify-content: center;
  }
}
