/* ── Reset & Base ──────────────────────────────────────── */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: var(--grid-bg, #fafafa);
  color: var(--text-color, #1a1a1a);
}

/* ── CSS Custom Properties (Light defaults) ───────────── */
:root {
  --grid-bg: #fafafa;
  --grid-line: #e5e5e5;
  --hour-line: #cccccc;
  --text-color: #1a1a1a;
  --header-bg: #ffffff;
  --header-text: #555555;
  --accent-color: #4A90D9;
}

/* ── App Layout ───────────────────────────────────────── */
.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 clamp(8px, 2vw, 24px);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Toolbar ──────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--grid-bg);
}

.toolbar__title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-color);
  letter-spacing: -0.01em;
  cursor: default;
  user-select: none;
}

.toolbar__title-input {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-color);
  letter-spacing: -0.01em;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--grid-line);
  outline: none;
  padding: 0;
  min-width: 80px;
}

.toolbar__actions {
  display: flex;
  gap: 8px;
}

.toolbar__btn {
  padding: 6px 14px;
  border: 1px solid var(--grid-line);
  border-radius: 6px;
  background: var(--grid-bg);
  color: var(--text-color);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}

.toolbar__btn:hover {
  background: var(--hour-line);
}

/* ── Timetable Grid ───────────────────────────────────── */
.grid-wrapper {
  overflow-x: visible;
  flex: 1;
}

.day-headers {
  display: flex;
  min-width: 600px;
}

.header-gutter {
  width: 56px;
  flex-shrink: 0;
}

.day-header {
  flex: 1;
  min-width: 0;
  text-align: center;
  padding: 8px 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--header-text);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-left: 1px solid var(--grid-line);
}

.day-header:first-of-type {
  border-left: none;
}

.day-header:last-of-type {
  border-right: 1px solid var(--grid-line);
}

.grid {
  display: flex;
  min-width: 600px;
}

/* ── Time Gutter ──────────────────────────────────────── */
.time-gutter {
  position: relative;
  width: 56px;
  flex-shrink: 0;
}

.time-gutter__label {
  position: absolute;
  right: 8px;
  font-size: 11px;
  color: var(--text-color);
  opacity: 0.5;
  transform: translateY(-50%);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ── Day Column ───────────────────────────────────────── */
.day-column {
  position: relative;
  flex: 1;
  min-width: 0;
  background:
    repeating-linear-gradient(
      to bottom,
      transparent 0px,
      transparent calc(var(--row-h) - 1px),
      var(--grid-line) calc(var(--row-h) - 1px),
      var(--grid-line) var(--row-h)
    );
  background-color: var(--grid-bg);
  background-size: 100% calc(100% - 1px);
  background-repeat: no-repeat;
  border-left: 1px solid var(--grid-line);
}

.day-column:first-of-type {
  border-left: none;
}

.day-column:last-of-type {
  border-right: 1px solid var(--grid-line);
}

.hour-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--hour-line);
  pointer-events: none;
  z-index: 0;
}

/* ── Course Block ─────────────────────────────────────── */
.course-block {
  position: absolute;
  left: 3px;
  right: 3px;
  padding: 4px 8px 4px 16px;
  cursor: pointer;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-radius: 4px;
}

.course-block::before {
  content: '';
  position: absolute;
  top: calc(var(--inset-top, 3px) + 3px);
  bottom: calc(var(--inset-bottom, 3px) + 3px);
  left: 8px;
  right: 2px;
  background: var(--block-bg, transparent);
  border-radius: 2px;
  transition: background 0.15s;
  pointer-events: none;
}

.course-block:hover::before {
  background: var(--block-bg, transparent);
  filter: brightness(0.97);
}

.course-block::after {
  content: '';
  position: absolute;
  top: calc(var(--inset-top, 3px) + 2px);
  bottom: calc(var(--inset-bottom, 3px) + 2px);
  left: 8px;
  right: 2px;
  border-radius: 3px;
  background: transparent;
  pointer-events: none;
  transition: background 0.15s;
}

.course-block:hover::after {
  background: rgba(0, 0, 0, 0.03);
}

