/* =========================================================
   Scoped styles for chart display page only
   Everything is under .cd to avoid affecting global site
   ========================================================= */

.cd {
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

/* page backgrounds (scoped) */
.cd {
  background: #f5f6fb;
  color: #1f2430;
  min-height: 100vh;
}

body.dark .cd {
  background: #1e1e2f;
  color: #e0e0e0;
}

/* container spacing */
.cd #charts-container {
  padding: 12px;
  padding-bottom: 120px;
  transition: opacity 0.3s ease;
}

.cd .updating {
  opacity: 0.35;
  pointer-events: none;
}

/* dark toggle (still fixed, but scoped by class name) */
.cd .toggle-dark-mode {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 10000;
  padding: 0.5rem 1rem;
  font-size: 1rem;
  border-radius: 0.75rem;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 0.5rem 1rem rgba(0,0,0,0.2);
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.cd .toggle-dark-mode:hover {
  transform: scale(1.05);
}

/* chart tile */
.cd .chart-box {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 8px;

  background: #ffffff;
  border-radius: 1rem;
  padding: 1.25rem;
  box-shadow: 0 0.5rem 1rem rgba(0,0,0,0.08);
  transition: background 0.25s ease, box-shadow 0.25s ease, transform 0.25s ease;

  cursor: move; /* sortable handle */
}

.cd .chart-box:hover {
  transform: translateY(-2px);
  box-shadow: 0 0.75rem 1.6rem rgba(0,0,0,0.12);
}

body.dark .cd .chart-box {
  background: #2c2c3c;
  box-shadow: 0 0.75rem 2rem rgba(0,0,0,0.25);
}

/* title + meta */
.cd .chart-title {
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.2;
  margin-top: 8px;
}

.cd .chart-meta {
  font-size: 0.75rem;
  opacity: 0.65;
  margin-bottom: 6px;
}

/* chart mount */
.cd .chart-mount {
  width: 100%;
  min-height: 340px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* selector (top-right) */
.cd .chart-type-selector {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
  border-radius: 0.4rem;
  border: 1px solid #d0d4dd;
  background: #fff;
  color: #333;
  z-index: 2;
  outline: none;
}

body.dark .cd .chart-type-selector {
  background: #2f2f3f;
  color: #e0e0e0;
  border: 1px solid #444;
}

/* refresh button (bottom-right) */
.cd .refresh-selector {
  position: absolute;
  bottom: 0.75rem;
  right: 0.75rem;
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
  border-radius: 0.4rem;
  border: 1px solid #d0d4dd;
  background: #fff;
  color: #333;
  z-index: 2;
  cursor: pointer;
  transition: background 0.2s ease;
}

.cd .refresh-selector:hover {
  background: #f0f0f0;
}

body.dark .cd .refresh-selector {
  background: #2f2f3f;
  color: #e0e0e0;
  border: 1px solid #444;
}

/* matrix table */
.cd .matrix-wrap {
  width: 100%;
  overflow: auto;
  border-radius: 0.75rem;
}

.cd .matrix-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 520px;
}

.cd .matrix-table th,
.cd .matrix-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(0,0,0,0.08);
  text-align: left;
  font-size: 0.85rem;
  white-space: nowrap;
}

.cd .matrix-table thead th {
  position: sticky;
  top: 0;
  background: rgba(255,255,255,0.95);
  z-index: 1;
}

body.dark .cd .matrix-table thead th {
  background: rgba(44,44,60,0.95);
}

body.dark .cd .matrix-table th,
body.dark .cd .matrix-table td {
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

/* map tile */
.cd .leaflet-map {
  background: #ffffff;
  border-radius: 1rem;
  overflow: hidden;
  transition: background 0.3s ease;
}

body.dark .cd .leaflet-map {
  background: #2c2c3c;
}

.cd .leaflet-container {
  width: 100% !important;
  height: 420px !important;
  border-radius: 0.75rem;
}

/* leaflet dark popups */
body.dark .cd .leaflet-popup-content-wrapper,
body.dark .cd .leaflet-popup-tip {
  background: #2f2f3f;
  color: #fff;
  border: 1px solid #3f3f4f;
}

/* cluster styling (scoped) */
.cd .marker-cluster div {
  position: relative;
  background: #e53935;
  border-radius: 50%;
  color: #fff;
  font-weight: bold;
  font-size: 1.1rem;
  text-align: center;
  line-height: 45px;
  width: 50px;
  height: 50px;
  border: 3px solid #fff;
  box-shadow: 0 0 10px rgba(229, 57, 53, 0.6);
  transition: transform 0.2s ease;
  z-index: 1;
}

.cd .marker-cluster div::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 50px;
  height: 50px;
  background: rgba(229, 57, 53, 0.3);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  animation: cdPulseRed 1.5s ease-out infinite;
  z-index: -1;
}

