/*
 * calendar.css — Tier 2 (calendar-map page type)
 *
 * Loaded on calendar pages (e.g. /calendars/2026-atp/).
 * Depends on tokens + base defined in site.css.
 *
 * Contains: hero court treatment, tier/surface badges, distribution bars
 * + legend, filter controls, stats bar, view tabs (map/calendar), Leaflet
 * popup skinning, month sections, event cards, Gantt grid + popups.
 *
 * Leaflet.js CSS is loaded separately via CDN <link> on calendar pages —
 * do NOT fold Leaflet styles into this file.
 *
 * See docs/design-system/tiers.md.
 */

/* ─────────────────────────────────────────────────────────────
 * 1. i18n display overrides for calendar-specific flex containers
 * ───────────────────────────────────────────────────────────── */

body.lang-en .stats-bar[data-lang="en"],
body.lang-zh .stats-bar[data-lang="zh"] { display: flex !important; }
body.lang-en .control-row[data-lang="en"],
body.lang-zh .control-row[data-lang="zh"] { display: flex !important; }
body.lang-en .view-tabs[data-lang="en"],
body.lang-zh .view-tabs[data-lang="zh"] { display: flex !important; }

/* ─────────────────────────────────────────────────────────────
 * 2. Distribution bars (tier + surface breakdown)
 * ───────────────────────────────────────────────────────────── */

.dist-section {
  margin: 24px auto 0;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: relative;
}
.dist-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.dist-label {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-tertiary);
}
.dist-bar {
  display: flex;
  height: 26px;
  border-radius: 13px;
  overflow: hidden;
  background: rgba(255,255,255,0.04);
  cursor: pointer;
}
.dist-seg {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: rgba(0,0,0,0.8);
  white-space: nowrap;
  overflow: hidden;
  transition: opacity 0.2s, filter 0.2s;
  min-width: 0;
  position: relative;
}
.dist-seg span { padding: 0 5px; }
/* Dim non-hovered segments when any segment is hovered — NO transform to avoid layout shift */
.dist-bar.has-hover .dist-seg { opacity: 0.4; filter: saturate(0.4) brightness(0.7); }
.dist-bar.has-hover .dist-seg.hovered { opacity: 1; filter: brightness(1.15); }
.dist-legend-item { transition: opacity 0.2s; }
.dist-row.has-hover .dist-legend-item { opacity: 0.4; }
.dist-row.has-hover .dist-legend-item.hovered { opacity: 1; }

.dist-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-top: 2px;
}
.dist-legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--text-tertiary);
  cursor: pointer;
}
.dist-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  /* per-instance color set via inline `style="--swatch-color:#xxx"` (allowlisted parametric) */
  background: var(--swatch-color, var(--text-tertiary));
}

/* Distribution tooltip */
.dist-tooltip {
  display: none;
  position: fixed;
  z-index: 1001;
  background: rgba(10,18,50,0.95);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 10px;
  backdrop-filter: blur(16px);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-primary);
  box-shadow: 0 8px 28px rgba(0,0,0,0.5);
  max-width: 220px;
  pointer-events: none;
  line-height: 1.5;
}
.dist-tooltip.visible { display: block; }
.dist-tooltip-color {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
  background: var(--swatch-color, var(--text-tertiary));
}
.dist-tooltip-detail {
  margin-top: 4px;
  font-size: 13px;
  color: var(--text-tertiary);
  line-height: 1.4;
}
.dist-tooltip-name { font-weight: 600; color: var(--white); }
.dist-tooltip-count { color: var(--text-tertiary); font-size: 13px; margin-top: 2px; }
.dist-tooltip-pct { font-size: 18px; font-weight: 700; margin-top: 2px; }

@media (max-width: 480px) {
  .dist-section { max-width: 100%; }
  .dist-bar { height: 24px; border-radius: 12px; }
}

/* ─────────────────────────────────────────────────────────────
 * 3. Hero (tennis-court boundary treatment)
 * ───────────────────────────────────────────────────────────── */

