/* =============================================================
   calendar.css — Campus Calendar
   Theme-aware: uses only tokens from style.css (:root / [data-theme]).
   Automatically adapts to light / dark / oled themes.
   ============================================================= */

/* Event-type color map (resolves via existing theme tokens).
   Personal color comes from the event record itself. */
:root {
  --cal-holiday:   #10b981;   /* emerald  */
  --cal-exam:      #ef4444;   /* red      */
  --cal-deadline:  #f97316;   /* orange   */
  --cal-academic:  #3b82f6;   /* blue     */
  --cal-event:     #8b5cf6;   /* violet   */
  --cal-break:     #06b6d4;   /* cyan     */
  --cal-festival:  #ec4899;   /* pink     */
  --cal-personal:  #84cc16;   /* lime     */
}

/* ---------- Shell ---------- */
.cal-shell {
  max-width: 1080px;
  margin: 0 auto;
  padding: 18px 16px 80px;
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
}

/* ---------- Toolbar ---------- */
.cal-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.cal-toolbar-left,
.cal-toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.cal-nav-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  transition: var(--transition);
}
.cal-nav-btn:hover:not(:disabled) {
  background: var(--surface3);
  border-color: var(--accent);
  color: var(--accent);
}
.cal-nav-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.cal-month-title {
  font-size: 18px;
  font-weight: 700;
  min-width: 180px;
  text-align: center;
  letter-spacing: -0.01em;
}
.cal-today-btn {
  background: var(--accent-bg);
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 7px 14px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
}
.cal-today-btn:hover:not(:disabled) { background: var(--accent); color: #fff; }
.cal-today-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.cal-view-switcher {
  display: inline-flex;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px;
}
.cal-view-btn {
  background: transparent;
  border: 0;
  color: var(--text2);
  padding: 6px 14px;
  border-radius: calc(var(--radius) - 2px);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}
.cal-view-btn.active {
  background: var(--accent);
  color: #fff;
}

/* ---------- Legend ---------- */
.cal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text2);
  margin-bottom: 12px;
}
.cal-lg { display: inline-flex; align-items: center; gap: 6px; }
.cal-dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
}
.cal-dot-holiday   { background: var(--cal-holiday); }
.cal-dot-exam      { background: var(--cal-exam); }
.cal-dot-deadline  { background: var(--cal-deadline); }
.cal-dot-academic  { background: var(--cal-academic); }
.cal-dot-event     { background: var(--cal-event); }
.cal-dot-break     { background: var(--cal-break); }
.cal-dot-festival  { background: var(--cal-festival); }
.cal-dot-personal  { background: var(--cal-personal); border: 1px dashed var(--text2); }

/* ---------- Weekday header ---------- */
.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.cal-weekdays > div {
  padding: 6px 4px;
  text-align: center;
}
.cal-weekdays > div:first-child,
.cal-weekdays > div:last-child { color: var(--accent); }

/* ---------- Month grid ---------- */
.cal-month {
  /* Allow vertical scroll, capture horizontal swipes for month navigation. */
  touch-action: pan-y;
  -webkit-user-select: none;
  user-select: none;
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  will-change: transform, opacity;
}
.cal-cell {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 96px;
  padding: 6px;
  cursor: pointer;
  transition: var(--transition);
  overflow: hidden;
}
.cal-cell:hover { border-color: var(--accent); background: var(--surface2); }
.cal-cell.out-of-month {
  opacity: 0.35;
  background: transparent;
}
.cal-cell.weekend { background: var(--surface2); }
.cal-cell.is-today {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-bg);
}
.cal-cell.is-today .cal-date-num {
  background: var(--accent);
  color: #fff;
}
.cal-cell.has-vacation::before {
  content: "";
  position: absolute; inset: 0;
  background:
    repeating-linear-gradient(45deg,
      transparent 0 8px,
      rgba(106, 138, 156, 0.10) 8px 14px);
  pointer-events: none;
}
.cal-cell.has-break {
  background: color-mix(in srgb, var(--cal-break) 10%, var(--surface));
}