body.dark .cd .marker-cluster div {
  background: #ef5350;
  border-color: #2c2c3c;
  box-shadow: 0 0 12px rgba(255, 82, 82, 0.8);
}

body.dark .cd .marker-cluster div::before {
  background: rgba(255, 82, 82, 0.25);
}

@keyframes cdPulseRed {
  0% { transform: translate(-50%, -50%) scale(1); opacity: 0.8; }
  70% { transform: translate(-50%, -50%) scale(2.2); opacity: 0.1; }
  100% { transform: translate(-50%, -50%) scale(2.5); opacity: 0; }
}

/* =======================
   Filters bar (scoped)
   ======================= */
.cd .cd-filters{
  padding: 14px 14px 0 14px;
}

.cd .cd-filters-card{
  background:#fff;
  border-radius: 1rem;
  padding: 14px;
  box-shadow: 0 0.5rem 1rem rgba(0,0,0,0.08);
}

body.dark .cd .cd-filters-card{
 
}

.cd .cd-filters-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  margin-bottom:10px;
}

.cd .cd-filters-title{
  font-weight:700;
  font-size:0.95rem;
}

.cd .cd-filters-grid{
  display:grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 12px;
}

.cd .cd-filter{
  grid-column: span 3;
  min-width: 220px;
}

@media (max-width: 1200px){
  .cd .cd-filter{ grid-column: span 4; }
}
@media (max-width: 900px){
  .cd .cd-filter{ grid-column: span 6; }
}
@media (max-width: 560px){
  .cd .cd-filter{ grid-column: span 12; }
}

.cd .cd-filter label{
  display:block;
  font-size: 0.78rem;
  opacity: 0.75;
  margin-bottom: 6px;
  font-weight: 600;
}

.cd .cd-filter select,
.cd .cd-filter input{
  width:100%;
  border:1px solid #d0d4dd;
  border-radius: .6rem;
  padding: .45rem .6rem;
  font-size: .85rem;
  background:#fff;
  outline:none;
}

body.dark .cd .cd-filter select,
body.dark .cd .cd-filter input{
  background:#2f2f3f;
  color:#e0e0e0;
  border:1px solid #444;
}

.cd .cd-filter small{
  display:block;
  margin-top:6px;
  font-size:0.75rem;
  opacity:0.65;
}

.cd .cd-btn{
  border:1px solid #d0d4dd;
  background:#fff;
  border-radius:.7rem;
  padding:.45rem .75rem;
  font-size:.85rem;
  cursor:pointer;
}
body.dark .cd .cd-btn{
  background:#2f2f3f;
  color:#e0e0e0;
  border:1px solid #444;
}

.reset-chart-settings{
  margin-left:8px;
  border:1px solid #ccc;
  background:#fff;
  padding:6px 10px;
  border-radius:10px;
  font-size:12px;
}



/* =======================
   Floating bar + sidebar (scoped)
   ======================= */

.cd .cd-floatbar{
  position: fixed;
  left: 16px;
  bottom: 16px;
  z-index: 10001;
  display:flex;
  align-items:center;
  gap:10px;
  padding:10px 12px;
  border-radius: 14px;
  box-shadow: 0 8px 22px rgba(0,0,0,.15);
  background:#fff;
  color:#222;
  border:1px solid rgba(0,0,0,.08);
  max-width: calc(100vw - 32px);
}

body.dark .cd .cd-floatbar{
  background:#151515;
  color:#eee;
  border-color: rgba(255,255,255,.12);
}

.cd .cd-floatbar .cd-title{
  font-weight:700;
  font-size:13px;
  line-height:1.1;
  max-width:220px;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}

.cd .cd-floatbar .cd-count{
  font-size:12px;
  opacity:.8;
}

.cd .cd-floatbar .cd-actions{
  display:flex;
  gap:8px;
  margin-left:8px;
}

.cd .cd-floatbar button{
  border:1px solid rgba(0,0,0,.15);
  background:transparent;
  padding:6px 10px;
  border-radius:10px;
  font-size:12px;
  cursor:pointer;
}

body.dark .cd .cd-floatbar button{
  border-color: rgba(255,255,255,.18);
  color:#fff;
}

.cd .cd-floatbar button:hover{ opacity:.85; }

/* Overlay */
.cd .cd-overlay{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.42);
  z-index: 10000;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
}

.cd .cd-overlay.open{
  opacity: 1;
  pointer-events: auto;
}

/* Sidebar */
.cd .cd-sidebar{
  position: fixed;
  left: 0;
  top: 0;
  height: 100vh;
  width: min(420px, 88vw);
  z-index: 10002;
  background:#fff;
  border-right:1px solid rgba(0,0,0,.08);
  transform: translateX(-105%);
  transition: transform .18s ease;
  display:flex;
  flex-direction:column;
}