.course-block__bracket {
  position: absolute;
  left: 4px;
  width: 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.course-block__serif-top,
.course-block__serif-bottom {
  width: 10px;
  flex-shrink: 0;
}

.course-block__serif-top {
  height: 1.5px;
  border-radius: 0.5px 0.5px 0.5px 0;
}

.course-block__serif-bottom {
  height: 1.5px;
  border-radius: 0 0.5px 0.5px 0.5px;
}

.course-block__stem {
  width: 1.5px;
  flex: 1;
  min-height: 2px;
  border-radius: 0;
}

.course-block__name {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text-color);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  position: relative;
  z-index: 1;
}

.course-block__location {
  font-size: 11px;
  color: var(--text-color);
  opacity: 0.55;
  line-height: 1.2;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  position: relative;
  z-index: 1;
}

.course-block__time {
  font-size: 10px;
  color: var(--text-color);
  opacity: 0.4;
  line-height: 1.2;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
  position: relative;
  z-index: 1;
}

/* ── Footnote ─────────────────────────────────────────── */
.footnote {
  padding: 8px 0 16px;
  min-width: 600px;
  margin-top: auto;
}

.footnote__text {
  font-size: 11px;
  color: var(--text-color);
  opacity: 0.35;
  cursor: default;
  user-select: none;
}

.footnote__input {
  font-size: 11px;
  color: var(--text-color);
  opacity: 0.5;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--grid-line);
  outline: none;
  padding: 0;
  min-width: 200px;
}

/* ── Modal Overlay ────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-panel {
  background: var(--header-bg);
  border-radius: 10px;
  padding: 24px;
  width: 340px;
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

.modal-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-color);
  margin-bottom: 16px;
}

/* ── Form Fields ──────────────────────────────────────── */
.field {
  margin-bottom: 12px;
}

.field--row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-color);
  opacity: 0.6;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.label--inline {
  display: inline;
  font-size: 12px;
  font-weight: 400;
  opacity: 0.7;
  margin-bottom: 0;
  text-transform: none;
  letter-spacing: normal;
}

.input,
.select {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--grid-line);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-color);
  background: var(--grid-bg);
  outline: none;
  box-sizing: border-box;
  transition: border-color 0.15s;
}

.input:focus,
.select:focus {
  border-color: var(--accent-color);
}

.time-row {
  display: flex;
  gap: 8px;
}

.time-row > .field {
  flex: 1;
}

/* ── Buttons ──────────────────────────────────────────── */
.actions {
  display: flex;
  gap: 8px;
  margin-top: 18px;
}

.btn-primary,
.btn-secondary,
.btn-danger {
  flex: 1;
  padding: 8px 0;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-primary {
  background: var(--accent-color);
  color: #fff;
}

.btn-secondary {
  background: var(--grid-bg);
  color: var(--text-color);
  border: 1px solid var(--grid-line);
}

.btn-danger {
  background: none;
  color: #e07a5f;
  flex: 0;
  padding: 8px 14px;
}

.btn-primary:hover,
.btn-secondary:hover,
.btn-danger:hover {
  opacity: 0.8;
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ── Color Picker ─────────────────────────────────────── */
.color-picker {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.color-picker__swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s;
  position: relative;
}

.swatch--active {
  border-color: var(--text-color);
}

.swatch::before {
  content: '';
  position: absolute;
  inset: 2px;
  border-radius: 50%;
  background:
    conic-gradient(#ddd 25%, #fff 25% 50%, #ddd 50% 75%, #fff 75%);
  background-size: 8px 8px;
  z-index: 0;
}

.swatch__inner {
  position: absolute;
  inset: 2px;
  border-radius: 50%;
  z-index: 1;
}

.swatch__remove {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-color);
  color: var(--grid-bg);
  font-size: 10px;
  line-height: 14px;
  text-align: center;
  z-index: 2;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}

.swatch--custom:hover .swatch__remove {
  opacity: 0.7;
}

.color-picker__custom-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px dashed var(--grid-line);
  cursor: pointer;
  background: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--text-color);
  opacity: 0.4;
  transition: opacity 0.15s;
}

