/**
 * @file prod/css/fund-styles.css
 * @description Factsheet card layout, stat grids, canvas visualizer stacks, allocation donuts, tables, and tooltips.
 * @dependencies prod/css/global-styles.css
 * @status Active
 * @nextSteps Add micro-sparklines styling for screener tables.
 */

/* Fund Factsheet Header */
.fund-header-card {
  background: var(--card-inner);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.1rem;
  margin-bottom: 1.25rem;
}

.fund-meta-pill-box {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.65rem 0;
}

.pill {
  background: rgba(30, 41, 59, 0.7);
  border: 1px solid var(--border);
  font-size: 0.75rem;
  padding: 0.25rem 0.55rem;
  border-radius: 4px;
  color: var(--text-muted);
}

.pill strong {
  color: var(--text);
}

/* Filter Tag & Search */
.filter-bar {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.filter-tag {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.filter-tag input {
  accent-color: var(--accent);
  cursor: pointer;
}

.search-box {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  position: relative;
}

.results-list {
  list-style: none;
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 1rem;
  padding: 0;
  background: var(--card-inner);
}

.results-list li {
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.85rem;
}

.results-list li:hover {
  background: #1e293b;
  color: var(--accent);
}

/* Stat Boxes & Value Modifiers */
.section-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 1.4rem 0 0.65rem 0;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.section-title {
  font-size: 0.85rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.period-tabs {
  display: flex;
  gap: 0.2rem;
  background: var(--card-inner);
  padding: 0.2rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  overflow-x: auto;
}

.period-tab {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  padding: 0.3rem 0.55rem;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 500;
  transition: 0.15s;
  white-space: nowrap;
}

.period-tab.active {
  background: var(--accent);
  color: #0b1120;
  font-weight: bold;
}

.grid-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
  gap: 0.65rem;
  margin-bottom: 0.75rem;
}

.stat-box {
  background: var(--card-inner);
  border: 1px solid var(--border);
  padding: 0.75rem 0.6rem;
  border-radius: 6px;
  text-align: center;
  position: relative;
  cursor: help;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
  text-transform: uppercase;
  font-weight: 500;
}

.stat-val {
  font-size: 1.05rem;
  font-weight: bold;
  color: var(--text);
}

.stat-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  font-weight: 500;
}

.positive { color: var(--success) !important; }
.negative { color: var(--danger) !important; }

.val-estimated {
  color: var(--warning);
  font-weight: 500;
  border-bottom: 1px dashed var(--warning);
  cursor: help;
  display: inline-block;
}

.val-missing {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-style: italic;
}

.val-wip {
  color: var(--warning);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.2px;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

/* Dual-Layer Canvas Graphs */
.chart-scroll-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-inner);
}

.chart-box-main {
  background: var(--card-inner);
  border-radius: 8px;
  padding: 1rem;
  text-align: center;
  position: relative;
  height: 280px;
}

.chart-box-main canvas {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.chart-legend-top {
  position: relative;
  z-index: 10;
  display: flex;
  justify-content: center;
  gap: 1.25rem;
  font-size: 0.78rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

.legend-indicator {
  width: 10px;
  height: 3px;
  border-radius: 2px;
  display: inline-block;
  vertical-align: middle;
  margin-right: 0.3rem;
}

/* Allocations & Donut Charts */
.unified-alloc-card {
  background: var(--card-inner);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  margin-top: 0.75rem;
}

.alloc-tabs-header {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.alloc-tab-btn {
  background: #1e293b;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.4rem 0.85rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 500;
  transition: 0.2s;
}

.alloc-tab-btn.active {
  background: #0284c7;
  border-color: var(--accent);
  color: #fff;
  font-weight: bold;
}

.alloc-pane { display: none; }
.alloc-pane.active { display: block; }

.donut-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

@media (min-width: 640px) {
  .donut-layout {
    flex-direction: row;
    justify-content: space-around;
  }
}

.donut-wrapper {
  position: relative;
  width: 150px;
  height: 150px;
  flex-shrink: 0;
}

.alloc-table-view {
  width: 100%;
  max-width: 440px;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.alloc-table-view td {
  padding: 0.55rem 0.4rem;
  border-bottom: 1px solid rgba(51, 65, 85, 0.4);
}

.alloc-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 0.45rem;
}

/* Data Tables */
.data-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-top: 0.5rem;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.data-table th, .data-table td {
  padding: 0.65rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table th.col-fund-name, 
.data-table td.col-fund-name {
  white-space: normal !important;
  word-wrap: break-word;
  width: 180px;
  min-width: 160px;
  max-width: 220px;
  line-height: 1.35;
}

.data-table th {
  background: #0c1527;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table td.numeric, .data-table th.numeric { text-align: right; }
.data-table th.header-group { text-align: center; border-bottom: 1px solid var(--border); background: #131e36; }

/* Watchlist & Tooltips */
.watchlist-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: 0.2s;
}

.watchlist-item:hover {
  background: rgba(56, 189, 248, 0.06);
}

#canvas-tooltip, #rolling-tooltip, #metric-tooltip {
  position: fixed;
  display: none;
  background: rgba(15, 23, 42, 0.96);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(56, 189, 248, 0.5);
  color: var(--text);
  padding: 0.55rem 0.8rem;
  border-radius: 7px;
  font-size: 0.75rem;
  pointer-events: none;
  z-index: 20000;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.75);
  width: max-content;
  max-width: min(280px, calc(100vw - 24px));
  line-height: 1.4;
  word-wrap: break-word;
  white-space: normal;
}

#rolling-tooltip { border-color: rgba(234, 179, 8, 0.6); }

/* Mobile Component Overrides */
@media (max-width: 640px) {
  .fund-header-card { padding: 0.85rem 0.5rem !important; }
  .grid-stats { grid-template-columns: repeat(auto-fit, minmax(105px, 1fr)) !important; gap: 0.4rem !important; }
  .stat-box { padding: 0.55rem 0.3rem !important; }
  .stat-val { font-size: 0.95rem !important; }
  .chart-box-main { padding: 0.5rem 0.2rem !important; height: 270px !important; }
}
