/*
 * Modern UI tables: surfaces, headers, stripes, hover and attendance cells.
 */

.table {
  color: var(--tb-text);
  background-color: var(--tb-surface);
  border-color: var(--tb-table-border);
}

.table thead th {
  background-color: var(--tb-table-header-bg);
  color: var(--tb-heading);
  border-color: var(--tb-table-border);
  border-bottom-color: var(--tb-border-strong);
  font-weight: 600;
  vertical-align: middle;
}

.table td,
.table th {
  border-color: var(--tb-table-border);
  vertical-align: middle;
}

.table-striped tbody tr:nth-child(even of :where(:not(.d-none):not(.collapse))) {
  background-color: var(--tb-table-stripe-bg);
}

.table-striped tbody tr:nth-child(even of :where(:not(.d-none):not(.collapse))) > td,
.table-striped tbody tr:nth-child(even of :where(:not(.d-none):not(.collapse))) > th {
  background-color: var(--tb-table-stripe-bg);
}

.table-striped tbody tr:nth-child(odd of :where(:not(.d-none):not(.collapse))),
.table-striped tbody tr:nth-child(odd of :where(:not(.d-none):not(.collapse))) > td,
.table-striped tbody tr:nth-child(odd of :where(:not(.d-none):not(.collapse))) > th {
  background-color: transparent;
}

.table-hover tbody tr:hover {
  background-color: var(--tb-table-hover-bg);
  color: var(--tb-text);
}

.table-hover tbody tr:hover > td,
.table-hover tbody tr:hover > th {
  background-color: var(--tb-table-hover-bg);
}

.table-bordered,
.table-bordered th,
.table-bordered td {
  border-color: var(--tb-table-border);
}

.table-responsive {
  border-radius: var(--tb-radius-sm);
}

.table .thead-dark th {
  background-color: var(--tb-table-header-bg);
  color: var(--tb-heading);
  border-color: var(--tb-table-border);
}

.table .thead-light th {
  background-color: var(--tb-surface-alt);
  color: var(--tb-text);
  border-color: var(--tb-table-border);
}

.table-active,
.table-active > th,
.table-active > td {
  background-color: var(--tb-table-hover-bg);
}

.table-success,
.table-success > th,
.table-success > td {
  background-color: var(--tb-success-bg) !important;
}

.table-warning,
.table-warning > th,
.table-warning > td {
  background-color: var(--tb-warning-bg) !important;
}

.table-danger,
.table-danger > th,
.table-danger > td {
  background-color: var(--tb-danger-bg) !important;
}

.table-info,
.table-info > th,
.table-info > td {
  background-color: var(--tb-info-bg) !important;
}

/* Attendance matrix cells (replaces the old btn-* / border / shadow classes). */

.cell {
  display: block;
  margin: 4px;
  padding: 8px 10px;
  border: 1px solid var(--tb-border);
  border-radius: var(--tb-radius-sm);
  line-height: 1.25;
  text-align: center;
  transition: background-color var(--tb-transition), border-color var(--tb-transition),
    box-shadow var(--tb-transition), transform var(--tb-transition);
}

.cell[onclick] {
  cursor: pointer;
}

@media (hover: hover) {
  .cell[onclick]:hover {
    transform: translateY(-1px);
    box-shadow: var(--tb-shadow-sm);
  }
}

.cell--recorded {
  background-color: var(--tb-success-bg);
  border-color: var(--tb-success);
  color: var(--tb-text);
}

.cell--ongoing {
  background-color: var(--tb-info-bg);
  border-color: var(--tb-info);
  border-style: dashed;
  color: var(--tb-text);
}

.cell--pending {
  background-color: var(--tb-warning-bg);
  border-color: var(--tb-warning);
  color: var(--tb-text);
}

.cell--skipped {
  background-color: var(--tb-cell-neutral-bg);
  border-color: var(--tb-border-strong);
  color: var(--tb-text-muted);
}

.cell--missing {
  background-color: var(--tb-danger-bg);
  border-color: var(--tb-danger);
  color: var(--tb-text);
}

.cell--upcoming {
  background: var(--tb-cell-neutral-bg);
  border: 1px dashed var(--tb-border-strong);
  color: var(--tb-text);
  font-weight: 500;
}

#TableClasses tbody tr.tb-row-selected > td,
#TableClasses tbody tr.tb-row-selected > th {
  background-color: var(--tb-selection-bg) !important;
  color: var(--tb-text) !important;
}

