/* =========================================================
 * Ground Dryness — Styles
 * ========================================================= */

/* Padding inherits from .wd-card (var(--wd-space-lg) = 16px) so the
   dryness card sits flush with the rain-gauge map / rainfall-history cards
   below it on the Ground tab. */

/* ─── Vertical rhythm — gaps between cards on the Ground tab ─── */

/* Hide the placeholder error span when empty so it doesn't push the first
   card down. (Was adding ~19px of phantom height above the dryness card.) */
#tab-grounds #wd-rainx-err:empty {
  display: none;
}

#tab-grounds .wd-grounds-dryness-card,
#tab-grounds .wd-grounds-grid {
  margin-bottom: var(--wd-space-lg, 16px) !important;
}

/* Stretch the rainfall history card to match the map card's height. */
#tab-grounds .wd-grounds-grid {
  align-items: stretch;
}

/* ─── Top 60/40 split: left = hero + scale + station picker, right = data sources ─── */
.wd-ground-top-grid {
  display: grid;
  grid-template-columns: 6fr 4fr;
  gap: var(--wd-space-lg, 16px);
  align-items: start;
}

/* ─── Hero summary — gradient score, label, description, meta pills ─── */
.wd-ground-summary {
  padding: 0;
}

.wd-ground-hero {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 18px;
  align-items: center;
}

.wd-ground-score-num {
  font-size: 3.4rem;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  /* Colour set by JS via the blue→green→brown gradient. */
}

.wd-ground-hero-meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.wd-ground-title {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--wd-text-primary, #222);
}

.wd-ground-desc {
  font-size: 0.88rem;
  color: var(--wd-text-secondary, #5b626b);
  line-height: 1.45;
  max-width: 520px;
}

.wd-ground-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
  font-size: 0.76rem;
}

