/* ==========================================================================
   Realply Sourcing & Export Market Explorer
   Design tokens: paper-toned background, deep pine accent (Source),
   warm timber-brown accent (Export), serif display / sans body / mono data.
   ========================================================================== */

:root {
  --color-bg: #F4F5F0;
  --color-surface: #FFFFFF;
  --color-border: #E2E5DC;
  --color-border-strong: #C9CFC1;
  --color-text: #1B231E;
  --color-text-muted: #626E63;
  --color-accent: #2B6E4F;       /* pine green, Source tag, primary actions */
  --color-accent-dark: #17422D;
  --color-accent-soft: #E8F0EA;
  --color-export: #9A5B2E;       /* timber brown, Export tag */
  --color-export-soft: #F5EAE0;
  --color-error: #B3432E;
  --color-error-bg: #FBEAE6;

  --font-display: 'Source Serif 4', Georgia, serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;

  --radius: 10px;
  --radius-lg: 16px;
  --shadow-card: 0 1px 2px rgba(23, 30, 25, 0.04), 0 1px 1px rgba(23, 30, 25, 0.03);
  --shadow-card-hover: 0 10px 24px rgba(23, 30, 25, 0.10), 0 2px 6px rgba(23, 30, 25, 0.06);
  --shadow-panel: 0 20px 60px rgba(20, 27, 22, 0.22);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* -------------------------------------------------------------------- */
/* Header                                                                */
/* -------------------------------------------------------------------- */

.site-header {
  background: var(--color-surface);
  box-shadow: 0 1px 0 var(--color-border), 0 4px 16px rgba(23, 30, 25, 0.04);
}

.header-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 2.5rem 1.75rem 1.75rem;
}

.site-header h1 {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 0.45rem;
  color: var(--color-accent-dark);
}

.home-button {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  text-align: left;
  display: block;
  transition: opacity 0.15s ease;
}

.home-button:hover {
  opacity: 0.82;
}

.tagline {
  margin: 0;
  color: var(--color-text-muted);
  font-size: 0.98rem;
}

main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 1.75rem;
}

/* -------------------------------------------------------------------- */
/* Controls                                                              */
/* -------------------------------------------------------------------- */

.control-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 1.75rem;
}

#search-input,
#region-select,
#sort-select {
  font-family: var(--font-body);
  font-size: 0.92rem;
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#search-input:focus,
#region-select:focus,
#sort-select:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-soft);
  outline: none;
}

#search-input {
  flex: 1 1 220px;
  min-width: 180px;
}

button {
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 500;
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}

button:hover {
  border-color: var(--color-accent);
  box-shadow: 0 2px 8px rgba(23, 30, 25, 0.06);
}

button:active {
  transform: scale(0.97);
}

#shortlist-toggle[aria-pressed="true"] {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: white;
}

.view-toggle {
  display: flex;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  overflow: hidden;
}

.view-btn {
  border: none;
  border-radius: 0;
  background: var(--color-surface);
}

.view-btn.active {
  background: var(--color-accent);
  color: white;
}

:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* -------------------------------------------------------------------- */
/* State messages (loading / error / empty)                             */
/* -------------------------------------------------------------------- */

.state-message {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--color-text-muted);
}

#error-state {
  background: var(--color-error-bg);
  border: 1px solid var(--color-error);
  border-radius: var(--radius);
  color: var(--color-error);
}

#error-state button {
  margin-top: 0.75rem;
  border-color: var(--color-error);
  color: var(--color-error);
}

/* -------------------------------------------------------------------- */
/* Country grid + cards                                                 */
/* -------------------------------------------------------------------- */

.country-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 1.1rem;
}

.country-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.1rem;
  cursor: pointer;
  box-shadow: var(--shadow-card);
  transition: box-shadow 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
  position: relative;
}

.country-card:hover,
.country-card:focus-visible {
  border-color: var(--color-border-strong);
  box-shadow: var(--shadow-card-hover);
  transform: translateY(-2px);
}

.country-flag {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 0.8rem;
  background: var(--color-bg);
  display: block;
}

.country-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.08rem;
  letter-spacing: -0.005em;
  margin: 0 0 0.25rem;
}

.country-region {
  margin: 0 0 0.35rem;
  color: var(--color-text-muted);
  font-size: 0.84rem;
}