.color-picker__custom-btn:hover {
  opacity: 0.7;
}

.color-picker__none-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid var(--grid-line);
  cursor: pointer;
  background: none;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.color-picker__none-btn--active {
  border-color: var(--text-color);
  border-width: 2px;
}

.color-picker__none-line {
  width: 18px;
  height: 1.5px;
  background: #e07a5f;
  transform: rotate(-45deg);
  border-radius: 1px;
}

.color-picker__row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
}

.color-picker__color-input {
  width: 32px;
  height: 28px;
  border: 1px solid var(--grid-line);
  border-radius: 4px;
  padding: 0;
  cursor: pointer;
  background: none;
}

.color-picker__opacity-slider {
  width: 80px;
  cursor: pointer;
  accent-color: var(--accent-color);
}

.color-picker__opacity-label {
  font-size: 10px;
  color: var(--text-color);
  opacity: 0.5;
  min-width: 28px;
  font-variant-numeric: tabular-nums;
}

.color-picker__preview {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--grid-line);
  position: relative;
  overflow: hidden;
}

.color-picker__preview::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    conic-gradient(#ddd 25%, #fff 25% 50%, #ddd 50% 75%, #fff 75%);
  background-size: 8px 8px;
}

.color-picker__preview-inner {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  z-index: 1;
}

.color-picker__apply-btn {
  padding: 4px 10px;
  border: 1px solid var(--grid-line);
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  background: var(--grid-bg);
  color: var(--text-color);
}

.color-picker__apply-btn:hover {
  opacity: 0.8;
}

/* ── Settings Panel ───────────────────────────────────── */
.settings-panel {
  width: 320px;
  max-width: 90vw;
}

.settings-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.settings-label {
  font-size: 12px;
  color: var(--text-color);
  opacity: 0.7;
}

.settings-time-input {
  width: 60px;
  padding: 4px 8px;
  border: 1px solid var(--grid-line);
  border-radius: 4px;
  font-size: 12px;
  color: var(--text-color);
  background: var(--grid-bg);
  text-align: right;
  outline: none;
  font-variant-numeric: tabular-nums;
}

.settings-time-input:focus {
  border-color: var(--accent-color);
}

.settings-color-input {
  width: 32px;
  height: 24px;
  border: 1px solid var(--grid-line);
  border-radius: 4px;
  padding: 0;
  cursor: pointer;
  background: none;
}

.slider-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.slider {
  width: 100px;
  cursor: pointer;
  accent-color: var(--accent-color);
}

.slider-value {
  font-size: 11px;
  color: var(--text-color);
  opacity: 0.5;
  min-width: 36px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Toggle switch */
.toggle {
  position: relative;
  width: 36px;
  height: 20px;
  border-radius: 10px;
  border: 1px solid var(--grid-line);
  background: var(--grid-bg);
  cursor: pointer;
  padding: 0;
  transition: background 0.2s, border-color 0.2s;
}

.toggle--on {
  background: var(--accent-color);
  border-color: var(--accent-color);
}

.toggle__knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-color);
  opacity: 0.4;
  transition: left 0.2s, opacity 0.2s, background 0.2s;
}

.toggle--on .toggle__knob {
  left: 18px;
  background: #fff;
  opacity: 1;
}

.divider {
  height: 1px;
  background: var(--grid-line);
  margin: 12px 0;
}

.settings-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.settings-btn {
  flex: 1;
  padding: 8px 0;
  border: 1px solid var(--grid-line);
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  background: var(--grid-bg);
  color: var(--text-color);
}

.settings-btn:hover {
  opacity: 0.8;
}

/* ── Export Dialog ─────────────────────────────────────── */
.export-panel {
  width: 320px;
  max-width: 90vw;
}

/* ── Share Dialog ──────────────────────────────────────── */
.share-panel {
  width: 320px;
  max-width: 90vw;
}

.share-desc {
  font-size: 12px;
  color: var(--text-color);
  opacity: 0.55;
  margin-bottom: 16px;
  line-height: 1.4;
}

.share-btn {
  width: 100%;
  margin-bottom: 8px;
  padding: 10px 0;
}