#TableClasses tbody tr.tb-row-selected > td:first-child {
  box-shadow: inset 3px 0 0 var(--tb-primary);
  font-weight: 600;
}

.cell-label {
  background: var(--tb-cell-neutral-bg);
  color: var(--tb-heading);
  font-weight: 600;
}

@media (max-width: 768px) {
  .table-sm td,
  .table-sm th {
    padding: 0.45rem 0.5rem;
    font-size: 13px;
  }
}

/* Attendance matrix and Today strip */

.attendance-table {
  border: 1px solid var(--tb-table-border);
  border-radius: var(--tb-radius-sm);
  border-collapse: separate;
  border-spacing: 0;
  background-color: var(--tb-surface);
  color: var(--tb-text);
}

.attendance-table thead th {
  background-color: var(--tb-table-header-bg);
  color: var(--tb-heading);
  border: 0;
  border-bottom: 2px solid var(--tb-table-border);
}

.attendance-table tbody td,
.attendance-table tbody th {
  background-color: var(--tb-surface);
  border: 0;
  border-bottom: 1px solid var(--tb-table-border);
}

.attendance-table tbody tr:last-child td,
.attendance-table tbody tr:last-child th {
  border-bottom: 0;
}

.attendance-table tbody tr:hover > td,
.attendance-table tbody tr:hover > th {
  background-color: var(--tb-surface);
}

.attendance-day-header {
  white-space: nowrap;
  font-weight: 600;
}

.attendance-day-header__name,
.attendance-day-header__date {
  display: block;
}

.attendance-day-header__date {
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--tb-text-muted);
}

.attendance-day--today {
  box-shadow: inset 0 -3px 0 var(--tb-primary);
}

.attendance-period-cell {
  position: sticky;
  left: 0;
  z-index: 2;
  background-color: var(--tb-surface);
  box-shadow: 1px 0 0 var(--tb-table-border);
  white-space: nowrap;
  font-weight: 600;
}

.attendance-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  justify-content: space-between;
}

.attendance-toolbar .btn {
  margin: 0;
}

.attendance-week-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.attendance-week-range {
  font-weight: 600;
  color: var(--tb-heading);
}

.attendance-legend {
  margin-top: 0.75rem;
  color: var(--tb-text-muted);
  font-size: 0.85rem;
}

.attendance-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 100%;
  min-height: 48px;
  margin: 0;
  padding: 6px 8px;
  font: inherit;
  line-height: 1.25;
  text-align: center;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  border-radius: var(--tb-radius-sm);
}

.attendance-cell:hover {
  transform: translateY(-1px);
  box-shadow: var(--tb-shadow-sm);
}

.attendance-cell:active {
  transform: translateY(1px);
}

.attendance-cell:focus-visible {
  outline: 2px solid var(--tb-focus);
  outline-offset: 2px;
}

.attendance-cell__name {
  font-weight: 600;
}

.attendance-cell__meta {
  font-size: 0.8rem;
  color: var(--tb-text-muted);
}

.attendance-cell__state {
  font-size: 0.75rem;
  color: var(--tb-text-muted);
}

.attendance-day-picker {
  display: none;
  flex-wrap: nowrap;
  gap: 0.4rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
  margin-bottom: 0.75rem;
}

.attendance-day-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-width: 44px;
  min-height: 44px;
  padding: 0.3rem 0.4rem;
  background-color: var(--tb-surface);
  border: 1px solid var(--tb-border);
  border-radius: var(--tb-radius-sm);
  color: var(--tb-text);
  font: inherit;
  cursor: pointer;
}

.attendance-day-chip.active {
  background-color: var(--tb-primary);
  border-color: var(--tb-primary);
  color: var(--tb-primary-fg);
}

.attendance-day-chip__date {
  font-size: 0.7rem;
  opacity: 0.8;
}

.attendance-student-toggle {
  width: 100%;
  background: none;
  border: 0;
  color: inherit;
  font: inherit;
  text-align: center;
  cursor: pointer;
}

.attendance-student-toggle:hover {
  text-decoration: underline;
}

.attendance-student-toggle:focus-visible {
  outline: 2px solid var(--tb-focus);
  outline-offset: 2px;
}

.attendance-table thead th.attendance-period-cell {
  background-color: var(--tb-table-header-bg);
}

/* Schedule timetable */

