:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #66727e;
  --line: #dce2e7;
  --soft-line: #edf0f2;
  --surface: #ffffff;
  --canvas: #f3f5f6;
  --accent: #c9362b;
  --accent-soft: #fff0ee;
  --green: #23815d;
  --green-soft: #eaf7f1;
  --focus: #2d6cdf;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  min-width: 320px;
  overflow: hidden;
  background: var(--canvas);
  color: var(--ink);
  font-size: 14px;
  letter-spacing: 0;
}

button, input, select { font: inherit; letter-spacing: 0; }
button, select { cursor: pointer; }

button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.topbar {
  height: 56px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand, .sync, .selection-title { display: flex; align-items: center; }
.brand { gap: 10px; }
.brand-mark {
  display: block;
  width: 30px;
  height: 30px;
}
.brand div { display: grid; line-height: 1.15; }
.brand strong { font-size: 14px; font-weight: 700; }
.brand div span { margin-top: 2px; color: var(--muted); font-size: 10px; }

.sync { gap: 10px; }
.sync-state {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}
.sync-state i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
}
.sync-state.busy i { animation: pulse 1.2s infinite; background: var(--accent); }
@keyframes pulse { 50% { opacity: .35; transform: scale(.8); } }

.icon-button, .favorite-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: #4c5864;
}
.icon-button:hover, .favorite-button:hover { border-color: #b8c1c8; color: var(--ink); }
.icon-button:disabled { cursor: wait; opacity: .55; }

.app-shell {
  height: calc(100vh - 56px);
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(360px, 30vw) 1fr;
}

.browser-panel {
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.type-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) 42px;
  height: 44px;
  border-bottom: 1px solid var(--line);
}
.type-tabs button {
  position: relative;
  min-width: 0;
  padding: 0 7px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}
