/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f1117;
  --surface:   #181c27;
  --surface2:  #1f2435;
  --border:    #2a2f44;
  --accent:    #e8a020;
  --accent2:   #ff6b35;
  --text:      #dde1f0;
  --text-muted:#7a82a0;
  --today:     #1a2a1a;
  --today-bd:  #3a6b3a;
  --radius:    10px;
  --shadow:    0 8px 32px rgba(0,0,0,0.55);
}

html { font-size: 16px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
  padding-bottom: 3rem;
}

/* ===== HEADER ===== */
.site-header {
  background: linear-gradient(135deg, #0d1018 0%, #1a2035 100%);
  border-bottom: 2px solid var(--accent);
  padding: .75rem 2rem;
  position: sticky;
  top: 0;
  z-index: 200;
}
.header-inner {
  max-width: 1100px;
  margin: auto;
  display: flex;
  align-items: center;
  gap: 1.2rem;
  flex-wrap: wrap;
}
.logo {
  display: flex;
  align-items: center;
  gap: .5rem;
  text-decoration: none;
}
.logo-icon {
  width: 1.6rem;
  height: 1.6rem;
  color: var(--accent);
  flex-shrink: 0;
}
.logo-text {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: .05em;
  color: #fff;
}

/* ===== SITE NAV ===== */
.site-nav {
  display: flex;
  gap: .2rem;
  margin-left: auto;
}
.site-nav-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: .86rem;
  font-weight: 600;
  padding: .42rem .9rem;
  border-radius: 6px;
  border: 1px solid transparent;
  transition: color .15s, background .15s, border-color .15s;
  white-space: nowrap;
}
.site-nav-link:hover {
  color: var(--accent);
  background: var(--surface2);
  border-color: var(--border);
}
.site-nav-link.active {
  color: var(--accent);
  background: var(--surface2);
  border-color: var(--border);
}

/* ===== CALENDAR WRAPPER ===== */
.calendar-wrapper {
  max-width: 960px;
  margin: 2.5rem auto;
  padding: 0 1rem;
}

/* ===== NAV ===== */
.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.2rem;
}
.cal-title {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: capitalize;
}
.nav-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1.8rem;
  line-height: 1;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, border-color .15s, color .15s;
}
.nav-btn:hover,
.nav-btn:focus-visible {
  background: var(--accent);
  border-color: var(--accent);
  color: #000;
  outline: none;
}

/* ===== GRID ===== */
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.cal-header-row { margin-bottom: 6px; }
.dow {
  text-align: center;
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: .4rem 0;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.dow:nth-child(6),
.dow:nth-child(7) { color: var(--accent); }

/* ===== CELLS ===== */
.cal-cell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 100px;
  min-width: 0;
  padding: .5rem;
  position: relative;
  transition: border-color .15s;
  overflow: hidden;
}
.cal-cell.empty {
  background: transparent;
  border-color: transparent;
  pointer-events: none;
}
.cal-cell.today {
  background: var(--today);
  border-color: var(--today-bd);
}
.cal-cell:not(.empty):hover { border-color: var(--accent); }

