/**
 * Calendar View - Mobile-First CSS
 * Google Calendar style day view
 */

/* ========== CONTAINER ========== */
.cv-container {
  min-height: 100vh;
  background: var(--bg-primary);
  padding-bottom: 80px; /* Space for bottom nav */
}

/* Remove main-content padding when calendar view is active */
.main-content:has(.cv-container) {
  padding: 0 !important;
}

/* ========== HEADER ========== */
.cv-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 8px;
  flex-wrap: nowrap;
  padding: 8px 12px;
}

.cv-date-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.cv-nav-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.cv-nav-btn:hover {
  background: var(--primary);
  color: white;
}

.cv-nav-btn:active {
  transform: scale(0.95);
}

.cv-date-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  min-width: 0;
}

/* Clickable date display - opens date picker */
.cv-date-clickable {
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 8px;
  transition: background 0.2s ease;
  position: relative;
}

.cv-date-clickable:hover {
  background: var(--bg-tertiary);
}

.cv-date-clickable:active {
  background: var(--bg-secondary);
}

.cv-date-icon {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.cv-weekday {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.cv-weekday.cv-is-today {
  color: var(--primary);
  background: rgba(59, 130, 246, 0.1);
  padding: 2px 12px;
  border-radius: 12px;
}

.cv-full-date {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-primary);
  text-align: center;
}

.cv-today-btn {
  padding: 10px 16px;
  border: none;
  background: var(--primary);
  color: white;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.cv-today-btn:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.cv-today-btn:active {
  transform: translateY(0);
}

/* ========== LEGEND ========== */
.cv-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.cv-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.cv-legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 4px;
  flex-shrink: 0;
}

/* ========== TIME GRID ========== */
.cv-grid-wrapper {
  position: relative;
  overflow-y: auto;
  /* Altura flexível para permitir scroll de todo o dia (6h-22h) */
  height: calc(100vh - 70px);
  max-height: calc(100vh - 70px);
  -webkit-overflow-scrolling: touch;
}

.cv-time-grid {
  display: flex;
  flex-direction: column;
  position: relative;
}

.cv-time-slot {
  display: flex;
  /* Slots mais pequenos para caber mais horas no ecrã */
  min-height: 32px;
  border-bottom: 1px solid var(--border-color);
}

.cv-time-label {
  width: 50px;
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 4px 2px;
  font-size: 0.7rem;
  color: var(--text-muted);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
}

.cv-hour-label {
  font-weight: 600;
  color: var(--text-secondary);
}

.cv-half-label {
  border-bottom: 1px dashed var(--border-color);
}

.cv-slot-content {
  flex: 1;
  padding: 4px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
}

/* ========== EVENTS ========== */
.cv-event {
  padding: 6px 10px;
  border-radius: 6px;
  color: white;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
  /* Ajustado para slots mais compactos */
  min-height: calc(var(--event-slots, 1) * 32px);
  backdrop-filter: blur(10px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.cv-event::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: rgba(255, 255, 255, 0.4);
}

.cv-event:hover {
  transform: translateX(2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.cv-event:active {
  transform: scale(0.98);
}

/* PT Colors */
.cv-event.pt-nr { background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%); }
.cv-event.pt-gil { background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%); }
.cv-event.pt-jm { background: linear-gradient(135deg, #f97316 0%, #ea580c 100%); }
.cv-event.pt-jp { background: linear-gradient(135deg, #eab308 0%, #ca8a04 100%); color: #000; }
.cv-event.pt-dn { background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%); }

.cv-event-time {
  font-size: 0.75rem;
  opacity: 0.9;
  display: flex;
  align-items: center;
  gap: 6px;
}

.cv-duo-badge {
  font-size: 0.875rem;
}

.cv-event-client {
  font-size: 0.9375rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.cv-event-session {
  font-size: 0.6875rem;
  opacity: 0.8;
  margin-top: 2px;
}

/* ========== CURRENT TIME INDICATOR ========== */
.cv-current-time {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  z-index: 50;
  pointer-events: none;
}

.cv-current-time-line {
  flex: 1;
  height: 2px;
  background: #ef4444;
  box-shadow: 0 0 4px rgba(239, 68, 68, 0.5);
}

.cv-current-time::before {
  content: '';
  width: 12px;
  height: 12px;
  background: #ef4444;
  border-radius: 50%;
  flex-shrink: 0;
  margin-left: 54px;
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.6);
}

.cv-current-time-label {
  position: absolute;
  left: 4px;
  font-size: 0.625rem;
  font-weight: 600;
  color: #ef4444;
  background: var(--bg-primary);
  padding: 2px 4px;
  border-radius: 4px;
}

/* ========== LOADING ========== */
.cv-loading {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-secondary);
  padding: 24px 32px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  z-index: 200;
}

.cv-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border-color);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: cv-spin 0.8s linear infinite;
}

@keyframes cv-spin {
  to { transform: rotate(360deg); }
}

.cv-loading p {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin: 0;
}

/* ========== EMPTY STATE ========== */
.cv-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
  color: var(--text-muted);
}

.cv-empty i {
  font-size: 3rem;
  opacity: 0.3;
  margin-bottom: 16px;
}

.cv-empty p {
  font-size: 1rem;
  margin: 0;
}

/* ========== MODAL ========== */
.cv-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
  animation: cv-fade-in 0.2s ease;
}

@keyframes cv-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.cv-modal {
  background: var(--bg-primary);
  border-radius: 16px;
  width: 100%;
  max-width: 360px;
  overflow: hidden;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
  animation: cv-slide-up 0.3s ease;
}

@keyframes cv-slide-up {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.cv-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  color: white;
}

.cv-modal-header h3 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cv-modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border-radius: 50%;
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}

.cv-modal-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

.cv-modal-body {
  padding: 16px 20px 24px;
}

.cv-modal-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-color);
}

.cv-modal-row:last-child {
  border-bottom: none;
}

.cv-modal-row i {
  width: 20px;
  color: var(--text-muted);
  text-align: center;
  flex-shrink: 0;
}

.cv-modal-row span {
  font-size: 0.9375rem;
  color: var(--text-primary);
}

/* ========== RESPONSIVE ========== */

/* Tablet */
@media (min-width: 768px) {
  .cv-header {
    padding: 16px 24px;
  }

  .cv-date-display {
    flex-direction: row;
    gap: 12px;
  }

  .cv-weekday {
    font-size: 1rem;
  }

  .cv-full-date {
    font-size: 1.25rem;
  }

  .cv-time-slot {
    min-height: 40px;
  }

  .cv-time-label {
    width: 60px;
    font-size: 0.8rem;
  }

  .cv-event {
    padding: 12px 16px;
  }

  .cv-event-client {
    font-size: 1rem;
  }

  .cv-current-time::before {
    margin-left: 74px;
  }
}

/* Desktop */
@media (min-width: 1024px) {
  .cv-container {
    max-width: 900px;
    margin: 0 auto;
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
  }

  .cv-grid-wrapper {
    height: calc(100vh - 80px);
    max-height: calc(100vh - 80px);
  }

  .cv-time-slot {
    min-height: 50px;
  }

  .cv-modal {
    max-width: 420px;
  }
}

/* Touch device optimizations */
@media (hover: none) {
  .cv-nav-btn:hover,
  .cv-today-btn:hover,
  .cv-event:hover {
    transform: none;
    background: inherit;
  }

  .cv-event:active {
    transform: scale(0.98);
  }
}