.country-population {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

/* Shortlist tag badges, shown on cards inside the My Shortlist view */
.shortlist-tags {
  display: flex;
  gap: 0.35rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

.tag {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  color: white;
  letter-spacing: 0.02em;
}

.tag-source {
  background: var(--color-accent);
}

.tag-export {
  background: var(--color-export);
}

.shortlist-controls {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.7rem;
}

.shortlist-btn {
  font-size: 0.72rem;
  font-weight: 500;
  padding: 0.32rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.shortlist-btn.active-source {
  background: var(--color-accent-soft);
  border-color: var(--color-accent);
  color: var(--color-accent-dark);
}

.shortlist-btn.active-export {
  background: var(--color-export-soft);
  border-color: var(--color-export);
  color: var(--color-export);
}

.shortlist-note {
  display: block;
  width: 100%;
  margin-top: 0.65rem;
  padding: 0.45rem 0.65rem;
  font-size: 0.82rem;
  font-family: var(--font-body);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface);
  color: var(--color-text);
}

/* -------------------------------------------------------------------- */
/* Detail panel (modal overlay)                                         */
/* -------------------------------------------------------------------- */

.detail-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 26, 23, 0.45);
  z-index: 2000;
}

.detail-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(440px, 100vw);
  background: var(--color-surface);
  box-shadow: var(--shadow-panel);
  z-index: 2001;
  overflow-y: auto;
}

.detail-panel-inner {
  padding: 2.25rem 2rem;
  position: relative;
}

#detail-close {
  position: absolute;
  top: 1.5rem;
  right: 1.5rem;
  font-size: 1.3rem;
  line-height: 1;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  color: var(--color-text-muted);
}

#detail-close:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.detail-flag {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
}

.detail-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.65rem;
  letter-spacing: -0.01em;
  margin: 0 0 0.25rem;
}

.detail-region {
  color: var(--color-text-muted);
  margin: 0 0 1.5rem;
  font-size: 0.95rem;
}

.detail-facts {
  display: grid;
  grid-template-columns: auto 1fr;
  row-gap: 0.75rem;
  column-gap: 1.25rem;
  margin: 0 0 1.75rem;
}

.detail-facts dt {
  font-weight: 600;
  color: var(--color-text-muted);
  font-size: 0.82rem;
}

.detail-facts dd {
  margin: 0;
  font-size: 0.92rem;
}

.detail-panel h3 {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  margin: 1.5rem 0 0.6rem;
}

.gdp-bar-track {
  background: var(--color-bg);
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
  border: 1px solid var(--color-border);
}

.gdp-bar-fill {
  height: 100%;
  background: var(--color-accent);
  border-radius: 999px;
}

.gdp-value,
.currency-rate {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  margin: 0.4rem 0 0;
}

.data-unavailable {
  color: var(--color-text-muted);
  font-style: italic;
  font-size: 0.88rem;
  margin: 0.2rem 0 0;
}

/* -------------------------------------------------------------------- */
/* Map view                                                              */
/* -------------------------------------------------------------------- */

.map-section {
  position: relative;
}

#world-map {
  height: 640px;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: #E9EDE7;
}

.leaflet-container {
  font-family: var(--font-body);
  border-radius: var(--radius);
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.9rem;
  margin-top: 0.9rem;
  padding: 0.8rem 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.82rem;
  color: var(--color-text-muted);
}

.map-legend-title {
  margin: 0;
  font-weight: 600;
  color: var(--color-text);
  width: 100%;
}

.map-legend-title:not(:first-child) {
  margin-top: 0.3rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
}

.map-tooltip {
  font-family: var(--font-body);
  font-size: 0.85rem;
}

/* -------------------------------------------------------------------- */
/* Shortlist view                                                       */
/* -------------------------------------------------------------------- */

.shortlist-view {
  margin-top: 1.5rem;
}

.shortlist-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.shortlist-header h2 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.4rem;
  margin: 0;
}

.shortlist-actions {
  display: flex;
  gap: 0.5rem;
}

/* -------------------------------------------------------------------- */
/* Footer                                                               */
/* -------------------------------------------------------------------- */

.site-footer {
  max-width: 1100px;
  margin: 2rem auto 0;
  padding: 1.5rem;
  border-top: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: 0.85rem;
}

.site-footer a {
  color: var(--color-accent-dark);
}

/* -------------------------------------------------------------------- */
/* Responsive                                                            */
/* -------------------------------------------------------------------- */

@media (max-width: 600px) {
  .country-grid {
    grid-template-columns: 1fr;
  }

  #world-map {
    height: 440px;
  }

  .detail-panel {
    width: 100%;
  }

  .control-row {
    flex-direction: column;
    align-items: stretch;
  }

  .header-inner {
    padding: 1.5rem 1rem 1.25rem;
  }
}

/* -------------------------------------------------------------------- */
/* Reduced motion                                                        */
/* -------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}