:root {
  --bg-page: #F8FAFC;
  --bg-card: #FFFFFF;
  --bg-subtle: #F1F5F9;
  --bg-hover: #F8FAFC;
  --border-color: #E2E8F0;
  --border-strong: #CBD5E1;

  --text-primary: #0F172A;
  --text-secondary: #475569;
  --text-muted: #64748B;

  --brand-primary: #2563EB;
  --brand-hover: #1D4ED8;
  --brand-light: #EFF6FF;

  --pos-text: #047857;
  --pos-bg: #ECFDF5;
  --pos-border: #A7F3D0;

  --neg-text: #BE123C;
  --neg-bg: #FFF1F2;
  --neg-border: #FECDD3;

  --neutral-text: #475569;
  --neutral-bg: #F1F5F9;

  --shadow-sm: 0 1px 2px 0 rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.06), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 25px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.04);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 64px;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
}

/* Barra Superior */
.topbar {
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: var(--shadow-sm);
  padding-top: env(safe-area-inset-top, 0px);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 14px;
  padding-bottom: 12px;
  gap: 20px;
  flex-wrap: wrap;
}

/* Pestañas principales (Acciones / Cryptos) alineadas a la izquierda */
.nav-tabs-wrapper {
  display: flex;
  justify-content: flex-start;
  border-top: 1px solid var(--bg-subtle);
  padding-top: 4px;
}

.main-nav-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  white-space: nowrap;
  width: 100%;
}

.main-nav-tabs::-webkit-scrollbar {
  display: none;
}

.main-nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  flex-shrink: 0;
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.16s ease;
}

.main-nav-tab:hover {
  color: var(--text-primary);
  background: var(--bg-page);
  border-radius: 8px 8px 0 0;
}

.main-nav-tab.active {
  color: var(--brand-primary);
  border-bottom-color: var(--brand-primary);
}

