/* Allow space for right menu when expanded */
:root {
  --calendar-widget-side-offset: 280px;
}

/* Calendar Widget Button */
.calendar-widget-btn {
  position: fixed;
  bottom: 30px;
  right: 30px;
  z-index: 2001;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: transform 0.2s, box-shadow 0.2s;
}

/* The FAB also carries the generic .btn class, so page stylesheets loaded
   after this one (e.g. messaging.css's .btn { border-radius:8px; padding }) can
   clobber its circular shape and squash the logo. Win with higher specificity. */
.btn.calendar-widget-btn {
  border-radius: 50%;
  padding: 0;
}

.calendar-widget-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.calendar-widget-btn:active {
  transform: scale(0.95);
}

.calendar-widget-btn-logo {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: contain;
  object-position: center;
  display: block;
  padding: 0;
  margin: 0;
}

/* Calendar Widget Container */
.calendar-widget-container {
  position: fixed;
  bottom: 100px;
  right: 30px;
  z-index: 2000;
  width: 340px;
  max-width: 95vw;
  max-height: calc(100vh - 140px);
  background: white;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  display: none;
  flex-direction: column;
  overflow: hidden;
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.calendar-widget-resize-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  z-index: 2201;
  background: transparent;
}

.calendar-widget-resize-handle.nw {
  top: 0;
  left: 0;
  cursor: nwse-resize;
}

.calendar-widget-resize-handle.ne {
  top: 0;
  right: 0;
  cursor: nesw-resize;
}

.calendar-widget-resize-handle.sw {
  bottom: 0;
  left: 0;
  cursor: nesw-resize;
}

.calendar-widget-resize-handle.se {
  bottom: 0;
  right: 0;
  cursor: nwse-resize;
}

.calendar-widget-container.active {
  display: flex;
}

/* Expanded view - bottom 30% of screen */
.calendar-widget-container.expanded {
  position: fixed;
  top: 16px;
  left: 16px;
  right: auto;
  bottom: auto;
  width: calc(100vw - var(--calendar-widget-side-offset) - 32px);
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  height: 70vh;
  border-radius: 12px;
  z-index: 2000;
  flex-direction: column;
  display: flex;
}

.calendar-widget-container.expanded .calendar-widget-content {
  display: flex;
  flex-direction: row;
  gap: 8px;
  padding: 12px;
  overflow-x: auto;
  overflow-y: auto;
  flex: 1;
}

