:root {
  --ink: #182f3a;
  --muted: #627782;
  --line: #d9e4e7;
  --paper: #f4f7f6;
  --card-bg: #ffffff;
  --teal: #087f78;
  --teal-light: #e6f4f2;
  --amber: #b48039;
  --amber-light: #fef3c7;
  --bull: #059669;
  --bull-bg: #ecfdf5;
  --bear: #dc2626;
  --bear-bg: #fef2f2;
  --neutral: #94a3b8;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft JhengHei", sans-serif;
  line-height: 1.5;
}

.breadth-page {
  max-width: 1280px;
  margin: auto;
  padding: 24px 20px 48px;
}

nav, .toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

nav span, .eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--teal);
  text-transform: uppercase;
}

a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }

header { padding: 24px 0 16px; }
h1 { font-size: clamp(26px, 4vw, 40px); margin: 6px 0 10px; font-weight: 800; color: #0f242e; }
h2 { font-size: 20px; margin: 0; font-weight: 700; color: #112833; }
p { margin: 6px 0; color: #334e59; }
.muted, footer { color: var(--muted); font-size: 13px; }

.section-header {
  margin: 32px 0 14px;
}
.section-header h2 {
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-header p {
  margin-top: 4px;
}

/* Controls & Buttons */
button, input, select {
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  background: white;
  color: var(--ink);
  transition: all 0.15s ease;
}
button { cursor: pointer; }
button:hover { background: #f8fafc; border-color: #cbd5e1; }
button[aria-pressed=true], button.active {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
}
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 3px solid #f59e0b;
  outline-offset: 2px;
}

.toolbar { margin: 16px 0; }
.market-toggle-group button { font-weight: 600; font-size: 13.5px; }
.date-ctrls { display: flex; align-items: center; gap: 8px; font-size: 13px; }

#breadth-status {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
  padding: 4px 0;
}

/* 1. Overview Dashboard Section */
.overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 16px;
  margin-top: 12px;
}

.overview-card {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.03);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ov-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.ov-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 6px;
}
.ov-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 12px;
}
.ov-badge-bull { background: var(--bull-bg); color: var(--bull); border: 1px solid #a7f3d0; }
.ov-badge-bear { background: var(--bear-bg); color: var(--bear); border: 1px solid #fecaca; }
.ov-badge-neutral { background: #f1f5f9; color: #475569; border: 1px solid #cbd5e1; }

.ov-body {
  display: flex;
  gap: 18px;
  align-items: center;
}

/* Circular Radial Meter */
.radial-meter {
  position: relative;
  width: 96px;
  height: 96px;
  flex-shrink: 0;
}
.radial-meter svg {
  transform: rotate(-90deg);
  width: 96px;
  height: 96px;
}
.radial-bg {
  fill: none;
  stroke: #e2e8f0;
  stroke-width: 8;
}
.radial-fill {
  fill: none;
  stroke: var(--teal);
  stroke-width: 8;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.8s ease;
}
.radial-fill.is-bear { stroke: #f97316; }
.radial-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}
.radial-val {
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
  color: var(--ink);
}
.radial-label {
  font-size: 10px;
  color: var(--muted);
  margin-top: 2px;
}

.ov-metrics {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.metric-bar-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.metric-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
}
.metric-bar-label strong {
  color: var(--ink);
}

/* Advance / Decline Segmented Momentum Bar */
.ad-momentum-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ad-stacked-bar {
  display: flex;
  height: 10px;
  border-radius: 6px;
  overflow: hidden;
  background: #e2e8f0;
  width: 100%;
}
.ad-seg-adv { background: var(--bull); transition: width 0.3s; }
.ad-seg-unch { background: var(--neutral); transition: width 0.3s; }
.ad-seg-dec { background: var(--bear); transition: width 0.3s; }

.ad-legend {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--muted);
}
.ad-legend span { display: inline-flex; align-items: center; gap: 3px; }
.ad-adv-txt { color: var(--bull); font-weight: 600; }
.ad-dec-txt { color: var(--bear); font-weight: 600; }

/* 2. Eight Basket Cards */
.cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.breadth-card {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 1px 2px rgba(0,0,0,0.02);
  transition: transform 0.15s, box-shadow 0.15s;
}
.breadth-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.breadth-card .card-head {
  margin-bottom: 12px;
}
.breadth-card .subtitle {
  font-size: 11.5px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.breadth-card h3 {
  margin: 6px 0 0;
  font-size: 16px;
  font-weight: 700;
  color: #102a35;
  min-height: 40px;
  line-height: 1.35;
}

/* Gauge comparisons inside basket cards */
.card-gauges {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 10px 0 14px;
}
.gauge-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.gauge-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
}
.gauge-pct {
  font-weight: 700;
  color: var(--ink);
}
.gauge-pct.is-bull { color: var(--teal); }
.gauge-pct.is-bear { color: #c2410c; }

.gauge-track {
  position: relative;
  height: 8px;
  background: #e5eceb;
  border-radius: 4px;
  overflow: visible;
}
.gauge-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--teal);
  transition: width 0.4s ease;
}
.gauge-fill.is-bear { background: #f97316; }
.gauge-fill.is-ma200 { background: var(--amber); }

/* Center 50% benchmark tick */
.gauge-tick-50 {
  position: absolute;
  left: 50%;
  top: -2px;
  bottom: -2px;
  width: 2px;
  background: rgba(0,0,0,0.25);
  border-radius: 1px;
}

.breadth-card .pending-box {
  background: #fffbeb;
  border: 1px dashed #fcd34d;
  border-radius: 8px;
  padding: 16px 12px;
  margin: 12px 0;
  text-align: center;
}
.breadth-card .pending-title {
  color: var(--amber);
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 4px;
}

.card-footer {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.5;
}

/* 3. History Chart Section */
.history-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.history-card {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}
.history-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.history-card h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}
.history-current-pill {
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  background: #f1f5f9;
}

.chart-svg-wrap {
  position: relative;
  width: 100%;
}
.history-card svg {
  width: 100%;
  height: auto;
  overflow: visible;
}
.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(15, 23, 42, 0.92);
  color: white;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 11.5px;
  line-height: 1.4;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  transform: translate(-50%, -120%);
  display: none;
  z-index: 10;
}