.wd-ground-meta-pill {
  background: var(--wd-bg-soft, #f1f4f7);
  color: var(--wd-text-secondary, #5b626b);
  padding: 3px 10px;
  border-radius: 999px;
}
.wd-ground-meta-pill[hidden] { display: none; }

/* ─── Gradient scale strip — Saturated → Bone dry, marker at the score's position ─── */
.wd-ground-scale {
  margin: 16px 0 0;
  position: relative;
}
.wd-ground-scale[hidden] { display: none; }

.wd-ground-scale-bar {
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(90deg,
    #1f5d8c 0%,
    #4a90c0 12%,
    #6fa86b 38%,
    #6c8d4a 56%,
    #a89357 78%,
    #8b6f47 100%
  );
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}

.wd-ground-scale-marker {
  position: absolute;
  top: -3px;
  left: 0;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid currentColor;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  transform: translateX(-50%);
  transition: left 200ms ease, border-color 200ms ease;
}

.wd-ground-scale-labels,
.wd-ground-scale-numbers {
  display: flex;
  justify-content: space-between;
}
.wd-ground-scale-labels {
  margin-top: 8px;
  font-size: 0.7rem;
  color: var(--wd-text-secondary, #8a929b);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.wd-ground-scale-numbers {
  margin-top: 3px;
  font-size: 0.65rem;
  color: var(--wd-text-tertiary, #b1b6bd);
  font-variant-numeric: tabular-nums;
}

/* ─── Divider between hero and the rest of the card ─── */
.wd-ground-divider {
  height: 1px;
  background: var(--wd-border-soft, #e7eaee);
  margin: 16px 0;
}

/* Surface-water puddling pill — shown when s_surf is high or runoff active */
.wd-ground-puddling {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 10px;
  font-size: 0.8rem;
  font-weight: 500;
  color: #fff;
  background: var(--wd-blue, #4a90c0);
  border-radius: var(--wd-radius-md, 8px);
  line-height: 1.2;
}

/* Rain-station selector — Direction B "card with IDW weight bar".
   Selectors are scoped under #wd-ground-station-picker for specificity
   high enough to defeat Elementor's button-tag overrides; properties
   that Elementor likes to clobber (padding/font-size/bg/border) are
   marked !important. */
#wd-ground-station-picker.wd-ground-station-picker {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: var(--wd-space-md, 12px) 0 0;
}

#wd-ground-station-picker .wd-ground-station-label {
  color: var(--wd-text-tertiary, #8a929b);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
}

#wd-ground-station-picker .wd-ground-station-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

#wd-ground-station-picker .wd-ground-station-btn {
  appearance: none !important;
  background: var(--wd-bg-card, #fff) !important;
  border: 1px solid var(--wd-border, #d8d4cb) !important;
  border-radius: var(--wd-radius-md, 10px) !important;
  padding: 8px 12px 9px !important;
  font-family: var(--wd-font, inherit) !important;
  font-size: 0.8rem !important;
  font-weight: 600 !important;
  color: var(--wd-text-primary, #2a2a2a) !important;
  cursor: pointer;
  text-align: left;
  position: relative;
  overflow: hidden;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.02);
  transition: border-color 0.15s ease;
  display: flex !important;
  flex-direction: column;
  gap: 2px;
  line-height: 1.2;
  min-width: 0;
}

#wd-ground-station-picker .wd-ground-station-btn:hover {
  border-color: var(--wd-text-tertiary, #8a929b) !important;
}

#wd-ground-station-picker .wd-ground-station-btn .wd-gsb-name {
  white-space: normal;
  overflow-wrap: anywhere;
}

#wd-ground-station-picker .wd-ground-station-btn .wd-gsb-meta {
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--wd-text-tertiary, #8a929b);
  font-variant-numeric: tabular-nums;
}

#wd-ground-station-picker .wd-ground-station-btn.is-active,
#wd-ground-station-picker .wd-ground-station-btn.is-active:hover {
  background: var(--wd-green, #4a9d4f) !important;
  border-color: var(--wd-green, #4a9d4f) !important;
  color: #fff !important;
}

#wd-ground-station-picker .wd-ground-station-btn.is-active .wd-gsb-meta {
  color: rgba(255, 255, 255, 0.78);
}

#wd-ground-station-picker .wd-ground-station-btn.is-combined .wd-gsb-name::after {
  content: ' · default';
  font-weight: 500;
  opacity: 0.55;
  font-size: 0.7rem;
}

#wd-ground-station-picker .wd-ground-station-btn.is-active.is-combined .wd-gsb-name::after {
  opacity: 0.8;
}

#wd-ground-station-picker .wd-ground-station-btn:disabled {
  opacity: 0.6;
  cursor: progress;
}

/* Three-layer wetness chart panel (skin / top / deep as % capacity) */
.wd-ground-layers-wrap {
  margin: 12px 0 0;
  padding: 10px 0 4px;
  border-top: 1px solid var(--wd-border-soft, #e7eaee);
}

.wd-ground-layers-legend {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 4px;
  font-size: 0.72rem;
  color: var(--wd-text-secondary, #666);
}

.wd-ground-layer-key {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

#wd-ground-layers-chart {
  height: 100px !important;
  max-height: 100px;
}

/* Chart container */
.wd-ground-chart-wrap {
  position: relative;
  width: 100%;
  min-height: 200px;
  max-height: 300px;
  margin: 12px 0 8px;
}

.wd-ground-chart-wrap canvas {
  width: 100% !important;
}

/* Standalone wrapper */
.wd-ground-standalone {
  max-width: 600px;
}

/* Full-width card in rain explorer bottom */
.wd-rainx-card--full {
  width: 100%;
  grid-column: 1 / -1;
}

/* Search box (standalone mode) */
.wd-ground-search {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.wd-ground-search input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--wd-border);
  border-radius: 4px;
  font-size: 0.9rem;
  font-family: inherit;
}

.wd-ground-search input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.wd-ground-search button {
  padding: 8px 16px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  font-family: inherit;
}

.wd-ground-search button:hover {
  background: #1d4ed8;
}

.wd-ground-search button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Data sources — right column of the top 60/40 split, always visible */
.wd-ground-sources-card {
  margin: 0;
  padding: var(--wd-space-md, 12px) var(--wd-space-lg, 16px);
  background: var(--wd-bg-subtle, #fafbfc);
  border: 1px solid var(--wd-border-soft, #e7eaee);
  border-radius: var(--wd-radius-sm, 6px);
  align-self: stretch;
}
.wd-ground-sources-card[hidden] { display: none; }

.wd-ground-sources-summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
  font-size: 0.78rem;
  color: var(--wd-text-secondary, #6a7079);
}

.wd-ground-sources-label {
  font-weight: 700;
  color: var(--wd-text-primary, #222);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.7rem;
}
.wd-ground-sources-meta {
  font-weight: 400;
  color: var(--wd-text-secondary, #8a929b);
  font-size: 0.7rem;
}

/* Data sources content */
.wd-ground-sources {
  margin: 0;
  padding: 0;
  font-size: 0.76rem;
}

.wd-ground-sources-head {
  font-weight: 800;
  font-size: 0.82rem;
  color: #1c2b23;
  margin-bottom: 4px;
}

.wd-ground-sources-grid {
  display: flex;
  flex-direction: column;
  gap: var(--wd-space-md, 12px);
}

.wd-ground-sources-subtitle {
  font-weight: 700;
  font-size: 0.74rem;
  color: var(--wd-text-secondary);
  margin-bottom: 2px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.wd-ground-src-hdr {
  display: flex;
  justify-content: space-between;
  padding: 0 0 1px;
  font-size: 0.68rem;
  font-weight: 600;
  color: #8a9a8f;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.wd-ground-src-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 2px 0;
  border-bottom: 1px dotted #dde3de;
}

.wd-ground-src-row:last-child {
  border-bottom: none;
}

.wd-ground-src-name {
  font-weight: 700;
  color: #1c2b23;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 55%;
}

.wd-ground-src-tag {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--wd-text-secondary);
  background: #e8ece9;
  padding: 0 4px;
  border-radius: 3px;
  margin-left: 3px;
  vertical-align: baseline;
}

.wd-ground-src-vals {
  display: flex;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--wd-text-secondary);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.wd-ground-src-vals span {
  min-width: 42px;
  text-align: right;
}

/* Responsive */
@media (max-width: 768px) {
  .wd-ground-top-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .wd-grounds-dryness-card {
    padding: var(--wd-card-padding-mobile, 16px);
  }
  .wd-ground-score-num {
    font-size: 2.8rem;
  }
  .wd-ground-title {
    font-size: 1.05rem;
  }
  .wd-ground-desc {
    font-size: 0.84rem;
  }
  .wd-ground-chart-wrap {
    min-height: 160px;
    max-height: 240px;
  }
}