.schedule-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  margin-bottom: 1rem;
  background-color: var(--tb-surface);
  border: 1px solid var(--tb-border);
  border-radius: var(--tb-radius);
}

.schedule-view-toggle {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--tb-border-strong);
  border-radius: var(--tb-radius-sm);
}

.schedule-view-toggle__btn {
  min-height: 44px;
  padding: 0.35rem 0.9rem;
  background-color: var(--tb-surface);
  border: 0;
  color: var(--tb-text);
  font: inherit;
  cursor: pointer;
}

.schedule-view-toggle__btn + .schedule-view-toggle__btn {
  border-left: 1px solid var(--tb-border-strong);
}

.schedule-view-toggle__btn.is-active {
  background-color: var(--tb-primary);
  color: var(--tb-primary-fg);
}

.schedule-view-toggle__btn:focus-visible,
.schedule-toggle:focus-within,
.schedule-print:focus-visible {
  outline: 2px solid var(--tb-focus);
  outline-offset: 2px;
}

.schedule-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 44px;
  margin: 0;
  padding: 0 0.5rem;
  color: var(--tb-text);
  cursor: pointer;
}

.schedule-toggle input {
  width: 1.1rem;
  height: 1.1rem;
}

.schedule-table-wrap {
  overflow-x: auto;
}

@media (min-width: 992px) {
  .schedule-table-wrap {
    overflow: visible;
  }
}

.schedule-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid var(--tb-table-border);
  border-radius: var(--tb-radius-sm);
  color: var(--tb-text);
}

.schedule-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background-color: var(--tb-table-header-bg);
  border-bottom: 1px solid var(--tb-table-border);
  color: var(--tb-heading);
  font-weight: 600;
}

.schedule-table th,
.schedule-table td {
  padding: 0.4rem;
  border-bottom: 1px solid var(--tb-table-border);
  vertical-align: top;
}

.schedule-period {
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 82px;
  background-color: var(--tb-surface);
  border-right: 1px solid var(--tb-table-border);
  text-align: center;
  vertical-align: middle;
}

.schedule-table thead .schedule-period {
  z-index: 3;
}

.schedule-period__num {
  display: block;
  font-weight: 600;
}

.schedule-period__name {
  display: block;
  font-size: 0.75rem;
  color: var(--tb-text-muted);
}

.schedule-period__time {
  display: block;
  font-size: 0.75rem;
  color: var(--tb-text-muted);
}

.schedule-period__now {
  display: inline-block;
  margin-top: 0.2rem;
  padding: 0 0.4rem;
  background-color: var(--tb-primary);
  border-radius: 999px;
  color: var(--tb-primary-fg);
  font-size: 0.7rem;
  line-height: 1.5;
}

.schedule-period.is-now .schedule-period__num {
  color: var(--tb-primary);
}

.schedule-day {
  min-width: 110px;
  text-align: center;
}

.schedule-day.is-today,
.schedule-period-cell.is-today {
  background-color: var(--tb-selection-bg);
}

.schedule-period-cell {
  text-align: center;
}

.schedule-row-hidden,
.schedule-col-hidden {
  display: none !important;
}

.schedule-card {
  display: block;
  width: 100%;
  min-height: 64px;
  margin: 0.15rem 0;
  padding: 0.45rem 0.55rem;
  background-color: var(--tb-surface);
  border: 1px solid var(--tb-border);
  border-left: var(--schedule-accent-width) solid var(--schedule-accent, var(--tb-border-strong));
  border-radius: var(--tb-radius-sm);
  color: var(--tb-text);
  font: inherit;
  text-align: left;
  appearance: none;
  cursor: pointer;
  transition: box-shadow var(--tb-transition), border-color var(--tb-transition),
    transform var(--tb-transition);
}

.schedule-card:hover {
  border-color: var(--tb-border-strong);
  box-shadow: var(--tb-shadow-sm);
  transform: translateY(-1px);
}

.schedule-card:focus-visible {
  outline: 2px solid var(--tb-focus);
  outline-offset: 2px;
}

.schedule-card:active {
  transform: translateY(1px);
}

.schedule-card__name {
  display: block;
  font-weight: 600;
}

.schedule-card__meta,
.schedule-card__room {
  display: block;
  font-size: 0.78rem;
  opacity: 0.8;
}

