:root {
  --bg: #0f1420;
  --panel: #1a2130;
  --panel-2: #222b3d;
  --border: #2c3648;
  --text: #e7ecf3;
  --muted: #8a97ab;
  --primary: #3b82f6;
  --primary-hover: #2f6fd6;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ---------- Barra superior ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 20px; margin: 0; font-weight: 600; }
.logo { font-size: 24px; }
.actions { display: flex; align-items: center; gap: 12px; }

/* ---------- Botones ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: #2a3346; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--panel-2); }

/* ---------- Banner de alertas ---------- */
.alert-banner {
  margin: 16px 24px 0;
  padding: 14px 18px;
  border-radius: 10px;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fecaca;
  font-size: 14px;
  line-height: 1.5;
}

/* ---------- Resumen ---------- */
.summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  padding: 20px 24px 4px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
}
.card-label { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.card-value { font-size: 26px; font-weight: 700; }

/* ---------- Tabla ---------- */
main { padding: 16px 24px 40px; }
.holdings {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.holdings th, .holdings td {
  padding: 14px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.holdings th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  background: var(--panel-2);
}
.holdings tbody tr:last-child td { border-bottom: none; }
.holdings tbody tr:hover { background: rgba(255, 255, 255, 0.02); }
.num { text-align: right; }
.holdings td.num { text-align: right; font-variant-numeric: tabular-nums; }

.ticker-cell { display: flex; flex-direction: column; }
.ticker-symbol { font-weight: 700; }
.ticker-name { color: var(--muted); font-size: 12px; }

.up { color: var(--green); }
.down { color: var(--red); }
.pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.pill.up { background: rgba(34, 197, 94, 0.15); }
.pill.down { background: rgba(239, 68, 68, 0.15); }

tr.drastico { background: rgba(239, 68, 68, 0.08) !important; }
tr.drastico td:first-child { box-shadow: inset 3px 0 0 var(--red); }
.badge-alert {
  font-size: 11px;
  background: var(--red);
  color: #fff;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 8px;
  vertical-align: middle;
}
.badge-error {
  font-size: 11px;
  background: var(--amber);
  color: #1a1200;
  padding: 2px 6px;
  border-radius: 4px;
}

/* ---------- Estados vacíos ---------- */
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}
.empty p { margin-bottom: 16px; }

/* ---------- Footer ---------- */
.footbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}

/* ---------- Modales ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 20px;
}
.modal-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.modal-head h2 { margin: 0; font-size: 20px; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 20px;
}

.editor { width: 100%; border-collapse: collapse; margin: 12px 0; }
.editor th {
  text-align: left;
  color: var(--muted);
  font-size: 12px;
  padding: 6px 8px;
  font-weight: 600;
}
.editor td { padding: 4px; }
.editor input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 14px;
}
.editor input:focus { outline: 2px solid var(--primary); border-color: transparent; }
.del-btn {
  background: transparent;
  border: none;
  color: var(--red);
  cursor: pointer;
  font-size: 18px;
  padding: 4px 8px;
}

.field { display: block; margin: 16px 0 4px; }
.field span { display: block; margin-bottom: 6px; font-size: 14px; }
.field input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
}
.field input:focus { outline: 2px solid var(--primary); border-color: transparent; }

.sep { border: none; border-top: 1px solid var(--border); margin: 22px 0 6px; }
.sub { font-size: 15px; margin: 8px 0 4px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
a { color: var(--primary); }
.hidden { display: none !important; }

@media (max-width: 640px) {
  .summary { grid-template-columns: 1fr; }
  .holdings th:nth-child(2), .holdings td:nth-child(2) { display: none; }
}