.calendar-widget-container.expanded .calendar-widget-day {
  margin: 0;
  border: 1px solid #dee2e6;
  border-radius: 0;
  min-width: 180px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.calendar-widget-container.expanded .calendar-widget-day:last-child {
  border-right: 1px solid #dee2e6;
}

.calendar-widget-container.expanded .calendar-widget-day-content {
  flex: 1;
  overflow-y: auto;
  max-height: calc(70vh - 80px);
}

.calendar-widget-container.daily-mode .calendar-widget-day,
.calendar-widget-container:not(.expanded).daily-mode .calendar-widget-day {
  flex: 1 0 100%;
  min-width: 100%;
  max-width: 100%;
}

/* Consistent horizontal layout for weekly view in compact */
.calendar-widget-container:not(.expanded).weekly-mode .calendar-widget-content {
  display: flex;
  flex-direction: row;
  gap: 8px;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 12px;
}

/* General day sizing */
.calendar-widget-day {
  flex: 0 0 220px;
  min-width: 220px;
}

/* Prevent oversized columns in compact weekly */
.calendar-widget-container:not(.expanded).weekly-mode .calendar-widget-day {
  flex: 0 0 240px;
  min-width: 240px;
  max-width: 260px;
}

@media (max-width: 1200px) {
  .calendar-widget-container.expanded {
    width: calc(100vw - 24px);
    left: 12px;
    max-width: calc(100vw - 24px);
    height: 70vh;
  }
}

.calendar-widget-container.expanded .calendar-widget-header {
  position: relative;
  z-index: 10;
  flex-shrink: 0;
}

/* Hide expand button in expanded view, show minimize button */
.calendar-widget-container.expanded .calendar-widget-expand {
  display: none;
}

.calendar-widget-container.expanded .calendar-widget-minimize {
  display: flex;
}

/* Hide minimize button in compact view */
.calendar-widget-container:not(.expanded) .calendar-widget-minimize {
  display: none;
}
.calendar-widget-container:not(.expanded) .calendar-widget-view-toggle {
  display: inline-flex;
}
.calendar-widget-container.expanded .calendar-widget-view-toggle {
  display: none;
}

.calendar-widget-container.dark-mode {
  background: var(--bg-card, #2d3748);
  color: white;
}

/* Widget Header */
.calendar-widget-header {
  padding: 12px 16px;
  background: linear-gradient(135deg, var(--accent-blue) 0%, var(--accent-blue-hover) 100%);
  color: white;
  font-weight: 600;
  font-size: 0.95rem;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  cursor: grab;
  flex-shrink: 0;
  gap: 8px;
  flex-wrap: wrap;
}

.calendar-widget-header:active {
  cursor: grabbing;
}

/* Close button - always on left */
.calendar-widget-close {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  font-size: 1.2rem;
  padding: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.2s;
  flex-shrink: 0;
}

.calendar-widget-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Title - left aligned in center-left */
.calendar-widget-title {
  flex: 1;
  text-align: left;
}

.calendar-widget-nav {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  font-size: 1.2rem;
  padding: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.2s;
  flex-shrink: 0;
}

.calendar-widget-nav:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Expand button - compact view only, on right */
.calendar-widget-expand {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0 8px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.2s;
  flex-shrink: 0;
}

.calendar-widget-expand:hover {
  background: rgba(255, 255, 255, 0.2);
}

.calendar-widget-expand::before {
  content: '⛶';
}

.calendar-widget-minimize {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0 8px;
  width: 28px;
  height: 28px;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.2s;
  flex-shrink: 0;
}

.calendar-widget-minimize:hover {
  background: rgba(255, 255, 255, 0.2);
}

.calendar-widget-minimize::before {
  content: '⛶';
}

.calendar-widget-view-toggle {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: white;
  cursor: pointer;
  font-size: 0.8rem;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: background 0.2s, color 0.2s, border-color 0.2s;
  flex-shrink: 0;
  line-height: 1.1;
  white-space: nowrap;
}

.calendar-widget-view-toggle:hover {
  background: rgba(255, 255, 255, 0.15);
}

.calendar-widget-container.expanded .calendar-widget-view-toggle {
  display: none;
}

/* Widget Content */
.calendar-widget-content {
  padding: 12px;
  overflow-y: auto;
  flex: 1;
  font-size: 0.875rem;
  display: flex;
  flex-direction: row;
  gap: 8px;
  overflow-x: auto;
}

.calendar-widget-content::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.calendar-widget-content::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.05);
  border-radius: 3px;
}

.calendar-widget-content::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 3px;
}

.calendar-widget-container:not(.expanded) .calendar-widget-content {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 12px;
  gap: 8px;
}

.calendar-widget-content::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.3);
}

.calendar-widget-container.expanded .calendar-widget-content::-webkit-scrollbar {
  height: 8px;
}

.calendar-widget-container.expanded .calendar-widget-content::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.3);
}

.calendar-widget-day {
  margin-bottom: 12px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #e9ecef;
}