/* 4. Sectors & Industries Visual Views */
.groups-toolbar {
  margin: 0 0 12px;
}
.view-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.view-switch-group {
  display: flex;
  background: #e2e8f0;
  padding: 3px;
  border-radius: 8px;
  gap: 2px;
}
.view-btn {
  border: none;
  background: transparent;
  padding: 6px 12px;
  font-size: 12.5px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  color: #475569;
}
.view-btn.active {
  background: white;
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.filter-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
  background: #edf3f2;
  padding: 10px 14px;
  border-radius: 10px;
}
.sort-ctrls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.sort-pill {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  background: white;
  border: 1px solid var(--line);
  color: var(--muted);
}
.sort-pill.active {
  background: var(--teal);
  color: white;
  border-color: var(--teal);
}
.search-ctrls {
  display: flex;
  align-items: center;
  gap: 8px;
}
.search-ctrls input {
  padding: 6px 12px;
  font-size: 13px;
  min-width: 240px;
}

/* Visual Horizontal Bar Chart View */
.groups-chart-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.group-bar-row {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 16px;
  display: grid;
  grid-template-columns: 200px 1fr 180px;
  align-items: center;
  gap: 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.02);
  transition: border-color 0.15s, transform 0.15s;
}
.group-bar-row:hover {
  border-color: #94a3b8;
  transform: translateY(-1px);
}

.bar-row-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.bar-row-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 14.5px;
  color: var(--ink);
}
.bar-row-en {
  font-size: 11px;
  color: var(--muted);
}
.bar-row-count {
  font-size: 11px;
  color: #64748b;
  margin-top: 2px;
}

