/* =========================================
   GreenFlip Sector Intelligence v2
   ========================================= */

:root {
  --green-base:    #32544A;
  --green-bright:  #1ED65E;
  --green-dark:    #1D4338;
  --navy:          #21334B;
  --gold:          #CFB254;
  --coral:         #FF715B;

  --bg:    #F5F7F5;
  --bg2:   #EDF0EC;
  --bg3:   #E2E8E3;
  --card:  #FFFFFF;
  --card2: #F8FAF8;

  --text:  #21334B;
  --text2: #32544A;
  --text3: #7A9088;

  --border:  rgba(50,84,74,0.10);
  --border2: rgba(50,84,74,0.18);

  --accent:       #1ED65E;
  --accent-light: rgba(30,214,94,0.10);
  --amber:        #CFB254;
  --amber-light:  rgba(207,178,84,0.12);
  --red:          #c8192b;
  --red-light:    rgba(200,25,43,0.08);

  --mono:    'DM Mono', monospace;
  --sans:    'Lexend', sans-serif;
  --radius:  14px;
  --radius-sm: 9px;
  --shadow:    0 2px 12px rgba(33,51,75,0.07);
  --shadow-md: 0 6px 28px rgba(33,51,75,0.12);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-weight: 400;
  min-height: 100vh;
  background-image:
    radial-gradient(ellipse 60% 40% at 90% 0%, rgba(30,214,94,0.06), transparent),
    radial-gradient(ellipse 40% 30% at 0% 100%, rgba(50,84,74,0.04), transparent);
}

a { color: var(--green-base); text-decoration: none; }
a:hover { color: var(--green-dark); text-decoration: underline; }
.hidden { display: none !important; }

/* ── HEADER ── */
.site-header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(245,247,245,0.96);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border2);
  box-shadow: var(--shadow);
}

.header-inner {
  display: flex; align-items: center; gap: 24px;
  padding: 14px 32px;
}

/* ── LOGO ── */
.brand { display: flex; align-items: baseline; gap: 10px; flex-shrink: 0; }

.brand-logo {
  font-family: var(--sans); font-weight: 700; font-size: 22px;
  letter-spacing: -0.02em; line-height: 1;
}
.logo-green { color: var(--green-base); }
.logo-n     { color: var(--green-bright); font-style: italic; }
.logo-flip  { color: var(--green-base); }

.brand-tagline {
  font-family: var(--mono); font-size: 10px; color: var(--text3);
  text-transform: uppercase; letter-spacing: 0.08em;
}

/* ── SEARCH ── */
.search-wrap {
  position: relative; flex: 1; max-width: 520px;
}
.search-icon {
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; color: var(--text3); pointer-events: none;
}
#globalSearch {
  width: 100%; background: var(--card);
  border: 1.5px solid var(--border2); border-radius: var(--radius-sm);
  color: var(--text); font-family: var(--sans); font-size: 14px;
  padding: 10px 14px 10px 40px; outline: none; box-shadow: var(--shadow);
  transition: border-color 0.2s;
}
#globalSearch:focus { border-color: var(--accent); }
#globalSearch::placeholder { color: var(--text3); }

/* ── SECTOR BANNER ── */
.sector-banner {
  display: flex; align-items: center; gap: 12px;
  padding: 7px 32px; border-top: 1px solid var(--border);
  background: var(--green-base);
}
.sector-stat {
  font-family: var(--mono); font-size: 11px; color: rgba(255,255,255,0.75);
  letter-spacing: 0.04em;
}
.sector-stat strong { color: var(--green-bright); }
.sector-divider { color: rgba(255,255,255,0.3); font-size: 14px; }

/* ── SEARCH DROPDOWN ── */
.search-dropdown {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--card); border: 1.5px solid var(--border2);
  border-radius: var(--radius); box-shadow: var(--shadow-md);
  max-height: 320px; overflow-y: auto; z-index: 200;
}
.search-result-item {
  padding: 11px 16px; cursor: pointer;
  border-bottom: 1px solid var(--border); transition: background 0.15s;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--accent-light); }
.result-name { font-size: 13px; color: var(--navy); font-weight: 500; }
.result-reg  { font-family: var(--mono); font-size: 11px; color: var(--text3); margin-top: 2px; }

