:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --line: #dde1e6;
  --text: #1f2937;
  --muted: #667085;
  --accent: #007aff;
  --chip: #eef4ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top right, #ffffff, #eef3fa 40%, #e9edf4);
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 340px 1fr;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #fbfcff;
  padding: 20px;
  overflow: auto;
  display: flex;
  flex-direction: column;
}

h1 {
  margin: 0 0 2px;
  font-size: 24px;
}

h2 {
  margin: 18px 0 8px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.subline {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.sidebar-reset {
  margin-top: 10px;
}

.menu-group {
  margin: 0 0 14px;
}

.menu-group h3 {
  font-size: 13px;
  margin: 0 0 6px;
}

.menu-group a {
  display: block;
  padding: 6px 8px;
  color: #0f172a;
  text-decoration: none;
  border-radius: 7px;
}

.menu-group a:hover {
  background: #edf2ff;
}

.menu-bottom {
  margin-top: auto;
  padding-top: 8px;
}

details.menu-fold {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

details.menu-fold > summary {
  cursor: pointer;
  list-style: none;
  padding: 9px 10px;
  font-weight: 600;
  font-size: 13px;
}

details.menu-fold #site-menus {
  padding: 0 10px 6px;
}

details.filter {
  margin-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

details.filter > summary {
  cursor: pointer;
  list-style: none;
  padding: 8px 10px;
  font-weight: 600;
  font-size: 13px;
}

details.history-panel > summary {
  background: #f8fafc;
}

.history-body {
  padding: 8px 10px 10px;
  display: grid;
  gap: 8px;
  max-height: 240px;
  overflow: auto;
}

.history-controls {
  display: flex;
  justify-content: flex-end;
}

.history-empty {
  margin: 2px 0 0;
  font-size: 12px;
  color: #6b7280;
}

.history-item {
  border: 1px solid #dbe3ef;
  border-radius: 8px;
  padding: 7px;
  background: #fff;
  display: grid;
  gap: 5px;
}

.history-head {
  font-size: 11px;
  font-weight: 700;
  color: #475569;
}

.history-desc {
  font-size: 11px;
  color: #111827;
  line-height: 1.35;
}

#room-color-legend {
  display: grid;
  gap: 6px;
  max-height: 180px;
  overflow: auto;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #1f2937;
  padding: 4px 6px;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
  transition: background-color 120ms ease, box-shadow 120ms ease;
}

.legend-item.is-hover,
.legend-item.is-active {
  background: #eef4ff;
}

.legend-item.is-active {
  box-shadow: inset 0 0 0 1px #95b8ff;
}

.legend-swatch {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  border: 1px solid rgba(15, 23, 42, 0.22);
  flex: 0 0 18px;
}

.legend-empty {
  margin: 0;
  font-size: 12px;
  color: #6b7280;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 10px 10px;
  max-height: 170px;
  overflow: auto;
}

.chip {
  border: 1px solid #c6d2ea;
  background: #fff;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
}

.chip.selector-chip {
  background: hsla(var(--chip-hue, 210), 88%, 52%, 0.1);
  border-color: hsla(var(--chip-hue, 210), 72%, 42%, 0.35);
}

.chip-divider {
  flex-basis: 100%;
  height: 1px;
  background: #d7deea;
  margin: 3px 0;
}

.chip.active {
  background: var(--chip);
  color: #003f99;
  border-color: #95b8ff;
}

.chip.selector-chip.active {
  background: hsla(var(--chip-hue, 210), 90%, 55%, 0.3);
  border-color: hsla(var(--chip-hue, 210), 80%, 45%, 0.65);
  color: #0b254a;
}

.chip.selector-chip.teacher-focus-hover {
  box-shadow: 0 0 0 2px hsla(var(--chip-hue, 210), 80%, 45%, 0.28);
}

.search-box {
  padding: 0 10px 10px;
}

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

.search-input {
  flex: 1;
  min-width: 0;
  border: 1px solid #c6d2ea;
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 13px;
  background: #fff;
}

.search-results {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.search-result-item {
  display: grid;
  gap: 3px;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #dbe3ef;
  border-radius: 10px;
  background: #fbfcff;
  text-align: left;
  appearance: none;
  cursor: pointer;
  color: #1f2937;
}

.search-result-item:hover {
  border-color: #b9c7de;
  background: #f6f9ff;
}

.search-result-item strong {
  font-size: 12px;
  line-height: 1.3;
}

.search-result-item span {
  font-size: 11px;
  color: #667085;
  line-height: 1.35;
}

.search-result-empty {
  padding: 8px 10px;
  font-size: 12px;
  color: #667085;
}

.search-jump-target {
  outline: 2px solid rgba(10, 132, 255, 0.85);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(10, 132, 255, 0.18);
}

.calendar-panel {
  padding: 8px 16px 14px;
  overflow: auto;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  gap: 16px;
}

.toolbar-main {
  display: flex;
  align-items: center;
  min-width: 0;
}

.toolbar-actions {
  display: grid;
  justify-items: end;
  gap: 8px;
  flex: 0 0 auto;
}

.toolbar-primary-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: nowrap;
}

#stats {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.stats-source {
  font-size: 12px;
}

.stats-source-meta {
  font-size: 12px;
  color: var(--muted);
}

#reset-all,
#refresh-data,
#toggle-room-color,
#toggle-google-calendar,
#google-prev,
#google-next,
#google-today,
#google-mode-week,
#google-mode-month,
#google-mode-year {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
}

