"""Analyst overlay for Mining Cost Standard v1.0. Every entry cites a filing source. Missing (ticker,period) keys fall back to
defaults: DA method REV (consolidated D&A x revenue share), no non-recurring/non-cash SG&A adjustments, no accelerated D&A."""

TIER = {"RIOT":1,"MARA":1,"CLSK":1,"HIVE":1,"IREN":1,"CIFR":1,"CORZ":1,"WULF":1,"BTDR":1,
        "ABTC":2,"BTBT":2,"CANG":2,"KEEL":3,"HUT":3,"FUFU":3}
TIER_NOTE = {
 "RIOT":"Owner-operator; three reportable segments; BTC segment cost of revenue incl. power, site compensation, insurance, taxes, R&M.",
 "MARA":"Owner-operator + third-party hosting (hosted BTC ≈ half of production); single segment; direct cost = purchased energy + O&M + third-party hosting.",
 "CLSK":"Owner-operator pure-play; cost of revenues = energy & utilities only (site payroll sits in 'Payroll expenses').",
 "HIVE":"Owner-operator (Paraguay, Canada, Sweden) + BUZZ HPC; direct cost = electricity + O&M fees; SBC is a separate P&L line.",
 "IREN":"Owner-operator; BTC mining being decommissioned for AI Cloud; BTC cost of revenue = electricity + employee benefits + other; RECs/property tax/insurance in SG&A.",
 "CIFR":"Owner-operator (Odessa); single segment through Q2 2026; HPC-project debt allocated to BTC by revenue share (100%).",
 "CORZ":"Owner-operator self-mining (minority of revenue); segment cost of revenue INCLUDES depreciation — stripped with segment D&A.",
 "WULF":"Owner-operator; mining segment cost of revenue = electricity only, NET of demand-response proceeds (grossed up); site opex outside CoR.",
 "BTDR":"Owner-operator + co-mining; 6-K filer; segment cost of revenue includes D&A+SBC — stripped; production and cost include co-mining.",
 "CANG":"Fleet hosted at third-party sites under all-in hosting fees (electricity embedded); 6-K/20-F filer; mining-segment energy & hosting cost = company-reported average cash cost per BTC × BTC (cross-checked to the 20-F 'energy and hosting costs' line).",
 "FUFU":"Cloud-mining platform with self-mining on owned + leased hashrate; 6-K/20-F filer; cost of revenues is disclosed by counterparty (Bitmain / third parties / D&A), not by stream — self-mining direct cost not separable.",
 "ABTC":"100% hosted at Hut 8 under related-party MCSA/MMSA (fixed fee + variable pass-through). Cost base embeds host margin.",
 "BTBT":"Hosted miners, winding down; immaterial volume; shown for completeness.",
 "KEEL":"Consolidated cost of revenues covers mining + power plants + electrical services; mining-only cost not disclosed.",
 "HUT":"Consolidates ABTC; 'Compute' cost of revenue mixes ASIC Compute, Traditional Cloud and AI Cloud — ASIC piece not disclosed.",
}
SCOPE = {
 "RIOT":("E+S","Energy + site opex (compensation, insurance, property tax/rent, R&M); gross of curtailment credits"),
 "MARA":("E+S+H","Purchased energy (owned) + O&M + third-party hosting & other energy"),
 "CLSK":("E","Energy & utilities only; site labor outside cost of revenues"),
 "HIVE":("E+S","Electricity + O&M fees to suppliers/service providers"),
 "IREN":("E+S*","Electricity + employee benefits + other direct; RECs, property taxes, insurance booked in SG&A"),
 "CIFR":("E+S","'Primarily electricity' + other facilities costs; gross of power sales"),
 "CORZ":("E+S","Power fees + employee compensation + facility operations + other (segment D&A stripped)"),
 "WULF":("E","Electricity only, grossed up for demand-response proceeds; site opex excluded from CoR"),
 "BTDR":("E+S","Electricity + other costs (self-mining + co-mining), D&A/SBC stripped"),
 "CANG":("H","Third-party all-in hosting fees (electricity embedded); non-mining cost of revenue (vehicles) excluded"),
 "FUFU":("N/S","Not separable (cost of revenues by counterparty: Bitmain hosting/hashrate, third parties, D&A; self-mining vs cloud-mining not split)"),
 "ABTC":("H-RP","Related-party hosting fee (fixed + variable pass-through) to Hut 8"),
 "BTBT":("H","Third-party hosting: electricity + profit-sharing + other"),
 "KEEL":("N/S","Not separable (mining + power generation + electrical services)"),
 "HUT":("N/D","Not disclosed at ASIC-compute level"),
}
STATUS = {"RIOT":"Active","MARA":"Active","CLSK":"Active","HIVE":"Active","IREN":"Active — decommissioning (substantially complete by 31 Dec 2026; 402 BTC in Q3 2026, 12% of revenue)","CIFR":"Active — Odessa only (two segments from Q3 2026: Bitcoin Mining / HPC Leasing)",
 "CORZ":"Active — minority (mining fleet held for sale; hosted mining ends 31-Dec-26)","WULF":"Active — minority","BTDR":"Active","CANG":"Active (hosted)","FUFU":"Active — not separable","ABTC":"Active (hosted, RP)","BTBT":"Winding down",
 "KEEL":"Winding down (US mining ceased 29-Jun-26; Québec only; BTC treasury sold Q3 2026)","HUT":"Via ABTC"}

