/* =========================================================
   Calendar Views — Month / Week / Day
   Aligned with Valex theme CSS variables
   ========================================================= */

/* ── Tokens ──────────────────────────────────────────── */
.cal-views {
  --cal-hour-h: 56px;
  --cal-hour-label-w: 56px;
  --cal-accent: rgb(var(--primary-rgb));
  --cal-accent-light: rgba(var(--primary-rgb), 0.08);
  --cal-accent-lighter: rgba(var(--primary-rgb), 0.04);
  --cal-border: var(--default-border, #eae8f1);
  --cal-bg: var(--custom-white, #fff);
  --cal-surface: var(--default-background, #f8fafd);
  --cal-fg: var(--default-text-color, #031b4e);
  --cal-muted: var(--text-muted, #7987a1);
  --cal-radius: 6px;
  --cal-event-blue: #1677ff;
  --cal-event-green: #52c41a;
  --cal-event-orange: #fa8c16;
  --cal-event-purple: #7c3aed;
}

/* ── Nav bar shared ──────────────────────────────────── */
.cal-nav-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.cal-date-display {
  font-size: 18px;
  font-weight: 600;
  white-space: nowrap;
}

/* ── View tabs ───────────────────────────────────────── */
.cal-view-tabs {
  display: flex;
  gap: 2px;
  background: var(--cal-surface);
  border-radius: var(--cal-radius);
  padding: 2px;
  border: 1px solid var(--cal-border);
}
.cal-view-tab {
  padding: 5px 14px;
  border: none;
  background: transparent;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--cal-muted);
  transition: all 0.15s;
}
.cal-view-tab:hover { color: var(--cal-fg); }
.cal-view-tab.active {
  background: var(--cal-bg);
  color: var(--cal-accent);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* =========================================================
   MONTH VIEW
   ========================================================= */
.month-grid-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0;
  margin-bottom: 4px;
}
.month-grid-header span {
  padding: 8px 0;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--cal-muted);
  letter-spacing: 0.04em;
}

.month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--cal-border);
  border: 1px solid var(--cal-border);
  border-radius: var(--cal-radius);
  overflow: hidden;
}
.month-cell {
  background: var(--cal-bg);
  min-height: 100px;
  padding: 6px 6px 4px;
  cursor: pointer;
  transition: background 0.1s;
  display: flex;
  flex-direction: column;
}
.month-cell:hover { background: var(--cal-accent-lighter); }
.month-cell.other-month { background: var(--cal-surface); }
.month-cell.other-month .day-num { color: var(--cal-muted); opacity: 0.5; }
.month-cell.today { box-shadow: inset 0 0 0 2px var(--cal-accent); }
.month-cell.selected { background: var(--cal-accent-light); }
.month-cell.selected.today {
  box-shadow: inset 0 0 0 2px var(--cal-accent);
  background: var(--cal-accent-light);
}

.day-num {
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  margin-bottom: 4px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.15s;
}
.today .day-num {
  background: var(--cal-accent);
  color: #fff;
  font-weight: 600;
}

.month-events {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  overflow: hidden;
}
.month-event {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  color: #fff;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
  cursor: pointer;
  transition: opacity 0.15s;
}
.month-event:hover { opacity: 0.85; }
.more-events {
  font-size: 11px;
  color: var(--cal-muted);
  padding: 1px 6px;
  cursor: pointer;
  font-weight: 500;
}
.more-events:hover { color: var(--cal-accent); }

/* Mobile indicators */
.mobile-event-indicator {
  display: none;
  gap: 3px;
  justify-content: center;
  margin-top: 2px;
}
.mobile-event-indicator span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  display: inline-block;
}
.has-events::after {
  content: '';
  display: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cal-accent);
  margin: 2px auto 0;
}

/* =========================================================
   WEEK VIEW
   ========================================================= */
.week-view {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 260px);
  min-height: 420px;
}