.day-num {
  font-size: .8rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: .35rem;
  user-select: none;
}
.cal-cell.today .day-num { color: #6ecf6e; }
.cal-cell.weekend .day-num { color: var(--accent); }

/* ===== EVENT CHIPS (visual only, cell is the click target) ===== */
.event-chip {
  display: block;
  width: 100%;
  font-size: .7rem;
  font-weight: 700;
  border-radius: 4px;
  padding: .2rem .45rem;
  margin-bottom: .28rem;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  user-select: none;
}
/* chip colours by tag */
.chip-open  { background: linear-gradient(90deg, #d4820a, #e8a020); color: #0d1018; }
.chip-large { background: linear-gradient(90deg, #1e7a40, #27ae60); color: #fff; }
.chip-night { background: linear-gradient(90deg, #6c3483, #9b59b6); color: #fff; }
.chip-other { background: linear-gradient(90deg, #2471a3, #4a90d9); color: #fff; }

/* Clickable cells */
.cal-cell.has-events {
  cursor: pointer;
}
.cal-cell.has-events:hover {
  border-color: var(--accent);
}
.cal-cell.has-events:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ===== MODAL OVERLAY ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.75);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-overlay.open { display: flex; }

/* ===== MODAL CARD ===== */
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 2rem;
  position: relative;
  animation: slideUp .22s ease;
}
@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 1.3rem;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s, border-color .15s;
}
.modal-close:hover,
.modal-close:focus-visible {
  background: #c0392b;
  color: #fff;
  border-color: #c0392b;
  outline: none;
}

.modal-tag {
  display: inline-block;
  color: #0d1018;
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
  border-radius: 4px;
  padding: .15rem .6rem;
  margin-bottom: .75rem;
}
/* modal / day-card tag colours */
.tag-open  { background: #e8a020; color: #0d1018; }
.tag-large { background: #27ae60; color: #fff; }
.tag-night { background: #9b59b6; color: #fff; }
.tag-other { background: #4a90d9; color: #fff; }
.modal-title {
  font-size: 1.4rem;
  font-weight: 800;
  margin-bottom: 1.2rem;
  line-height: 1.25;
}

/* ===== META ROWS ===== */
.modal-meta {
  display: flex;
  flex-direction: column;
  gap: .65rem;
  margin-bottom: 1.4rem;
}
.meta-row {
  display: flex;
  align-items: flex-start;
  gap: .65rem;
  font-size: .92rem;
  color: var(--text);
}
.meta-icon {
  font-size: 1rem;
  flex-shrink: 0;
  margin-top: .05rem;
}

/* ===== MAP ===== */
.map-container {
  width: 100%;
  height: 240px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  margin-bottom: 1.4rem;
  background: var(--surface2);
}
.map-container iframe {
  display: block;
  border-radius: 10px;
}

/* ===== RULES BUTTON ===== */
.modal-actions { display: flex; justify-content: flex-end; }
.btn-rules {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  background: var(--accent);
  color: #0d1018;
  font-weight: 700;
  font-size: .9rem;
  border-radius: 8px;
  padding: .6rem 1.4rem;
  text-decoration: none;
  transition: background .15s, transform .1s;
}
.btn-rules:hover,
.btn-rules:focus-visible {
  background: var(--accent2);
  transform: translateY(-1px);
  outline: 2px solid var(--accent2);
  outline-offset: 2px;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--surface2); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ===== LOADING STATE ===== */
.cal-loading {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem 0;
  color: var(--text-muted);
  font-size: .95rem;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: .5; }
  50%       { opacity: 1;  }
}

/* ===== PAGE WRAPPER (organizers / polygons) ===== */
.page-wrapper {
  max-width: 1100px;
  margin: 2.5rem auto;
  padding: 0 1.5rem 4rem;
}
.page-title {
  font-size: 1.6rem;
  font-weight: 800;
  margin-bottom: .4rem;
}
.page-subtitle {
  color: var(--text-muted);
  font-size: .9rem;
  margin-bottom: 2rem;
}

/* ===== ORGANIZER CARDS ===== */
.org-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}
.org-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem 1.4rem;
  display: flex;
  flex-direction: column;
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.org-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,.4);
}
.org-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .8rem;
}
.org-type-badge {
  font-size: .64rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: .16rem .55rem;
  border-radius: 4px;
}
.org-type-badge.cqb     { background: rgba(74,144,217,.18); color: #6eb8f7; border: 1px solid rgba(74,144,217,.35); }
.org-type-badge.outdoor { background: rgba(39,174, 96,.18); color: #6ecf7e; border: 1px solid rgba(39,174, 96,.35); }
.org-type-badge.event   { background: rgba(155,89,182,.18); color: #c39bd3; border: 1px solid rgba(155,89,182,.35); }

.org-name {
  font-size: 1.05rem;
  font-weight: 800;
  margin-bottom: .65rem;
  line-height: 1.25;
}
.org-info-row {
  display: flex;
  align-items: flex-start;
  gap: .45rem;
  font-size: .82rem;
  color: var(--text-muted);
  margin-bottom: .3rem;
  line-height: 1.4;
}
.org-info-icon { flex-shrink: 0; }
.org-desc {
  font-size: .82rem;
  color: var(--text-muted);
  line-height: 1.55;
  margin: .8rem 0;
  border-top: 1px solid var(--border);
  padding-top: .8rem;
  flex: 1;
}
.org-buttons {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  margin-top: .9rem;
  padding-top: .9rem;
  border-top: 1px solid var(--border);
}
.org-btn {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font-size: .8rem;
  font-weight: 700;
  padding: .4rem .9rem;
  border-radius: 6px;
  text-decoration: none;
  transition: background .15s, color .15s, border-color .15s;
  white-space: nowrap;
}
.org-btn.vk   { background: var(--accent); color: #0d1018; }
.org-btn.vk:hover { background: var(--accent2); }
.org-btn.site { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.org-btn.site:hover { border-color: var(--accent); color: var(--accent); }

/* ===== POLYGON MAP PAGE ===== */
.poly-map-wrap {
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  margin-bottom: 1.2rem;
}
#poly-map { height: 520px; width: 100%; }

.poly-legend {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: 2rem;
  align-items: center;
}
.poly-legend-label {
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  margin-right: .25rem;
}
.poly-legend-item {
  display: flex;
  align-items: center;
  gap: .45rem;
  font-size: .83rem;
  color: var(--text-muted);
}
.legend-dot {
  width: 13px; height: 13px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px rgba(255,255,255,.15);
}
.legend-dot.cqb     { background: #4a90d9; }
.legend-dot.outdoor { background: #27ae60; }
.legend-dot.event   { background: #e74c3c; }

/* ===== FILTER BAR ===== */
.cal-filter-bar {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  align-items: center;
  padding: .9rem 0 1rem;
  margin-bottom: .4rem;
  border-bottom: 1px solid var(--border);
}
.filter-btn {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  font-size: .82rem;
  font-weight: 600;
  font-family: inherit;
  padding: .38rem .9rem;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
.filter-btn:hover {
  border-color: var(--fc, var(--accent));
  color: var(--text);
  background: var(--surface2);
}
.filter-btn.active {
  background: var(--surface2);
  border-color: var(--fc, var(--accent));
  color: #fff;
}
.filter-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--fc, var(--accent));
  flex-shrink: 0;
}

/* ===== DAY MODAL ===== */
.day-modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 2rem;
  position: relative;
  animation: slideUp .22s ease;
}

.day-modal-title {
  font-size: 1.3rem;
  font-weight: 800;
  margin-bottom: 1.4rem;
  padding-right: 2.5rem;
  color: #fff;
}

.day-event-list {
  display: flex;
  flex-direction: column;
  gap: .65rem;
}

.day-ev-card {
  display: block;
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.2rem;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  transition: border-color .15s, transform .1s, background .15s;
}
.day-ev-card:hover,
.day-ev-card:focus-visible {
  border-color: var(--accent);
  background: #252b3d;
  transform: translateX(3px);
  outline: none;
}

.day-ev-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .5rem;
}

.day-ev-tag {
  display: inline-block;
  font-size: .63rem;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
  border-radius: 4px;
  padding: .12rem .5rem;
  /* colour applied via .tag-* classes */
}

.day-ev-arrow {
  font-size: .75rem;
  color: var(--text-muted);
  transition: color .15s, transform .15s;
}
.day-ev-card:hover .day-ev-arrow {
  color: var(--accent);
  transform: translateX(3px);
}

.day-ev-title {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  margin-bottom: .6rem;
  line-height: 1.3;
}

.day-ev-meta {
  display: flex;
  flex-direction: column;
  gap: .28rem;
  font-size: .82rem;
  color: var(--text-muted);
}
.day-ev-icon {
  margin-right: .4rem;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 640px) {
  .cal-cell { min-height: 72px; padding: .35rem; }
  .event-chip { font-size: .62rem; padding: .12rem .3rem; }
  .modal-card { padding: 1.4rem; }
  .modal-title { font-size: 1.15rem; }
  .map-container { height: 170px; }
  .logo-text { font-size: 1.15rem; }
  .site-nav-link { font-size: .8rem; padding: .38rem .6rem; }
  .org-grid { grid-template-columns: 1fr; }
  #poly-map { height: 360px; }
  .page-wrapper { padding: 0 1rem 3rem; }
}
