/* ============================================================
   Kite Spot Fact Base — Stylesheet
   ============================================================ */

:root {
  --c-kite: #2E8B57;
  --c-kite-light: #a8d8a8;
  --c-strong: #e07020;
  --c-foil: #b8d4e3;
  --c-water: #1E90FF;
  --c-air: #FF6347;
  --c-bg: #f8f9fa;
  --c-card: #ffffff;
  --c-border: #e2e8f0;
  --c-text: #1a202c;
  --c-text-muted: #718096;
  --c-hover: #edf2f7;
  --c-accent: #2E8B57;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--c-bg);
  color: var(--c-text);
  line-height: 1.6;
}

/* ─── Layout ─── */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px;
}
.container-wide {
  max-width: 1900px;
}

/* ─── Header ─── */
.app-header {
  background: linear-gradient(135deg, #1a365d 0%, #2E8B57 100%);
  color: white;
  padding: 24px 0;
  margin-bottom: 24px;
}
.app-header h1 {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}
.app-header p {
  opacity: 0.85;
  font-size: 0.95rem;
  margin-top: 4px;
}
.app-header a { color: white; text-decoration: none; }
.app-header .nav {
  display: flex;
  gap: 24px;
  margin-top: 12px;
  font-size: 0.9rem;
}
.app-header .nav a {
  opacity: 0.75;
  transition: opacity 0.2s;
}
.app-header .nav a:hover, .app-header .nav a.active { opacity: 1; font-weight: 600; }

/* ─── Filter Bar ─── */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  padding: 16px;
  background: var(--c-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.filter-bar label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--c-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.filter-bar select, .filter-bar input {
  padding: 6px 12px;
  border: 1px solid var(--c-border);
  border-radius: 6px;
  font-size: 0.9rem;
  background: white;
  color: var(--c-text);
}
.filter-bar select:focus, .filter-bar input:focus {
  outline: none;
  border-color: var(--c-accent);
  box-shadow: 0 0 0 3px rgba(46,139,87,0.15);
}
.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-primary {
  background: var(--c-accent);
  color: white;
}
.btn-primary:hover { background: #247a4a; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary {
  background: var(--c-hover);
  color: var(--c-text);
}
.btn-secondary:hover { background: var(--c-border); }

/* ─── Ranking Table ─── */
.table-wrapper {
  background: var(--c-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
thead {
  position: sticky;
  top: 0;
  z-index: 10;
}
th {
  background: #f1f5f9;
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--c-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  border-bottom: 2px solid var(--c-border);
}
th:hover { background: #e2e8f0; }
th.sorted-asc::after { content: ' \u25b2'; font-size: 0.7rem; }
th.sorted-desc::after { content: ' \u25bc'; font-size: 0.7rem; }
td {
  padding: 10px 12px;
  border-bottom: 1px solid #f1f5f9;
  white-space: nowrap;
}
tr:hover td { background: var(--c-hover); }
td.spot-name {
  font-weight: 600;
  color: var(--c-accent);
}
td.spot-name a {
  color: inherit;
  text-decoration: none;
}
td.spot-name a:hover { text-decoration: underline; }
td.numeric { text-align: right; font-variant-numeric: tabular-nums; }

/* Kite days color coding */
.kite-val { font-weight: 600; }
.kite-val.tier-1 { color: #1a7a3a; }  /* 4+ days/wk */
.kite-val.tier-2 { color: #2E8B57; }  /* 3-4 */
.kite-val.tier-3 { color: #718096; }  /* 2-3 */
.kite-val.tier-4 { color: #a0aec0; }  /* <2 */

/* Compare checkbox */
.compare-cb {
  width: 16px;
  height: 16px;
  accent-color: var(--c-accent);
  cursor: pointer;
}

/* ─── Spot Detail Page ─── */
.spot-header {
  background: var(--c-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}
.spot-header h1 {
  font-size: 2rem;
  font-weight: 700;
  color: var(--c-text);
}
.spot-header .subtitle {
  font-size: 1rem;
  color: var(--c-text-muted);
  margin-top: 4px;
}
.spot-header .rank-badge {
  display: inline-block;
  background: var(--c-accent);
  color: white;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 4px 12px;
  border-radius: 20px;
  margin-right: 8px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-top: 16px;
}
.stat-card {
  background: var(--c-bg);
  border-radius: 6px;
  padding: 12px;
  text-align: center;
}
.stat-card .stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--c-accent);
}
.stat-card .stat-label {
  font-size: 0.75rem;
  color: var(--c-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 2px;
}
.stat-card .stat-sublabel {
  font-size: 0.65rem;
  color: var(--c-text-muted);
  opacity: 0.7;
  margin-top: 1px;
}

/* Wind pattern badges */
.wind-pattern-badge {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.wp-trade-wind { background: #d1fae5; color: #065f46; }
.wp-thermal { background: #fef3c7; color: #92400e; }
.wp-frontal { background: #dbeafe; color: #1e40af; }
.wp-channeled { background: #ede9fe; color: #5b21b6; }
.wp-monsoon { background: #fce7f3; color: #9d174d; }
.wind-pattern-info {
  margin-top: 12px;
  padding: 10px 14px;
  background: var(--c-bg);
  border-radius: 6px;
  font-size: 0.88rem;
  color: var(--c-text-muted);
  line-height: 1.5;
}
.predictability-detail {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--c-border);
}
.predictability-badge {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.pred-very-high { background: #d1fae5; color: #065f46; }
.pred-high { background: #dbeafe; color: #1e40af; }
.pred-medium { background: #fef3c7; color: #92400e; }
.pred-variable { background: #fee2e2; color: #991b1b; }

/* Info cards */
.info-card-full {
  background: var(--c-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.info-card-full h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--c-text-muted);
  margin-bottom: 8px;
}
.info-card-full p {
  font-size: 0.95rem;
  color: var(--c-text);
}
.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.info-grid.info-grid-3 {
  grid-template-columns: repeat(3, 1fr);
  min-width: 0;
}
.info-card {
  background: var(--c-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.info-card h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--c-text-muted);
  margin-bottom: 8px;
}
.info-card p {
  font-size: 0.95rem;
  color: var(--c-text);
}

/* Charts */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(450px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.chart-card {
  background: var(--c-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.chart-card h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 12px;
}
.chart-card canvas {
  width: 100% !important;
  max-height: 300px;
}

/* Chart Takeaway Boxes */
.chart-takeaway {
  margin-top: 12px;
  padding: 10px 14px;
  background: #f0faf4;
  border-left: 3px solid var(--c-kite);
  border-radius: 0 6px 6px 0;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--c-text);
}
.chart-takeaway-value {
  font-weight: 700;
  color: var(--c-kite);
}
.chart-takeaway-text {
  color: #4a5568;
}

/* Hourly Wind Heatmap (spot detail page) */
.heatmap-full {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.7rem;
  text-align: center;
  table-layout: fixed;
}
.heatmap-full th {
  padding: 4px 2px;
  font-weight: 600;
  font-size: 0.75rem;
  color: var(--c-text-muted);
  background: var(--c-card);
}
.heatmap-full td {
  padding: 0;
  height: 18px;
  border: 1.5px solid var(--c-card);
}
.heatmap-full .heatmap-hour {
  font-weight: 600;
  color: var(--c-text-muted);
  background: var(--c-card);
  text-align: right;
  padding-right: 8px;
  white-space: nowrap;
  width: 50px;
  font-size: 0.72rem;
  height: auto;
}
.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 10px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--c-text-muted);
}

/* ─── Compare Page ─── */
.compare-header {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  margin-bottom: 20px;
}
.compare-spot-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--c-card);
  border: 2px solid var(--c-accent);
  border-radius: 20px;
  padding: 6px 16px;
  font-weight: 600;
  font-size: 0.9rem;
}
.compare-spot-tag .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.compare-table {
  width: 100%;
}
.compare-table th:first-child {
  min-width: 160px;
}
.compare-table td.better {
  background: rgba(46, 139, 87, 0.08);
  font-weight: 600;
}

/* ─── Heatmap Ranking ─── */
.heatmap-legend-inline {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-left: 16px;
}
.legend-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--c-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-right: 4px;
  white-space: nowrap;
}
.legend-swatch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 20px;
  font-size: 0.65rem;
  font-weight: 600;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.08);
}

.heatmap-wrapper {
  background: var(--c-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: auto;
  max-height: calc(100vh - 220px);
}

/* Table structure */
.heatmap-table {
  border-collapse: separate;
  border-spacing: 0;
  width: auto;
  font-size: 0.7rem;
}
.heatmap-table th,
.heatmap-table td {
  padding: 0;
  border: none;
}

/* Month header row */
.hm-month {
  background: #1a365d;
  color: #fff;
  text-align: center;
  padding: 0;
  height: 28px;
  line-height: 28px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.3px;
  border-right: 1px solid rgba(255,255,255,0.2);
  cursor: default;
  position: sticky;
  top: 0;
  z-index: 20;
}
.hm-month:last-child { border-right: none; }

/* Corner cell — sticky in both axes */
.hm-corner {
  position: sticky;
  top: 0;
  left: 0;
  z-index: 30;
  background: #f1f5f9;
  min-width: 180px;
  padding: 0 10px;
  text-align: left;
  vertical-align: middle;
  border-bottom: 2px solid var(--c-border);
  border-right: 2px solid var(--c-border);
  cursor: default;
}
.sort-rank-btn {
  cursor: pointer;
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--c-accent);
}
.sort-rank-btn:hover { text-decoration: underline; }

/* Week number header */
.hm-week {
  background: #f1f5f9;
  text-align: center;
  padding: 3px 0;
  font-size: 0.6rem;
  font-weight: 500;
  color: var(--c-text-muted);
  min-width: 30px;
  width: 30px;
  cursor: pointer;
  border-bottom: 2px solid var(--c-border);
  position: sticky;
  top: 28px;
  z-index: 20;
  transition: background 0.12s;
}
.hm-week:hover {
  background: #dbeafe;
  color: #1e40af;
}
.hm-week.hm-week-sel {
  background: #1a365d;
  color: #fff;
  font-weight: 700;
}

/* Spot name column — sticky left */
.hm-spot {
  position: sticky;
  left: 0;
  z-index: 10;
  background: var(--c-card);
  padding: 3px 8px;
  white-space: nowrap;
  min-width: 180px;
  border-bottom: 1px solid #f1f5f9;
  border-right: 2px solid var(--c-border);
  font-size: 0.8rem;
}
.hm-spot-inner {
  display: flex;
  align-items: center;
  gap: 4px;
}
.hm-spot:hover { background: var(--c-hover); }
.hm-rank {
  display: inline-block;
  width: 30px;
  text-align: right;
  flex-shrink: 0;
  font-size: 0.7rem;
  color: var(--c-text-muted);
}
.hm-name {
  color: var(--c-accent);
  text-decoration: none;
  font-weight: 600;
}
.hm-name:hover { text-decoration: underline; }

/* Heatmap data cells */
.hm-cell {
  text-align: center;
  padding: 4px 0;
  min-width: 30px;
  width: 30px;
  font-size: 0.65rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  border-bottom: 1px solid rgba(255,255,255,0.5);
  border-right: 1px solid rgba(255,255,255,0.3);
  cursor: default;
}
.hm-cell.hm-week-sel {
  outline: 2px solid #1a365d;
  outline-offset: -2px;
  font-weight: 700;
}

/* Compare checkbox in heatmap */
.heatmap-table .compare-cb {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  accent-color: var(--c-accent);
  cursor: pointer;
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
  /* Compact header */
  .app-header { padding: 14px 0; margin-bottom: 14px; }
  .app-header h1 { font-size: 1.2rem; }
  .app-header p { font-size: 0.78rem; margin-top: 2px; }
  .app-header .nav { margin-top: 8px; gap: 16px; font-size: 0.82rem; }
  .container { padding: 0 12px; }

  /* Filter bar */
  .filter-bar { flex-direction: column; align-items: stretch; padding: 10px; gap: 8px; }

  /* Legend: wrap to own line, allow all swatches to show */
  .heatmap-legend-inline {
    margin-left: 0;
    margin-top: 4px;
    flex-wrap: wrap;
    justify-content: flex-start;
  }
  .legend-swatch { width: 24px; height: 18px; font-size: 0.6rem; }
  .legend-label { font-size: 0.7rem; }

  /* Heatmap spot column — narrower on mobile */
  .hm-spot { min-width: 120px; padding: 3px 4px; font-size: 0.72rem; }
  .hm-corner { min-width: 120px; padding: 0 6px; }
  .hm-rank { width: 22px; font-size: 0.62rem; }
  .hm-name { font-size: 0.72rem; }
  .heatmap-table .compare-cb { width: 12px; height: 12px; }

  /* Heatmap cells — slightly narrower */
  .hm-cell { min-width: 26px; width: 26px; font-size: 0.58rem; }
  .hm-week { min-width: 26px; width: 26px; font-size: 0.55rem; }
  .hm-month { font-size: 0.62rem; height: 24px; line-height: 24px; }

  /* Heatmap scroll hint */
  .heatmap-wrapper {
    position: relative;
    max-height: calc(100vh - 180px);
  }
  .heatmap-wrapper::after {
    content: '';
    position: absolute;
    top: 0; right: 0; bottom: 0;
    width: 24px;
    background: linear-gradient(to right, transparent, rgba(0,0,0,0.06));
    pointer-events: none;
    z-index: 5;
  }

  /* Charts: single column, no min-width overflow */
  .charts-grid { grid-template-columns: 1fr; }
  .chart-card { padding: 14px; }
  .chart-card canvas { max-height: 250px; }

  /* Info grids single column */
  .info-grid { grid-template-columns: 1fr; }
  .info-grid-3 { grid-template-columns: 1fr; }

  /* Stats grid: 3 columns still works but tighter */
  .stats-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .stat-card { padding: 8px; }
  .stat-card .stat-value { font-size: 1.2rem; }
  .stat-card .stat-label { font-size: 0.68rem; }

  /* Spot header compact */
  .spot-header { padding: 16px; margin-bottom: 14px; }
  .spot-header h1 { font-size: 1.4rem; }
  .spot-header .subtitle { font-size: 0.85rem; }

  /* Tables */
  table { font-size: 0.8rem; }
  th, td { padding: 8px 6px; }

  /* Footer: vertical stack */
  .footer-inner {
    flex-direction: column;
    gap: 10px;
  }
  .footer-link { width: 100%; justify-content: center; }
  .app-footer { margin-top: 24px; padding: 18px 0; }

  /* Compare page */
  .compare-header { gap: 8px; }
  .compare-spot-tag { font-size: 0.8rem; padding: 4px 12px; }

  /* Bottom text */
  .text-sm { font-size: 0.75rem; }
}

/* Extra-small screens (iPhone SE, etc.) */
@media (max-width: 380px) {
  .app-header h1 { font-size: 1.05rem; }
  .app-header p { font-size: 0.7rem; }
  .hm-spot { min-width: 100px; font-size: 0.65rem; }
  .hm-corner { min-width: 100px; }
  .hm-rank { width: 18px; font-size: 0.58rem; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-card .stat-value { font-size: 1rem; }
  .legend-swatch { width: 20px; height: 16px; font-size: 0.55rem; }
}

/* ─── Footer ─── */
.app-footer {
  margin-top: 40px;
  padding: 24px 0;
  border-top: 1px solid var(--c-border);
  background: var(--c-card);
}
.footer-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 24px;
  font-size: 0.88rem;
  color: var(--c-text-muted);
}
.footer-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: 20px;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.85rem;
  transition: all 0.2s;
}
.footer-link-feedback {
  background: #edf2f7;
  color: #2d3748;
}
.footer-link-feedback:hover {
  background: #e2e8f0;
  color: #1a202c;
}
.footer-link-coffee {
  background: #fff3cd;
  color: #856404;
}
.footer-link-coffee:hover {
  background: #ffe69c;
  color: #664d03;
}
.footer-link svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}
.footer-credit {
  font-size: 0.78rem;
  color: var(--c-text-muted);
  opacity: 0.7;
}

/* ─── Utility ─── */
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-2 { margin-bottom: 16px; }
.text-muted { color: var(--c-text-muted); }
.text-sm { font-size: 0.85rem; }
.hidden { display: none; }