.hero {
  position: relative;
  overflow: hidden;
}

/* Court boundary — a real wrapper around content, not a positioned pseudo.
   The border always hugs the content with equal padding on all sides,
   regardless of hero height, viewport, or browser chrome. */
.hero-court {
  border: 1.5px solid rgba(200, 230, 49, 0.18);
  border-radius: 6px;
  padding: 24px 28px;
  margin: 0 auto;
  max-width: 720px;
}
@media (max-width: 600px) {
  .hero-court { padding: 18px 16px; margin: 0 8px; }
}

/* ─────────────────────────────────────────────────────────────
 * 4. Tier colors + combo badge — moved to site.css §9c.
 *    Calendar still consumes --tier-color via .tier-* classes on event
 *    cards, Gantt bars, and the Gantt popup left-border (rules below).
 * ───────────────────────────────────────────────────────────── */

/* ─────────────────────────────────────────────────────────────
 * 5. Map container + Leaflet popup skinning
 *    (Leaflet core CSS is loaded separately via CDN)
 * ───────────────────────────────────────────────────────────── */

#map-container {
  position: relative;
  margin: 0 -24px;
  height: 600px;
  border-top: 1px solid rgba(255,255,255,0.06);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
#map { width: 100%; height: 100%; }
@media (max-width: 1024px) {
  #map-container { height: 450px; }
}
@media (max-width: 768px) {
  #map-container { height: 360px; }
}
.leaflet-container { background: #0a0e1a; }
.leaflet-popup-content-wrapper {
  background: rgba(10,18,50,0.95);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  backdrop-filter: blur(16px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  color: var(--text-primary);
  font-family: 'Sora', sans-serif;
}
.leaflet-popup-content { margin: 12px 16px; font-size: 14px; line-height: 1.5; }
.leaflet-popup-content .popup-name { font-weight: 600; color: var(--white); font-size: 15px; margin-bottom: 4px; }
.leaflet-popup-content .popup-dates { color: var(--text-tertiary); font-size: 13px; }
.leaflet-popup-content .popup-surface { margin-top: 4px; }
.leaflet-popup-content a { color: var(--accent-primary-text, #5dd4f5); text-decoration: none; font-size: 13px; }
.leaflet-popup-content a:hover { text-decoration: underline; }
.leaflet-popup-tip { background: rgba(10,18,50,0.95); }

/* ─────────────────────────────────────────────────────────────
 * 6. Control area (filter buttons, tier/surface rows, separator)
 * ───────────────────────────────────────────────────────────── */

.control-area {
  padding: 20px 0 16px;
  display: flex;
  flex-direction: column;
  gap: 0;
}
.control-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 0;
}
.control-row:first-child {
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  margin-bottom: 4px;
}
.control-label {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-right: 2px;
}
.filter-btn {
  padding: 4px 12px;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.03);
  color: var(--text-tertiary);
  font-family: 'Sora', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.filter-btn:hover {
  border-color: rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.06);
  color: var(--text-secondary);
}
.filter-btn .dot {
  width: 8px; height: 8px; border-radius: 50%; display: inline-block;
  background: var(--tier-color, var(--text-tertiary));
}
/* The .f-{tier} class on the button sets --tier-color, which the .dot
 * child consumes for its background AND the active-state border below.
 * Same palette as .tier-* tokens in site.css §10.3. */
.filter-btn.f-gs     { --tier-color: #f5c842; }
.filter-btn.f-m1000  { --tier-color: #5dd4f5; }
.filter-btn.f-500    { --tier-color: #4ade80; }
.filter-btn.f-250    { --tier-color: var(--text-tertiary); }
.filter-btn.f-finals { --tier-color: #c084fc; }
.filter-btn.active { background: rgba(255,255,255,0.08); color: var(--text-primary); }
.filter-btn.active.f-gs,
.filter-btn.active.f-m1000,
.filter-btn.active.f-500,
.filter-btn.active.f-250,
.filter-btn.active.f-finals { border-color: color-mix(in srgb, var(--tier-color) 45%, transparent); }
/* Surface filters — ghost/text style, no color coding */
.filter-btn.f-surface {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--text-tertiary);
  font-weight: 400;
  padding: 4px 14px;
}
.filter-btn.f-surface:hover {
  background: transparent;
  border-color: rgba(255,255,255,0.15);
  color: var(--text-secondary);
}
.filter-btn.f-surface.active {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.2);
  color: var(--text-primary);
  font-weight: 500;
}
.filter-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}
.filter-row {
  gap: 10px;
}
.filter-sep {
  width: 1px; height: 18px;
  background: rgba(255,255,255,0.08);
  flex-shrink: 0;
}
@media (max-width: 960px) {
  .filter-row { flex-direction: column; gap: 10px; }
  .filter-sep { display: none; }
}
@media (max-width: 768px) {
  .control-label { display: none; }
}

/* ─────────────────────────────────────────────────────────────
 * 7. Month sections + timeline event cards
 * ───────────────────────────────────────────────────────────── */

.month-header {
  font-size: 20px;
  font-weight: 700;
  color: var(--white);
  padding: 32px 0 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  margin-bottom: 16px;
}
.month-header:first-of-type { padding-top: 16px; }

.event-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
  margin-bottom: 8px;
}
@media (max-width: 480px) {
  .event-grid { grid-template-columns: 1fr; }
}
.event-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 20px;
  background: rgba(11,21,53,0.7);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  backdrop-filter: blur(16px);
  transition: transform 0.2s, box-shadow 0.2s;
  border-left: 3px solid var(--tier-color);
}
.event-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}
.event-card-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.event-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--white);
  flex: 1;
  min-width: 150px;
}
.event-name a { color: var(--white); text-decoration: none; }
.event-name a:hover { color: var(--accent-primary-text, #5dd4f5); }
.event-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  color: var(--text-tertiary);
  font-size: 14px;
}
.event-city { color: var(--text-secondary); font-weight: 500; }
.event-dates { color: var(--text-tertiary); font-size: 13px; }
.event-link-icon {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-tertiary);
  font-size: 13px;
  text-decoration: none;
  transition: color 0.2s;
}
.event-link-icon:hover { color: var(--accent-primary-text); }

