/* ========================================
   CALENDARIO — Layout + Components
   ======================================== */

/* ========================================
   LAYOUT GRID (Sidebar + Main)
   ======================================== */

.cal-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: calc(100vh - 52px);
}

.cal-sidebar {
  height: calc(100vh - 52px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border-right: 1px solid var(--color-border);
  padding: var(--spacing-md);
  background: var(--color-bg-base);
}

.cal-main {
  height: calc(100vh - 52px);
  overflow-y: auto;
  padding: var(--spacing-sm);
  position: relative;
}

/* Sidebar backdrop (mobile) — hidden on desktop */
.cal-sidebar-backdrop {
  display: none;
}

/* Mobile sidebar toggle — hidden on desktop */
.cal-sidebar-toggle {
  display: none;
}

/* ========================================
   SIDEBAR — KPIs
   ======================================== */

.cal-kpi-row {
  gap: var(--spacing-xs);
  margin-bottom: var(--spacing-xs);
}

/* ========================================
   SIDEBAR — View Switcher
   ======================================== */

.cal-view-switcher {
  margin-bottom: var(--spacing-xs);
}

/* ========================================
   SIDEBAR — Collapsible Sections
   ======================================== */

.cal-section {
  margin-bottom: var(--spacing-sm);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg-card);
}

.cal-section summary {
  font-weight: 600;
  font-size: var(--font-size-xs);
  cursor: pointer;
  padding: var(--spacing-sm) var(--spacing-md);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  user-select: none;
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  list-style: none;
  border-radius: var(--radius-md);
}

.cal-section[open] summary {
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.cal-section summary::-webkit-details-marker {
  display: none;
}

.cal-section summary::before {
  content: 'chevron_right';
  font-family: 'Material Symbols Outlined';
  font-size: 18px;
  transition: transform 0.2s;
  color: var(--color-text-tertiary);
}

.cal-section[open] summary::before {
  transform: rotate(90deg);
}

.cal-section-content {
  padding: 0 var(--spacing-md) var(--spacing-md);
}

/* Stock count badge in summary */
.cal-section .stock-panel-count {
  background: var(--color-danger);
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
  margin-left: auto;
}

.cal-section .stock-panel-count:empty {
  display: none;
}

/* ========================================
   SIDEBAR — Layer Toggles
   ======================================== */

.cal-section-content .layer-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-bg-elevated);
  transition: background 0.15s, opacity 0.15s;
  user-select: none;
  margin-bottom: 4px;
}

.cal-section-content .layer-toggle:last-child {
  margin-bottom: 0;
}

.cal-section-content .layer-toggle:hover {
  background: var(--color-bg-hover);
}

.cal-section-content .layer-toggle:has(input:not(:checked)) {
  opacity: 0.5;
}

.cal-section-content .layer-toggle input[type="checkbox"] {
  display: none;
}

.layer-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.layer-dot-classes { background: #E8625C; }
.layer-dot-reserves { background: #8E8E93; }
.layer-dot-prestecs { background: #f59e0b; }
.layer-dot-pedidos { background: #14b8a6; }
.layer-dot-festius { background: #ef4444; opacity: 0.6; }

/* Calendar events (normal, clickable) */
.fc-event-calendari {
  cursor: pointer;
  border-left-width: 3px;
}
.fc-event-calendari-content {
  display: flex;
  align-items: center;
  gap: var(--space-1, 4px);
  font-size: var(--font-size-xs, 0.75rem);
  font-weight: var(--font-weight-medium, 500);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Calendaris dinàmics — summary amb botó settings */
.cal-summary-with-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cal-settings-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px;
  color: var(--color-text-tertiary);
  line-height: 1;
  border-radius: 4px;
  transition: color 0.15s;
}
.cal-settings-btn:hover {
  color: var(--color-primary);
}
.cal-settings-btn .material-symbols-outlined {
  font-size: 18px;
}

/* ========================================
   SIDEBAR — Filter Fields
   ======================================== */

.cal-filter-fields {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

.cal-filter-fields .filter-group {
  min-width: 0;
}

.cal-filter-fields label {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  margin-bottom: 2px;
}

.cal-filter-fields label .material-symbols-outlined {
  font-size: 16px;
}

/* Multi-select buttons */
.filter-multiselect-wrapper {
  position: relative;
}

.filter-multiselect-btn {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  padding: 6px 10px;
  font-size: var(--font-size-xs);
  color: var(--color-text-primary);
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.15s ease;
  width: 100%;
  height: 34px;
  text-align: left;
}

.filter-multiselect-btn:hover {
  border-color: var(--color-text-secondary);
}

.filter-multiselect-btn.active {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(19, 117, 188, 0.1);
}

.filter-multiselect-btn .btn-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filter-multiselect-btn .btn-arrow {
  font-size: 16px;
  color: var(--color-text-secondary);
  transition: transform 0.2s ease;
}

.filter-multiselect-btn.active .btn-arrow {
  transform: rotate(180deg);
}

.filter-multiselect-btn .filter-count {
  background: var(--color-primary);
  color: white;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 10px;
  min-width: 16px;
  text-align: center;
}

/* Dropdown */
.filter-multiselect-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 220px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all 0.2s ease;
  pointer-events: none;
}

.filter-multiselect-dropdown.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}

.filter-multiselect-option {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-sm) var(--spacing-md);
  cursor: pointer;
  transition: background 0.15s ease;
}

.filter-multiselect-option:hover {
  background: var(--color-bg-hover);
}

.filter-multiselect-option input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--color-primary);
  flex-shrink: 0;
}

.filter-multiselect-option .filter-option-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.filter-multiselect-option span {
  font-size: var(--font-size-sm);
  color: var(--color-text-primary);
}

/* ========================================
   SIDEBAR — Legend
   ======================================== */

.cal-legend-group {
  margin-bottom: var(--spacing-sm);
}

.cal-legend-group:last-child {
  margin-bottom: 0;
}

.cal-legend-title {
  display: block;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-tertiary);
  margin-bottom: 4px;
}