# Energy-layer component keys per ticker (names as used in extract components); BTC base override for MARA (owned-site BTC)
ENERGY_KEYS = {
 "RIOT":["power"], "MARA":["purchased_energy"], "CLSK":["energy_owned_facilities"], "HIVE":["electricity"], "IREN":["electricity"],
 "CORZ":["power_fees"], "WULF":["energy_net_of_DR","DR_proceeds_added_back"], "BTDR":["self_mining_electricity","co_mining_electricity"],
 "KEEL":["energy_expenses_net_of_RECs_WTCs"], "BTBT":["electricity"], "CIFR":[], "ABTC":[], "HUT":[], "CANG":[], "FUFU":[],
}
ENERGY_BTC_BASE_EXTRA = {"MARA":"btc_produced_owned_facilities"}  # key inside _extra.reported_other_cost_metric.value

# Denominator adjustments (BTC mined used in the stack) — (ticker, period) -> (btc, source)
BTC_DENOM = {
 ("MARA","Q3_2026"):(2217,"text: MD&A fn (1) — 2,247 BTC produced incl. 30 BTC share of the ADGM equity-method investee; ADGM costs are not in MARA's cost lines → excluded from denominator (owned-site BTC 1,213 for the energy layer)"),
 ("MARA","Q2_2026"):(2384,"text: MD&A — 2,422 BTC produced incl. 38 BTC share of ADGM equity-method investee; ADGM costs are not in MARA's cost lines → excluded from denominator"),
 ("MARA","Q1_2026"):(2200,"text: MD&A — 2,247 BTC produced incl. 47 BTC ADGM share; excluded from denominator"),
 ("MARA","Q4_2025"):(1966,"derived: 10-K MD&A FY 8,799 BTC produced (incl. 180 ADGM share) − 9M 6,788 (incl. 135) = 2,011 incl. 45 ADGM; ADGM excluded → 1,966"),
 ("MARA","Q3_2025"):(2115,"text: MD&A — 2,144 BTC produced incl. 29 BTC share of the ADGM equity-method investee; excluded from denominator"),
}
# Direct-cost adjustments to align numerator with denominator — (ticker, period) -> (value, source)
DIRECT_COST_OVERRIDE = {
 ("BTDR","Q3_2026"):(159300000,"text: Q3 2026 release cost-of-revenue table — self-mining electricity 109.3 + other 11.7 PLUS co-mining electricity 29.8 + other 8.5 (US$ m); BTC mined 3,855 includes co-mining (self/co split not disclosed), so co-mining costs are added for a consistent per-BTC base"),
 ("BTDR","Q2_2026"):(107400000,"text: Q2 release cost-of-revenue table — self-mining electricity 84.7 + other 6.5 PLUS co-mining electricity 13.3 + other 2.9 (US$ m); BTC mined 2,694 includes co-mining, so co-mining costs are added for a consistent per-BTC base"),
 ("BTDR","Q1_2026"):(110500000,"text: Q1 release — self-mining 105.0 + co-mining 5.5 (US$ m); denominator 2,033 BTC includes co-mining"),
 ("CANG","Q2_2026"):(48093328,"derived: reported 'average cash cost per Bitcoin' US$73,313 × 656 BTC = mining-segment energy & hosting cost (consolidated 'Cost of revenue (exclusive of depreciation)' 50,694,280 also carries non-mining cost of vehicles/others 2,600,952); FY2025 identity: 20-F 'Cost of mining services - energy and hosting costs' 525,636,805 / 6,594.6 BTC = reported 79,707"),
 ("CANG","Q1_2026"):(97390848,"derived: reported average cash cost per Bitcoin US$76,928 × 1,266 BTC (consolidated CoR ex-dep 99,578,785 incl. non-mining residual 2,187,937)"),
 ("CANG","Q4_2025"):(145285702,"derived: reported 'average cost to mine, excluding depreciation' US$84,552 × 1,718.3 BTC; cross-check H2 2025 exact energy & hosting = 20-F FY 525,636,805 (xbrl Cango.com:CostEnergyAndHostingExpenses) − H1 6-K 223,719,042 = 301,917,763 vs Q3+Q4 implied 301,819,520 (0.03%)"),
 ("CANG","Q3_2025"):(156533818,"derived: reported average cost to mine ex-depreciation US$81,072 × 1,930.8 BTC (consolidated CoR ex-dep 162,572,731 incl. non-mining residual 6,038,913); see Q4_2025 H2 cross-check"),
 ("CORZ","Q4_2025"):(None,"NOT DERIVABLE: 10-K introduced 'Colocation organizational and site startup costs' / 'Advisor fees' lines carved out of segment cost of revenue without restating 9M → FY−9M self-mining employee compensation = −4,881k; only power fees (28,089k, used in the energy layer) and depreciation (12,773k) are reliable for Q4 2025"),
}

