/* ═══════════════════════════════════════════════
   Variables y Reset
═══════════════════════════════════════════════ */
:root {
  --bg:           #f0f4f8;
  --bg-card:      #ffffff;
  --primary:      #2563eb;
  --primary-dk:   #1d4ed8;
  --primary-lt:   #dbeafe;
  --secondary:    #7c3aed;
  --secondary-lt: #ede9fe;
  --success:      #16a34a;
  --success-lt:   #dcfce7;
  --danger:       #dc2626;
  --danger-lt:    #fee2e2;
  --warning:      #d97706;
  --warning-lt:   #fef3c7;
  --text:         #1e293b;
  --text-muted:   #64748b;
  --text-light:   #94a3b8;
  --border:       #e2e8f0;
  --border-dk:    #cbd5e1;
  --shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md:    0 4px 12px rgba(0,0,0,.08), 0 2px 6px rgba(0,0,0,.05);
  --shadow-lg:    0 8px 24px rgba(0,0,0,.1),  0 4px 8px rgba(0,0,0,.06);
  --radius:       14px;
  --radius-sm:    8px;
  --radius-xs:    4px;
  --transition:   .2s ease;
  --font:         'Inter', system-ui, sans-serif;
  --enrique-color: #2563eb;
  --claude-color:  #7c3aed;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ═══════════════════════════════════════════════
   Utilidades
═══════════════════════════════════════════════ */
.up   { color: var(--success) !important; }
.down { color: var(--danger)  !important; }
.neutral { color: var(--text-muted) !important; }

.text-sm  { font-size: .8rem; }
.text-xs  { font-size: .72rem; }
.text-lg  { font-size: 1.1rem; }
.text-xl  { font-size: 1.3rem; }
.text-2xl { font-size: 1.6rem; }
.fw-600   { font-weight: 600; }
.fw-700   { font-weight: 700; }
.fw-800   { font-weight: 800; }
.mt-1  { margin-top: .5rem; }
.mt-2  { margin-top: 1rem; }
.opacity-60 { opacity: .6; }

/* ═══════════════════════════════════════════════
   Botones
═══════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1.1rem;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  user-select: none;
  text-decoration: none;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.btn-primary   { background: var(--primary);   color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dk); }

.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: var(--border-dk); }

.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled)  { background: #b91c1c; }

.btn-ghost     { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled)   { background: var(--bg); color: var(--text); }

.btn-sm  { padding: .32rem .75rem; font-size: .78rem; }
.btn-lg  { padding: .75rem 1.6rem; font-size: 1rem; }
.btn-block { width: 100%; justify-content: center; }

.btn-icon {
  width: 32px; height: 32px;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--border);
  color: var(--text);
  border: none;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 700;
  transition: var(--transition);
  flex-shrink: 0;
  user-select: none;
}
.btn-icon:hover:not(:disabled) { background: var(--border-dk); }
.btn-icon:active { transform: scale(.9); }
.btn-icon:disabled { opacity: .35; cursor: not-allowed; }

/* ═══════════════════════════════════════════════
   Badges
═══════════════════════════════════════════════ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: .18rem .55rem;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .01em;
}
.badge-up      { background: var(--success-lt); color: var(--success); }
.badge-down    { background: var(--danger-lt);  color: var(--danger); }
.badge-neutral { background: var(--border);     color: var(--text-muted); }
.badge-blue    { background: var(--primary-lt); color: var(--primary); }
.badge-purple  { background: var(--secondary-lt); color: var(--secondary); }

/* ═══════════════════════════════════════════════
   Cards
═══════════════════════════════════════════════ */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-header {
  padding: 1.1rem 1.4rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.card-body    { padding: 1.2rem 1.4rem; }
.card-footer  { padding: .8rem 1.4rem; border-top: 1px solid var(--border); background: #fafbfc; }

/* ═══════════════════════════════════════════════
   Input / Number stepper
═══════════════════════════════════════════════ */
.input {
  width: 100%;
  padding: .48rem .8rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: .9rem;
  color: var(--text);
  background: var(--bg-card);
  transition: border-color var(--transition);
  outline: none;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-lt); }

.stepper {
  display: flex;
  align-items: center;
  gap: .4rem;
}
.stepper input[type=number] {
  width: 64px;
  text-align: center;
  padding: .32rem .4rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: .88rem;
  color: var(--text);
  -moz-appearance: textfield;
  outline: none;
  transition: border-color var(--transition);
}
.stepper input[type=number]:focus { border-color: var(--primary); }
.stepper input[type=number]::-webkit-outer-spin-button,
.stepper input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; }

/* ═══════════════════════════════════════════════
   Spinner / Loading
═══════════════════════════════════════════════ */
@keyframes spin { to { transform: rotate(360deg); } }

.spinner {
  width: 44px; height: 44px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  gap: 1.2rem;
  color: var(--text-muted);
  font-size: .95rem;
}

/* ═══════════════════════════════════════════════
   PANTALLA DE CONFIGURACIÓN
═══════════════════════════════════════════════ */
.setup-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.setup-header {
  background: linear-gradient(135deg, var(--primary) 0%, #1a40c9 100%);
  color: #fff;
  padding: 1.4rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  box-shadow: 0 2px 8px rgba(37, 99, 235, .3);
}
.setup-header.claude-theme {
  background: linear-gradient(135deg, var(--secondary) 0%, #5b21b6 100%);
  box-shadow: 0 2px 8px rgba(124, 58, 237, .3);
}

.setup-header-left { display: flex; align-items: center; gap: 1rem; }
.setup-player-emoji {
  width: 52px; height: 52px;
  border-radius: 50%;
  background: rgba(255,255,255,.2);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem;
  flex-shrink: 0;
}
.setup-header h1  { font-size: 1.3rem; font-weight: 800; margin-bottom: .1rem; }
.setup-header p   { font-size: .85rem; opacity: .85; }

.setup-budget-info {
  text-align: right;
}
.setup-budget-info .budget-label { font-size: .78rem; opacity: .8; }
.setup-budget-info .budget-value {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -.5px;
}
.setup-budget-info .budget-value.over-budget { color: #fca5a5; }

.setup-body {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 1.4rem;
  padding: 1.4rem 2rem;
  flex: 1;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* Stock list panel */
.stocks-panel { display: flex; flex-direction: column; gap: .8rem; }

.search-bar { position: relative; }
.search-bar .search-icon {
  position: absolute; left: .85rem; top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted); font-size: 1rem;
}
.search-bar input {
  width: 100%;
  padding: .6rem .8rem .6rem 2.5rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: .9rem;
  background: var(--bg-card);
  outline: none;
  transition: border-color var(--transition);
}
.search-bar input:focus { border-color: var(--primary); }

.stocks-list {
  display: flex;
  flex-direction: column;
  gap: .45rem;
  max-height: calc(100vh - 220px);
  overflow-y: auto;
  padding-right: .3rem;
}
.stocks-list::-webkit-scrollbar { width: 5px; }
.stocks-list::-webkit-scrollbar-track { background: transparent; }
.stocks-list::-webkit-scrollbar-thumb { background: var(--border-dk); border-radius: 10px; }

.stock-item {
  display: flex;
  align-items: center;
  gap: .8rem;
  padding: .75rem 1rem;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  border: 1.5px solid transparent;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.stock-item:hover { border-color: var(--border-dk); }
.stock-item.selected { border-color: var(--primary); background: #f8fbff; }

.stock-item-ticker {
  min-width: 72px;
  font-weight: 700;
  font-size: .8rem;
  color: var(--primary);
  background: var(--primary-lt);
  padding: .2rem .5rem;
  border-radius: var(--radius-xs);
  letter-spacing: .02em;
  text-align: center;
}
.setup-screen .claude-theme ~ .setup-body .stock-item.selected { border-color: var(--secondary); background: #faf8ff; }
.setup-screen .claude-theme ~ .setup-body .stock-item-ticker { color: var(--secondary); background: var(--secondary-lt); }

.stock-item-name {
  flex: 1;
  font-size: .88rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stock-item-price {
  text-align: right;
  min-width: 100px;
}
.stock-item-price .price-val { font-weight: 700; font-size: .9rem; }
.stock-item-price .price-change { font-size: .75rem; margin-top: .1rem; }
.stock-item-cost {
  min-width: 80px;
  text-align: right;
  font-weight: 600;
  font-size: .82rem;
  color: var(--text-muted);
}
.stock-item-cost.has-cost { color: var(--text); }

/* Cart panel */
.cart-panel {
  display: flex;
  flex-direction: column;
  gap: 0;
  position: sticky;
  top: 1.4rem;
  height: fit-content;
  max-height: calc(100vh - 130px);
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.cart-header {
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: .95rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cart-items {
  flex: 1;
  overflow-y: auto;
  padding: .6rem;
  display: flex;
  flex-direction: column;
  gap: .4rem;
  max-height: 380px;
}
.cart-items::-webkit-scrollbar { width: 4px; }
.cart-items::-webkit-scrollbar-thumb { background: var(--border-dk); border-radius: 10px; }

.cart-empty {
  text-align: center;
  color: var(--text-light);
  font-size: .85rem;
  padding: 2rem 1rem;
}

.cart-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .6rem .8rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
  font-size: .83rem;
}
.cart-item-ticker {
  font-weight: 700;
  color: var(--primary);
  min-width: 65px;
  font-size: .78rem;
}
.cart-item-info { flex: 1; min-width: 0; }
.cart-item-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.cart-item-shares { color: var(--text-muted); font-size: .75rem; }
.cart-item-cost { font-weight: 700; min-width: 72px; text-align: right; font-size: .85rem; }
.cart-item-remove {
  background: none; border: none; cursor: pointer;
  color: var(--text-light); font-size: .95rem;
  padding: .1rem .2rem; border-radius: 4px;
  transition: color var(--transition);
  flex-shrink: 0;
}
.cart-item-remove:hover { color: var(--danger); }

.cart-summary {
  padding: .9rem 1.2rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: .45rem;
}
.cart-summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: .85rem;
  color: var(--text-muted);
}
.cart-summary-row.total {
  font-size: .95rem;
  font-weight: 700;
  color: var(--text);
  border-top: 1px solid var(--border);
  padding-top: .45rem;
  margin-top: .1rem;
}
.cart-summary-row.total .amount { font-size: 1.1rem; }
.cart-summary-row.total.over-budget .amount { color: var(--danger); }
.cart-summary-row.cash-left .amount { color: var(--success); font-weight: 600; }
.cart-summary-row.cash-left.over-budget .amount { color: var(--danger); }

.cart-progress {
  margin: .2rem 0;
  height: 6px;
  border-radius: 10px;
  background: var(--border);
  overflow: hidden;
}
.cart-progress-bar {
  height: 100%;
  border-radius: 10px;
  background: var(--primary);
  transition: width .3s ease;
}
.cart-progress-bar.over { background: var(--danger); }

.cart-footer { padding: .8rem 1.2rem; border-top: 1px solid var(--border); }

.budget-warning {
  text-align: center;
  color: var(--danger);
  font-size: .8rem;
  font-weight: 600;
  margin-bottom: .6rem;
  padding: .4rem .6rem;
  background: var(--danger-lt);
  border-radius: var(--radius-xs);
}

/* ═══════════════════════════════════════════════
   DASHBOARD
═══════════════════════════════════════════════ */
.dashboard { display: flex; flex-direction: column; min-height: 100vh; }

/* Header del dashboard */
.dash-header {
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.dash-header-inner {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0 2rem;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
  height: 64px;
}

.dash-brand {
  display: flex; align-items: center; gap: .6rem;
  font-size: 1.05rem; font-weight: 800; color: var(--text);
  white-space: nowrap; text-decoration: none;
}
.dash-brand-icon { font-size: 1.5rem; }

.dash-mini-lead {
  display: flex;
  gap: 1rem;
  flex: 1;
  justify-content: center;
}
.lead-player {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .35rem .8rem;
  border-radius: 20px;
  font-size: .83rem;
  font-weight: 600;
  background: var(--bg);
  border: 1.5px solid var(--border);
}
.lead-player.leader { border-color: var(--warning); background: var(--warning-lt); }
.lead-player-rank { font-size: .75rem; font-weight: 700; opacity: .7; }
.lead-player-change { font-size: .78rem; }

.dash-nav { display: flex; gap: .2rem; }
.nav-tab {
  padding: .42rem .9rem;
  border-radius: 20px;
  border: none;
  background: transparent;
  font-family: var(--font);
  font-size: .83rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
  transition: var(--transition);
  white-space: nowrap;
}
.nav-tab:hover { background: var(--bg); color: var(--text); }
.nav-tab.active { background: var(--primary); color: #fff; }

.dash-actions {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-shrink: 0;
}
.last-update { font-size: .72rem; color: var(--text-light); white-space: nowrap; }

/* Barra de top gainers */
.dash-top-gainers {
  display: flex;
  align-items: center;
  gap: .9rem;
  padding: 0 2rem;
  height: 32px;
  background: #f0fdf4;
  border-top: 1px solid #bbf7d0;
  overflow: hidden;
}
.tg-label {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--success);
  white-space: nowrap;
  flex-shrink: 0;
  padding-right: .4rem;
  border-right: 1px solid #bbf7d0;
}
.tg-item {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font-size: .76rem;
  white-space: nowrap;
}
.tg-ticker {
  font-weight: 700;
  color: var(--text);
}
.tg-pct {
  color: var(--success);
  font-weight: 600;
}
.tg-sep {
  color: var(--border-dk);
  font-size: .75rem;
  user-select: none;
}

/* Contenido del dashboard */
.dash-content {
  padding: 1.6rem 2rem;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
  flex: 1;
}

/* Tabs */
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ─── Tab Resumen ─── */
.overview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.4rem;
}

.portfolio-card { border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-md); }

.portfolio-card-header {
  padding: 1.2rem 1.4rem;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  color: #fff;
}
.portfolio-card-header.enrique-bg {
  background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
}
.portfolio-card-header.claude-bg {
  background: linear-gradient(135deg, #7c3aed 0%, #5b21b6 100%);
}

.pch-player {
  display: flex; align-items: center; gap: .7rem;
}
.pch-emoji { font-size: 1.8rem; }
.pch-name { font-size: 1.1rem; font-weight: 800; }
.pch-label { font-size: .78rem; opacity: .8; margin-top: .05rem; }

.pch-value { text-align: right; }
.pch-value-total {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -.5px;
  line-height: 1.1;
}
.pch-value-change {
  font-size: .88rem;
  margin-top: .15rem;
  opacity: .9;
  font-weight: 600;
}
.pch-value-change.positive { color: #bbf7d0; }
.pch-value-change.negative { color: #fecaca; }

.portfolio-card-body { background: var(--bg-card); }

.portfolio-stats {
  display: flex;
  padding: .9rem 1.4rem;
  border-bottom: 1px solid var(--border);
  gap: 1rem;
}
.stat-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: .15rem;
}
.stat-label { font-size: .72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.stat-value { font-size: .95rem; font-weight: 700; }
.stat-value.up   { color: var(--success); }
.stat-value.down { color: var(--danger); }

.portfolio-table-wrap {
  overflow-x: auto;
  max-height: 400px;
  overflow-y: auto;
}
.portfolio-table-wrap::-webkit-scrollbar { height: 4px; width: 4px; }
.portfolio-table-wrap::-webkit-scrollbar-thumb { background: var(--border-dk); border-radius: 10px; }

.portfolio-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
}
.portfolio-table th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  padding: .6rem .8rem;
  text-align: right;
  font-weight: 600;
  color: var(--text-muted);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.portfolio-table th:first-child,
.portfolio-table th:nth-child(2) { text-align: left; }
.portfolio-table td {
  padding: .65rem .8rem;
  border-bottom: 1px solid var(--border);
  text-align: right;
  color: var(--text);
  vertical-align: middle;
}
.portfolio-table td:first-child,
.portfolio-table td:nth-child(2) { text-align: left; }
.portfolio-table tbody tr:last-child td { border-bottom: none; }
.portfolio-table tbody tr:hover td { background: #f8fafc; }

.portfolio-table .td-ticker {
  font-weight: 700;
  font-size: .75rem;
  color: var(--primary);
  background: var(--primary-lt);
  padding: .18rem .45rem;
  border-radius: var(--radius-xs);
  white-space: nowrap;
}
.portfolio-table .td-name {
  max-width: 160px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}
.portfolio-table .td-value { font-weight: 700; }
.portfolio-table .td-gp { font-weight: 700; }
.portfolio-table .td-gp.up   { color: var(--success); }
.portfolio-table .td-gp.down { color: var(--danger); }

.portfolio-no-data {
  text-align: center;
  color: var(--text-light);
  padding: 2rem;
  font-size: .9rem;
}

.portfolio-footer {
  padding: .75rem 1.4rem;
  background: #f8fafc;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: .82rem;
}
.portfolio-footer .cash-label { color: var(--text-muted); }
.portfolio-footer .cash-amount { font-weight: 700; color: var(--text); }

/* ─── Tab Evolución ─── */
.chart-card { background: var(--bg-card); border-radius: var(--radius); box-shadow: var(--shadow-md); padding: 1.4rem; }
.chart-card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap; gap: .5rem;
}
.chart-card-title { font-size: 1rem; font-weight: 700; }
.chart-legend {
  display: flex;
  gap: 1.2rem;
}
.chart-legend-item {
  display: flex; align-items: center; gap: .4rem;
  font-size: .82rem; font-weight: 600; color: var(--text-muted);
}
.chart-legend-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.legend-item {
  display: inline-flex; align-items: center; gap: .4rem;
  font-size: .82rem; font-weight: 600;
}
.legend-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.chart-container { position: relative; height: 400px; }
.chart-no-data {
  display: flex; align-items: center; justify-content: center;
  height: 300px;
  flex-direction: column; gap: .5rem;
  color: var(--text-muted); font-size: .9rem;
  text-align: center;
}
.chart-disclaimer {
  text-align: center;
  font-size: .72rem;
  color: var(--text-light);
  margin-top: .6rem;
}

/* ─── Tab Clasificación ─── */
.leaderboard-wrap {
  max-width: 700px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.leaderboard-title {
  text-align: center;
  font-size: 1.3rem;
  font-weight: 800;
  margin-bottom: .5rem;
}

.leaderboard-card {
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  border: 2px solid transparent;
  transition: var(--transition);
}
.leaderboard-card.first-place {
  border-color: var(--warning);
  box-shadow: 0 4px 20px rgba(217, 119, 6, .15);
}

.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 1.2rem;
  padding: 1.2rem 1.4rem;
  background: var(--bg-card);
}

.lb-rank {
  width: 38px; height: 38px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  font-weight: 800;
  flex-shrink: 0;
  background: var(--bg);
  color: var(--text-muted);
}
.leaderboard-card.first-place .lb-rank {
  background: var(--warning-lt);
  color: var(--warning);
}

.lb-player {
  display: flex; align-items: center; gap: .7rem;
  flex: 1;
}
.lb-emoji { font-size: 1.7rem; }
.lb-name { font-size: 1.05rem; font-weight: 700; }
.lb-subtitle { font-size: .78rem; color: var(--text-muted); margin-top: .05rem; }

.lb-stats { text-align: right; }
.lb-total { font-size: 1.25rem; font-weight: 800; letter-spacing: -.3px; }
.lb-change { font-size: .85rem; font-weight: 600; margin-top: .15rem; }
.lb-change.up   { color: var(--success); }
.lb-change.down { color: var(--danger); }
.lb-change.neutral { color: var(--text-muted); }

.leaderboard-gap-card {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: .8rem 1.4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
  font-size: .85rem;
}
.leaderboard-gap-label { color: var(--text-muted); font-weight: 500; }
.leaderboard-gap-value { font-weight: 800; font-size: 1rem; }

/* ═══════════════════════════════════════════════
   Botón Operar
═══════════════════════════════════════════════ */
.btn-trade {
  background: rgba(37, 99, 235, .09);
  color: var(--primary);
  border: 1px solid rgba(37, 99, 235, .22);
}
.btn-trade:hover:not(:disabled) { background: rgba(37, 99, 235, .16); }

/* ═══════════════════════════════════════════════
   Modal de operaciones
═══════════════════════════════════════════════ */
.trade-modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 92%;
  max-width: 460px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: scaleIn .2s ease;
}

.trade-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .85rem 1.2rem;
  color: #fff;
  font-weight: 700;
  font-size: .95rem;
  flex-shrink: 0;
}
.trade-close {
  background: rgba(255,255,255,.2);
  border: none;
  color: #fff;
  width: 28px; height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: .85rem;
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
}
.trade-close:hover { background: rgba(255,255,255,.35); }

.trade-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.trade-tab {
  flex: 1;
  padding: .62rem;
  border: none;
  background: transparent;
  font-family: var(--font);
  font-size: .84rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
  border-bottom: 2.5px solid transparent;
  transition: var(--transition);
}
.trade-tab:hover { color: var(--text); background: var(--bg); }
.trade-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.trade-body {
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: .85rem;
  overflow-y: auto;
}
.trade-body::-webkit-scrollbar { width: 4px; }
.trade-body::-webkit-scrollbar-thumb { background: var(--border-dk); border-radius: 10px; }

.trade-cash-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .5rem .8rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
  font-size: .82rem;
  color: var(--text-muted);
}
.trade-cash-val { font-weight: 700; color: var(--text); }

.trade-field { display: flex; flex-direction: column; gap: .3rem; }
.trade-label {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
}
.trade-select {
  width: 100%;
  padding: .48rem .7rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: .87rem;
  color: var(--text);
  background: var(--bg-card);
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition);
}
.trade-select:focus { border-color: var(--primary); }

.trade-price-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: .81rem;
  color: var(--text-muted);
}
.trade-max-shares { font-size: .8rem; }

.trade-stepper { display: flex; align-items: center; gap: .45rem; }
.trade-max-hint { font-size: .77rem; color: var(--text-light); }

.trade-breakdown {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: .75rem .95rem;
  display: flex;
  flex-direction: column;
  gap: .38rem;
}
.trade-breakdown-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: .82rem;
  color: var(--text-muted);
}
.trade-breakdown-sep {
  border-top: 1px solid var(--border);
  margin: .1rem 0;
}
.trade-breakdown-total {
  font-weight: 700;
  font-size: .9rem;
  color: var(--text);
}
.trade-breakdown-danger { color: var(--danger) !important; font-weight: 600; }
.trade-commission { color: var(--warning); font-weight: 600; }

.trade-no-holdings {
  text-align: center;
  color: var(--text-light);
  padding: 1.5rem 0;
  font-size: .88rem;
}

/* ═══════════════════════════════════════════════
   Notificaciones / Toast
═══════════════════════════════════════════════ */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  z-index: 1000;
}
.toast {
  padding: .7rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: .5rem;
  animation: slideIn .25s ease;
  max-width: 320px;
  color: #fff;
}
.toast-success { background: var(--success); }
.toast-error   { background: var(--danger); }
.toast-info    { background: var(--primary); }
@keyframes slideIn {
  from { transform: translateX(120%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}
@keyframes slideOut {
  from { transform: translateX(0);    opacity: 1; }
  to   { transform: translateX(120%); opacity: 0; }
}

/* ═══════════════════════════════════════════════
   Modal de confirmación
═══════════════════════════════════════════════ */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 500;
  animation: fadeIn .15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 1.8rem;
  max-width: 380px;
  width: 90%;
  animation: scaleIn .2s ease;
}
@keyframes scaleIn {
  from { transform: scale(.94); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}
.modal h3 { font-size: 1rem; font-weight: 700; margin-bottom: .5rem; }
.modal p  { color: var(--text-muted); font-size: .88rem; margin-bottom: 1.2rem; }
.modal-actions { display: flex; gap: .6rem; justify-content: flex-end; }

/* ═══════════════════════════════════════════════
   Panel de detalle de empresa
═══════════════════════════════════════════════ */
.stock-detail-modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 92%;
  max-width: 360px;
  overflow: hidden;
  animation: scaleIn .2s ease;
}
.stock-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .9rem 1.2rem;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
}
.stock-detail-ticker {
  font-size: .72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: .2rem;
}
.stock-detail-name {
  font-size: .98rem;
  font-weight: 700;
  color: var(--text);
}
.stock-detail-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  color: var(--text-muted);
  padding: .3rem .5rem;
  border-radius: 4px;
  line-height: 1;
  flex-shrink: 0;
}
.stock-detail-close:hover { background: var(--border); }
.stock-detail-body {
  padding: 1.3rem 1.2rem 1rem;
}
.stock-detail-loading {
  text-align: center;
  color: var(--text-muted);
  padding: 1.4rem 0;
  font-size: .9rem;
}
.stock-detail-error { color: var(--danger); }
.stock-detail-price {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  margin-bottom: 1rem;
}
.stock-detail-rows { display: flex; flex-direction: column; gap: 0; }
.stock-detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: .875rem;
  padding: .5rem 0;
  border-bottom: 1px solid var(--border);
}
.stock-detail-row:last-child { border-bottom: none; }
.stock-detail-label { color: var(--text-muted); }
.stock-detail-value { font-weight: 600; }
.stock-detail-disclaimer {
  font-size: .72rem;
  color: var(--text-muted);
  margin-top: .9rem;
  margin-bottom: 0;
}

