/* =========================================================
   Tread Lightly! Membership Density Map - v2.0.0
   Brand colors: #F5A800 gold scale, #2e302e dark
   Layout: Map top, cards below
   ========================================================= */

.tlm-widget {
  --tlm-gold:       #F5A800;
  --tlm-dark:       #2e302e;
  --tlm-map-bg:     #f5f0e8;
  --tlm-error-bg:   #fff3f3;
  --tlm-error-text: #8b2222;
  --tlm-warn-bg:    #fffbea;
  --tlm-warn-text:  #6b4c10;
  --tlm-radius:     8px;
  --tlm-shadow:     0 2px 8px rgba(46,48,46,0.10);
  --tlm-font:       -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;

  font-family: var(--tlm-font);
  color:       var(--tlm-dark);
  background:  transparent;
  box-sizing:  border-box;
  padding:     0;
  margin:      0;
}

.tlm-widget *, .tlm-widget *::before, .tlm-widget *::after {
  box-sizing: inherit;
}

/* State / Error Screens */
.tlm-state {
  display:         flex;
  flex-direction:  column;
  align-items:     center;
  justify-content: center;
  padding:         48px 24px;
  background:      #fef6d8;
  border:          1px solid rgba(46,48,46,0.15);
  border-radius:   var(--tlm-radius);
  text-align:      center;
  min-height:      280px;
}

.tlm-state-icon { font-size: 3rem; margin-bottom: 12px; }
.tlm-state h3   { margin: 0 0 8px; font-size: 1.25rem; font-weight: 600; }
.tlm-state p    { margin: 0 0 6px; opacity: .7; }
.tlm-state-sub  { font-size: 0.875rem; opacity: .55; }
.tlm-error-state { background: var(--tlm-error-bg); }
.tlm-error-state h3 { color: var(--tlm-error-text); }

/* Warning Banner */
.tlm-banner {
  padding:       10px 16px;
  border-radius: var(--tlm-radius);
  font-size:     0.875rem;
  margin-bottom: 14px;
}
.tlm-banner-warning {
  background: var(--tlm-warn-bg);
  border:     1px solid #d4b04a;
  color:      var(--tlm-warn-text);
}

.tlm-widget-header {
  margin: 0 0 18px;
}

.tlm-widget-header h2 {
  margin: 0 0 4px;
  color: var(--tlm-dark);
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.1;
}

.tlm-widget-header p {
  margin: 0;
  color: #666;
  font-size: 0.95rem;
  font-weight: 600;
}

/* Map Container */
.tlm-map-container {
  position:      relative;
  background:    var(--tlm-map-bg);
  border-radius: var(--tlm-radius);
  padding:       14px;
  margin-bottom: 14px;
  box-shadow:    var(--tlm-shadow);
}

.tlm-map-loading {
  display:         flex;
  flex-direction:  column;
  align-items:     center;
  justify-content: center;
  min-height:      280px;
  color:           var(--tlm-dark);
  opacity:         .6;
}

.tlm-map-loading p { margin: 12px 0 0; font-size: 0.9rem; }
.tlm-load-error    { color: var(--tlm-error-text); font-size: 0.9rem; text-align: center; }

.tlm-spinner {
  width:        40px;
  height:       40px;
  border:       4px solid #e8e0cc;
  border-top-color: #f9bd27;
  border-radius: 50%;
  animation:    tlm-spin 0.9s linear infinite;
}

@keyframes tlm-spin { to { transform: rotate(360deg); } }

.tlm-map-svg { display: block; width: 100%; max-width: 100%; }

.tlm-widget svg path:hover { opacity: 0.82; cursor: pointer; }
.tlm-widget svg path.is-selected {
  stroke: #111;
  stroke-width: 1.8;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.22));
}

/* Tooltip */
.tlm-tooltip {
  position:       absolute;
  pointer-events: none;
  background:     var(--tlm-dark);
  color:          #fff;
  padding:        10px 14px;
  border-radius:  6px;
  font-size:      0.85rem;
  box-shadow:     0 4px 12px rgba(0,0,0,0.25);
  z-index:        100;
  min-width:      150px;
}

.tlm-tt-state { font-weight: 700; font-size: 1rem; margin-bottom: 2px; }
.tlm-tt-abbr  { font-size: 0.75rem; opacity: 0.6; margin-bottom: 6px; }
.tlm-tt-count { font-size: 0.9rem; font-weight: 600; color: var(--tlm-gold); }
.tlm-tt-pct   { font-size: 0.8rem; opacity: 0.75; margin-top: 2px; }

