/* styles.css */

:root {
  --bg: #0b1120;
  --card-bg: #131d31;
  --card-inner: #0b1329;
  --card-highlight: #1e2c4a;
  --accent: #38bdf8;
  --accent-hover: #0284c7;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --border: #243452;
  --success: #34d399;
  --danger: #f87171;
  --warning: #fbbf24;
  --benchmark: #a78bfa;
  --category: #f59e0b;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

html, body {
  width: 100%;
  min-height: 100vh;
  background-color: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

body {
  padding: 0.75rem 0.5rem;
  display: flex;
  justify-content: center;
}

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
}

@media (max-width: 640px) {
  body {
    padding: 0.35rem 0.2rem;
  }
  .card {
    padding: 0.85rem 0.5rem !important;
    border-radius: 6px !important;
    margin-bottom: 0.75rem !important;
  }
  .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;
  }
  .data-table th.col-fund-name, 
  .data-table td.col-fund-name {
    width: 140px !important;
    min-width: 140px !important;
    max-width: 140px !important;
  }
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.75rem;
  margin-bottom: 1rem;
}

h1 {
  font-size: 1.35rem;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: -0.5px;
}

.nav {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.nav-btn {
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 500;
  transition: 0.2s;
}

.nav-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: bold;
  background: rgba(56, 189, 248, 0.1);
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}

.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;
}

input[type="text"] {
  flex: 1;
  background: var(--card-inner);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.65rem 0.85rem;
  color: var(--text);
  outline: none;
  font-size: 0.85rem;
}

input[type="text"]:focus {
  border-color: var(--accent);
}

button.btn {
  background: var(--accent);
  color: #0f172a;
  border: none;
  padding: 0.6rem 1.1rem;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.2s;
  font-size: 0.82rem;
  white-space: nowrap;
}

button.btn:hover {
  background: var(--accent-hover);
}

.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);
}

.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);
}

.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;
}

/* Explicit Status State Indicators */
.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;
}

.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;
}

.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-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-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);
}

/* Universal Viewport-Safe Fixed Tooltip */
#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: 1000;
  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);
}