/* Center Dual Bar Graphic */
.bar-row-visual {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.bar-track-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.bar-metric-track {
  position: relative;
  width: 100%;
  height: 18px;
  background: #e6eded;
  border-radius: 6px;
  overflow: hidden;
}
.bar-metric-fill {
  height: 100%;
  background: var(--teal);
  border-radius: 6px;
  display: flex;
  align-items: center;
  padding: 0 8px;
  color: white;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  transition: width 0.4s ease;
}
.bar-metric-fill.is-bear { background: #f97316; }
.bar-metric-fill.is-deep-bear { background: #ef4444; }

.bar-track-50mark {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(15, 23, 42, 0.2);
  z-index: 2;
}

.bar-sub-track {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
}
.mini-line-track {
  flex: 1;
  height: 4px;
  background: #e2e8f0;
  border-radius: 2px;
  overflow: hidden;
}
.mini-line-fill {
  height: 100%;
  background: var(--amber);
  border-radius: 2px;
}

/* Right Column: A/D & Net */
.bar-row-ad {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}
.bar-ad-badge {
  font-size: 12px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
}
.bar-ad-badge.pos { background: var(--bull-bg); color: var(--bull); }
.bar-ad-badge.neg { background: var(--bear-bg); color: var(--bear); }
.bar-ad-mini-bar {
  width: 120px;
  height: 6px;
  display: flex;
  border-radius: 3px;
  overflow: hidden;
  background: #e2e8f0;
}

/* Matrix Tiles View */
.groups-matrix-container {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}
.matrix-quadrant {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.quadrant-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}
.quadrant-title {
  font-size: 14.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}
.quadrant-cards-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.quadrant-item {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Data Table View */
.table-wrap {
  overflow-x: auto;
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
table {
  border-collapse: collapse;
  width: 100%;
  white-space: nowrap;
  text-align: left;
}
th, td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
th {
  background: #eaf1ef;
  color: #45616c;
}
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { background: #dce7e4; }
th.sortable.active { background: #d3e1dd; color: #102d33; font-weight: 700; }
th.sortable.active .sort-icon { color: var(--teal); }

.cell-metric { display: flex; align-items: center; gap: 8px; }
.pct-val { font-weight: 700; min-width: 48px; }
.pct-val.is-bull { color: var(--teal); }
.pct-val.is-bear { color: #5a717a; }
.mini-track { flex: 1; min-width: 45px; max-width: 75px; height: 6px; background: #e5eceb; border-radius: 4px; overflow: hidden; }
.mini-fill { height: 100%; background: #94abb3; border-radius: 4px; }
.mini-fill.is-bull { background: var(--teal); }

.mkt-tag { font-size: 10.5px; font-weight: 700; padding: 2px 5px; border-radius: 4px; line-height: 1; }
.tag-hk { background: rgba(14, 76, 157, 0.12); color: #0e4c9d; }
.tag-us { background: rgba(165, 102, 24, 0.14); color: #8c5310; }

.net-pos { color: var(--bull); font-weight: 700; }
.net-neg { color: var(--bear); font-weight: 700; }

details {
  background: #eaf1ef;
  padding: 18px;
  margin-top: 30px;
  border-radius: var(--radius);
}
footer { padding: 24px 0; }

/* Responsive adjustments */
@media (max-width: 1050px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .history-grid { grid-template-columns: 1fr; }
  .groups-matrix-container { grid-template-columns: 1fr; }
  .group-bar-row { grid-template-columns: 160px 1fr 140px; }
}

@media (max-width: 640px) {
  .breadth-page { padding: 16px 12px; }
  .cards { grid-template-columns: 1fr; }
  .overview-grid { grid-template-columns: 1fr; }
  .group-bar-row {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .bar-row-ad { align-items: flex-start; }
  .search-ctrls input { min-width: 100%; }
}