.cal-date-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.cal-chips {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.cal-chip {
  display: block;
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  color: #fff;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-chip.personal {
  border: 1px dashed rgba(255,255,255,0.5);
}
.cal-chip-more {
  font-size: 10px;
  font-weight: 600;
  color: var(--text3);
  padding: 1px 4px;
}

/* Chip colors — match event types */
.cal-chip.type-holiday   { background: var(--cal-holiday); }
.cal-chip.type-exam      { background: var(--cal-exam); }
.cal-chip.type-deadline  { background: var(--cal-deadline); color: #111; }
.cal-chip.type-academic  { background: var(--cal-academic); }
.cal-chip.type-event     { background: var(--cal-event); }
.cal-chip.type-break     { background: var(--cal-break); }
.cal-chip.type-festival  { background: var(--cal-festival); }

/* ---------- Upcoming view ---------- */
.cal-upcoming-title {
  font-size: 18px;
  font-weight: 700;
  margin: 4px 0 12px;
}
.cal-upcoming-week {
  margin-bottom: 20px;
}
.cal-upcoming-week-head {
  font-size: 11px;
  font-weight: 700;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px dashed var(--border);
}
.cal-upcoming-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 6px;
  cursor: pointer;
  transition: var(--transition);
}
.cal-upcoming-row:hover {
  border-color: var(--accent);
  background: var(--surface2);
}
.cal-upcoming-date {
  flex-shrink: 0;
  text-align: center;
  min-width: 44px;
}
.cal-upcoming-date-day {
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
  color: var(--accent);
}
.cal-upcoming-date-dow {
  font-size: 10px;
  color: var(--text3);
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.05em;
  margin-top: 2px;
}
.cal-upcoming-info { flex: 1; min-width: 0; }
.cal-upcoming-title-row {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}
.cal-upcoming-meta {
  font-size: 11.5px;
  color: var(--text3);
  margin-top: 2px;
}
.cal-upcoming-chip {
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  color: #fff;
}

.cal-upcoming-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text3);
  font-size: 14px;
}

/* ---------- Drawer ---------- */
/* [hidden] must beat display:flex on .cal-drawer / .cal-add-form */
[hidden] { display: none !important; }

.cal-drawer-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 998;
  animation: cal-fade 0.18s ease;
}
@keyframes cal-fade { from { opacity: 0; } to { opacity: 1; } }

.cal-drawer {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  z-index: 999;
  display: flex;
  flex-direction: column;
  overflow: hidden;

  /* Desktop: right-side panel */
  top: 0; right: 0; bottom: 0;
  width: 420px;
  max-width: 100%;
  border-left: 1px solid var(--border);
  animation: cal-slide-right 0.2s ease;
}
@keyframes cal-slide-right {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}

.cal-drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border);
}
.cal-drawer-date {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.cal-drawer-sub {
  font-size: 12px;
  color: var(--text3);
  margin-top: 2px;
}
.cal-drawer-close {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  flex-shrink: 0;
  transition: var(--transition);
}
.cal-drawer-close:hover { background: var(--surface3); color: var(--accent); }

.cal-drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 18px 20px;
}