.calendar-widget-container.dark-mode .calendar-widget-day {
  border-color: var(--border-color, #475569);
}

.calendar-widget-day-header {
  background: var(--surface-light, #f8f9fa);
  padding: 8px 10px;
  font-weight: 600;
  color: var(--accent-blue, var(--accent-blue));
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--accent-blue);
  flex-shrink: 0;
}

.calendar-widget-container.dark-mode .calendar-widget-day-header {
  background: var(--surface-dark, #3d444d);
  color: var(--accent-blue, #60a5fa);
  border-bottom-color: var(--accent-blue, #60a5fa);
}

/* Day header is a link to the full day view (calendar/day/). */
a.calendar-widget-day-header {
  display: block;
  text-decoration: none;
  color: var(--accent-blue);
  cursor: pointer;
  transition: filter 0.15s ease;
}

a.calendar-widget-day-header:hover {
  filter: brightness(1.12);
  text-decoration: underline;
}

.calendar-widget-container.expanded .calendar-widget-day-header {
  padding: 10px 8px;
  font-size: 0.75rem;
  white-space: nowrap;
}

.calendar-widget-day-content {
  padding: 8px 10px;
}

.calendar-widget-event {
  display: block;
  padding: 6px 8px;
  margin-bottom: 4px;
  border-radius: 6px;
  font-size: 0.75rem;
  line-height: 1.3;
  background: rgba(55, 48, 163, 0.1);
  border: 1px solid rgba(55, 48, 163, 0.25);
  word-break: break-word;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}

.calendar-widget-event:visited {
  text-decoration: none;
  color: inherit;
}

.calendar-widget-event:hover,
.calendar-widget-event:focus-visible {
  filter: brightness(0.96);
  text-decoration: none;
  color: inherit;
}

.calendar-widget-event.personal {
  background: rgba(15, 118, 110, 0.1);
  border-color: rgba(15, 118, 110, 0.3);
  color: inherit;
}

.calendar-widget-event.recommended {
  background: rgba(245, 158, 11, 0.1);
  border-color: rgba(245, 158, 11, 0.3);
  opacity: 0.9;
}

.calendar-widget-event.recommended.favorite-creator {
  background: rgba(245, 158, 11, 0.18);
  border-color: rgba(217, 119, 6, 0.4);
  opacity: 1;
  box-shadow: 0 3px 10px rgba(245, 158, 11, 0.15);
}

.calendar-widget-container.dark-mode .calendar-widget-event.recommended.favorite-creator {
  background: rgba(245, 158, 11, 0.18);
  border-color: rgba(251, 191, 36, 0.4);
}

.calendar-widget-free-slot {
  padding: 6px 8px;
  margin-bottom: 4px;
  border-radius: 6px;
  font-size: 0.75rem;
  line-height: 1.3;
  background: rgba(76, 175, 80, 0.1);
  border: 1px solid rgba(76, 175, 80, 0.28);
  color: inherit;
  word-break: break-word;
}

.calendar-widget-free-slot-title {
  font-weight: 600;
  color: inherit;
}

.calendar-widget-free-slot-time {
  color: rgba(46, 125, 50, 0.7);
  font-size: 0.7rem;
  margin-top: 2px;
}

@media (max-width: 991.98px) and (orientation: landscape) {
  .calendar-widget-btn {
    bottom: 16px;
    right: 16px;
  }

  .calendar-widget-container {
    bottom: 70px;
    right: 12px;
    left: 12px;
    width: auto;
    max-width: none;
    max-height: calc(100vh - 110px);
  }
}


.calendar-widget-event-title {
  font-weight: 600;
  color: inherit;
}

.calendar-widget-event-time {
  color: rgba(0, 0, 0, 0.6);
  font-size: 0.7rem;
  margin-top: 2px;
}

.calendar-widget-container.dark-mode .calendar-widget-event-time {
  color: rgba(255, 255, 255, 0.5);
}

.calendar-widget-empty {
  padding: 20px 10px;
  text-align: center;
  color: var(--text-muted, #6c757d);
  font-size: 0.85rem;
}

.calendar-widget-container.dark-mode .calendar-widget-empty {
  color: var(--text-muted, #9ca3af);
}

/* Loading state */
.calendar-widget-loading {
  padding: 20px;
  text-align: center;
  color: var(--text-muted, #6c757d);
}

.calendar-widget-loading::after {
  content: '';
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid #f3f3f3;
  border-top: 2px solid var(--accent-blue);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-left: 8px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Drag constraints hint */
.calendar-widget-constraint {
  position: fixed;
  bottom: 0;
  right: 0;
  width: 400px;
  height: 600px;
  pointer-events: none;
  z-index: 998;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .calendar-widget-btn {
    bottom: 72px;
    right: 16px;
  }
}

@media (max-width: 576px) {
  .calendar-widget-btn {
    bottom: 72px;
    right: 12px;
    width: 50px;
    height: 50px;
    font-size: 1.25rem;
  }

  .calendar-widget-container {
    width: 320px;
    max-height: 400px;
    bottom: 80px;
    right: 20px;
  }
}

@media (max-width: 380px) {
  .calendar-widget-container {
    width: 90vw;
    max-width: 300px;
  }
}

/* Go Back floating button — to the left of the calendar FAB */
#go-back-btn {
  position: fixed;
  bottom: 30px;
  right: 102px; /* no sidebar: 30 (cal right) + 60 (cal width) + 12 (gap) */
  z-index: 2001;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card, #fff);
  color: var(--text-primary, #1a1a2e);
  border: 1.5px solid var(--border-light, #e2e8f0);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, background 0.15s;
}

#go-back-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
  background: var(--bg-hover, #f1f5f9);
}

#go-back-btn:active {
  transform: scale(0.95);
}

/* When right sidebar present, calendar FAB shifts left — match it */
body:has(#sidebar-root.app-sidebar-right) #go-back-btn {
  right: calc(var(--sidebar-width) + 30px + 60px + 12px);
}