.schedule-card__now {
  display: inline-block;
  margin-top: 0.15rem;
  padding: 0 0.35rem;
  background-color: var(--tb-primary);
  border-radius: 999px;
  color: var(--tb-primary-fg);
  font-size: 0.68rem;
}

@media (prefers-reduced-motion: reduce) {
  .schedule-card {
    transition: none;
  }

  .schedule-card:hover,
  .schedule-card:active {
    transform: none;
  }
}

/* Schedule palette. PHP stores keys only; these are the visual values. */

.schedule-color--sand { background-color: #f3ecdf; color: #4a3f2b; --schedule-accent: #a1794b; --schedule-bg: #f3ecdf; --schedule-fg: #4a3f2b; }
.schedule-color--brown { background-color: #ddc3a9; color: #48220f; --schedule-accent: #8a4a28; --schedule-bg: #ddc3a9; --schedule-fg: #48220f; }
.schedule-color--red { background-color: #fecaca; color: #7f1d1d; --schedule-accent: #dc2626; --schedule-bg: #fecaca; --schedule-fg: #7f1d1d; }
.schedule-color--orange { background-color: #ffedd5; color: #7c2d12; --schedule-accent: #ea580c; --schedule-bg: #ffedd5; --schedule-fg: #7c2d12; }
.schedule-color--amber { background-color: #fef3c7; color: #78350f; --schedule-accent: #d97706; --schedule-bg: #fef3c7; --schedule-fg: #78350f; }
.schedule-color--yellow { background-color: #fef9c3; color: #713f12; --schedule-accent: #ca8a04; --schedule-bg: #fef9c3; --schedule-fg: #713f12; }
.schedule-color--lime { background-color: #ecfccb; color: #365314; --schedule-accent: #65a30d; --schedule-bg: #ecfccb; --schedule-fg: #365314; }
.schedule-color--olive { background-color: #e9eccb; color: #474d16; --schedule-accent: #808a2f; --schedule-bg: #e9eccb; --schedule-fg: #474d16; }
.schedule-color--green { background-color: #bbf7d0; color: #14532d; --schedule-accent: #16a34a; --schedule-bg: #bbf7d0; --schedule-fg: #14532d; }
.schedule-color--emerald { background-color: #d1fae5; color: #064e3b; --schedule-accent: #059669; --schedule-bg: #d1fae5; --schedule-fg: #064e3b; }
.schedule-color--teal { background-color: #d6e8d9; color: #244a34; --schedule-accent: #3f8262; --schedule-bg: #d6e8d9; --schedule-fg: #244a34; }
.schedule-color--cyan { background-color: #a5f3fc; color: #164e63; --schedule-accent: #0891b2; --schedule-bg: #a5f3fc; --schedule-fg: #164e63; }
.schedule-color--sky { background-color: #e0f2fe; color: #0c4a6e; --schedule-accent: #0284c7; --schedule-bg: #e0f2fe; --schedule-fg: #0c4a6e; }
.schedule-color--steel { background-color: #dbe4ee; color: #1e293b; --schedule-accent: #375a7f; --schedule-bg: #dbe4ee; --schedule-fg: #1e293b; }
.schedule-color--cobalt { background-color: #dbe7ff; color: #0b2a6b; --schedule-accent: #0e3efa; --schedule-bg: #dbe7ff; --schedule-fg: #0b2a6b; }
.schedule-color--violet { background-color: #ede9fe; color: #4c1d95; --schedule-accent: #7c3aed; --schedule-bg: #ede9fe; --schedule-fg: #4c1d95; }
.schedule-color--fuchsia { background-color: #fae8ff; color: #701a75; --schedule-accent: #c026d3; --schedule-bg: #fae8ff; --schedule-fg: #701a75; }
.schedule-color--pink { background-color: #fce7f3; color: #831843; --schedule-accent: #db2777; --schedule-bg: #fce7f3; --schedule-fg: #831843; }
.schedule-color--rose { background-color: #ffe4e6; color: #881337; --schedule-accent: #e11d48; --schedule-bg: #ffe4e6; --schedule-fg: #881337; }
.schedule-color--default { background-color: var(--tb-surface); color: var(--tb-text); --schedule-accent: var(--tb-border-strong); --schedule-bg: var(--tb-surface); --schedule-fg: var(--tb-text); }

/* The palette class on the card supplies the custom properties; the card itself
   stays neutral so the tint only paints the header. */

.overview-class-card[data-color-target] {
  background-color: var(--tb-surface);
  color: var(--tb-text);
  border-left: var(--schedule-accent-width) solid var(--schedule-accent, var(--tb-border-strong));
}

.overview-class-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background-color: var(--schedule-bg);
  color: var(--schedule-fg);
  text-align: left;
}

.overview-class-head__text {
  min-width: 0;
}

.overview-class-name {
  display: block;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.overview-class-meta {
  display: block;
  font-size: 0.85rem;
  opacity: 0.85;
}

.overview-class-color {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: transparent;
  border: 1px solid currentColor;
  border-radius: var(--tb-radius-sm);
  color: inherit;
  font-size: 1.05rem;
  cursor: pointer;
}

.overview-class-color:hover {
  background-color: rgba(0, 0, 0, 0.08);
}

.overview-class-color:focus-visible {
  outline: 2px solid var(--tb-focus);
  outline-offset: 2px;
}

html[data-theme="dark"] .overview-class-color:hover {
  background-color: rgba(255, 255, 255, 0.12);
}

/* Schedule color picker */

.schedule-swatch-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.5rem;
}

.schedule-swatch {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-height: 44px;
  margin: 0;
  padding: 0.3rem;
  border: 2px solid transparent;
  border-radius: var(--tb-radius-sm);
  cursor: pointer;
}

.schedule-swatch:focus-within {
  outline: 2px solid var(--tb-focus);
  outline-offset: 2px;
}

.schedule-swatch.is-checked {
  border-color: var(--tb-primary);
  box-shadow: var(--tb-shadow-sm);
}

.schedule-swatch input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
}

.schedule-swatch__tile {
  display: block;
  width: 100%;
  height: 34px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-left: var(--schedule-accent-width) solid var(--schedule-accent, var(--tb-border-strong));
  border-radius: 6px;
}

.schedule-swatch.is-checked .schedule-swatch__tile,
.schedule-swatch input:checked + .schedule-swatch__tile {
  outline: 2px solid var(--tb-primary);
  outline-offset: 1px;
}

.schedule-swatch__label {
  display: block;
  color: var(--tb-text);
  font-size: 0.72rem;
  line-height: 1.2;
  text-align: center;
}

.schedule-color-selected {
  color: var(--tb-text-muted);
}

.schedule-empty {
  padding: 1.5rem;
  background-color: var(--tb-surface);
  border: 1px solid var(--tb-border);
  border-radius: var(--tb-radius);
  color: var(--tb-text-muted);
  text-align: center;
}

/* The Today view shows this message instead of the timetable, so it carries the
   page on its own rather than reading as a footnote under a table. */
.schedule-empty--today {
  padding: 2.5rem 1.5rem;
  background-color: var(--tb-surface-alt);
  border: 1px dashed var(--tb-border-strong);
  color: var(--tb-text);
}

.schedule-empty--today i {
  margin-right: 0.4rem;
  color: var(--tb-text-muted);
}

@media (max-width: 575.98px) {
  .schedule-swatch-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 991.98px) {
  .schedule-table {
    min-width: 760px;
  }

  .schedule-day {
    min-width: 130px;
  }

  /* Faculty timetable on small screens: the period column stops pinning and
     follows the grid, and both column kinds are sized from their content by
     schedule.js. These rules are the no-JS fallback and the measuring pass. */
  .schedule-table--fluid {
    width: auto;
    min-width: 0;
  }

  .schedule-table--fluid .schedule-period {
    position: static;
    width: 1%;
  }

  .schedule-table--fluid thead .schedule-period {
    position: sticky;
    top: 0;
    left: auto;
  }

  .schedule-table--fluid .schedule-period__time {
    white-space: nowrap;
  }

  .schedule-table--fluid .schedule-day {
    min-width: 0;
  }

  /* Measuring pass: with nothing allowed to wrap, each column's minimum width
     is its content width, so auto layout reports the same numbers as
     width: max-content would, on browsers that never supported it. */
  .schedule-table--fluid.is-measuring {
    width: auto;
  }

  .schedule-table--fluid.is-measuring .schedule-period {
    width: auto;
  }

  .schedule-table--fluid.is-measuring th,
  .schedule-table--fluid.is-measuring td {
    min-width: 0;
    white-space: nowrap;
  }

  .schedule-view-toggle__btn,
  .schedule-toggle,
  .schedule-print {
    min-height: 44px;
  }
}