.week-header {
  display: grid;
  grid-template-columns: var(--cal-hour-label-w) repeat(7, 1fr);
  gap: 1px;
  background: var(--cal-border);
  border: 1px solid var(--cal-border);
  border-radius: var(--cal-radius) var(--cal-radius) 0 0;
  overflow: hidden;
}
.week-header-item {
  background: var(--cal-surface);
  padding: 8px 4px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
}
.week-header-item .day-label {
  color: var(--cal-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-size: 11px;
}
.week-header-item .day-num-w {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.2;
  margin-top: 2px;
}
.week-header-item.today-col .day-num-w { color: var(--cal-accent); }
.week-header-item.today-col { background: rgba(var(--primary-rgb), 0.08); }

.week-body {
  display: grid;
  grid-template-columns: var(--cal-hour-label-w) repeat(7, 1fr);
  gap: 1px;
  background: var(--cal-border);
  border: 1px solid var(--cal-border);
  border-top: none;
  border-radius: 0 0 var(--cal-radius) var(--cal-radius);
  overflow-y: auto;
  flex: 1;
  position: relative;
}
.week-time-column {
  display: flex;
  flex-direction: column;
}
.week-time-label {
  background: var(--cal-surface);
  font-size: 11px;
  color: var(--cal-muted);
  text-align: right;
  padding: 0 6px;
  height: var(--cal-hour-h);
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding-top: 2px;
  font-variant-numeric: tabular-nums;
  border-bottom: 1px solid var(--cal-border);
}
.week-day-col {
  background: var(--cal-bg);
  position: relative;
  min-height: calc(24 * var(--cal-hour-h));
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent calc(var(--cal-hour-h) - 1px),
    var(--cal-border) calc(var(--cal-hour-h) - 1px),
    var(--cal-border) var(--cal-hour-h)
  );
  background-size: 100% var(--cal-hour-h);
}
.week-day-col.today-col { background-color: rgba(var(--primary-rgb), 0.04); }
.week-day-col.today-col:hover { background-color: rgba(var(--primary-rgb), 0.08); }

.week-event {
  position: absolute;
  left: 2px;
  right: 2px;
  border-radius: 4px;
  padding: 3px 5px;
  color: #fff;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.3;
  overflow: hidden;
  cursor: pointer;
  transition: opacity 0.15s;
  z-index: 1;
  min-height: 20px;
}
.week-event:hover { opacity: 0.85; }
.week-event .event-time {
  font-size: 10px;
  opacity: 0.9;
  font-weight: 400;
  display: block;
}

/* =========================================================
   DAY VIEW
   ========================================================= */
.day-view {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 260px);
  min-height: 420px;
}

.day-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--cal-surface);
  border: 1px solid var(--cal-border);
  border-radius: var(--cal-radius) var(--cal-radius) 0 0;
}
.day-header .day-big {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  color: var(--cal-accent);
}
.day-header .day-info { flex: 1; }
.day-header .day-name { font-size: 16px; font-weight: 600; }
.day-header .day-date { font-size: 13px; color: var(--cal-muted); }
.day-header .day-count {
  font-size: 13px;
  color: var(--cal-muted);
  padding: 4px 10px;
  background: var(--cal-bg);
  border-radius: 20px;
  border: 1px solid var(--cal-border);
}