.nav-tab-icon {
  font-size: 1rem;
  line-height: 1;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, #2563EB 0%, #1D4ED8 100%);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

.brand h1 {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.subtitle {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 500;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.market-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: 4px;
}

.meta-pill {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.meta-pill strong {
  color: var(--text-primary);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.78rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #10B981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

/* Botones */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.18s ease;
}

.btn-primary {
  background: var(--brand-primary);
  color: #FFFFFF;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.22);
}

.btn-primary:hover {
  background: var(--brand-hover);
  transform: translateY(-1px);
}

.btn-primary:disabled {
  opacity: 0.7;
  cursor: wait;
  transform: none;
}

.btn-secondary {
  background: #FFFFFF;
  color: var(--text-primary);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
  background: var(--bg-subtle);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: var(--bg-subtle);
}

.btn-danger {
  background: var(--neg-bg);
  color: var(--neg-text);
  border-color: var(--neg-border);
}

.btn-danger:hover {
  background: #FFE4E6;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinning {
  animation: spin 0.9s linear infinite;
}

/* Contenido Principal */
.main-content {
  margin-top: 28px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Tarjetas KPI */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.kpi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.kpi-title {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.kpi-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1rem;
}

.kpi-icon-blue {
  background: var(--brand-light);
  color: var(--brand-primary);
}

.kpi-icon-slate {
  background: var(--bg-subtle);
  color: var(--text-secondary);
}

.kpi-icon-pos {
  background: var(--pos-bg);
  color: var(--pos-text);
}

.kpi-icon-neg {
  background: var(--neg-bg);
  color: var(--neg-text);
}

.kpi-value-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

.kpi-value {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  font-family: 'Plus Jakarta Sans', sans-serif;
  color: var(--text-primary);
}

.kpi-footer {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--bg-subtle);
}

.kpi-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Badges de Ganancia / Pérdida */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  border: 1px solid transparent;
}

.badge-pos {
  background-color: var(--pos-bg);
  color: var(--pos-text);
  border-color: var(--pos-border);
}

.badge-neg {
  background-color: var(--neg-bg);
  color: var(--neg-text);
  border-color: var(--neg-border);
}

.badge-neutral {
  background-color: var(--neutral-bg);
  color: var(--neutral-text);
  border-color: var(--border-color);
}

.text-pos {
  color: var(--pos-text) !important;
}

.text-neg {
  color: var(--neg-text) !important;
}

/* Tarjetas de Gráficos y Tabla */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 24px;
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.card-header h2 {
  font-size: 1.125rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.card-subtitle {
  font-size: 0.825rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: stretch;
}

.chart-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.distribution-layout {
  display: grid;
  grid-template-columns: 205px 1fr;
  gap: 20px;
  align-items: center;
  justify-content: center;
  flex: 1;
  margin: auto 0;
}

.doughnut-wrapper {
  position: relative;
  height: 220px;
  width: 205px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.distribution-legend {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 10px;
  align-content: center;
}

.legend-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 0.72rem;
  padding: 5px 9px;
  border-radius: 7px;
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  white-space: nowrap;
  overflow: hidden;
}

.legend-left {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  color: var(--text-primary);
  font-size: 0.72rem;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 3px;
  flex-shrink: 0;
}

.legend-right {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
  font-size: 0.69rem;
  color: var(--text-secondary);
  text-align: right;
}

.bar-wrapper {
  position: relative;
  height: 280px;
  width: 100%;
  margin: auto 0;
}

.bar-wrapper-tall {
  position: relative;
  height: 320px;
  width: 100%;
}

.chart-tabs {
  display: flex;
  background: var(--bg-subtle);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
}

.tab-btn,
.history-tab-btn,
.lt-filter-btn {
  border: none;
  background: transparent;
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-secondary);
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tab-btn.active,
.history-tab-btn.active,
.lt-filter-btn.active {
  background: #FFFFFF;
  color: var(--brand-primary);
  box-shadow: var(--shadow-sm);
}

.history-header-right {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.history-stats {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.history-pill {
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 600;
}

.history-pill strong {
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-primary);
}

/* Tabla de Posiciones */
.table-card {
  padding: 0;
  overflow: visible;
}

.table-header-bar {
  padding: 22px 24px 18px 24px;
  margin-bottom: 0;
  border-bottom: 1px solid var(--border-color);
}

.table-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-sm {
  padding: 8px 13px;
  font-size: 0.82rem;
}

.col-config-wrapper {
  position: relative;
}

.col-config-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 310px;
  background: #FFFFFF;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 14px;
  z-index: 60;
}

.col-popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.84rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.btn-link {
  background: none;
  border: none;
  color: var(--brand-primary);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.btn-link:hover {
  text-decoration: underline;
}

.col-popover-hint {
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.col-config-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 310px;
  overflow-y: auto;
}

.col-config-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
}

.col-move-btns {
  display: flex;
  gap: 4px;
}

.col-move-btn {
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  border-radius: 5px;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  cursor: pointer;
  color: var(--text-secondary);
}

.col-move-btn:hover:not(:disabled) {
  background: var(--brand-light);
  color: var(--brand-primary);
  border-color: #BFDBFE;
}

.col-move-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.portfolio-table th[draggable="true"] {
  cursor: grab;
}

.portfolio-table th.drag-over-col {
  background: var(--brand-light) !important;
  box-shadow: inset 3px 0 0 var(--brand-primary);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 8px 14px;
  width: 280px;
}

.search-box input {
  border: none;
  background: transparent;
  outline: none;
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--text-primary);
  width: 100%;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.portfolio-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.portfolio-table th {
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
  user-select: none;
}

.portfolio-table th.sortable {
  cursor: pointer;
  transition: background 0.15s;
}

.portfolio-table th.sortable:hover {
  background: #E2E8F0;
  color: var(--text-primary);
}

.portfolio-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.9rem;
  vertical-align: middle;
  white-space: nowrap;
}

.portfolio-table tbody tr:hover {
  background-color: #F8FAFC;
}

.text-right {
  text-align: right;
}

.text-center {
  text-align: center;
}

.ticker-cell {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ticker-badge {
  min-width: 68px;
  text-align: center;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--brand-light);
  color: var(--brand-primary);
  font-family: 'JetBrains Mono', monospace;
  font-weight: 800;
  font-size: 0.82rem;
  border: 1px solid #BFDBFE;
}

.company-info {
  display: flex;
  flex-direction: column;
}

.company-name {
  font-weight: 700;
  color: var(--text-primary);
  font-size: 0.88rem;
}

.currency-tag {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 600;
}

.mono-num {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
}

.mono-bold {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  color: var(--text-primary);
}

.price-sub {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-top: 2px;
}

.weight-cell {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.weight-bar-bg {
  width: 52px;
  height: 6px;
  background: var(--bg-subtle);
  border-radius: 999px;
  overflow: hidden;
}

.weight-bar-fill {
  height: 100%;
  background: var(--brand-primary);
  border-radius: 999px;
}

.row-action-btn {
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.row-action-btn:hover {
  background: var(--brand-light);
  color: var(--brand-primary);
  border-color: #BFDBFE;
}

.portfolio-table tfoot td {
  background: #F8FAFC;
  font-weight: 800;
  font-size: 0.95rem;
  border-top: 2px solid var(--border-strong);
  border-bottom: none;
  padding: 16px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.hidden {
  display: none !important;
}

.modal-content {
  background: #FFFFFF;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 560px;
  padding: 28px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 800;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.6rem;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
  width: 100%;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-group label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.form-group input[type="text"],
.form-group input[type="number"] {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text-primary);
  outline: none;
}

.form-group input:focus {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.form-hint {
  font-size: 0.74rem;
  color: var(--text-muted);
}

.operation-selector {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.op-option {
  border: 1px solid var(--border-color);
  background: var(--bg-page);
  padding: 10px;
  border-radius: 8px;
  text-align: center;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 700;
  transition: all 0.15s;
}

.op-option input {
  display: none;
}

.op-option.active {
  background: var(--brand-light);
  border-color: var(--brand-primary);
  color: var(--brand-primary);
}

.modal-info-box {
  background: var(--bg-subtle);
  border-left: 4px solid var(--brand-primary);
  padding: 12px 14px;
  border-radius: 6px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-actions-right {
  display: flex;
  gap: 10px;
  margin-left: auto;
}

/* Pantalla de Desbloqueo (Cifrado Cliente) */
.unlock-overlay {
  position: fixed;
  inset: 0;
  background: rgba(248, 250, 252, 0.96);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 150;
  padding: 20px;
}

.unlock-card {
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 32px 28px;
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.unlock-icon {
  width: 52px;
  height: 52px;
  margin: 0 auto 14px auto;
  border-radius: 14px;
  background: var(--brand-light);
  color: var(--brand-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.unlock-card h2 {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.unlock-desc {
  font-size: 0.84rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.unlock-card .form-group {
  text-align: left;
}

.unlock-card input[type="password"] {
  padding: 11px 13px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text-primary);
  outline: none;
  width: 100%;
}

.unlock-card input[type="password"]:focus {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.unlock-error {
  color: var(--neg-text);
  background: var(--neg-bg);
  border: 1px solid var(--neg-border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 14px;
}

.unlock-submit-btn {
  width: 100%;
  padding: 12px 16px;
}

.stacked-bar-svg {
  display: block;
  width: 100%;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--border-color);
}

.weight-progress {
  width: 52px;
  height: 6px;
  appearance: none;
  -webkit-appearance: none;
  border: none;
  border-radius: 999px;
  overflow: hidden;
  background: var(--bg-subtle);
}

.weight-progress::-webkit-progress-bar {
  background: var(--bg-subtle);
  border-radius: 999px;
}

.weight-progress::-webkit-progress-value {
  background: var(--brand-primary);
  border-radius: 999px;
}

.weight-progress::-moz-progress-bar {
  background: var(--brand-primary);
  border-radius: 999px;
}

/* Clases de color estáticas para cumplir CSP style-src 'self' sin estilos en línea */
.dot-risk-high { background-color: #E11D48; }
.dot-risk-mod { background-color: #2563EB; }
.dot-risk-safe { background-color: #059669; }
.dot-cur-eur { background-color: #2563EB; }
.dot-cur-usd { background-color: #D97706; }

.dot-c0 { background-color: #2563EB; }
.dot-c1 { background-color: #059669; }
.dot-c2 { background-color: #7C3AED; }
.dot-c3 { background-color: #EA580C; }
.dot-c4 { background-color: #0891B2; }
.dot-c5 { background-color: #D97706; }
.dot-c6 { background-color: #DB2777; }
.dot-c7 { background-color: #4F46E5; }
.dot-c8 { background-color: #0D9488; }
.dot-c9 { background-color: #65A30D; }
.dot-c10 { background-color: #E11D48; }
.dot-c11 { background-color: #6366F1; }
.dot-c12 { background-color: #0284C7; }
.dot-c13 { background-color: #9333EA; }
.dot-c14 { background-color: #475569; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #0F172A;
  color: #FFFFFF;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 0.875rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 200;
}

.view-stack {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Hall of Fame (Balance Histórico) */
.hof-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hof-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--bg-page);
  border: 1px solid var(--border-color);
}

.hof-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.hof-rank {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.hof-meta {
  display: flex;
  flex-direction: column;
}

.hof-title {
  font-weight: 800;
  font-size: 0.88rem;
  color: var(--text-primary);
}

.hof-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.hof-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Panel de Métricas Globales (Salud del Patrimonio) */
.insights-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.insight-box {
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.insight-title {
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.stacked-bar {
  display: flex;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--border-color);
  gap: 2px;
}

.stacked-seg {
  height: 100%;
  border-radius: 999px;
}

.insight-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.8rem;
}

.insight-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.insight-row-label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-weight: 600;
}

.insight-dot {
  width: 8px;
  height: 8px;
  border-radius: 3px;
  flex-shrink: 0;
}

.insight-row-val {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  color: var(--text-primary);
}

/* Cuadros Principales Reordenables */
.widgets-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
  align-items: stretch;
}

.widgets-grid > [data-span="1"] {
  grid-column: span 1;
}

.widgets-grid > [data-span="2"] {
  grid-column: span 2;
}

/* Modo Edición de Diseño */
.btn-layout-active {
  background: var(--brand-primary) !important;
  color: #FFFFFF !important;
  border-color: var(--brand-primary) !important;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

.layout-editing [data-widget-id],
.layout-editing [data-kpi-id] {
  position: relative;
  outline: 2px dashed #93C5FD;
  outline-offset: 2px;
  cursor: grab;
  transition: transform 0.15s ease, outline-color 0.15s ease;
}

.layout-editing [data-widget-id]:hover,
.layout-editing [data-kpi-id]:hover {
  outline-color: var(--brand-primary);
}

.layout-editing .drag-over-widget {
  outline: 2px solid var(--brand-primary) !important;
  background-color: #F0F7FF !important;
}

.widget-edit-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  background: #EFF6FF;
  border: 1px solid #BFDBFE;
  border-radius: 8px;
  padding: 5px 10px;
  margin-bottom: 12px;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--brand-primary);
  user-select: none;
}

.table-card .widget-edit-bar {
  margin: 12px 16px 0 16px;
}

.widget-edit-handle {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: grab;
}

.widget-edit-btns {
  display: flex;
  align-items: center;
  gap: 4px;
}

.widget-ctrl-btn {
  background: #FFFFFF;
  border: 1px solid #BFDBFE;
  color: var(--brand-primary);
  border-radius: 6px;
  padding: 2px 7px;
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.12s;
}

.widget-ctrl-btn:hover:not(:disabled) {
  background: var(--brand-primary);
  color: #FFFFFF;
}

.widget-ctrl-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

/* Responsive */
@media (max-width: 1150px) {
  .kpi-grid,
  .insights-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .charts-grid,
  .widgets-grid {
    grid-template-columns: 1fr;
  }
  .widgets-grid > [data-span="1"],
  .widgets-grid > [data-span="2"] {
    grid-column: span 1;
  }
}

@media (max-width: 680px) {
  body {
    padding-bottom: calc(48px + env(safe-area-inset-bottom, 0px));
  }
  .container {
    padding: 0 14px;
  }
  .topbar-inner {
    padding-top: 10px;
    padding-bottom: 10px;
    gap: 10px;
  }
  .brand h1 {
    font-size: 1.05rem;
  }
  .subtitle {
    font-size: 0.72rem;
  }
  .market-meta {
    width: 100%;
    justify-content: space-between;
    margin-right: 0;
  }
  .topbar-actions {
    width: 100%;
    gap: 8px;
  }
  .topbar-actions .btn {
    flex: 1 1 auto;
    padding: 9px 10px;
    font-size: 0.8rem;
  }
  .kpi-grid,
  .insights-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .kpi-value {
    font-size: 1.65rem;
  }
  .card {
    padding: 16px;
  }
  .distribution-layout {
    grid-template-columns: 1fr;
  }
  .search-box {
    width: 100%;
  }
  .form-row {
    grid-template-columns: 1fr;
  }
}