.cal-legend-items {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-dot-free {
  background: transparent;
  border: 1.5px dashed var(--color-text-tertiary, #aaa);
}

.legend-express-active { background: #f59e0b; }
.legend-express-overdue { background: #ef4444; }
.legend-programada-future { background: #3b82f6; }
.legend-programada-active { background: #f59e0b; }
.legend-returned { background: #94a3b8; }
.legend-pedido-ordered { background: #14b8a6; }
.legend-pedido-draft { background: #94a3b8; }
.legend-pedido-pending { background: #eab308; }
.legend-pedido-approved { background: #6366f1; }
.legend-classe-epc { background: #E8625C; }
.legend-classe-es { background: #0A84FF; }
.legend-classe-cai { background: #30D158; }
.legend-reserva { background: #8E8E93; }
.legend-festivo { background: #ef4444; opacity: 0.5; }
.legend-festivo-escolar { background: #DC2626; opacity: 0.5; }

/* ========================================
   SIDEBAR — Stock Panel
   ======================================== */

.stock-panel-list {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
}

.stock-panel-item {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-xs) var(--spacing-sm);
  border-radius: var(--radius-md);
  background: var(--color-bg-secondary, var(--color-bg-base));
}

.stock-panel-item-info {
  flex: 1;
  min-width: 0;
}

.stock-panel-item-name {
  font-weight: 600;
  font-size: var(--font-size-xs);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stock-panel-item-meta {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  font-size: 10px;
  color: var(--color-text-secondary);
  flex-wrap: wrap;
}

.stock-panel-item-bar {
  width: 50px;
  height: 5px;
  border-radius: 3px;
  background: var(--color-bg-tertiary, var(--color-border));
  overflow: hidden;
  flex-shrink: 0;
}

.stock-panel-item-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s;
}

.stock-panel-item-bar-fill.danger { background: var(--color-danger); }
.stock-panel-item-bar-fill.warning { background: var(--color-warning); }
.stock-panel-item-bar-fill.ok { background: var(--color-success); }

.stock-panel-item-nums {
  font-size: 10px;
  color: var(--color-text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
}

.stock-panel-item-nums strong {
  color: var(--color-text-primary);
}

.stock-panel-order-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: rgba(0, 122, 255, 0.12);
  color: var(--color-primary);
  font-size: 10px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 8px;
}

.stock-panel-order-badge .material-symbols-outlined {
  font-size: 11px;
}

.stock-panel-no-provider {
  color: var(--color-danger);
  font-size: var(--font-size-xs);
  font-weight: 500;
}

.stock-panel-directus-link {
  color: var(--color-text-tertiary);
  text-decoration: none;
  flex-shrink: 0;
}

.stock-panel-directus-link:hover {
  color: var(--color-primary);
}

.stock-panel-directus-link .material-symbols-outlined {
  font-size: 14px;
}

.stock-panel-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-xs);
  padding: var(--spacing-sm);
  color: var(--color-text-tertiary);
  font-size: var(--font-size-xs);
}

.stock-panel-empty .material-symbols-outlined {
  color: var(--color-success);
}

.stock-panel-loading {
  display: flex;
  justify-content: center;
  padding: var(--spacing-sm);
}

/* ========================================
   MAIN — Filter Pills
   ======================================== */

.calendario-pills {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-xs);
  margin-bottom: var(--spacing-sm);
  min-height: 0;
}

.calendario-pills:empty {
  display: none;
}

.cal-filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 12px;
  font-size: var(--font-size-xs);
  font-weight: 500;
  border-radius: 20px;
  cursor: default;
  transition: all 0.15s ease;
}

.cal-filter-pill .filter-pill-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}

.cal-filter-pill .filter-pill-remove {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.15s ease;
  padding: 0;
}

.cal-filter-pill .filter-pill-remove .material-symbols-outlined {
  font-size: 14px;
}

.cal-filter-pill .filter-pill-remove:hover {
  opacity: 0.7;
}

/* ========================================
   FULLCALENDAR OVERRIDES
   ======================================== */

#calendario {
  background: var(--color-bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  overflow: hidden;
}

/* Toolbar header */
.fc .fc-toolbar {
  padding: var(--spacing-md) var(--spacing-lg);
  margin-bottom: 0;
}

.fc .fc-toolbar-title {
  font-size: var(--font-size-lg) !important;
  color: var(--color-text-primary);
  font-weight: 600;
}

/* Buttons toolbar */
.fc .fc-button {
  background: var(--color-bg-elevated) !important;
  border: 1px solid var(--color-border) !important;
  color: var(--color-text-primary) !important;
  font-size: var(--font-size-sm) !important;
  padding: 6px 12px !important;
  border-radius: var(--radius-sm) !important;
  box-shadow: none !important;
  text-transform: none !important;
}

.fc .fc-button:hover {
  background: var(--color-bg-hover) !important;
  border-color: var(--color-border-hover) !important;
}

.fc .fc-button-active {
  background: var(--color-primary) !important;
  border-color: var(--color-primary) !important;
  color: #fff !important;
}

.fc .fc-today-button {
  background: var(--color-primary) !important;
  border-color: var(--color-primary) !important;
  color: #fff !important;
}

.fc .fc-today-button:disabled {
  opacity: 0.5;
}

/* Day column headers */
.fc .fc-col-header-cell {
  background: var(--color-bg-elevated);
  border-color: var(--color-border);
  padding: var(--spacing-sm) 0;
}

.fc .fc-col-header-cell-cushion {
  color: var(--color-text-primary);
  font-weight: 600;
  font-size: var(--font-size-sm);
  text-decoration: none;
}

/* Time slots */
.fc .fc-timegrid-slot {
  height: 40px;
  border-color: var(--color-border);
  cursor: cell;
}

.fc .fc-daygrid-day {
  cursor: cell;
}

.fc .fc-timegrid-slot-label-cushion {
  color: var(--color-text-tertiary);
  font-size: var(--font-size-xs);
}

.fc .fc-timegrid-axis-cushion {
  color: var(--color-text-secondary);
  font-size: var(--font-size-xs);
  font-weight: 500;
}

/* Today highlight */
.fc .fc-day-today {
  background: rgba(19, 117, 188, 0.04) !important;
}

/* Now indicator */
.fc .fc-timegrid-now-indicator-line {
  border-color: var(--color-danger);
}

.fc .fc-timegrid-now-indicator-arrow {
  border-color: var(--color-danger);
}

/* Grid borders */
.fc td, .fc th {
  border-color: var(--color-border);
}

.fc .fc-scrollgrid {
  border-color: var(--color-border);
}

/* Popover "+N more" — estils quan es mou a body per evitar clipping */
.fc .fc-popover,
.fc-more-popover {
  z-index: 9999;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md, 8px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.fc-more-popover .fc-popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  font-weight: 600;
  font-size: 13px;
  border-bottom: 1px solid var(--color-border, #e0e0e0);
  color: var(--color-text-primary, #1c1c1e);
}

.fc-more-popover .fc-popover-header .fc-popover-close {
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  color: var(--color-text-secondary, #8e8e93);
  background: none;
  border: none;
  padding: 0;
}

.fc-more-popover .fc-popover-body {
  padding: 4px 8px 8px;
}

.fc-more-popover .fc-popover-body .fc-event {
  margin: 2px 0;
}

@media (prefers-color-scheme: dark) {
  .fc-more-popover {
    background: var(--color-bg-elevated, #2c2c2e);
    border-color: var(--color-border, #3a3a3c);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  }
  .fc-more-popover .fc-popover-header {
    color: var(--color-text-primary, #f5f5f7);
    border-bottom-color: var(--color-border, #3a3a3c);
  }
  .fc-more-popover .fc-popover-header .fc-popover-close {
    color: var(--color-text-secondary, #98989d);
  }
}

/* ========================================
   EVENTS — Color Classes
   ======================================== */

.fc-event {
  border: none !important;
  border-radius: var(--radius-sm) !important;
  padding: 2px 4px !important;
  cursor: pointer;
  font-size: var(--font-size-xs);
  transition: opacity 0.15s;
}

.fc-event:hover {
  opacity: 0.85;
}

/* Express active — Orange */
.fc-event-express-active {
  background: rgba(245, 158, 11, 0.85) !important;
  border-left: 3px solid #d97706 !important;
}

/* Express overdue — Red */
.fc-event-express-overdue {
  background: rgba(239, 68, 68, 0.85) !important;
  border-left: 3px solid #dc2626 !important;
  animation: pulse-overdue 2s infinite;
}

@keyframes pulse-overdue {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.75; }
}

/* Scheduled future — Blue */
.fc-event-programada-future {
  background: rgba(59, 130, 246, 0.85) !important;
  border-left: 3px solid #2563eb !important;
}

/* Scheduled active — Orange */
.fc-event-programada-active {
  background: rgba(245, 158, 11, 0.85) !important;
  border-left: 3px solid #d97706 !important;
}

/* Returned — Grey strikethrough */
.fc-event-returned {
  background: rgba(120, 133, 150, 0.8) !important;
  border-left: 3px solid #94a3b8 !important;
  text-decoration: line-through;
  opacity: 0.85;
}

/* ========================================
   EVENT CONTENT
   ======================================== */

.fc-event-inner {
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow: hidden;
  line-height: 1.3;
}

.fc-event-icon {
  font-size: 14px !important;
  opacity: 0.8;
}

.fc-event-text {
  font-weight: 500;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fc-event-classe .fc-event-text {
  color: inherit;
}

.fc-event-user {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.75);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fc-event-classe .fc-event-user {
  color: inherit;
  opacity: 0.7;
}

/* ========================================
   EVENTS — Classe
   ======================================== */

.fc-event-classe {
  border-left-width: 3px !important;
  border-left-style: solid !important;
}

.fc-daygrid-dot-event.fc-event-classe .fc-daygrid-event-dot {
  display: none;
}

.fc-event-classe-inner {
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow: hidden;
  line-height: 1.3;
}

.fc-event-formacio-badge {
  display: inline-block;
  align-self: flex-start;
  font-size: 9px;
  font-weight: 700;
  padding: 0 5px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.25);
  color: #fff !important;
  line-height: 16px;
  margin-right: 4px;
  vertical-align: middle;
}

.fc-event-formacio-badge-epc { background: #E8625C; }
.fc-event-formacio-badge-es  { background: #0A84FF; }
.fc-event-formacio-badge-cai { background: #30D158; }

/* AllDay classes */
.fc-event-diacomplet {
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.8em;
  font-weight: 500;
}

.fc-event-diacomplet .fc-event-formacio-badge {
  font-size: 8px;
  padding: 0 3px;
}

/* ========================================
   EVENTS — Reserva
   ======================================== */

.fc-event-reserva {
  background: rgba(142, 142, 147, 0.75) !important;
  border-left: 3px solid #636366 !important;
}

.fc-event-reserva-inner {
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow: hidden;
  line-height: 1.3;
}

/* ========================================
   EVENTS — Pedido (striped)
   ======================================== */

.fc-event-pedido-draft,
.fc-event-pedido-pending,
.fc-event-pedido-approved,
.fc-event-pedido-ordered,
.fc-event-pedido-received {
  background-image: repeating-linear-gradient(
    -45deg, transparent, transparent 4px,
    rgba(255, 255, 255, 0.13) 4px, rgba(255, 255, 255, 0.13) 8px
  ) !important;
}

.fc-event-pedido-draft {
  background-color: rgba(148, 163, 184, 0.75) !important;
  border-left: 3px solid #64748b !important;
}

.fc-event-pedido-pending {
  background-color: rgba(234, 179, 8, 0.75) !important;
  border-left: 3px solid #ca8a04 !important;
}

.fc-event-pedido-approved {
  background-color: rgba(99, 102, 241, 0.75) !important;
  border-left: 3px solid #4f46e5 !important;
}

.fc-event-pedido-ordered {
  background-color: rgba(20, 184, 166, 0.75) !important;
  border-left: 3px solid #0d9488 !important;
}

.fc-event-pedido-received {
  background-color: rgba(34, 197, 94, 0.75) !important;
  border-left: 3px solid #16a34a !important;
}

.fc-event-pedido-inner {
  flex-direction: row;
  align-items: center;
  gap: var(--spacing-xs);
}

/* ========================================
   MODAL OVERRIDES (per-ID specifics only)
   Base styles come from shared-components.css
   ======================================== */

/* All calendar modals: hidden by default, flex when active */
#modalDetallPrestec,
#modalConfirmacio,
#modalDetallClasse,
#modalDetallReserva,
#modalEditarClasse,
#modalCancellarClasse,
#modalReservaTimeline,
#modalChecklistClasse,
#modalCrearClasseSim,
#modalGestioCalendaris,
#modalFormCalendari,
#modalChangePassword,
#modalSelectorTipus,
#modalDetallCalEvent,
#modalFormCalEvent {
  display: none;
  z-index: 9999;
  backdrop-filter: none;
}

#modalDetallPrestec.active,
#modalConfirmacio.active,
#modalDetallClasse.active,
#modalDetallReserva.active,
#modalEditarClasse.active,
#modalCancellarClasse.active,
#modalReservaTimeline.active,
#modalChecklistClasse.active,
#modalCrearClasseSim.active,
#modalGestioCalendaris.active,
#modalFormCalendari.active,
#modalChangePassword.active,
#modalSelectorTipus.active,
#modalDetallCalEvent.active,
#modalFormCalEvent.active {
  display: flex;
}

/* Higher z-index for stacked modals */
#modalConfirmacio,
#modalEditarClasse,
#modalCancellarClasse,
#modalReservaTimeline,
#modalCrearClasseSim {
  z-index: 10001;
}

#modalChecklistClasse {
  z-index: 10000;
}

/* ========================================
   COMPACT CLASS DETAIL MODAL
   ======================================== */

/* Header: assignatura com a títol + badges */
.detall-compact-header {
  flex-direction: row;
  align-items: flex-start;
  padding: 12px 16px;
}

.detall-compact-header-left {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  flex: 1;
}

.detall-compact-header-left h3 {
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--color-text-primary);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.detall-compact-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* Body: reduced padding/gap, no separators */
.detall-compact-body {
  padding: 8px 16px 12px;
  gap: 0;
}

/* Inline row: icon + value on 1 line */
.detall-compact-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: var(--font-size-base);
  color: var(--color-text-primary);
  line-height: 1.4;
}

.detall-compact-icon {
  font-size: 18px;
  color: var(--color-text-secondary);
  flex-shrink: 0;
  width: 20px;
  text-align: center;
}

/* Spacer for indented professor rows */
.detall-compact-icon-spacer {
  display: inline-block;
  width: 20px;
  flex-shrink: 0;
}

.detall-compact-override-icon {
  font-size: 14px;
  color: var(--color-text-tertiary);
  flex-shrink: 0;
}

.detall-compact-secondary {
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
}

.detall-compact-notes {
  font-style: italic;
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
  white-space: pre-wrap;
}

/* Footer always visible — sticky bottom */
#modalDetallClasse .modal-footer {
  position: sticky;
  bottom: 0;
  background: var(--color-bg-card);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* Icon color overrides per modal */
#modalDetallClasse .modal-header h3 { color: var(--color-text-primary); }
#modalDetallReserva .modal-header h3 .material-symbols-outlined { color: #8E8E93; }
#modalEditarClasse .modal-header h3 .material-symbols-outlined { color: #0A84FF; }
#modalCancellarClasse .modal-header h3 .material-symbols-outlined { color: #FF453A; }
#modalChecklistClasse .modal-header h3 .material-symbols-outlined { color: #30D158; }
#modalConfirmacio .modal-header .material-symbols-outlined { color: #f59e0b; }

/* Modal detail sections */
.detall-section {
  margin-bottom: var(--spacing-md);
  padding-bottom: var(--spacing-md);
  border-bottom: 1px solid var(--color-border);
}

.detall-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.detall-estat {
  display: flex;
  gap: var(--spacing-sm);
  flex-wrap: wrap;
}

.detall-label {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  margin-bottom: var(--spacing-xs);
}

.detall-label .material-symbols-outlined {
  font-size: 18px;
}

.detall-value {
  font-size: var(--font-size-base);
  color: var(--color-text-primary);
}

.detall-notes {
  background: var(--color-bg-base);
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: var(--radius-sm);
  font-style: italic;
  white-space: pre-wrap;
}

.detall-materials-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.detall-materials-list li {
  padding: var(--spacing-xs) 0;
  color: var(--color-text-primary);
  font-size: var(--font-size-sm);
  border-bottom: 1px solid var(--color-border);
}

.detall-materials-list li:last-child {
  border-bottom: none;
}

.detall-materials-list li strong {
  color: var(--color-primary);
}

/* Cancel loan button */
.detall-actions {
  padding: var(--spacing-md) var(--spacing-lg);
  border-top: 1px solid var(--color-border);
}

.btn-cancel-prestec {
  width: 100%;
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius-md);
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
  font-size: var(--font-size-sm);
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-xs);
}

.btn-cancel-prestec:hover {
  background: rgba(239, 68, 68, 0.2);
}

.btn-cancel-prestec .material-symbols-outlined {
  font-size: 18px;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: var(--font-size-xs);
  font-weight: 600;
}

.badge-warning { background: rgba(245, 158, 11, 0.15); color: #d97706; }
.badge-info { background: rgba(59, 130, 246, 0.15); color: #3b82f6; }
.badge-success { background: rgba(16, 185, 129, 0.15); color: #10b981; }
.badge-danger { background: rgba(239, 68, 68, 0.15); color: #ef4444; }
.badge-default { background: rgba(148, 163, 184, 0.15); color: #64748b; }
.badge-tipo { background: rgba(19, 117, 188, 0.12); color: var(--color-primary); }
.badge-pedido-ordered { background: rgba(20, 184, 166, 0.15); color: #0d9488; }

.badge-formacio { font-weight: 700; letter-spacing: 0.5px; }
.badge-formacio-epc { background: rgba(232, 98, 92, 0.15); color: #E8625C; }
.badge-formacio-es { background: rgba(10, 132, 255, 0.15); color: #0A84FF; }
.badge-formacio-cai { background: rgba(48, 209, 88, 0.15); color: #30D158; }
.badge-formacio-default { background: rgba(94, 92, 230, 0.15); color: #5E5CE6; }

/* Directus link button */
.btn-directus-link {
  width: 100%;
  padding: 10px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg-card);
  color: var(--color-primary);
  font-size: var(--font-size-sm);
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-xs);
  text-decoration: none;
  transition: background 0.15s;
}

.btn-directus-link:hover {
  background: var(--color-bg-hover);
}

.btn-directus-link .material-symbols-outlined {
  font-size: 18px;
}

/* Btn accent (checklist) */
.btn-accent {
  padding: 10px 20px;
  background: rgba(48, 209, 88, 0.15);
  color: #30D158;
  border: none;
  border-radius: var(--radius-sm);
  font-size: var(--font-size-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-accent:hover {
  background: rgba(48, 209, 88, 0.25);
}

.btn-danger-action {
  background: #ef4444;
}

.btn-danger-action:hover {
  background: #dc2626;
}

/* Class detail footer */
#modalDetallClasseFooter {
  display: flex;
  gap: var(--spacing-sm);
  justify-content: flex-end;
  padding: var(--spacing-md) var(--spacing-lg);
  border-top: 1px solid var(--color-border);
}

#modalDetallClasseFooter .btn .material-symbols-outlined,
.btn-danger .material-symbols-outlined {
  font-size: 18px;
}

/* Scope segmented (edit/cancel class) */
.scope-segmented {
  display: flex;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  overflow: hidden;
  margin-top: 4px;
}

.scope-segmented input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.scope-segmented label {
  flex: 1;
  text-align: center;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--color-text-secondary);
  background: transparent;
  transition: all 0.2s ease;
  border-right: 1px solid var(--color-border);
  user-select: none;
}

.scope-segmented label:last-of-type {
  border-right: none;
}

.scope-segmented input[type="radio"]:checked + label {
  background: var(--color-primary);
  color: #fff;
  font-weight: 600;
}

/* Drag-and-drop feedback */
.fc-event-dragging {
  opacity: 0.7 !important;
}

.fc-event-mirror {
  border: 2px dashed rgba(255, 255, 255, 0.7) !important;
  opacity: 0.8 !important;
}

.fc-event-programada-future {
  cursor: grab;
}

.fc-event-programada-future:active {
  cursor: grabbing;
}

/* Date comparison (reprogramming) */
.dates-comparison {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  margin: var(--spacing-md) 0;
}

.dates-comparison .dates-old,
.dates-comparison .dates-new {
  flex: 1;
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
}

.dates-comparison .dates-old {
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.2);
  text-decoration: line-through;
  opacity: 0.7;
}

.dates-comparison .dates-new {
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.dates-comparison .dates-label {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  margin-bottom: 2px;
}

.dates-comparison .dates-value {
  color: var(--color-text-primary);
  font-weight: 500;
}

.dates-comparison .dates-arrow {
  color: var(--color-text-tertiary);
  font-size: 20px;
  flex-shrink: 0;
}

/* ========================================
   CHECKLIST POST-CLASSE/RESERVA
   ======================================== */

.checklist-items {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.checklist-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--card-bg, rgba(0, 0, 0, 0.03));
  transition: background-color 0.2s;
}

.checklist-item:has(input:checked) {
  background: rgba(48, 209, 88, 0.08);
}

.checklist-item label {
  flex: 1;
  font-size: 15px;
  cursor: pointer;
  user-select: none;
}

.checklist-item input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: #30D158;
  cursor: pointer;
  flex-shrink: 0;
}

.checklist-item input[type="checkbox"]:disabled {
  opacity: 0.6;
  cursor: default;
}

.checklist-required::after {
  content: " *";
  color: #FF453A;
  font-weight: 600;
}

.checklist-number-input {
  width: 100px;
  padding: 6px 10px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--color-bg-base);
  color: var(--color-text-primary);
}

.checklist-number-input:disabled {
  opacity: 0.6;
  background: var(--color-bg-base);
}

.checklist-observacions {
  width: 100%;
  min-height: 60px;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  background: var(--color-bg-base);
  color: var(--color-text-primary);
}

.checklist-required-note {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-top: 8px;
}

.checklist-taller-note {
  font-size: 12px;
  color: #FF9F0A;
  margin-top: 8px;
  font-style: italic;
}

.checklist-completed-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(48, 209, 88, 0.1);
  color: #30D158;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 12px;
}

.checklist-completed-banner .material-symbols-outlined {
  font-size: 20px;
}

.checklist-pending-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
}

.checklist-pending-badge.pendent { background: rgba(255, 159, 10, 0.15); color: #FF9F0A; }
.checklist-pending-badge.completat { background: rgba(48, 209, 88, 0.15); color: #30D158; }
.checklist-pending-badge.incomplet { background: rgba(255, 69, 58, 0.15); color: #FF453A; }

/* ========================================
   VIEW: DAY GRID MONTH
   ======================================== */

.fc-daygrid-event {
  border-radius: var(--radius-sm) !important;
  padding: 1px 4px !important;
  font-size: 11px !important;
  margin-bottom: 1px !important;
}

.fc-daygrid-event .fc-event-inner {
  flex-direction: row;
  align-items: center;
  gap: 4px;
}

.fc-daygrid-event .fc-event-icon {
  font-size: 12px !important;
}

.fc-daygrid-event .fc-event-user {
  display: none;
}

.fc .fc-daygrid-day-frame {
  min-height: 80px;
}

.fc .fc-daygrid-day-number {
  color: var(--color-text-primary);
  font-size: var(--font-size-sm);
  font-weight: 500;
  padding: 4px 8px;
}

.fc .fc-daygrid-day.fc-day-other .fc-daygrid-day-number {
  color: var(--color-text-tertiary);
  opacity: 0.7;
}

.fc .fc-daygrid-more-link {
  color: var(--color-primary);
  font-size: var(--font-size-xs);
  font-weight: 600;
}

.fc .fc-daygrid-day-events {
  min-height: 0;
}

.fc-daygrid-event.fc-event-classe .fc-event-formacio-badge {
  font-size: 8px;
  padding: 0 3px;
}

.fc-daygrid-event.fc-event-classe .fc-event-user,
.fc-daygrid-event.fc-event-reserva .fc-event-user {
  display: none;
}

/* ========================================
   VIEW: LIST WEEK
   ======================================== */

.fc .fc-list {
  border-color: var(--color-border);
}

.fc .fc-list-sticky .fc-list-day > * {
  background: var(--color-bg-elevated);
}

.fc .fc-list-day-cushion {
  background: var(--color-bg-elevated) !important;
  color: var(--color-text-primary);
  font-weight: 600;
}

.fc .fc-list-event td {
  border-color: var(--color-border);
  padding: var(--spacing-sm) var(--spacing-md);
}

.fc .fc-list-event:hover td {
  background: var(--color-bg-hover);
}

.fc .fc-list-event-dot {
  border-radius: 50%;
}

.fc .fc-list-event-title {
  color: var(--color-text-primary);
}

.fc .fc-list-event-time {
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.fc .fc-list-empty-cushion {
  color: var(--color-text-tertiary);
  font-style: italic;
}

.fc-list-event .fc-event-text {
  color: var(--color-text-primary);
}

.fc-list-event .fc-event-user {
  color: var(--color-text-secondary);
}

.fc-list-event .fc-event-icon {
  color: var(--color-text-secondary);
}

/* Returned in list view */
.fc-list-event.fc-event-returned td {
  background: rgba(120, 133, 150, 0.8);
  opacity: 0.85;
}

.fc-list-event.fc-event-returned .fc-event-text {
  color: #fff;
  text-decoration: line-through;
}

.fc-list-event.fc-event-returned .fc-event-icon,
.fc-list-event.fc-event-returned .fc-event-user {
  color: rgba(255, 255, 255, 0.75);
}

.fc-list-event.fc-event-returned .fc-list-event-time {
  color: rgba(255, 255, 255, 0.7);
}

/* Reserva in list view */
.fc-list-event.fc-event-reserva td {
  background: rgba(142, 142, 147, 0.12);
}

.fc-list-event.fc-event-reserva .fc-event-text,
.fc-list-event.fc-event-classe .fc-event-text {
  color: var(--color-text-primary);
}

.fc-list-event.fc-event-reserva .fc-event-user,
.fc-list-event.fc-event-reserva .fc-event-icon,
.fc-list-event.fc-event-classe .fc-event-user,
.fc-list-event.fc-event-classe .fc-event-icon {
  color: var(--color-text-secondary);
}

/* ========================================
   BACKGROUND EVENTS — Holidays
   ======================================== */

.fc .fc-bg-event {
  opacity: 1;
  border-radius: 0;
}

/* Light mode: rgba backgrounds (no parent opacity → labels stay readable) */
.fc-festivo-nacional { background: rgba(239, 68, 68, 0.18) !important; }
.fc-festivo-autonomico { background: rgba(245, 158, 11, 0.18) !important; }
.fc-festivo-local { background: rgba(59, 130, 246, 0.18) !important; }
.fc-festivo-escolar { background: rgba(220, 38, 38, 0.18) !important; }

.fc-festivo-label {
  position: absolute;
  bottom: 2px;
  left: 4px;
  right: 4px;
  font-size: 9px;
  font-weight: 600;
  color: var(--color-text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  z-index: 1;
}

.fc-festivo-bg-label {
  position: absolute;
  top: 2px;
  left: 4px;
  right: 4px;
  font-size: 9px;
  font-weight: 600;
  color: var(--color-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

/* ========================================
   MULTI-MONTH YEAR VIEW
   ======================================== */

.fc-multiMonthYear-view .fc-multimonth-month { padding: 4px; }
.fc-multiMonthYear-view .fc-daygrid-day-frame { min-height: 1.8em; }
.fc-multiMonthYear-view .fc-daygrid-day-events { margin-bottom: 0; }
.fc-multiMonthYear-view .fc-daygrid-event { font-size: 10px; padding: 0 2px; margin-bottom: 1px; }
.fc-multiMonthYear-view .fc-multimonth-title { font-size: var(--font-size-sm); padding: 6px 8px; }
.fc-multiMonthYear-view .fc-col-header-cell { font-size: 10px; }

/* ========================================
   TIMELINE AULES — Date Nav
   ======================================== */

.timeline-date-nav {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-md);
  flex-wrap: wrap;
}

.timeline-nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 var(--spacing-sm);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg-card);
  color: var(--color-text-primary);
  cursor: pointer;
  font-size: var(--font-size-sm);
  transition: background 0.15s;
}

.timeline-nav-btn:hover {
  background: var(--color-bg-hover);
}

.timeline-today-btn {
  font-weight: 600;
  padding: 0 var(--spacing-md);
}

.timeline-date-picker {
  padding: var(--spacing-xs) var(--spacing-sm);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg-card);
  color: var(--color-text-primary);
  font-size: var(--font-size-sm);
}

.timeline-sub-toggle {
  display: flex;
  margin-left: auto;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 2px;
  gap: 1px;
}

.sub-toggle-btn {
  padding: 4px 12px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--color-text-secondary);
  font-size: var(--font-size-xs);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.sub-toggle-btn.active {
  background: var(--color-primary);
  color: #fff;
}

/* ========================================
   TIMELINE AULES — Grid
   ======================================== */

.timeline-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-xl, 32px);
  color: var(--color-text-secondary);
}

.timeline-aules-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg-card);
}

.timeline-aules-grid {
  display: grid;
  grid-template-columns: 120px 1fr;
  min-width: 750px;
  position: relative;
}

.timeline-time-header {
  grid-column: 2 / -1;
  position: relative;
  height: 28px;
  border-bottom: 1px solid var(--color-border);
}

.timeline-time-header-spacer {
  grid-column: 1 / 2;
  height: 28px;
  border-bottom: 1px solid var(--color-border);
  border-right: 1px solid var(--color-border);
  background: var(--color-bg-card);
  position: sticky;
  left: 0;
  z-index: 3;
}

.timeline-time-tick {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  font-size: 10px;
  color: var(--color-text-tertiary);
  line-height: 28px;
  white-space: nowrap;
}

.timeline-edifici-row {
  grid-column: 1 / -1;
  padding: 4px var(--spacing-sm);
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--color-text-secondary);
  background: var(--color-bg-elevated, rgba(0,0,0,0.03));
  border-bottom: 1px solid var(--color-border);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.timeline-aula-name {
  position: sticky;
  left: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  padding: 0 var(--spacing-sm);
  min-height: 44px;
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--color-text-primary);
  background: var(--color-bg-card);
  border-bottom: 1px solid var(--color-border);
  border-right: 1px solid var(--color-border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timeline-aula-bars {
  position: relative;
  min-height: 44px;
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
}

.timeline-gridline {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  pointer-events: none;
}

.timeline-gridline-hour { background: var(--color-border); opacity: 0.5; }
.timeline-gridline-half { background: var(--color-border); opacity: 0.2; }

.timeline-bar {
  position: absolute;
  top: 4px;
  bottom: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  padding: 0 6px;
  overflow: hidden;
  white-space: nowrap;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  z-index: 1;
  transition: opacity 0.15s;
}

.timeline-bar:hover {
  opacity: 0.85;
  z-index: 3;
}

.timeline-bar-badge {
  display: inline-block;
  flex-shrink: 0;
  font-size: 9px;
  font-weight: 700;
  padding: 0 4px;
  border-radius: 3px;
  color: #fff;
  line-height: 16px;
  margin-right: 4px;
  letter-spacing: 0.3px;
}

.timeline-bar-reserva {
  background: rgba(142, 142, 147, 0.35);
  color: var(--color-text-primary);
  border: 1px dashed rgba(142, 142, 147, 0.6);
}

.timeline-bar-editable { cursor: grab; touch-action: none; }
.timeline-bar-editable:active { cursor: grabbing; }

.timeline-resize-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 8px;
  cursor: ew-resize;
  opacity: 0;
  z-index: 2;
  transition: opacity 0.15s;
}

.timeline-resize-handle::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 3px;
  height: 14px;
  border-radius: 2px;
  background: var(--color-text-secondary);
}

.timeline-resize-left { left: -2px; border-radius: 4px 0 0 4px; }
.timeline-resize-right { right: -2px; border-radius: 0 4px 4px 0; }

.timeline-bar-editable:hover .timeline-resize-handle { opacity: 0.7; }

.timeline-bar-ghost {
  position: absolute;
  top: 4px;
  bottom: 4px;
  border: 2px dashed var(--color-primary);
  background: rgba(19, 117, 188, 0.12);
  border-radius: 4px;
  pointer-events: none;
  z-index: 8;
}

.timeline-bar-dragging { opacity: 0.5; cursor: grabbing; }

.timeline-aula-target {
  background: rgba(19, 117, 188, 0.06);
  outline: 1px dashed rgba(19, 117, 188, 0.3);
  outline-offset: -1px;
}

.timeline-bar-text {
  overflow: hidden;
  text-overflow: ellipsis;
}

.timeline-now-indicator {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #FF453A;
  z-index: 5;
  pointer-events: none;
}

.timeline-now-indicator::before {
  content: '';
  position: absolute;
  top: -4px;
  left: -4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #FF453A;
}

.timeline-no-aules {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-xl, 32px);
  color: var(--color-text-secondary);
}

.timeline-no-aules .material-symbols-outlined {
  font-size: 40px;
  opacity: 0.4;
}

/* ========================================
   TIMELINE AULES — Heatmap (Week view)
   ======================================== */

.timeline-heatmap {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg-card);
  overflow-x: auto;
}

.timeline-heatmap-grid {
  display: grid;
  grid-template-columns: 120px repeat(5, 1fr);
  min-width: 400px;
}

.timeline-heatmap-header {
  padding: 6px 4px;
  text-align: center;
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--color-text-secondary);
  border-bottom: 1px solid var(--color-border);
}

.timeline-heatmap-header:first-child {
  border-right: 1px solid var(--color-border);
}

.timeline-heatmap-edifici {
  grid-column: 1 / -1;
  padding: 4px var(--spacing-sm);
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--color-text-secondary);
  background: var(--color-bg-elevated, rgba(0,0,0,0.03));
  border-bottom: 1px solid var(--color-border);
}

.timeline-heatmap-name {
  display: flex;
  align-items: center;
  padding: 0 var(--spacing-sm);
  font-size: var(--font-size-sm);
  font-weight: 500;
  min-height: 36px;
  border-bottom: 1px solid var(--color-border);
  border-right: 1px solid var(--color-border);
}

.timeline-heatmap-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  font-size: var(--font-size-xs);
  font-weight: 600;
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  transition: opacity 0.15s;
}

.timeline-heatmap-cell:hover { opacity: 0.8; }

.heatmap-0 { background: rgba(48, 209, 88, 0.15); color: #30D158; }
.heatmap-25 { background: rgba(255, 214, 10, 0.2); color: #C09900; }
.heatmap-50 { background: rgba(255, 159, 10, 0.25); color: #CC7F08; }
.heatmap-75 { background: rgba(255, 69, 58, 0.25); color: #FF453A; }
.heatmap-100 { background: rgba(255, 69, 58, 0.4); color: #CC362E; }

/* ========================================
   DARK MODE
   ======================================== */

@media (prefers-color-scheme: dark) {
  /* Sidebar */
  .cal-sidebar {
    background: var(--color-bg-card);
    border-right-color: var(--color-border);
  }

  .cal-section {
    background: rgba(255, 255, 255, 0.04);
    border-color: var(--color-border);
  }

  .cal-section-content .layer-toggle {
    background: var(--color-bg-elevated);
    border-color: var(--color-border);
  }

  /* Filter dropdowns */
  .filter-multiselect-btn {
    background: var(--color-bg-card);
    border-color: var(--color-border);
    color: var(--color-text-primary);
  }

  .filter-multiselect-dropdown {
    background: var(--color-bg-card);
    border-color: var(--color-border);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  }

  .filter-multiselect-option:hover {
    background: rgba(255, 255, 255, 0.08);
  }

  /* Stock panel */
  .stock-panel-item {
    background: rgba(255, 255, 255, 0.05);
  }

  .stock-panel-order-badge {
    background: rgba(10, 132, 255, 0.18);
    color: #0a84ff;
  }

  /* FullCalendar */
  #calendario {
    background: var(--color-bg-card);
  }

  .fc-theme-standard th,
  .fc .fc-col-header-cell,
  .fc .fc-scrollgrid-section-header > * {
    background: var(--color-bg-elevated) !important;
  }

  .fc .fc-day-today {
    background: rgba(10, 132, 255, 0.08) !important;
  }

  .fc .fc-timegrid-now-indicator-line,
  .fc .fc-timegrid-now-indicator-arrow {
    border-color: #FF453A;
  }

  /* Event colors dark mode — iOS HIG */
  .fc-event-express-active {
    background: rgba(255, 159, 10, 0.85) !important;
    border-left-color: #FF9F0A !important;
  }

  .fc-event-express-overdue {
    background: rgba(255, 69, 58, 0.85) !important;
    border-left-color: #FF453A !important;
  }

  .fc-event-programada-future {
    background: rgba(10, 132, 255, 0.85) !important;
    border-left-color: #0A84FF !important;
  }

  .fc-event-programada-active {
    background: rgba(255, 159, 10, 0.85) !important;
    border-left-color: #FF9F0A !important;
  }

  .fc-event-returned {
    background: rgba(142, 142, 147, 0.65) !important;
    border-left-color: #8E8E93 !important;
  }

  .fc-event-reserva {
    background: rgba(142, 142, 147, 0.65) !important;
    border-left-color: #8E8E93 !important;
  }

  .fc-list-event.fc-event-reserva td {
    background: rgba(142, 142, 147, 0.08);
  }

  .fc-list-event.fc-event-returned td {
    background: rgba(142, 142, 147, 0.65);
  }

  /* Pedido events dark mode */
  .fc-event-pedido-draft { background-color: rgba(142, 142, 147, 0.65) !important; border-left-color: #8E8E93 !important; }
  .fc-event-pedido-pending { background-color: rgba(255, 214, 10, 0.7) !important; border-left-color: #FFD60A !important; }
  .fc-event-pedido-approved { background-color: rgba(94, 92, 230, 0.75) !important; border-left-color: #5E5CE6 !important; }
  .fc-event-pedido-ordered { background-color: rgba(100, 210, 255, 0.7) !important; border-left-color: #64D2FF !important; }
  .fc-event-pedido-received { background-color: rgba(48, 209, 88, 0.7) !important; border-left-color: #30D158 !important; }

  /* Badges dark mode */
  .badge-warning { background: rgba(255, 159, 10, 0.2); color: #FF9F0A; }
  .badge-info { background: rgba(10, 132, 255, 0.2); color: #0A84FF; }
  .badge-success { background: rgba(48, 209, 88, 0.2); color: #30D158; }
  .badge-danger { background: rgba(255, 69, 58, 0.2); color: #FF453A; }
  .badge-tipo { background: rgba(10, 132, 255, 0.15); color: #0A84FF; }
  .badge-pedido-ordered { background: rgba(100, 210, 255, 0.2); color: #64D2FF; }

  .badge-formacio-epc { background: rgba(10, 132, 255, 0.2); color: #0A84FF; }
  .badge-formacio-es { background: rgba(48, 209, 88, 0.2); color: #30D158; }
  .badge-formacio-cai { background: rgba(255, 159, 10, 0.2); color: #FF9F0A; }
  .badge-formacio-default { background: rgba(94, 92, 230, 0.2); color: #5E5CE6; }

  /* Buttons */
  .btn-cancel-prestec { background: rgba(255, 69, 58, 0.15); color: #FF453A; }
  .btn-cancel-prestec:hover { background: rgba(255, 69, 58, 0.25); }
  .btn-danger-action { background: #FF453A; }
  .btn-danger-action:hover { background: #e0342e; }

  .btn-directus-link {
    background: var(--color-bg-elevated);
    border-color: var(--color-border);
    color: #0A84FF;
  }

  .btn-directus-link:hover {
    background: var(--color-bg-hover);
  }

  .btn-accent { background: rgba(48, 209, 88, 0.2); }
  .btn-accent:hover { background: rgba(48, 209, 88, 0.3); }

  /* Modal icon overrides */
  #modalConfirmacio .modal-header .material-symbols-outlined { color: #FF9F0A; }

  /* Holiday colors dark mode — rgba for visibility on dark bg */
  .fc-festivo-nacional { background: rgba(255, 69, 58, 0.35) !important; }
  .fc-festivo-autonomico { background: rgba(255, 159, 10, 0.35) !important; }
  .fc-festivo-local { background: rgba(10, 132, 255, 0.35) !important; }
  .fc-festivo-escolar { background: rgba(255, 105, 97, 0.35) !important; }
  .fc-festivo-label { color: var(--color-text-secondary); }

  /* List view dark mode */
  .fc .fc-list-day-cushion { background: var(--color-bg-elevated) !important; }
  .fc .fc-daygrid-more-link { color: #0A84FF; }

  /* Dates comparison dark mode */
  .dates-comparison .dates-old { background: rgba(255, 69, 58, 0.1); border-color: rgba(255, 69, 58, 0.3); }
  .dates-comparison .dates-new { background: rgba(48, 209, 88, 0.1); border-color: rgba(48, 209, 88, 0.3); }

  /* Scope segmented dark mode */
  .scope-segmented { border-color: var(--color-border); }
  .scope-segmented label { border-color: var(--color-border); }

  /* Checklist dark mode */
  .checklist-item { background: rgba(255, 255, 255, 0.06); }
  .checklist-item:has(input:checked) { background: rgba(48, 209, 88, 0.12); }
  .checklist-number-input { background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.15); color: #f2f2f7; }
  .checklist-observacions { background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.15); color: #f2f2f7; }
  .checklist-completed-banner { background: rgba(48, 209, 88, 0.15); }

  /* Multi-month dark mode */
  .fc-multiMonthYear-view .fc-multimonth-month { border-color: var(--color-border) !important; }
  .fc-multiMonthYear-view .fc-multimonth-title { background: var(--color-bg-elevated) !important; color: var(--color-text-primary) !important; }
  .fc-multiMonthYear-view .fc-daygrid-day { background: var(--color-bg-card) !important; }
  .fc-multiMonthYear-view .fc-day-other { background: var(--color-bg-base) !important; }
  .fc .fc-daygrid-day.fc-day-other .fc-daygrid-day-number { opacity: 0.5; }

  /* Timeline dark mode */
  .timeline-nav-btn, .timeline-date-picker { background: var(--color-bg-card); border-color: var(--color-border); color: var(--color-text-primary); }
  .timeline-sub-toggle { background: var(--color-bg-card); border-color: var(--color-border); }
  .timeline-aules-scroll { background: var(--color-bg-card); border-color: var(--color-border); }
  .timeline-aula-name { background: var(--color-bg-card); }
  .timeline-time-header-spacer { background: var(--color-bg-card); }
  .timeline-edifici-row { background: rgba(255, 255, 255, 0.05); }
  .timeline-bar-reserva { background: rgba(142, 142, 147, 0.25); border-color: rgba(142, 142, 147, 0.5); }
  .timeline-bar-ghost { border-color: #0A84FF; background: rgba(10, 132, 255, 0.15); }
  .timeline-aula-target { background: rgba(10, 132, 255, 0.1); outline-color: rgba(10, 132, 255, 0.35); }
  .timeline-resize-handle::after { background: rgba(255, 255, 255, 0.5); }
  .timeline-heatmap { background: var(--color-bg-card); border-color: var(--color-border); }
  .timeline-heatmap-edifici { background: rgba(255, 255, 255, 0.05); }
  .timeline-heatmap-name { color: var(--color-text-primary); }

  .heatmap-0 { background: rgba(48, 209, 88, 0.2); color: #30D158; }
  .heatmap-25 { background: rgba(255, 214, 10, 0.2); color: #FFD60A; }
  .heatmap-50 { background: rgba(255, 159, 10, 0.25); color: #FF9F0A; }
  .heatmap-75 { background: rgba(255, 69, 58, 0.3); color: #FF453A; }
  .heatmap-100 { background: rgba(255, 69, 58, 0.45); color: #FF6961; }

  /* Mobile sidebar dark mode */
  .cal-sidebar-backdrop {
    background: rgba(0, 0, 0, 0.6);
  }
}

/* ========================================
   RESPONSIVE — Mobile (< 1024px)
   ======================================== */

@media (max-width: 1023px) {
  .cal-layout {
    grid-template-columns: 1fr;
    height: auto;
  }

  .cal-sidebar {
    position: fixed;
    left: 0;
    top: 52px;
    bottom: 0;
    width: 300px;
    z-index: 900;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    height: calc(100vh - 52px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .cal-sidebar.open {
    transform: translateX(0);
  }

  .cal-sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    top: 52px;
    background: rgba(0, 0, 0, 0.4);
    z-index: 899;
  }

  .cal-sidebar.open ~ .cal-sidebar-backdrop {
    display: block;
  }

  .cal-main {
    height: auto;
    min-height: calc(100vh - 52px);
    padding: var(--spacing-sm);
    padding-bottom: 80px; /* tab bar space */
  }

  .cal-sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-bg-card);
    color: var(--color-text-primary);
    cursor: pointer;
    margin-bottom: var(--spacing-sm);
  }

  .cal-sidebar-toggle .material-symbols-outlined {
    font-size: 20px;
  }

  /* Multi-month columns on tablet */
  .fc-multiMonthYear-view .fc-multimonth {
    --fc-multimonth-max-columns: 2;
  }
}

@media (max-width: 768px) {
  .fc .fc-toolbar {
    flex-direction: column;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
  }

  .fc .fc-toolbar-title {
    font-size: var(--font-size-base) !important;
  }

  .fc .fc-button {
    font-size: var(--font-size-xs) !important;
    padding: 4px 8px !important;
  }

  .dates-comparison {
    flex-direction: column;
  }

  .dates-comparison .dates-arrow {
    transform: rotate(90deg);
  }

  .stock-panel-item {
    flex-wrap: wrap;
  }

  .stock-panel-item-meta {
    width: 100%;
  }

  /* Timeline responsive */
  .timeline-aules-grid {
    grid-template-columns: 100px 1fr;
    min-width: 600px;
  }

  .timeline-aula-name {
    font-size: var(--font-size-xs);
    padding: 0 6px;
  }

  .timeline-heatmap-grid {
    grid-template-columns: 100px repeat(5, 1fr);
  }
}

@media (max-width: 480px) {
  /* Hide Month and Week buttons on small mobile */
  .fc .fc-multiMonthYear-button,
  .fc .fc-dayGridMonth-button,
  .fc .fc-timeGridWeek-button {
    display: none;
  }

  .fc-festivo-label {
    font-size: 8px;
  }

  .timeline-aules-grid {
    grid-template-columns: 80px 1fr;
    min-width: 500px;
  }

  .timeline-aula-name {
    font-size: 11px;
    padding: 0 4px;
  }

  .timeline-bar {
    font-size: 0;
  }

  .timeline-heatmap-grid {
    grid-template-columns: 80px repeat(5, 1fr);
  }

  .timeline-sub-toggle {
    margin-left: 0;
  }

  .timeline-date-nav {
    gap: 4px;
  }
}

/* ========================================
 * MODE SIMULADOR
 * ======================================== */

/* Toggle button in sidebar */
.sim-toggle-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-md, 8px);
  background: transparent;
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
  cursor: pointer;
  transition: all 0.2s;
}

.sim-toggle-btn:hover {
  background: var(--color-bg-hover);
  color: var(--color-text-primary);
}

.sim-toggle-btn.active {
  background: var(--color-warning, #f59e0b);
  color: white;
  border-color: var(--color-warning, #f59e0b);
  border-style: solid;
}

.sim-toggle-btn .material-symbols-outlined {
  font-size: 20px;
}

/* Sim banner */
.sim-banner {
  position: sticky;
  top: 0;
  z-index: 500;
  background: var(--color-warning-bg, #fef3c7);
  border: 1px solid var(--color-warning-border, #f59e0b);
  border-radius: var(--radius-md, 8px);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.sim-banner-content {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--color-warning-text, #92400e);
  font-size: var(--font-size-sm);
}

.sim-banner-content .material-symbols-outlined {
  font-size: 20px;
}

.sim-banner-count {
  font-weight: 400;
  opacity: 0.8;
}

.sim-banner-actions {
  display: flex;
  gap: 8px;
}

.sim-banner-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border-radius: var(--radius-sm, 6px);
  border: none;
  font-size: var(--font-size-xs);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.sim-banner-btn .material-symbols-outlined {
  font-size: 16px;
}

.sim-btn-apply {
  background: var(--color-success, #22c55e);
  color: white;
}

.sim-btn-apply:hover:not(:disabled) {
  filter: brightness(0.9);
}

.sim-btn-apply:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.sim-btn-discard {
  background: var(--color-bg-elevated, #f1f5f9);
  color: var(--color-text-secondary);
}

.sim-btn-discard:hover {
  background: var(--color-bg-hover);
}

/* Sim events in FullCalendar */
.fc-event.sim-original {
  opacity: 0.3 !important;
  text-decoration: line-through;
  pointer-events: none;
}

.fc-event.sim-proposed {
  border: 2px dashed var(--color-warning, #f59e0b) !important;
  background: rgba(245, 158, 11, 0.15) !important;
  animation: sim-pulse 2s ease-in-out infinite;
}

.fc-event.sim-cancel {
  opacity: 0.25 !important;
  text-decoration: line-through;
  background: rgba(239, 68, 68, 0.15) !important;
  border: 2px dashed var(--color-danger, #ef4444) !important;
  pointer-events: none;
}

@keyframes sim-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.3); }
  50% { box-shadow: 0 0 0 4px rgba(245, 158, 11, 0); }
}

/* Sim hidden: real event that has a pending change */
.fc-event.sim-hidden {
  opacity: 0.15 !important;
  pointer-events: none;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  .sim-banner {
    background: rgba(245, 158, 11, 0.15);
    border-color: rgba(245, 158, 11, 0.4);
    color: var(--color-text-primary);
  }

  .sim-banner-content {
    color: #fbbf24;
  }

  .sim-btn-discard {
    background: var(--color-bg-card);
    color: var(--color-text-secondary);
  }

  .fc-event.sim-proposed {
    background: rgba(245, 158, 11, 0.25) !important;
  }
}