.cal-drawer-events {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}
.cal-drawer-event {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.cal-drawer-event.personal { border-style: dashed; }
.cal-drawer-event-stripe {
  width: 4px;
  align-self: stretch;
  border-radius: 2px;
  flex-shrink: 0;
}
.cal-drawer-event-body { flex: 1; min-width: 0; }
.cal-drawer-event-title {
  font-weight: 600;
  font-size: 14px;
  line-height: 1.3;
  color: var(--text);
}
.cal-drawer-event-note {
  font-size: 12px;
  color: var(--text3);
  margin-top: 3px;
  line-height: 1.4;
}
.cal-drawer-event-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.cal-icon-btn {
  background: transparent;
  border: 0;
  color: var(--text3);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: var(--transition);
}
.cal-icon-btn:hover { background: var(--surface3); color: var(--text); }
.cal-icon-btn.danger:hover { color: var(--danger); }
.cal-icon-btn[disabled] { opacity: 0.35; cursor: not-allowed; }

.cal-drawer-empty {
  text-align: center;
  color: var(--text3);
  font-size: 13px;
  padding: 18px 4px;
}

/* Add form */
.cal-add-btn {
  display: block;
  width: 100%;
  background: var(--accent-bg);
  border: 1px dashed var(--accent);
  color: var(--accent);
  padding: 10px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: var(--transition);
}
.cal-add-btn:hover { background: var(--accent); color: #fff; }

.cal-add-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 10px;
}
.cal-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 9px 11px;
  font: inherit;
  font-size: 14px;
  transition: var(--transition);
}
.cal-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-bg);
}
.cal-textarea { resize: vertical; min-height: 60px; font-size: 13px; }
.cal-form-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.cal-time-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--text3);
  font-weight: 600;
}
.cal-time-input { width: 120px; padding: 7px 9px; }

.cal-color-picker {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  flex: 1;
  justify-content: flex-end;
}
.cal-swatch {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  transition: var(--transition);
}
.cal-swatch:hover { transform: scale(1.1); }
.cal-swatch.active { border-color: var(--text); box-shadow: 0 0 0 2px var(--surface); }

.cal-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

/* ---------- Mobile responsiveness ---------- */
@media (max-width: 768px) {
  .cal-drawer {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-height: 82vh;
    border-left: 0;
    border-top: 1px solid var(--border);
    border-top-left-radius: var(--radius-lg);
    border-top-right-radius: var(--radius-lg);
    animation: cal-slide-up 0.22s ease;
  }
  @keyframes cal-slide-up {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
  }
}

@media (max-width: 600px) {
  .cal-shell { padding: 14px 10px 80px; }
  .cal-toolbar { gap: 8px; }
  .cal-toolbar-left { flex: 1; justify-content: center; }
  .cal-toolbar-right { flex: 1; justify-content: space-between; }
  .cal-month-title { font-size: 16px; min-width: 130px; }
  .cal-legend { font-size: 11px; padding: 8px 10px; gap: 8px 10px; }

  .cal-cell {
    min-height: 58px;
    padding: 4px 3px;
  }
  .cal-date-num {
    width: 20px; height: 20px;
    font-size: 11px;
  }
  .cal-chip,
  .cal-chip-more {
    display: none;  /* hidden on mobile — replaced by dot cluster */
  }
  .cal-dots {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    margin-top: 2px;
  }
  .cal-dots .cal-dot { width: 6px; height: 6px; }
}

@media (min-width: 601px) {
  .cal-dots { display: none; }
}

@media (max-width: 380px) {
  .cal-shell { padding: 12px 8px 80px; }
  .cal-weekdays > div { font-size: 10px; }
  .cal-cell { min-height: 52px; padding: 3px 2px; }
  .cal-date-num { width: 18px; height: 18px; font-size: 10.5px; }
  .cal-legend { font-size: 10.5px; }
  .cal-drawer { max-height: 88vh; }
  .cal-drawer-head { padding: 14px 14px 10px; }
  .cal-drawer-body { padding: 12px 14px 18px; }
}

/* Touch tap feedback (mobile) */
@media (hover: none) {
  .cal-cell:active { background: var(--surface2); }
  .cal-nav-btn:active, .cal-view-btn:active, .cal-today-btn:active { transform: scale(0.97); }
}

/* ---------- Toast (reusing existing pattern) ---------- */
.toast-container {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--surface3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.2);
  pointer-events: auto;
}
.toast-info    { border-color: var(--accent); }
.toast-success { border-color: var(--success); color: var(--success); }
.toast-error   { border-color: var(--danger);  color: var(--danger); }