/* Map Footer */
.tlm-map-footer {
  display:         flex;
  justify-content: space-between;
  align-items:     center;
  margin-top:      10px;
  flex-wrap:       wrap;
  gap:             6px;
}

.tlm-legend-inner {
  display:     flex;
  align-items: center;
  gap:         10px;
  flex-wrap:   wrap;
}

.tlm-legend-label {
  font-size:   0.7rem;
  color:       var(--tlm-dark);
  font-weight: 500;
  white-space: nowrap;
}

.tlm-legend-swatches {
  display:     flex;
  gap:         5px;
  flex-wrap:   wrap;
  align-items: center;
}

.tlm-legend-swatch { display: flex; align-items: center; gap: 3px; }

.tlm-swatch-color {
  display:       inline-block;
  width:         16px;
  height:        12px;
  border-radius: 2px;
}

.tlm-swatch-text { font-size: 0.7rem; color: var(--tlm-dark); }

.tlm-refresh-note {
  font-size:      0.68rem;
  color:          var(--tlm-dark);
  font-weight:    500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity:        0.7;
}

/* Summary Cards */
.tlm-cards {
  display:               grid;
  grid-template-columns: repeat(3, 1fr);
  gap:                   10px;
  margin-top:            4px;
}

.tlm-card {
  background:    #f9bd27;
  border-radius: var(--tlm-radius);
  padding:       18px 14px;
  text-align:    center;
  box-shadow:    var(--tlm-shadow);
}

.tlm-card-value {
  font-size:     2rem;
  font-weight:   700;
  color:         var(--tlm-dark);
  line-height:   1.1;
  margin-bottom: 5px;
}

.tlm-card-label {
  font-size:   0.8rem;
  color:       var(--tlm-dark);
  font-weight: 500;
  line-height: 1.3;
}

.tlm-drilldown {
  margin-top: 18px;
  background: #fff;
  border: 1px solid rgba(46,48,46,0.12);
  border-radius: var(--tlm-radius);
  box-shadow: var(--tlm-shadow);
  overflow: hidden;
}

.tlm-drilldown-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 18px;
  border-bottom: 1px solid #e8e8e8;
}

.tlm-drilldown h3 {
  margin: 0 0 4px;
  font-size: 1.05rem;
  font-weight: 800;
}

.tlm-drilldown p {
  margin: 0;
  color: #646464;
  font-size: 0.86rem;
}

.tlm-reset-selection {
  appearance: none;
  border: 1px solid rgba(46,48,46,0.25);
  border-radius: 6px;
  background: #fff;
  color: var(--tlm-dark);
  cursor: pointer;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 8px 12px;
  white-space: nowrap;
}

.tlm-reset-selection:hover {
  background: #f7f7f7;
}

.tlm-reset-selection:disabled {
  cursor: default;
  opacity: 0.65;
}

.tlm-type-filter {
  padding: 0;
  border-bottom: 1px solid #e8e8e8;
  background: #fffdf8;
}

.tlm-type-filter-head {
  margin: 0;
}

.tlm-type-toggle {
  appearance: none;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 18px;
  border: 0;
  background: transparent;
  color: var(--tlm-dark);
  cursor: pointer;
  font: inherit;
  text-align: left;
}

.tlm-type-toggle strong {
  display: block;
  color: var(--tlm-dark);
  font-size: 0.92rem;
  font-weight: 800;
}

.tlm-type-toggle em {
  display: block;
  margin-top: 3px;
  color: #646464;
  font-size: 0.8rem;
  font-style: normal;
  font-weight: 500;
}

.tlm-type-toggle-icon {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  border: 1px solid rgba(46,48,46,0.16);
  border-radius: 999px;
  background: #fff;
  color: var(--tlm-dark);
  font-size: 1rem;
  font-weight: 900;
  line-height: 1;
  transition: transform 160ms ease, background 160ms ease;
}

.tlm-type-filter.is-open .tlm-type-toggle-icon {
  background: #f7f7f7;
  transform: rotate(45deg);
}

.tlm-type-panel {
  padding: 0 18px 16px;
}

.tlm-type-panel[hidden] {
  display: none;
}

.tlm-type-filter-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.tlm-type-filter-actions button {
  appearance: none;
  border: 1px solid rgba(46,48,46,0.18);
  border-radius: 6px;
  background: #fff;
  color: var(--tlm-dark);
  cursor: pointer;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 800;
  padding: 7px 10px;
  white-space: nowrap;
}

.tlm-type-filter-actions button:hover {
  background: #f7f7f7;
}