.day-grid {
  flex: 1;
  overflow-y: auto;
  border: 1px solid var(--cal-border);
  border-top: none;
  border-radius: 0 0 var(--cal-radius) var(--cal-radius);
  position: relative;
  mask-image: linear-gradient(to bottom, transparent 0, #000 12px, #000 calc(100% - 24px), transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 12px, #000 calc(100% - 24px), transparent 100%);
}
.day-hour-row {
  display: grid;
  grid-template-columns: var(--cal-hour-label-w) 1fr;
  gap: 0;
  border-bottom: 1px solid var(--cal-border);
  min-height: var(--cal-hour-h);
}
.day-hour-row:last-child { border-bottom: none; }
.day-time-label {
  padding: 4px 8px;
  font-size: 11px;
  color: var(--cal-muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
  border-right: 1px solid var(--cal-border);
  background: var(--cal-surface);
}
.day-slot {
  padding: 6px 12px;
  min-height: var(--cal-hour-h);
  cursor: pointer;
  transition: background 0.1s;
  position: relative;
}
.day-slot:hover { background: rgba(var(--primary-rgb), 0.04); }

.day-event-card {
  margin: 4px 0;
  padding: 10px 12px;
  border-radius: var(--cal-radius);
  border-left: 4px solid var(--cal-event-blue);
  background: var(--cal-surface);
  cursor: pointer;
  transition: box-shadow 0.15s;
}
.day-event-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
.day-event-card .event-title { font-size: 14px; font-weight: 600; line-height: 1.3; }
.day-event-card .event-time-range {
  font-size: 12px;
  color: var(--cal-muted);
  margin-top: 3px;
}
.day-event-card .event-desc {
  font-size: 13px;
  color: var(--cal-fg);
  margin-top: 4px;
  opacity: 0.65;
  line-height: 1.4;
}

/* ── Empty state ─────────────────────────────────────── */
.empty-day-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 180px;
  color: var(--cal-muted);
  font-size: 14px;
  flex-direction: column;
  gap: 8px;
}
.empty-day-state svg {
  width: 44px;
  height: 44px;
  stroke: var(--cal-muted);
  opacity: 0.5;
}

/* =========================================================
   POPOVER
   ========================================================= */
.event-popover-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1040;
}
.event-popover-overlay.visible { display: block; }

.event-popover {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 1045;
  background: var(--cal-bg);
  border: 1px solid var(--cal-border);
  border-radius: var(--cal-radius);
  box-shadow: 0 8px 30px rgba(0,0,0,0.12);
  padding: 18px;
  max-width: 320px;
  width: calc(100vw - 32px);
  opacity: 0;
  transform: translate(-50%, calc(-50% + 4px));
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.event-popover.visible {
  display: block;
  opacity: 1;
  transform: translate(-50%, -50%);
}
.event-popover .pop-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 6px;
}
.event-popover .pop-time {
  font-size: 13px;
  color: var(--cal-muted);
  margin-bottom: 4px;
}
.event-popover .pop-desc {
  font-size: 13px;
  line-height: 1.5;
  margin-top: 6px;
  opacity: 0.8;
}
.event-popover .pop-close {
  margin-top: 12px;
  padding: 5px 14px;
  background: var(--cal-surface);
  border: 1px solid var(--cal-border);
  border-radius: var(--cal-radius);
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s;
}
.event-popover .pop-close:hover { background: var(--cal-border); }

/* =========================================================
   RESPONSIVE
   ========================================================= */
@media (max-width: 768px) {
  .month-cell { min-height: 80px; padding: 4px; }
  .day-num { width: 24px; height: 24px; font-size: 12px; }
  .month-event { font-size: 10px; padding: 1px 4px; }
  .week-view { height: calc(100dvh - 280px); min-height: 360px; }
  .day-view { height: calc(100dvh - 280px); min-height: 360px; }
  .cal-date-display { font-size: 15px; }
  .cal-view-tab { padding: 4px 10px; font-size: 12px; }
}

@media (max-width: 540px) {
  .month-cell { min-height: 68px; }
  .month-events { display: none; }
  .has-events::after { display: block; }
  .mobile-event-indicator { display: flex; }
  .week-header { grid-template-columns: 44px repeat(7, 1fr); }
  .week-grid { grid-template-columns: 44px repeat(7, 1fr); }
  .week-header-item .day-num-w { font-size: 14px; }
  .week-time-label { font-size: 10px; padding: 0 4px; }
  .week-event { font-size: 10px; padding: 2px 3px; }
  .day-hour-row { grid-template-columns: 44px 1fr; }
  .day-time-label { font-size: 10px; padding: 4px 6px; }
  .day-header .day-big { font-size: 22px; }
  .day-event-card .event-title { font-size: 13px; }
}