.type-tabs button:hover { color: var(--ink); background: #f8f9fa; }
.type-tabs button.active { color: var(--accent); }
.type-tabs button.active::after {
  content: "";
  position: absolute;
  right: 8px;
  bottom: -1px;
  left: 8px;
  height: 2px;
  background: var(--accent);
}
.type-tabs button:last-child svg { width: 16px; }

.filters { padding: 12px; border-bottom: 1px solid var(--soft-line); }
.search-box {
  height: 38px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid #cfd6dc;
  border-radius: 6px;
  background: white;
}
.search-box:focus-within { border-color: var(--focus); box-shadow: 0 0 0 2px #2d6cdf18; }
.search-box svg { width: 17px; color: var(--muted); }
.search-box input { min-width: 0; flex: 1; border: 0; outline: 0; color: var(--ink); }
.search-box input::placeholder { color: #8a949d; }
kbd {
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-bottom-color: #c6cdd3;
  border-radius: 4px;
  background: #f7f8f9;
  color: #7a858e;
  font: 11px ui-monospace, monospace;
}

.filter-row { display: grid; grid-template-columns: 1fr; gap: 7px; margin-top: 9px; }
.filter-row select {
  width: 100%;
  height: 34px;
  padding: 0 30px 0 9px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: white;
  color: #45515c;
  font-size: 12px;
  text-overflow: ellipsis;
}

.result-summary {
  min-height: 37px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--soft-line);
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}
.result-summary button { border: 0; background: transparent; color: var(--muted); font-size: 11px; text-transform: none; }
.result-summary button:hover { color: var(--accent); }

.result-list {
  min-height: 0;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}
.result-item {
  width: 100%;
  min-height: 56px;
  padding: 9px 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--soft-line);
  background: white;
  color: var(--ink);
}
.result-item:hover { background: #f8fafb; }
.result-item.active { background: var(--accent-soft); box-shadow: inset 3px 0 var(--accent); }
.result-item strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.result-item small { grid-column: 1; overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.result-item .mini-star { grid-column: 2; grid-row: 1 / span 2; align-self: center; color: #a5adb5; }
.result-item .mini-star.filled { color: #d39a16; fill: #f5bd35; }
.compare-check {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: center;
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
}
.no-results { padding: 42px 20px; color: var(--muted); text-align: center; line-height: 1.55; }

.schedule-panel { min-width: 0; display: grid; grid-template-rows: 66px 1fr; }
.schedule-toolbar {
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.selection-title { min-width: 0; gap: 11px; }
.selection-title > div { min-width: 0; }
.selection-title h1 { margin: 0; overflow: hidden; font-size: 15px; text-overflow: ellipsis; white-space: nowrap; }
.selection-title p { margin: 3px 0 0; overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.favorite-button { display: none; flex: 0 0 auto; }
.favorite-button.visible { display: grid; }
.favorite-button.active { border-color: #e0b041; background: #fff9df; color: #be8611; }
.favorite-button.active svg { fill: #f4bd35; }
.source-link { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; text-decoration: none; white-space: nowrap; }
.source-link:hover { color: var(--ink); }
.source-link svg { width: 15px; }
.schedule-actions { display: flex; align-items: center; gap: 10px; }
.clear-compare {
  display: none;
  height: 34px;
  padding: 0 10px;
  border: 1px solid #e1b9b5;
  border-radius: 5px;
  background: var(--accent-soft);
  color: #a9342c;
  font-size: 11px;
}
.clear-compare.visible { display: block; }
.export-button {
  display: none;
  height: 34px;
  align-items: center;
  gap: 6px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: white;
  color: #45515c;
  font-size: 11px;
  font-weight: 700;
}
.export-button.visible { display: flex; }
.export-button:hover { border-color: #aeb8c0; color: var(--ink); }
.export-button:disabled { cursor: wait; opacity: .55; }
.export-button svg { width: 15px; }
#group-filter {
  display: none;
  max-width: 170px;
  height: 34px;
  padding: 0 30px 0 9px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: white;
  color: #45515c;
  font-size: 12px;
}

.schedule-stage { position: relative; min-height: 0; overflow: hidden; padding: 14px; }
.calendar {
  width: 100%;
  height: 100%;
  display: none;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
}
.calendar.visible { display: grid; grid-template-rows: 40px 1fr; }
.calendar-head {
  min-width: 760px;
  display: grid;
  grid-template-columns: 58px repeat(5, minmax(140px, 1fr));
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: #f8f9fa;
  color: #45515c;
  font-size: 11px;
  text-align: center;
}
.calendar-head span { color: #8a949d; font-weight: 500; }
.calendar-head strong { border-left: 1px solid var(--line); font-size: 11px; }
.calendar-scroll { min-width: 0; min-height: 0; overflow-x: auto; overflow-y: hidden; }
.calendar-body {
  width: 100%;
  min-width: 760px;
  height: 510px;
  display: grid;
  grid-template-columns: 58px repeat(5, minmax(140px, 1fr));
  background: #fff;
}
.time-gutter, .day-track { position: relative; height: 510px; }
.time-gutter { background: #fafbfb; }
.time-gutter span {
  position: absolute;
  right: 8px;
  z-index: 2;
  color: #89939c;
  font-size: 10px;
  transform: translateY(-6px);
}
.day-track { border-left: 1px solid var(--line); }
.day-track > i {
  position: absolute;
  right: 0;
  left: 0;
  height: 1px;
  background: var(--soft-line);
}
.free-slot {
  position: absolute;
  right: 3px;
  left: 3px;
  z-index: 0;
  padding: 5px;
  overflow: hidden;
  border: 1px dashed #72b99c;
  border-radius: 4px;
  background: #eaf7f180;
  color: #28775a;
  font-size: 9px;
  font-weight: 700;
}
.calendar-event {
  position: absolute;
  z-index: 1;
  min-width: 0;
  padding: 5px 6px;
  overflow: hidden;
  border: 1px solid transparent;
  border-left-width: 3px;
  border-radius: 4px;
  text-align: left;
}
.calendar-event:hover { z-index: 4; filter: brightness(.97); box-shadow: 0 4px 14px #17202a20; }
.calendar-event strong, .calendar-event span { display: block; overflow: hidden; text-overflow: ellipsis; }
.calendar-event strong { color: #28343d; font-size: 10px; line-height: 1.25; }
.calendar-event span { margin-top: 3px; color: #596773; font-size: 9px; white-space: nowrap; }
.calendar-event.lecture { border-color: #e8bdb8; border-left-color: #ca4439; background: #fff0ee; }
.calendar-event.exercise { border-color: #b8d9ca; border-left-color: #27805e; background: #eaf7f1; }
.calendar-event.lab { border-color: #b9cee9; border-left-color: #3d6fa8; background: #edf5fd; }
.calendar-event.mixed { border-color: #d5c6e8; border-left-color: #74549e; background: #f5f0fb; }
.calendar-event.concurrent strong { color: #422f59; }
.calendar-event.concurrent span { line-height: 1.35; white-space: normal; }
.calendar-loading { grid-column: 1 / -1; display: grid; height: 100%; place-items: center; color: var(--muted); font-size: 12px; }
.empty-state {
  height: 100%;
  display: grid;
  place-content: center;
  justify-items: center;
  color: var(--muted);
  text-align: center;
}
.empty-state.hidden { display: none; }
.empty-state h2 { margin: 18px 0 5px; color: #3a4650; font-size: 16px; }
.empty-state p { max-width: 340px; margin: 0; font-size: 12px; line-height: 1.55; }
.empty-glyph { width: 168px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; opacity: .85; }
.empty-glyph span { height: 38px; border: 1px solid #cbd3d9; border-radius: 4px; background: white; }
.empty-glyph span:nth-child(2), .empty-glyph span:nth-child(6) { background: var(--green-soft); border-color: #b9dece; }
.empty-glyph span:nth-child(4) { background: var(--accent-soft); border-color: #edc7c3; }
.empty-mark { width: 48px; height: 48px; opacity: .28; }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 10px 13px;
  border: 1px solid #27323b;
  border-radius: 6px;
  background: #202a32;
  color: white;
  box-shadow: 0 8px 30px #17202a26;
  font-size: 12px;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: .18s ease;
}
.toast.visible { opacity: 1; transform: translateY(0); }

.event-dialog {
  width: min(480px, calc(100vw - 28px));
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  box-shadow: 0 24px 70px #17202a40;
}
.event-dialog::backdrop { background: #17202a70; }
.dialog-close { position: absolute; top: 12px; right: 12px; display: grid; width: 32px; height: 32px; padding: 0; place-items: center; border: 0; border-radius: 5px; background: #f2f4f5; color: #56616b; }
.event-kind { color: var(--accent); font-size: 11px; font-weight: 700; text-transform: uppercase; }
.event-dialog h2 { max-width: calc(100% - 30px); margin: 7px 0 20px; font-size: 19px; line-height: 1.3; }
.event-dialog dl { display: grid; grid-template-columns: 88px 1fr; gap: 10px 14px; margin: 0; }
.event-dialog dt { color: var(--muted); font-size: 11px; }
.event-dialog dd { margin: 0; font-size: 12px; line-height: 1.45; }
.concurrent-detail strong, .concurrent-detail span { display: block; }
.concurrent-detail span { margin-top: 3px; color: var(--muted); font-size: 11px; }

@media (max-width: 800px) {
  body { overflow: auto; }
  .topbar { position: sticky; top: 0; z-index: 5; }
  .sync-state span { display: none; }
  .app-shell { height: auto; min-height: calc(100vh - 56px); grid-template-columns: 1fr; grid-template-rows: minmax(420px, 52vh) minmax(520px, 70vh); }
  .browser-panel { height: 52vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .schedule-toolbar { padding: 0 12px; }
  .source-link { width: 34px; height: 34px; justify-content: center; border: 1px solid var(--line); border-radius: 6px; font-size: 0; }
  #group-filter { max-width: 122px; }
  .schedule-stage { padding: 8px; }
}

@media (min-width: 1200px) {
  .filter-row { grid-template-columns: 1.1fr 1fr; }
  .filter-row select:first-child { grid-column: 1 / -1; }
}