.tlm-type-filter-actions button:disabled {
  cursor: default;
  opacity: 0.55;
}

.tlm-type-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.tlm-type-option {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas:
    "check label"
    "check group";
  column-gap: 8px;
  row-gap: 2px;
  align-items: center;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid rgba(46,48,46,0.12);
  border-radius: 7px;
  background: #fff;
  cursor: pointer;
}

.tlm-type-option input {
  grid-area: check;
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--tlm-gold);
}

.tlm-type-option span {
  grid-area: label;
  min-width: 0;
  color: var(--tlm-dark);
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1.25;
}

.tlm-type-option em {
  grid-area: group;
  min-width: 0;
  color: #777;
  font-size: 0.68rem;
  font-style: normal;
  font-weight: 700;
  line-height: 1.2;
  text-transform: uppercase;
}

.tlm-type-empty {
  margin: 0;
  color: #646464;
  font-size: 0.84rem;
}

.tlm-drilldown-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid #e8e8e8;
}

.tlm-drilldown-stats div {
  padding: 14px 18px;
  border-right: 1px solid #e8e8e8;
}

.tlm-drilldown-stats div:last-child {
  border-right: 0;
}

.tlm-drilldown-stats span {
  display: block;
  color: #6b6b6b;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.tlm-drilldown-stats strong {
  display: block;
  color: var(--tlm-dark);
  font-size: 1.4rem;
  line-height: 1.1;
}

.tlm-breakdown-table {
  width: 100%;
  border-collapse: collapse;
}

.tlm-breakdown-table th,
.tlm-breakdown-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #eeeeee;
  font-size: 0.9rem;
}

.tlm-breakdown-table th {
  background: #f7f7f7;
  color: #555;
  font-size: 0.72rem;
  font-weight: 800;
  text-align: left;
  text-transform: uppercase;
}

.tlm-breakdown-table th:nth-child(2),
.tlm-breakdown-table th:nth-child(3),
.tlm-breakdown-table td:nth-child(2),
.tlm-breakdown-table td:nth-child(3) {
  text-align: right;
}

.tlm-unmapped {
  margin-top: 18px;
}

.tlm-unmapped h3 {
  margin: 0 0 10px;
  font-size: 1rem;
  font-weight: 700;
}

.tlm-unmapped table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

.tlm-unmapped th,
.tlm-unmapped td {
  padding: 9px 12px;
  border-bottom: 1px solid #e5e5e5;
  font-size: 0.9rem;
}

.tlm-unmapped th {
  background: #f7f7f7;
  text-align: left;
}

.tlm-unmapped th:last-child,
.tlm-unmapped td:last-child {
  text-align: right;
}

.tlm-unmapped th:nth-child(n+2),
.tlm-unmapped td:nth-child(n+2) {
  text-align: right;
}

/* Responsive */

/* Tablet */
@media (max-width: 780px) {
  .tlm-cards      { gap: 8px; }
  .tlm-card       { padding: 14px 10px; }
  .tlm-card-value { font-size: 1.6rem; }
  .tlm-card-label { font-size: 0.72rem; }
}

/* Narrow: stack cards vertically, horizontal layout per card */
@media (max-width: 560px) {
  .tlm-cards        { grid-template-columns: 1fr; gap: 8px; }
  .tlm-card         { padding: 12px 16px; display: flex; align-items: center; text-align: left; }
  .tlm-card-value   { font-size: 1.8rem; margin-bottom: 0; margin-right: 14px; white-space: nowrap; }
  .tlm-card-label   { font-size: 0.8rem; flex: 1; }
  .tlm-map-footer   { flex-direction: column; align-items: flex-start; gap: 8px; }
  .tlm-refresh-note { font-size: 0.65rem; }
  .tlm-drilldown-head { align-items: flex-start; flex-direction: column; }
  .tlm-type-toggle { align-items: flex-start; }
  .tlm-type-filter-actions { justify-content: flex-start; }
  .tlm-type-options { grid-template-columns: 1fr; }
  .tlm-drilldown-stats { grid-template-columns: 1fr; }
  .tlm-drilldown-stats div { border-right: 0; border-bottom: 1px solid #e8e8e8; }
  .tlm-drilldown-stats div:last-child { border-bottom: 0; }
}

/* Small phone */
@media (max-width: 420px) {
  .tlm-card-value      { font-size: 1.5rem; }
  .tlm-legend-inner    { flex-direction: column; align-items: flex-start; gap: 6px; }
  .tlm-legend-swatches { flex-wrap: wrap; }
}