/* ── MAIN ── */
#main-content { max-width: 1280px; margin: 0 auto; padding: 32px 32px; }

.view { display: none; }
.view.active { display: block; }

/* ── LEADERBOARD ── */
.leaderboard-header {
  display: flex; justify-content: space-between; align-items: flex-end;
  margin-bottom: 20px; flex-wrap: wrap; gap: 16px;
}
.leaderboard-title {
  font-family: var(--sans); font-weight: 800; font-size: 28px;
  letter-spacing: -0.02em; color: var(--navy);
}
.year-tag {
  font-family: var(--mono); font-size: 14px; font-weight: 400;
  color: var(--green-base); background: var(--accent-light);
  border: 1px solid rgba(30,214,94,0.3);
  border-radius: 6px; padding: 2px 8px; vertical-align: middle; margin-left: 4px;
}
.leaderboard-sub {
  font-family: var(--mono); font-size: 12px; color: var(--text3);
  margin-top: 5px; letter-spacing: 0.03em;
}

.sort-controls { display: flex; align-items: center; gap: 8px; }
.sort-label { font-family: var(--mono); font-size: 11px; color: var(--text3); text-transform: uppercase; letter-spacing: 0.06em; }
.sort-btn {
  font-family: var(--mono); font-size: 11px; color: var(--text3);
  background: var(--card); border: 1.5px solid var(--border2);
  border-radius: var(--radius-sm); padding: 6px 12px; cursor: pointer;
  text-transform: uppercase; letter-spacing: 0.05em; transition: all 0.2s;
}
.sort-btn.active { background: var(--green-base); color: #fff; border-color: var(--green-base); }
.sort-btn:not(.active):hover { border-color: var(--green-base); color: var(--green-base); }

/* ── DATA TABLE ── */
.table-wrap {
  border-radius: var(--radius); border: 1.5px solid var(--border2);
  overflow: hidden; box-shadow: var(--shadow); overflow-x: auto;
}
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--card); }
.data-table thead th {
  background: var(--green-base); padding: 13px 16px; text-align: left;
  font-family: var(--mono); font-size: 10px; color: rgba(255,255,255,0.8);
  text-transform: uppercase; letter-spacing: 0.08em; white-space: nowrap;
}
.data-table thead th.col-rank    { width: 60px; text-align: center; }
.data-table thead th.col-epc25   { width: 130px; }
.data-table thead th.col-epc24   { width: 130px; }
.data-table thead th.col-change  { width: 120px; }
.data-table thead th.col-homes   { width: 150px; }

.leaderboard-row {
  border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.15s;
}
.leaderboard-row:last-child { border-bottom: none; }
.leaderboard-row:hover { background: var(--accent-light); }
.leaderboard-row td { padding: 12px 16px; vertical-align: middle; }

.col-rank { text-align: center; }
.rank-num {
  font-family: var(--mono); font-size: 13px; color: var(--text3);
  display: inline-block; width: 32px; text-align: center;
}
.rank-num.rank-top { color: var(--green-base); font-weight: 500; }
.rank-num.rank-mid { color: var(--text2); }

.prov-name { font-weight: 500; color: var(--navy); font-size: 13px; }
.prov-reg  { font-family: var(--mono); font-size: 11px; color: var(--text3); margin-top: 2px; }

.epc-pct    { font-family: var(--mono); font-weight: 500; color: var(--green-base); font-size: 14px; }
.epc-pct-24 { font-family: var(--mono); color: var(--text3); font-size: 13px; }

