/* =========================================================
   CM Group — Tungsten Trade page stylesheet
   PART 1 is copied VERBATIM from tungsten.css (header, mega menu, sidebar,
   filters, chart cards, footer) so every tungsten page shares one template.
   Do NOT edit PART 1 here — change the template everywhere or not at all.
   PART 2 holds only what is specific to the trade page.
   ========================================================= */

/* ===================== PART 1 — shared template ===================== */
*{margin:0;padding:0;box-sizing:border-box}
.header{background:#fff;border-bottom:1px solid #e0e0e0;position:sticky;top:0;z-index:1000}
.header-inner{max-width:1400px;margin:0 auto;padding:0 48px;display:flex;align-items:center;height:80px;gap:36px}
.header-logo img{height:40px}
.header-nav{display:flex;gap:32px;list-style:none;align-items:center}
.header-nav>li{position:relative}
.header-nav>li>a,.header-nav>li>a:visited,.header-nav>li>a:active{color:#333!important;text-decoration:none!important;font-size:15px;font-weight:500;cursor:pointer;display:inline-flex;align-items:center;gap:4px}
.header-nav>li>a:hover{color:#024d8f!important;text-decoration:none!important}
.header-nav>li>a.active{color:#024d8f;font-weight:600}
.header-nav>li>a .arrow{font-size:9px;color:#80868b;transition:transform .2s}
.header-nav>li.open>a .arrow{transform:rotate(180deg)}
.header-nav>li>a.locked{color:#b0b8c4;cursor:default}
.header-nav>li>a.locked:hover{color:#b0b8c4}
.soon-badge{font-size:8px;background:#dadce0;color:#8892a0;padding:2px 6px;border-radius:8px;font-weight:600;letter-spacing:.5px;text-transform:uppercase}
.mega-menu{display:none;position:fixed;top:64px;left:0;right:0;background:#fff;border-top:1px solid #e0e0e0;box-shadow:0 12px 40px rgba(0,0,0,.08);z-index:9999}
.header-nav>li.open .mega-menu{display:block}
.mega-inner{max-width:1400px;margin:0 auto;padding:40px 48px;display:grid;grid-template-columns:1fr 1fr 1fr;gap:48px;align-items:start}
.mega-col h4{font-size:14px;font-weight:600;color:#1a1a1a;margin-bottom:20px;padding-left:14px}
.mega-item{display:flex;align-items:flex-start;gap:14px;padding:12px 14px;border-radius:8px;text-decoration:none;color:inherit;transition:background .15s;margin-bottom:2px}
.mega-item:hover{background:#f4f7fc}
.mega-item-icon{width:40px;height:40px;border-radius:8px;background:#f0f4f9;display:flex;align-items:center;justify-content:center;flex-shrink:0}
.mega-item-icon svg{width:20px;height:20px;stroke:#024d8f;fill:none;stroke-width:2}
.mega-item-text h5{font-size:14px;font-weight:500;color:#1a1a1a;margin-bottom:2px}
.mega-item-text p{font-size:12px;color:#80868b;line-height:1.4}
.mega-links h4{font-size:14px;font-weight:600;color:#1a1a1a;margin-bottom:16px}
.mega-links a{display:block;font-size:14px;color:#3c4043;text-decoration:none;padding:8px 0;transition:color .15s}
.mega-links a:hover{color:#024d8f}
.mega-links .section{margin-bottom:24px}
.mega-promo{background:#f8f9fb;border-radius:12px;padding:28px}
.mega-promo h5{font-size:16px;font-weight:500;color:#1a1a1a;margin-bottom:10px}
.mega-promo p{font-size:13px;color:#5f6368;line-height:1.7;margin-bottom:16px}
.mega-promo .promo-btn{color:#024d8f;font-size:14px;font-weight:600;text-decoration:none}
.mega-promo .promo-btn:hover{text-decoration:underline}
.header-signin{display:flex;align-items:center;font-size:14px;font-weight:400;text-decoration:none;color:#2a2a2a}
.header-right{display:flex;align-items:center;gap:20px;margin-left:auto}
.header-right a{color:#024d8f;text-decoration:none;font-size:13px;font-weight:400}
.header-right a:hover{text-decoration:underline}
.header-right .signout{color:#80868b}
.header-right .signout:hover{color:#c62828;text-decoration:none}
body{font-family:Inter,Helvetica Neue,Helvetica,Arial,sans-serif;background:#fff;color:#202124;font-size:14px}
.main-layout{display:grid;grid-template-columns:280px 1fr;max-width:1400px;margin:0 auto;min-height:calc(100vh - 80px)}
.page-title{font-size:24px;font-weight:400;color:#202124;margin-bottom:2px}
.page-subtitle{font-size:13px;color:#80868b;font-weight:400;margin-bottom:20px}
.ccy-toggle{display:flex;gap:0;border:1px solid #dadce0;border-radius:20px;overflow:hidden}
.tb-btn{padding:6px 14px;border:1px solid #dadce0;border-radius:20px;font-size:12px;font-weight:500;color:#3c4043;background:#fff;cursor:pointer;display:inline-flex;align-items:center;gap:5px;font-family:inherit;transition:all .15s}
.tb-btn:hover{background:#f1f3f4}
.tb-btn.active{border-color:#1a1a1a;color:#1a1a1a;background:#f0f0f0}
.ccy-toggle button{padding:7px 16px;border:none;background:#fff;font-size:13px;font-weight:500;color:#5f6368;cursor:pointer;transition:all .15s;font-family:inherit}
.ccy-toggle button:not(:last-child){border-right:1px solid #dadce0}
.ccy-toggle button.active{background:#f0f0f0;color:#1a1a1a;font-weight:600}
.ccy-toggle button:hover:not(.active){background:#f1f3f4}
.sidebar-toggle-full{width:100%}
.sidebar-toggle-full button{flex:1;padding:7px 0;font-size:12px}
.mega-overlay{display:none;position:fixed;top:64px;left:0;right:0;bottom:0;background:rgba(0,0,0,.12);z-index:998}

.user-dropdown{position:relative;display:inline-flex}
.user-dropdown-btn{display:flex;align-items:center;gap:6px;font-size:14px;font-weight:400;color:#2a2a2a;background:none;border:none;outline:none;cursor:pointer;font-family:inherit;padding:4px 0}
.user-dropdown-btn:hover{color:#024d8f}
.user-dropdown-menu{visibility:hidden;opacity:0;pointer-events:none;position:absolute;top:calc(100% + 10px);right:0;background:#fff;border:1px solid #e0e0e0;border-radius:10px;box-shadow:0 8px 24px rgba(0,0,0,.10);min-width:180px;z-index:10000;overflow:hidden;transition:opacity .15s}
.user-dropdown-menu.open{visibility:visible;opacity:1;pointer-events:auto}
.user-dropdown-menu a{display:flex;align-items:center;gap:10px;padding:10px 16px;font-size:13px;color:#3c4043!important;text-decoration:none!important}
.user-dropdown-menu a:hover{background:#f8f9fa}
.dd-divider{height:1px;background:#f1f3f4;margin:4px 0}
.dd-logout{color:#c62828!important}

.sidebar{border-right:1px solid #ebebeb;overflow-y:auto;max-height:calc(100vh - 80px);position:sticky;top:80px;background:#fff;padding:20px 0}
.sb-section{padding:12px 22px 16px;margin-bottom:4px;border-bottom:1px solid #f1f3f4}
.sb-section:last-child{border-bottom:none}
.sb-label{font-size:11px;font-weight:600;color:#5f6368;text-transform:uppercase;letter-spacing:.5px;margin-bottom:10px;display:flex;justify-content:space-between;align-items:center}
.tab-row{display:flex;flex-direction:column;gap:2px}
.tab-btn{padding:10px 16px;border:none;border-radius:8px;font-size:13px;font-weight:500;color:#3c4043;background:transparent;cursor:pointer;font-family:inherit;transition:all .15s;text-align:left;display:flex;align-items:center;gap:8px}
.tab-btn:hover{background:#f1f3f4}
.tab-btn.active{background:#f0f0f0;color:#1a1a1a;font-weight:600}

.sidebar select{width:100%;padding:8px 14px;border:1px solid #dadce0;border-radius:20px;font-size:13px;font-family:inherit;background:#fff;outline:none;color:#3c4043;cursor:pointer;-webkit-appearance:none;appearance:none;background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235f6368' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");background-repeat:no-repeat;background-position:right 12px center;padding-right:32px}
.sidebar select:focus{border-color:#1a1a1a;box-shadow:0 0 0 2px rgba(26,26,26,.15)}
.sidebar select:hover{background-color:#f8f9fa}

.quick-btn{padding:4px 10px;border:1px solid #dadce0;border-radius:20px;font-size:10px;font-weight:600;color:#8892a0;background:#fff;cursor:pointer;transition:all .15s}
.quick-btn:hover{border-color:#1a1a1a;color:#1a1a1a}
.quick-btn.active{background:#f0f0f0;color:#1a1a1a;border-color:#1a1a1a;font-weight:600}
.filter-label{font-size:9px;text-transform:uppercase;letter-spacing:1px;color:#b0b8c4;font-weight:600}
.content{padding:16px 28px 40px;min-width:0}
.chart-section{background:#f8f9fa;border-radius:16px;padding:20px 24px;margin-bottom:20px}
.chart-header{display:flex;align-items:center;justify-content:space-between;margin-bottom:12px}
.chart-title{font-size:18px;font-weight:400;color:#202124}
.chart-subtitle{font-size:13px;color:#80868b;margin-top:2px;font-weight:400}
.chart-wrap{overflow:hidden;height:420px;position:relative}
.legend-row{display:flex;gap:6px;flex-wrap:wrap;margin-top:12px;justify-content:center}
.legend-item{display:inline-flex;align-items:center;gap:5px;font-size:12px;color:#3c4043;padding:4px 12px;border:1px solid #dadce0;border-radius:20px;background:#fff;box-shadow:0 1px 2px rgba(0,0,0,.04)}
#trend-legend{justify-content:center;gap:16px}
#trend-legend .legend-item{border:none;box-shadow:none;background:none;padding:0;gap:6px;font-size:12px;color:#4a5b67}
#trend-legend .legend-swatch{border:none;width:10px;height:10px}
.legend-swatch{width:10px;height:10px;border-radius:3px;border:1px solid #1a1a1a}
.detail-panel{background:#fff;border:1px solid #ebebeb;border-radius:16px;padding:24px;box-shadow:0 1px 3px rgba(0,0,0,.04);margin-bottom:20px;overflow:visible}
.rank-count{font-size:12px;color:#80868b;white-space:nowrap;margin-left:16px;padding-top:4px}
.rank-scroll{max-height:min(560px,70vh);overflow:auto;border:1px solid #f1f3f4;border-radius:8px}
.rank-expand{margin-top:14px;width:100%;justify-content:center}
.detail-header{display:flex;justify-content:space-between;align-items:flex-start;margin-bottom:16px}
.detail-title{font-size:22px;font-weight:400;color:#202124}
.detail-sub{font-size:13px;color:#80868b;margin-top:3px}
.footer{max-width:1440px;margin:0 auto;padding:0 40px 40px;text-align:center}
.footer-text{font-size:11px;color:#ccc}
.filter-dd{position:relative}
.filter-dd-btn{width:100%;padding:8px 14px;border:1px solid #dadce0;border-radius:20px;font-size:13px;background:#fff;cursor:pointer;text-align:left;color:#3c4043;display:flex;justify-content:space-between;align-items:center;box-sizing:border-box;transition:all .15s;outline:none}
.filter-dd-btn:hover{border-color:#1a1a1a}
.filter-dd-btn.active{border-color:#1a1a1a;background:#f5f5f5;font-weight:500}
.filter-dd-list{display:none;max-height:200px;overflow-y:auto;background:#fff;border:1px solid #dadce0;border-radius:12px;margin-top:4px;padding:4px 0;box-sizing:border-box;box-shadow:0 4px 16px rgba(0,0,0,.12);position:relative;left:0;right:0;z-index:500}
.filter-dd-list.open{display:block}
.filter-dd-item{display:flex;align-items:center;gap:8px;padding:7px 14px;font-size:13px;cursor:pointer;color:#3c4043;transition:background .1s}
.filter-dd-item:hover{background:#f1f3f4}
.filter-dd-item input{margin:0;accent-color:#1a1a1a;width:16px;height:16px}
.user-avatar{width:32px;height:32px;border-radius:50%;background:#024d8f;color:#fff;display:flex;align-items:center;justify-content:center;font-size:11px;font-weight:600;cursor:pointer;letter-spacing:.5px}

/* ===================== PART 2 — trade-page specific ===================== */

/* ===================== Period Filter — Segmented control style ===================== */
.period-presets {
  display: flex;
  margin-bottom: 10px;
  border: 1px solid #dadce0;
  border-radius: 7px;
  overflow: hidden;
}
.period-btn {
  flex: 1;
  padding: 7px 2px;
  background: #fff;
  border: none;
  border-right: 1px solid #dadce0;
  color: #80868b;
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.12s;
  letter-spacing: 0.2px;
}
.period-btn:last-child { border-right: none; }
.period-btn:hover { background: #f8f9fa; color: #3c4043; }
.period-btn.active {
  background: #1a1a1a;
  color: #fff;
  border-right-color: #1a1a1a;
}
.period-btn.active + .period-btn { border-left-color: #1a1a1a; }

.period-custom {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 7px;
}
.period-input {
  flex: 1;
  min-width: 0;
  padding: 6px 7px;
  background: #fafafa;
  border: 1px solid #e8eaed;
  border-radius: 5px;
  color: #1a1a1a;
  font-size: 11px;
  font-family: 'SF Mono', 'Consolas', monospace;
  text-align: center;
  transition: border-color 0.12s;
}
.period-input:focus {
  outline: none;
  border-color: #1a1a1a;
  background: #fff;
}
.period-input::placeholder { color: #c0c4cc; }
.period-sep {
  color: #c0c4cc;
  font-size: 12px;
  flex-shrink: 0;
}
.period-apply {
  flex-shrink: 0;
  padding: 6px 10px;
  background: #1a1a1a;
  border: none;
  border-radius: 5px;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s;
  font-family: inherit;
  letter-spacing: 0.3px;
}
.period-apply:hover { background: #333; }
.period-apply:disabled { background: #dadce0; cursor: not-allowed; }

.period-display {
  font-size: 10px;
  color: #9aa0a6;
  letter-spacing: 0.1px;
}
.period-display strong {
  color: #3c4043;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.page-header{display:flex;align-items:flex-start;justify-content:space-between;gap:16px;margin-bottom:20px}
.page-actions{display:flex;gap:8px;align-items:center;padding-top:4px}
.tb-btn:disabled{opacity:.45;cursor:not-allowed}
.tb-btn:disabled:hover{background:#fff}
.preview-badge{background:#fbbc04;color:#202124;font-size:11px;padding:3px 10px;border-radius:12px;font-weight:600;vertical-align:middle;margin-left:8px}
.icon-16{width:16px;height:16px}

/* small layout utilities used instead of inline styles (HTML/CSS/JS stay separate) */
.full-width{width:100%}
.mb-8{margin-bottom:8px}
.mb-10{margin-bottom:10px}
.mb-12{margin-bottom:12px}
.quick-btn-row{display:flex;gap:4px}
.quick-btn-row .quick-btn{flex:1;text-align:center}
.dd-val-wrap{color:#555;font-weight:400}
.hl-input{width:100%;padding:8px 14px;border:1px solid #dadce0;border-radius:20px;font-size:12px;font-family:inherit;background:#fff;box-sizing:border-box;outline:none}

/* empty state shown over a chart until data is connected */
.empty-note{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:6px;color:#80868b;font-size:13px;pointer-events:none;text-align:center}
.empty-note b{font-weight:500;color:#5f6368;font-size:14px}

/* section heading between blocks */
.section-title{font-size:18px;font-weight:400;color:#202124;margin:8px 0 4px}
.section-sub{font-size:13px;color:#80868b;margin-bottom:14px}

/* sankey flow diagram wrap (d3-sankey draws an <svg> into this) */
#sankeyWrap{position:relative;height:420px}
#sankeyWrap svg{width:100%;height:100%}

/* difference / summary table */
.diff-table{width:100%;border-collapse:collapse;font-size:13px}
.diff-table th{text-align:left;font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.5px;color:#80868b;padding:8px 12px;border-bottom:1px solid #e4e9f0;background:#f8fafc;position:sticky;top:0;z-index:2;box-shadow:0 1px 0 #e4e9f0}
.diff-table td{padding:6px 12px;border-bottom:1px solid #f1f3f4;color:#3c4043;font-variant-numeric:tabular-nums}
.diff-table th.r,.diff-table td.r{text-align:right}
.diff-table .empty-row td{text-align:center;color:#80868b;padding:28px 12px}
.diff-table th.rank-col,.diff-table td.rank-col{width:28px;color:#aab1ba;font-weight:400}
.diff-table th.sortable{cursor:pointer}
.diff-table th.sortable.sort-asc,.diff-table th.sortable.sort-desc{color:#024d8f;background:#eef3f9}
.diff-table th.sortable.sort-asc::after{content:' \25B2';font-size:9px}
.diff-table th.sortable.sort-desc::after{content:' \25BC';font-size:9px}
.diff-table tr.other-row td{color:#80868b;font-style:italic}
.diff-table tr.total-row td{font-weight:600;color:#1a1a1a;border-top:2px solid #e4e9f0}
.diff-pos{color:#188038}
.diff-neg{color:#c62828}

/* ===================== sankey flow diagram ===================== */
.sankey-tip{position:fixed;pointer-events:none;background:#202124;color:#fff;font-size:12px;padding:8px 12px;border-radius:8px;z-index:3000;max-width:320px;line-height:1.5;box-shadow:0 4px 16px rgba(0,0,0,.2)}
#sankeyWrap .sankey-link{transition:stroke-opacity .15s}
#sankeyWrap .sankey-node-label{font-size:11px;fill:#3c4043}
#sankeyWrap .sankey-axis-label{font-size:10px;font-weight:600;fill:#80868b;letter-spacing:.5px}
.dd-disabled{opacity:.4;pointer-events:none}

/* ===================== KPI strip ===================== */
.kpi-strip{display:grid;grid-template-columns:repeat(4,1fr);border:1px solid #ebebeb;border-radius:16px;margin-bottom:20px;background:#fff}
.kpi{padding:16px 20px;border-left:1px solid #f1f3f4}
.kpi:first-child{border-left:none}
.kpi-l{font-size:11px;font-weight:600;color:#80868b;text-transform:uppercase;letter-spacing:.5px}
.kpi-v{font-size:24px;font-weight:500;color:#202124;margin-top:6px;font-variant-numeric:tabular-nums}
.kpi-c{font-size:12px;color:#80868b;margin-top:4px;font-variant-numeric:tabular-nums}
.kpi-c.pos{color:#188038}
.kpi-c.neg{color:#c62828}

/* ===================== tabs ===================== */
.tab-bar{display:flex;gap:2px;border-bottom:1px solid #ebebeb;margin-bottom:20px}
.tab-btn2{height:40px;padding:0 16px;border:none;background:none;font:inherit;font-size:13px;font-weight:600;color:#80868b;cursor:pointer;border-bottom:2px solid transparent;margin-bottom:-1px;transition:color .15s}
.tab-btn2:hover{color:#1a1a1a}
.tab-btn2.active{color:#024d8f;border-bottom-color:#024d8f}
.tab-view[hidden]{display:none}

/* sidebar note under Split By */
.sb-note{font-size:11px;color:#80868b;line-height:1.5;margin-top:2px}
.sb-note a{color:#024d8f}

/* page-header asof text */
.asof{font-size:12px;color:#80868b;white-space:nowrap}

/* ===================== Flow Matrix heatmap ===================== */
.matrix-wrap{overflow:auto;max-height:640px;border:1px solid #f1f3f4;border-radius:8px}
table.mx-table{border-collapse:separate;border-spacing:0;font-size:12px;min-width:100%}
table.mx-table th{font-size:11px;font-weight:600;color:#024d8f;padding:0 10px;height:32px;background:#f8fafc;white-space:nowrap;text-align:right;position:sticky;top:0;z-index:2;max-width:120px;overflow:hidden;text-overflow:ellipsis}
table.mx-table th:first-child{text-align:left;left:0;z-index:3;background:#f8fafc}
table.mx-table td{padding:0 10px;height:32px;text-align:right;font-variant-numeric:tabular-nums;white-space:nowrap;border-right:1px solid #fff;border-bottom:1px solid #fff}
table.mx-table td.row-h{text-align:left;font-weight:600;background:#fff;position:sticky;left:0;z-index:1;border-right:1px solid #f1f3f4;color:#3c4043}
table.mx-table td.mx-tot,table.mx-table tr.mx-tot td{font-weight:600;background:#eef3f9!important;color:#1a1a1a}
table.mx-table tr.mx-tot td{border-top:2px solid #024d8f}
table.mx-table td.zero{color:#dadce0}
.matrix-legend{display:flex;align-items:center;gap:8px;font-size:11px;color:#80868b;margin-bottom:10px}
.matrix-legend i{display:inline-block;width:110px;height:8px;border-radius:4px;background:linear-gradient(90deg,#f8fafc,#024d8f)}
.stage-defs{font-size:12px;color:#5f6368;line-height:1.6;margin-top:14px;padding-top:12px;border-top:1px solid #e4e9f0}
.stage-defs-title{font-size:11px;font-weight:600;color:#3c4043;text-transform:uppercase;letter-spacing:.4px;margin-bottom:8px}
.stage-defs-list{list-style:none;margin:0;padding:0;display:grid;grid-template-columns:repeat(2,1fr);gap:4px 16px}
.stage-defs-list li{font-size:12px;color:#5f6368}
.stage-defs-list b{color:#3c4043;font-weight:600}
.stage-defs-foot{font-size:11px;color:#aab1ba;margin-top:8px}

/* ===================== trend chart tooltip card (same design as costs.html/alumina-costs.html/trade-data.css .cc-tip) ===================== */
.cc-tip{position:fixed;z-index:9999;pointer-events:none;opacity:0;transition:opacity .12s ease;min-width:230px;max-width:300px;background:#fff;border-radius:12px;overflow:hidden;box-shadow:0 8px 28px rgba(16,24,40,.16),0 0 0 1px rgba(16,24,40,.06);font-size:12px;color:#1a1a1a}
.cc-tip-hd{padding:11px 14px 9px;border-bottom:1px solid #eef0f3;display:flex;align-items:baseline;justify-content:space-between;gap:10px}
.cc-tip-period{font-size:13px;font-weight:700;letter-spacing:-.2px}
.cc-tip-unit{font-size:12px;color:#80868b;font-weight:400;white-space:nowrap}
.cc-tip-body{padding:8px 14px 4px}
.cc-row{display:flex;align-items:center;gap:8px;padding:4px 0;font-variant-numeric:tabular-nums}
.cc-dot{width:9px;height:9px;border-radius:2px;flex-shrink:0}
.cc-name{flex:1;color:#80868b;font-weight:500}
.cc-val{font-weight:600;color:#1a1a1a}
.cc-pct{width:48px;text-align:right;color:#80868b;font-size:12px}
.cc-tip-ft{margin:6px 14px 12px;padding-top:9px;border-top:1px solid #eef0f3;display:flex;align-items:baseline;justify-content:space-between;gap:10px}
.cc-tip-ft .lbl{font-size:12px;font-weight:600;color:#80868b}
.cc-tip-ft .amt{font-size:16px;font-weight:700;letter-spacing:-.3px;font-variant-numeric:tabular-nums}
.cc-tip-ft .chg{font-size:12px;font-weight:500;margin-left:6px}
.cc-tip::after{content:"";position:absolute;left:var(--cx,20px);bottom:-6px;width:12px;height:12px;background:#fff;transform:rotate(45deg);box-shadow:3px 3px 6px rgba(16,24,40,.06)}
.cc-tip.below::after{bottom:auto;top:-6px;box-shadow:-3px -3px 6px rgba(16,24,40,.06)}
.chg.pos{color:#188038}
.chg.neg{color:#c62828}