# D&A attributable to BTC mining — (ticker, period) -> (method, value USD or None, source). Methods: SEG, DER, REV, NA
DA_ATTRIB = {
 ("RIOT","Q3_2026"):("DER",64728000,"text: MD&A cost-to-mine table 'Bitcoin miner depreciation' $64,728k (3M ended Sep 30 2026); cross-check (78,805−39,265)×1,637 = 64,727k"),
 ("WULF","Q3_2026"):("DER",9446940,"text: MD&A cost-of-mining footnote: miner-fleet depreciation 'would add $50,790' per BTC × 186 BTC (same basis as Q2 2026 $52,939 and Q3 2025 $70,277; includes accelerated depreciation of the shut-down miner building and related miners)"),
 ("CIFR","Q3_2026"):("SEG",16415000,"xbrl: us-gaap:DepreciationAndAmortization 3M [StatementBusinessSegmentsAxis=BitcoinMiningSegmentMember] — first quarter with a segment split (HPC Leasing 2,406k); Odessa assets incl. infrastructure, not miners only"),
 ("CORZ","Q3_2026"):("SEG",7173000,"xbrl: us-gaap:CostDepreciationAmortizationAndDepletion 3M [DigitalAssetSelfMiningSegmentMember]; mining equipment reclassified to held for sale is no longer depreciated → mostly infrastructure depreciation"),
 ("ABTC","Q3_2026"):("SEG",28579000,"xbrl: us-gaap:DepreciationAndAmortization 3M (single-segment miner; PP&E = miners and mining equipment only)"),
 ("RIOT","Q2_2026"):("DER",64622000,"text: MD&A cost-to-mine table 'Bitcoin miner depreciation' $64,622k; cross-check (90,631−49,912)×1,587 = 64,621k"),
 ("RIOT","Q1_2026"):("DER",76066000,"text: MD&A cost-to-mine table 'Bitcoin miner depreciation'; cross-check (96,283−44,629)×1,473 = 76,086k"),
 ("CLSK","Q2_2026"):("SEG",99851000,"xbrl: us-gaap:Depreciation 3M [PropertyPlantAndEquipmentByTypeAxis=MinersMember]; MD&A 'Depreciation expense - miners only'"),
 ("CLSK","Q1_2026"):("SEG",104390000,"xbrl: us-gaap:Depreciation 3M [MinersMember]; MD&A 'Depreciation expense - miners only'"),
 ("WULF","Q2_2026"):("DER",9476000,"text: MD&A cost-of-mining footnote: miner-fleet depreciation 'would add $52,939' per BTC × 179 BTC (includes accelerated depreciation)"),
 ("WULF","Q1_2026"):("DER",13414000,"text: MD&A: cost to mine incl. depreciation $79,464 − ex-D&A (−$381) = $79,845 × 168 BTC"),
 ("CIFR","Q2_2026"):("SEG",19365000,"xbrl: us-gaap:DepreciationAndAmortization 3M [BitcoinMiningMember] (single segment)"),
 ("CIFR","Q1_2026"):("SEG",19010000,"xbrl: us-gaap:DepreciationAndAmortization 3M [BitcoinMiningMember]"),
 ("CORZ","Q2_2026"):("SEG",9897000,"xbrl: us-gaap:CostDepreciationAmortizationAndDepletion 3M [DigitalAssetSelfMiningSegmentMember]"),
 ("CORZ","Q1_2026"):("SEG",13910000,"xbrl: us-gaap:CostDepreciationAmortizationAndDepletion 3M [DigitalAssetSelfMiningSegmentMember]"),
 ("ABTC","Q2_2026"):("SEG",28237000,"xbrl: us-gaap:DepreciationAndAmortization 3M (single-segment pure-play; miners only)"),
 ("ABTC","Q1_2026"):("SEG",26620000,"xbrl: us-gaap:DepreciationAndAmortization 3M"),
 ("RIOT","Q4_2025"):("DER",60154000,"derived: 'Bitcoin miner depreciation' 10-K FY2025 cost-to-mine table 237,574k − Q3 10-Q 9M table 177,420k"),
 ("RIOT","Q3_2025"):("DER",60106000,"text: MD&A cost-to-mine table 'Bitcoin miner depreciation' $60,106k (3M ended Sep 30 2025)"),
 ("CLSK","Q4_2025"):("SEG",95060000,"xbrl: us-gaap:Depreciation 3M [PropertyPlantAndEquipmentByTypeAxis=MinersMember]; MD&A 'Depreciation expense - miners only'"),
 ("CLSK","Q3_2025"):("SEG",97255000,"derived: MD&A 'Depreciation expense - miners only' FY2025 306,914k (xbrl us-gaap:Depreciation [MinersMember]) − 9M (Jun-25 10-Q)"),
 ("WULF","Q3_2025"):("DER",26494000,"text: MD&A cost-of-mining footnote: miner-fleet depreciation 'would add $70,277' per BTC × 377 BTC; ≈ consolidated depreciation 26,502k (HPC depreciation had not started) — includes accelerated depreciation 7,800k"),
 ("CIFR","Q4_2025"):("SEG",51871000,"xbrl: us-gaap:DepreciationAndAmortization [BitcoinMiningMember] FY 198,973k − 9M 147,102k (single segment)"),
 ("CIFR","Q3_2025"):("SEG",59549000,"xbrl: us-gaap:DepreciationAndAmortization 3M [StatementBusinessSegmentsAxis=BitcoinMiningMember] (single segment)"),
 ("CORZ","Q4_2025"):("SEG",12773000,"xbrl: us-gaap:CostDepreciationAmortizationAndDepletion [DigitalAssetSelfMiningSegmentMember] FY 65,565k − restated 9M"),
 ("CORZ","Q3_2025"):("SEG",15474000,"xbrl: us-gaap:CostDepreciationAmortizationAndDepletion 3M [DigitalAssetSelfMiningSegmentMember] (10-Q/A)"),
 ("ABTC","Q4_2025"):("SEG",26649000,"derived: us-gaap:DepreciationAndAmortization FY − 9M (single-segment miner; PP&E = miners only)"),
 ("ABTC","Q3_2025"):("SEG",15215000,"xbrl: us-gaap:DepreciationAndAmortization 3M (single-segment miner; PP&E = miners only)"),
 ("CANG","Q2_2026"):("SEG",16930355,"text: income statement 'Cost of revenue (depreciation) 16,930,355' (3M) — depreciation of mining machines"),
 ("CANG","Q1_2026"):("SEG",29372199,"text: income statement 'Cost of revenue (depreciation) 29,372,199' (3M) — mining machines"),
 ("CANG","Q4_2025"):("SEG",37284701,"derived: 20-F Note 12 'Cost of mining services - depreciation' FY 115,835,500 (xbrl Cango.com:DepreciationCryptoAssetMiningMachinery) − 9M income-statement CoR depreciation 78,550,799; cross-check (106,251 − 84,552) × 1,718.3 = 37,285k"),
 ("CANG","Q3_2025"):("SEG",35356473,"text: income statement 'Cost of revenue (depreciation) 35,356,473' (3M; mining machines)"),
 ("KEEL","Q2_2026"):("NA",None,"mining cost not separable"), ("KEEL","Q1_2026"):("NA",None,"mining cost not separable"),
 ("HUT","Q2_2026"):("NA",None,"ASIC cost not disclosed"), ("HUT","Q1_2026"):("NA",None,"ASIC cost not disclosed"),
}
DA_DEFAULT_NOTE = {
 "MARA":"single segment; D&A not split — revenue-share of consolidated D&A",
 "HIVE":"single operating segment; revenue-share of consolidated D&A",
 "IREN":"CODM measure excludes D&A; revenue-share of consolidated D&A — HIGH uncertainty (AI-Cloud GPU depreciation dominates)",
 "BTDR":"3M self-mining D&A disclosed only combined with SBC; revenue-share of consolidated D&A",
 "BTBT":"D&A not allocated to segments", "WULF":"Q4 2025: FY and 9M footnotes use different depreciation bases → miner-fleet D&A not derivable; revenue-share of consolidated depreciation",
}
# Non-recurring CASH items inside SG&A — (ticker, period) -> (value, source)
NONREC_CASH_SGA = {
 ("MARA","Q3_2026"):(1944000,"Adj. EBITDA reconciliation: acquisition and integration costs 1,944k 'reported in General and administrative'; restructuring costs 18,979k (Project Align) and litigation 0 are separate P&L lines → not SG&A adjustments"),
 ("MARA","Q2_2026"):(25645000,"Adj. EBITDA reconciliation fn(3): acquisition & integration costs $15,445k (6M 26,463 − Q1 11,018) + litigation settlement $10,200k, both 'reported in General and administrative'"),
 ("MARA","Q1_2026"):(11018000,"Adj. EBITDA reconciliation: acquisition & integration costs $11,018k in G&A"),
 ("CLSK","Q2_2026"):(5930000,"Adj. EBITDA reconciliation (3M): fees related to financing & business development 4,973k + litigation & settlement 807k + severance and other 150k (embedded in professional fees / payroll / G&A); indirect tax contingency and loss on disposal are separate P&L lines → excluded"),
 ("CLSK","Q1_2026"):(5651000,"Adj. EBITDA reconciliation (3M): fees related to financing & business development 5,068k + litigation & settlement 715k + severance and other (132)k; indirect tax contingency, loss on disposal, impairment are separate P&L lines → excluded"),
 ("CORZ","Q2_2026"):(397000,"Adj. EBITDA fn(3): post-emergence bankruptcy advisory costs $397k in SG&A"),
 ("MARA","Q4_2025"):(530000,"Adj. EBITDA reconciliation: acquisition & integration costs FY 2,005k − 9M 1,475k, 'reported in General and administrative'"),
 ("MARA","Q3_2025"):(1475000,"Adj. EBITDA reconciliation fn(2): acquisition & integration costs $1,475k 'reported in General and administrative'"),
 ("CLSK","Q4_2025"):(1979000,"Adj. EBITDA reconciliation (3M): fees related to financing & business development 202k + litigation & settlement 1,745k + severance and other 32k (embedded in professional fees / payroll / G&A)"),
 ("CLSK","Q3_2025"):(5934000,"Adj. EBITDA reconciliation (10-K FY − Jun-25 10-Q 9M): fees financing & BD 125k + litigation & settlement 873k + severance and other 4,936k (cash CEO severance; SBC severance 20,003k sits in SBC)"),
 ("CORZ","Q4_2025"):(16289000,"derived: 'Advisor fees' Q4 = merger agreement related costs 16,081k + post-emergence bankruptcy advisory 208k (Adj. EBITDA reconciliation; inside SG&A on the 10-Q presentation basis used for Q4)"),
 ("CORZ","Q3_2025"):(5785000,"Adj. EBITDA reconciliation: Merger Agreement related costs 5,507k + post-emergence bankruptcy advisory costs 278k, in SG&A"),
 ("ABTC","Q4_2025"):(360000,"EBITDA table 'Non-recurring transactions' FY 7,838k − 9M 7,478k (Merger-related transaction costs in G&A)"),
 ("ABTC","Q3_2025"):(5239000,"EBITDA table 'Non-recurring transactions (1) | 5,239' = Merger-related transaction costs in G&A (MD&A)"),
}
OTHER_NONCASH_SGA = {("WULF","Q2_2026"):(14390000,"text: related-party SG&A includes stock-based charitable contribution $14,390k (non-cash)")}
# Accelerated depreciation inside consolidated D&A — (ticker, period) -> (value, source, in_attrib) ; in_attrib: True if the attributable D&A figure already contains it
ACCEL_DA = {
 ("WULF","Q3_2026"):(7700000,"xbrl: wulf:AcceleratedDepreciationExpense 3M [MiningFacilitiesMember] 7.7m — 'a miner building and related miners ... as well as certain electrical equipment' (Note: PP&E); the miner/building split is not disclosed; treated as inside the miner-fleet DER figure as in Q2 2026 and Q3 2025 (upper bound for the run-rate adjustment)",True),
 ("MARA","Q2_2026"):(28100000,"text: MD&A — accelerated depreciation on retired miners $28.1m","REV"),
 ("MARA","Q1_2026"):(20100000,"text: MD&A — accelerated depreciation $20.1m","REV"),
 ("WULF","Q2_2026"):(2600000,"text: accelerated depreciation (HPC conversion) $2.6m; included in miner depreciation footnote",True),
 ("WULF","Q1_2026"):(11900000,"text: accelerated depreciation $11.9m; included in miner depreciation footnote",True),
 ("MARA","Q4_2025"):(110500000,"text: 10-K — FY2025 D&A 'included $110.5 million of accelerated depreciation of certain mining rigs' (mara:DepreciationAccelerated FY); none disclosed in the Q1–Q3 10-Qs → attributed to Q4 by derivation","REV"),
 ("WULF","Q4_2025"):(11800000,"derived: terawulf:AcceleratedDepreciationExpense FY 19,600k − 9M 7,800k (miner building/miners shut down for HPC); D&A attributable is revenue-share → REV rule","REV"),
 ("WULF","Q3_2025"):(7800000,"xbrl: terawulf:AcceleratedDepreciationExpense [MiningFacilitiesMember] 3M; included in the miner-depreciation footnote figure",True),
 ("KEEL","Q2_2026"):(62993000,"xbrl: us-gaap:DepreciationDepletionAndAmortization [ServiceLifeMember] 3M = 62,993k",False),
 ("KEEL","Q1_2026"):(4700000,"derived from MD&A (~$4.7m accelerated)",False),
}
SBC_FALLBACK = {"HUT":("total","SBC not split by line; MD&A attributes G&A increase to SBC — total SBC used"),
                "BTDR":("zero","3M SBC split undisclosed (6M: G&A 4.16m, selling 0.24m, R&D 7.98m, CoR 1.15m) — NOT deducted: conservative")}
MATERIALITY_BTC = 500   # headline ranking threshold, BTC mined per quarter
BTC_SPOT = (68249.27,"BTC-USD daily close 2026-11-13 (Yahoo research feed) — the same figure and date as the hashflops.io Capacity base daily roll (src/data/mining/capacity_daily.json, as_of 2026-11-13)","2026-11-13","https://hashflops.io/mining/value-per-megawatt/")
# previous release (v1.0 2026Q2): (82308.83, "CoinGecko BTC/USD 2026-10-15 20:00 UTC — same data cut as Mining NAV Standard v1.1", "2026-10-15")
SHORT_NAME = {"RIOT":"Riot Platforms","MARA":"MARA Holdings","CLSK":"CleanSpark","HIVE":"HIVE Digital","IREN":"IREN","CIFR":"Cipher Digital (ex-Cipher Mining)","CORZ":"Core Scientific","WULF":"TeraWulf","BTDR":"Bitdeer","CANG":"Cango","FUFU":"BitFuFu","ABTC":"American Bitcoin","BTBT":"Bit Digital","KEEL":"Keel Infrastructure (ex-Bitfarms)","HUT":"Hut 8"}