/* Nombres de empresa clicables */
.stock-name-link {
  cursor: pointer;
  transition: color .15s;
}
.stock-name-link:hover { color: var(--primary); text-decoration: underline; }
.td-name-link {
  cursor: pointer;
  transition: color .15s;
}
.td-name-link:hover { color: var(--primary); text-decoration: underline; }

/* ═══════════════════════════════════════════════
   Responsive
═══════════════════════════════════════════════ */
@media (max-width: 1024px) {
  .setup-body {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .cart-panel {
    position: static;
    max-height: none;
  }
  .stocks-list { max-height: 50vh; }
  .overview-grid { grid-template-columns: 1fr; }
  .dash-mini-lead { display: none; }
}

@media (max-width: 640px) {
  .setup-header { padding: 1rem 1.2rem; }
  .setup-body   { padding: 1rem 1.2rem; }
  .dash-content { padding: 1rem 1.2rem; }
  .dash-header-inner { padding: 0 1.2rem; gap: .8rem; }
  .dash-brand span { display: none; }
  .nav-tab { padding: .4rem .6rem; font-size: .78rem; }
  .portfolio-card-header { padding: 1rem; }
  .pch-value-total { font-size: 1.3rem; }
  .portfolio-stats { flex-wrap: wrap; }
  .stat-item { min-width: 45%; }
  .last-update { display: none; }
  .dash-top-gainers { padding: 0 1.2rem; gap: .6rem; }
}

/* ═══════════════════════════════════════════════
   Botón toggle modo oscuro
═══════════════════════════════════════════════ */
#btn-tema {
  position: fixed;
  bottom: 1.5rem;
  left: 1.5rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--bg-card);
  font-size: 1.1rem;
  cursor: pointer;
  z-index: 999;
  box-shadow: var(--shadow-md);
  transition: box-shadow var(--transition), transform var(--transition), background var(--transition), border-color var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
