/* ===== CSS Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: #f0f4f8;
  color: #1e293b;
  min-height: 100vh;
  line-height: 1.5;
}
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Header ===== */
.header {
  background: linear-gradient(135deg, #1e40af 0%, #2563eb 100%);
  border-bottom: 1px solid #1e3a8a;
  padding: 1rem 2rem;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 2px 8px rgba(37,99,235,0.2);
}
.header h1 { font-size: 1.4rem; font-weight: 700; color: #fff; letter-spacing: -0.01em; }
.header-subtitle {
  font-size: 0.8rem; color: rgba(255,255,255,0.8); margin-left: 0.75rem;
  padding: 0.15rem 0.5rem; background: rgba(255,255,255,0.15); border-radius: 12px; display: inline-block;
}
.header-right { display: flex; align-items: center; gap: 1rem; }

/* ===== Search ===== */
.search-box { position: relative; }
.search-box input {
  background: rgba(255,255,255,0.9); border: 1px solid rgba(255,255,255,0.3);
  color: #1e293b; padding: 0.5rem 0.75rem 0.5rem 2.25rem; border-radius: 8px;
  font-size: 0.9rem; width: 320px; outline: none; transition: all 0.2s;
}
.search-box input:focus { background: #fff; border-color: #fff; box-shadow: 0 0 0 3px rgba(255,255,255,0.3); }
.search-box input::placeholder { color: #64748b; }
.search-icon { position: absolute; left: 0.65rem; top: 50%; transform: translateY(-50%); color: #64748b; pointer-events: none; }
.search-results {
  position: absolute; top: 100%; left: 0; right: 0; background: #fff;
  border: 1px solid #e2e8f0; border-radius: 8px; margin-top: 4px;
  max-height: 320px; overflow-y: auto; box-shadow: 0 8px 24px rgba(0,0,0,0.12); z-index: 200;
}
.search-results.hidden { display: none; }
.search-result-item {
  padding: 0.6rem 0.85rem; cursor: pointer; display: flex; align-items: center;
  gap: 0.6rem; border-bottom: 1px solid #f1f5f9; transition: background 0.15s;
  text-decoration: none; color: inherit;
}
.search-result-item:hover { background: #eff6ff; text-decoration: none; }
.search-result-item .team-num { font-weight: 700; color: #2563eb; min-width: 60px; }
.search-result-item .team-name { color: #64748b; font-size: 0.85rem; }

/* ===== Nav ===== */
.nav-bar {
  background: #fff; border-bottom: 1px solid #e2e8f0;
  padding: 0 2rem; display: flex; gap: 0; overflow-x: auto;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.nav-btn {
  background: none; border: none; color: #64748b; padding: 0.75rem 1.25rem;
  font-size: 0.875rem; font-weight: 500; cursor: pointer;
  border-bottom: 2px solid transparent; display: flex; align-items: center;
  gap: 0.4rem; transition: color 0.2s, border-color 0.2s; white-space: nowrap;
}
.nav-btn:hover { color: #1e293b; }
.nav-btn.active { color: #2563eb; border-bottom-color: #2563eb; }

/* ===== Main Content ===== */
.main-content { padding: 1.5rem 2rem 3rem; max-width: 1440px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

/* ===== Stats Grid ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 12px; padding: 1.25rem;
  transition: transform 0.2s, box-shadow 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.08); }
.stat-card .stat-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: #64748b; margin-bottom: 0.35rem; }
.stat-card .stat-value { font-size: 1.75rem; font-weight: 700; color: #1e293b; }
.stat-card .stat-detail { font-size: 0.8rem; color: #94a3b8; margin-top: 0.25rem; }
.stat-card.highlight { border-left: 3px solid #2563eb; }
.stat-card.green { border-left: 3px solid #16a34a; }
.stat-card.yellow { border-left: 3px solid #ca8a04; }
.stat-card.red { border-left: 3px solid #dc2626; }

/* ===== Sections ===== */
.section { margin-bottom: 2rem; }
.section-title {
  font-size: 1.1rem; font-weight: 600; color: #1e293b;
  margin-bottom: 1rem; padding-bottom: 0.5rem; border-bottom: 1px solid #e2e8f0;
}

/* ===== Top Performers ===== */
.top-performers-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; }
.performer-card {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 12px; padding: 1.25rem;
  cursor: pointer; transition: transform 0.2s, box-shadow 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.performer-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(37,99,235,0.12); border-color: #93c5fd; }
.performer-card .card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 0.75rem; }
.performer-card .team-info h3 { font-size: 1rem; color: #1e293b; }
.performer-card .team-info .team-num-label { font-size: 0.85rem; color: #2563eb; font-weight: 600; }
.performer-card .card-badge { padding: 0.2rem 0.6rem; border-radius: 12px; font-size: 0.7rem; font-weight: 600; text-transform: uppercase; }
.performer-card .card-stats { display: flex; gap: 1rem; flex-wrap: wrap; }
.performer-card .mini-stat .label { font-size: 0.7rem; color: #94a3b8; text-transform: uppercase; }
.performer-card .mini-stat .value { font-size: 0.95rem; font-weight: 600; color: #1e293b; }

/* ===== Tables ===== */
.table-container { overflow-x: auto; border-radius: 12px; border: 1px solid #e2e8f0; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.data-table thead { background: #f8fafc; }
.data-table th {
  padding: 0.75rem 1rem; text-align: left; font-weight: 600; color: #475569;
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em;
  border-bottom: 2px solid #e2e8f0; cursor: pointer; user-select: none; white-space: nowrap;
}
.data-table th:hover { color: #1e293b; background: #f1f5f9; }
.data-table td { padding: 0.65rem 1rem; border-bottom: 1px solid #f1f5f9; white-space: nowrap; }
.data-table tbody tr { transition: background 0.15s; cursor: pointer; }
.data-table tbody tr:hover { background: #eff6ff; }
.data-table .team-link { color: #2563eb; font-weight: 600; }
.data-table .team-link:hover { text-decoration: underline; }

/* ===== Badges ===== */
.badge {
  display: inline-block; padding: 0.15rem 0.5rem; border-radius: 12px;
  font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em;
}
.badge-strong { background: #dcfce7; color: #15803d; }
.badge-moderate { background: #fef9c3; color: #a16207; }
.badge-weak { background: #fee2e2; color: #dc2626; }
.badge-none { background: #f1f5f9; color: #64748b; }
.badge-improved { background: #dcfce7; color: #15803d; }
.badge-declined { background: #fee2e2; color: #dc2626; }
.badge-stable { background: #f1f5f9; color: #64748b; }
.badge-new { background: #dbeafe; color: #2563eb; }
.badge-warning { background: #fef9c3; color: #a16207; }
.badge-danger { background: #fee2e2; color: #dc2626; }
.badge-carried { background: #fef9c3; color: #a16207; }
.badge-independent { background: #dcfce7; color: #15803d; }
.badge-redflag {
  background: #dc2626; color: #fff; font-size: 0.7rem; font-weight: 700;
  padding: 0.2rem 0.6rem; border-radius: 6px; text-transform: uppercase;
  animation: pulse-red 2s ease-in-out infinite;
}
@keyframes pulse-red { 0%,100% { box-shadow: 0 0 0 0 rgba(220,38,38,0.4); } 50% { box-shadow: 0 0 0 4px rgba(220,38,38,0); } }
.badge-info { background: #dbeafe; color: #1d4ed8; }

/* ===== Red Flag Banner ===== */
.redflag-banner {
  background: linear-gradient(135deg, #fef2f2, #fee2e2);
  border: 2px solid #fca5a5; border-radius: 12px; padding: 1rem 1.25rem;
  margin-bottom: 1.5rem; display: flex; align-items: flex-start; gap: 0.75rem;
}
.redflag-banner .redflag-icon { font-size: 1.5rem; flex-shrink: 0; }
.redflag-banner .redflag-text h3 { color: #dc2626; font-size: 1rem; font-weight: 700; margin-bottom: 0.25rem; }
.redflag-banner .redflag-text p { color: #7f1d1d; font-size: 0.85rem; line-height: 1.6; }

/* ===== View Header ===== */
.view-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.25rem; flex-wrap: wrap; gap: 0.75rem; }
.view-header h2 { font-size: 1.2rem; color: #1e293b; }
.filter-bar { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.filter-bar select, .filter-bar input {
  background: #fff; border: 1px solid #e2e8f0; color: #1e293b;
  padding: 0.4rem 0.75rem; border-radius: 8px; font-size: 0.85rem; outline: none;
}
.filter-bar select:focus, .filter-bar input:focus { border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }

/* ===== Competition Tabs ===== */
.comp-tabs { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.comp-tab {
  padding: 0.5rem 1.25rem; background: #fff; border: 1px solid #e2e8f0; border-radius: 8px;
  color: #64748b; cursor: pointer; font-size: 0.875rem; font-weight: 500; transition: all 0.2s;
}
.comp-tab:hover { border-color: #93c5fd; color: #1e293b; }
.comp-tab.active { background: #2563eb; border-color: #2563eb; color: #fff; }

/* ===== Back Button ===== */
.back-btn {
  display: inline-flex; align-items: center; gap: 0.35rem; background: #fff;
  border: 1px solid #e2e8f0; color: #64748b; padding: 0.5rem 1rem; border-radius: 8px;
  cursor: pointer; font-size: 0.85rem; margin-bottom: 1.25rem; transition: all 0.2s;
}
.back-btn:hover { color: #1e293b; border-color: #93c5fd; background: #eff6ff; }

/* ===== Team Detail ===== */
.team-detail-header {
  background: linear-gradient(135deg, #1e40af, #2563eb); border-radius: 16px;
  padding: 2rem; margin-bottom: 1.5rem; color: #fff;
  box-shadow: 0 4px 12px rgba(37,99,235,0.25);
}
.team-detail-header .team-title { display: flex; align-items: center; gap: 1rem; margin-bottom: 0.75rem; flex-wrap: wrap; }
.team-detail-header .team-number { font-size: 2rem; font-weight: 800; color: #fff; }
.team-detail-header .team-name-big { font-size: 1.5rem; font-weight: 600; color: rgba(255,255,255,0.9); }
.team-detail-header .badges { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.team-detail-header .badges .badge { background: rgba(255,255,255,0.2); color: #fff; }
.team-detail-header .badges .badge-redflag { background: #fff; color: #dc2626; animation: none; font-size: 0.75rem; }
.team-detail-header .quick-stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 0.75rem; margin-top: 1rem; background: rgba(255,255,255,0.1);
  border-radius: 12px; padding: 1rem;
}
.quick-stat { text-align: center; }
.quick-stat .qs-value { font-size: 1.4rem; font-weight: 700; color: #fff; }
.quick-stat .qs-label { font-size: 0.65rem; color: rgba(255,255,255,0.7); text-transform: uppercase; letter-spacing: 0.05em; }
.team-detail-header .export-btn {
  background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.3);
  color: #fff; padding: 0.5rem 1.25rem; border-radius: 8px; cursor: pointer;
  font-size: 0.85rem; font-weight: 500; display: inline-flex; align-items: center;
  gap: 0.4rem; transition: all 0.2s; margin-top: 1rem;
}
.team-detail-header .export-btn:hover { background: rgba(255,255,255,0.25); }

/* ===== Detail Sections ===== */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-bottom: 1.5rem; }
.detail-card {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 12px; padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.detail-card.full-width { grid-column: 1 / -1; }
.detail-card h3 {
  font-size: 0.95rem; font-weight: 600; color: #1e293b;
  margin-bottom: 1rem; padding-bottom: 0.5rem; border-bottom: 1px solid #f1f5f9;
}
.detail-card .chart-container { position: relative; height: 420px; }
.detail-card .chart-container canvas { max-height: 100%; }

/* ===== Scouting Report ===== */
.scouting-report {
  background: linear-gradient(135deg, #f8fafc, #eff6ff);
  border: 1px solid #bfdbfe; border-radius: 12px;
  padding: 1.5rem; margin-bottom: 1.5rem; box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.scouting-report h3 { font-size: 1.05rem; font-weight: 700; color: #1e293b; margin-bottom: 1rem; display: flex; align-items: center; gap: 0.5rem; }
.scouting-section { margin-bottom: 1rem; }
.scouting-section h4 { font-size: 0.85rem; font-weight: 600; color: #475569; text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 0.35rem; }
.scouting-section p { font-size: 0.875rem; color: #334155; line-height: 1.7; }
.scouting-section ul { list-style: none; padding: 0; }
.scouting-section li { padding: 0.25rem 0; font-size: 0.85rem; color: #334155; position: relative; padding-left: 1.25rem; }
.scouting-section li::before { content: ''; position: absolute; left: 0; top: 0.55rem; width: 8px; height: 8px; border-radius: 50%; }
.scouting-section.strengths li::before { background: #16a34a; }
.scouting-section.weaknesses li::before { background: #dc2626; }
.scouting-section.observations li::before { background: #2563eb; }
.scouting-section.recommendations li::before { background: #ca8a04; }

/* ===== Metric Bars ===== */
.metric-bar-container { display: flex; align-items: center; gap: 0.5rem; margin: 0.2rem 0; }
.metric-bar { width: 100px; height: 8px; background: #e2e8f0; border-radius: 4px; overflow: hidden; display: inline-block; vertical-align: middle; }
.metric-bar-fill { height: 100%; border-radius: 4px; transition: width 0.3s; }

/* ===== Insights Page ===== */
.insight-section { margin-bottom: 2rem; }
.insight-section > h2 {
  font-size: 1.1rem; color: #1e293b; margin-bottom: 1rem;
  display: flex; align-items: center; gap: 0.5rem;
}
.insight-section > p { color: #64748b; margin-bottom: 1rem; font-size: 0.85rem; }
.insight-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 1rem; }
.insight-card {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 12px; padding: 1.25rem;
  cursor: pointer; transition: transform 0.2s, box-shadow 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.insight-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(37,99,235,0.12); border-color: #93c5fd; }
.insight-card .insight-title { font-weight: 600; color: #1e293b; margin-bottom: 0.35rem; display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.insight-card .insight-body { font-size: 0.85rem; color: #64748b; line-height: 1.6; }
.insight-card .insight-body strong { color: #1e293b; }
.insight-card.redflag-card { border-color: #fca5a5; background: #fef2f2; }
.insight-card.redflag-card:hover { border-color: #f87171; box-shadow: 0 4px 12px rgba(220,38,38,0.12); }

/* ===== Match Row Colors ===== */
.match-win { color: #16a34a; font-weight: 600; }
.match-loss { color: #dc2626; font-weight: 600; }
.match-tie { color: #ca8a04; font-weight: 600; }

/* ===== Violation Row ===== */
.violation-row td { color: #92400e !important; }

/* ===== Carry Meter ===== */
.carry-meter {
  width: 80px; height: 8px; background: #e2e8f0; border-radius: 4px;
  overflow: hidden; display: inline-block; vertical-align: middle; margin-left: 0.4rem;
}
.carry-meter-fill { height: 100%; border-radius: 4px; transition: width 0.3s; }

/* ===== Trend Arrow ===== */
.trend-up { color: #16a34a; font-weight: 600; }
.trend-down { color: #dc2626; font-weight: 600; }
.trend-flat { color: #64748b; }

/* ===== Reliability Gauge ===== */
.reliability-gauge { display: flex; align-items: center; gap: 0.5rem; }
.gauge-bar { width: 120px; height: 10px; background: #e2e8f0; border-radius: 5px; overflow: hidden; }
.gauge-fill { height: 100%; border-radius: 5px; }
.gauge-label { font-size: 0.8rem; font-weight: 600; }

/* ===== Footer ===== */
.site-footer {
  text-align: center; padding: 1.5rem 2rem; color: #94a3b8;
  font-size: 0.8rem; border-top: 1px solid #e2e8f0; margin-top: 2rem;
  background: #fff;
}
.site-footer strong { color: #64748b; }

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .header { flex-direction: column; gap: 0.75rem; padding: 1rem; }
  .search-box input { width: 100%; }
  .main-content { padding: 1rem; }
  .detail-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .stats-grid { grid-template-columns: 1fr; }
  .nav-bar { padding: 0 0.5rem; }
  .nav-btn { padding: 0.6rem 0.75rem; font-size: 0.8rem; }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #f1f5f9; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ===== Animations ===== */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.view.active { animation: fadeIn 0.25s ease-out; }

/* ===== Tooltip ===== */
.tooltip-wrapper { position: relative; display: inline-block; }
.tooltip-wrapper .tooltip-text {
  visibility: hidden; opacity: 0; background: #1e293b; color: #fff;
  font-size: 0.75rem; padding: 0.4rem 0.6rem; border-radius: 6px;
  position: absolute; bottom: 125%; left: 50%; transform: translateX(-50%);
  white-space: nowrap; transition: opacity 0.2s; z-index: 50; pointer-events: none;
}
.tooltip-wrapper:hover .tooltip-text { visibility: visible; opacity: 1; }