.google-view-controls {
  display: none;
  gap: 6px;
  align-items: center;
  flex-wrap: nowrap;
}

.google-view-controls.visible {
  display: flex;
}

#google-range-label {
  font-size: 12px;
  color: #4b5563;
  margin: 0 4px;
}

#google-mode-week.active,
#google-mode-month.active,
#google-mode-year.active {
  background: #eef4ff;
  border-color: #95b8ff;
  color: #003f99;
}

.calendar-shell {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: auto;
  background: var(--panel);
}

.calendar-grid {
  min-width: 960px;
}

.header-row {
  display: grid;
  grid-template-columns: 70px repeat(5, 1fr);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: #f7f9fc;
  z-index: 2;
}

.gmonth {
  padding: 10px;
}

.gmonth-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.gmonth-weekday {
  font-size: 12px;
  color: #6b7280;
  padding: 4px 6px;
}

.gmonth-day {
  min-height: 110px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
  padding: 6px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 4px;
}

.gmonth-day.muted {
  background: #f9fafb;
  color: #9ca3af;
}

.gmonth-daynum {
  font-size: 12px;
  font-weight: 600;
}

.gmonth-events {
  display: grid;
  gap: 3px;
  align-content: start;
}

.gmonth-chip {
  font-size: 10px;
  border-radius: 999px;
  padding: 2px 6px;
  color: #111;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gyear {
  padding: 10px;
}

.gyear-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.gyear-card {
  width: 100%;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  background: #fff;
  padding: 8px;
  cursor: pointer;
  text-align: left;
}

.gyear-card:hover {
  background: #f8fbff;
}

.gyear-title {
  font-size: 13px;
  font-weight: 700;
}

.gyear-count {
  font-size: 11px;
  color: #4b5563;
  margin-top: 4px;
}

.header-row div {
  padding: 8px;
  border-right: 1px solid var(--line);
  font-weight: 600;
  text-align: center;
}

.header-row div:first-child {
  border-right: 1px solid var(--line);
  text-align: left;
}

.body-row {
  display: grid;
  grid-template-columns: 70px repeat(5, 1fr);
}

.all-day-row {
  display: grid;
  grid-template-columns: 70px 1fr;
  border-bottom: 1px solid var(--line);
  background: #fbfcff;
}

.all-day-label {
  padding: 8px;
  border-right: 1px solid var(--line);
  color: #667085;
  font-size: 11px;
  font-weight: 600;
}

.all-day-lanes {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-template-rows: repeat(var(--all-day-rows, 1), 26px);
  gap: 4px;
  padding: 6px;
}

.all-day-event {
  display: block;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 11px;
  line-height: 16px;
  color: #111827;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.16);
  border: 1px solid transparent;
}

.time-axis {
  position: relative;
  border-right: 1px solid var(--line);
  background: #fafbfc;
}

.time-label {
  position: absolute;
  right: 8px;
  transform: translateY(-50%);
  font-size: 11px;
  color: #8a94a6;
}

.day-col {
  position: relative;
  border-right: 1px solid var(--line);
}

.hour-line {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px solid #edf0f5;
}

.event {
  position: absolute;
  left: 7%;
  width: 89%;
  border-radius: 8px;
  color: #111;
  padding: 6px 7px;
  overflow: hidden;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.18);
  font-size: 11px;
  border: 1px solid transparent;
  backdrop-filter: saturate(130%);
  text-shadow: none;
  z-index: 1;
  transition: transform 120ms ease, box-shadow 120ms ease, filter 120ms ease, z-index 0ms linear 120ms;
}

.event:hover,
.event:focus-visible {
  z-index: 9999;
  opacity: 1;
  background-color: var(--event-solid) !important;
  transform: translateY(-2px) scale(1.02);
  filter: saturate(120%) brightness(1.08);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.28);
  transition: transform 120ms ease, box-shadow 120ms ease, filter 120ms ease;
}

.event b {
  display: block;
  font-size: 12px;
  margin-bottom: 2px;
}

.event.legend-dim,
.all-day-event.legend-dim {
  opacity: 0.25;
  filter: saturate(70%);
  z-index: 1;
}

.event.legend-focus,
.all-day-event.legend-focus {
  opacity: 1;
  background-color: var(--event-solid) !important;
  transform: translateY(-1px) scale(1.01);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.28);
  z-index: 50;
}

@media (max-width: 1020px) {
  .app {
    grid-template-columns: 1fr;
  }
  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: 48vh;
  }
}