/* ─────────────────────────────────────────────────────────────
 * 8. Stats bar — moved to site.css §9b (shared component).
 *    The .stats-bar i18n display override at the top of this file
 *    stays here because it is calendar-specific (only the calendar
 *    template renders the bilingual <div class="stats-bar"> twice).
 * ───────────────────────────────────────────────────────────── */

/* ─────────────────────────────────────────────────────────────
 * 9. View tabs (Map / Calendar) + panels
 * ───────────────────────────────────────────────────────────── */

.view-tabs {
  display: flex;
  gap: 0;
}
.view-tab {
  padding: 5px 18px;
  font-family: 'Sora', sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-tertiary);
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.1);
  cursor: pointer;
  transition: all 0.2s;
}
.view-tab:first-child { border-radius: 14px 0 0 14px; }
.view-tab:last-child { border-radius: 0 14px 14px 0; margin-left: -1px; }
.view-tab.active {
  background: rgba(255,255,255,0.1);
  color: var(--white);
  border-color: var(--accent-primary, #C8E631);
}
.view-tab:hover:not(.active) {
  background: rgba(255,255,255,0.06);
  color: var(--text-secondary);
}
.view-panel { display: none; }
.view-panel.active { display: block; }

/* ─────────────────────────────────────────────────────────────
 * 10. Gantt calendar grid (rows, month headers, bars, sort toggle)
 * ───────────────────────────────────────────────────────────── */

.cal-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -24px;
  padding: 16px 24px 24px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.15) transparent;
}
.cal-container::-webkit-scrollbar { height: 6px; }
.cal-container::-webkit-scrollbar-track { background: transparent; }
.cal-container::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }
.cal-container::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.25); }
.cal-grid {
  position: relative;
  min-width: 900px;
}
.cal-header {
  display: grid;
  grid-template-columns: 200px repeat(48, 1fr);
  gap: 0;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  padding-bottom: 8px;
  margin-bottom: 4px;
}
.cal-month-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-align: center;
  padding: 4px 0;
  border-left: 1px solid rgba(255,255,255,0.04);
  /* per-instance week span set via inline `style="--month-span:N"` (allowlisted parametric) */
  grid-column: span var(--month-span, 1);
}
.cal-month-label:first-of-type { border-left: none; }
.cal-corner { font-size: 13px; color: var(--text-tertiary); font-weight: 500; padding: 4px 0; }
.cal-row {
  display: grid;
  grid-template-columns: 200px repeat(48, 1fr);
  align-items: center;
  min-height: 36px;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.cal-row:hover { background: rgba(255,255,255,0.02); }
.cal-event-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 8px;
}
.cal-event-name a { color: inherit; text-decoration: none; }
.cal-event-name a:hover { color: var(--white); }
.cal-bar-cell {
  position: relative;
  grid-column: var(--col-start) / var(--col-end);
  height: 24px;
}
.cal-bar {
  position: absolute;
  top: 2px;
  left: 0;
  min-width: fit-content;
  height: 22px;
  border-radius: 11px;
  background: var(--tier-color);
  opacity: 0.8;
  transition: opacity 0.2s;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cal-bar:hover { opacity: 1; }
.cal-bar-label {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: rgba(0,0,0,0.75);
  white-space: nowrap;
  line-height: 1;
  padding: 0 10px;
}
.cal-tier-group {
  padding: 8px 0 4px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--tier-color);
}
.cal-row.hidden { display: none; }
.cal-tier-group.hidden { display: none; }