.change-up      { font-family: var(--mono); font-size: 12px; color: #0a9b4b; font-weight: 500; }
.change-down    { font-family: var(--mono); font-size: 12px; color: var(--red); font-weight: 500; }
.change-neutral { font-family: var(--mono); font-size: 12px; color: var(--text3); }

/* ── BACK LINK ── */
.back-link { margin-bottom: 20px; }
.back-link a {
  font-family: var(--mono); font-size: 12px; color: var(--text3);
  text-transform: uppercase; letter-spacing: 0.06em; text-decoration: none;
}
.back-link a:hover { color: var(--green-base); }

/* ── PROFILE HEADER ── */
.profile-header { margin-bottom: 24px; }
.profile-name {
  font-family: var(--sans); font-weight: 800;
  font-size: clamp(22px, 4vw, 36px); letter-spacing: -0.02em;
  color: var(--navy); margin-bottom: 12px;
}
.profile-meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.badge {
  font-family: var(--mono); font-size: 10px; padding: 4px 11px;
  border-radius: 20px; text-transform: uppercase; letter-spacing: 0.07em; font-weight: 500;
}
.badge-reg   { background: var(--bg3); color: var(--text2); border: 1px solid var(--border2); }
.badge-rank  { background: var(--green-base); color: #fff; }
.badge-grade { background: var(--accent-light); color: var(--green-base); border: 1px solid rgba(30,214,94,0.3); }

/* ── KPI STRIP ── */
.kpi-strip {
  display: grid; grid-template-columns: repeat(6,1fr); gap: 12px; margin-bottom: 20px;
}
.kpi-card {
  background: var(--card); border: 1.5px solid var(--border);
  border-radius: var(--radius); padding: 18px 16px; box-shadow: var(--shadow);
  position: relative; overflow: hidden; transition: transform 0.2s, box-shadow 0.2s;
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.kpi-card::after {
  content:''; position:absolute; bottom:0; left:0; right:0; height:3px;
  background: linear-gradient(90deg, var(--accent), transparent);
  opacity:0; transition: opacity 0.3s;
}
.kpi-card:hover::after { opacity:1; }
.kpi-label {
  font-family: var(--mono); font-size: 10px; color: var(--text3);
  text-transform: uppercase; letter-spacing: 0.09em; margin-bottom: 10px;
}
.kpi-value {
  font-family: var(--sans); font-weight: 700; font-size: 24px;
  letter-spacing: -0.02em; line-height: 1.1; color: var(--navy);
}
.kpi-value.accent { color: var(--green-base); }
.kpi-value.warn   { color: var(--amber); }
.kpi-value.muted  { color: var(--text3); }
.kpi-sub { font-family: var(--mono); font-size: 10px; color: var(--text3); margin-top: 6px; }

/* ── SECTION GRID ── */
.section-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
}
.module-card {
  background: var(--card); border: 1.5px solid var(--border);
  border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow);
}
.module-card.span-2 { grid-column: 1 / -1; }

.module-title {
  font-family: var(--mono); font-size: 10px; color: var(--text3);
  text-transform: uppercase; letter-spacing: 0.1em;
  padding-bottom: 14px; margin-bottom: 18px; border-bottom: 1px solid var(--border);
}

/* ── EPC FULL BAR ── */
.epc-full-bar {
  display: flex; height: 36px; border-radius: 10px; overflow: hidden; gap: 2px;
  margin-bottom: 20px;
}
.epc-seg {
  position: relative; display: flex; align-items: center; justify-content: center;
  transition: flex 0.5s ease; min-width: 2px;
}
.epc-seg-label {
  font-family: var(--mono); font-size: 11px; font-weight: 500; color: rgba(255,255,255,0.9);
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
  pointer-events: none;
}

/* ── EPC LEGEND GRID ── */
.epc-legend-grid {
  display: grid; grid-template-columns: repeat(3,1fr); gap: 8px 20px;
}
.epc-legend-row {
  display: grid; grid-template-columns: 12px 1fr auto auto; gap: 8px;
  align-items: center; padding: 6px 0; border-bottom: 1px solid var(--border);
}
.epc-legend-row:last-child { border-bottom: none; }
.epc-legend-row.muted-row .epc-legend-label { color: var(--text3); }
.epc-legend-dot  { width:12px; height:12px; border-radius:3px; flex-shrink:0; }
.epc-legend-label { font-family:var(--mono); font-size:11px; color:var(--text2); }
.epc-legend-count { font-family:var(--mono); font-size:11px; color:var(--navy); text-align:right; }
.epc-legend-pct   { font-family:var(--mono); font-size:11px; color:var(--text3); text-align:right; min-width:40px; }

/* ── YoY BARS ── */
.comparison-bar-section { margin-top: 20px; border-top: 1px solid var(--border); padding-top: 20px; }
.yoy-row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.yoy-label { font-family: var(--mono); font-size: 11px; color: var(--text3); width: 36px; text-align: right; }
.yoy-bar-track { flex: 1; height: 14px; background: var(--bg3); border-radius: 7px; overflow: hidden; }
.yoy-bar { height: 100%; border-radius: 7px; transition: width 0.8s ease; }
.yoy-25 { background: linear-gradient(90deg, var(--green-bright), var(--green-base)); }
.yoy-24 { background: linear-gradient(90deg, #94a3b8, #64748b); }
.yoy-val { font-family: var(--mono); font-size: 12px; color: var(--navy); font-weight: 500; width: 44px; }

/* ── REGULATORY RATINGS ── */
.ratings-grid { display: flex; gap: 16px; justify-content: space-around; padding: 8px 0; }
.rating-item  { text-align: center; }
.rating-label { font-family: var(--mono); font-size: 10px; color: var(--text3); text-transform: uppercase; letter-spacing: 0.07em; margin-bottom: 10px; }
.rating-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 52px; height: 52px; border-radius: 12px;
  font-family: var(--sans); font-weight: 700; font-size: 20px; letter-spacing: -0.01em;
}
.grade-1    { background: var(--accent-light); color: var(--green-base); border: 2px solid rgba(30,214,94,0.4); }
.grade-2    { background: var(--amber-light);  color: var(--amber);      border: 2px solid rgba(207,178,84,0.4); }
.grade-3    { background: var(--red-light);    color: var(--red);        border: 2px solid rgba(200,25,43,0.3); }
.grade-4    { background: var(--red-light);    color: var(--red);        border: 2px solid rgba(200,25,43,0.3); }
.grade-none { background: var(--bg3); color: var(--text3); border: 2px solid var(--border2); }

/* ── FINANCIAL TABLE ── */
.fin-table { width:100%; border-collapse:collapse; }
.fin-table tr { border-bottom: 1px solid var(--border); }
.fin-table tr:last-child { border-bottom: none; }
.fin-table td { padding: 11px 0; font-size: 13px; }
.fin-table td:first-child { color: var(--text3); font-family: var(--mono); font-size: 11px; }
.fin-table td:last-child  { text-align: right; font-family: var(--mono); color: var(--navy); font-weight: 500; }
.fin-table td.neg { color: var(--red); }

/* ── MAINTENANCE GRID ── */
.maintenance-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 16px; }
.maint-item { background: var(--bg2); border-radius: var(--radius-sm); padding: 16px; }
.maint-label { font-family: var(--mono); font-size: 10px; color: var(--text3); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 8px; }
.maint-value { font-family: var(--sans); font-weight: 700; font-size: 20px; color: var(--navy); letter-spacing: -0.01em; }

/* ── NOTICE ── */
.notice-box {
  background: var(--amber-light); border: 1px solid rgba(207,178,84,0.3);
  border-radius: var(--radius-sm); padding: 16px; color: var(--amber);
  font-family: var(--mono); font-size: 13px;
}

/* ── LOADING ── */
.loading-overlay {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center; z-index: 999;
}
.loading-overlay.hidden { display: none; }
.loader-inner { text-align: center; }
.loader-ring {
  width: 48px; height: 48px; border: 3px solid var(--border2);
  border-top-color: var(--green-bright); border-radius: 50%;
  animation: spin 0.8s linear infinite; margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-inner p { font-family: var(--mono); font-size: 12px; color: var(--text3); }

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 3px; }

/* ── RESPONSIVE ── */
@media (max-width:1100px) { .kpi-strip { grid-template-columns: repeat(3,1fr); } }
@media (max-width:800px)  {
  .section-grid { grid-template-columns: 1fr; }
  .module-card.span-2 { grid-column: 1; }
  .kpi-strip { grid-template-columns: repeat(2,1fr); }
  .epc-legend-grid { grid-template-columns: repeat(2,1fr); }
  .maintenance-grid { grid-template-columns: 1fr; }
  .header-inner { padding: 12px 16px; }
  .sector-banner { padding: 6px 16px; }
  #main-content { padding: 20px 16px; }
  .leaderboard-header { flex-direction: column; align-items: flex-start; }
}
@media (max-width:500px) {
  .kpi-strip { grid-template-columns: 1fr 1fr; }
  .ratings-grid { gap: 8px; }
}

/* ── DATA CAVEAT ── */
.data-caveat {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text3);
  line-height: 1.7;
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
