/**
 * 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 ========== */
:root {
  --cv-grid-height: 1700px;
}

.cv-container.cv-zoom-out {
  --cv-grid-height: calc(100dvh - 140px);
}

.cv-grid-wrapper {
  position: relative;
  overflow-y: auto;
  height: calc(100vh - 70px);
  max-height: calc(100vh - 70px);
  -webkit-overflow-scrolling: touch;
}

.cv-time-grid {
  display: flex;
  flex-direction: column;
  position: relative;
  height: var(--cv-grid-height);
  min-height: var(--cv-grid-height);
}

.cv-time-row {
  display: flex;
  flex: 1;
  border-bottom: 1px solid var(--border-color);
  position: relative;
}

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

.cv-time-line {
  flex: 1;
  position: relative;
}

/* ========== EVENTS LAYER ========== */
.cv-events-layer {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 50px; /* Offset for time label */
  pointer-events: none;
}

/* ========== EVENTS ========== */
.cv-event {
  position: absolute;
  padding: 4px 8px;
  border-radius: 4px;
  color: white;
  cursor: pointer;
  transition: all 0.2s ease;
  overflow: hidden;
  pointer-events: auto;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  z-index: 10;
  box-sizing: border-box;
}

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

.cv-event-content {
  height: 100%;
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

/* Zoom Out Adjustments */
.cv-zoom-out .cv-event {
    padding: 2px 4px;
    border-radius: 2px;
}

.cv-zoom-out .cv-event-time {
    font-size: 0.6rem;
}

.cv-zoom-out .cv-event-client {
    font-size: 0.7rem;
}

.cv-zoom-out .cv-event-session {
    font-size: 0.55rem;
}

.cv-zoom-out .cv-time-label {
    font-size: 0.65rem;
}

.cv-event:hover {
  z-index: 20;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* PT Colors */
.cv-event.pt-nr { background: #039be5; }
.cv-event.pt-jm { background: #f4511e; }
.cv-event.pt-jp { background: #f6bf26; color: #000; }
.cv-event.pt-dn { background: #33b679; }
.cv-event.pt-gil { background: #616161; }
.cv-event.pt-js { background: #7986cb; }

.cv-event-time {
  font-size: 0.7rem;
  font-weight: 700;
  opacity: 0.9;
}

.cv-event-client {
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cv-event-session {
  font-size: 0.65rem;
  opacity: 0.8;
}

/* ========== 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);
}

.cv-modal-edit-btn {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.cv-modal-edit-btn:active {
    transform: scale(0.98);
    opacity: 0.9;
}

/* ========== 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:active,
  .cv-today-btn:active {
    background: var(--bg-tertiary);
    opacity: 0.7;
  }
  
  .cv-event:hover {
    transform: none;
  }

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