/* Calendar sort toggle */
.cal-corner {
  display: flex;
  gap: 4px;
  align-items: center;
}
.cal-sort-btn {
  font-size: 13px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 10px;
  cursor: pointer;
  color: var(--text-tertiary);
  background: transparent;
  border: 1px solid rgba(255,255,255,0.08);
  transition: all 0.2s;
  user-select: none;
}
.cal-sort-btn:hover { color: var(--text-secondary); border-color: rgba(255,255,255,0.15); }
.cal-sort-btn.active {
  color: var(--text-primary);
  background: rgba(255,255,255,0.08);
  border-color: var(--accent-primary, #C8E631);
}

/* ─────────────────────────────────────────────────────────────
 * 11. Gantt popup card + visibility helpers
 * ───────────────────────────────────────────────────────────── */

.cal-popup {
  display: none;
  position: fixed;
  z-index: 1000;
  background: rgba(11,21,53,0.95);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 14px;
  backdrop-filter: blur(16px);
  padding: 16px 20px;
  font-size: 14px;
  color: var(--text-primary);
  box-shadow: 0 12px 40px rgba(0,0,0,0.6);
  max-width: 300px;
  line-height: 1.5;
  border-left: 3px solid var(--popup-tier-color, #bcc0ca);
}
.cal-popup.visible { display: block; }
.cal-popup-badge { margin-bottom: 8px; }
.cal-popup-name { font-weight: 600; color: var(--white); font-size: 16px; margin-bottom: 4px; }
.cal-popup-name a { color: var(--white); text-decoration: none; }
.cal-popup-name a:hover { color: var(--accent-primary-text, #5dd4f5); }
.cal-popup-meta { color: var(--text-tertiary); font-size: 13px; margin-bottom: 8px; }
/* Stacking helpers for the Leaflet popup contents (inserted via innerHTML
 * literal in the template). Replace inline margin-top to keep the template
 * style-attribute-free. */
.cal-popup-badge-row { margin-top: 6px; }
.cal-popup-link-row  { margin-top: 8px; }
.cal-popup-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--accent-primary-text, #5dd4f5);
  text-decoration: none;
}
.cal-popup-link:hover { text-decoration: underline; }

/* Hide event cards when filtered out */
.event-card.hidden { display: none; }
.month-section.hidden { display: none; }