body.dark .cd .cd-sidebar{
  background:#121212;
  border-right-color: rgba(255,255,255,.12);
}

.cd .cd-sidebar.open{ transform: translateX(0); }

.cd .cd-sidebar-head{
  padding:14px 14px 10px 14px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  border-bottom:1px solid rgba(0,0,0,.08);
}

body.dark .cd .cd-sidebar-head{
  border-bottom-color: rgba(255,255,255,.12);
}

.cd .cd-sidebar-head .h{
  font-weight:800;
  font-size:14px;
}

.cd .cd-sidebar-head button{
  border:1px solid rgba(0,0,0,.15);
  background:transparent;
  padding:6px 10px;
  border-radius:10px;
  cursor:pointer;
  font-size:12px;
}

body.dark .cd .cd-sidebar-head button{
  border-color: rgba(255,255,255,.18);
  color:#fff;
}

.cd .cd-sidebar-body{
  padding: 12px 14px 14px 14px;
  overflow:auto;
}

.cd .cd-sidebar-foot{
  padding: 12px 14px;
  border-top:1px solid rgba(0,0,0,.08);
  display:flex;
  gap:8px;
}

body.dark .cd .cd-sidebar-foot{
  border-top-color: rgba(255,255,255,.12);
}

.cd .cd-sidebar-foot button{
  flex:1;
  border:1px solid rgba(0,0,0,.15);
  background:transparent;
  padding:10px;
  border-radius:12px;
  cursor:pointer;
  font-size:12px;
}

body.dark .cd .cd-sidebar-foot button{
  border-color: rgba(255,255,255,.18);
  color:#fff;
}

/* Hide the inline filters area once sidebar is used */
.cd .cd-filters.is-hidden{
  display:none;
}

/* =========================================
   Sidebar-friendly filters layout + chips
   ========================================= */

.cd .cd-filters-card{
  background: transparent;         /* sidebar already has background */
  box-shadow: none;
  padding: 0;
  border-radius: 0;
}

.cd .cd-filters-head{
  position: sticky;
  top: 0;
  z-index: 2;
  background: inherit;
  padding: 6px 0 10px 0;
  margin-bottom: 10px;
  border-bottom: 1px solid rgba(0,0,0,0.08);
}

body.dark .cd .cd-filters-head{
  border-bottom-color: rgba(255,255,255,0.12);
}

.cd .cd-filters-title{
  font-size: 14px;
  font-weight: 800;
}

/* Sidebar: use a single column list */
.cd .cd-filters-grid{
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.cd .cd-filter{
  min-width: 0;
  grid-column: auto;
}

/* label + helper */
.cd .cd-filter label{
  font-size: 12px;
  opacity: .85;
  margin-bottom: 0px;
  font-weight: 500;
}

.cd .cd-filter small{
  margin-top: 8px;
  font-size: 11px;
  opacity: .55;
}

/* inputs look tighter */
.cd .cd-filter select,
.cd .cd-filter input[type="text"]{
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
}

/* ---- Chips ---- */
.cd .cd-choice{ 
  display: inline-flex; 
  align-items: center; 
}

/* hide native checkbox/radio but keep accessible */
.cd .cd-chip-input{
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.cd .cd-chip{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid rgba(0,0,0,0.14);
  background: rgba(255,255,255,0.7);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
}

body.dark .cd .cd-chip{
  border-color: rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.06);
}

/* hover */
.cd .cd-chip:hover{ transform: translateY(-1px); }

/* selected state */
.cd .cd-chip-input:checked + .cd-chip{
  border-color: rgba(0,0,0,0.55);
  background: rgba(0,0,0,0.06);
}

body.dark .cd .cd-chip-input:checked + .cd-chip{
  border-color: rgba(255,255,255,0.45);
  background: rgba(255,255,255,0.12);
}

/* focus ring */
.cd .cd-chip-input:focus-visible + .cd-chip{
  outline: 2px solid rgba(0,0,0,0.35);
  outline-offset: 2px;
}
body.dark .cd .cd-chip-input:focus-visible + .cd-chip{
  outline-color: rgba(255,255,255,0.35);
}

/* chips container */
.cd .cd-chips{
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Optional: show "Any" first and slightly different */
.cd .cd-chip--any{
  opacity: .85;
}


/* Leaflet breaks inside flex containers */
.cd .chart-mount:has(.leaflet-map),
.cd .chart-mount:has(.leaflet-container) {
  display: block !important;
}

/* optional: ensure the map wrapper can size properly */
.cd .chart-mount .leaflet-map {
  width: 100%;
}