#btn-tema:hover { box-shadow: var(--shadow-lg); transform: scale(1.08); }

/* ═══════════════════════════════════════════════
   Modo oscuro — variables
═══════════════════════════════════════════════ */
html.dark {
  --bg:        #0f172a;
  --bg-card:   #1e293b;
  --text:      #e2e8f0;
  --text-muted:#94a3b8;
  --text-light:#64748b;
  --border:    #334155;
  --border-dk: #475569;
  --shadow:    0 1px 3px rgba(0,0,0,.35), 0 1px 2px rgba(0,0,0,.25);
  --shadow-md: 0 4px 12px rgba(0,0,0,.35), 0 2px 6px rgba(0,0,0,.25);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.45), 0 4px 8px rgba(0,0,0,.3);
}

/* Overrides de colores hardcodeados que no usan variables */
html.dark .dash-header              { background: var(--bg-card); }
html.dark .portfolio-table th       { background: #172032; }
html.dark .portfolio-table tbody tr:hover td { background: #172032; }
html.dark .portfolio-footer         { background: #172032; }
html.dark .card-footer              { background: #172032; }
html.dark .dash-top-gainers         { background: #0d2218; border-top-color: #166534; }
html.dark .stock-item.selected      { background: #1a2744; }
html.dark .search-bar input         { color: var(--text); background: var(--bg-card); }
html.dark .input                    { color: var(--text); background: var(--bg-card); }
html.dark .trade-select             { color: var(--text); background: var(--bg-card); }
html.dark .stepper input[type=number] { background: var(--bg-card); color: var(--text); border-color: var(--border); }

/* ═══════════════════════════════════════════════
   Pantalla de Login
═══════════════════════════════════════════════ */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 2.4rem 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .75rem;
}

.login-logo {
  font-size: 2.8rem;
  line-height: 1;
  margin-bottom: .25rem;
}

.login-title {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text);
  text-align: center;
}

.login-subtitle {
  font-size: .85rem;
  color: var(--text-muted);
  margin-bottom: .5rem;
}

.login-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: .5rem;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: .35rem;
}

.login-field label {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-muted);
}

.login-field input {
  width: 100%;
  padding: .6rem .85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: .9rem;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: border-color var(--transition);
}

.login-field input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.login-error {
  font-size: .82rem;
  color: var(--danger);
  background: var(--danger-lt);
  border-radius: var(--radius-xs);
  padding: .45rem .75rem;
  text-align: center;
}

/* Modo oscuro */
html.dark .login-card   { background: var(--bg-card); }
html.dark .login-field input { background: var(--bg-card); color: var(--text); border-color: var(--border); }
